@@ -7,22 +7,22 @@ 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_API { |
15 | 15 | protected $post_type = 'wpi_invoice'; |
16 | 16 | |
17 | - public function __construct( $params = array() ) { |
|
17 | + public function __construct($params = array()) { |
|
18 | 18 | } |
19 | - public function insert_invoice( $data ) { |
|
19 | + public function insert_invoice($data) { |
|
20 | 20 | global $wpdb; |
21 | 21 | //wpinv_transaction_query( 'start' ); |
22 | 22 | |
23 | 23 | try { |
24 | - if ( ! isset( $data['invoice'] ) ) { |
|
25 | - throw new WPInv_API_Exception( 'wpinv_api_missing_invoice_data', sprintf( __( 'No %1$s data specified to create %1$s', 'invoicing' ), 'invoice' ), 400 ); |
|
24 | + if (!isset($data['invoice'])) { |
|
25 | + throw new WPInv_API_Exception('wpinv_api_missing_invoice_data', sprintf(__('No %1$s data specified to create %1$s', 'invoicing'), 'invoice'), 400); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | $data = $data['invoice']; |
@@ -32,37 +32,37 @@ discard block |
||
32 | 32 | //throw new WPInv_API_Exception( 'wpinv_api_user_cannot_create_invoice', __( 'You do not have permission to create invoices', 'invoicing' ), 401 ); |
33 | 33 | //} |
34 | 34 | |
35 | - $data = apply_filters( 'wpinv_api_create_invoice_data', $data, $this ); |
|
35 | + $data = apply_filters('wpinv_api_create_invoice_data', $data, $this); |
|
36 | 36 | |
37 | - $invoice = wpinv_insert_invoice( $data ); |
|
38 | - if ( is_wp_error( $invoice ) ) { |
|
39 | - throw new WPInv_API_Exception( 'wpinv_api_cannot_create_invoice', sprintf( __( 'Cannot create invoice: %s', 'invoicing' ), implode( ', ', $invoice->get_error_messages() ) ), 400 ); |
|
37 | + $invoice = wpinv_insert_invoice($data); |
|
38 | + if (is_wp_error($invoice)) { |
|
39 | + throw new WPInv_API_Exception('wpinv_api_cannot_create_invoice', sprintf(__('Cannot create invoice: %s', 'invoicing'), implode(', ', $invoice->get_error_messages())), 400); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | // HTTP 201 Created |
43 | - $this->send_status( 201 ); |
|
43 | + $this->send_status(201); |
|
44 | 44 | |
45 | - do_action( 'wpinv_api_create_invoice', $invoice->ID, $data, $this ); |
|
45 | + do_action('wpinv_api_create_invoice', $invoice->ID, $data, $this); |
|
46 | 46 | |
47 | 47 | //wpinv_transaction_query( 'commit' ); |
48 | 48 | |
49 | - return wpinv_get_invoice( $invoice->ID ); |
|
49 | + return wpinv_get_invoice($invoice->ID); |
|
50 | 50 | |
51 | - } catch ( WPInv_API_Exception $e ) { |
|
51 | + } catch (WPInv_API_Exception $e) { |
|
52 | 52 | |
53 | 53 | //wpinv_transaction_query( 'rollback' ); |
54 | 54 | |
55 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
55 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
59 | - public function create_invoice( $data ) { |
|
59 | + public function create_invoice($data) { |
|
60 | 60 | global $wpdb; |
61 | 61 | //wpinv_transaction_query( 'start' ); |
62 | 62 | |
63 | 63 | try { |
64 | - if ( ! isset( $data['invoice'] ) ) { |
|
65 | - throw new WPInv_API_Exception( 'wpinv_api_missing_invoice_data', sprintf( __( 'No %1$s data specified to create %1$s', 'invoicing' ), 'invoice' ), 400 ); |
|
64 | + if (!isset($data['invoice'])) { |
|
65 | + throw new WPInv_API_Exception('wpinv_api_missing_invoice_data', sprintf(__('No %1$s data specified to create %1$s', 'invoicing'), 'invoice'), 400); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | $data = $data['invoice']; |
@@ -72,111 +72,111 @@ discard block |
||
72 | 72 | //throw new WPInv_API_Exception( 'wpinv_api_user_cannot_create_invoice', __( 'You do not have permission to create invoices', 'invoicing' ), 401 ); |
73 | 73 | //} |
74 | 74 | |
75 | - $data = apply_filters( 'wpinv_api_create_invoice_data', $data, $this ); |
|
75 | + $data = apply_filters('wpinv_api_create_invoice_data', $data, $this); |
|
76 | 76 | |
77 | 77 | // default invoice args, note that status is checked for validity in wpinv_create_invoice() |
78 | 78 | $default_invoice_args = array( |
79 | - 'status' => isset( $data['status'] ) ? $data['status'] : '', |
|
80 | - 'user_note' => isset( $data['note'] ) ? $data['note'] : null, |
|
81 | - 'invoice_id' => isset( $data['invoice_id'] ) ? (int)$data['invoice_id'] : 0, |
|
79 | + 'status' => isset($data['status']) ? $data['status'] : '', |
|
80 | + 'user_note' => isset($data['note']) ? $data['note'] : null, |
|
81 | + 'invoice_id' => isset($data['invoice_id']) ? (int)$data['invoice_id'] : 0, |
|
82 | 82 | ); |
83 | 83 | |
84 | 84 | // if creating invoice for existing user |
85 | - if ( ! empty( $data['user_id'] ) ) { |
|
85 | + if (!empty($data['user_id'])) { |
|
86 | 86 | // make sure user exists |
87 | - if ( false === get_user_by( 'id', $data['user_id'] ) ) { |
|
88 | - throw new WPInv_API_Exception( 'wpinv_api_invalid_user_id', __( 'User ID is invalid', 'invoicing' ), 400 ); |
|
87 | + if (false === get_user_by('id', $data['user_id'])) { |
|
88 | + throw new WPInv_API_Exception('wpinv_api_invalid_user_id', __('User ID is invalid', 'invoicing'), 400); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | $default_invoice_args['user_id'] = $data['user_id']; |
92 | 92 | } |
93 | 93 | |
94 | 94 | // create the pending invoice |
95 | - $invoice = $this->create_base_invoice( $default_invoice_args, $data ); |
|
95 | + $invoice = $this->create_base_invoice($default_invoice_args, $data); |
|
96 | 96 | |
97 | - if ( is_wp_error( $invoice ) ) { |
|
98 | - throw new WPInv_API_Exception( 'wpinv_api_cannot_create_invoice', sprintf( __( 'Cannot create invoice: %s', 'invoicing' ), implode( ', ', $invoice->get_error_messages() ) ), 400 ); |
|
97 | + if (is_wp_error($invoice)) { |
|
98 | + throw new WPInv_API_Exception('wpinv_api_cannot_create_invoice', sprintf(__('Cannot create invoice: %s', 'invoicing'), implode(', ', $invoice->get_error_messages())), 400); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | // Add note |
102 | - if ( !empty( $data['user_note'] ) ) { |
|
103 | - $invoice->add_note( $data['user_note'], true ); |
|
102 | + if (!empty($data['user_note'])) { |
|
103 | + $invoice->add_note($data['user_note'], true); |
|
104 | 104 | } |
105 | 105 | |
106 | - if ( !empty( $data['private_note'] ) ) { |
|
107 | - $invoice->add_note( $data['private_note'] ); |
|
106 | + if (!empty($data['private_note'])) { |
|
107 | + $invoice->add_note($data['private_note']); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | // billing address |
111 | - $invoice = $this->set_billing_details( $invoice, $data ); |
|
111 | + $invoice = $this->set_billing_details($invoice, $data); |
|
112 | 112 | |
113 | 113 | // items |
114 | - $invoice = $this->set_discount( $invoice, $data ); |
|
114 | + $invoice = $this->set_discount($invoice, $data); |
|
115 | 115 | |
116 | 116 | // items |
117 | - $invoice = $this->set_items( $invoice, $data ); |
|
117 | + $invoice = $this->set_items($invoice, $data); |
|
118 | 118 | |
119 | 119 | // payment method (and payment_complete() if `paid` == true) |
120 | - if ( isset( $data['payment_details'] ) && is_array( $data['payment_details'] ) ) { |
|
120 | + if (isset($data['payment_details']) && is_array($data['payment_details'])) { |
|
121 | 121 | // method ID & title are required |
122 | - if ( empty( $data['payment_details']['method_id'] ) || empty( $data['payment_details']['method_title'] ) ) { |
|
123 | - throw new WPInv_API_Exception( 'wpinv_invalid_payment_details', __( 'Payment method ID and title are required', 'invoicing' ), 400 ); |
|
122 | + if (empty($data['payment_details']['method_id']) || empty($data['payment_details']['method_title'])) { |
|
123 | + throw new WPInv_API_Exception('wpinv_invalid_payment_details', __('Payment method ID and title are required', 'invoicing'), 400); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | // set invoice currency |
127 | - if ( isset( $data['payment_details']['currency'] ) ) { |
|
128 | - if ( ! array_key_exists( $data['payment_details']['currency'], wpinv_get_currencies() ) ) { |
|
129 | - throw new WPInv_API_Exception( 'wpinv_invalid_invoice_currency', __( 'Provided invoice currency is invalid', 'invoicing' ), 400 ); |
|
127 | + if (isset($data['payment_details']['currency'])) { |
|
128 | + if (!array_key_exists($data['payment_details']['currency'], wpinv_get_currencies())) { |
|
129 | + throw new WPInv_API_Exception('wpinv_invalid_invoice_currency', __('Provided invoice currency is invalid', 'invoicing'), 400); |
|
130 | 130 | } |
131 | 131 | |
132 | - update_post_meta( $invoice->ID, '_wpinv_currency', $data['payment_details']['currency'] ); |
|
132 | + update_post_meta($invoice->ID, '_wpinv_currency', $data['payment_details']['currency']); |
|
133 | 133 | |
134 | 134 | $invoice->currency = $data['payment_details']['currency']; |
135 | 135 | } |
136 | 136 | |
137 | - update_post_meta( $invoice->ID, '_wpinv_gateway', $data['payment_details']['method_id'] ); |
|
138 | - update_post_meta( $invoice->ID, '_wpinv_gateway_title', $data['payment_details']['method_title'] ); |
|
137 | + update_post_meta($invoice->ID, '_wpinv_gateway', $data['payment_details']['method_id']); |
|
138 | + update_post_meta($invoice->ID, '_wpinv_gateway_title', $data['payment_details']['method_title']); |
|
139 | 139 | |
140 | 140 | $invoice->gateway = $data['payment_details']['method_id']; |
141 | 141 | $invoice->gateway_title = $data['payment_details']['method_title']; |
142 | 142 | |
143 | 143 | // mark as paid if set |
144 | - if ( isset( $data['payment_details']['paid'] ) && true === $data['payment_details']['paid'] ) { |
|
144 | + if (isset($data['payment_details']['paid']) && true === $data['payment_details']['paid']) { |
|
145 | 145 | //$invoice->payment_complete( isset( $data['payment_details']['transaction_id'] ) ? $data['payment_details']['transaction_id'] : $invoice->ID ); |
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
149 | 149 | // set invoice meta |
150 | - if ( isset( $data['invoice_meta'] ) && is_array( $data['invoice_meta'] ) ) { |
|
151 | - $this->set_invoice_meta( $invoice->ID, $data['invoice_meta'] ); |
|
150 | + if (isset($data['invoice_meta']) && is_array($data['invoice_meta'])) { |
|
151 | + $this->set_invoice_meta($invoice->ID, $data['invoice_meta']); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | // HTTP 201 Created |
155 | - $this->send_status( 201 ); |
|
155 | + $this->send_status(201); |
|
156 | 156 | |
157 | - do_action( 'wpinv_api_create_invoice', $invoice->ID, $data, $this ); |
|
157 | + do_action('wpinv_api_create_invoice', $invoice->ID, $data, $this); |
|
158 | 158 | |
159 | 159 | //wpinv_transaction_query( 'commit' ); |
160 | 160 | |
161 | - return wpinv_get_invoice( $invoice->ID ); |
|
161 | + return wpinv_get_invoice($invoice->ID); |
|
162 | 162 | |
163 | - } catch ( WPInv_API_Exception $e ) { |
|
163 | + } catch (WPInv_API_Exception $e) { |
|
164 | 164 | |
165 | 165 | //wpinv_transaction_query( 'rollback' ); |
166 | 166 | |
167 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
167 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
171 | - public function send_status( $code ) { |
|
172 | - status_header( $code ); |
|
171 | + public function send_status($code) { |
|
172 | + status_header($code); |
|
173 | 173 | } |
174 | 174 | |
175 | - protected function create_base_invoice( $args, $data ) { |
|
176 | - return wpinv_create_invoice( $args, $data ); |
|
175 | + protected function create_base_invoice($args, $data) { |
|
176 | + return wpinv_create_invoice($args, $data); |
|
177 | 177 | } |
178 | 178 | |
179 | - protected function set_billing_details( $invoice, $data ) { |
|
179 | + protected function set_billing_details($invoice, $data) { |
|
180 | 180 | $address_fields = array( |
181 | 181 | 'user_id', |
182 | 182 | 'first_name', |
@@ -195,66 +195,66 @@ discard block |
||
195 | 195 | $billing_details = array(); |
196 | 196 | $user_id = $invoice->get_user_id(); |
197 | 197 | |
198 | - foreach ( $address_fields as $field ) { |
|
199 | - if ( isset( $data['billing_details'][ $field ] ) ) { |
|
200 | - $value = sanitize_text_field( $data['billing_details'][ $field ] ); |
|
198 | + foreach ($address_fields as $field) { |
|
199 | + if (isset($data['billing_details'][$field])) { |
|
200 | + $value = sanitize_text_field($data['billing_details'][$field]); |
|
201 | 201 | |
202 | - if ( $field == 'country' && empty( $value ) ) { |
|
203 | - if ( !empty( $invoice->country ) ) { |
|
202 | + if ($field == 'country' && empty($value)) { |
|
203 | + if (!empty($invoice->country)) { |
|
204 | 204 | $value = $invoice->country; |
205 | 205 | } else { |
206 | - $value = wpinv_default_billing_country( '', $user_id ); |
|
206 | + $value = wpinv_default_billing_country('', $user_id); |
|
207 | 207 | } |
208 | 208 | } |
209 | 209 | |
210 | - if ( $field == 'state' && empty( $value ) ) { |
|
211 | - if ( !empty( $invoice->state ) ) { |
|
210 | + if ($field == 'state' && empty($value)) { |
|
211 | + if (!empty($invoice->state)) { |
|
212 | 212 | $value = $invoice->state; |
213 | 213 | } else { |
214 | 214 | $value = wpinv_get_default_state(); |
215 | 215 | } |
216 | 216 | } |
217 | 217 | |
218 | - $invoice->set( $field, $value ); |
|
218 | + $invoice->set($field, $value); |
|
219 | 219 | |
220 | - update_post_meta( $invoice->ID, '_wpinv_' . $field, $value ); |
|
220 | + update_post_meta($invoice->ID, '_wpinv_' . $field, $value); |
|
221 | 221 | } |
222 | 222 | } |
223 | 223 | |
224 | 224 | return $invoice; |
225 | 225 | } |
226 | 226 | |
227 | - protected function set_discount( $invoice, $data ) { |
|
228 | - if ( isset( $data['discount'] ) ) { |
|
229 | - $invoice->set( 'discount', wpinv_format_amount( $data['discount'], NULL, true ) ); |
|
227 | + protected function set_discount($invoice, $data) { |
|
228 | + if (isset($data['discount'])) { |
|
229 | + $invoice->set('discount', wpinv_format_amount($data['discount'], NULL, true)); |
|
230 | 230 | |
231 | - update_post_meta( $invoice->ID, '_wpinv_discount', wpinv_format_amount( $data['discount'], NULL, true ) ); |
|
231 | + update_post_meta($invoice->ID, '_wpinv_discount', wpinv_format_amount($data['discount'], NULL, true)); |
|
232 | 232 | |
233 | - if ( isset( $data['discount_code'] ) ) { |
|
234 | - $invoice->set( 'discount_code', $data['discount_code'] ); |
|
233 | + if (isset($data['discount_code'])) { |
|
234 | + $invoice->set('discount_code', $data['discount_code']); |
|
235 | 235 | |
236 | - update_post_meta( $invoice->ID, '_wpinv_discount_code', $data['discount_code'] ); |
|
236 | + update_post_meta($invoice->ID, '_wpinv_discount_code', $data['discount_code']); |
|
237 | 237 | } |
238 | 238 | } |
239 | 239 | |
240 | 240 | return $invoice; |
241 | 241 | } |
242 | 242 | |
243 | - protected function set_items( $invoice, $data ) { |
|
244 | - if ( !empty( $data['items'] ) && is_array( $data['items'] ) ) { |
|
243 | + protected function set_items($invoice, $data) { |
|
244 | + if (!empty($data['items']) && is_array($data['items'])) { |
|
245 | 245 | $items_array = array(); |
246 | 246 | |
247 | - if ( !empty( $invoice->country ) ) { |
|
247 | + if (!empty($invoice->country)) { |
|
248 | 248 | $country = $invoice->country; |
249 | - } else if ( !empty( $data['billing_details']['country'] ) ) { |
|
249 | + } else if (!empty($data['billing_details']['country'])) { |
|
250 | 250 | $country = $data['billing_details']['country']; |
251 | 251 | } else { |
252 | - $country = wpinv_default_billing_country( '', $invoice->get_user_id() ); |
|
252 | + $country = wpinv_default_billing_country('', $invoice->get_user_id()); |
|
253 | 253 | } |
254 | 254 | |
255 | - if ( !empty( $invoice->state ) ) { |
|
255 | + if (!empty($invoice->state)) { |
|
256 | 256 | $state = $invoice->state; |
257 | - } else if ( !empty( $data['billing_details']['state'] ) ) { |
|
257 | + } else if (!empty($data['billing_details']['state'])) { |
|
258 | 258 | $state = $data['billing_details']['state']; |
259 | 259 | } else { |
260 | 260 | $state = wpinv_get_default_state(); |
@@ -263,54 +263,54 @@ discard block |
||
263 | 263 | $_POST['country'] = $country; |
264 | 264 | $_POST['state'] = $state; |
265 | 265 | |
266 | - $rate = wpinv_get_tax_rate( $country, $state, 'global' ); |
|
266 | + $rate = wpinv_get_tax_rate($country, $state, 'global'); |
|
267 | 267 | |
268 | 268 | $total_tax = 0; |
269 | - foreach ( $data['items'] as $item ) { |
|
270 | - $id = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : ''; |
|
271 | - $title = isset( $item['title'] ) ? sanitize_text_field( $item['title'] ) : ''; |
|
272 | - $desc = isset( $item['description'] ) ? sanitize_text_field( $item['description'] ) : ''; |
|
273 | - $amount = isset( $item['amount'] ) ? wpinv_format_amount( $item['amount'], NULL, true ) : 0; |
|
269 | + foreach ($data['items'] as $item) { |
|
270 | + $id = isset($item['id']) ? sanitize_text_field($item['id']) : ''; |
|
271 | + $title = isset($item['title']) ? sanitize_text_field($item['title']) : ''; |
|
272 | + $desc = isset($item['description']) ? sanitize_text_field($item['description']) : ''; |
|
273 | + $amount = isset($item['amount']) ? wpinv_format_amount($item['amount'], NULL, true) : 0; |
|
274 | 274 | |
275 | - if ( !empty( $item['vat_rates_class'] ) ) { |
|
275 | + if (!empty($item['vat_rates_class'])) { |
|
276 | 276 | $vat_rates_class = $item['vat_rates_class']; |
277 | 277 | } else { |
278 | 278 | $vat_rates_class = '_standard'; |
279 | 279 | } |
280 | - $vat_rate = wpinv_get_tax_rate( $country, $state, $id ); |
|
280 | + $vat_rate = wpinv_get_tax_rate($country, $state, $id); |
|
281 | 281 | |
282 | - $tax = $amount > 0 ? ( $amount * 0.01 * (float)$vat_rate ) : 0; |
|
282 | + $tax = $amount > 0 ? ($amount * 0.01 * (float)$vat_rate) : 0; |
|
283 | 283 | $total_tax += $tax; |
284 | 284 | |
285 | 285 | $items_array[] = array( |
286 | 286 | 'id' => $id, |
287 | - 'title' => esc_html( $title ), |
|
288 | - 'description' => esc_html( $desc ), |
|
289 | - 'amount' => $amount > 0 ? wpinv_format_amount( $amount, NULL, true ) : 0, |
|
290 | - 'subtotal' => $amount > 0 ? wpinv_format_amount( $amount, NULL, true ) : 0, |
|
287 | + 'title' => esc_html($title), |
|
288 | + 'description' => esc_html($desc), |
|
289 | + 'amount' => $amount > 0 ? wpinv_format_amount($amount, NULL, true) : 0, |
|
290 | + 'subtotal' => $amount > 0 ? wpinv_format_amount($amount, NULL, true) : 0, |
|
291 | 291 | 'vat_rates_class' => $vat_rates_class, |
292 | - 'vat_rate' => $vat_rate > 0 ? wpinv_format_amount( $vat_rate, NULL, true ) : 0, |
|
293 | - 'tax' => $tax > 0 ? wpinv_format_amount( $tax, NULL, true ) : 0, |
|
292 | + 'vat_rate' => $vat_rate > 0 ? wpinv_format_amount($vat_rate, NULL, true) : 0, |
|
293 | + 'tax' => $tax > 0 ? wpinv_format_amount($tax, NULL, true) : 0, |
|
294 | 294 | ); |
295 | 295 | } |
296 | 296 | |
297 | - update_post_meta( $invoice->ID, '_wpinv_tax', wpinv_format_amount( $total_tax, NULL, true ) ); |
|
298 | - $invoice->set( 'tax', wpinv_format_amount( $total_tax, NULL, true ) ); |
|
297 | + update_post_meta($invoice->ID, '_wpinv_tax', wpinv_format_amount($total_tax, NULL, true)); |
|
298 | + $invoice->set('tax', wpinv_format_amount($total_tax, NULL, true)); |
|
299 | 299 | |
300 | - $items_array = apply_filters( 'wpinv_save_invoice_items', $items_array, $data['items'], $invoice ); |
|
300 | + $items_array = apply_filters('wpinv_save_invoice_items', $items_array, $data['items'], $invoice); |
|
301 | 301 | |
302 | - $invoice->set( 'items', $items_array ); |
|
303 | - update_post_meta( $invoice->ID, '_wpinv_items', $items_array ); |
|
302 | + $invoice->set('items', $items_array); |
|
303 | + update_post_meta($invoice->ID, '_wpinv_items', $items_array); |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | return $invoice; |
307 | 307 | } |
308 | 308 | |
309 | - protected function set_invoice_meta( $invoice_id, $invoice_meta ) { |
|
310 | - foreach ( $invoice_meta as $meta_key => $meta_value ) { |
|
309 | + protected function set_invoice_meta($invoice_id, $invoice_meta) { |
|
310 | + foreach ($invoice_meta as $meta_key => $meta_value) { |
|
311 | 311 | |
312 | - if ( is_string( $meta_key) && ! is_protected_meta( $meta_key ) && is_scalar( $meta_value ) ) { |
|
313 | - update_post_meta( $invoice_id, $meta_key, $meta_value ); |
|
312 | + if (is_string($meta_key) && !is_protected_meta($meta_key) && is_scalar($meta_value)) { |
|
313 | + update_post_meta($invoice_id, $meta_key, $meta_value); |
|
314 | 314 | } |
315 | 315 | } |
316 | 316 | } |
@@ -320,9 +320,9 @@ discard block |
||
320 | 320 | class WPInv_API_Exception extends Exception { |
321 | 321 | protected $error_code; |
322 | 322 | |
323 | - public function __construct( $error_code, $error_message, $http_status_code ) { |
|
323 | + public function __construct($error_code, $error_message, $http_status_code) { |
|
324 | 324 | $this->error_code = $error_code; |
325 | - parent::__construct( $error_message, $http_status_code ); |
|
325 | + parent::__construct($error_message, $http_status_code); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | public function getErrorCode() { |
@@ -7,28 +7,28 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | class WPInv_Ajax { |
15 | 15 | public static function init() { |
16 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
17 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
16 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
17 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
18 | 18 | self::add_ajax_events(); |
19 | 19 | } |
20 | 20 | |
21 | 21 | public static function define_ajax() { |
22 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
23 | - if ( ! defined( 'DOING_AJAX' ) ) { |
|
24 | - define( 'DOING_AJAX', true ); |
|
22 | + if (!empty($_GET['wpinv-ajax'])) { |
|
23 | + if (!defined('DOING_AJAX')) { |
|
24 | + define('DOING_AJAX', true); |
|
25 | 25 | } |
26 | - if ( ! defined( 'WC_DOING_AJAX' ) ) { |
|
27 | - define( 'WC_DOING_AJAX', true ); |
|
26 | + if (!defined('WC_DOING_AJAX')) { |
|
27 | + define('WC_DOING_AJAX', true); |
|
28 | 28 | } |
29 | 29 | // Turn off display_errors during AJAX events to prevent malformed JSON |
30 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
31 | - @ini_set( 'display_errors', 0 ); |
|
30 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
31 | + @ini_set('display_errors', 0); |
|
32 | 32 | } |
33 | 33 | $GLOBALS['wpdb']->hide_errors(); |
34 | 34 | } |
@@ -37,24 +37,24 @@ discard block |
||
37 | 37 | public static function do_wpinv_ajax() { |
38 | 38 | global $wp_query; |
39 | 39 | |
40 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
41 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) ); |
|
40 | + if (!empty($_GET['wpinv-ajax'])) { |
|
41 | + $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax'])); |
|
42 | 42 | } |
43 | 43 | |
44 | - if ( $action = $wp_query->get( 'wpinv-ajax' ) ) { |
|
44 | + if ($action = $wp_query->get('wpinv-ajax')) { |
|
45 | 45 | self::wpinv_ajax_headers(); |
46 | - do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) ); |
|
46 | + do_action('wpinv_ajax_' . sanitize_text_field($action)); |
|
47 | 47 | die(); |
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
51 | 51 | private static function wpinv_ajax_headers() { |
52 | 52 | send_origin_headers(); |
53 | - @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
54 | - @header( 'X-Robots-Tag: noindex' ); |
|
53 | + @header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
54 | + @header('X-Robots-Tag: noindex'); |
|
55 | 55 | send_nosniff_header(); |
56 | 56 | nocache_headers(); |
57 | - status_header( 200 ); |
|
57 | + status_header(200); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | public static function add_ajax_events() { |
@@ -76,39 +76,39 @@ discard block |
||
76 | 76 | 'remove_discount' => false, |
77 | 77 | ); |
78 | 78 | |
79 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
80 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
79 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
80 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
81 | 81 | |
82 | - if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) { |
|
83 | - define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 ); |
|
82 | + if (!defined('WPI_AJAX_' . strtoupper($nopriv))) { |
|
83 | + define('WPI_AJAX_' . strtoupper($nopriv), 1); |
|
84 | 84 | } |
85 | 85 | |
86 | - if ( $nopriv ) { |
|
87 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
86 | + if ($nopriv) { |
|
87 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
88 | 88 | |
89 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
89 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | 94 | public static function add_note() { |
95 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
95 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
96 | 96 | |
97 | - if ( !current_user_can( 'manage_options' ) ) { |
|
97 | + if (!current_user_can('manage_options')) { |
|
98 | 98 | die(-1); |
99 | 99 | } |
100 | 100 | |
101 | - $post_id = absint( $_POST['post_id'] ); |
|
102 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
103 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
101 | + $post_id = absint($_POST['post_id']); |
|
102 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
103 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
104 | 104 | |
105 | 105 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
106 | 106 | |
107 | - if ( $post_id > 0 ) { |
|
108 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
107 | + if ($post_id > 0) { |
|
108 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
109 | 109 | |
110 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
111 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
110 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
111 | + wpinv_get_invoice_note_line_item($note_id); |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
@@ -116,16 +116,16 @@ discard block |
||
116 | 116 | } |
117 | 117 | |
118 | 118 | public static function delete_note() { |
119 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
119 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
120 | 120 | |
121 | - if ( !current_user_can( 'manage_options' ) ) { |
|
121 | + if (!current_user_can('manage_options')) { |
|
122 | 122 | die(-1); |
123 | 123 | } |
124 | 124 | |
125 | 125 | $note_id = (int)$_POST['note_id']; |
126 | 126 | |
127 | - if ( $note_id > 0 ) { |
|
128 | - wp_delete_comment( $note_id, true ); |
|
127 | + if ($note_id > 0) { |
|
128 | + wp_delete_comment($note_id, true); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | die(); |
@@ -138,8 +138,8 @@ discard block |
||
138 | 138 | } |
139 | 139 | |
140 | 140 | public static function checkout() { |
141 | - if ( ! defined( 'WPINV_CHECKOUT' ) ) { |
|
142 | - define( 'WPINV_CHECKOUT', true ); |
|
141 | + if (!defined('WPINV_CHECKOUT')) { |
|
142 | + define('WPINV_CHECKOUT', true); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | wpinv_process_checkout(); |
@@ -148,53 +148,53 @@ discard block |
||
148 | 148 | |
149 | 149 | public static function add_invoice_item() { |
150 | 150 | global $wpi_userID, $wpinv_ip_address_country; |
151 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
152 | - if ( !current_user_can( 'manage_options' ) ) { |
|
151 | + check_ajax_referer('invoice-item', '_nonce'); |
|
152 | + if (!current_user_can('manage_options')) { |
|
153 | 153 | die(-1); |
154 | 154 | } |
155 | 155 | |
156 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
157 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
156 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
157 | + $invoice_id = absint($_POST['invoice_id']); |
|
158 | 158 | |
159 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
159 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
160 | 160 | die(); |
161 | 161 | } |
162 | 162 | |
163 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
164 | - if ( empty( $invoice ) ) { |
|
163 | + $invoice = wpinv_get_invoice($invoice_id); |
|
164 | + if (empty($invoice)) { |
|
165 | 165 | die(); |
166 | 166 | } |
167 | 167 | |
168 | - if ( $invoice->is_paid() ) { |
|
168 | + if ($invoice->is_paid()) { |
|
169 | 169 | die(); // Don't allow modify items for paid invoice. |
170 | 170 | } |
171 | 171 | |
172 | - if ( !empty( $_POST['user_id'] ) ) { |
|
173 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
172 | + if (!empty($_POST['user_id'])) { |
|
173 | + $wpi_userID = absint($_POST['user_id']); |
|
174 | 174 | } |
175 | 175 | |
176 | - $item = new WPInv_Item( $item_id ); |
|
177 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
176 | + $item = new WPInv_Item($item_id); |
|
177 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
178 | 178 | die(); |
179 | 179 | } |
180 | 180 | |
181 | 181 | // Validate item before adding to invoice because recurring item must be paid individually. |
182 | - if ( !empty( $invoice->cart_details ) ) { |
|
182 | + if (!empty($invoice->cart_details)) { |
|
183 | 183 | $valid = true; |
184 | 184 | |
185 | - if ( $recurring_item = $invoice->get_recurring() ) { |
|
186 | - if ( $recurring_item != $item_id ) { |
|
185 | + if ($recurring_item = $invoice->get_recurring()) { |
|
186 | + if ($recurring_item != $item_id) { |
|
187 | 187 | $valid = false; |
188 | 188 | } |
189 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
189 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
190 | 190 | $valid = false; |
191 | 191 | } |
192 | 192 | |
193 | - if ( !$valid ) { |
|
193 | + if (!$valid) { |
|
194 | 194 | $response = array(); |
195 | 195 | $response['success'] = false; |
196 | - $response['msg'] = __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' ); |
|
197 | - wp_send_json( $response ); |
|
196 | + $response['msg'] = __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing'); |
|
197 | + wp_send_json($response); |
|
198 | 198 | } |
199 | 199 | } |
200 | 200 | |
@@ -202,9 +202,9 @@ discard block |
||
202 | 202 | |
203 | 203 | $data = array(); |
204 | 204 | $data['invoice_id'] = $invoice_id; |
205 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
205 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
206 | 206 | |
207 | - wpinv_set_checkout_session( $data ); |
|
207 | + wpinv_set_checkout_session($data); |
|
208 | 208 | |
209 | 209 | $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1; |
210 | 210 | |
@@ -218,21 +218,21 @@ discard block |
||
218 | 218 | 'fees' => array() |
219 | 219 | ); |
220 | 220 | |
221 | - $invoice->add_item( $item_id, $args ); |
|
221 | + $invoice->add_item($item_id, $args); |
|
222 | 222 | $invoice->save(); |
223 | 223 | |
224 | - if ( empty( $_POST['country'] ) ) { |
|
224 | + if (empty($_POST['country'])) { |
|
225 | 225 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
226 | 226 | } |
227 | - if ( empty( $_POST['state'] ) ) { |
|
227 | + if (empty($_POST['state'])) { |
|
228 | 228 | $_POST['state'] = $invoice->state; |
229 | 229 | } |
230 | 230 | |
231 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
232 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
231 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
232 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
233 | 233 | |
234 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
235 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
234 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
235 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
236 | 236 | |
237 | 237 | $wpinv_ip_address_country = $invoice->country; |
238 | 238 | |
@@ -240,52 +240,52 @@ discard block |
||
240 | 240 | |
241 | 241 | $response = array(); |
242 | 242 | $response['success'] = true; |
243 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
243 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
244 | 244 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
245 | 245 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
246 | 246 | $response['data']['tax'] = $invoice->get_tax(); |
247 | 247 | $response['data']['taxf'] = $invoice->get_tax(true); |
248 | 248 | $response['data']['discount'] = $invoice->discount; |
249 | - $response['data']['discountf'] = wpinv_price( $invoice->discount, $invoice->get_currency() ); |
|
249 | + $response['data']['discountf'] = wpinv_price($invoice->discount, $invoice->get_currency()); |
|
250 | 250 | $response['data']['total'] = $invoice->get_total(); |
251 | 251 | $response['data']['totalf'] = $invoice->get_total(true); |
252 | 252 | |
253 | 253 | wpinv_set_checkout_session($checkout_session); |
254 | 254 | |
255 | - wp_send_json( $response ); |
|
255 | + wp_send_json($response); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | public static function remove_invoice_item() { |
259 | 259 | global $wpi_userID, $wpinv_ip_address_country; |
260 | 260 | |
261 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
262 | - if ( !current_user_can( 'manage_options' ) ) { |
|
261 | + check_ajax_referer('invoice-item', '_nonce'); |
|
262 | + if (!current_user_can('manage_options')) { |
|
263 | 263 | die(-1); |
264 | 264 | } |
265 | 265 | |
266 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
267 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
268 | - $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
266 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
267 | + $invoice_id = absint($_POST['invoice_id']); |
|
268 | + $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
269 | 269 | |
270 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
270 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
271 | 271 | die(); |
272 | 272 | } |
273 | 273 | |
274 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
275 | - if ( empty( $invoice ) ) { |
|
274 | + $invoice = wpinv_get_invoice($invoice_id); |
|
275 | + if (empty($invoice)) { |
|
276 | 276 | die(); |
277 | 277 | } |
278 | 278 | |
279 | - if ( $invoice->is_paid() ) { |
|
279 | + if ($invoice->is_paid()) { |
|
280 | 280 | die(); // Don't allow modify items for paid invoice. |
281 | 281 | } |
282 | 282 | |
283 | - if ( !empty( $_POST['user_id'] ) ) { |
|
284 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
283 | + if (!empty($_POST['user_id'])) { |
|
284 | + $wpi_userID = absint($_POST['user_id']); |
|
285 | 285 | } |
286 | 286 | |
287 | - $item = new WPInv_Item( $item_id ); |
|
288 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
287 | + $item = new WPInv_Item($item_id); |
|
288 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
289 | 289 | die(); |
290 | 290 | } |
291 | 291 | |
@@ -293,9 +293,9 @@ discard block |
||
293 | 293 | |
294 | 294 | $data = array(); |
295 | 295 | $data['invoice_id'] = $invoice_id; |
296 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
296 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
297 | 297 | |
298 | - wpinv_set_checkout_session( $data ); |
|
298 | + wpinv_set_checkout_session($data); |
|
299 | 299 | |
300 | 300 | $args = array( |
301 | 301 | 'id' => $item_id, |
@@ -303,21 +303,21 @@ discard block |
||
303 | 303 | 'cart_index' => $cart_index |
304 | 304 | ); |
305 | 305 | |
306 | - $invoice->remove_item( $item_id, $args ); |
|
306 | + $invoice->remove_item($item_id, $args); |
|
307 | 307 | $invoice->save(); |
308 | 308 | |
309 | - if ( empty( $_POST['country'] ) ) { |
|
309 | + if (empty($_POST['country'])) { |
|
310 | 310 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
311 | 311 | } |
312 | - if ( empty( $_POST['state'] ) ) { |
|
312 | + if (empty($_POST['state'])) { |
|
313 | 313 | $_POST['state'] = $invoice->state; |
314 | 314 | } |
315 | 315 | |
316 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
317 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
316 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
317 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
318 | 318 | |
319 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
320 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
319 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
320 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
321 | 321 | |
322 | 322 | $wpinv_ip_address_country = $invoice->country; |
323 | 323 | |
@@ -325,52 +325,52 @@ discard block |
||
325 | 325 | |
326 | 326 | $response = array(); |
327 | 327 | $response['success'] = true; |
328 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
328 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
329 | 329 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
330 | 330 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
331 | 331 | $response['data']['tax'] = $invoice->get_tax(); |
332 | 332 | $response['data']['taxf'] = $invoice->get_tax(true); |
333 | 333 | $response['data']['discount'] = $invoice->discount; |
334 | - $response['data']['discountf'] = wpinv_price( $invoice->discount, $invoice->get_currency() ); |
|
334 | + $response['data']['discountf'] = wpinv_price($invoice->discount, $invoice->get_currency()); |
|
335 | 335 | $response['data']['total'] = $invoice->get_total(); |
336 | 336 | $response['data']['totalf'] = $invoice->get_total(true); |
337 | 337 | |
338 | 338 | wpinv_set_checkout_session($checkout_session); |
339 | 339 | |
340 | - wp_send_json( $response ); |
|
340 | + wp_send_json($response); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | public static function create_invoice_item() { |
344 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
345 | - if ( !current_user_can( 'manage_options' ) ) { |
|
344 | + check_ajax_referer('invoice-item', '_nonce'); |
|
345 | + if (!current_user_can('manage_options')) { |
|
346 | 346 | die(-1); |
347 | 347 | } |
348 | 348 | |
349 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
349 | + $invoice_id = absint($_POST['invoice_id']); |
|
350 | 350 | |
351 | 351 | // Find the item |
352 | - if ( !is_numeric( $invoice_id ) ) { |
|
352 | + if (!is_numeric($invoice_id)) { |
|
353 | 353 | die(); |
354 | 354 | } |
355 | 355 | |
356 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
357 | - if ( empty( $invoice ) ) { |
|
356 | + $invoice = wpinv_get_invoice($invoice_id); |
|
357 | + if (empty($invoice)) { |
|
358 | 358 | die(); |
359 | 359 | } |
360 | 360 | |
361 | 361 | // Validate item before adding to invoice because recurring item must be paid individually. |
362 | - if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) { |
|
362 | + if (!empty($invoice->cart_details) && $invoice->get_recurring()) { |
|
363 | 363 | $response = array(); |
364 | 364 | $response['success'] = false; |
365 | - $response['msg'] = __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' ); |
|
366 | - wp_send_json( $response ); |
|
365 | + $response['msg'] = __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing'); |
|
366 | + wp_send_json($response); |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | $save_item = $_POST['_wpinv_quick']; |
370 | 370 | |
371 | 371 | $meta = array(); |
372 | 372 | $meta['type'] = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom'; |
373 | - $meta['price'] = !empty($save_item['price']) ? wpinv_format_amount($save_item['price'], NULL, true ) : 0; |
|
373 | + $meta['price'] = !empty($save_item['price']) ? wpinv_format_amount($save_item['price'], NULL, true) : 0; |
|
374 | 374 | $meta['vat_rule'] = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital'; |
375 | 375 | $meta['vat_class'] = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard'; |
376 | 376 | |
@@ -380,9 +380,9 @@ discard block |
||
380 | 380 | $data['meta'] = $meta; |
381 | 381 | |
382 | 382 | $item = new WPInv_Item(); |
383 | - $item->create( $data ); |
|
383 | + $item->create($data); |
|
384 | 384 | |
385 | - if ( !empty( $item ) ) { |
|
385 | + if (!empty($item)) { |
|
386 | 386 | $_POST['item_id'] = $item->ID; |
387 | 387 | $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1; |
388 | 388 | |
@@ -392,15 +392,15 @@ discard block |
||
392 | 392 | } |
393 | 393 | |
394 | 394 | public static function get_billing_details() { |
395 | - check_ajax_referer( 'get-billing-details', '_nonce' ); |
|
395 | + check_ajax_referer('get-billing-details', '_nonce'); |
|
396 | 396 | |
397 | - if ( !current_user_can( 'manage_options' ) ) { |
|
397 | + if (!current_user_can('manage_options')) { |
|
398 | 398 | die(-1); |
399 | 399 | } |
400 | 400 | |
401 | 401 | $user_id = (int)$_POST['user_id']; |
402 | 402 | $billing_details = wpinv_get_user_address($user_id); |
403 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
403 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
404 | 404 | |
405 | 405 | if (isset($billing_details['user_id'])) { |
406 | 406 | unset($billing_details['user_id']); |
@@ -414,20 +414,20 @@ discard block |
||
414 | 414 | $response['success'] = true; |
415 | 415 | $response['data']['billing_details'] = $billing_details; |
416 | 416 | |
417 | - wp_send_json( $response ); |
|
417 | + wp_send_json($response); |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | public static function admin_recalculate_totals() { |
421 | 421 | global $wpi_userID, $wpinv_ip_address_country; |
422 | 422 | |
423 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
424 | - if ( !current_user_can( 'manage_options' ) ) { |
|
423 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
424 | + if (!current_user_can('manage_options')) { |
|
425 | 425 | die(-1); |
426 | 426 | } |
427 | 427 | |
428 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
429 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
430 | - if ( empty( $invoice ) ) { |
|
428 | + $invoice_id = absint($_POST['invoice_id']); |
|
429 | + $invoice = wpinv_get_invoice($invoice_id); |
|
430 | + if (empty($invoice)) { |
|
431 | 431 | die(); |
432 | 432 | } |
433 | 433 | |
@@ -435,23 +435,23 @@ discard block |
||
435 | 435 | |
436 | 436 | $data = array(); |
437 | 437 | $data['invoice_id'] = $invoice_id; |
438 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
438 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
439 | 439 | |
440 | - wpinv_set_checkout_session( $data ); |
|
440 | + wpinv_set_checkout_session($data); |
|
441 | 441 | |
442 | - if ( !empty( $_POST['user_id'] ) ) { |
|
443 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
442 | + if (!empty($_POST['user_id'])) { |
|
443 | + $wpi_userID = absint($_POST['user_id']); |
|
444 | 444 | } |
445 | 445 | |
446 | - if ( empty( $_POST['country'] ) ) { |
|
446 | + if (empty($_POST['country'])) { |
|
447 | 447 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
448 | 448 | } |
449 | 449 | |
450 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
451 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
452 | - if ( isset( $_POST['state'] ) ) { |
|
453 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
454 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
450 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
451 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
452 | + if (isset($_POST['state'])) { |
|
453 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
454 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | $wpinv_ip_address_country = $invoice->country; |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | |
461 | 461 | $response = array(); |
462 | 462 | $response['success'] = true; |
463 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
463 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
464 | 464 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
465 | 465 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
466 | 466 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -472,25 +472,25 @@ discard block |
||
472 | 472 | |
473 | 473 | wpinv_set_checkout_session($checkout_session); |
474 | 474 | |
475 | - wp_send_json( $response ); |
|
475 | + wp_send_json($response); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | public static function admin_apply_discount() { |
479 | 479 | global $wpi_userID; |
480 | 480 | |
481 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
482 | - if ( !current_user_can( 'manage_options' ) ) { |
|
481 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
482 | + if (!current_user_can('manage_options')) { |
|
483 | 483 | die(-1); |
484 | 484 | } |
485 | 485 | |
486 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
487 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
488 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
486 | + $invoice_id = absint($_POST['invoice_id']); |
|
487 | + $discount_code = sanitize_text_field($_POST['code']); |
|
488 | + if (empty($invoice_id) || empty($discount_code)) { |
|
489 | 489 | die(); |
490 | 490 | } |
491 | 491 | |
492 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
493 | - if ( empty( $invoice ) || ( !empty( $invoice ) && $invoice->is_paid() ) ) { |
|
492 | + $invoice = wpinv_get_invoice($invoice_id); |
|
493 | + if (empty($invoice) || (!empty($invoice) && $invoice->is_paid())) { |
|
494 | 494 | die(); |
495 | 495 | } |
496 | 496 | |
@@ -498,49 +498,49 @@ discard block |
||
498 | 498 | |
499 | 499 | $data = array(); |
500 | 500 | $data['invoice_id'] = $invoice_id; |
501 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
501 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
502 | 502 | |
503 | - wpinv_set_checkout_session( $data ); |
|
503 | + wpinv_set_checkout_session($data); |
|
504 | 504 | |
505 | 505 | $response = array(); |
506 | 506 | $response['success'] = false; |
507 | - $response['msg'] = __( 'This discount is invalid.', 'invoicing' ); |
|
507 | + $response['msg'] = __('This discount is invalid.', 'invoicing'); |
|
508 | 508 | $response['data']['code'] = $discount_code; |
509 | 509 | |
510 | - if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) { |
|
511 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
510 | + if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) { |
|
511 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
512 | 512 | |
513 | 513 | $response['success'] = true; |
514 | - $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' ); |
|
515 | - } else { |
|
514 | + $response['msg'] = __('Discount has been applied successfully.', 'invoicing'); |
|
515 | + } else { |
|
516 | 516 | $errors = wpinv_get_errors(); |
517 | - if ( !empty( $errors['wpinv-discount-error'] ) ) { |
|
517 | + if (!empty($errors['wpinv-discount-error'])) { |
|
518 | 518 | $response['msg'] = $errors['wpinv-discount-error']; |
519 | 519 | } |
520 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
520 | + wpinv_unset_error('wpinv-discount-error'); |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | wpinv_set_checkout_session($checkout_session); |
524 | 524 | |
525 | - wp_send_json( $response ); |
|
525 | + wp_send_json($response); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | public static function admin_remove_discount() { |
529 | 529 | global $wpi_userID; |
530 | 530 | |
531 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
532 | - if ( !current_user_can( 'manage_options' ) ) { |
|
531 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
532 | + if (!current_user_can('manage_options')) { |
|
533 | 533 | die(-1); |
534 | 534 | } |
535 | 535 | |
536 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
537 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
538 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
536 | + $invoice_id = absint($_POST['invoice_id']); |
|
537 | + $discount_code = sanitize_text_field($_POST['code']); |
|
538 | + if (empty($invoice_id) || empty($discount_code)) { |
|
539 | 539 | die(); |
540 | 540 | } |
541 | 541 | |
542 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
543 | - if ( empty( $invoice ) || ( !empty( $invoice ) && $invoice->is_paid() ) ) { |
|
542 | + $invoice = wpinv_get_invoice($invoice_id); |
|
543 | + if (empty($invoice) || (!empty($invoice) && $invoice->is_paid())) { |
|
544 | 544 | die(); |
545 | 545 | } |
546 | 546 | |
@@ -548,38 +548,38 @@ discard block |
||
548 | 548 | |
549 | 549 | $data = array(); |
550 | 550 | $data['invoice_id'] = $invoice_id; |
551 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
551 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
552 | 552 | |
553 | - wpinv_set_checkout_session( $data ); |
|
553 | + wpinv_set_checkout_session($data); |
|
554 | 554 | |
555 | 555 | $response = array(); |
556 | 556 | $response['success'] = false; |
557 | 557 | $response['msg'] = NULL; |
558 | 558 | |
559 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
559 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
560 | 560 | $response['success'] = true; |
561 | - $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' ); |
|
561 | + $response['msg'] = __('Discount has been removed successfully.', 'invoicing'); |
|
562 | 562 | |
563 | 563 | wpinv_set_checkout_session($checkout_session); |
564 | 564 | |
565 | - wp_send_json( $response ); |
|
565 | + wp_send_json($response); |
|
566 | 566 | } |
567 | 567 | |
568 | 568 | public static function check_email() { |
569 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
570 | - if ( !current_user_can( 'manage_options' ) ) { |
|
569 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
570 | + if (!current_user_can('manage_options')) { |
|
571 | 571 | die(-1); |
572 | 572 | } |
573 | 573 | |
574 | - $email = sanitize_text_field( $_POST['email'] ); |
|
574 | + $email = sanitize_text_field($_POST['email']); |
|
575 | 575 | |
576 | 576 | $response = array(); |
577 | - if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) { |
|
577 | + if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) { |
|
578 | 578 | $user_id = $user_data->ID; |
579 | 579 | $user_login = $user_data->user_login; |
580 | 580 | $display_name = $user_data->display_name ? $user_data->display_name : $user_login; |
581 | 581 | $billing_details = wpinv_get_user_address($user_id); |
582 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
582 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
583 | 583 | |
584 | 584 | if (isset($billing_details['user_id'])) { |
585 | 585 | unset($billing_details['user_id']); |
@@ -595,31 +595,31 @@ discard block |
||
595 | 595 | $response['data']['billing_details'] = $billing_details; |
596 | 596 | } |
597 | 597 | |
598 | - wp_send_json( $response ); |
|
598 | + wp_send_json($response); |
|
599 | 599 | } |
600 | 600 | |
601 | 601 | public static function run_tool() { |
602 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
603 | - if ( !current_user_can( 'manage_options' ) ) { |
|
602 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
603 | + if (!current_user_can('manage_options')) { |
|
604 | 604 | die(-1); |
605 | 605 | } |
606 | 606 | |
607 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
607 | + $tool = sanitize_text_field($_POST['tool']); |
|
608 | 608 | |
609 | - do_action( 'wpinv_run_tool' ); |
|
609 | + do_action('wpinv_run_tool'); |
|
610 | 610 | |
611 | - if ( !empty( $tool ) ) { |
|
612 | - do_action( 'wpinv_tool_' . $tool ); |
|
611 | + if (!empty($tool)) { |
|
612 | + do_action('wpinv_tool_' . $tool); |
|
613 | 613 | } |
614 | 614 | } |
615 | 615 | |
616 | 616 | public static function apply_discount() { |
617 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
617 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
618 | 618 | |
619 | 619 | $response = array(); |
620 | 620 | |
621 | - if ( isset( $_POST['code'] ) ) { |
|
622 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
621 | + if (isset($_POST['code'])) { |
|
622 | + $discount_code = sanitize_text_field($_POST['code']); |
|
623 | 623 | |
624 | 624 | $response['success'] = false; |
625 | 625 | $response['msg'] = ''; |
@@ -627,14 +627,14 @@ discard block |
||
627 | 627 | |
628 | 628 | $user = is_user_logged_in() ? get_current_user_id() : ''; |
629 | 629 | |
630 | - if ( wpinv_is_discount_valid( $discount_code, $user ) ) { |
|
631 | - $discount = wpinv_get_discount_by_code( $discount_code ); |
|
632 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
633 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) ); |
|
634 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
635 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
630 | + if (wpinv_is_discount_valid($discount_code, $user)) { |
|
631 | + $discount = wpinv_get_discount_by_code($discount_code); |
|
632 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
633 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID)); |
|
634 | + $total = wpinv_get_cart_total(null, $discounts); |
|
635 | + $cart_totals = wpinv_recalculate_tax(true); |
|
636 | 636 | |
637 | - if ( !empty( $cart_totals ) ) { |
|
637 | + if (!empty($cart_totals)) { |
|
638 | 638 | $response['success'] = true; |
639 | 639 | $response['data'] = $cart_totals; |
640 | 640 | $response['data']['code'] = $discount_code; |
@@ -643,29 +643,29 @@ discard block |
||
643 | 643 | } |
644 | 644 | } else { |
645 | 645 | $errors = wpinv_get_errors(); |
646 | - $response['msg'] = $errors['wpinv-discount-error']; |
|
647 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
646 | + $response['msg'] = $errors['wpinv-discount-error']; |
|
647 | + wpinv_unset_error('wpinv-discount-error'); |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | // Allow for custom discount code handling |
651 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
651 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
652 | 652 | } |
653 | 653 | |
654 | - wp_send_json( $response ); |
|
654 | + wp_send_json($response); |
|
655 | 655 | } |
656 | 656 | |
657 | 657 | public static function remove_discount() { |
658 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
658 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
659 | 659 | |
660 | 660 | $response = array(); |
661 | 661 | |
662 | - if ( isset( $_POST['code'] ) ) { |
|
663 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
664 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
665 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
666 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
662 | + if (isset($_POST['code'])) { |
|
663 | + $discount_code = sanitize_text_field($_POST['code']); |
|
664 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
665 | + $total = wpinv_get_cart_total(null, $discounts); |
|
666 | + $cart_totals = wpinv_recalculate_tax(true); |
|
667 | 667 | |
668 | - if ( !empty( $cart_totals ) ) { |
|
668 | + if (!empty($cart_totals)) { |
|
669 | 669 | $response['success'] = true; |
670 | 670 | $response['data'] = $cart_totals; |
671 | 671 | $response['data']['code'] = $discount_code; |
@@ -674,10 +674,10 @@ discard block |
||
674 | 674 | } |
675 | 675 | |
676 | 676 | // Allow for custom discount code handling |
677 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
677 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
678 | 678 | } |
679 | 679 | |
680 | - wp_send_json( $response ); |
|
680 | + wp_send_json($response); |
|
681 | 681 | } |
682 | 682 | } |
683 | 683 |
@@ -7,90 +7,90 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_get_discount_types() { |
15 | 15 | $discount_types = array( |
16 | - 'percent' => __( 'Percentage', 'invoicing' ), |
|
17 | - 'flat' => __( 'Flat Amount', 'invoicing' ), |
|
16 | + 'percent' => __('Percentage', 'invoicing'), |
|
17 | + 'flat' => __('Flat Amount', 'invoicing'), |
|
18 | 18 | ); |
19 | - return (array)apply_filters( 'wpinv_discount_types', $discount_types ); |
|
19 | + return (array)apply_filters('wpinv_discount_types', $discount_types); |
|
20 | 20 | } |
21 | 21 | |
22 | -function wpinv_get_discount_type_name( $type = '' ) { |
|
22 | +function wpinv_get_discount_type_name($type = '') { |
|
23 | 23 | $types = wpinv_get_discount_types(); |
24 | - return isset( $types[ $type ] ) ? $types[ $type ] : ''; |
|
24 | + return isset($types[$type]) ? $types[$type] : ''; |
|
25 | 25 | } |
26 | 26 | |
27 | -function wpinv_delete_discount( $data ) { |
|
28 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
29 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
27 | +function wpinv_delete_discount($data) { |
|
28 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
29 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
30 | 30 | } |
31 | 31 | |
32 | - if( ! current_user_can( 'manage_options' ) ) { |
|
33 | - wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
32 | + if (!current_user_can('manage_options')) { |
|
33 | + wp_die(__('You do not have permission to delete discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | $discount_id = $data['discount']; |
37 | - wpinv_remove_discount( $discount_id ); |
|
37 | + wpinv_remove_discount($discount_id); |
|
38 | 38 | } |
39 | -add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' ); |
|
39 | +add_action('wpinv_delete_discount', 'wpinv_delete_discount'); |
|
40 | 40 | |
41 | -function wpinv_activate_discount( $data ) { |
|
42 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
43 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
41 | +function wpinv_activate_discount($data) { |
|
42 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
43 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
44 | 44 | } |
45 | 45 | |
46 | - if( ! current_user_can( 'manage_options' ) ) { |
|
47 | - wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
46 | + if (!current_user_can('manage_options')) { |
|
47 | + wp_die(__('You do not have permission to edit discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
48 | 48 | } |
49 | 49 | |
50 | - $id = absint( $data['discount'] ); |
|
51 | - wpinv_update_discount_status( $id, 'publish' ); |
|
50 | + $id = absint($data['discount']); |
|
51 | + wpinv_update_discount_status($id, 'publish'); |
|
52 | 52 | } |
53 | -add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' ); |
|
53 | +add_action('wpinv_activate_discount', 'wpinv_activate_discount'); |
|
54 | 54 | |
55 | -function wpinv_deactivate_discount( $data ) { |
|
56 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
57 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
55 | +function wpinv_deactivate_discount($data) { |
|
56 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
57 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
58 | 58 | } |
59 | 59 | |
60 | - if( ! current_user_can( 'manage_options' ) ) { |
|
61 | - wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) ); |
|
60 | + if (!current_user_can('manage_options')) { |
|
61 | + wp_die(__('You do not have permission to create discount codes', 'invoicing'), array('response' => 403)); |
|
62 | 62 | } |
63 | 63 | |
64 | - $id = absint( $data['discount'] ); |
|
65 | - wpinv_update_discount_status( $id, 'pending' ); |
|
64 | + $id = absint($data['discount']); |
|
65 | + wpinv_update_discount_status($id, 'pending'); |
|
66 | 66 | } |
67 | -add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' ); |
|
67 | +add_action('wpinv_deactivate_discount', 'wpinv_deactivate_discount'); |
|
68 | 68 | |
69 | -function wpinv_get_discounts( $args = array() ) { |
|
69 | +function wpinv_get_discounts($args = array()) { |
|
70 | 70 | $defaults = array( |
71 | 71 | 'post_type' => 'wpi_discount', |
72 | 72 | 'posts_per_page' => 20, |
73 | 73 | 'paged' => null, |
74 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ) |
|
74 | + 'post_status' => array('publish', 'pending', 'draft', 'expired') |
|
75 | 75 | ); |
76 | 76 | |
77 | - $args = wp_parse_args( $args, $defaults ); |
|
77 | + $args = wp_parse_args($args, $defaults); |
|
78 | 78 | |
79 | - $discounts = get_posts( $args ); |
|
79 | + $discounts = get_posts($args); |
|
80 | 80 | |
81 | - if ( $discounts ) { |
|
81 | + if ($discounts) { |
|
82 | 82 | return $discounts; |
83 | 83 | } |
84 | 84 | |
85 | - if( ! $discounts && ! empty( $args['s'] ) ) { |
|
85 | + if (!$discounts && !empty($args['s'])) { |
|
86 | 86 | $args['meta_key'] = 'gd_discount_code'; |
87 | 87 | $args['meta_value'] = $args['s']; |
88 | 88 | $args['meta_compare'] = 'LIKE'; |
89 | - unset( $args['s'] ); |
|
90 | - $discounts = get_posts( $args ); |
|
89 | + unset($args['s']); |
|
90 | + $discounts = get_posts($args); |
|
91 | 91 | } |
92 | 92 | |
93 | - if( $discounts ) { |
|
93 | + if ($discounts) { |
|
94 | 94 | return $discounts; |
95 | 95 | } |
96 | 96 | |
@@ -102,9 +102,9 @@ discard block |
||
102 | 102 | |
103 | 103 | $discounts = wpinv_get_discounts(); |
104 | 104 | |
105 | - if ( $discounts) { |
|
106 | - foreach ( $discounts as $discount ) { |
|
107 | - if ( wpinv_is_discount_active( $discount->ID ) ) { |
|
105 | + if ($discounts) { |
|
106 | + foreach ($discounts as $discount) { |
|
107 | + if (wpinv_is_discount_active($discount->ID)) { |
|
108 | 108 | $has_active = true; |
109 | 109 | break; |
110 | 110 | } |
@@ -113,38 +113,38 @@ discard block |
||
113 | 113 | return $has_active; |
114 | 114 | } |
115 | 115 | |
116 | -function wpinv_get_discount( $discount_id = 0 ) { |
|
117 | - if( empty( $discount_id ) ) { |
|
116 | +function wpinv_get_discount($discount_id = 0) { |
|
117 | + if (empty($discount_id)) { |
|
118 | 118 | return false; |
119 | 119 | } |
120 | 120 | |
121 | - if ( get_post_type( $discount_id ) != 'wpi_discount' ) { |
|
121 | + if (get_post_type($discount_id) != 'wpi_discount') { |
|
122 | 122 | return false; |
123 | 123 | } |
124 | 124 | |
125 | - $discount = get_post( $discount_id ); |
|
125 | + $discount = get_post($discount_id); |
|
126 | 126 | |
127 | 127 | return $discount; |
128 | 128 | } |
129 | 129 | |
130 | -function wpinv_get_discount_by_code( $code = '' ) { |
|
131 | - if( empty( $code ) || ! is_string( $code ) ) { |
|
130 | +function wpinv_get_discount_by_code($code = '') { |
|
131 | + if (empty($code) || !is_string($code)) { |
|
132 | 132 | return false; |
133 | 133 | } |
134 | 134 | |
135 | - return wpinv_get_discount_by( 'code', $code ); |
|
135 | + return wpinv_get_discount_by('code', $code); |
|
136 | 136 | } |
137 | 137 | |
138 | -function wpinv_get_discount_by( $field = '', $value = '' ) { |
|
139 | - if( empty( $field ) || empty( $value ) ) { |
|
138 | +function wpinv_get_discount_by($field = '', $value = '') { |
|
139 | + if (empty($field) || empty($value)) { |
|
140 | 140 | return false; |
141 | 141 | } |
142 | 142 | |
143 | - if( ! is_string( $field ) ) { |
|
143 | + if (!is_string($field)) { |
|
144 | 144 | return false; |
145 | 145 | } |
146 | 146 | |
147 | - switch( strtolower( $field ) ) { |
|
147 | + switch (strtolower($field)) { |
|
148 | 148 | |
149 | 149 | case 'code': |
150 | 150 | $meta_query = array(); |
@@ -154,32 +154,32 @@ discard block |
||
154 | 154 | 'compare' => '=' |
155 | 155 | ); |
156 | 156 | |
157 | - $discount = wpinv_get_discounts( array( |
|
157 | + $discount = wpinv_get_discounts(array( |
|
158 | 158 | 'posts_per_page' => 1, |
159 | 159 | 'post_status' => 'any', |
160 | 160 | 'meta_query' => $meta_query, |
161 | - ) ); |
|
161 | + )); |
|
162 | 162 | |
163 | - if( $discount ) { |
|
163 | + if ($discount) { |
|
164 | 164 | $discount = $discount[0]; |
165 | 165 | } |
166 | 166 | |
167 | 167 | break; |
168 | 168 | |
169 | 169 | case 'id': |
170 | - $discount = wpinv_get_discount( $value ); |
|
170 | + $discount = wpinv_get_discount($value); |
|
171 | 171 | |
172 | 172 | break; |
173 | 173 | |
174 | 174 | case 'name': |
175 | - $discount = get_posts( array( |
|
175 | + $discount = get_posts(array( |
|
176 | 176 | 'post_type' => 'wpi_discount', |
177 | 177 | 'name' => $value, |
178 | 178 | 'posts_per_page' => 1, |
179 | 179 | 'post_status' => 'any' |
180 | - ) ); |
|
180 | + )); |
|
181 | 181 | |
182 | - if( $discount ) { |
|
182 | + if ($discount) { |
|
183 | 183 | $discount = $discount[0]; |
184 | 184 | } |
185 | 185 | |
@@ -189,99 +189,99 @@ discard block |
||
189 | 189 | return false; |
190 | 190 | } |
191 | 191 | |
192 | - if( ! empty( $discount ) ) { |
|
192 | + if (!empty($discount)) { |
|
193 | 193 | return $discount; |
194 | 194 | } |
195 | 195 | |
196 | 196 | return false; |
197 | 197 | } |
198 | 198 | |
199 | -function wpinv_store_discount( $post_id, $data, $post, $update = false ) { |
|
199 | +function wpinv_store_discount($post_id, $data, $post, $update = false) { |
|
200 | 200 | $meta = array( |
201 | - 'code' => isset( $data['code'] ) ? sanitize_text_field( $data['code'] ) : '', |
|
202 | - 'type' => isset( $data['type'] ) ? sanitize_text_field( $data['type'] ) : 'percent', |
|
203 | - 'amount' => isset( $data['amount'] ) ? wpinv_sanitize_amount( $data['amount'] ) : '', |
|
204 | - 'start' => isset( $data['start'] ) ? sanitize_text_field( $data['start'] ) : '', |
|
205 | - 'expiration' => isset( $data['expiration'] ) ? sanitize_text_field( $data['expiration'] ) : '', |
|
206 | - 'min_total' => isset( $data['min_total'] ) ? wpinv_sanitize_amount( $data['min_total'] ) : '', |
|
207 | - 'max_total' => isset( $data['max_total'] ) ? wpinv_sanitize_amount( $data['max_total'] ) : '', |
|
208 | - 'max_uses' => isset( $data['max_uses'] ) ? absint( $data['max_uses'] ) : '', |
|
209 | - 'items' => isset( $data['items'] ) ? $data['items'] : array(), |
|
210 | - 'excluded_items' => isset( $data['excluded_items'] ) ? $data['excluded_items'] : array(), |
|
211 | - 'is_recurring' => isset( $data['recurring'] ) ? (bool)$data['recurring'] : false, |
|
212 | - 'is_single_use' => isset( $data['single_use'] ) ? (bool)$data['single_use'] : false, |
|
213 | - 'uses' => isset( $data['uses'] ) ? (int)$data['uses'] : false, |
|
201 | + 'code' => isset($data['code']) ? sanitize_text_field($data['code']) : '', |
|
202 | + 'type' => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent', |
|
203 | + 'amount' => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '', |
|
204 | + 'start' => isset($data['start']) ? sanitize_text_field($data['start']) : '', |
|
205 | + 'expiration' => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '', |
|
206 | + 'min_total' => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '', |
|
207 | + 'max_total' => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '', |
|
208 | + 'max_uses' => isset($data['max_uses']) ? absint($data['max_uses']) : '', |
|
209 | + 'items' => isset($data['items']) ? $data['items'] : array(), |
|
210 | + 'excluded_items' => isset($data['excluded_items']) ? $data['excluded_items'] : array(), |
|
211 | + 'is_recurring' => isset($data['recurring']) ? (bool)$data['recurring'] : false, |
|
212 | + 'is_single_use' => isset($data['single_use']) ? (bool)$data['single_use'] : false, |
|
213 | + 'uses' => isset($data['uses']) ? (int)$data['uses'] : false, |
|
214 | 214 | ); |
215 | 215 | |
216 | - $start_timestamp = strtotime( $meta['start'] ); |
|
216 | + $start_timestamp = strtotime($meta['start']); |
|
217 | 217 | |
218 | - if ( !empty( $meta['start'] ) ) { |
|
219 | - $meta['start'] = date( 'Y-m-d H:i:s', $start_timestamp ); |
|
218 | + if (!empty($meta['start'])) { |
|
219 | + $meta['start'] = date('Y-m-d H:i:s', $start_timestamp); |
|
220 | 220 | } |
221 | 221 | |
222 | - if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) { |
|
222 | + if ($meta['type'] == 'percent' && (float)$meta['amount'] > 100) { |
|
223 | 223 | $meta['amount'] = 100; |
224 | 224 | } |
225 | 225 | |
226 | - if ( !empty( $meta['expiration'] ) ) { |
|
227 | - $meta['expiration'] = date( 'Y-m-d H:i:s', strtotime( date( 'Y-m-d', strtotime( $meta['expiration'] ) ) . ' 23:59:59' ) ); |
|
228 | - $end_timestamp = strtotime( $meta['expiration'] ); |
|
226 | + if (!empty($meta['expiration'])) { |
|
227 | + $meta['expiration'] = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime($meta['expiration'])) . ' 23:59:59')); |
|
228 | + $end_timestamp = strtotime($meta['expiration']); |
|
229 | 229 | |
230 | - if ( !empty( $meta['start'] ) && $start_timestamp > $end_timestamp ) { |
|
230 | + if (!empty($meta['start']) && $start_timestamp > $end_timestamp) { |
|
231 | 231 | $meta['expiration'] = $meta['start']; // Set the expiration date to the start date if start is later than expiration date. |
232 | 232 | } |
233 | 233 | } |
234 | 234 | |
235 | - if ( $meta['uses'] === false ) { |
|
236 | - unset( $meta['uses'] ); |
|
235 | + if ($meta['uses'] === false) { |
|
236 | + unset($meta['uses']); |
|
237 | 237 | } |
238 | 238 | |
239 | - if ( ! empty( $meta['items'] ) ) { |
|
240 | - foreach ( $meta['items'] as $key => $item ) { |
|
241 | - if ( 0 === intval( $item ) ) { |
|
242 | - unset( $meta['items'][ $key ] ); |
|
239 | + if (!empty($meta['items'])) { |
|
240 | + foreach ($meta['items'] as $key => $item) { |
|
241 | + if (0 === intval($item)) { |
|
242 | + unset($meta['items'][$key]); |
|
243 | 243 | } |
244 | 244 | } |
245 | 245 | } |
246 | 246 | |
247 | - if ( ! empty( $meta['excluded_items'] ) ) { |
|
248 | - foreach ( $meta['excluded_items'] as $key => $item ) { |
|
249 | - if ( 0 === intval( $item ) ) { |
|
250 | - unset( $meta['excluded_items'][ $key ] ); |
|
247 | + if (!empty($meta['excluded_items'])) { |
|
248 | + foreach ($meta['excluded_items'] as $key => $item) { |
|
249 | + if (0 === intval($item)) { |
|
250 | + unset($meta['excluded_items'][$key]); |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 | } |
254 | 254 | |
255 | - $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post ); |
|
255 | + $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post); |
|
256 | 256 | |
257 | - do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post ); |
|
257 | + do_action('wpinv_pre_update_discount', $meta, $post_id, $post); |
|
258 | 258 | |
259 | - foreach( $meta as $key => $value ) { |
|
260 | - update_post_meta( $post_id, '_wpi_discount_' . $key, $value ); |
|
259 | + foreach ($meta as $key => $value) { |
|
260 | + update_post_meta($post_id, '_wpi_discount_' . $key, $value); |
|
261 | 261 | } |
262 | 262 | |
263 | - do_action( 'wpinv_post_update_discount', $meta, $post_id, $post ); |
|
263 | + do_action('wpinv_post_update_discount', $meta, $post_id, $post); |
|
264 | 264 | |
265 | 265 | return $post_id; |
266 | 266 | } |
267 | 267 | |
268 | -function wpinv_remove_discount( $discount_id = 0 ) { |
|
269 | - do_action( 'wpinv_pre_delete_discount', $discount_id ); |
|
268 | +function wpinv_remove_discount($discount_id = 0) { |
|
269 | + do_action('wpinv_pre_delete_discount', $discount_id); |
|
270 | 270 | |
271 | - wp_delete_post( $discount_id, true ); |
|
271 | + wp_delete_post($discount_id, true); |
|
272 | 272 | |
273 | - do_action( 'wpinv_post_delete_discount', $discount_id ); |
|
273 | + do_action('wpinv_post_delete_discount', $discount_id); |
|
274 | 274 | } |
275 | 275 | |
276 | -function wpinv_update_discount_status( $code_id = 0, $new_status = 'publish' ) { |
|
277 | - $discount = wpinv_get_discount( $code_id ); |
|
276 | +function wpinv_update_discount_status($code_id = 0, $new_status = 'publish') { |
|
277 | + $discount = wpinv_get_discount($code_id); |
|
278 | 278 | |
279 | - if ( $discount ) { |
|
280 | - do_action( 'wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status ); |
|
279 | + if ($discount) { |
|
280 | + do_action('wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status); |
|
281 | 281 | |
282 | - wp_update_post( array( 'ID' => $code_id, 'post_status' => $new_status ) ); |
|
282 | + wp_update_post(array('ID' => $code_id, 'post_status' => $new_status)); |
|
283 | 283 | |
284 | - do_action( 'wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status ); |
|
284 | + do_action('wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status); |
|
285 | 285 | |
286 | 286 | return true; |
287 | 287 | } |
@@ -289,173 +289,173 @@ discard block |
||
289 | 289 | return false; |
290 | 290 | } |
291 | 291 | |
292 | -function wpinv_discount_exists( $code_id ) { |
|
293 | - if ( wpinv_get_discount( $code_id ) ) { |
|
292 | +function wpinv_discount_exists($code_id) { |
|
293 | + if (wpinv_get_discount($code_id)) { |
|
294 | 294 | return true; |
295 | 295 | } |
296 | 296 | |
297 | 297 | return false; |
298 | 298 | } |
299 | 299 | |
300 | -function wpinv_is_discount_active( $code_id = null ) { |
|
301 | - $discount = wpinv_get_discount( $code_id ); |
|
300 | +function wpinv_is_discount_active($code_id = null) { |
|
301 | + $discount = wpinv_get_discount($code_id); |
|
302 | 302 | $return = false; |
303 | 303 | |
304 | - if ( $discount ) { |
|
305 | - if ( wpinv_is_discount_expired( $code_id ) ) { |
|
306 | - if( defined( 'DOING_AJAX' ) ) { |
|
307 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) ); |
|
304 | + if ($discount) { |
|
305 | + if (wpinv_is_discount_expired($code_id)) { |
|
306 | + if (defined('DOING_AJAX')) { |
|
307 | + wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing')); |
|
308 | 308 | } |
309 | - } elseif ( $discount->post_status == 'publish' ) { |
|
309 | + } elseif ($discount->post_status == 'publish') { |
|
310 | 310 | $return = true; |
311 | 311 | } else { |
312 | - if( defined( 'DOING_AJAX' ) ) { |
|
313 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) ); |
|
312 | + if (defined('DOING_AJAX')) { |
|
313 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing')); |
|
314 | 314 | } |
315 | 315 | } |
316 | 316 | } |
317 | 317 | |
318 | - return apply_filters( 'wpinv_is_discount_active', $return, $code_id ); |
|
318 | + return apply_filters('wpinv_is_discount_active', $return, $code_id); |
|
319 | 319 | } |
320 | 320 | |
321 | -function wpinv_get_discount_code( $code_id = null ) { |
|
322 | - $code = get_post_meta( $code_id, '_wpi_discount_code', true ); |
|
321 | +function wpinv_get_discount_code($code_id = null) { |
|
322 | + $code = get_post_meta($code_id, '_wpi_discount_code', true); |
|
323 | 323 | |
324 | - return apply_filters( 'wpinv_get_discount_code', $code, $code_id ); |
|
324 | + return apply_filters('wpinv_get_discount_code', $code, $code_id); |
|
325 | 325 | } |
326 | 326 | |
327 | -function wpinv_get_discount_start_date( $code_id = null ) { |
|
328 | - $start_date = get_post_meta( $code_id, '_wpi_discount_start', true ); |
|
327 | +function wpinv_get_discount_start_date($code_id = null) { |
|
328 | + $start_date = get_post_meta($code_id, '_wpi_discount_start', true); |
|
329 | 329 | |
330 | - return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id ); |
|
330 | + return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id); |
|
331 | 331 | } |
332 | 332 | |
333 | -function wpinv_get_discount_expiration( $code_id = null ) { |
|
334 | - $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true ); |
|
333 | +function wpinv_get_discount_expiration($code_id = null) { |
|
334 | + $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true); |
|
335 | 335 | |
336 | - return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id ); |
|
336 | + return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id); |
|
337 | 337 | } |
338 | 338 | |
339 | -function wpinv_get_discount_max_uses( $code_id = null ) { |
|
340 | - $max_uses = get_post_meta( $code_id, '_wpi_discount_max_uses', true ); |
|
339 | +function wpinv_get_discount_max_uses($code_id = null) { |
|
340 | + $max_uses = get_post_meta($code_id, '_wpi_discount_max_uses', true); |
|
341 | 341 | |
342 | - return (int) apply_filters( 'wpinv_get_discount_max_uses', $max_uses, $code_id ); |
|
342 | + return (int)apply_filters('wpinv_get_discount_max_uses', $max_uses, $code_id); |
|
343 | 343 | } |
344 | 344 | |
345 | -function wpinv_get_discount_uses( $code_id = null ) { |
|
346 | - $uses = get_post_meta( $code_id, '_wpi_discount_uses', true ); |
|
345 | +function wpinv_get_discount_uses($code_id = null) { |
|
346 | + $uses = get_post_meta($code_id, '_wpi_discount_uses', true); |
|
347 | 347 | |
348 | - return (int) apply_filters( 'wpinv_get_discount_uses', $uses, $code_id ); |
|
348 | + return (int)apply_filters('wpinv_get_discount_uses', $uses, $code_id); |
|
349 | 349 | } |
350 | 350 | |
351 | -function wpinv_get_discount_min_total( $code_id = null ) { |
|
352 | - $min_total = get_post_meta( $code_id, '_wpi_discount_min_total', true ); |
|
351 | +function wpinv_get_discount_min_total($code_id = null) { |
|
352 | + $min_total = get_post_meta($code_id, '_wpi_discount_min_total', true); |
|
353 | 353 | |
354 | - return (float) apply_filters( 'wpinv_get_discount_min_total', $min_total, $code_id ); |
|
354 | + return (float)apply_filters('wpinv_get_discount_min_total', $min_total, $code_id); |
|
355 | 355 | } |
356 | 356 | |
357 | -function wpinv_get_discount_max_total( $code_id = null ) { |
|
358 | - $max_total = get_post_meta( $code_id, '_wpi_discount_max_total', true ); |
|
357 | +function wpinv_get_discount_max_total($code_id = null) { |
|
358 | + $max_total = get_post_meta($code_id, '_wpi_discount_max_total', true); |
|
359 | 359 | |
360 | - return (float) apply_filters( 'wpinv_get_discount_max_total', $max_total, $code_id ); |
|
360 | + return (float)apply_filters('wpinv_get_discount_max_total', $max_total, $code_id); |
|
361 | 361 | } |
362 | 362 | |
363 | -function wpinv_get_discount_amount( $code_id = null ) { |
|
364 | - $amount = get_post_meta( $code_id, '_wpi_discount_amount', true ); |
|
363 | +function wpinv_get_discount_amount($code_id = null) { |
|
364 | + $amount = get_post_meta($code_id, '_wpi_discount_amount', true); |
|
365 | 365 | |
366 | - return (float) apply_filters( 'wpinv_get_discount_amount', $amount, $code_id ); |
|
366 | + return (float)apply_filters('wpinv_get_discount_amount', $amount, $code_id); |
|
367 | 367 | } |
368 | 368 | |
369 | -function wpinv_get_discount_type( $code_id = null, $name = false ) { |
|
370 | - $type = strtolower( get_post_meta( $code_id, '_wpi_discount_type', true ) ); |
|
369 | +function wpinv_get_discount_type($code_id = null, $name = false) { |
|
370 | + $type = strtolower(get_post_meta($code_id, '_wpi_discount_type', true)); |
|
371 | 371 | |
372 | - if ( $name ) { |
|
373 | - $name = wpinv_get_discount_type_name( $type ); |
|
372 | + if ($name) { |
|
373 | + $name = wpinv_get_discount_type_name($type); |
|
374 | 374 | |
375 | - return apply_filters( 'wpinv_get_discount_type_name', $name, $code_id ); |
|
375 | + return apply_filters('wpinv_get_discount_type_name', $name, $code_id); |
|
376 | 376 | } |
377 | 377 | |
378 | - return apply_filters( 'wpinv_get_discount_type', $type, $code_id ); |
|
378 | + return apply_filters('wpinv_get_discount_type', $type, $code_id); |
|
379 | 379 | } |
380 | 380 | |
381 | -function wpinv_discount_status( $status ) { |
|
382 | - switch( $status ){ |
|
381 | +function wpinv_discount_status($status) { |
|
382 | + switch ($status) { |
|
383 | 383 | case 'expired' : |
384 | - $name = __( 'Expired', 'invoicing' ); |
|
384 | + $name = __('Expired', 'invoicing'); |
|
385 | 385 | break; |
386 | 386 | case 'publish' : |
387 | 387 | case 'active' : |
388 | - $name = __( 'Active', 'invoicing' ); |
|
388 | + $name = __('Active', 'invoicing'); |
|
389 | 389 | break; |
390 | 390 | default : |
391 | - $name = __( 'Inactive', 'invoicing' ); |
|
391 | + $name = __('Inactive', 'invoicing'); |
|
392 | 392 | break; |
393 | 393 | } |
394 | 394 | return $name; |
395 | 395 | } |
396 | 396 | |
397 | -function wpinv_get_discount_excluded_items( $code_id = null ) { |
|
398 | - $excluded_items = get_post_meta( $code_id, '_wpi_discount_excluded_items', true ); |
|
397 | +function wpinv_get_discount_excluded_items($code_id = null) { |
|
398 | + $excluded_items = get_post_meta($code_id, '_wpi_discount_excluded_items', true); |
|
399 | 399 | |
400 | - if ( empty( $excluded_items ) || ! is_array( $excluded_items ) ) { |
|
400 | + if (empty($excluded_items) || !is_array($excluded_items)) { |
|
401 | 401 | $excluded_items = array(); |
402 | 402 | } |
403 | 403 | |
404 | - return (array) apply_filters( 'wpinv_get_discount_excluded_items', $excluded_items, $code_id ); |
|
404 | + return (array)apply_filters('wpinv_get_discount_excluded_items', $excluded_items, $code_id); |
|
405 | 405 | } |
406 | 406 | |
407 | -function wpinv_get_discount_item_reqs( $code_id = null ) { |
|
408 | - $item_reqs = get_post_meta( $code_id, '_wpi_discount_items', true ); |
|
407 | +function wpinv_get_discount_item_reqs($code_id = null) { |
|
408 | + $item_reqs = get_post_meta($code_id, '_wpi_discount_items', true); |
|
409 | 409 | |
410 | - if ( empty( $item_reqs ) || ! is_array( $item_reqs ) ) { |
|
410 | + if (empty($item_reqs) || !is_array($item_reqs)) { |
|
411 | 411 | $item_reqs = array(); |
412 | 412 | } |
413 | 413 | |
414 | - return (array) apply_filters( 'wpinv_get_discount_item_reqs', $item_reqs, $code_id ); |
|
414 | + return (array)apply_filters('wpinv_get_discount_item_reqs', $item_reqs, $code_id); |
|
415 | 415 | } |
416 | 416 | |
417 | -function wpinv_get_discount_item_condition( $code_id = 0 ) { |
|
418 | - return get_post_meta( $code_id, '_wpi_discount_item_condition', true ); |
|
417 | +function wpinv_get_discount_item_condition($code_id = 0) { |
|
418 | + return get_post_meta($code_id, '_wpi_discount_item_condition', true); |
|
419 | 419 | } |
420 | 420 | |
421 | -function wpinv_is_discount_not_global( $code_id = 0 ) { |
|
422 | - return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true ); |
|
421 | +function wpinv_is_discount_not_global($code_id = 0) { |
|
422 | + return (bool)get_post_meta($code_id, '_wpi_discount_is_not_global', true); |
|
423 | 423 | } |
424 | 424 | |
425 | -function wpinv_is_discount_expired( $code_id = null ) { |
|
426 | - $discount = wpinv_get_discount( $code_id ); |
|
425 | +function wpinv_is_discount_expired($code_id = null) { |
|
426 | + $discount = wpinv_get_discount($code_id); |
|
427 | 427 | $return = false; |
428 | 428 | |
429 | - if ( $discount ) { |
|
430 | - $expiration = wpinv_get_discount_expiration( $code_id ); |
|
431 | - if ( $expiration ) { |
|
432 | - $expiration = strtotime( $expiration ); |
|
433 | - if ( $expiration < current_time( 'timestamp' ) ) { |
|
429 | + if ($discount) { |
|
430 | + $expiration = wpinv_get_discount_expiration($code_id); |
|
431 | + if ($expiration) { |
|
432 | + $expiration = strtotime($expiration); |
|
433 | + if ($expiration < current_time('timestamp')) { |
|
434 | 434 | // Discount is expired |
435 | - wpinv_update_discount_status( $code_id, 'pending' ); |
|
435 | + wpinv_update_discount_status($code_id, 'pending'); |
|
436 | 436 | $return = true; |
437 | 437 | } |
438 | 438 | } |
439 | 439 | } |
440 | 440 | |
441 | - return apply_filters( 'wpinv_is_discount_expired', $return, $code_id ); |
|
441 | + return apply_filters('wpinv_is_discount_expired', $return, $code_id); |
|
442 | 442 | } |
443 | 443 | |
444 | -function wpinv_is_discount_started( $code_id = null ) { |
|
445 | - $discount = wpinv_get_discount( $code_id ); |
|
444 | +function wpinv_is_discount_started($code_id = null) { |
|
445 | + $discount = wpinv_get_discount($code_id); |
|
446 | 446 | $return = false; |
447 | 447 | |
448 | - if ( $discount ) { |
|
449 | - $start_date = wpinv_get_discount_start_date( $code_id ); |
|
448 | + if ($discount) { |
|
449 | + $start_date = wpinv_get_discount_start_date($code_id); |
|
450 | 450 | |
451 | - if ( $start_date ) { |
|
452 | - $start_date = strtotime( $start_date ); |
|
451 | + if ($start_date) { |
|
452 | + $start_date = strtotime($start_date); |
|
453 | 453 | |
454 | - if ( $start_date < current_time( 'timestamp' ) ) { |
|
454 | + if ($start_date < current_time('timestamp')) { |
|
455 | 455 | // Discount has past the start date |
456 | 456 | $return = true; |
457 | 457 | } else { |
458 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) ); |
|
458 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing')); |
|
459 | 459 | } |
460 | 460 | } else { |
461 | 461 | // No start date for this discount, so has to be true |
@@ -463,159 +463,159 @@ discard block |
||
463 | 463 | } |
464 | 464 | } |
465 | 465 | |
466 | - return apply_filters( 'wpinv_is_discount_started', $return, $code_id ); |
|
466 | + return apply_filters('wpinv_is_discount_started', $return, $code_id); |
|
467 | 467 | } |
468 | 468 | |
469 | -function wpinv_check_discount_dates( $code_id = null ) { |
|
470 | - $discount = wpinv_get_discount( $code_id ); |
|
469 | +function wpinv_check_discount_dates($code_id = null) { |
|
470 | + $discount = wpinv_get_discount($code_id); |
|
471 | 471 | $return = false; |
472 | 472 | |
473 | - if ( $discount ) { |
|
474 | - $start_date = wpinv_get_discount_start_date( $code_id ); |
|
473 | + if ($discount) { |
|
474 | + $start_date = wpinv_get_discount_start_date($code_id); |
|
475 | 475 | |
476 | - if ( $start_date ) { |
|
477 | - $start_date = strtotime( $start_date ); |
|
476 | + if ($start_date) { |
|
477 | + $start_date = strtotime($start_date); |
|
478 | 478 | |
479 | - if ( $start_date < current_time( 'timestamp' ) ) { |
|
479 | + if ($start_date < current_time('timestamp')) { |
|
480 | 480 | // Discount has past the start date |
481 | 481 | $return = true; |
482 | 482 | } else { |
483 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) ); |
|
483 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing')); |
|
484 | 484 | } |
485 | 485 | } else { |
486 | 486 | // No start date for this discount, so has to be true |
487 | 487 | $return = true; |
488 | 488 | } |
489 | 489 | |
490 | - if ( $return ) { |
|
491 | - $expiration = wpinv_get_discount_expiration( $code_id ); |
|
490 | + if ($return) { |
|
491 | + $expiration = wpinv_get_discount_expiration($code_id); |
|
492 | 492 | |
493 | - if ( $expiration ) { |
|
494 | - $expiration = strtotime( $expiration ); |
|
495 | - if ( $expiration < current_time( 'timestamp' ) ) { |
|
493 | + if ($expiration) { |
|
494 | + $expiration = strtotime($expiration); |
|
495 | + if ($expiration < current_time('timestamp')) { |
|
496 | 496 | // Discount is expired |
497 | - wpinv_update_discount_status( $code_id, 'pending' ); |
|
497 | + wpinv_update_discount_status($code_id, 'pending'); |
|
498 | 498 | $return = true; |
499 | 499 | } |
500 | 500 | } |
501 | 501 | } |
502 | 502 | } |
503 | 503 | |
504 | - return apply_filters( 'wpinv_check_discount_dates', $return, $code_id ); |
|
504 | + return apply_filters('wpinv_check_discount_dates', $return, $code_id); |
|
505 | 505 | } |
506 | 506 | |
507 | -function wpinv_is_discount_maxed_out( $code_id = null ) { |
|
508 | - $discount = wpinv_get_discount( $code_id ); |
|
507 | +function wpinv_is_discount_maxed_out($code_id = null) { |
|
508 | + $discount = wpinv_get_discount($code_id); |
|
509 | 509 | $return = false; |
510 | 510 | |
511 | - if ( $discount ) { |
|
512 | - $uses = wpinv_get_discount_uses( $code_id ); |
|
511 | + if ($discount) { |
|
512 | + $uses = wpinv_get_discount_uses($code_id); |
|
513 | 513 | // Large number that will never be reached |
514 | - $max_uses = wpinv_get_discount_max_uses( $code_id ); |
|
514 | + $max_uses = wpinv_get_discount_max_uses($code_id); |
|
515 | 515 | // Should never be greater than, but just in case |
516 | - if ( $uses >= $max_uses && ! empty( $max_uses ) ) { |
|
516 | + if ($uses >= $max_uses && !empty($max_uses)) { |
|
517 | 517 | // Discount is maxed out |
518 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) ); |
|
518 | + wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing')); |
|
519 | 519 | $return = true; |
520 | 520 | } |
521 | 521 | } |
522 | 522 | |
523 | - return apply_filters( 'wpinv_is_discount_maxed_out', $return, $code_id ); |
|
523 | + return apply_filters('wpinv_is_discount_maxed_out', $return, $code_id); |
|
524 | 524 | } |
525 | 525 | |
526 | -function wpinv_discount_is_min_met( $code_id = null ) { |
|
527 | - $discount = wpinv_get_discount( $code_id ); |
|
526 | +function wpinv_discount_is_min_met($code_id = null) { |
|
527 | + $discount = wpinv_get_discount($code_id); |
|
528 | 528 | $return = false; |
529 | 529 | |
530 | - if ( $discount ) { |
|
531 | - $min = (float)wpinv_get_discount_min_total( $code_id ); |
|
532 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id ); |
|
530 | + if ($discount) { |
|
531 | + $min = (float)wpinv_get_discount_min_total($code_id); |
|
532 | + $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id); |
|
533 | 533 | |
534 | - if ( !$min > 0 || $cart_amount >= $min ) { |
|
534 | + if (!$min > 0 || $cart_amount >= $min) { |
|
535 | 535 | // Minimum has been met |
536 | 536 | $return = true; |
537 | 537 | } else { |
538 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $min ) ) ) ); |
|
538 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($min)))); |
|
539 | 539 | } |
540 | 540 | } |
541 | 541 | |
542 | - return apply_filters( 'wpinv_is_discount_min_met', $return, $code_id ); |
|
542 | + return apply_filters('wpinv_is_discount_min_met', $return, $code_id); |
|
543 | 543 | } |
544 | 544 | |
545 | -function wpinv_discount_is_max_met( $code_id = null ) { |
|
546 | - $discount = wpinv_get_discount( $code_id ); |
|
545 | +function wpinv_discount_is_max_met($code_id = null) { |
|
546 | + $discount = wpinv_get_discount($code_id); |
|
547 | 547 | $return = false; |
548 | 548 | |
549 | - if ( $discount ) { |
|
550 | - $max = (float)wpinv_get_discount_max_total( $code_id ); |
|
551 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id ); |
|
549 | + if ($discount) { |
|
550 | + $max = (float)wpinv_get_discount_max_total($code_id); |
|
551 | + $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id); |
|
552 | 552 | |
553 | - if ( !$max > 0 || $cart_amount <= $max ) { |
|
553 | + if (!$max > 0 || $cart_amount <= $max) { |
|
554 | 554 | // Minimum has been met |
555 | 555 | $return = true; |
556 | 556 | } else { |
557 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $max ) ) ) ); |
|
557 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($max)))); |
|
558 | 558 | } |
559 | 559 | } |
560 | 560 | |
561 | - return apply_filters( 'wpinv_is_discount_max_met', $return, $code_id ); |
|
561 | + return apply_filters('wpinv_is_discount_max_met', $return, $code_id); |
|
562 | 562 | } |
563 | 563 | |
564 | -function wpinv_discount_is_single_use( $code_id = 0 ) { |
|
565 | - $single_use = get_post_meta( $code_id, '_wpi_discount_is_single_use', true ); |
|
566 | - return (bool) apply_filters( 'wpinv_is_discount_single_use', $single_use, $code_id ); |
|
564 | +function wpinv_discount_is_single_use($code_id = 0) { |
|
565 | + $single_use = get_post_meta($code_id, '_wpi_discount_is_single_use', true); |
|
566 | + return (bool)apply_filters('wpinv_is_discount_single_use', $single_use, $code_id); |
|
567 | 567 | } |
568 | 568 | |
569 | -function wpinv_discount_is_recurring( $code_id = 0, $code = false ) { |
|
570 | - if ( $code ) { |
|
571 | - $discount = wpinv_get_discount_by_code( $code_id ); |
|
569 | +function wpinv_discount_is_recurring($code_id = 0, $code = false) { |
|
570 | + if ($code) { |
|
571 | + $discount = wpinv_get_discount_by_code($code_id); |
|
572 | 572 | |
573 | - if ( !empty( $discount ) ) { |
|
573 | + if (!empty($discount)) { |
|
574 | 574 | $code_id = $discount->ID; |
575 | 575 | } |
576 | 576 | } |
577 | 577 | |
578 | - $recurring = get_post_meta( $code_id, '_wpi_discount_is_recurring', true ); |
|
578 | + $recurring = get_post_meta($code_id, '_wpi_discount_is_recurring', true); |
|
579 | 579 | |
580 | - return (bool) apply_filters( 'wpinv_is_discount_recurring', $recurring, $code_id, $code ); |
|
580 | + return (bool)apply_filters('wpinv_is_discount_recurring', $recurring, $code_id, $code); |
|
581 | 581 | } |
582 | 582 | |
583 | -function wpinv_discount_item_reqs_met( $code_id = null ) { |
|
584 | - $item_reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
585 | - $condition = wpinv_get_discount_item_condition( $code_id ); |
|
586 | - $excluded_ps = wpinv_get_discount_excluded_items( $code_id ); |
|
583 | +function wpinv_discount_item_reqs_met($code_id = null) { |
|
584 | + $item_reqs = wpinv_get_discount_item_reqs($code_id); |
|
585 | + $condition = wpinv_get_discount_item_condition($code_id); |
|
586 | + $excluded_ps = wpinv_get_discount_excluded_items($code_id); |
|
587 | 587 | $cart_items = wpinv_get_cart_contents(); |
588 | - $cart_ids = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null; |
|
588 | + $cart_ids = $cart_items ? wp_list_pluck($cart_items, 'id') : null; |
|
589 | 589 | $ret = false; |
590 | 590 | |
591 | - if ( empty( $item_reqs ) && empty( $excluded_ps ) ) { |
|
591 | + if (empty($item_reqs) && empty($excluded_ps)) { |
|
592 | 592 | $ret = true; |
593 | 593 | } |
594 | 594 | |
595 | 595 | // Normalize our data for item requirements, exclusions and cart data |
596 | 596 | // First absint the items, then sort, and reset the array keys |
597 | - $item_reqs = array_map( 'absint', $item_reqs ); |
|
598 | - asort( $item_reqs ); |
|
599 | - $item_reqs = array_values( $item_reqs ); |
|
597 | + $item_reqs = array_map('absint', $item_reqs); |
|
598 | + asort($item_reqs); |
|
599 | + $item_reqs = array_values($item_reqs); |
|
600 | 600 | |
601 | - $excluded_ps = array_map( 'absint', $excluded_ps ); |
|
602 | - asort( $excluded_ps ); |
|
603 | - $excluded_ps = array_values( $excluded_ps ); |
|
601 | + $excluded_ps = array_map('absint', $excluded_ps); |
|
602 | + asort($excluded_ps); |
|
603 | + $excluded_ps = array_values($excluded_ps); |
|
604 | 604 | |
605 | - $cart_ids = array_map( 'absint', $cart_ids ); |
|
606 | - asort( $cart_ids ); |
|
607 | - $cart_ids = array_values( $cart_ids ); |
|
605 | + $cart_ids = array_map('absint', $cart_ids); |
|
606 | + asort($cart_ids); |
|
607 | + $cart_ids = array_values($cart_ids); |
|
608 | 608 | |
609 | 609 | // Ensure we have requirements before proceeding |
610 | - if ( !$ret && ! empty( $item_reqs ) ) { |
|
611 | - switch( $condition ) { |
|
610 | + if (!$ret && !empty($item_reqs)) { |
|
611 | + switch ($condition) { |
|
612 | 612 | case 'all' : |
613 | 613 | // Default back to true |
614 | 614 | $ret = true; |
615 | 615 | |
616 | - foreach ( $item_reqs as $item_id ) { |
|
617 | - if ( !wpinv_item_in_cart( $item_id ) ) { |
|
618 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
616 | + foreach ($item_reqs as $item_id) { |
|
617 | + if (!wpinv_item_in_cart($item_id)) { |
|
618 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
619 | 619 | $ret = false; |
620 | 620 | break; |
621 | 621 | } |
@@ -624,15 +624,15 @@ discard block |
||
624 | 624 | break; |
625 | 625 | |
626 | 626 | default : // Any |
627 | - foreach ( $item_reqs as $item_id ) { |
|
628 | - if ( wpinv_item_in_cart( $item_id ) ) { |
|
627 | + foreach ($item_reqs as $item_id) { |
|
628 | + if (wpinv_item_in_cart($item_id)) { |
|
629 | 629 | $ret = true; |
630 | 630 | break; |
631 | 631 | } |
632 | 632 | } |
633 | 633 | |
634 | - if( ! $ret ) { |
|
635 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
634 | + if (!$ret) { |
|
635 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | break; |
@@ -641,68 +641,68 @@ discard block |
||
641 | 641 | $ret = true; |
642 | 642 | } |
643 | 643 | |
644 | - if( ! empty( $excluded_ps ) ) { |
|
644 | + if (!empty($excluded_ps)) { |
|
645 | 645 | // Check that there are items other than excluded ones in the cart |
646 | - if( $cart_ids == $excluded_ps ) { |
|
647 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) ); |
|
646 | + if ($cart_ids == $excluded_ps) { |
|
647 | + wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing')); |
|
648 | 648 | $ret = false; |
649 | 649 | } |
650 | 650 | } |
651 | 651 | |
652 | - return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition ); |
|
652 | + return (bool)apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition); |
|
653 | 653 | } |
654 | 654 | |
655 | -function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) { |
|
655 | +function wpinv_is_discount_used($code = null, $user = '', $code_id = 0) { |
|
656 | 656 | global $wpi_checkout_id; |
657 | 657 | |
658 | 658 | $return = false; |
659 | 659 | |
660 | - if ( empty( $code_id ) ) { |
|
661 | - $code_id = wpinv_get_discount_id_by_code( $code ); |
|
660 | + if (empty($code_id)) { |
|
661 | + $code_id = wpinv_get_discount_id_by_code($code); |
|
662 | 662 | |
663 | - if( empty( $code_id ) ) { |
|
663 | + if (empty($code_id)) { |
|
664 | 664 | return false; // No discount was found |
665 | 665 | } |
666 | 666 | } |
667 | 667 | |
668 | - if ( wpinv_discount_is_single_use( $code_id ) ) { |
|
668 | + if (wpinv_discount_is_single_use($code_id)) { |
|
669 | 669 | $payments = array(); |
670 | 670 | |
671 | 671 | $user_id = 0; |
672 | - if ( is_int( $user ) ) { |
|
672 | + if (is_int($user)) { |
|
673 | 673 | $user_id = $user; |
674 | - } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) { |
|
674 | + } else if (is_email($user) && $user_data = get_user_by('email', $user)) { |
|
675 | 675 | $user_id = $user_data->ID; |
676 | - } else if ( $user_data = get_user_by( 'login', $user ) ) { |
|
676 | + } else if ($user_data = get_user_by('login', $user)) { |
|
677 | 677 | $user_id = $user_data->ID; |
678 | 678 | } |
679 | 679 | |
680 | - if ( !$user_id ) { |
|
681 | - $query = array( 'user' => $user_id, 'limit' => false ); |
|
682 | - $payments = wpinv_get_invoices( $query ); // Get all payments with matching email |
|
680 | + if (!$user_id) { |
|
681 | + $query = array('user' => $user_id, 'limit' => false); |
|
682 | + $payments = wpinv_get_invoices($query); // Get all payments with matching email |
|
683 | 683 | } |
684 | 684 | |
685 | - if ( $payments ) { |
|
686 | - foreach ( $payments as $payment ) { |
|
687 | - if ( $payment->has_status( array( 'cancelled', 'failed' ) ) ) { |
|
685 | + if ($payments) { |
|
686 | + foreach ($payments as $payment) { |
|
687 | + if ($payment->has_status(array('cancelled', 'failed'))) { |
|
688 | 688 | continue; |
689 | 689 | } |
690 | 690 | |
691 | 691 | // Don't count discount used for current invoice chekcout. |
692 | - if ( !empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) { |
|
692 | + if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) { |
|
693 | 693 | continue; |
694 | 694 | } |
695 | 695 | |
696 | - $discounts = $payment->get_discounts( true ); |
|
697 | - if ( empty( $discounts ) ) { |
|
696 | + $discounts = $payment->get_discounts(true); |
|
697 | + if (empty($discounts)) { |
|
698 | 698 | continue; |
699 | 699 | } |
700 | 700 | |
701 | - $discounts = $discounts && !is_array( $discounts ) ? explode( ',', $discounts ) : $discounts; |
|
701 | + $discounts = $discounts && !is_array($discounts) ? explode(',', $discounts) : $discounts; |
|
702 | 702 | |
703 | - if ( !empty( $discounts ) && is_array( $discounts ) ) { |
|
704 | - if ( in_array( strtolower( $code ), array_map( 'strtolower', $discounts ) ) ) { |
|
705 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) ); |
|
703 | + if (!empty($discounts) && is_array($discounts)) { |
|
704 | + if (in_array(strtolower($code), array_map('strtolower', $discounts))) { |
|
705 | + wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing')); |
|
706 | 706 | $return = true; |
707 | 707 | break; |
708 | 708 | } |
@@ -711,61 +711,61 @@ discard block |
||
711 | 711 | } |
712 | 712 | } |
713 | 713 | |
714 | - return apply_filters( 'wpinv_is_discount_used', $return, $code, $user ); |
|
714 | + return apply_filters('wpinv_is_discount_used', $return, $code, $user); |
|
715 | 715 | } |
716 | 716 | |
717 | -function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) { |
|
717 | +function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) { |
|
718 | 718 | $return = false; |
719 | - $discount_id = wpinv_get_discount_id_by_code( $code ); |
|
720 | - $user = trim( $user ); |
|
719 | + $discount_id = wpinv_get_discount_id_by_code($code); |
|
720 | + $user = trim($user); |
|
721 | 721 | |
722 | - if ( wpinv_get_cart_contents() ) { |
|
723 | - if ( $discount_id ) { |
|
722 | + if (wpinv_get_cart_contents()) { |
|
723 | + if ($discount_id) { |
|
724 | 724 | if ( |
725 | - wpinv_is_discount_active( $discount_id ) && |
|
726 | - wpinv_check_discount_dates( $discount_id ) && |
|
727 | - !wpinv_is_discount_maxed_out( $discount_id ) && |
|
728 | - !wpinv_is_discount_used( $code, $user, $discount_id ) && |
|
729 | - wpinv_discount_is_min_met( $discount_id ) && |
|
730 | - wpinv_discount_is_max_met( $discount_id ) && |
|
731 | - wpinv_discount_item_reqs_met( $discount_id ) |
|
725 | + wpinv_is_discount_active($discount_id) && |
|
726 | + wpinv_check_discount_dates($discount_id) && |
|
727 | + !wpinv_is_discount_maxed_out($discount_id) && |
|
728 | + !wpinv_is_discount_used($code, $user, $discount_id) && |
|
729 | + wpinv_discount_is_min_met($discount_id) && |
|
730 | + wpinv_discount_is_max_met($discount_id) && |
|
731 | + wpinv_discount_item_reqs_met($discount_id) |
|
732 | 732 | ) { |
733 | 733 | $return = true; |
734 | 734 | } |
735 | - } elseif( $set_error ) { |
|
736 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) ); |
|
735 | + } elseif ($set_error) { |
|
736 | + wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing')); |
|
737 | 737 | } |
738 | 738 | } |
739 | 739 | |
740 | - return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user ); |
|
740 | + return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user); |
|
741 | 741 | } |
742 | 742 | |
743 | -function wpinv_get_discount_id_by_code( $code ) { |
|
744 | - $discount = wpinv_get_discount_by_code( $code ); |
|
745 | - if( $discount ) { |
|
743 | +function wpinv_get_discount_id_by_code($code) { |
|
744 | + $discount = wpinv_get_discount_by_code($code); |
|
745 | + if ($discount) { |
|
746 | 746 | return $discount->ID; |
747 | 747 | } |
748 | 748 | return false; |
749 | 749 | } |
750 | 750 | |
751 | -function wpinv_get_discounted_amount( $code, $base_price ) { |
|
751 | +function wpinv_get_discounted_amount($code, $base_price) { |
|
752 | 752 | $amount = $base_price; |
753 | - $discount_id = wpinv_get_discount_id_by_code( $code ); |
|
753 | + $discount_id = wpinv_get_discount_id_by_code($code); |
|
754 | 754 | |
755 | - if( $discount_id ) { |
|
756 | - $type = wpinv_get_discount_type( $discount_id ); |
|
757 | - $rate = wpinv_get_discount_amount( $discount_id ); |
|
755 | + if ($discount_id) { |
|
756 | + $type = wpinv_get_discount_type($discount_id); |
|
757 | + $rate = wpinv_get_discount_amount($discount_id); |
|
758 | 758 | |
759 | - if ( $type == 'flat' ) { |
|
759 | + if ($type == 'flat') { |
|
760 | 760 | // Set amount |
761 | 761 | $amount = $base_price - $rate; |
762 | - if ( $amount < 0 ) { |
|
762 | + if ($amount < 0) { |
|
763 | 763 | $amount = 0; |
764 | 764 | } |
765 | 765 | |
766 | 766 | } else { |
767 | 767 | // Percentage discount |
768 | - $amount = $base_price - ( $base_price * ( $rate / 100 ) ); |
|
768 | + $amount = $base_price - ($base_price * ($rate / 100)); |
|
769 | 769 | } |
770 | 770 | |
771 | 771 | } else { |
@@ -774,108 +774,108 @@ discard block |
||
774 | 774 | |
775 | 775 | } |
776 | 776 | |
777 | - return apply_filters( 'wpinv_discounted_amount', $amount ); |
|
777 | + return apply_filters('wpinv_discounted_amount', $amount); |
|
778 | 778 | } |
779 | 779 | |
780 | -function wpinv_increase_discount_usage( $code ) { |
|
780 | +function wpinv_increase_discount_usage($code) { |
|
781 | 781 | |
782 | - $id = wpinv_get_discount_id_by_code( $code ); |
|
783 | - $uses = wpinv_get_discount_uses( $id ); |
|
782 | + $id = wpinv_get_discount_id_by_code($code); |
|
783 | + $uses = wpinv_get_discount_uses($id); |
|
784 | 784 | |
785 | - if ( $uses ) { |
|
785 | + if ($uses) { |
|
786 | 786 | $uses++; |
787 | 787 | } else { |
788 | 788 | $uses = 1; |
789 | 789 | } |
790 | 790 | |
791 | - update_post_meta( $id, '_wpi_discount_uses', $uses ); |
|
791 | + update_post_meta($id, '_wpi_discount_uses', $uses); |
|
792 | 792 | |
793 | - do_action( 'wpinv_discount_increase_use_count', $uses, $id, $code ); |
|
793 | + do_action('wpinv_discount_increase_use_count', $uses, $id, $code); |
|
794 | 794 | |
795 | 795 | return $uses; |
796 | 796 | |
797 | 797 | } |
798 | 798 | |
799 | -function wpinv_decrease_discount_usage( $code ) { |
|
799 | +function wpinv_decrease_discount_usage($code) { |
|
800 | 800 | |
801 | - $id = wpinv_get_discount_id_by_code( $code ); |
|
802 | - $uses = wpinv_get_discount_uses( $id ); |
|
801 | + $id = wpinv_get_discount_id_by_code($code); |
|
802 | + $uses = wpinv_get_discount_uses($id); |
|
803 | 803 | |
804 | - if ( $uses ) { |
|
804 | + if ($uses) { |
|
805 | 805 | $uses--; |
806 | 806 | } |
807 | 807 | |
808 | - if ( $uses < 0 ) { |
|
808 | + if ($uses < 0) { |
|
809 | 809 | $uses = 0; |
810 | 810 | } |
811 | 811 | |
812 | - update_post_meta( $id, '_wpi_discount_uses', $uses ); |
|
812 | + update_post_meta($id, '_wpi_discount_uses', $uses); |
|
813 | 813 | |
814 | - do_action( 'wpinv_discount_decrease_use_count', $uses, $id, $code ); |
|
814 | + do_action('wpinv_discount_decrease_use_count', $uses, $id, $code); |
|
815 | 815 | |
816 | 816 | return $uses; |
817 | 817 | |
818 | 818 | } |
819 | 819 | |
820 | -function wpinv_format_discount_rate( $type, $amount ) { |
|
821 | - if ( $type == 'flat' ) { |
|
822 | - return wpinv_price( wpinv_format_amount( $amount ) ); |
|
820 | +function wpinv_format_discount_rate($type, $amount) { |
|
821 | + if ($type == 'flat') { |
|
822 | + return wpinv_price(wpinv_format_amount($amount)); |
|
823 | 823 | } else { |
824 | 824 | return $amount . '%'; |
825 | 825 | } |
826 | 826 | } |
827 | 827 | |
828 | -function wpinv_set_cart_discount( $code = '' ) { |
|
829 | - if ( wpinv_multiple_discounts_allowed() ) { |
|
828 | +function wpinv_set_cart_discount($code = '') { |
|
829 | + if (wpinv_multiple_discounts_allowed()) { |
|
830 | 830 | // Get all active cart discounts |
831 | 831 | $discounts = wpinv_get_cart_discounts(); |
832 | 832 | } else { |
833 | 833 | $discounts = false; // Only one discount allowed per purchase, so override any existing |
834 | 834 | } |
835 | 835 | |
836 | - if ( $discounts ) { |
|
837 | - $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) ); |
|
838 | - if( false !== $key ) { |
|
839 | - unset( $discounts[ $key ] ); // Can't set the same discount more than once |
|
836 | + if ($discounts) { |
|
837 | + $key = array_search(strtolower($code), array_map('strtolower', $discounts)); |
|
838 | + if (false !== $key) { |
|
839 | + unset($discounts[$key]); // Can't set the same discount more than once |
|
840 | 840 | } |
841 | 841 | $discounts[] = $code; |
842 | 842 | } else { |
843 | 843 | $discounts = array(); |
844 | 844 | $discounts[] = $code; |
845 | 845 | } |
846 | - $discounts = array_values( $discounts ); |
|
846 | + $discounts = array_values($discounts); |
|
847 | 847 | |
848 | 848 | $data = wpinv_get_checkout_session(); |
849 | - if ( empty( $data ) ) { |
|
849 | + if (empty($data)) { |
|
850 | 850 | $data = array(); |
851 | 851 | } else { |
852 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
853 | - $payment_meta['user_info']['discount'] = implode( ',', $discounts ); |
|
854 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
852 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
853 | + $payment_meta['user_info']['discount'] = implode(',', $discounts); |
|
854 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
855 | 855 | } |
856 | 856 | } |
857 | 857 | $data['cart_discounts'] = $discounts; |
858 | 858 | |
859 | - wpinv_set_checkout_session( $data ); |
|
859 | + wpinv_set_checkout_session($data); |
|
860 | 860 | |
861 | 861 | return $discounts; |
862 | 862 | } |
863 | 863 | |
864 | -function wpinv_unset_cart_discount( $code = '' ) { |
|
864 | +function wpinv_unset_cart_discount($code = '') { |
|
865 | 865 | $discounts = wpinv_get_cart_discounts(); |
866 | 866 | |
867 | - if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) { |
|
868 | - $key = array_search( $code, $discounts ); |
|
869 | - unset( $discounts[ $key ] ); |
|
867 | + if ($code && !empty($discounts) && in_array($code, $discounts)) { |
|
868 | + $key = array_search($code, $discounts); |
|
869 | + unset($discounts[$key]); |
|
870 | 870 | |
871 | 871 | $data = wpinv_get_checkout_session(); |
872 | 872 | $data['cart_discounts'] = $discounts; |
873 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
874 | - $payment_meta['user_info']['discount'] = !empty( $discounts ) ? implode( ',', $discounts ) : ''; |
|
875 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
873 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
874 | + $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : ''; |
|
875 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
876 | 876 | } |
877 | 877 | |
878 | - wpinv_set_checkout_session( $data ); |
|
878 | + wpinv_set_checkout_session($data); |
|
879 | 879 | } |
880 | 880 | |
881 | 881 | return $discounts; |
@@ -884,27 +884,27 @@ discard block |
||
884 | 884 | function wpinv_unset_all_cart_discounts() { |
885 | 885 | $data = wpinv_get_checkout_session(); |
886 | 886 | |
887 | - if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) { |
|
888 | - unset( $data['cart_discounts'] ); |
|
887 | + if (!empty($data) && isset($data['cart_discounts'])) { |
|
888 | + unset($data['cart_discounts']); |
|
889 | 889 | |
890 | - wpinv_set_checkout_session( $data ); |
|
890 | + wpinv_set_checkout_session($data); |
|
891 | 891 | return true; |
892 | 892 | } |
893 | 893 | |
894 | 894 | return false; |
895 | 895 | } |
896 | 896 | |
897 | -function wpinv_get_cart_discounts( $items = array() ) { |
|
897 | +function wpinv_get_cart_discounts($items = array()) { |
|
898 | 898 | $session = wpinv_get_checkout_session(); |
899 | 899 | |
900 | - $discounts = !empty( $session['cart_discounts'] ) ? $session['cart_discounts'] : false; |
|
900 | + $discounts = !empty($session['cart_discounts']) ? $session['cart_discounts'] : false; |
|
901 | 901 | return $discounts; |
902 | 902 | } |
903 | 903 | |
904 | -function wpinv_cart_has_discounts( $items = array() ) { |
|
904 | +function wpinv_cart_has_discounts($items = array()) { |
|
905 | 905 | $ret = false; |
906 | 906 | |
907 | - if ( wpinv_get_cart_discounts( $items ) ) { |
|
907 | + if (wpinv_get_cart_discounts($items)) { |
|
908 | 908 | $ret = true; |
909 | 909 | } |
910 | 910 | |
@@ -915,131 +915,131 @@ discard block |
||
915 | 915 | } |
916 | 916 | */ |
917 | 917 | |
918 | - return apply_filters( 'wpinv_cart_has_discounts', $ret ); |
|
918 | + return apply_filters('wpinv_cart_has_discounts', $ret); |
|
919 | 919 | } |
920 | 920 | |
921 | -function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) { |
|
921 | +function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) { |
|
922 | 922 | $amount = 0.00; |
923 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
923 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
924 | 924 | |
925 | - if ( $items ) { |
|
926 | - $discounts = wp_list_pluck( $items, 'discount' ); |
|
925 | + if ($items) { |
|
926 | + $discounts = wp_list_pluck($items, 'discount'); |
|
927 | 927 | |
928 | - if ( is_array( $discounts ) ) { |
|
929 | - $discounts = array_map( 'floatval', $discounts ); |
|
930 | - $amount = array_sum( $discounts ); |
|
928 | + if (is_array($discounts)) { |
|
929 | + $discounts = array_map('floatval', $discounts); |
|
930 | + $amount = array_sum($discounts); |
|
931 | 931 | } |
932 | 932 | } |
933 | 933 | |
934 | - return apply_filters( 'wpinv_get_cart_discounted_amount', $amount ); |
|
934 | + return apply_filters('wpinv_get_cart_discounted_amount', $amount); |
|
935 | 935 | } |
936 | 936 | |
937 | -function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) { |
|
938 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
937 | +function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) { |
|
938 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
939 | 939 | |
940 | - if ( empty( $discount ) || empty( $items ) ) { |
|
940 | + if (empty($discount) || empty($items)) { |
|
941 | 941 | return 0; |
942 | 942 | } |
943 | 943 | |
944 | 944 | $amount = 0; |
945 | 945 | |
946 | - foreach ( $items as $item ) { |
|
947 | - $amount += wpinv_get_cart_item_discount_amount( $item, $discount ); |
|
946 | + foreach ($items as $item) { |
|
947 | + $amount += wpinv_get_cart_item_discount_amount($item, $discount); |
|
948 | 948 | } |
949 | 949 | |
950 | - $amount = wpinv_format_amount( $amount ); |
|
950 | + $amount = wpinv_format_amount($amount); |
|
951 | 951 | |
952 | 952 | return $amount; |
953 | 953 | } |
954 | 954 | |
955 | -function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) { |
|
955 | +function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) { |
|
956 | 956 | global $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
957 | 957 | |
958 | 958 | $amount = 0; |
959 | 959 | |
960 | - if ( empty( $item ) || empty( $item['id'] ) ) { |
|
960 | + if (empty($item) || empty($item['id'])) { |
|
961 | 961 | return $amount; |
962 | 962 | } |
963 | 963 | |
964 | - if ( empty( $item['quantity'] ) ) { |
|
964 | + if (empty($item['quantity'])) { |
|
965 | 965 | return $amount; |
966 | 966 | } |
967 | 967 | |
968 | - if ( empty( $item['options'] ) ) { |
|
968 | + if (empty($item['options'])) { |
|
969 | 969 | $item['options'] = array(); |
970 | 970 | } |
971 | 971 | |
972 | - $price = wpinv_get_cart_item_price( $item['id'], $item['options'] ); |
|
972 | + $price = wpinv_get_cart_item_price($item['id'], $item['options']); |
|
973 | 973 | $discounted_price = $price; |
974 | 974 | |
975 | 975 | $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount; |
976 | - if ( empty( $discounts ) ) { |
|
976 | + if (empty($discounts)) { |
|
977 | 977 | return $amount; |
978 | 978 | } |
979 | 979 | |
980 | - if ( $discounts ) { |
|
981 | - if ( is_array( $discounts ) ) { |
|
982 | - $discounts = array_values( $discounts ); |
|
980 | + if ($discounts) { |
|
981 | + if (is_array($discounts)) { |
|
982 | + $discounts = array_values($discounts); |
|
983 | 983 | } else { |
984 | - $discounts = explode( ',', $discounts ); |
|
984 | + $discounts = explode(',', $discounts); |
|
985 | 985 | } |
986 | 986 | } |
987 | 987 | |
988 | - if( $discounts ) { |
|
989 | - foreach ( $discounts as $discount ) { |
|
990 | - $code_id = wpinv_get_discount_id_by_code( $discount ); |
|
988 | + if ($discounts) { |
|
989 | + foreach ($discounts as $discount) { |
|
990 | + $code_id = wpinv_get_discount_id_by_code($discount); |
|
991 | 991 | |
992 | 992 | // Check discount exists |
993 | - if( ! $code_id ) { |
|
993 | + if (!$code_id) { |
|
994 | 994 | continue; |
995 | 995 | } |
996 | 996 | |
997 | - $reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
998 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
997 | + $reqs = wpinv_get_discount_item_reqs($code_id); |
|
998 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
999 | 999 | |
1000 | 1000 | // Make sure requirements are set and that this discount shouldn't apply to the whole cart |
1001 | - if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) { |
|
1002 | - foreach ( $reqs as $item_id ) { |
|
1003 | - if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) { |
|
1004 | - $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price ); |
|
1001 | + if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) { |
|
1002 | + foreach ($reqs as $item_id) { |
|
1003 | + if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) { |
|
1004 | + $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price); |
|
1005 | 1005 | } |
1006 | 1006 | } |
1007 | 1007 | } else { |
1008 | 1008 | // This is a global cart discount |
1009 | - if ( !in_array( $item['id'], $excluded_items ) ) { |
|
1010 | - if ( 'flat' === wpinv_get_discount_type( $code_id ) ) { |
|
1009 | + if (!in_array($item['id'], $excluded_items)) { |
|
1010 | + if ('flat' === wpinv_get_discount_type($code_id)) { |
|
1011 | 1011 | $items_subtotal = 0.00; |
1012 | 1012 | $cart_items = wpinv_get_cart_contents(); |
1013 | 1013 | |
1014 | - foreach ( $cart_items as $cart_item ) { |
|
1015 | - if ( ! in_array( $cart_item['id'], $excluded_items ) ) { |
|
1016 | - $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array(); |
|
1017 | - $item_price = wpinv_get_cart_item_price( $cart_item['id'], $options ); |
|
1014 | + foreach ($cart_items as $cart_item) { |
|
1015 | + if (!in_array($cart_item['id'], $excluded_items)) { |
|
1016 | + $options = !empty($cart_item['options']) ? $cart_item['options'] : array(); |
|
1017 | + $item_price = wpinv_get_cart_item_price($cart_item['id'], $options); |
|
1018 | 1018 | $items_subtotal += $item_price * $cart_item['quantity']; |
1019 | 1019 | } |
1020 | 1020 | } |
1021 | 1021 | |
1022 | - $subtotal_percent = ( ( $price * $item['quantity'] ) / $items_subtotal ); |
|
1023 | - $code_amount = wpinv_get_discount_amount( $code_id ); |
|
1022 | + $subtotal_percent = (($price * $item['quantity']) / $items_subtotal); |
|
1023 | + $code_amount = wpinv_get_discount_amount($code_id); |
|
1024 | 1024 | $discounted_amount = $code_amount * $subtotal_percent; |
1025 | 1025 | $discounted_price -= $discounted_amount; |
1026 | 1026 | |
1027 | - $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() ); |
|
1027 | + $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter()); |
|
1028 | 1028 | |
1029 | - if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) { |
|
1029 | + if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) { |
|
1030 | 1030 | $adjustment = $code_amount - $wpinv_flat_discount_total; |
1031 | 1031 | $discounted_price -= $adjustment; |
1032 | 1032 | } |
1033 | 1033 | } else { |
1034 | - $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price ); |
|
1034 | + $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price); |
|
1035 | 1035 | } |
1036 | 1036 | } |
1037 | 1037 | } |
1038 | 1038 | } |
1039 | 1039 | |
1040 | - $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) ); |
|
1040 | + $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price)); |
|
1041 | 1041 | |
1042 | - if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) { |
|
1042 | + if ('flat' !== wpinv_get_discount_type($code_id)) { |
|
1043 | 1043 | $amount = $amount * $item['quantity']; |
1044 | 1044 | } |
1045 | 1045 | } |
@@ -1047,59 +1047,59 @@ discard block |
||
1047 | 1047 | return $amount; |
1048 | 1048 | } |
1049 | 1049 | |
1050 | -function wpinv_cart_discounts_html( $items = array() ) { |
|
1051 | - echo wpinv_get_cart_discounts_html( $items ); |
|
1050 | +function wpinv_cart_discounts_html($items = array()) { |
|
1051 | + echo wpinv_get_cart_discounts_html($items); |
|
1052 | 1052 | } |
1053 | 1053 | |
1054 | -function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) { |
|
1054 | +function wpinv_get_cart_discounts_html($items = array(), $discounts = false) { |
|
1055 | 1055 | global $wpi_cart_columns; |
1056 | 1056 | |
1057 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
1057 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
1058 | 1058 | |
1059 | - if ( !$discounts ) { |
|
1060 | - $discounts = wpinv_get_cart_discounts( $items ); |
|
1059 | + if (!$discounts) { |
|
1060 | + $discounts = wpinv_get_cart_discounts($items); |
|
1061 | 1061 | } |
1062 | 1062 | |
1063 | - if ( !$discounts ) { |
|
1063 | + if (!$discounts) { |
|
1064 | 1064 | return; |
1065 | 1065 | } |
1066 | 1066 | |
1067 | - $discounts = is_array( $discounts ) ? $discounts : array( $discounts ); |
|
1067 | + $discounts = is_array($discounts) ? $discounts : array($discounts); |
|
1068 | 1068 | |
1069 | 1069 | $html = ''; |
1070 | 1070 | |
1071 | - foreach ( $discounts as $discount ) { |
|
1072 | - $discount_id = wpinv_get_discount_id_by_code( $discount ); |
|
1073 | - $discount_value = wpinv_get_discount_amount( $discount_id ); |
|
1074 | - $rate = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value ); |
|
1075 | - $amount = wpinv_get_cart_items_discount_amount( $items, $discount ); |
|
1076 | - $remove_btn = '<a title="' . esc_attr__( 'Remove discount', 'invoicing' ) . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> '; |
|
1071 | + foreach ($discounts as $discount) { |
|
1072 | + $discount_id = wpinv_get_discount_id_by_code($discount); |
|
1073 | + $discount_value = wpinv_get_discount_amount($discount_id); |
|
1074 | + $rate = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value); |
|
1075 | + $amount = wpinv_get_cart_items_discount_amount($items, $discount); |
|
1076 | + $remove_btn = '<a title="' . esc_attr__('Remove discount', 'invoicing') . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> '; |
|
1077 | 1077 | |
1078 | 1078 | $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">'; |
1079 | 1079 | ob_start(); |
1080 | - do_action( 'wpinv_checkout_table_discount_first', $items ); |
|
1080 | + do_action('wpinv_checkout_table_discount_first', $items); |
|
1081 | 1081 | $html .= ob_get_clean(); |
1082 | - $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label( $discount, $rate, false ) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">–' . wpinv_price( $amount ) . '</span></td>'; |
|
1082 | + $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label($discount, $rate, false) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">–' . wpinv_price($amount) . '</span></td>'; |
|
1083 | 1083 | ob_start(); |
1084 | - do_action( 'wpinv_checkout_table_discount_last', $items ); |
|
1084 | + do_action('wpinv_checkout_table_discount_last', $items); |
|
1085 | 1085 | $html .= ob_get_clean(); |
1086 | 1086 | $html .= '</tr>'; |
1087 | 1087 | } |
1088 | 1088 | |
1089 | - return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate ); |
|
1089 | + return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate); |
|
1090 | 1090 | } |
1091 | 1091 | |
1092 | -function wpinv_display_cart_discount( $formatted = false, $echo = false ) { |
|
1092 | +function wpinv_display_cart_discount($formatted = false, $echo = false) { |
|
1093 | 1093 | $discounts = wpinv_get_cart_discounts(); |
1094 | 1094 | |
1095 | - if ( empty( $discounts ) ) { |
|
1095 | + if (empty($discounts)) { |
|
1096 | 1096 | return false; |
1097 | 1097 | } |
1098 | 1098 | |
1099 | - $discount_id = wpinv_get_discount_id_by_code( $discounts[0] ); |
|
1100 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) ); |
|
1099 | + $discount_id = wpinv_get_discount_id_by_code($discounts[0]); |
|
1100 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id)); |
|
1101 | 1101 | |
1102 | - if ( $echo ) { |
|
1102 | + if ($echo) { |
|
1103 | 1103 | echo $amount; |
1104 | 1104 | } |
1105 | 1105 | |
@@ -1107,133 +1107,133 @@ discard block |
||
1107 | 1107 | } |
1108 | 1108 | |
1109 | 1109 | function wpinv_remove_cart_discount() { |
1110 | - if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) { |
|
1110 | + if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) { |
|
1111 | 1111 | return; |
1112 | 1112 | } |
1113 | 1113 | |
1114 | - do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
1114 | + do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id'])); |
|
1115 | 1115 | |
1116 | - wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) ); |
|
1116 | + wpinv_unset_cart_discount(urldecode($_GET['discount_code'])); |
|
1117 | 1117 | |
1118 | - do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
1118 | + do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id'])); |
|
1119 | 1119 | |
1120 | - wp_redirect( wpinv_get_checkout_uri() ); wpinv_die(); |
|
1120 | + wp_redirect(wpinv_get_checkout_uri()); wpinv_die(); |
|
1121 | 1121 | } |
1122 | -add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' ); |
|
1122 | +add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount'); |
|
1123 | 1123 | |
1124 | -function wpinv_maybe_remove_cart_discount( $cart_key = 0 ) { |
|
1124 | +function wpinv_maybe_remove_cart_discount($cart_key = 0) { |
|
1125 | 1125 | $discounts = wpinv_get_cart_discounts(); |
1126 | 1126 | |
1127 | - if ( !$discounts ) { |
|
1127 | + if (!$discounts) { |
|
1128 | 1128 | return; |
1129 | 1129 | } |
1130 | 1130 | |
1131 | - foreach ( $discounts as $discount ) { |
|
1132 | - if ( !wpinv_is_discount_valid( $discount ) ) { |
|
1133 | - wpinv_unset_cart_discount( $discount ); |
|
1131 | + foreach ($discounts as $discount) { |
|
1132 | + if (!wpinv_is_discount_valid($discount)) { |
|
1133 | + wpinv_unset_cart_discount($discount); |
|
1134 | 1134 | } |
1135 | 1135 | } |
1136 | 1136 | } |
1137 | -add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' ); |
|
1137 | +add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount'); |
|
1138 | 1138 | |
1139 | 1139 | function wpinv_multiple_discounts_allowed() { |
1140 | - $ret = wpinv_get_option( 'allow_multiple_discounts', false ); |
|
1141 | - return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret ); |
|
1140 | + $ret = wpinv_get_option('allow_multiple_discounts', false); |
|
1141 | + return (bool)apply_filters('wpinv_multiple_discounts_allowed', $ret); |
|
1142 | 1142 | } |
1143 | 1143 | |
1144 | 1144 | function wpinv_listen_for_cart_discount() { |
1145 | 1145 | global $wpi_session; |
1146 | 1146 | |
1147 | - if ( empty( $_REQUEST['discount'] ) || is_array( $_REQUEST['discount'] ) ) { |
|
1147 | + if (empty($_REQUEST['discount']) || is_array($_REQUEST['discount'])) { |
|
1148 | 1148 | return; |
1149 | 1149 | } |
1150 | 1150 | |
1151 | - $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount'] ); |
|
1151 | + $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount']); |
|
1152 | 1152 | |
1153 | - $wpi_session->set( 'preset_discount', $code ); |
|
1153 | + $wpi_session->set('preset_discount', $code); |
|
1154 | 1154 | } |
1155 | 1155 | //add_action( 'init', 'wpinv_listen_for_cart_discount', 0 ); |
1156 | 1156 | |
1157 | 1157 | function wpinv_apply_preset_discount() { |
1158 | 1158 | global $wpi_session; |
1159 | 1159 | |
1160 | - $code = $wpi_session->get( 'preset_discount' ); |
|
1160 | + $code = $wpi_session->get('preset_discount'); |
|
1161 | 1161 | |
1162 | - if ( !$code ) { |
|
1162 | + if (!$code) { |
|
1163 | 1163 | return; |
1164 | 1164 | } |
1165 | 1165 | |
1166 | - if ( !wpinv_is_discount_valid( $code, '', false ) ) { |
|
1166 | + if (!wpinv_is_discount_valid($code, '', false)) { |
|
1167 | 1167 | return; |
1168 | 1168 | } |
1169 | 1169 | |
1170 | - $code = apply_filters( 'wpinv_apply_preset_discount', $code ); |
|
1170 | + $code = apply_filters('wpinv_apply_preset_discount', $code); |
|
1171 | 1171 | |
1172 | - wpinv_set_cart_discount( $code ); |
|
1172 | + wpinv_set_cart_discount($code); |
|
1173 | 1173 | |
1174 | - $wpi_session->set( 'preset_discount', null ); |
|
1174 | + $wpi_session->set('preset_discount', null); |
|
1175 | 1175 | } |
1176 | 1176 | //add_action( 'init', 'wpinv_apply_preset_discount', 999 ); |
1177 | 1177 | |
1178 | -function wpinv_get_discount_label( $code, $echo = true ) { |
|
1179 | - $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) ); |
|
1180 | - $label = apply_filters( 'wpinv_get_discount_label', $label, $code ); |
|
1178 | +function wpinv_get_discount_label($code, $echo = true) { |
|
1179 | + $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : '')); |
|
1180 | + $label = apply_filters('wpinv_get_discount_label', $label, $code); |
|
1181 | 1181 | |
1182 | - if ( $echo ) { |
|
1182 | + if ($echo) { |
|
1183 | 1183 | echo $label; |
1184 | 1184 | } else { |
1185 | 1185 | return $label; |
1186 | 1186 | } |
1187 | 1187 | } |
1188 | 1188 | |
1189 | -function wpinv_cart_discount_label( $code, $rate, $echo = true ) { |
|
1190 | - $label = wp_sprintf( __( '%1$s Discount: %2$s', 'invoicing' ), $rate, $code ); |
|
1191 | - $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate ); |
|
1189 | +function wpinv_cart_discount_label($code, $rate, $echo = true) { |
|
1190 | + $label = wp_sprintf(__('%1$s Discount: %2$s', 'invoicing'), $rate, $code); |
|
1191 | + $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate); |
|
1192 | 1192 | |
1193 | - if ( $echo ) { |
|
1193 | + if ($echo) { |
|
1194 | 1194 | echo $label; |
1195 | 1195 | } else { |
1196 | 1196 | return $label; |
1197 | 1197 | } |
1198 | 1198 | } |
1199 | 1199 | |
1200 | -function wpinv_check_delete_discount( $check, $post, $force_delete ) { |
|
1201 | - if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) { |
|
1200 | +function wpinv_check_delete_discount($check, $post, $force_delete) { |
|
1201 | + if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) { |
|
1202 | 1202 | return true; |
1203 | 1203 | } |
1204 | 1204 | |
1205 | 1205 | return $check; |
1206 | 1206 | } |
1207 | -add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 3 ); |
|
1207 | +add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 3); |
|
1208 | 1208 | |
1209 | 1209 | function wpinv_checkout_form_validate_discounts() { |
1210 | 1210 | $discounts = wpinv_get_cart_discounts(); |
1211 | 1211 | |
1212 | - if ( !empty( $discounts ) ) { |
|
1212 | + if (!empty($discounts)) { |
|
1213 | 1213 | $invalid = false; |
1214 | 1214 | |
1215 | - foreach ( $discounts as $key => $code ) { |
|
1216 | - if ( !wpinv_is_discount_valid( $code, get_current_user_id() ) ) { |
|
1215 | + foreach ($discounts as $key => $code) { |
|
1216 | + if (!wpinv_is_discount_valid($code, get_current_user_id())) { |
|
1217 | 1217 | $invalid = true; |
1218 | 1218 | |
1219 | - wpinv_unset_cart_discount( $code ); |
|
1219 | + wpinv_unset_cart_discount($code); |
|
1220 | 1220 | } |
1221 | 1221 | } |
1222 | 1222 | |
1223 | - if ( $invalid ) { |
|
1223 | + if ($invalid) { |
|
1224 | 1224 | $errors = wpinv_get_errors(); |
1225 | - $error = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
1226 | - $error .= __( 'The discount has been removed from cart.', 'invoicing' ); |
|
1227 | - wpinv_set_error( 'wpinv-discount-error', $error ); |
|
1225 | + $error = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
1226 | + $error .= __('The discount has been removed from cart.', 'invoicing'); |
|
1227 | + wpinv_set_error('wpinv-discount-error', $error); |
|
1228 | 1228 | |
1229 | - wpinv_recalculate_tax( true ); |
|
1229 | + wpinv_recalculate_tax(true); |
|
1230 | 1230 | } |
1231 | 1231 | } |
1232 | 1232 | } |
1233 | -add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 ); |
|
1233 | +add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10); |
|
1234 | 1234 | |
1235 | 1235 | function wpinv_discount_amount() { |
1236 | 1236 | $output = 0.00; |
1237 | 1237 | |
1238 | - return apply_filters( 'wpinv_discount_amount', $output ); |
|
1238 | + return apply_filters('wpinv_discount_amount', $output); |
|
1239 | 1239 | } |
1240 | 1240 | \ No newline at end of file |
@@ -1,121 +1,121 @@ 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 | function wpinv_use_taxes() { |
8 | - $ret = wpinv_get_option( 'enable_taxes', false ); |
|
8 | + $ret = wpinv_get_option('enable_taxes', false); |
|
9 | 9 | |
10 | - return (bool) apply_filters( 'wpinv_use_taxes', $ret ); |
|
10 | + return (bool)apply_filters('wpinv_use_taxes', $ret); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | function wpinv_get_tax_rates() { |
14 | - $rates = get_option( 'wpinv_tax_rates', array() ); |
|
14 | + $rates = get_option('wpinv_tax_rates', array()); |
|
15 | 15 | |
16 | - return apply_filters( 'wpinv_get_tax_rates', $rates ); |
|
16 | + return apply_filters('wpinv_get_tax_rates', $rates); |
|
17 | 17 | } |
18 | 18 | |
19 | -function wpinv_get_tax_rate( $country = false, $state = false, $item_id = 0 ) { |
|
19 | +function wpinv_get_tax_rate($country = false, $state = false, $item_id = 0) { |
|
20 | 20 | global $wpinv_euvat, $wpi_tax_rates, $wpi_userID; |
21 | - $wpi_tax_rates = !empty( $wpi_tax_rates ) ? $wpi_tax_rates : array(); |
|
21 | + $wpi_tax_rates = !empty($wpi_tax_rates) ? $wpi_tax_rates : array(); |
|
22 | 22 | |
23 | - if ( !empty( $wpi_tax_rates ) && !empty( $item_id ) && isset( $wpi_tax_rates[$item_id] ) ) { |
|
23 | + if (!empty($wpi_tax_rates) && !empty($item_id) && isset($wpi_tax_rates[$item_id])) { |
|
24 | 24 | return $wpi_tax_rates[$item_id]; |
25 | 25 | } |
26 | 26 | |
27 | - if ( !$wpinv_euvat->item_is_taxable( $item_id, $country, $state ) ) { |
|
27 | + if (!$wpinv_euvat->item_is_taxable($item_id, $country, $state)) { |
|
28 | 28 | $wpi_tax_rates[$item_id] = 0; |
29 | 29 | return 0; |
30 | 30 | } |
31 | 31 | |
32 | 32 | $is_global = false; |
33 | - if ( $item_id == 'global' ) { |
|
33 | + if ($item_id == 'global') { |
|
34 | 34 | $is_global = true; |
35 | 35 | $item_id = 0; |
36 | 36 | } |
37 | 37 | |
38 | - $rate = (float)wpinv_get_option( 'tax_rate', 0 ); |
|
39 | - $user_address = wpinv_get_user_address( $wpi_userID ); |
|
38 | + $rate = (float)wpinv_get_option('tax_rate', 0); |
|
39 | + $user_address = wpinv_get_user_address($wpi_userID); |
|
40 | 40 | |
41 | - if( empty( $country ) ) { |
|
42 | - if( !empty( $_POST['wpinv_country'] ) ) { |
|
41 | + if (empty($country)) { |
|
42 | + if (!empty($_POST['wpinv_country'])) { |
|
43 | 43 | $country = $_POST['wpinv_country']; |
44 | - } elseif( !empty( $_POST['wpinv_country'] ) ) { |
|
44 | + } elseif (!empty($_POST['wpinv_country'])) { |
|
45 | 45 | $country = $_POST['wpinv_country']; |
46 | - } elseif( !empty( $_POST['country'] ) ) { |
|
46 | + } elseif (!empty($_POST['country'])) { |
|
47 | 47 | $country = $_POST['country']; |
48 | - } elseif( is_user_logged_in() && !empty( $user_address ) ) { |
|
48 | + } elseif (is_user_logged_in() && !empty($user_address)) { |
|
49 | 49 | $country = $user_address['country']; |
50 | 50 | } |
51 | - $country = !empty( $country ) ? $country : wpinv_get_default_country(); |
|
51 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
52 | 52 | } |
53 | 53 | |
54 | - if( empty( $state ) ) { |
|
55 | - if( !empty( $_POST['wpinv_state'] ) ) { |
|
54 | + if (empty($state)) { |
|
55 | + if (!empty($_POST['wpinv_state'])) { |
|
56 | 56 | $state = $_POST['wpinv_state']; |
57 | - } elseif( !empty( $_POST['wpinv_state'] ) ) { |
|
57 | + } elseif (!empty($_POST['wpinv_state'])) { |
|
58 | 58 | $state = $_POST['wpinv_state']; |
59 | - } elseif( !empty( $_POST['state'] ) ) { |
|
59 | + } elseif (!empty($_POST['state'])) { |
|
60 | 60 | $state = $_POST['state']; |
61 | - } elseif( is_user_logged_in() && !empty( $user_address ) ) { |
|
61 | + } elseif (is_user_logged_in() && !empty($user_address)) { |
|
62 | 62 | $state = $user_address['state']; |
63 | 63 | } |
64 | - $state = !empty( $state ) ? $state : wpinv_get_default_state(); |
|
64 | + $state = !empty($state) ? $state : wpinv_get_default_state(); |
|
65 | 65 | } |
66 | 66 | |
67 | - if( !empty( $country ) ) { |
|
68 | - $tax_rates = wpinv_get_tax_rates(); |
|
67 | + if (!empty($country)) { |
|
68 | + $tax_rates = wpinv_get_tax_rates(); |
|
69 | 69 | |
70 | - if( !empty( $tax_rates ) ) { |
|
70 | + if (!empty($tax_rates)) { |
|
71 | 71 | // Locate the tax rate for this country / state, if it exists |
72 | - foreach( $tax_rates as $key => $tax_rate ) { |
|
73 | - if( $country != $tax_rate['country'] ) |
|
72 | + foreach ($tax_rates as $key => $tax_rate) { |
|
73 | + if ($country != $tax_rate['country']) |
|
74 | 74 | continue; |
75 | 75 | |
76 | - if( !empty( $tax_rate['global'] ) ) { |
|
77 | - if( !empty( $tax_rate['rate'] ) ) { |
|
78 | - $rate = number_format( $tax_rate['rate'], 4 ); |
|
76 | + if (!empty($tax_rate['global'])) { |
|
77 | + if (!empty($tax_rate['rate'])) { |
|
78 | + $rate = number_format($tax_rate['rate'], 4); |
|
79 | 79 | } |
80 | 80 | } else { |
81 | 81 | |
82 | - if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
82 | + if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) |
|
83 | 83 | continue; |
84 | 84 | |
85 | 85 | $state_rate = $tax_rate['rate']; |
86 | - if( 0 !== $state_rate || !empty( $state_rate ) ) { |
|
87 | - $rate = number_format( $state_rate, 4 ); |
|
86 | + if (0 !== $state_rate || !empty($state_rate)) { |
|
87 | + $rate = number_format($state_rate, 4); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | - $rate = apply_filters( 'wpinv_tax_rate', $rate, $country, $state, $item_id ); |
|
94 | + $rate = apply_filters('wpinv_tax_rate', $rate, $country, $state, $item_id); |
|
95 | 95 | |
96 | - if ( !empty( $item_id ) ) { |
|
96 | + if (!empty($item_id)) { |
|
97 | 97 | $wpi_tax_rates[$item_id] = $rate; |
98 | - } else if ( $is_global ) { |
|
98 | + } else if ($is_global) { |
|
99 | 99 | $wpi_tax_rates['global'] = $rate; |
100 | 100 | } |
101 | 101 | |
102 | 102 | return $rate; |
103 | 103 | } |
104 | 104 | |
105 | -function wpinv_get_formatted_tax_rate( $country = false, $state = false, $item_id ) { |
|
106 | - $rate = wpinv_get_tax_rate( $country, $state, $item_id ); |
|
107 | - $rate = round( $rate, 4 ); |
|
105 | +function wpinv_get_formatted_tax_rate($country = false, $state = false, $item_id) { |
|
106 | + $rate = wpinv_get_tax_rate($country, $state, $item_id); |
|
107 | + $rate = round($rate, 4); |
|
108 | 108 | $formatted = $rate .= '%'; |
109 | - return apply_filters( 'wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id ); |
|
109 | + return apply_filters('wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id); |
|
110 | 110 | } |
111 | 111 | |
112 | -function wpinv_calculate_tax( $amount = 0, $country = false, $state = false, $item_id = 0 ) { |
|
113 | - $rate = wpinv_get_tax_rate( $country, $state, $item_id ); |
|
112 | +function wpinv_calculate_tax($amount = 0, $country = false, $state = false, $item_id = 0) { |
|
113 | + $rate = wpinv_get_tax_rate($country, $state, $item_id); |
|
114 | 114 | $tax = 0.00; |
115 | 115 | |
116 | - if ( wpinv_use_taxes() ) { |
|
117 | - if ( wpinv_prices_include_tax() ) { |
|
118 | - $pre_tax = ( $amount / ( ( 1 + $rate ) * 0.01 ) ); |
|
116 | + if (wpinv_use_taxes()) { |
|
117 | + if (wpinv_prices_include_tax()) { |
|
118 | + $pre_tax = ($amount / ((1 + $rate) * 0.01)); |
|
119 | 119 | $tax = $amount - $pre_tax; |
120 | 120 | } else { |
121 | 121 | $tax = $amount * $rate * 0.01; |
@@ -123,46 +123,46 @@ discard block |
||
123 | 123 | |
124 | 124 | } |
125 | 125 | |
126 | - return apply_filters( 'wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id ); |
|
126 | + return apply_filters('wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | function wpinv_prices_include_tax() { |
130 | 130 | return false; // TODO |
131 | - $ret = ( wpinv_get_option( 'prices_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
131 | + $ret = (wpinv_get_option('prices_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
132 | 132 | |
133 | - return apply_filters( 'wpinv_prices_include_tax', $ret ); |
|
133 | + return apply_filters('wpinv_prices_include_tax', $ret); |
|
134 | 134 | } |
135 | 135 | |
136 | -function wpinv_sales_tax_for_year( $year = null ) { |
|
137 | - return wpinv_price( wpinv_format_amount( wpinv_get_sales_tax_for_year( $year ) ) ); |
|
136 | +function wpinv_sales_tax_for_year($year = null) { |
|
137 | + return wpinv_price(wpinv_format_amount(wpinv_get_sales_tax_for_year($year))); |
|
138 | 138 | } |
139 | 139 | |
140 | -function wpinv_get_sales_tax_for_year( $year = null ) { |
|
140 | +function wpinv_get_sales_tax_for_year($year = null) { |
|
141 | 141 | global $wpdb; |
142 | 142 | |
143 | 143 | // Start at zero |
144 | 144 | $tax = 0; |
145 | 145 | |
146 | - if ( ! empty( $year ) ) { |
|
146 | + if (!empty($year)) { |
|
147 | 147 | $args = array( |
148 | 148 | 'post_type' => 'wpi_invoice', |
149 | - 'post_status' => array( 'publish', 'revoked' ), |
|
149 | + 'post_status' => array('publish', 'revoked'), |
|
150 | 150 | 'posts_per_page' => -1, |
151 | 151 | 'year' => $year, |
152 | 152 | 'fields' => 'ids' |
153 | 153 | ); |
154 | 154 | |
155 | - $payments = get_posts( $args ); |
|
156 | - $payment_ids = implode( ',', $payments ); |
|
155 | + $payments = get_posts($args); |
|
156 | + $payment_ids = implode(',', $payments); |
|
157 | 157 | |
158 | - if ( count( $payments ) > 0 ) { |
|
158 | + if (count($payments) > 0) { |
|
159 | 159 | $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )"; |
160 | - $tax = $wpdb->get_var( $sql ); |
|
160 | + $tax = $wpdb->get_var($sql); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | } |
164 | 164 | |
165 | - return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year ); |
|
165 | + return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | function wpinv_is_cart_taxed() { |
@@ -171,33 +171,33 @@ discard block |
||
171 | 171 | |
172 | 172 | function wpinv_prices_show_tax_on_checkout() { |
173 | 173 | return false; // TODO |
174 | - $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
174 | + $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
175 | 175 | |
176 | - return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret ); |
|
176 | + return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | function wpinv_display_tax_rate() { |
180 | - $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false ); |
|
180 | + $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false); |
|
181 | 181 | |
182 | - return apply_filters( 'wpinv_display_tax_rate', $ret ); |
|
182 | + return apply_filters('wpinv_display_tax_rate', $ret); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | function wpinv_cart_needs_tax_address_fields() { |
186 | - if( !wpinv_is_cart_taxed() ) |
|
186 | + if (!wpinv_is_cart_taxed()) |
|
187 | 187 | return false; |
188 | 188 | |
189 | - return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' ); |
|
189 | + return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields'); |
|
190 | 190 | } |
191 | 191 | |
192 | -function wpinv_item_is_tax_exclusive( $item_id = 0 ) { |
|
193 | - $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false ); |
|
194 | - return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id ); |
|
192 | +function wpinv_item_is_tax_exclusive($item_id = 0) { |
|
193 | + $ret = (bool)get_post_meta($item_id, '_wpinv_tax_exclusive', false); |
|
194 | + return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id); |
|
195 | 195 | } |
196 | 196 | |
197 | -function wpinv_currency_decimal_filter( $decimals = 2 ) { |
|
197 | +function wpinv_currency_decimal_filter($decimals = 2) { |
|
198 | 198 | $currency = wpinv_get_currency(); |
199 | 199 | |
200 | - switch ( $currency ) { |
|
200 | + switch ($currency) { |
|
201 | 201 | case 'RIAL' : |
202 | 202 | case 'JPY' : |
203 | 203 | case 'TWD' : |
@@ -206,48 +206,48 @@ discard block |
||
206 | 206 | break; |
207 | 207 | } |
208 | 208 | |
209 | - return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency ); |
|
209 | + return apply_filters('wpinv_currency_decimal_count', $decimals, $currency); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | function wpinv_tax_amount() { |
213 | 213 | $output = 0.00; |
214 | 214 | |
215 | - return apply_filters( 'wpinv_tax_amount', $output ); |
|
215 | + return apply_filters('wpinv_tax_amount', $output); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | function wpinv_recalculated_tax() { |
219 | - define( 'WPINV_RECALCTAX', true ); |
|
219 | + define('WPINV_RECALCTAX', true); |
|
220 | 220 | } |
221 | -add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1 ); |
|
221 | +add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1); |
|
222 | 222 | |
223 | -function wpinv_recalculate_tax( $return = false ) { |
|
223 | +function wpinv_recalculate_tax($return = false) { |
|
224 | 224 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
225 | - if ( empty( $invoice_id ) ) { |
|
225 | + if (empty($invoice_id)) { |
|
226 | 226 | return false; |
227 | 227 | } |
228 | 228 | |
229 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
229 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
230 | 230 | |
231 | - if ( empty( $invoice ) ) { |
|
231 | + if (empty($invoice)) { |
|
232 | 232 | return false; |
233 | 233 | } |
234 | 234 | |
235 | - if ( empty( $_POST['country'] ) ) { |
|
235 | + if (empty($_POST['country'])) { |
|
236 | 236 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
237 | 237 | } |
238 | 238 | |
239 | 239 | $invoice->country = sanitize_text_field($_POST['country']); |
240 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
240 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
241 | 241 | if (isset($_POST['state'])) { |
242 | 242 | $invoice->state = sanitize_text_field($_POST['state']); |
243 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
243 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | $invoice->cart_details = wpinv_get_cart_content_details(); |
247 | 247 | |
248 | - $subtotal = wpinv_get_cart_subtotal( $invoice->cart_details ); |
|
249 | - $tax = wpinv_get_cart_tax( $invoice->cart_details ); |
|
250 | - $total = wpinv_get_cart_total( $invoice->cart_details ); |
|
248 | + $subtotal = wpinv_get_cart_subtotal($invoice->cart_details); |
|
249 | + $tax = wpinv_get_cart_tax($invoice->cart_details); |
|
250 | + $total = wpinv_get_cart_total($invoice->cart_details); |
|
251 | 251 | |
252 | 252 | $invoice->tax = $tax; |
253 | 253 | $invoice->subtotal = $subtotal; |
@@ -255,60 +255,60 @@ discard block |
||
255 | 255 | |
256 | 256 | $invoice->save(); |
257 | 257 | |
258 | - if ( $invoice->is_free_trial() ) { |
|
258 | + if ($invoice->is_free_trial()) { |
|
259 | 259 | $total = 0; |
260 | 260 | } |
261 | 261 | |
262 | 262 | $response = array( |
263 | - 'total' => html_entity_decode( wpinv_price( wpinv_format_amount( $total ) ), ENT_COMPAT, 'UTF-8' ), |
|
263 | + 'total' => html_entity_decode(wpinv_price(wpinv_format_amount($total)), ENT_COMPAT, 'UTF-8'), |
|
264 | 264 | 'total_raw' => $total, |
265 | - 'html' => wpinv_checkout_cart( $invoice->cart_details, false ), |
|
265 | + 'html' => wpinv_checkout_cart($invoice->cart_details, false), |
|
266 | 266 | ); |
267 | 267 | |
268 | - if ( $return ) { |
|
268 | + if ($return) { |
|
269 | 269 | return $response; |
270 | 270 | } |
271 | 271 | |
272 | - wp_send_json( $response ); |
|
272 | + wp_send_json($response); |
|
273 | 273 | } |
274 | -add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax' ); |
|
275 | -add_action( 'wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax' ); |
|
274 | +add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax'); |
|
275 | +add_action('wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax'); |
|
276 | 276 | |
277 | 277 | // VAT Settings |
278 | -function wpinv_vat_rate_add_callback( $args ) { |
|
278 | +function wpinv_vat_rate_add_callback($args) { |
|
279 | 279 | ?> |
280 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e( 'Add', 'invoicing' );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
280 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
281 | 281 | <?php |
282 | 282 | } |
283 | 283 | |
284 | -function wpinv_vat_rate_delete_callback( $args ) { |
|
284 | +function wpinv_vat_rate_delete_callback($args) { |
|
285 | 285 | global $wpinv_euvat; |
286 | 286 | |
287 | 287 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
288 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : ''; |
|
289 | - if ( isset( $vat_classes[$vat_class] ) ) { |
|
288 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : ''; |
|
289 | + if (isset($vat_classes[$vat_class])) { |
|
290 | 290 | ?> |
291 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf( esc_attr__( 'Delete class "%s"', 'invoicing' ), $vat_classes[$vat_class] );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
291 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf(esc_attr__('Delete class "%s"', 'invoicing'), $vat_classes[$vat_class]); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
292 | 292 | <?php |
293 | 293 | } |
294 | 294 | } |
295 | 295 | |
296 | -function wpinv_vat_rates_callback( $args ) { |
|
296 | +function wpinv_vat_rates_callback($args) { |
|
297 | 297 | global $wpinv_euvat; |
298 | 298 | |
299 | 299 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
300 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_standard'; |
|
300 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_standard'; |
|
301 | 301 | |
302 | 302 | $eu_states = $wpinv_euvat->get_eu_states(); |
303 | 303 | $countries = wpinv_get_country_list(); |
304 | 304 | $vat_groups = $wpinv_euvat->get_vat_groups(); |
305 | - $rates = $wpinv_euvat->get_vat_rates( $vat_class ); |
|
305 | + $rates = $wpinv_euvat->get_vat_rates($vat_class); |
|
306 | 306 | ob_start(); |
307 | 307 | ?> |
308 | 308 | </td><tr> |
309 | 309 | <td colspan="2" class="wpinv_vat_tdbox"> |
310 | - <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class;?>" /> |
|
311 | - <p><?php echo ( isset( $args['desc'] ) ? $args['desc'] : '' ); ?></p> |
|
310 | + <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class; ?>" /> |
|
311 | + <p><?php echo (isset($args['desc']) ? $args['desc'] : ''); ?></p> |
|
312 | 312 | <table id="wpinv_vat_rates" class="wp-list-table widefat fixed posts"> |
313 | 313 | <colgroup> |
314 | 314 | <col width="50px" /> |
@@ -320,43 +320,43 @@ discard block |
||
320 | 320 | </colgroup> |
321 | 321 | <thead> |
322 | 322 | <tr> |
323 | - <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e( 'Country', 'invoicing' ); ?></th> |
|
324 | - <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e( 'Apply rate to whole country', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th> |
|
325 | - <th scope="col" class="wpinv_vat_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> |
|
326 | - <th scope="col" class="wpinv_vat_name"><?php _e( 'VAT Name', 'invoicing' ); ?></th> |
|
327 | - <th scope="col" class="wpinv_vat_group"><?php _e( 'Tax Group', 'invoicing' ); ?></th> |
|
323 | + <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e('Country', 'invoicing'); ?></th> |
|
324 | + <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e('Apply rate to whole country', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th> |
|
325 | + <th scope="col" class="wpinv_vat_rate"><?php _e('Rate %', 'invoicing'); ?></th> |
|
326 | + <th scope="col" class="wpinv_vat_name"><?php _e('VAT Name', 'invoicing'); ?></th> |
|
327 | + <th scope="col" class="wpinv_vat_group"><?php _e('Tax Group', 'invoicing'); ?></th> |
|
328 | 328 | </tr> |
329 | 329 | </thead> |
330 | 330 | <tbody> |
331 | - <?php if( !empty( $eu_states ) ) { ?> |
|
331 | + <?php if (!empty($eu_states)) { ?> |
|
332 | 332 | <?php |
333 | - foreach ( $eu_states as $state ) { |
|
334 | - $country_name = isset( $countries[$state] ) ? $countries[$state] : ''; |
|
333 | + foreach ($eu_states as $state) { |
|
334 | + $country_name = isset($countries[$state]) ? $countries[$state] : ''; |
|
335 | 335 | |
336 | 336 | // Filter the rate for each country |
337 | - $country_rate = array_filter( $rates, function( $rate ) use( $state ) { return $rate['country'] === $state; } ); |
|
337 | + $country_rate = array_filter($rates, function($rate) use($state) { return $rate['country'] === $state; } ); |
|
338 | 338 | |
339 | 339 | // If one does not exist create a default |
340 | - $country_rate = is_array( $country_rate ) && count( $country_rate ) > 0 ? reset( $country_rate ) : array(); |
|
340 | + $country_rate = is_array($country_rate) && count($country_rate) > 0 ? reset($country_rate) : array(); |
|
341 | 341 | |
342 | - $vat_global = isset( $country_rate['global'] ) ? !empty( $country_rate['global'] ) : true; |
|
343 | - $vat_rate = isset( $country_rate['rate'] ) ? $country_rate['rate'] : ''; |
|
344 | - $vat_name = !empty( $country_rate['name'] ) ? esc_attr( stripslashes( $country_rate['name'] ) ) : ''; |
|
345 | - $vat_group = !empty( $country_rate['group'] ) ? $country_rate['group'] : ( $vat_class === '_standard' ? 'standard' : 'reduced' ); |
|
342 | + $vat_global = isset($country_rate['global']) ? !empty($country_rate['global']) : true; |
|
343 | + $vat_rate = isset($country_rate['rate']) ? $country_rate['rate'] : ''; |
|
344 | + $vat_name = !empty($country_rate['name']) ? esc_attr(stripslashes($country_rate['name'])) : ''; |
|
345 | + $vat_group = !empty($country_rate['group']) ? $country_rate['group'] : ($vat_class === '_standard' ? 'standard' : 'reduced'); |
|
346 | 346 | ?> |
347 | 347 | <tr> |
348 | 348 | <td class="wpinv_vat_country"><?php echo $state; ?><input type="hidden" name="vat_rates[<?php echo $state; ?>][country]" value="<?php echo $state; ?>" /><input type="hidden" name="vat_rates[<?php echo $state; ?>][state]" value="" /></td> |
349 | 349 | <td class="wpinv_vat_country_name"><?php echo $country_name; ?></td> |
350 | 350 | <td class="wpinv_vat_global"> |
351 | - <input type="checkbox" name="vat_rates[<?php echo $state;?>][global]" id="vat_rates[<?php echo $state;?>][global]" value="1" <?php checked( true, $vat_global );?> disabled="disabled" /> |
|
352 | - <label for="tax_rates[<?php echo $state;?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label> |
|
353 | - <input type="hidden" name="vat_rates[<?php echo $state;?>][global]" value="1" checked="checked" /> |
|
351 | + <input type="checkbox" name="vat_rates[<?php echo $state; ?>][global]" id="vat_rates[<?php echo $state; ?>][global]" value="1" <?php checked(true, $vat_global); ?> disabled="disabled" /> |
|
352 | + <label for="tax_rates[<?php echo $state; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label> |
|
353 | + <input type="hidden" name="vat_rates[<?php echo $state; ?>][global]" value="1" checked="checked" /> |
|
354 | 354 | </td> |
355 | - <td class="wpinv_vat_rate"><input type="number" class="small-text" step="0.10" min="0.00" name="vat_rates[<?php echo $state;?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
356 | - <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state;?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
355 | + <td class="wpinv_vat_rate"><input type="number" class="small-text" step="0.10" min="0.00" name="vat_rates[<?php echo $state; ?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
356 | + <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state; ?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
357 | 357 | <td class="wpinv_vat_group"> |
358 | 358 | <?php |
359 | - echo wpinv_html_select( array( |
|
359 | + echo wpinv_html_select(array( |
|
360 | 360 | 'name' => 'vat_rates[' . $state . '][group]', |
361 | 361 | 'selected' => $vat_group, |
362 | 362 | 'id' => 'vat_rates[' . $state . '][group]', |
@@ -366,14 +366,14 @@ discard block |
||
366 | 366 | 'chosen' => false, |
367 | 367 | 'show_option_all' => false, |
368 | 368 | 'show_option_none' => false |
369 | - ) ); |
|
369 | + )); |
|
370 | 370 | ?> |
371 | 371 | </td> |
372 | 372 | </tr> |
373 | 373 | <?php } ?> |
374 | 374 | <tr> |
375 | 375 | <td colspan="6" style="background-color:#fafafa;"> |
376 | - <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e( 'Update EU VAT Rates', 'invoicing' ); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
376 | + <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e('Update EU VAT Rates', 'invoicing'); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
377 | 377 | </td> |
378 | 378 | </tr> |
379 | 379 | <?php } ?> |
@@ -385,35 +385,35 @@ discard block |
||
385 | 385 | echo $content; |
386 | 386 | } |
387 | 387 | |
388 | -function wpinv_vat_number_callback( $args ) { |
|
388 | +function wpinv_vat_number_callback($args) { |
|
389 | 389 | global $wpinv_euvat; |
390 | 390 | |
391 | 391 | $vat_number = $wpinv_euvat->get_vat_number(); |
392 | 392 | $vat_valid = $wpinv_euvat->is_vat_validated(); |
393 | 393 | |
394 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
395 | - $validated_text = $vat_valid ? __( 'VAT number validated', 'invoicing' ) : __( 'VAT number not validated', 'invoicing' ); |
|
394 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
395 | + $validated_text = $vat_valid ? __('VAT number validated', 'invoicing') : __('VAT number not validated', 'invoicing'); |
|
396 | 396 | $disabled = $vat_valid ? 'disabled="disabled"' : " "; |
397 | 397 | |
398 | - $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr( stripslashes( $vat_number ) ) . '"/>'; |
|
399 | - $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__( 'Validate VAT Number', 'invoicing' ) . '" /></span>'; |
|
398 | + $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr(stripslashes($vat_number)) . '"/>'; |
|
399 | + $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__('Validate VAT Number', 'invoicing') . '" /></span>'; |
|
400 | 400 | $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int)$vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>'; |
401 | - $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __( 'Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing' ).'</p>' . '</label>'; |
|
402 | - $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce( 'vat_validation' ) . '">'; |
|
401 | + $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __('Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing') . '</p>' . '</label>'; |
|
402 | + $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce('vat_validation') . '">'; |
|
403 | 403 | |
404 | 404 | echo $html; |
405 | 405 | } |
406 | 406 | |
407 | -function wpinv_eu_fallback_rate_callback( $args ) { |
|
407 | +function wpinv_eu_fallback_rate_callback($args) { |
|
408 | 408 | global $wpinv_options; |
409 | 409 | |
410 | - $value = isset( $wpinv_options[$args['id']] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : '' ); |
|
411 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'small'; |
|
410 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : ''); |
|
411 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'small'; |
|
412 | 412 | |
413 | - $html = '<input type="number" min="0", max="99.99" step="0.10" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
414 | - $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Add EU Member States', 'invoicing' ) . '" /></span>'; |
|
415 | - $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Remove EU Member States', 'invoicing' ) . '" /></span>'; |
|
416 | - $html .= '<span> <input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__( 'Update EU VAT Rates', 'invoicing' ) . '" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span>'; |
|
413 | + $html = '<input type="number" min="0", max="99.99" step="0.10" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr(stripslashes($value)) . '" />'; |
|
414 | + $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Add EU Member States', 'invoicing') . '" /></span>'; |
|
415 | + $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Remove EU Member States', 'invoicing') . '" /></span>'; |
|
416 | + $html .= '<span> <input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__('Update EU VAT Rates', 'invoicing') . '" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span>'; |
|
417 | 417 | $html .= '<p><label for="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '">' . $args['desc'] . '</label></p>'; |
418 | 418 | echo $html; |
419 | 419 | ?> |
@@ -421,36 +421,36 @@ discard block |
||
421 | 421 | <?php |
422 | 422 | } |
423 | 423 | |
424 | -function wpinv_vat_ip_lookup_callback( $args ) { |
|
424 | +function wpinv_vat_ip_lookup_callback($args) { |
|
425 | 425 | global $wpinv_options, $wpinv_euvat; |
426 | 426 | |
427 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : 'default' ); |
|
427 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : 'default'); |
|
428 | 428 | |
429 | 429 | $options = array(); |
430 | - if ( function_exists( 'geoip_country_code_by_name' ) ) { |
|
431 | - $options['geoip'] = __( 'PHP GeoIP extension', 'invoicing' ); |
|
430 | + if (function_exists('geoip_country_code_by_name')) { |
|
431 | + $options['geoip'] = __('PHP GeoIP extension', 'invoicing'); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | $geoip2_database = $wpinv_euvat->geoip2_country_dbfile(); |
435 | 435 | |
436 | - if ( !function_exists( 'bcadd' ) ) { |
|
437 | - $geoip2_message = __( 'GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing' ); |
|
436 | + if (!function_exists('bcadd')) { |
|
437 | + $geoip2_message = __('GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing'); |
|
438 | 438 | } else { |
439 | - $geoip2_message = ini_get('safe_mode') ? __( 'GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing' ) : ''; |
|
439 | + $geoip2_message = ini_get('safe_mode') ? __('GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing') : ''; |
|
440 | 440 | } |
441 | 441 | |
442 | - if ( $geoip2_database !== false && empty( $geoip2_message ) ) { |
|
443 | - $options['geoip2'] = __( 'GeoIP2 Database', 'invoicing' ); |
|
442 | + if ($geoip2_database !== false && empty($geoip2_message)) { |
|
443 | + $options['geoip2'] = __('GeoIP2 Database', 'invoicing'); |
|
444 | 444 | } |
445 | 445 | |
446 | - if ( function_exists( 'simplexml_load_file' ) ) { |
|
447 | - $options['geoplugin'] = __( 'geoPlugin Web Service', 'invoicing' ); |
|
446 | + if (function_exists('simplexml_load_file')) { |
|
447 | + $options['geoplugin'] = __('geoPlugin Web Service', 'invoicing'); |
|
448 | 448 | } |
449 | 449 | |
450 | - $options['site'] = __( 'Use default country', 'invoicing' ); |
|
451 | - $options['default'] = __( 'Auto', 'invoicing' ); |
|
450 | + $options['site'] = __('Use default country', 'invoicing'); |
|
451 | + $options['default'] = __('Auto', 'invoicing'); |
|
452 | 452 | |
453 | - $html = wpinv_html_select( array( |
|
453 | + $html = wpinv_html_select(array( |
|
454 | 454 | 'name' => "wpinv_settings[{$args['id']}]", |
455 | 455 | 'selected' => $value, |
456 | 456 | 'id' => "wpinv_settings[{$args['id']}]", |
@@ -463,23 +463,23 @@ discard block |
||
463 | 463 | )); |
464 | 464 | |
465 | 465 | $desc = '<label for="wpinv_settings[' . $args['id'] . ']">'; |
466 | - $desc .= __( 'Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing' ); |
|
466 | + $desc .= __('Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing'); |
|
467 | 467 | $desc .= '<p>'; |
468 | - if ( empty( $geoip2_message ) ) { |
|
469 | - if ( $geoip2_database ) { |
|
468 | + if (empty($geoip2_message)) { |
|
469 | + if ($geoip2_database) { |
|
470 | 470 | $last_updated = ''; |
471 | - if ( $time_updated = wpinv_get_option( 'wpinv_geoip2_date_updated' ) ) { |
|
472 | - $date_updated = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $time_updated ); |
|
473 | - $last_updated = '<br>' . sprintf( __( 'The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing' ), $date_updated ); |
|
471 | + if ($time_updated = wpinv_get_option('wpinv_geoip2_date_updated')) { |
|
472 | + $date_updated = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $time_updated); |
|
473 | + $last_updated = '<br>' . sprintf(__('The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing'), $date_updated); |
|
474 | 474 | } |
475 | - $desc .= __( 'GeoIP2 database exists:', 'invoicing' ) . $last_updated . ' <input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __( 'Update GeoIP2 database now (~55MB)', 'invoicing' ) . '"></input>'; |
|
475 | + $desc .= __('GeoIP2 database exists:', 'invoicing') . $last_updated . ' <input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __('Update GeoIP2 database now (~55MB)', 'invoicing') . '"></input>'; |
|
476 | 476 | } else { |
477 | - $desc .= __( 'GeoIP2 database does not exist:', 'invoicing' ) . ' <input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __( 'Download GeoIP2 database now', 'invoicing' ) . ' (~53MB)"></input><br>' . __( 'After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing' ); |
|
477 | + $desc .= __('GeoIP2 database does not exist:', 'invoicing') . ' <input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __('Download GeoIP2 database now', 'invoicing') . ' (~53MB)"></input><br>' . __('After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing'); |
|
478 | 478 | } |
479 | 479 | } else { |
480 | 480 | $desc .= $geoip2_message; |
481 | 481 | } |
482 | - $desc .= '</p><p>'. __( 'GeoPlugin is a great free service please consider supporting them: ', 'invoicing' ) . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>'; |
|
482 | + $desc .= '</p><p>' . __('GeoPlugin is a great free service please consider supporting them: ', 'invoicing') . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>'; |
|
483 | 483 | $desc .= '</label>'; |
484 | 484 | |
485 | 485 | $html .= $desc; |
@@ -1,28 +1,28 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -function wpinv_user_invoices( $current_page = 1 ) { |
|
5 | +function wpinv_user_invoices($current_page = 1) { |
|
6 | 6 | global $current_page; |
7 | - wpinv_get_template_part( 'wpinv-invoice-history' ); |
|
7 | + wpinv_get_template_part('wpinv-invoice-history'); |
|
8 | 8 | } |
9 | 9 | |
10 | -function wpinv_get_users_invoices( $user = 0, $number = 20, $pagination = false, $status = 'complete' ) { |
|
11 | - if ( empty( $user ) ) { |
|
10 | +function wpinv_get_users_invoices($user = 0, $number = 20, $pagination = false, $status = 'complete') { |
|
11 | + if (empty($user)) { |
|
12 | 12 | $user = get_current_user_id(); |
13 | 13 | } |
14 | 14 | |
15 | - if ( 0 === $user ) { |
|
15 | + if (0 === $user) { |
|
16 | 16 | return false; |
17 | 17 | } |
18 | 18 | |
19 | 19 | $status = $status === 'complete' ? 'publish' : $status; |
20 | 20 | |
21 | - if ( $pagination ) { |
|
22 | - if ( get_query_var( 'paged' ) ) |
|
21 | + if ($pagination) { |
|
22 | + if (get_query_var('paged')) |
|
23 | 23 | $paged = get_query_var('paged'); |
24 | - else if ( get_query_var( 'page' ) ) |
|
25 | - $paged = get_query_var( 'page' ); |
|
24 | + else if (get_query_var('page')) |
|
25 | + $paged = get_query_var('page'); |
|
26 | 26 | else |
27 | 27 | $paged = 1; |
28 | 28 | } |
@@ -31,21 +31,21 @@ discard block |
||
31 | 31 | 'post_type' => 'wpi_invoice', |
32 | 32 | 'posts_per_page' => 20, |
33 | 33 | 'paged' => null, |
34 | - 'post_status' => array( 'complete', 'publish', 'pending' ), |
|
34 | + 'post_status' => array('complete', 'publish', 'pending'), |
|
35 | 35 | 'user' => $user, |
36 | 36 | 'order' => 'date', |
37 | 37 | ); |
38 | 38 | |
39 | - $invoices = get_posts( $args ); |
|
39 | + $invoices = get_posts($args); |
|
40 | 40 | |
41 | 41 | // No invoices |
42 | - if ( ! $invoices ) |
|
42 | + if (!$invoices) |
|
43 | 43 | return false; |
44 | 44 | |
45 | 45 | return $invoices; |
46 | 46 | } |
47 | 47 | |
48 | -function wpinv_dropdown_users( $args = '' ) { |
|
48 | +function wpinv_dropdown_users($args = '') { |
|
49 | 49 | $defaults = array( |
50 | 50 | 'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '', |
51 | 51 | 'orderby' => 'display_name', 'order' => 'ASC', |
@@ -56,18 +56,18 @@ discard block |
||
56 | 56 | 'option_none_value' => -1 |
57 | 57 | ); |
58 | 58 | |
59 | - $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0; |
|
59 | + $defaults['selected'] = is_author() ? get_query_var('author') : 0; |
|
60 | 60 | |
61 | - $r = wp_parse_args( $args, $defaults ); |
|
61 | + $r = wp_parse_args($args, $defaults); |
|
62 | 62 | |
63 | - $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) ); |
|
63 | + $query_args = wp_array_slice_assoc($r, array('blog_id', 'include', 'exclude', 'orderby', 'order', 'who')); |
|
64 | 64 | |
65 | - $fields = array( 'ID', 'user_login', 'user_email' ); |
|
65 | + $fields = array('ID', 'user_login', 'user_email'); |
|
66 | 66 | |
67 | - $show = ! empty( $r['show'] ) ? $r['show'] : 'display_name'; |
|
68 | - if ( 'display_name_with_login' === $show ) { |
|
67 | + $show = !empty($r['show']) ? $r['show'] : 'display_name'; |
|
68 | + if ('display_name_with_login' === $show) { |
|
69 | 69 | $fields[] = 'display_name'; |
70 | - } else if ( 'display_name_with_email' === $show ) { |
|
70 | + } else if ('display_name_with_email' === $show) { |
|
71 | 71 | $fields[] = 'display_name'; |
72 | 72 | } else { |
73 | 73 | $fields[] = $show; |
@@ -79,99 +79,99 @@ discard block |
||
79 | 79 | $show_option_none = $r['show_option_none']; |
80 | 80 | $option_none_value = $r['option_none_value']; |
81 | 81 | |
82 | - $query_args = apply_filters( 'wpinv_dropdown_users_args', $query_args, $r ); |
|
82 | + $query_args = apply_filters('wpinv_dropdown_users_args', $query_args, $r); |
|
83 | 83 | |
84 | - $users = get_users( $query_args ); |
|
84 | + $users = get_users($query_args); |
|
85 | 85 | |
86 | 86 | $output = ''; |
87 | - if ( ! empty( $users ) && ( empty( $r['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) { |
|
88 | - $name = esc_attr( $r['name'] ); |
|
89 | - if ( $r['multi'] && ! $r['id'] ) { |
|
87 | + if (!empty($users) && (empty($r['hide_if_only_one_author']) || count($users) > 1)) { |
|
88 | + $name = esc_attr($r['name']); |
|
89 | + if ($r['multi'] && !$r['id']) { |
|
90 | 90 | $id = ''; |
91 | 91 | } else { |
92 | - $id = $r['id'] ? " id='" . esc_attr( $r['id'] ) . "'" : " id='$name'"; |
|
92 | + $id = $r['id'] ? " id='" . esc_attr($r['id']) . "'" : " id='$name'"; |
|
93 | 93 | } |
94 | 94 | $output = "<select name='{$name}'{$id} class='" . $r['class'] . "'>\n"; |
95 | 95 | |
96 | - if ( $show_option_all ) { |
|
96 | + if ($show_option_all) { |
|
97 | 97 | $output .= "\t<option value='0'>$show_option_all</option>\n"; |
98 | 98 | } |
99 | 99 | |
100 | - if ( $show_option_none ) { |
|
101 | - $_selected = selected( $option_none_value, $r['selected'], false ); |
|
102 | - $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n"; |
|
100 | + if ($show_option_none) { |
|
101 | + $_selected = selected($option_none_value, $r['selected'], false); |
|
102 | + $output .= "\t<option value='" . esc_attr($option_none_value) . "'$_selected>$show_option_none</option>\n"; |
|
103 | 103 | } |
104 | 104 | |
105 | - if ( $r['include_selected'] && ( $r['selected'] > 0 ) ) { |
|
105 | + if ($r['include_selected'] && ($r['selected'] > 0)) { |
|
106 | 106 | $found_selected = false; |
107 | - $r['selected'] = (int) $r['selected']; |
|
108 | - foreach ( (array) $users as $user ) { |
|
109 | - $user->ID = (int) $user->ID; |
|
110 | - if ( $user->ID === $r['selected'] ) { |
|
107 | + $r['selected'] = (int)$r['selected']; |
|
108 | + foreach ((array)$users as $user) { |
|
109 | + $user->ID = (int)$user->ID; |
|
110 | + if ($user->ID === $r['selected']) { |
|
111 | 111 | $found_selected = true; |
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
115 | - if ( ! $found_selected ) { |
|
116 | - $users[] = get_userdata( $r['selected'] ); |
|
115 | + if (!$found_selected) { |
|
116 | + $users[] = get_userdata($r['selected']); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | - foreach ( (array) $users as $user ) { |
|
121 | - if ( 'display_name_with_login' === $show ) { |
|
120 | + foreach ((array)$users as $user) { |
|
121 | + if ('display_name_with_login' === $show) { |
|
122 | 122 | /* translators: 1: display name, 2: user_login */ |
123 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login ); |
|
124 | - } elseif ( 'display_name_with_email' === $show ) { |
|
123 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_login); |
|
124 | + } elseif ('display_name_with_email' === $show) { |
|
125 | 125 | /* translators: 1: display name, 2: user_email */ |
126 | - if ( $user->display_name == $user->user_email ) { |
|
126 | + if ($user->display_name == $user->user_email) { |
|
127 | 127 | $display = $user->display_name; |
128 | 128 | } else { |
129 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_email ); |
|
129 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_email); |
|
130 | 130 | } |
131 | - } elseif ( ! empty( $user->$show ) ) { |
|
131 | + } elseif (!empty($user->$show)) { |
|
132 | 132 | $display = $user->$show; |
133 | 133 | } else { |
134 | 134 | $display = '(' . $user->user_login . ')'; |
135 | 135 | } |
136 | 136 | |
137 | - $_selected = selected( $user->ID, $r['selected'], false ); |
|
138 | - $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n"; |
|
137 | + $_selected = selected($user->ID, $r['selected'], false); |
|
138 | + $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n"; |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | $output .= "</select>"; |
142 | 142 | } |
143 | 143 | |
144 | - $html = apply_filters( 'wpinv_dropdown_users', $output ); |
|
144 | + $html = apply_filters('wpinv_dropdown_users', $output); |
|
145 | 145 | |
146 | - if ( $r['echo'] ) { |
|
146 | + if ($r['echo']) { |
|
147 | 147 | echo $html; |
148 | 148 | } |
149 | 149 | return $html; |
150 | 150 | } |
151 | 151 | |
152 | -function wpinv_guest_redirect( $redirect_to, $user_id = 0 ) { |
|
153 | - if ( (int)wpinv_get_option( 'guest_checkout' ) && $user_id > 0 ) { |
|
154 | - wpinv_login_user( $user_id ); |
|
152 | +function wpinv_guest_redirect($redirect_to, $user_id = 0) { |
|
153 | + if ((int)wpinv_get_option('guest_checkout') && $user_id > 0) { |
|
154 | + wpinv_login_user($user_id); |
|
155 | 155 | } else { |
156 | - $redirect_to = wp_login_url( $redirect_to ); |
|
156 | + $redirect_to = wp_login_url($redirect_to); |
|
157 | 157 | } |
158 | 158 | |
159 | - $redirect_to = apply_filters( 'wpinv_invoice_link_guest_redirect', $redirect_to, $user_id ); |
|
159 | + $redirect_to = apply_filters('wpinv_invoice_link_guest_redirect', $redirect_to, $user_id); |
|
160 | 160 | |
161 | - wp_redirect( $redirect_to ); |
|
161 | + wp_redirect($redirect_to); |
|
162 | 162 | } |
163 | 163 | |
164 | -function wpinv_login_user( $user_id ) { |
|
165 | - if ( is_user_logged_in() ) { |
|
164 | +function wpinv_login_user($user_id) { |
|
165 | + if (is_user_logged_in()) { |
|
166 | 166 | return true; |
167 | 167 | } |
168 | 168 | |
169 | - $user = get_user_by( 'id', $user_id ); |
|
169 | + $user = get_user_by('id', $user_id); |
|
170 | 170 | |
171 | - if ( !empty( $user ) && !is_wp_error( $user ) && !empty( $user->user_login ) ) { |
|
172 | - wp_set_current_user( $user_id, $user->user_login ); |
|
173 | - wp_set_auth_cookie( $user_id ); |
|
174 | - do_action( 'wp_login', $user->user_login ); |
|
171 | + if (!empty($user) && !is_wp_error($user) && !empty($user->user_login)) { |
|
172 | + wp_set_current_user($user_id, $user->user_login); |
|
173 | + wp_set_auth_cookie($user_id); |
|
174 | + do_action('wp_login', $user->user_login); |
|
175 | 175 | |
176 | 176 | return true; |
177 | 177 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -function wpinv_get_subscriptions( $args = array() ) { |
|
3 | - if ( empty( $args['parent_invoice_id'] ) ) { |
|
2 | +function wpinv_get_subscriptions($args = array()) { |
|
3 | + if (empty($args['parent_invoice_id'])) { |
|
4 | 4 | return false; |
5 | 5 | } |
6 | 6 | |
@@ -14,18 +14,18 @@ discard block |
||
14 | 14 | ); |
15 | 15 | |
16 | 16 | $args['post_parent'] = $args['parent_invoice_id']; |
17 | - $args = wp_parse_args( $args, $defaults ); |
|
17 | + $args = wp_parse_args($args, $defaults); |
|
18 | 18 | |
19 | - if( $args['numberposts'] < 1 ) { |
|
19 | + if ($args['numberposts'] < 1) { |
|
20 | 20 | $args['numberposts'] = 999999999999; |
21 | 21 | } |
22 | 22 | |
23 | - $posts = get_posts( $args ); |
|
23 | + $posts = get_posts($args); |
|
24 | 24 | $subscriptions = array(); |
25 | - if ( !empty( $posts ) ) { |
|
26 | - foreach ( $posts as $post ) { |
|
27 | - if ( !empty( $post->ID ) ) { |
|
28 | - $subscriptions[] = wpinv_get_invoice( $post->ID ); |
|
25 | + if (!empty($posts)) { |
|
26 | + foreach ($posts as $post) { |
|
27 | + if (!empty($post->ID)) { |
|
28 | + $subscriptions[] = wpinv_get_invoice($post->ID); |
|
29 | 29 | } |
30 | 30 | } |
31 | 31 | } |
@@ -33,19 +33,19 @@ discard block |
||
33 | 33 | |
34 | 34 | return $subscriptions; |
35 | 35 | } |
36 | -function wpinv_get_subscription( $id = 0, $by_profile_id = false ) { |
|
36 | +function wpinv_get_subscription($id = 0, $by_profile_id = false) { |
|
37 | 37 | global $wpdb; |
38 | 38 | |
39 | - if ( empty( $id ) ) { |
|
39 | + if (empty($id)) { |
|
40 | 40 | return false; |
41 | 41 | } |
42 | 42 | |
43 | - $id = esc_sql( $id ); |
|
43 | + $id = esc_sql($id); |
|
44 | 44 | |
45 | - $invoice_id = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_profile_id' AND meta_value = '{$id}' LIMIT 1" ); |
|
45 | + $invoice_id = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_profile_id' AND meta_value = '{$id}' LIMIT 1"); |
|
46 | 46 | |
47 | - if ( $invoice_id != null ) { |
|
48 | - return wpinv_get_invoice( $invoice_id ); |
|
47 | + if ($invoice_id != null) { |
|
48 | + return wpinv_get_invoice($invoice_id); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | return false; |
@@ -55,49 +55,49 @@ discard block |
||
55 | 55 | * Records a new payment on the subscription |
56 | 56 | * |
57 | 57 | */ |
58 | -function wpinv_recurring_add_subscription_payment( $parent_invoice_id, $subscription_args = array() ) { |
|
59 | - $args = wp_parse_args( $subscription_args, array( |
|
58 | +function wpinv_recurring_add_subscription_payment($parent_invoice_id, $subscription_args = array()) { |
|
59 | + $args = wp_parse_args($subscription_args, array( |
|
60 | 60 | 'amount' => '', |
61 | 61 | 'transaction_id' => '', |
62 | 62 | 'gateway' => '' |
63 | - ) ); |
|
63 | + )); |
|
64 | 64 | |
65 | - if ( wpinv_payment_exists( $args['transaction_id'] ) ) { |
|
65 | + if (wpinv_payment_exists($args['transaction_id'])) { |
|
66 | 66 | return false; |
67 | 67 | } |
68 | 68 | |
69 | - $parent_invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
70 | - if ( empty( $parent_invoice ) ) { |
|
69 | + $parent_invoice = wpinv_get_invoice($parent_invoice_id); |
|
70 | + if (empty($parent_invoice)) { |
|
71 | 71 | return; |
72 | 72 | } |
73 | 73 | |
74 | 74 | $invoice = new WPInv_Invoice(); |
75 | - $invoice->set( 'parent_invoice', $parent_invoice_id ); |
|
76 | - $invoice->set( 'currency', $parent_invoice->get_currency() ); |
|
75 | + $invoice->set('parent_invoice', $parent_invoice_id); |
|
76 | + $invoice->set('currency', $parent_invoice->get_currency()); |
|
77 | 77 | //$invoice->set( 'status', 'publish' ); |
78 | - $invoice->set( 'transaction_id', $args['transaction_id'] ); |
|
79 | - $invoice->set( 'key', $parent_invoice->get_key() ); |
|
78 | + $invoice->set('transaction_id', $args['transaction_id']); |
|
79 | + $invoice->set('key', $parent_invoice->get_key()); |
|
80 | 80 | |
81 | - $invoice->set( 'ip', $parent_invoice->ip ); |
|
82 | - $invoice->set( 'user_id', $parent_invoice->get_user_id() ); |
|
83 | - $invoice->set( 'first_name', $parent_invoice->get_first_name() ); |
|
84 | - $invoice->set( 'last_name', $parent_invoice->get_last_name() ); |
|
81 | + $invoice->set('ip', $parent_invoice->ip); |
|
82 | + $invoice->set('user_id', $parent_invoice->get_user_id()); |
|
83 | + $invoice->set('first_name', $parent_invoice->get_first_name()); |
|
84 | + $invoice->set('last_name', $parent_invoice->get_last_name()); |
|
85 | 85 | ///$invoice->set( 'email', $parent_invoice->get_email() ); |
86 | - $invoice->set( 'phone', $parent_invoice->phone ); |
|
87 | - $invoice->set( 'address', $parent_invoice->address ); |
|
88 | - $invoice->set( 'city', $parent_invoice->city ); |
|
89 | - $invoice->set( 'country', $parent_invoice->country ); |
|
90 | - $invoice->set( 'state', $parent_invoice->state ); |
|
91 | - $invoice->set( 'zip', $parent_invoice->zip ); |
|
92 | - $invoice->set( 'company', $parent_invoice->company ); |
|
93 | - $invoice->set( 'vat_number', $parent_invoice->vat_number ); |
|
94 | - $invoice->set( 'vat_rate', $parent_invoice->vat_rate ); |
|
95 | - $invoice->set( 'adddress_confirmed', $parent_invoice->adddress_confirmed ); |
|
96 | - |
|
97 | - if ( empty( $args['gateway'] ) ) { |
|
98 | - $invoice->set( 'gateway', $parent_invoice->get_gateway() ); |
|
86 | + $invoice->set('phone', $parent_invoice->phone); |
|
87 | + $invoice->set('address', $parent_invoice->address); |
|
88 | + $invoice->set('city', $parent_invoice->city); |
|
89 | + $invoice->set('country', $parent_invoice->country); |
|
90 | + $invoice->set('state', $parent_invoice->state); |
|
91 | + $invoice->set('zip', $parent_invoice->zip); |
|
92 | + $invoice->set('company', $parent_invoice->company); |
|
93 | + $invoice->set('vat_number', $parent_invoice->vat_number); |
|
94 | + $invoice->set('vat_rate', $parent_invoice->vat_rate); |
|
95 | + $invoice->set('adddress_confirmed', $parent_invoice->adddress_confirmed); |
|
96 | + |
|
97 | + if (empty($args['gateway'])) { |
|
98 | + $invoice->set('gateway', $parent_invoice->get_gateway()); |
|
99 | 99 | } else { |
100 | - $invoice->set( 'gateway', $args['gateway'] ); |
|
100 | + $invoice->set('gateway', $args['gateway']); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | $recurring_details = $parent_invoice->get_recurring_details(); |
@@ -105,11 +105,11 @@ discard block |
||
105 | 105 | // increase the earnings for each item in the subscription |
106 | 106 | $items = $recurring_details['cart_details']; |
107 | 107 | |
108 | - if ( $items ) { |
|
108 | + if ($items) { |
|
109 | 109 | $add_items = array(); |
110 | 110 | $cart_details = array(); |
111 | 111 | |
112 | - foreach ( $items as $item ) { |
|
112 | + foreach ($items as $item) { |
|
113 | 113 | $add_item = array(); |
114 | 114 | $add_item['id'] = $item['id']; |
115 | 115 | $add_item['quantity'] = $item['quantity']; |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | break; |
120 | 120 | } |
121 | 121 | |
122 | - $invoice->set( 'items', $add_items ); |
|
122 | + $invoice->set('items', $add_items); |
|
123 | 123 | $invoice->cart_details = $cart_details; |
124 | 124 | } |
125 | 125 | |
@@ -129,277 +129,277 @@ discard block |
||
129 | 129 | $tax = $recurring_details['tax']; |
130 | 130 | $discount = $recurring_details['discount']; |
131 | 131 | |
132 | - if ( $discount > 0 ) { |
|
133 | - $invoice->set( 'discount_code', $parent_invoice->discount_code ); |
|
132 | + if ($discount > 0) { |
|
133 | + $invoice->set('discount_code', $parent_invoice->discount_code); |
|
134 | 134 | } |
135 | 135 | |
136 | - $invoice->subtotal = wpinv_format_amount( $subtotal, NULL, true ); |
|
137 | - $invoice->tax = wpinv_format_amount( $tax, NULL, true ); |
|
138 | - $invoice->discount = wpinv_format_amount( $discount, NULL, true ); |
|
139 | - $invoice->total = wpinv_format_amount( $total, NULL, true ); |
|
136 | + $invoice->subtotal = wpinv_format_amount($subtotal, NULL, true); |
|
137 | + $invoice->tax = wpinv_format_amount($tax, NULL, true); |
|
138 | + $invoice->discount = wpinv_format_amount($discount, NULL, true); |
|
139 | + $invoice->total = wpinv_format_amount($total, NULL, true); |
|
140 | 140 | $invoice->save(); |
141 | 141 | |
142 | - wpinv_update_payment_status( $invoice->ID, 'publish' ); |
|
142 | + wpinv_update_payment_status($invoice->ID, 'publish'); |
|
143 | 143 | sleep(1); |
144 | - wpinv_update_payment_status( $invoice->ID, 'renewal' ); |
|
144 | + wpinv_update_payment_status($invoice->ID, 'renewal'); |
|
145 | 145 | |
146 | - $invoice = wpinv_get_invoice( $invoice->ID ); |
|
146 | + $invoice = wpinv_get_invoice($invoice->ID); |
|
147 | 147 | |
148 | - $subscription_data = wpinv_payment_subscription_data( $parent_invoice ); |
|
148 | + $subscription_data = wpinv_payment_subscription_data($parent_invoice); |
|
149 | 149 | $subscription_data['recurring_amount'] = $invoice->get_total(); |
150 | - $subscription_data['created'] = current_time( 'mysql', 0 ); |
|
151 | - $subscription_data['expiration'] = $invoice->get_new_expiration( $subscription_data['item_id'] ); |
|
150 | + $subscription_data['created'] = current_time('mysql', 0); |
|
151 | + $subscription_data['expiration'] = $invoice->get_new_expiration($subscription_data['item_id']); |
|
152 | 152 | |
153 | 153 | // Retrieve pending subscription from database and update it's status to active and set proper profile ID |
154 | - $invoice->update_subscription( $subscription_data ); |
|
154 | + $invoice->update_subscription($subscription_data); |
|
155 | 155 | |
156 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args ); |
|
157 | - do_action( 'wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args ); |
|
156 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args); |
|
157 | + do_action('wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args); |
|
158 | 158 | |
159 | 159 | return $invoice; |
160 | 160 | } |
161 | 161 | |
162 | -function wpinv_payment_exists( $txn_id = '' ) { |
|
162 | +function wpinv_payment_exists($txn_id = '') { |
|
163 | 163 | global $wpdb; |
164 | 164 | |
165 | - if ( empty( $txn_id ) ) { |
|
165 | + if (empty($txn_id)) { |
|
166 | 166 | return false; |
167 | 167 | } |
168 | 168 | |
169 | - $txn_id = esc_sql( $txn_id ); |
|
169 | + $txn_id = esc_sql($txn_id); |
|
170 | 170 | |
171 | - $invoice = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1" ); |
|
171 | + $invoice = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1"); |
|
172 | 172 | |
173 | - if ( $invoice != null ) { |
|
173 | + if ($invoice != null) { |
|
174 | 174 | return true; |
175 | 175 | } |
176 | 176 | |
177 | 177 | return false; |
178 | 178 | } |
179 | 179 | |
180 | -function wpinv_is_subscription_payment( $invoice = '' ) { |
|
181 | - if ( empty( $invoice ) ) { |
|
180 | +function wpinv_is_subscription_payment($invoice = '') { |
|
181 | + if (empty($invoice)) { |
|
182 | 182 | return false; |
183 | 183 | } |
184 | 184 | |
185 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
186 | - $invoice = wpinv_get_invoice( $invoice ); |
|
185 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
186 | + $invoice = wpinv_get_invoice($invoice); |
|
187 | 187 | } |
188 | 188 | |
189 | - if ( empty( $invoice ) ) { |
|
189 | + if (empty($invoice)) { |
|
190 | 190 | return false; |
191 | 191 | } |
192 | 192 | |
193 | - if ( $invoice->is_renewal() ) { |
|
193 | + if ($invoice->is_renewal()) { |
|
194 | 194 | return true; |
195 | 195 | } |
196 | 196 | |
197 | 197 | return false; |
198 | 198 | } |
199 | 199 | |
200 | -function wpinv_payment_subscription_data( $invoice = '' ) { |
|
201 | - if ( empty( $invoice ) ) { |
|
200 | +function wpinv_payment_subscription_data($invoice = '') { |
|
201 | + if (empty($invoice)) { |
|
202 | 202 | return false; |
203 | 203 | } |
204 | 204 | |
205 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
206 | - $invoice = wpinv_get_invoice( $invoice ); |
|
205 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
206 | + $invoice = wpinv_get_invoice($invoice); |
|
207 | 207 | } |
208 | 208 | |
209 | - if ( empty( $invoice ) ) { |
|
209 | + if (empty($invoice)) { |
|
210 | 210 | return false; |
211 | 211 | } |
212 | 212 | |
213 | 213 | return $invoice->get_subscription_data(); |
214 | 214 | } |
215 | 215 | |
216 | -function wpinv_payment_link_transaction_id( $invoice = '' ) { |
|
217 | - if ( empty( $invoice ) ) { |
|
216 | +function wpinv_payment_link_transaction_id($invoice = '') { |
|
217 | + if (empty($invoice)) { |
|
218 | 218 | return false; |
219 | 219 | } |
220 | 220 | |
221 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
222 | - $invoice = wpinv_get_invoice( $invoice ); |
|
221 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
222 | + $invoice = wpinv_get_invoice($invoice); |
|
223 | 223 | } |
224 | 224 | |
225 | - if ( empty( $invoice ) ) { |
|
225 | + if (empty($invoice)) { |
|
226 | 226 | return false; |
227 | 227 | } |
228 | 228 | |
229 | - return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice ); |
|
229 | + return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice); |
|
230 | 230 | } |
231 | 231 | |
232 | -function wpinv_get_pretty_subscription_period( $period ) { |
|
232 | +function wpinv_get_pretty_subscription_period($period) { |
|
233 | 233 | $frequency = ''; |
234 | 234 | //Format period details |
235 | - switch ( $period ) { |
|
235 | + switch ($period) { |
|
236 | 236 | case 'D' : |
237 | 237 | case 'day' : |
238 | - $frequency = __( 'Daily', 'invoicing' ); |
|
238 | + $frequency = __('Daily', 'invoicing'); |
|
239 | 239 | break; |
240 | 240 | case 'W' : |
241 | 241 | case 'week' : |
242 | - $frequency = __( 'Weekly', 'invoicing' ); |
|
242 | + $frequency = __('Weekly', 'invoicing'); |
|
243 | 243 | break; |
244 | 244 | case 'M' : |
245 | 245 | case 'month' : |
246 | - $frequency = __( 'Monthly', 'invoicing' ); |
|
246 | + $frequency = __('Monthly', 'invoicing'); |
|
247 | 247 | break; |
248 | 248 | case 'Y' : |
249 | 249 | case 'year' : |
250 | - $frequency = __( 'Yearly', 'invoicing' ); |
|
250 | + $frequency = __('Yearly', 'invoicing'); |
|
251 | 251 | break; |
252 | 252 | default : |
253 | - $frequency = apply_filters( 'wpinv_pretty_subscription_period', $frequency, $period ); |
|
253 | + $frequency = apply_filters('wpinv_pretty_subscription_period', $frequency, $period); |
|
254 | 254 | break; |
255 | 255 | } |
256 | 256 | |
257 | 257 | return $frequency; |
258 | 258 | } |
259 | 259 | |
260 | -function wpinv_get_pretty_subscription_period_name( $period ) { |
|
260 | +function wpinv_get_pretty_subscription_period_name($period) { |
|
261 | 261 | $frequency = ''; |
262 | 262 | //Format period details |
263 | - switch ( $period ) { |
|
263 | + switch ($period) { |
|
264 | 264 | case 'D' : |
265 | 265 | case 'day' : |
266 | - $frequency = __( 'Day', 'invoicing' ); |
|
266 | + $frequency = __('Day', 'invoicing'); |
|
267 | 267 | break; |
268 | 268 | case 'W' : |
269 | 269 | case 'week' : |
270 | - $frequency = __( 'Week', 'invoicing' ); |
|
270 | + $frequency = __('Week', 'invoicing'); |
|
271 | 271 | break; |
272 | 272 | case 'M' : |
273 | 273 | case 'month' : |
274 | - $frequency = __( 'Month', 'invoicing' ); |
|
274 | + $frequency = __('Month', 'invoicing'); |
|
275 | 275 | break; |
276 | 276 | case 'Y' : |
277 | 277 | case 'year' : |
278 | - $frequency = __( 'Year', 'invoicing' ); |
|
278 | + $frequency = __('Year', 'invoicing'); |
|
279 | 279 | break; |
280 | 280 | default : |
281 | - $frequency = apply_filters( 'wpinv_pretty_subscription_period_name', $frequency, $period ); |
|
281 | + $frequency = apply_filters('wpinv_pretty_subscription_period_name', $frequency, $period); |
|
282 | 282 | break; |
283 | 283 | } |
284 | 284 | |
285 | 285 | return $frequency; |
286 | 286 | } |
287 | 287 | |
288 | -function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) { |
|
288 | +function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) { |
|
289 | 289 | $interval = (int)$interval > 0 ? (int)$interval : 1; |
290 | 290 | |
291 | - if ( $trial_interval > 0 && !empty( $trial_period ) ) { |
|
292 | - $amount = __( 'Free', 'invoicing' ); |
|
291 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
292 | + $amount = __('Free', 'invoicing'); |
|
293 | 293 | $interval = $trial_interval; |
294 | 294 | $period = $trial_period; |
295 | 295 | } |
296 | 296 | |
297 | 297 | $description = ''; |
298 | - switch ( $period ) { |
|
298 | + switch ($period) { |
|
299 | 299 | case 'D' : |
300 | 300 | case 'day' : |
301 | - $description = wp_sprintf( _n( '%s for the first day.', '%s for the first %d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
301 | + $description = wp_sprintf(_n('%s for the first day.', '%s for the first %d days.', $interval, 'invoicing'), $amount, $interval); |
|
302 | 302 | break; |
303 | 303 | case 'W' : |
304 | 304 | case 'week' : |
305 | - $description = wp_sprintf( _n( '%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
305 | + $description = wp_sprintf(_n('%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
306 | 306 | break; |
307 | 307 | case 'M' : |
308 | 308 | case 'month' : |
309 | - $description = wp_sprintf( _n( '%s for the first month.', '%s for the first %d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
309 | + $description = wp_sprintf(_n('%s for the first month.', '%s for the first %d months.', $interval, 'invoicing'), $amount, $interval); |
|
310 | 310 | break; |
311 | 311 | case 'Y' : |
312 | 312 | case 'year' : |
313 | - $description = wp_sprintf( _n( '%s for the first year.', '%s for the first %d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
313 | + $description = wp_sprintf(_n('%s for the first year.', '%s for the first %d years.', $interval, 'invoicing'), $amount, $interval); |
|
314 | 314 | break; |
315 | 315 | } |
316 | 316 | |
317 | - return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval ); |
|
317 | + return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval); |
|
318 | 318 | } |
319 | 319 | |
320 | -function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) { |
|
320 | +function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) { |
|
321 | 321 | $interval = (int)$interval > 0 ? (int)$interval : 1; |
322 | 322 | $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0; |
323 | 323 | |
324 | 324 | $description = ''; |
325 | - switch ( $period ) { |
|
325 | + switch ($period) { |
|
326 | 326 | case 'D' : |
327 | 327 | case 'day' : |
328 | - if ( (int)$bill_times > 0 ) { |
|
329 | - if ( $interval > 1 ) { |
|
330 | - if ( $bill_times > 1 ) { |
|
331 | - $description = wp_sprintf( __( '%s for each %d days, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
328 | + if ((int)$bill_times > 0) { |
|
329 | + if ($interval > 1) { |
|
330 | + if ($bill_times > 1) { |
|
331 | + $description = wp_sprintf(__('%s for each %d days, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
332 | 332 | } else { |
333 | - $description = wp_sprintf( __( '%s for %d days.', 'invoicing' ), $amount, $interval ); |
|
333 | + $description = wp_sprintf(__('%s for %d days.', 'invoicing'), $amount, $interval); |
|
334 | 334 | } |
335 | 335 | } else { |
336 | - $description = wp_sprintf( _n( '%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
336 | + $description = wp_sprintf(_n('%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
337 | 337 | } |
338 | 338 | } else { |
339 | - $description = wp_sprintf( _n( '%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval ); |
|
339 | + $description = wp_sprintf(_n('%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval); |
|
340 | 340 | } |
341 | 341 | break; |
342 | 342 | case 'W' : |
343 | 343 | case 'week' : |
344 | - if ( (int)$bill_times > 0 ) { |
|
345 | - if ( $interval > 1 ) { |
|
346 | - if ( $bill_times > 1 ) { |
|
347 | - $description = wp_sprintf( __( '%s for each %d weeks, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
344 | + if ((int)$bill_times > 0) { |
|
345 | + if ($interval > 1) { |
|
346 | + if ($bill_times > 1) { |
|
347 | + $description = wp_sprintf(__('%s for each %d weeks, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
348 | 348 | } else { |
349 | - $description = wp_sprintf( __( '%s for %d weeks.', 'invoicing' ), $amount, $interval ); |
|
349 | + $description = wp_sprintf(__('%s for %d weeks.', 'invoicing'), $amount, $interval); |
|
350 | 350 | } |
351 | 351 | } else { |
352 | - $description = wp_sprintf( _n( '%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
352 | + $description = wp_sprintf(_n('%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
353 | 353 | } |
354 | 354 | } else { |
355 | - $description = wp_sprintf( _n( '%s for each week.', '%s for each %d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
355 | + $description = wp_sprintf(_n('%s for each week.', '%s for each %d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
356 | 356 | } |
357 | 357 | break; |
358 | 358 | case 'M' : |
359 | 359 | case 'month' : |
360 | - if ( (int)$bill_times > 0 ) { |
|
361 | - if ( $interval > 1 ) { |
|
362 | - if ( $bill_times > 1 ) { |
|
363 | - $description = wp_sprintf( __( '%s for each %d months, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
360 | + if ((int)$bill_times > 0) { |
|
361 | + if ($interval > 1) { |
|
362 | + if ($bill_times > 1) { |
|
363 | + $description = wp_sprintf(__('%s for each %d months, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
364 | 364 | } else { |
365 | - $description = wp_sprintf( __( '%s for %d months.', 'invoicing' ), $amount, $interval ); |
|
365 | + $description = wp_sprintf(__('%s for %d months.', 'invoicing'), $amount, $interval); |
|
366 | 366 | } |
367 | 367 | } else { |
368 | - $description = wp_sprintf( _n( '%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
368 | + $description = wp_sprintf(_n('%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
369 | 369 | } |
370 | 370 | } else { |
371 | - $description = wp_sprintf( _n( '%s for each month.', '%s for each %d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
371 | + $description = wp_sprintf(_n('%s for each month.', '%s for each %d months.', $interval, 'invoicing'), $amount, $interval); |
|
372 | 372 | } |
373 | 373 | break; |
374 | 374 | case 'Y' : |
375 | 375 | case 'year' : |
376 | - if ( (int)$bill_times > 0 ) { |
|
377 | - if ( $interval > 1 ) { |
|
378 | - if ( $bill_times > 1 ) { |
|
379 | - $description = wp_sprintf( __( '%s for each %d years, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
376 | + if ((int)$bill_times > 0) { |
|
377 | + if ($interval > 1) { |
|
378 | + if ($bill_times > 1) { |
|
379 | + $description = wp_sprintf(__('%s for each %d years, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
380 | 380 | } else { |
381 | - $description = wp_sprintf( __( '%s for %d years.', 'invoicing'), $amount, $interval ); |
|
381 | + $description = wp_sprintf(__('%s for %d years.', 'invoicing'), $amount, $interval); |
|
382 | 382 | } |
383 | 383 | } else { |
384 | - $description = wp_sprintf( _n( '%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
384 | + $description = wp_sprintf(_n('%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
385 | 385 | } |
386 | 386 | } else { |
387 | - $description = wp_sprintf( _n( '%s for each year.', '%s for each %d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
387 | + $description = wp_sprintf(_n('%s for each year.', '%s for each %d years.', $interval, 'invoicing'), $amount, $interval); |
|
388 | 388 | } |
389 | 389 | break; |
390 | 390 | } |
391 | 391 | |
392 | - return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
392 | + return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
393 | 393 | } |
394 | 394 | |
395 | -function wpinv_subscription_payment_desc( $invoice ) { |
|
396 | - if ( empty( $invoice ) ) { |
|
395 | +function wpinv_subscription_payment_desc($invoice) { |
|
396 | + if (empty($invoice)) { |
|
397 | 397 | return NULL; |
398 | 398 | } |
399 | 399 | |
400 | 400 | $description = ''; |
401 | - if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) { |
|
402 | - if ( $item->has_free_trial() ) { |
|
401 | + if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) { |
|
402 | + if ($item->has_free_trial()) { |
|
403 | 403 | $trial_period = $item->get_trial_period(); |
404 | 404 | $trial_interval = $item->get_trial_interval(); |
405 | 405 | } else { |
@@ -407,45 +407,45 @@ discard block |
||
407 | 407 | $trial_interval = 0; |
408 | 408 | } |
409 | 409 | |
410 | - $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() ); |
|
410 | + $description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency()); |
|
411 | 411 | } |
412 | 412 | |
413 | - return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice ); |
|
413 | + return apply_filters('wpinv_subscription_payment_desc', $description, $invoice); |
|
414 | 414 | } |
415 | 415 | |
416 | -function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) { |
|
417 | - $initial_total = wpinv_format_amount( $initial ); |
|
418 | - $recurring_total = wpinv_format_amount( $recurring ); |
|
416 | +function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') { |
|
417 | + $initial_total = wpinv_format_amount($initial); |
|
418 | + $recurring_total = wpinv_format_amount($recurring); |
|
419 | 419 | |
420 | - if ( $trial_interval > 0 && !empty( $trial_period ) ) { |
|
420 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
421 | 421 | // Free trial |
422 | 422 | } else { |
423 | - if ( $bill_times == 1 ) { |
|
423 | + if ($bill_times == 1) { |
|
424 | 424 | $recurring_total = $initial_total; |
425 | - } else if ( $bill_times > 1 && $initial_total != $recurring_total ) { |
|
425 | + } else if ($bill_times > 1 && $initial_total != $recurring_total) { |
|
426 | 426 | $bill_times--; |
427 | 427 | } |
428 | 428 | } |
429 | 429 | |
430 | - $initial_amount = wpinv_price( $initial_total, $currency ); |
|
431 | - $recurring_amount = wpinv_price( $recurring_total, $currency ); |
|
430 | + $initial_amount = wpinv_price($initial_total, $currency); |
|
431 | + $recurring_amount = wpinv_price($recurring_total, $currency); |
|
432 | 432 | |
433 | - $recurring = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
433 | + $recurring = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
434 | 434 | |
435 | - if ( $initial_total != $recurring_total ) { |
|
436 | - $initial = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval ); |
|
435 | + if ($initial_total != $recurring_total) { |
|
436 | + $initial = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval); |
|
437 | 437 | |
438 | - $description = wp_sprintf( __( '%s Then %s', 'invoicing' ), $initial, $recurring ); |
|
438 | + $description = wp_sprintf(__('%s Then %s', 'invoicing'), $initial, $recurring); |
|
439 | 439 | } else { |
440 | 440 | $description = $recurring; |
441 | 441 | } |
442 | 442 | |
443 | - return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency ); |
|
443 | + return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency); |
|
444 | 444 | } |
445 | 445 | |
446 | -function wpinv_recurring_send_payment_failed( $invoice ) { |
|
447 | - if ( !empty( $invoice->ID ) ) { |
|
448 | - wpinv_failed_invoice_notification( $invoice->ID ); |
|
446 | +function wpinv_recurring_send_payment_failed($invoice) { |
|
447 | + if (!empty($invoice->ID)) { |
|
448 | + wpinv_failed_invoice_notification($invoice->ID); |
|
449 | 449 | } |
450 | 450 | } |
451 | -add_action( 'wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1 ); |
|
452 | 451 | \ No newline at end of file |
452 | +add_action('wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1); |
|
453 | 453 | \ No newline at end of file |
@@ -7,36 +7,36 @@ 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 | -add_action( 'init', 'wpinv_register_post_types', 1 ); |
|
14 | +add_action('init', 'wpinv_register_post_types', 1); |
|
15 | 15 | function wpinv_register_post_types() { |
16 | 16 | $labels = array( |
17 | - 'name' => _x( 'Invoices', 'post type general name', 'invoicing' ), |
|
18 | - 'singular_name' => _x( 'Invoice', 'post type singular name', 'invoicing' ), |
|
19 | - 'menu_name' => _x( 'Invoices', 'admin menu', 'invoicing' ), |
|
20 | - 'name_admin_bar' => _x( 'Invoice', 'add new on admin bar', 'invoicing' ), |
|
21 | - 'add_new' => _x( 'Add New', 'book', 'invoicing' ), |
|
22 | - 'add_new_item' => __( 'Add New Invoice', 'invoicing' ), |
|
23 | - 'new_item' => __( 'New Invoice', 'invoicing' ), |
|
24 | - 'edit_item' => __( 'Edit Invoice', 'invoicing' ), |
|
25 | - 'view_item' => __( 'View Invoice', 'invoicing' ), |
|
26 | - 'all_items' => __( 'Invoices', 'invoicing' ), |
|
27 | - 'search_items' => __( 'Search Invoices', 'invoicing' ), |
|
28 | - 'parent_item_colon' => __( 'Parent Invoices:', 'invoicing' ), |
|
29 | - 'not_found' => __( 'No invoices found.', 'invoicing' ), |
|
30 | - 'not_found_in_trash' => __( 'No invoices found in trash.', 'invoicing' ) |
|
17 | + 'name' => _x('Invoices', 'post type general name', 'invoicing'), |
|
18 | + 'singular_name' => _x('Invoice', 'post type singular name', 'invoicing'), |
|
19 | + 'menu_name' => _x('Invoices', 'admin menu', 'invoicing'), |
|
20 | + 'name_admin_bar' => _x('Invoice', 'add new on admin bar', 'invoicing'), |
|
21 | + 'add_new' => _x('Add New', 'book', 'invoicing'), |
|
22 | + 'add_new_item' => __('Add New Invoice', 'invoicing'), |
|
23 | + 'new_item' => __('New Invoice', 'invoicing'), |
|
24 | + 'edit_item' => __('Edit Invoice', 'invoicing'), |
|
25 | + 'view_item' => __('View Invoice', 'invoicing'), |
|
26 | + 'all_items' => __('Invoices', 'invoicing'), |
|
27 | + 'search_items' => __('Search Invoices', 'invoicing'), |
|
28 | + 'parent_item_colon' => __('Parent Invoices:', 'invoicing'), |
|
29 | + 'not_found' => __('No invoices found.', 'invoicing'), |
|
30 | + 'not_found_in_trash' => __('No invoices found in trash.', 'invoicing') |
|
31 | 31 | ); |
32 | - $labels = apply_filters( 'wpinv_labels', $labels ); |
|
32 | + $labels = apply_filters('wpinv_labels', $labels); |
|
33 | 33 | |
34 | 34 | $menu_icon = WPINV_PLUGIN_URL . '/assets/images/favicon.ico'; |
35 | - $menu_icon = apply_filters( 'wpinv_menu_icon_invoice', $menu_icon ); |
|
35 | + $menu_icon = apply_filters('wpinv_menu_icon_invoice', $menu_icon); |
|
36 | 36 | |
37 | 37 | $args = array( |
38 | 38 | 'labels' => $labels, |
39 | - 'description' => __( 'This is where invoices are stored.', 'invoicing' ), |
|
39 | + 'description' => __('This is where invoices are stored.', 'invoicing'), |
|
40 | 40 | 'public' => true, |
41 | 41 | 'can_export' => true, |
42 | 42 | '_builtin' => false, |
@@ -50,68 +50,68 @@ discard block |
||
50 | 50 | 'has_archive' => false, |
51 | 51 | 'hierarchical' => false, |
52 | 52 | 'menu_position' => null, |
53 | - 'supports' => array( 'title', 'author' ), |
|
53 | + 'supports' => array('title', 'author'), |
|
54 | 54 | 'menu_icon' => $menu_icon, |
55 | 55 | ); |
56 | 56 | |
57 | - $args = apply_filters( 'wpinv_register_post_type_invoice', $args ); |
|
57 | + $args = apply_filters('wpinv_register_post_type_invoice', $args); |
|
58 | 58 | |
59 | - register_post_type( 'wpi_invoice', $args ); |
|
59 | + register_post_type('wpi_invoice', $args); |
|
60 | 60 | |
61 | 61 | $items_labels = array( |
62 | - 'name' => _x( 'Items', 'post type general name', 'invoicing' ), |
|
63 | - 'singular_name' => _x( 'Item', 'post type singular name', 'invoicing' ), |
|
64 | - 'menu_name' => _x( 'Items', 'admin menu', 'invoicing' ), |
|
65 | - 'add_new' => _x( 'Add New', 'wpi_item', 'invoicing' ), |
|
66 | - 'add_new_item' => __( 'Add New Item', 'invoicing' ), |
|
67 | - 'new_item' => __( 'New Item', 'invoicing' ), |
|
68 | - 'edit_item' => __( 'Edit Item', 'invoicing' ), |
|
69 | - 'view_item' => __( 'View Item', 'invoicing' ), |
|
70 | - 'all_items' => __( 'Items', 'invoicing' ), |
|
71 | - 'search_items' => __( 'Search Items', 'invoicing' ), |
|
62 | + 'name' => _x('Items', 'post type general name', 'invoicing'), |
|
63 | + 'singular_name' => _x('Item', 'post type singular name', 'invoicing'), |
|
64 | + 'menu_name' => _x('Items', 'admin menu', 'invoicing'), |
|
65 | + 'add_new' => _x('Add New', 'wpi_item', 'invoicing'), |
|
66 | + 'add_new_item' => __('Add New Item', 'invoicing'), |
|
67 | + 'new_item' => __('New Item', 'invoicing'), |
|
68 | + 'edit_item' => __('Edit Item', 'invoicing'), |
|
69 | + 'view_item' => __('View Item', 'invoicing'), |
|
70 | + 'all_items' => __('Items', 'invoicing'), |
|
71 | + 'search_items' => __('Search Items', 'invoicing'), |
|
72 | 72 | 'parent_item_colon' => '', |
73 | - 'not_found' => __( 'No items found.', 'invoicing' ), |
|
74 | - 'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' ) |
|
73 | + 'not_found' => __('No items found.', 'invoicing'), |
|
74 | + 'not_found_in_trash' => __('No items found in trash.', 'invoicing') |
|
75 | 75 | ); |
76 | - $items_labels = apply_filters( 'wpinv_items_labels', $items_labels ); |
|
76 | + $items_labels = apply_filters('wpinv_items_labels', $items_labels); |
|
77 | 77 | |
78 | 78 | $invoice_item_args = array( |
79 | 79 | 'labels' => $items_labels, |
80 | 80 | 'public' => false, |
81 | 81 | 'show_ui' => true, |
82 | 82 | 'show_in_menu' => 'wpinv', |
83 | - 'supports' => array( 'title', 'excerpt' ), |
|
83 | + 'supports' => array('title', 'excerpt'), |
|
84 | 84 | 'register_meta_box_cb' => 'wpinv_register_item_meta_boxes', |
85 | 85 | 'rewrite' => false, |
86 | 86 | 'query_var' => false, |
87 | 87 | 'map_meta_cap' => true, |
88 | 88 | 'can_export' => true, |
89 | 89 | ); |
90 | - $invoice_item_args = apply_filters( 'wpinv_register_post_type_invoice_item', $invoice_item_args ); |
|
90 | + $invoice_item_args = apply_filters('wpinv_register_post_type_invoice_item', $invoice_item_args); |
|
91 | 91 | |
92 | - register_post_type( 'wpi_item', $invoice_item_args ); |
|
92 | + register_post_type('wpi_item', $invoice_item_args); |
|
93 | 93 | |
94 | 94 | $labels = array( |
95 | - 'name' => _x( 'Discounts', 'post type general name', 'invoicing' ), |
|
96 | - 'singular_name' => _x( 'Discount', 'post type singular name', 'invoicing' ), |
|
97 | - 'menu_name' => _x( 'Discounts', 'admin menu', 'invoicing' ), |
|
98 | - 'name_admin_bar' => _x( 'Discount', 'add new on admin bar', 'invoicing' ), |
|
99 | - 'add_new' => _x( 'Add New', 'book', 'invoicing' ), |
|
100 | - 'add_new_item' => __( 'Add New Discount', 'invoicing' ), |
|
101 | - 'new_item' => __( 'New Discount', 'invoicing' ), |
|
102 | - 'edit_item' => __( 'Edit Discount', 'invoicing' ), |
|
103 | - 'view_item' => __( 'View Discount', 'invoicing' ), |
|
104 | - 'all_items' => __( 'Discounts', 'invoicing' ), |
|
105 | - 'search_items' => __( 'Search Discounts', 'invoicing' ), |
|
106 | - 'parent_item_colon' => __( 'Parent Discounts:', 'invoicing' ), |
|
107 | - 'not_found' => __( 'No discounts found.', 'invoicing' ), |
|
108 | - 'not_found_in_trash' => __( 'No discounts found in trash.', 'invoicing' ) |
|
95 | + 'name' => _x('Discounts', 'post type general name', 'invoicing'), |
|
96 | + 'singular_name' => _x('Discount', 'post type singular name', 'invoicing'), |
|
97 | + 'menu_name' => _x('Discounts', 'admin menu', 'invoicing'), |
|
98 | + 'name_admin_bar' => _x('Discount', 'add new on admin bar', 'invoicing'), |
|
99 | + 'add_new' => _x('Add New', 'book', 'invoicing'), |
|
100 | + 'add_new_item' => __('Add New Discount', 'invoicing'), |
|
101 | + 'new_item' => __('New Discount', 'invoicing'), |
|
102 | + 'edit_item' => __('Edit Discount', 'invoicing'), |
|
103 | + 'view_item' => __('View Discount', 'invoicing'), |
|
104 | + 'all_items' => __('Discounts', 'invoicing'), |
|
105 | + 'search_items' => __('Search Discounts', 'invoicing'), |
|
106 | + 'parent_item_colon' => __('Parent Discounts:', 'invoicing'), |
|
107 | + 'not_found' => __('No discounts found.', 'invoicing'), |
|
108 | + 'not_found_in_trash' => __('No discounts found in trash.', 'invoicing') |
|
109 | 109 | ); |
110 | - $labels = apply_filters( 'wpinv_discounts_labels', $labels ); |
|
110 | + $labels = apply_filters('wpinv_discounts_labels', $labels); |
|
111 | 111 | |
112 | 112 | $args = array( |
113 | 113 | 'labels' => $labels, |
114 | - 'description' => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ), |
|
114 | + 'description' => __('This is where you can add new discounts that users can use in invoices.', 'invoicing'), |
|
115 | 115 | 'public' => false, |
116 | 116 | 'can_export' => true, |
117 | 117 | '_builtin' => false, |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | 'map_meta_cap' => true, |
126 | 126 | 'has_archive' => false, |
127 | 127 | 'hierarchical' => false, |
128 | - 'supports' => array( 'title', 'excerpt' ), |
|
128 | + 'supports' => array('title', 'excerpt'), |
|
129 | 129 | 'register_meta_box_cb' => 'wpinv_register_discount_meta_boxes', |
130 | 130 | 'show_in_nav_menus' => false, |
131 | 131 | 'show_in_admin_bar' => true, |
@@ -133,99 +133,99 @@ discard block |
||
133 | 133 | 'menu_position' => null, |
134 | 134 | ); |
135 | 135 | |
136 | - $args = apply_filters( 'wpinv_register_post_type_discount', $args ); |
|
136 | + $args = apply_filters('wpinv_register_post_type_discount', $args); |
|
137 | 137 | |
138 | - register_post_type( 'wpi_discount', $args ); |
|
138 | + register_post_type('wpi_discount', $args); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | function wpinv_get_default_labels() { |
142 | 142 | $defaults = array( |
143 | - 'singular' => __( 'Invoice', 'invoicing' ), |
|
144 | - 'plural' => __( 'Invoices', 'invoicing' ) |
|
143 | + 'singular' => __('Invoice', 'invoicing'), |
|
144 | + 'plural' => __('Invoices', 'invoicing') |
|
145 | 145 | ); |
146 | 146 | |
147 | - return apply_filters( 'wpinv_default_invoices_name', $defaults ); |
|
147 | + return apply_filters('wpinv_default_invoices_name', $defaults); |
|
148 | 148 | } |
149 | 149 | |
150 | -function wpinv_get_label_singular( $lowercase = false ) { |
|
150 | +function wpinv_get_label_singular($lowercase = false) { |
|
151 | 151 | $defaults = wpinv_get_default_labels(); |
152 | 152 | |
153 | - return ($lowercase) ? strtolower( $defaults['singular'] ) : $defaults['singular']; |
|
153 | + return ($lowercase) ? strtolower($defaults['singular']) : $defaults['singular']; |
|
154 | 154 | } |
155 | 155 | |
156 | -function wpinv_get_label_plural( $lowercase = false ) { |
|
156 | +function wpinv_get_label_plural($lowercase = false) { |
|
157 | 157 | $defaults = wpinv_get_default_labels(); |
158 | 158 | |
159 | - return ( $lowercase ) ? strtolower( $defaults['plural'] ) : $defaults['plural']; |
|
159 | + return ($lowercase) ? strtolower($defaults['plural']) : $defaults['plural']; |
|
160 | 160 | } |
161 | 161 | |
162 | -function wpinv_change_default_title( $title ) { |
|
163 | - if ( !is_admin() ) { |
|
162 | +function wpinv_change_default_title($title) { |
|
163 | + if (!is_admin()) { |
|
164 | 164 | $label = wpinv_get_label_singular(); |
165 | - $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label ); |
|
165 | + $title = sprintf(__('Enter %s name here', 'invoicing'), $label); |
|
166 | 166 | return $title; |
167 | 167 | } |
168 | 168 | |
169 | 169 | $screen = get_current_screen(); |
170 | 170 | |
171 | - if ( 'wpi_invoice' == $screen->post_type ) { |
|
171 | + if ('wpi_invoice' == $screen->post_type) { |
|
172 | 172 | $label = wpinv_get_label_singular(); |
173 | - $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label ); |
|
173 | + $title = sprintf(__('Enter %s name here', 'invoicing'), $label); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | return $title; |
177 | 177 | } |
178 | -add_filter( 'enter_title_here', 'wpinv_change_default_title' ); |
|
178 | +add_filter('enter_title_here', 'wpinv_change_default_title'); |
|
179 | 179 | |
180 | 180 | function wpinv_register_post_status() { |
181 | - register_post_status( 'processing', array( |
|
182 | - 'label' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
181 | + register_post_status('processing', array( |
|
182 | + 'label' => _x('Processing', 'Invoice status', 'invoicing'), |
|
183 | 183 | 'public' => true, |
184 | 184 | 'exclude_from_search' => true, |
185 | 185 | 'show_in_admin_all_list' => true, |
186 | 186 | 'show_in_admin_status_list' => true, |
187 | - 'label_count' => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' ) |
|
188 | - ) ); |
|
189 | - register_post_status( 'onhold', array( |
|
190 | - 'label' => _x( 'On Hold', 'Invoice status', 'invoicing' ), |
|
187 | + 'label_count' => _n_noop('Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing') |
|
188 | + )); |
|
189 | + register_post_status('onhold', array( |
|
190 | + 'label' => _x('On Hold', 'Invoice status', 'invoicing'), |
|
191 | 191 | 'public' => true, |
192 | 192 | 'exclude_from_search' => true, |
193 | 193 | 'show_in_admin_all_list' => true, |
194 | 194 | 'show_in_admin_status_list' => true, |
195 | - 'label_count' => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' ) |
|
196 | - ) ); |
|
197 | - register_post_status( 'cancelled', array( |
|
198 | - 'label' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
195 | + 'label_count' => _n_noop('On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing') |
|
196 | + )); |
|
197 | + register_post_status('cancelled', array( |
|
198 | + 'label' => _x('Cancelled', 'Invoice status', 'invoicing'), |
|
199 | 199 | 'public' => true, |
200 | 200 | 'exclude_from_search' => true, |
201 | 201 | 'show_in_admin_all_list' => true, |
202 | 202 | 'show_in_admin_status_list' => true, |
203 | - 'label_count' => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' ) |
|
204 | - ) ); |
|
205 | - register_post_status( 'refunded', array( |
|
206 | - 'label' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
203 | + 'label_count' => _n_noop('Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing') |
|
204 | + )); |
|
205 | + register_post_status('refunded', array( |
|
206 | + 'label' => _x('Refunded', 'Invoice status', 'invoicing'), |
|
207 | 207 | 'public' => true, |
208 | 208 | 'exclude_from_search' => true, |
209 | 209 | 'show_in_admin_all_list' => true, |
210 | 210 | 'show_in_admin_status_list' => true, |
211 | - 'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' ) |
|
212 | - ) ); |
|
213 | - register_post_status( 'failed', array( |
|
214 | - 'label' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
211 | + 'label_count' => _n_noop('Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing') |
|
212 | + )); |
|
213 | + register_post_status('failed', array( |
|
214 | + 'label' => _x('Failed', 'Invoice status', 'invoicing'), |
|
215 | 215 | 'public' => true, |
216 | 216 | 'exclude_from_search' => true, |
217 | 217 | 'show_in_admin_all_list' => true, |
218 | 218 | 'show_in_admin_status_list' => true, |
219 | - 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' ) |
|
220 | - ) ); |
|
221 | - register_post_status( 'renewal', array( |
|
222 | - 'label' => _x( 'Renewal', 'Invoice status', 'invoicing' ), |
|
219 | + 'label_count' => _n_noop('Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing') |
|
220 | + )); |
|
221 | + register_post_status('renewal', array( |
|
222 | + 'label' => _x('Renewal', 'Invoice status', 'invoicing'), |
|
223 | 223 | 'public' => true, |
224 | 224 | 'exclude_from_search' => true, |
225 | 225 | 'show_in_admin_all_list' => true, |
226 | 226 | 'show_in_admin_status_list' => true, |
227 | - 'label_count' => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' ) |
|
228 | - ) ); |
|
227 | + 'label_count' => _n_noop('Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing') |
|
228 | + )); |
|
229 | 229 | } |
230 | -add_action( 'init', 'wpinv_register_post_status', 10 ); |
|
230 | +add_action('init', 'wpinv_register_post_status', 10); |
|
231 | 231 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; // Exit if accessed directly |
4 | 4 | } |
5 | 5 | |
@@ -14,65 +14,65 @@ discard block |
||
14 | 14 | } |
15 | 15 | |
16 | 16 | public function init() { |
17 | - do_action( 'wpinv_class_notes_init', $this ); |
|
17 | + do_action('wpinv_class_notes_init', $this); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | public function includes() { |
21 | - do_action( 'wpinv_class_notes_includes', $this ); |
|
21 | + do_action('wpinv_class_notes_includes', $this); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | public function actions() { |
25 | 25 | // Secure inovice notes |
26 | - add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
26 | + add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1); |
|
27 | 27 | |
28 | - do_action( 'wpinv_class_notes_actions', $this ); |
|
28 | + do_action('wpinv_class_notes_actions', $this); |
|
29 | 29 | } |
30 | 30 | |
31 | - public function set_invoice_note_type( $query ) { |
|
32 | - $post_ID = !empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
31 | + public function set_invoice_note_type($query) { |
|
32 | + $post_ID = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
33 | 33 | |
34 | - if ( $post_ID && get_post_type( $post_ID ) == $this->invoice_post_type ) { |
|
34 | + if ($post_ID && get_post_type($post_ID) == $this->invoice_post_type) { |
|
35 | 35 | $query->query_vars['type__in'] = $this->comment_type; |
36 | 36 | $query->query_vars['type__not_in'] = ''; |
37 | 37 | } else { |
38 | - if ( isset( $query->query_vars['type__in'] ) && $type_in = $query->query_vars['type__in'] ) { |
|
39 | - if ( is_array( $type_in ) && in_array( $this->comment_type, $type_in ) ) { |
|
40 | - $key = array_search( $this->comment_type, $type_in ); |
|
41 | - unset( $query->query_vars['type__in'][$key] ); |
|
42 | - } else if ( !is_array( $type_in ) && $type_in == $this->comment_type ) { |
|
38 | + if (isset($query->query_vars['type__in']) && $type_in = $query->query_vars['type__in']) { |
|
39 | + if (is_array($type_in) && in_array($this->comment_type, $type_in)) { |
|
40 | + $key = array_search($this->comment_type, $type_in); |
|
41 | + unset($query->query_vars['type__in'][$key]); |
|
42 | + } else if (!is_array($type_in) && $type_in == $this->comment_type) { |
|
43 | 43 | $query->query_vars['type__in'] = ''; |
44 | 44 | } |
45 | 45 | } |
46 | 46 | |
47 | - if ( isset( $query->query_vars['type__not_in'] ) && $type_not_in = $query->query_vars['type__not_in'] ) { |
|
48 | - if ( is_array( $type_not_in ) && !in_array( $this->comment_type, $type_not_in ) ) { |
|
47 | + if (isset($query->query_vars['type__not_in']) && $type_not_in = $query->query_vars['type__not_in']) { |
|
48 | + if (is_array($type_not_in) && !in_array($this->comment_type, $type_not_in)) { |
|
49 | 49 | $query->query_vars['type__not_in'][] = $this->comment_type; |
50 | - } else if ( !is_array( $type_not_in ) && $type_not_in != $this->comment_type ) { |
|
50 | + } else if (!is_array($type_not_in) && $type_not_in != $this->comment_type) { |
|
51 | 51 | $query->query_vars['type__not_in'] = (array)$query->query_vars['type__not_in']; |
52 | 52 | $query->query_vars['type__not_in'][] = $this->comment_type; |
53 | 53 | } |
54 | 54 | } else { |
55 | - $query->query_vars['type__not_in'] = $this->comment_type; |
|
55 | + $query->query_vars['type__not_in'] = $this->comment_type; |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
59 | 59 | return $query; |
60 | 60 | } |
61 | 61 | |
62 | - public function get_invoice_notes( $invoice_id = 0, $type = '' ) { |
|
62 | + public function get_invoice_notes($invoice_id = 0, $type = '') { |
|
63 | 63 | $args = array( |
64 | 64 | 'post_id' => $invoice_id, |
65 | 65 | 'order' => 'comment_date_gmt', |
66 | 66 | 'order' => 'DESC', |
67 | 67 | ); |
68 | 68 | |
69 | - if ( $type == 'customer' ) { |
|
69 | + if ($type == 'customer') { |
|
70 | 70 | $args['meta_key'] = '_wpi_customer_note'; |
71 | 71 | $args['meta_value'] = 1; |
72 | 72 | } |
73 | 73 | |
74 | - $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
74 | + $args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type); |
|
75 | 75 | |
76 | - return get_comments( $args ); |
|
76 | + return get_comments($args); |
|
77 | 77 | } |
78 | 78 | } |
@@ -7,112 +7,112 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_item_quantities_enabled() { |
15 | - $ret = wpinv_get_option( 'item_quantities', true ); |
|
15 | + $ret = wpinv_get_option('item_quantities', true); |
|
16 | 16 | |
17 | - return (bool) apply_filters( 'wpinv_item_quantities_enabled', $ret ); |
|
17 | + return (bool)apply_filters('wpinv_item_quantities_enabled', $ret); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | function wpinv_get_ip() { |
21 | 21 | $ip = '127.0.0.1'; |
22 | 22 | |
23 | - if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { |
|
24 | - $ip = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] ); |
|
25 | - } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { |
|
26 | - $ip = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] ); |
|
27 | - } elseif( !empty( $_SERVER['REMOTE_ADDR'] ) ) { |
|
28 | - $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] ); |
|
23 | + if (!empty($_SERVER['HTTP_CLIENT_IP'])) { |
|
24 | + $ip = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']); |
|
25 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
26 | + $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']); |
|
27 | + } elseif (!empty($_SERVER['REMOTE_ADDR'])) { |
|
28 | + $ip = sanitize_text_field($_SERVER['REMOTE_ADDR']); |
|
29 | 29 | } |
30 | 30 | |
31 | - return apply_filters( 'wpinv_get_ip', $ip ); |
|
31 | + return apply_filters('wpinv_get_ip', $ip); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | function wpinv_get_user_agent() { |
35 | - if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
|
36 | - $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ); |
|
35 | + if (!empty($_SERVER['HTTP_USER_AGENT'])) { |
|
36 | + $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']); |
|
37 | 37 | } else { |
38 | 38 | $user_agent = ''; |
39 | 39 | } |
40 | 40 | |
41 | - return apply_filters( 'wpinv_get_user_agent', $user_agent ); |
|
41 | + return apply_filters('wpinv_get_user_agent', $user_agent); |
|
42 | 42 | } |
43 | 43 | |
44 | -function wpinv_sanitize_amount( $amount ) { |
|
44 | +function wpinv_sanitize_amount($amount) { |
|
45 | 45 | $is_negative = false; |
46 | 46 | $thousands_sep = wpinv_thousands_seperator(); |
47 | 47 | $decimal_sep = wpinv_decimal_seperator(); |
48 | 48 | |
49 | 49 | // Sanitize the amount |
50 | - if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) { |
|
51 | - if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
52 | - $amount = str_replace( $thousands_sep, '', $amount ); |
|
53 | - } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) { |
|
54 | - $amount = str_replace( '.', '', $amount ); |
|
50 | + if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) { |
|
51 | + if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) { |
|
52 | + $amount = str_replace($thousands_sep, '', $amount); |
|
53 | + } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) { |
|
54 | + $amount = str_replace('.', '', $amount); |
|
55 | 55 | } |
56 | 56 | |
57 | - $amount = str_replace( $decimal_sep, '.', $amount ); |
|
58 | - } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
59 | - $amount = str_replace( $thousands_sep, '', $amount ); |
|
57 | + $amount = str_replace($decimal_sep, '.', $amount); |
|
58 | + } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
59 | + $amount = str_replace($thousands_sep, '', $amount); |
|
60 | 60 | } |
61 | 61 | |
62 | - if( $amount < 0 ) { |
|
62 | + if ($amount < 0) { |
|
63 | 63 | $is_negative = true; |
64 | 64 | } |
65 | 65 | |
66 | - $amount = preg_replace( '/[^0-9\.]/', '', $amount ); |
|
66 | + $amount = preg_replace('/[^0-9\.]/', '', $amount); |
|
67 | 67 | |
68 | - $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', 2, $amount ); |
|
69 | - $amount = number_format( (double) $amount, $decimals, '.', '' ); |
|
68 | + $decimals = apply_filters('wpinv_sanitize_amount_decimals', 2, $amount); |
|
69 | + $amount = number_format((double)$amount, $decimals, '.', ''); |
|
70 | 70 | |
71 | - if( $is_negative ) { |
|
71 | + if ($is_negative) { |
|
72 | 72 | $amount *= -1; |
73 | 73 | } |
74 | 74 | |
75 | - return apply_filters( 'wpinv_sanitize_amount', $amount ); |
|
75 | + return apply_filters('wpinv_sanitize_amount', $amount); |
|
76 | 76 | } |
77 | 77 | |
78 | -function wpinv_get_invoice_statuses( $trashed = false ) { |
|
78 | +function wpinv_get_invoice_statuses($trashed = false) { |
|
79 | 79 | $invoice_statuses = array( |
80 | - 'pending' => __( 'Pending Payment', 'invoicing' ), |
|
81 | - 'publish' => __( 'Paid', 'invoicing' ), |
|
82 | - 'processing' => __( 'Processing', 'invoicing' ), |
|
83 | - 'onhold' => __( 'On Hold', 'invoicing' ), |
|
84 | - 'refunded' => __( 'Refunded', 'invoicing' ), |
|
85 | - 'cancelled' => __( 'Cancelled', 'invoicing' ), |
|
86 | - 'failed' => __( 'Failed', 'invoicing' ), |
|
87 | - 'renewal' => __( 'Renewal Payment', 'invoicing' ) |
|
80 | + 'pending' => __('Pending Payment', 'invoicing'), |
|
81 | + 'publish' => __('Paid', 'invoicing'), |
|
82 | + 'processing' => __('Processing', 'invoicing'), |
|
83 | + 'onhold' => __('On Hold', 'invoicing'), |
|
84 | + 'refunded' => __('Refunded', 'invoicing'), |
|
85 | + 'cancelled' => __('Cancelled', 'invoicing'), |
|
86 | + 'failed' => __('Failed', 'invoicing'), |
|
87 | + 'renewal' => __('Renewal Payment', 'invoicing') |
|
88 | 88 | ); |
89 | 89 | |
90 | - if ( $trashed ) { |
|
91 | - $invoice_statuses['trash'] = __( 'Trash', 'invoicing' ); |
|
90 | + if ($trashed) { |
|
91 | + $invoice_statuses['trash'] = __('Trash', 'invoicing'); |
|
92 | 92 | } |
93 | 93 | |
94 | - return apply_filters( 'wpinv_statuses', $invoice_statuses ); |
|
94 | + return apply_filters('wpinv_statuses', $invoice_statuses); |
|
95 | 95 | } |
96 | 96 | |
97 | -function wpinv_status_nicename( $status ) { |
|
97 | +function wpinv_status_nicename($status) { |
|
98 | 98 | $statuses = wpinv_get_invoice_statuses(); |
99 | - $status = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' ); |
|
99 | + $status = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing'); |
|
100 | 100 | |
101 | 101 | return $status; |
102 | 102 | } |
103 | 103 | |
104 | 104 | function wpinv_get_currency() { |
105 | - $currency = wpinv_get_option( 'currency', 'USD' ); |
|
105 | + $currency = wpinv_get_option('currency', 'USD'); |
|
106 | 106 | |
107 | - return apply_filters( 'wpinv_currency', $currency ); |
|
107 | + return apply_filters('wpinv_currency', $currency); |
|
108 | 108 | } |
109 | 109 | |
110 | -function wpinv_currency_symbol( $currency = '' ) { |
|
111 | - if ( empty( $currency ) ) { |
|
110 | +function wpinv_currency_symbol($currency = '') { |
|
111 | + if (empty($currency)) { |
|
112 | 112 | $currency = wpinv_get_currency(); |
113 | 113 | } |
114 | 114 | |
115 | - $symbols = apply_filters( 'wpinv_currency_symbols', array( |
|
115 | + $symbols = apply_filters('wpinv_currency_symbols', array( |
|
116 | 116 | 'AED' => 'د.إ', |
117 | 117 | 'ARS' => '$', |
118 | 118 | 'AUD' => '$', |
@@ -164,78 +164,78 @@ discard block |
||
164 | 164 | 'USD' => '$', |
165 | 165 | 'VND' => '₫', |
166 | 166 | 'ZAR' => 'R', |
167 | - ) ); |
|
167 | + )); |
|
168 | 168 | |
169 | - $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : '$'; |
|
169 | + $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : '$'; |
|
170 | 170 | |
171 | - return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency ); |
|
171 | + return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | function wpinv_currency_position() { |
175 | - $position = wpinv_get_option( 'currency_position', 'left' ); |
|
175 | + $position = wpinv_get_option('currency_position', 'left'); |
|
176 | 176 | |
177 | - return apply_filters( 'wpinv_currency_position', $position ); |
|
177 | + return apply_filters('wpinv_currency_position', $position); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | function wpinv_thousands_seperator() { |
181 | - $thousand_sep = wpinv_get_option( 'thousands_seperator', ',' ); |
|
181 | + $thousand_sep = wpinv_get_option('thousands_seperator', ','); |
|
182 | 182 | |
183 | - return apply_filters( 'wpinv_thousands_seperator', $thousand_sep ); |
|
183 | + return apply_filters('wpinv_thousands_seperator', $thousand_sep); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | function wpinv_decimal_seperator() { |
187 | - $decimal_sep = wpinv_get_option( 'decimal_seperator', '.' ); |
|
187 | + $decimal_sep = wpinv_get_option('decimal_seperator', '.'); |
|
188 | 188 | |
189 | - return apply_filters( 'wpinv_decimal_seperator', $decimal_sep ); |
|
189 | + return apply_filters('wpinv_decimal_seperator', $decimal_sep); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | function wpinv_decimals() { |
193 | - $decimals = wpinv_get_option( 'decimals', 2 ); |
|
193 | + $decimals = wpinv_get_option('decimals', 2); |
|
194 | 194 | |
195 | - return apply_filters( 'wpinv_decimals', $decimals ); |
|
195 | + return apply_filters('wpinv_decimals', $decimals); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | function wpinv_get_currencies() { |
199 | 199 | $currencies = array( |
200 | - 'USD' => __( 'US Dollars ($)', 'invoicing' ), |
|
201 | - 'EUR' => __( 'Euros (€)', 'invoicing' ), |
|
202 | - 'GBP' => __( 'Pounds Sterling (£)', 'invoicing' ), |
|
203 | - 'AUD' => __( 'Australian Dollars ($)', 'invoicing' ), |
|
204 | - 'BRL' => __( 'Brazilian Real (R$)', 'invoicing' ), |
|
205 | - 'CAD' => __( 'Canadian Dollars ($)', 'invoicing' ), |
|
206 | - 'CLP' => __( 'Chilean Peso ($)', 'invoicing' ), |
|
207 | - 'CNY' => __( 'Chinese Yuan (¥)', 'invoicing' ), |
|
208 | - 'CZK' => __( 'Czech Koruna (Kč)', 'invoicing' ), |
|
209 | - 'DKK' => __( 'Danish Krone (DKK)', 'invoicing' ), |
|
210 | - 'HKD' => __( 'Hong Kong Dollar ($)', 'invoicing' ), |
|
211 | - 'HUF' => __( 'Hungarian Forint (Ft)', 'invoicing' ), |
|
212 | - 'INR' => __( 'Indian Rupee (₹)', 'invoicing' ), |
|
213 | - 'ILS' => __( 'Israeli Shekel (₪)', 'invoicing' ), |
|
214 | - 'JPY' => __( 'Japanese Yen (¥)', 'invoicing' ), |
|
215 | - 'MYR' => __( 'Malaysian Ringgit (RM)', 'invoicing' ), |
|
216 | - 'MXN' => __( 'Mexican Peso ($)', 'invoicing' ), |
|
217 | - 'NZD' => __( 'New Zealand Dollar ($)', 'invoicing' ), |
|
218 | - 'NOK' => __( 'Norwegian Krone (kr)', 'invoicing' ), |
|
219 | - 'PHP' => __( 'Philippine Peso (₱)', 'invoicing' ), |
|
220 | - 'PLN' => __( 'Polish Zloty (zł)', 'invoicing' ), |
|
221 | - 'SGD' => __( 'Singapore Dollar ($)', 'invoicing' ), |
|
222 | - 'SEK' => __( 'Swedish Krona (kr)', 'invoicing' ), |
|
223 | - 'CHF' => __( 'Swiss Franc (CHF)', 'invoicing' ), |
|
224 | - 'TWD' => __( 'Taiwan New Dollar (NT$)', 'invoicing' ), |
|
225 | - 'THB' => __( 'Thai Baht (฿)', 'invoicing' ), |
|
226 | - 'TRY' => __( 'Turkish Lira (₺)', 'invoicing' ), |
|
227 | - 'RIAL' => __( 'Iranian Rial (﷼)', 'invoicing' ), |
|
228 | - 'RUB' => __( 'Russian Ruble (₽)', 'invoicing' ), |
|
229 | - 'ZAR' => __( 'South African Rand (R)', 'invoicing' ) |
|
200 | + 'USD' => __('US Dollars ($)', 'invoicing'), |
|
201 | + 'EUR' => __('Euros (€)', 'invoicing'), |
|
202 | + 'GBP' => __('Pounds Sterling (£)', 'invoicing'), |
|
203 | + 'AUD' => __('Australian Dollars ($)', 'invoicing'), |
|
204 | + 'BRL' => __('Brazilian Real (R$)', 'invoicing'), |
|
205 | + 'CAD' => __('Canadian Dollars ($)', 'invoicing'), |
|
206 | + 'CLP' => __('Chilean Peso ($)', 'invoicing'), |
|
207 | + 'CNY' => __('Chinese Yuan (¥)', 'invoicing'), |
|
208 | + 'CZK' => __('Czech Koruna (Kč)', 'invoicing'), |
|
209 | + 'DKK' => __('Danish Krone (DKK)', 'invoicing'), |
|
210 | + 'HKD' => __('Hong Kong Dollar ($)', 'invoicing'), |
|
211 | + 'HUF' => __('Hungarian Forint (Ft)', 'invoicing'), |
|
212 | + 'INR' => __('Indian Rupee (₹)', 'invoicing'), |
|
213 | + 'ILS' => __('Israeli Shekel (₪)', 'invoicing'), |
|
214 | + 'JPY' => __('Japanese Yen (¥)', 'invoicing'), |
|
215 | + 'MYR' => __('Malaysian Ringgit (RM)', 'invoicing'), |
|
216 | + 'MXN' => __('Mexican Peso ($)', 'invoicing'), |
|
217 | + 'NZD' => __('New Zealand Dollar ($)', 'invoicing'), |
|
218 | + 'NOK' => __('Norwegian Krone (kr)', 'invoicing'), |
|
219 | + 'PHP' => __('Philippine Peso (₱)', 'invoicing'), |
|
220 | + 'PLN' => __('Polish Zloty (zł)', 'invoicing'), |
|
221 | + 'SGD' => __('Singapore Dollar ($)', 'invoicing'), |
|
222 | + 'SEK' => __('Swedish Krona (kr)', 'invoicing'), |
|
223 | + 'CHF' => __('Swiss Franc (CHF)', 'invoicing'), |
|
224 | + 'TWD' => __('Taiwan New Dollar (NT$)', 'invoicing'), |
|
225 | + 'THB' => __('Thai Baht (฿)', 'invoicing'), |
|
226 | + 'TRY' => __('Turkish Lira (₺)', 'invoicing'), |
|
227 | + 'RIAL' => __('Iranian Rial (﷼)', 'invoicing'), |
|
228 | + 'RUB' => __('Russian Ruble (₽)', 'invoicing'), |
|
229 | + 'ZAR' => __('South African Rand (R)', 'invoicing') |
|
230 | 230 | ); |
231 | 231 | |
232 | - asort( $currencies ); |
|
232 | + asort($currencies); |
|
233 | 233 | |
234 | - return apply_filters( 'wpinv_currencies', $currencies ); |
|
234 | + return apply_filters('wpinv_currencies', $currencies); |
|
235 | 235 | } |
236 | 236 | |
237 | -function wpinv_price( $amount = '', $currency = '' ) { |
|
238 | - if( empty( $currency ) ) { |
|
237 | +function wpinv_price($amount = '', $currency = '') { |
|
238 | + if (empty($currency)) { |
|
239 | 239 | $currency = wpinv_get_currency(); |
240 | 240 | } |
241 | 241 | |
@@ -243,14 +243,14 @@ discard block |
||
243 | 243 | |
244 | 244 | $negative = $amount < 0; |
245 | 245 | |
246 | - if ( $negative ) { |
|
247 | - $amount = substr( $amount, 1 ); |
|
246 | + if ($negative) { |
|
247 | + $amount = substr($amount, 1); |
|
248 | 248 | } |
249 | 249 | |
250 | - $symbol = wpinv_currency_symbol( $currency ); |
|
250 | + $symbol = wpinv_currency_symbol($currency); |
|
251 | 251 | |
252 | - if ( $position == 'left' || $position == 'left_space' ) { |
|
253 | - switch ( $currency ) { |
|
252 | + if ($position == 'left' || $position == 'left_space') { |
|
253 | + switch ($currency) { |
|
254 | 254 | case "GBP" : |
255 | 255 | case "BRL" : |
256 | 256 | case "EUR" : |
@@ -262,15 +262,15 @@ discard block |
||
262 | 262 | case "NZD" : |
263 | 263 | case "SGD" : |
264 | 264 | case "JPY" : |
265 | - $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
265 | + $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
266 | 266 | break; |
267 | 267 | default : |
268 | 268 | //$price = $currency . ' ' . $amount; |
269 | - $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
269 | + $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
270 | 270 | break; |
271 | 271 | } |
272 | 272 | } else { |
273 | - switch ( $currency ) { |
|
273 | + switch ($currency) { |
|
274 | 274 | case "GBP" : |
275 | 275 | case "BRL" : |
276 | 276 | case "EUR" : |
@@ -281,82 +281,82 @@ discard block |
||
281 | 281 | case "MXN" : |
282 | 282 | case "SGD" : |
283 | 283 | case "JPY" : |
284 | - $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
284 | + $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
285 | 285 | break; |
286 | 286 | default : |
287 | 287 | //$price = $amount . ' ' . $currency; |
288 | - $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
288 | + $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
289 | 289 | break; |
290 | 290 | } |
291 | 291 | } |
292 | 292 | |
293 | - if ( $negative ) { |
|
293 | + if ($negative) { |
|
294 | 294 | $price = '-' . $price; |
295 | 295 | } |
296 | 296 | |
297 | - $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount ); |
|
297 | + $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount); |
|
298 | 298 | |
299 | 299 | return $price; |
300 | 300 | } |
301 | 301 | |
302 | -function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) { |
|
302 | +function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) { |
|
303 | 303 | $thousands_sep = wpinv_thousands_seperator(); |
304 | 304 | $decimal_sep = wpinv_decimal_seperator(); |
305 | 305 | |
306 | - if ( $decimals === NULL ) { |
|
306 | + if ($decimals === NULL) { |
|
307 | 307 | $decimals = wpinv_decimals(); |
308 | 308 | } |
309 | 309 | |
310 | - if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) { |
|
311 | - $whole = substr( $amount, 0, $sep_found ); |
|
312 | - $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) ); |
|
310 | + if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) { |
|
311 | + $whole = substr($amount, 0, $sep_found); |
|
312 | + $part = substr($amount, $sep_found + 1, (strlen($amount) - 1)); |
|
313 | 313 | $amount = $whole . '.' . $part; |
314 | 314 | } |
315 | 315 | |
316 | - if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
317 | - $amount = str_replace( ',', '', $amount ); |
|
316 | + if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
317 | + $amount = str_replace(',', '', $amount); |
|
318 | 318 | } |
319 | 319 | |
320 | - if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
321 | - $amount = str_replace( ' ', '', $amount ); |
|
320 | + if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
321 | + $amount = str_replace(' ', '', $amount); |
|
322 | 322 | } |
323 | 323 | |
324 | - if ( empty( $amount ) ) { |
|
324 | + if (empty($amount)) { |
|
325 | 325 | $amount = 0; |
326 | 326 | } |
327 | 327 | |
328 | - $decimals = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate ); |
|
329 | - $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep ); |
|
328 | + $decimals = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate); |
|
329 | + $formatted = number_format((float)$amount, $decimals, $decimal_sep, $thousands_sep); |
|
330 | 330 | |
331 | - if ( $calculate ) { |
|
332 | - if ( $thousands_sep === "," ) { |
|
333 | - $formatted = str_replace( ",", "", $formatted ); |
|
331 | + if ($calculate) { |
|
332 | + if ($thousands_sep === ",") { |
|
333 | + $formatted = str_replace(",", "", $formatted); |
|
334 | 334 | } |
335 | 335 | |
336 | - if ( $decimal_sep === "," ) { |
|
337 | - $formatted = str_replace( ",", ".", $formatted ); |
|
336 | + if ($decimal_sep === ",") { |
|
337 | + $formatted = str_replace(",", ".", $formatted); |
|
338 | 338 | } |
339 | 339 | } |
340 | 340 | |
341 | - return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate ); |
|
341 | + return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate); |
|
342 | 342 | } |
343 | 343 | |
344 | -function wpinv_sanitize_key( $key ) { |
|
344 | +function wpinv_sanitize_key($key) { |
|
345 | 345 | $raw_key = $key; |
346 | - $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key ); |
|
346 | + $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key); |
|
347 | 347 | |
348 | - return apply_filters( 'wpinv_sanitize_key', $key, $raw_key ); |
|
348 | + return apply_filters('wpinv_sanitize_key', $key, $raw_key); |
|
349 | 349 | } |
350 | 350 | |
351 | -function wpinv_get_file_extension( $str ) { |
|
352 | - $parts = explode( '.', $str ); |
|
353 | - return end( $parts ); |
|
351 | +function wpinv_get_file_extension($str) { |
|
352 | + $parts = explode('.', $str); |
|
353 | + return end($parts); |
|
354 | 354 | } |
355 | 355 | |
356 | -function wpinv_string_is_image_url( $str ) { |
|
357 | - $ext = wpinv_get_file_extension( $str ); |
|
356 | +function wpinv_string_is_image_url($str) { |
|
357 | + $ext = wpinv_get_file_extension($str); |
|
358 | 358 | |
359 | - switch ( strtolower( $ext ) ) { |
|
359 | + switch (strtolower($ext)) { |
|
360 | 360 | case 'jpeg'; |
361 | 361 | case 'jpg'; |
362 | 362 | $return = true; |
@@ -372,32 +372,32 @@ discard block |
||
372 | 372 | break; |
373 | 373 | } |
374 | 374 | |
375 | - return (bool)apply_filters( 'wpinv_string_is_image', $return, $str ); |
|
375 | + return (bool)apply_filters('wpinv_string_is_image', $return, $str); |
|
376 | 376 | } |
377 | 377 | |
378 | -function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) { |
|
379 | - $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG ); |
|
378 | +function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) { |
|
379 | + $should_log = apply_filters('wpinv_log_errors', WP_DEBUG); |
|
380 | 380 | |
381 | - if ( true === $should_log ) { |
|
381 | + if (true === $should_log) { |
|
382 | 382 | $label = ''; |
383 | - if ( $file && $file !== '' ) { |
|
384 | - $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' ); |
|
383 | + if ($file && $file !== '') { |
|
384 | + $label .= basename($file) . ($line ? '(' . $line . ')' : ''); |
|
385 | 385 | } |
386 | 386 | |
387 | - if ( $title && $title !== '' ) { |
|
387 | + if ($title && $title !== '') { |
|
388 | 388 | $label = $label !== '' ? $label . ' ' : ''; |
389 | 389 | $label .= $title . ' '; |
390 | 390 | } |
391 | 391 | |
392 | - $label = $label !== '' ? trim( $label ) . ' : ' : ''; |
|
392 | + $label = $label !== '' ? trim($label) . ' : ' : ''; |
|
393 | 393 | |
394 | - if ( is_array( $log ) || is_object( $log ) ) { |
|
395 | - error_log( $label . print_r( $log, true ) ); |
|
394 | + if (is_array($log) || is_object($log)) { |
|
395 | + error_log($label . print_r($log, true)); |
|
396 | 396 | } else { |
397 | - error_log( $label . $log ); |
|
397 | + error_log($label . $log); |
|
398 | 398 | } |
399 | 399 | |
400 | - if ( $exit ) { |
|
400 | + if ($exit) { |
|
401 | 401 | exit; |
402 | 402 | } |
403 | 403 | } |
@@ -405,65 +405,65 @@ discard block |
||
405 | 405 | |
406 | 406 | function wpinv_is_ajax_disabled() { |
407 | 407 | $retval = false; |
408 | - return apply_filters( 'wpinv_is_ajax_disabled', $retval ); |
|
408 | + return apply_filters('wpinv_is_ajax_disabled', $retval); |
|
409 | 409 | } |
410 | 410 | |
411 | -function wpinv_get_current_page_url( $nocache = false ) { |
|
411 | +function wpinv_get_current_page_url($nocache = false) { |
|
412 | 412 | global $wp; |
413 | 413 | |
414 | - if ( get_option( 'permalink_structure' ) ) { |
|
415 | - $base = trailingslashit( home_url( $wp->request ) ); |
|
414 | + if (get_option('permalink_structure')) { |
|
415 | + $base = trailingslashit(home_url($wp->request)); |
|
416 | 416 | } else { |
417 | - $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) ); |
|
418 | - $base = remove_query_arg( array( 'post_type', 'name' ), $base ); |
|
417 | + $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request))); |
|
418 | + $base = remove_query_arg(array('post_type', 'name'), $base); |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | $scheme = is_ssl() ? 'https' : 'http'; |
422 | - $uri = set_url_scheme( $base, $scheme ); |
|
422 | + $uri = set_url_scheme($base, $scheme); |
|
423 | 423 | |
424 | - if ( is_front_page() ) { |
|
425 | - $uri = home_url( '/' ); |
|
426 | - } elseif ( wpinv_is_checkout( array(), false ) ) { |
|
424 | + if (is_front_page()) { |
|
425 | + $uri = home_url('/'); |
|
426 | + } elseif (wpinv_is_checkout(array(), false)) { |
|
427 | 427 | $uri = wpinv_get_checkout_uri(); |
428 | 428 | } |
429 | 429 | |
430 | - $uri = apply_filters( 'wpinv_get_current_page_url', $uri ); |
|
430 | + $uri = apply_filters('wpinv_get_current_page_url', $uri); |
|
431 | 431 | |
432 | - if ( $nocache ) { |
|
433 | - $uri = wpinv_add_cache_busting( $uri ); |
|
432 | + if ($nocache) { |
|
433 | + $uri = wpinv_add_cache_busting($uri); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | return $uri; |
437 | 437 | } |
438 | 438 | |
439 | 439 | function wpinv_get_php_arg_separator_output() { |
440 | - return ini_get( 'arg_separator.output' ); |
|
440 | + return ini_get('arg_separator.output'); |
|
441 | 441 | } |
442 | 442 | |
443 | -function wpinv_rgb_from_hex( $color ) { |
|
444 | - $color = str_replace( '#', '', $color ); |
|
443 | +function wpinv_rgb_from_hex($color) { |
|
444 | + $color = str_replace('#', '', $color); |
|
445 | 445 | // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF" |
446 | - $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color ); |
|
446 | + $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color); |
|
447 | 447 | |
448 | 448 | $rgb = array(); |
449 | - $rgb['R'] = hexdec( $color{0}.$color{1} ); |
|
450 | - $rgb['G'] = hexdec( $color{2}.$color{3} ); |
|
451 | - $rgb['B'] = hexdec( $color{4}.$color{5} ); |
|
449 | + $rgb['R'] = hexdec($color{0} . $color{1} ); |
|
450 | + $rgb['G'] = hexdec($color{2} . $color{3} ); |
|
451 | + $rgb['B'] = hexdec($color{4} . $color{5} ); |
|
452 | 452 | |
453 | 453 | return $rgb; |
454 | 454 | } |
455 | 455 | |
456 | -function wpinv_hex_darker( $color, $factor = 30 ) { |
|
457 | - $base = wpinv_rgb_from_hex( $color ); |
|
456 | +function wpinv_hex_darker($color, $factor = 30) { |
|
457 | + $base = wpinv_rgb_from_hex($color); |
|
458 | 458 | $color = '#'; |
459 | 459 | |
460 | - foreach ( $base as $k => $v ) { |
|
460 | + foreach ($base as $k => $v) { |
|
461 | 461 | $amount = $v / 100; |
462 | - $amount = round( $amount * $factor ); |
|
462 | + $amount = round($amount * $factor); |
|
463 | 463 | $new_decimal = $v - $amount; |
464 | 464 | |
465 | - $new_hex_component = dechex( $new_decimal ); |
|
466 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
465 | + $new_hex_component = dechex($new_decimal); |
|
466 | + if (strlen($new_hex_component) < 2) { |
|
467 | 467 | $new_hex_component = "0" . $new_hex_component; |
468 | 468 | } |
469 | 469 | $color .= $new_hex_component; |
@@ -472,18 +472,18 @@ discard block |
||
472 | 472 | return $color; |
473 | 473 | } |
474 | 474 | |
475 | -function wpinv_hex_lighter( $color, $factor = 30 ) { |
|
476 | - $base = wpinv_rgb_from_hex( $color ); |
|
475 | +function wpinv_hex_lighter($color, $factor = 30) { |
|
476 | + $base = wpinv_rgb_from_hex($color); |
|
477 | 477 | $color = '#'; |
478 | 478 | |
479 | - foreach ( $base as $k => $v ) { |
|
479 | + foreach ($base as $k => $v) { |
|
480 | 480 | $amount = 255 - $v; |
481 | 481 | $amount = $amount / 100; |
482 | - $amount = round( $amount * $factor ); |
|
482 | + $amount = round($amount * $factor); |
|
483 | 483 | $new_decimal = $v + $amount; |
484 | 484 | |
485 | - $new_hex_component = dechex( $new_decimal ); |
|
486 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
485 | + $new_hex_component = dechex($new_decimal); |
|
486 | + if (strlen($new_hex_component) < 2) { |
|
487 | 487 | $new_hex_component = "0" . $new_hex_component; |
488 | 488 | } |
489 | 489 | $color .= $new_hex_component; |
@@ -492,22 +492,22 @@ discard block |
||
492 | 492 | return $color; |
493 | 493 | } |
494 | 494 | |
495 | -function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { |
|
496 | - $hex = str_replace( '#', '', $color ); |
|
495 | +function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') { |
|
496 | + $hex = str_replace('#', '', $color); |
|
497 | 497 | |
498 | - $c_r = hexdec( substr( $hex, 0, 2 ) ); |
|
499 | - $c_g = hexdec( substr( $hex, 2, 2 ) ); |
|
500 | - $c_b = hexdec( substr( $hex, 4, 2 ) ); |
|
498 | + $c_r = hexdec(substr($hex, 0, 2)); |
|
499 | + $c_g = hexdec(substr($hex, 2, 2)); |
|
500 | + $c_b = hexdec(substr($hex, 4, 2)); |
|
501 | 501 | |
502 | - $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; |
|
502 | + $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000; |
|
503 | 503 | |
504 | 504 | return $brightness > 155 ? $dark : $light; |
505 | 505 | } |
506 | 506 | |
507 | -function wpinv_format_hex( $hex ) { |
|
508 | - $hex = trim( str_replace( '#', '', $hex ) ); |
|
507 | +function wpinv_format_hex($hex) { |
|
508 | + $hex = trim(str_replace('#', '', $hex)); |
|
509 | 509 | |
510 | - if ( strlen( $hex ) == 3 ) { |
|
510 | + if (strlen($hex) == 3) { |
|
511 | 511 | $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; |
512 | 512 | } |
513 | 513 | |
@@ -527,12 +527,12 @@ discard block |
||
527 | 527 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
528 | 528 | * @return string |
529 | 529 | */ |
530 | -function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) { |
|
531 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
532 | - return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding ); |
|
530 | +function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') { |
|
531 | + if (function_exists('mb_strimwidth')) { |
|
532 | + return mb_strimwidth($str, $start, $width, $trimmaker, $encoding); |
|
533 | 533 | } |
534 | 534 | |
535 | - return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker; |
|
535 | + return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker; |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | /** |
@@ -544,28 +544,28 @@ discard block |
||
544 | 544 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
545 | 545 | * @return int Returns the number of characters in string. |
546 | 546 | */ |
547 | -function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) { |
|
548 | - if ( function_exists( 'mb_strlen' ) ) { |
|
549 | - return mb_strlen( $str, $encoding ); |
|
547 | +function wpinv_utf8_strlen($str, $encoding = 'UTF-8') { |
|
548 | + if (function_exists('mb_strlen')) { |
|
549 | + return mb_strlen($str, $encoding); |
|
550 | 550 | } |
551 | 551 | |
552 | - return strlen( $str ); |
|
552 | + return strlen($str); |
|
553 | 553 | } |
554 | 554 | |
555 | -function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) { |
|
556 | - if ( function_exists( 'mb_strtolower' ) ) { |
|
557 | - return mb_strtolower( $str, $encoding ); |
|
555 | +function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') { |
|
556 | + if (function_exists('mb_strtolower')) { |
|
557 | + return mb_strtolower($str, $encoding); |
|
558 | 558 | } |
559 | 559 | |
560 | - return strtolower( $str ); |
|
560 | + return strtolower($str); |
|
561 | 561 | } |
562 | 562 | |
563 | -function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) { |
|
564 | - if ( function_exists( 'mb_strtoupper' ) ) { |
|
565 | - return mb_strtoupper( $str, $encoding ); |
|
563 | +function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') { |
|
564 | + if (function_exists('mb_strtoupper')) { |
|
565 | + return mb_strtoupper($str, $encoding); |
|
566 | 566 | } |
567 | 567 | |
568 | - return strtoupper( $str ); |
|
568 | + return strtoupper($str); |
|
569 | 569 | } |
570 | 570 | |
571 | 571 | /** |
@@ -579,12 +579,12 @@ discard block |
||
579 | 579 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
580 | 580 | * @return int Returns the position of the first occurrence of search in the string. |
581 | 581 | */ |
582 | -function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
583 | - if ( function_exists( 'mb_strpos' ) ) { |
|
584 | - return mb_strpos( $str, $find, $offset, $encoding ); |
|
582 | +function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
583 | + if (function_exists('mb_strpos')) { |
|
584 | + return mb_strpos($str, $find, $offset, $encoding); |
|
585 | 585 | } |
586 | 586 | |
587 | - return strpos( $str, $find, $offset ); |
|
587 | + return strpos($str, $find, $offset); |
|
588 | 588 | } |
589 | 589 | |
590 | 590 | /** |
@@ -598,12 +598,12 @@ discard block |
||
598 | 598 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
599 | 599 | * @return int Returns the position of the last occurrence of search. |
600 | 600 | */ |
601 | -function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
602 | - if ( function_exists( 'mb_strrpos' ) ) { |
|
603 | - return mb_strrpos( $str, $find, $offset, $encoding ); |
|
601 | +function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
602 | + if (function_exists('mb_strrpos')) { |
|
603 | + return mb_strrpos($str, $find, $offset, $encoding); |
|
604 | 604 | } |
605 | 605 | |
606 | - return strrpos( $str, $find, $offset ); |
|
606 | + return strrpos($str, $find, $offset); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | /** |
@@ -618,16 +618,16 @@ discard block |
||
618 | 618 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
619 | 619 | * @return string |
620 | 620 | */ |
621 | -function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) { |
|
622 | - if ( function_exists( 'mb_substr' ) ) { |
|
623 | - if ( $length === null ) { |
|
624 | - return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
621 | +function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') { |
|
622 | + if (function_exists('mb_substr')) { |
|
623 | + if ($length === null) { |
|
624 | + return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
625 | 625 | } else { |
626 | - return mb_substr( $str, $start, $length, $encoding ); |
|
626 | + return mb_substr($str, $start, $length, $encoding); |
|
627 | 627 | } |
628 | 628 | } |
629 | 629 | |
630 | - return substr( $str, $start, $length ); |
|
630 | + return substr($str, $start, $length); |
|
631 | 631 | } |
632 | 632 | |
633 | 633 | /** |
@@ -639,48 +639,48 @@ discard block |
||
639 | 639 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
640 | 640 | * @return string The width of string. |
641 | 641 | */ |
642 | -function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) { |
|
643 | - if ( function_exists( 'mb_strwidth' ) ) { |
|
644 | - return mb_strwidth( $str, $encoding ); |
|
642 | +function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') { |
|
643 | + if (function_exists('mb_strwidth')) { |
|
644 | + return mb_strwidth($str, $encoding); |
|
645 | 645 | } |
646 | 646 | |
647 | - return wpinv_utf8_strlen( $str, $encoding ); |
|
647 | + return wpinv_utf8_strlen($str, $encoding); |
|
648 | 648 | } |
649 | 649 | |
650 | -function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) { |
|
651 | - if ( function_exists( 'mb_strlen' ) ) { |
|
652 | - $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding ); |
|
650 | +function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') { |
|
651 | + if (function_exists('mb_strlen')) { |
|
652 | + $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding); |
|
653 | 653 | $str_end = ""; |
654 | 654 | |
655 | - if ( $lower_str_end ) { |
|
656 | - $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding ); |
|
655 | + if ($lower_str_end) { |
|
656 | + $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding); |
|
657 | 657 | } else { |
658 | - $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
658 | + $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | return $first_letter . $str_end; |
662 | 662 | } |
663 | 663 | |
664 | - return ucfirst( $str ); |
|
664 | + return ucfirst($str); |
|
665 | 665 | } |
666 | 666 | |
667 | -function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) { |
|
668 | - if ( function_exists( 'mb_convert_case' ) ) { |
|
669 | - return mb_convert_case( $str, MB_CASE_TITLE, $encoding ); |
|
667 | +function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') { |
|
668 | + if (function_exists('mb_convert_case')) { |
|
669 | + return mb_convert_case($str, MB_CASE_TITLE, $encoding); |
|
670 | 670 | } |
671 | 671 | |
672 | - return ucwords( $str ); |
|
672 | + return ucwords($str); |
|
673 | 673 | } |
674 | 674 | |
675 | -function wpinv_period_in_days( $period, $unit ) { |
|
676 | - $period = absint( $period ); |
|
675 | +function wpinv_period_in_days($period, $unit) { |
|
676 | + $period = absint($period); |
|
677 | 677 | |
678 | - if ( $period > 0 ) { |
|
679 | - if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) { |
|
678 | + if ($period > 0) { |
|
679 | + if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) { |
|
680 | 680 | $period = $period * 7; |
681 | - } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) { |
|
681 | + } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) { |
|
682 | 682 | $period = $period * 30; |
683 | - } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) { |
|
683 | + } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) { |
|
684 | 684 | $period = $period * 365; |
685 | 685 | } |
686 | 686 | } |