@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Authorize.net Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'sandbox', 'tokens' ); |
|
27 | + protected $supports = array('subscription', 'sandbox', 'tokens'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @var array |
54 | 54 | */ |
55 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
55 | + public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD'); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * URL to view a transaction. |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function __construct() { |
68 | 68 | |
69 | - $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
|
70 | - $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
|
71 | - $this->notify_url = wpinv_get_ipn_url( $this->id ); |
|
69 | + $this->title = __('Credit Card / Debit Card', 'invoicing'); |
|
70 | + $this->method_title = __('Authorize.Net', 'invoicing'); |
|
71 | + $this->notify_url = wpinv_get_ipn_url($this->id); |
|
72 | 72 | |
73 | - add_filter( 'getpaid_daily_maintenance_should_expire_subscription', array( $this, 'maybe_renew_subscription' ), 10, 2 ); |
|
74 | - add_filter( 'getpaid_authorizenet_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
73 | + add_filter('getpaid_daily_maintenance_should_expire_subscription', array($this, 'maybe_renew_subscription'), 10, 2); |
|
74 | + add_filter('getpaid_authorizenet_sandbox_notice', array($this, 'sandbox_notice')); |
|
75 | 75 | parent::__construct(); |
76 | 76 | } |
77 | 77 | |
@@ -81,13 +81,13 @@ discard block |
||
81 | 81 | * @param int $invoice_id 0 or invoice id. |
82 | 82 | * @param GetPaid_Payment_Form $form Current payment form. |
83 | 83 | */ |
84 | - public function payment_fields( $invoice_id, $form ) { |
|
84 | + public function payment_fields($invoice_id, $form) { |
|
85 | 85 | |
86 | 86 | // Let the user select a payment method. |
87 | 87 | echo $this->saved_payment_methods(); |
88 | 88 | |
89 | 89 | // Show the credit card entry form. |
90 | - echo $this->new_payment_method_entry( $this->get_cc_form( true ) ); |
|
90 | + echo $this->new_payment_method_entry($this->get_cc_form(true)); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -100,64 +100,64 @@ discard block |
||
100 | 100 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
101 | 101 | * @return string|WP_Error Payment profile id. |
102 | 102 | */ |
103 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
103 | + public function create_customer_profile($invoice, $submission_data, $save = true) { |
|
104 | 104 | |
105 | 105 | // Remove non-digits from the number |
106 | - $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
106 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
107 | 107 | |
108 | 108 | // Generate args. |
109 | 109 | $args = array( |
110 | 110 | 'createCustomerProfileRequest' => array( |
111 | 111 | 'merchantAuthentication' => $this->get_auth_params(), |
112 | 112 | 'profile' => array( |
113 | - 'merchantCustomerId' => getpaid_limit_length( $invoice->get_user_id(), 20 ), |
|
114 | - 'description' => getpaid_limit_length( $invoice->get_full_name(), 255 ), |
|
115 | - 'email' => getpaid_limit_length( $invoice->get_email(), 255 ), |
|
113 | + 'merchantCustomerId' => getpaid_limit_length($invoice->get_user_id(), 20), |
|
114 | + 'description' => getpaid_limit_length($invoice->get_full_name(), 255), |
|
115 | + 'email' => getpaid_limit_length($invoice->get_email(), 255), |
|
116 | 116 | 'paymentProfiles' => array( |
117 | 117 | 'customerType' => 'individual', |
118 | 118 | |
119 | 119 | // Billing information. |
120 | 120 | 'billTo' => array( |
121 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
122 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
123 | - 'address' => getpaid_limit_length( $invoice->get_last_name(), 60 ), |
|
124 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
125 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
126 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
127 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
121 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
122 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
123 | + 'address' => getpaid_limit_length($invoice->get_last_name(), 60), |
|
124 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
125 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
126 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
127 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
128 | 128 | ), |
129 | 129 | |
130 | 130 | // Payment information. |
131 | - 'payment' => $this->get_payment_information( $submission_data['authorizenet'] ), |
|
131 | + 'payment' => $this->get_payment_information($submission_data['authorizenet']), |
|
132 | 132 | ) |
133 | 133 | ), |
134 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
134 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
135 | 135 | ) |
136 | 136 | ); |
137 | 137 | |
138 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice ); |
|
138 | + $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice); |
|
139 | 139 | |
140 | - if ( is_wp_error( $response ) ) { |
|
140 | + if (is_wp_error($response)) { |
|
141 | 141 | return $response; |
142 | 142 | } |
143 | 143 | |
144 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId ); |
|
144 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId); |
|
145 | 145 | |
146 | 146 | // Save the payment token. |
147 | - if ( $save ) { |
|
147 | + if ($save) { |
|
148 | 148 | $this->save_token( |
149 | 149 | array( |
150 | 150 | 'id' => $response->customerPaymentProfileIdList[0], |
151 | - 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '····' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
151 | + 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . '····' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
152 | 152 | 'default' => true, |
153 | - 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
153 | + 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
154 | 154 | ) |
155 | 155 | ); |
156 | 156 | } |
157 | 157 | |
158 | 158 | // Add a note about the validation response. |
159 | 159 | $invoice->add_note( |
160 | - sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ), |
|
160 | + sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]), |
|
161 | 161 | false, |
162 | 162 | false, |
163 | 163 | true |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | * @return string|WP_Error Profile id. |
175 | 175 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
176 | 176 | */ |
177 | - public function get_customer_profile( $profile_id ) { |
|
177 | + public function get_customer_profile($profile_id) { |
|
178 | 178 | |
179 | 179 | // Generate args. |
180 | 180 | $args = array( |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | ) |
185 | 185 | ); |
186 | 186 | |
187 | - return $this->post( $args, false ); |
|
187 | + return $this->post($args, false); |
|
188 | 188 | |
189 | 189 | } |
190 | 190 | |
@@ -199,10 +199,10 @@ discard block |
||
199 | 199 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
200 | 200 | * @return string|WP_Error Profile id. |
201 | 201 | */ |
202 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
202 | + public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) { |
|
203 | 203 | |
204 | 204 | // Remove non-digits from the number |
205 | - $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
205 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
206 | 206 | |
207 | 207 | // Generate args. |
208 | 208 | $args = array( |
@@ -213,34 +213,34 @@ discard block |
||
213 | 213 | |
214 | 214 | // Billing information. |
215 | 215 | 'billTo' => array( |
216 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
217 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
218 | - 'address' => getpaid_limit_length( $invoice->get_last_name(), 60 ), |
|
219 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
220 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
221 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
222 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
216 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
217 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
218 | + 'address' => getpaid_limit_length($invoice->get_last_name(), 60), |
|
219 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
220 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
221 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
222 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
223 | 223 | ), |
224 | 224 | |
225 | 225 | // Payment information. |
226 | - 'payment' => $this->get_payment_information( $submission_data['authorizenet'] ) |
|
226 | + 'payment' => $this->get_payment_information($submission_data['authorizenet']) |
|
227 | 227 | ), |
228 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
228 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
229 | 229 | ) |
230 | 230 | ); |
231 | 231 | |
232 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
232 | + $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice); |
|
233 | 233 | |
234 | - if ( is_wp_error( $response ) ) { |
|
234 | + if (is_wp_error($response)) { |
|
235 | 235 | return $response; |
236 | 236 | } |
237 | 237 | |
238 | 238 | // Save the payment token. |
239 | - if ( $save ) { |
|
239 | + if ($save) { |
|
240 | 240 | $this->save_token( |
241 | 241 | array( |
242 | 242 | 'id' => $response->customerPaymentProfileId, |
243 | - 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' ···· ' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
243 | + 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . ' ···· ' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
244 | 244 | 'default' => true |
245 | 245 | ) |
246 | 246 | ); |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | |
249 | 249 | // Add a note about the validation response. |
250 | 250 | $invoice->add_note( |
251 | - sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ), |
|
251 | + sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse), |
|
252 | 252 | false, |
253 | 253 | false, |
254 | 254 | true |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | * @return string|WP_Error Profile id. |
268 | 268 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
269 | 269 | */ |
270 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
270 | + public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) { |
|
271 | 271 | |
272 | 272 | // Generate args. |
273 | 273 | $args = array( |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | ) |
279 | 279 | ); |
280 | 280 | |
281 | - return $this->post( $args, false ); |
|
281 | + return $this->post($args, false); |
|
282 | 282 | |
283 | 283 | } |
284 | 284 | |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
292 | 292 | * @return WP_Error|object |
293 | 293 | */ |
294 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
294 | + public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) { |
|
295 | 295 | |
296 | 296 | // Generate args. |
297 | 297 | $args = array( |
@@ -311,28 +311,28 @@ discard block |
||
311 | 311 | ) |
312 | 312 | ), |
313 | 313 | 'order' => array( |
314 | - 'invoiceNumber' => getpaid_limit_length( $invoice->get_number(), 20 ), |
|
314 | + 'invoiceNumber' => getpaid_limit_length($invoice->get_number(), 20), |
|
315 | 315 | ), |
316 | - 'lineItems' => array( 'lineItem' => $this->get_line_items( $invoice ) ), |
|
316 | + 'lineItems' => array('lineItem' => $this->get_line_items($invoice)), |
|
317 | 317 | 'tax' => array( |
318 | 318 | 'amount' => $invoice->get_total_tax(), |
319 | - 'name' => __( 'TAX', 'invoicing' ), |
|
319 | + 'name' => __('TAX', 'invoicing'), |
|
320 | 320 | ), |
321 | - 'poNumber' => getpaid_limit_length( $invoice->get_number(), 25 ), |
|
321 | + 'poNumber' => getpaid_limit_length($invoice->get_number(), 25), |
|
322 | 322 | 'customer' => array( |
323 | - 'id' => getpaid_limit_length( $invoice->get_user_id(), 25 ), |
|
324 | - 'email' => getpaid_limit_length( $invoice->get_email(), 25 ), |
|
323 | + 'id' => getpaid_limit_length($invoice->get_user_id(), 25), |
|
324 | + 'email' => getpaid_limit_length($invoice->get_email(), 25), |
|
325 | 325 | ), |
326 | 326 | 'customerIP' => $invoice->get_ip(), |
327 | 327 | ) |
328 | 328 | ) |
329 | 329 | ); |
330 | 330 | |
331 | - if ( 0 == $invoice->get_total_tax() ) { |
|
332 | - unset( $args['createTransactionRequest']['transactionRequest']['tax'] ); |
|
331 | + if (0 == $invoice->get_total_tax()) { |
|
332 | + unset($args['createTransactionRequest']['transactionRequest']['tax']); |
|
333 | 333 | } |
334 | 334 | |
335 | - return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
335 | + return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice); |
|
336 | 336 | |
337 | 337 | } |
338 | 338 | |
@@ -342,29 +342,29 @@ discard block |
||
342 | 342 | * @param stdClass $result Api response. |
343 | 343 | * @param WPInv_Invoice $invoice Invoice. |
344 | 344 | */ |
345 | - public function process_charge_response( $result, $invoice ) { |
|
345 | + public function process_charge_response($result, $invoice) { |
|
346 | 346 | |
347 | 347 | wpinv_clear_errors(); |
348 | 348 | $response_code = (int) $result->transactionResponse->responseCode; |
349 | 349 | |
350 | 350 | // Succeeded. |
351 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
351 | + if (1 == $response_code || 4 == $response_code) { |
|
352 | 352 | |
353 | 353 | // Maybe set a transaction id. |
354 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
355 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
354 | + if (!empty($result->transactionResponse->transId)) { |
|
355 | + $invoice->set_transaction_id($result->transactionResponse->transId); |
|
356 | 356 | } |
357 | 357 | |
358 | - $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
358 | + $invoice->add_note(sprintf(__('Authentication code: %s (%s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true); |
|
359 | 359 | |
360 | - if ( 1 == $response_code ) { |
|
360 | + if (1 == $response_code) { |
|
361 | 361 | return $invoice->mark_paid(); |
362 | 362 | } |
363 | 363 | |
364 | - $invoice->set_status( 'wpi-onhold' ); |
|
364 | + $invoice->set_status('wpi-onhold'); |
|
365 | 365 | $invoice->add_note( |
366 | 366 | sprintf( |
367 | - __( 'Held for review: %s', 'invoicing' ), |
|
367 | + __('Held for review: %s', 'invoicing'), |
|
368 | 368 | $result->transactionResponse->messages->message[0]->description |
369 | 369 | ) |
370 | 370 | ); |
@@ -373,11 +373,11 @@ discard block |
||
373 | 373 | |
374 | 374 | } |
375 | 375 | |
376 | - wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) ); |
|
376 | + wpinv_set_error('card_declined', __('Credit card declined.', 'invoicing')); |
|
377 | 377 | |
378 | - if ( ! empty( $result->transactionResponse->errors ) ) { |
|
378 | + if (!empty($result->transactionResponse->errors)) { |
|
379 | 379 | $errors = (object) $result->transactionResponse->errors; |
380 | - wpinv_set_error( $errors->error[0]->errorCode, esc_html( $errors->error[0]->errorText ) ); |
|
380 | + wpinv_set_error($errors->error[0]->errorCode, esc_html($errors->error[0]->errorText)); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | } |
@@ -389,10 +389,10 @@ discard block |
||
389 | 389 | * @param array $card Card details. |
390 | 390 | * @return array |
391 | 391 | */ |
392 | - public function get_payment_information( $card ) { |
|
392 | + public function get_payment_information($card) { |
|
393 | 393 | return array( |
394 | 394 | |
395 | - 'creditCard' => array ( |
|
395 | + 'creditCard' => array( |
|
396 | 396 | 'cardNumber' => $card['cc_number'], |
397 | 397 | 'expirationDate' => $card['cc_expire_year'] . '-' . $card['cc_expire_month'], |
398 | 398 | 'cardCode' => $card['cc_cvv2'], |
@@ -408,8 +408,8 @@ discard block |
||
408 | 408 | * @param WPInv_Invoice $invoice Invoice. |
409 | 409 | * @return string |
410 | 410 | */ |
411 | - public function get_customer_profile_meta_name( $invoice ) { |
|
412 | - return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
411 | + public function get_customer_profile_meta_name($invoice) { |
|
412 | + return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | /** |
@@ -420,34 +420,34 @@ discard block |
||
420 | 420 | * @param WPInv_Invoice $invoice |
421 | 421 | * @return WP_Error|string The payment profile id |
422 | 422 | */ |
423 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
423 | + public function validate_submission_data($submission_data, $invoice) { |
|
424 | 424 | |
425 | 425 | // Validate authentication details. |
426 | 426 | $auth = $this->get_auth_params(); |
427 | 427 | |
428 | - if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) { |
|
429 | - return new WP_Error( 'invalid_settings', __( 'Please set-up your login id and transaction key before using this gateway.', 'invoicing') ); |
|
428 | + if (empty($auth['name']) || empty($auth['transactionKey'])) { |
|
429 | + return new WP_Error('invalid_settings', __('Please set-up your login id and transaction key before using this gateway.', 'invoicing')); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | // Validate the payment method. |
433 | - if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) { |
|
434 | - return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing') ); |
|
433 | + if (empty($submission_data['getpaid-authorizenet-payment-method'])) { |
|
434 | + return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing')); |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | // Are we adding a new payment method? |
438 | - if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) { |
|
438 | + if ('new' != $submission_data['getpaid-authorizenet-payment-method']) { |
|
439 | 439 | return $submission_data['getpaid-authorizenet-payment-method']; |
440 | 440 | } |
441 | 441 | |
442 | 442 | // Retrieve the customer profile id. |
443 | - $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
443 | + $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
444 | 444 | |
445 | 445 | // Create payment method. |
446 | - if ( empty( $profile_id ) ) { |
|
447 | - return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
446 | + if (empty($profile_id)) { |
|
447 | + return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
448 | 448 | } |
449 | 449 | |
450 | - return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
450 | + return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
451 | 451 | |
452 | 452 | } |
453 | 453 | |
@@ -458,16 +458,16 @@ discard block |
||
458 | 458 | * @param WPInv_Invoice $invoice Invoice. |
459 | 459 | * @return array |
460 | 460 | */ |
461 | - public function get_line_items( $invoice ) { |
|
461 | + public function get_line_items($invoice) { |
|
462 | 462 | $items = array(); |
463 | 463 | |
464 | - foreach ( $invoice->get_items() as $item ) { |
|
464 | + foreach ($invoice->get_items() as $item) { |
|
465 | 465 | |
466 | 466 | $amount = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price(); |
467 | 467 | $items[] = array( |
468 | - 'itemId' => getpaid_limit_length( $item->get_id(), 31 ), |
|
469 | - 'name' => getpaid_limit_length( $item->get_raw_name(), 31 ), |
|
470 | - 'description' => getpaid_limit_length( $item->get_description(), 255 ), |
|
468 | + 'itemId' => getpaid_limit_length($item->get_id(), 31), |
|
469 | + 'name' => getpaid_limit_length($item->get_raw_name(), 31), |
|
470 | + 'description' => getpaid_limit_length($item->get_description(), 255), |
|
471 | 471 | 'quantity' => (string) $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(), |
472 | 472 | 'unitPrice' => (float) $amount, |
473 | 473 | 'taxable' => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(), |
@@ -475,15 +475,15 @@ discard block |
||
475 | 475 | |
476 | 476 | } |
477 | 477 | |
478 | - foreach ( $invoice->get_fees() as $fee_name => $fee ) { |
|
478 | + foreach ($invoice->get_fees() as $fee_name => $fee) { |
|
479 | 479 | |
480 | - $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee']; |
|
480 | + $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee']; |
|
481 | 481 | |
482 | - if ( $amount > 0 ) { |
|
482 | + if ($amount > 0) { |
|
483 | 483 | $items[] = array( |
484 | - 'itemId' => getpaid_limit_length( $fee_name, 31 ), |
|
485 | - 'name' => getpaid_limit_length( $fee_name, 31 ), |
|
486 | - 'description' => getpaid_limit_length( $fee_name, 255 ), |
|
484 | + 'itemId' => getpaid_limit_length($fee_name, 31), |
|
485 | + 'name' => getpaid_limit_length($fee_name, 31), |
|
486 | + 'description' => getpaid_limit_length($fee_name, 255), |
|
487 | 487 | 'quantity' => '1', |
488 | 488 | 'unitPrice' => (float) $amount, |
489 | 489 | 'taxable' => false, |
@@ -504,36 +504,36 @@ discard block |
||
504 | 504 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
505 | 505 | * @return array |
506 | 506 | */ |
507 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
507 | + public function process_payment($invoice, $submission_data, $submission) { |
|
508 | 508 | |
509 | 509 | // Validate the submitted data. |
510 | - $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
|
510 | + $payment_profile_id = $this->validate_submission_data($submission_data, $invoice); |
|
511 | 511 | |
512 | 512 | // Do we have an error? |
513 | - if ( is_wp_error( $payment_profile_id ) ) { |
|
514 | - wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() ); |
|
513 | + if (is_wp_error($payment_profile_id)) { |
|
514 | + wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message()); |
|
515 | 515 | wpinv_send_back_to_checkout(); |
516 | 516 | } |
517 | 517 | |
518 | 518 | // Save the payment method to the order. |
519 | - update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id ); |
|
519 | + update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id); |
|
520 | 520 | |
521 | 521 | // Check if this is a subscription or not. |
522 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
523 | - if ( ! empty( $subscription ) ) { |
|
524 | - $this->process_subscription( $invoice, $subscription ); |
|
522 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
523 | + if (!empty($subscription)) { |
|
524 | + $this->process_subscription($invoice, $subscription); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | // If it is free, send to the success page. |
528 | - if ( ! $invoice->needs_payment() ) { |
|
528 | + if (!$invoice->needs_payment()) { |
|
529 | 529 | $invoice->mark_paid(); |
530 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
530 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | // Charge the payment profile. |
534 | - $this->process_initial_payment( $invoice ); |
|
534 | + $this->process_initial_payment($invoice); |
|
535 | 535 | |
536 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
536 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
537 | 537 | |
538 | 538 | exit; |
539 | 539 | |
@@ -544,22 +544,22 @@ discard block |
||
544 | 544 | * |
545 | 545 | * @param WPInv_Invoice $invoice Invoice. |
546 | 546 | */ |
547 | - protected function process_initial_payment( $invoice ) { |
|
547 | + protected function process_initial_payment($invoice) { |
|
548 | 548 | |
549 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
550 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
551 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
549 | + $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
550 | + $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
551 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
552 | 552 | |
553 | 553 | // Do we have an error? |
554 | - if ( is_wp_error( $result ) ) { |
|
555 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
554 | + if (is_wp_error($result)) { |
|
555 | + wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
556 | 556 | wpinv_send_back_to_checkout(); |
557 | 557 | } |
558 | 558 | |
559 | 559 | // Process the response. |
560 | - $this->process_charge_response( $result, $invoice ); |
|
560 | + $this->process_charge_response($result, $invoice); |
|
561 | 561 | |
562 | - if ( wpinv_get_errors() ) { |
|
562 | + if (wpinv_get_errors()) { |
|
563 | 563 | wpinv_send_back_to_checkout(); |
564 | 564 | } |
565 | 565 | |
@@ -571,24 +571,24 @@ discard block |
||
571 | 571 | * @param WPInv_Invoice $invoice Invoice. |
572 | 572 | * @param WPInv_Subscription $subscription Subscription. |
573 | 573 | */ |
574 | - public function process_subscription( $invoice, $subscription ) { |
|
574 | + public function process_subscription($invoice, $subscription) { |
|
575 | 575 | |
576 | 576 | // Check if there is an initial amount to charge. |
577 | - if ( (float) $invoice->get_total() > 0 ) { |
|
578 | - $this->process_initial_payment( $invoice ); |
|
577 | + if ((float) $invoice->get_total() > 0) { |
|
578 | + $this->process_initial_payment($invoice); |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | // Activate the subscription. |
582 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
583 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
582 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
583 | + $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
584 | 584 | |
585 | - $subscription->set_next_renewal_date( $expiry ); |
|
586 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
587 | - $subscription->set_profile_id( $invoice->generate_key() ); |
|
585 | + $subscription->set_next_renewal_date($expiry); |
|
586 | + $subscription->set_date_created(current_time('mysql')); |
|
587 | + $subscription->set_profile_id($invoice->generate_key()); |
|
588 | 588 | $subscription->activate(); |
589 | 589 | |
590 | 590 | // Redirect to the success page. |
591 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
591 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
592 | 592 | |
593 | 593 | } |
594 | 594 | |
@@ -599,20 +599,20 @@ discard block |
||
599 | 599 | * @param bool $should_expire |
600 | 600 | * @param WPInv_Subscription $subscription |
601 | 601 | */ |
602 | - public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
602 | + public function maybe_renew_subscription($should_expire, $subscription) { |
|
603 | 603 | |
604 | 604 | // Ensure its our subscription && it's active. |
605 | - if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) { |
|
605 | + if ($this->id != $subscription->get_gateway() || !$subscription->has_status('active trialling')) { |
|
606 | 606 | return $should_expire; |
607 | 607 | } |
608 | 608 | |
609 | 609 | // If this is the last renewal, complete the subscription. |
610 | - if ( $subscription->is_last_renewal() ) { |
|
610 | + if ($subscription->is_last_renewal()) { |
|
611 | 611 | $subscription->complete(); |
612 | 612 | return false; |
613 | 613 | } |
614 | 614 | |
615 | - $this->renew_subscription( $subscription ); |
|
615 | + $this->renew_subscription($subscription); |
|
616 | 616 | |
617 | 617 | return false; |
618 | 618 | |
@@ -623,28 +623,28 @@ discard block |
||
623 | 623 | * |
624 | 624 | * @param WPInv_Subscription $subscription |
625 | 625 | */ |
626 | - public function renew_subscription( $subscription ) { |
|
626 | + public function renew_subscription($subscription) { |
|
627 | 627 | |
628 | 628 | // Generate the renewal invoice. |
629 | 629 | $new_invoice = $subscription->create_payment(); |
630 | 630 | $old_invoice = $subscription->get_parent_payment(); |
631 | 631 | |
632 | - if ( empty( $new_invoice ) ) { |
|
633 | - $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
|
632 | + if (empty($new_invoice)) { |
|
633 | + $old_invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false); |
|
634 | 634 | $subscription->failing(); |
635 | 635 | return; |
636 | 636 | } |
637 | 637 | |
638 | 638 | // Charge the payment method. |
639 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
640 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
641 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
639 | + $payment_profile_id = get_post_meta($old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
640 | + $customer_profile = get_user_meta($old_invoice->get_user_id(), $this->get_customer_profile_meta_name($old_invoice), true); |
|
641 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice); |
|
642 | 642 | |
643 | 643 | // Do we have an error? |
644 | - if ( is_wp_error( $result ) ) { |
|
644 | + if (is_wp_error($result)) { |
|
645 | 645 | |
646 | 646 | $old_invoice->add_note( |
647 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
647 | + sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()), |
|
648 | 648 | true, |
649 | 649 | false, |
650 | 650 | true |
@@ -655,12 +655,12 @@ discard block |
||
655 | 655 | } |
656 | 656 | |
657 | 657 | // Process the response. |
658 | - $this->process_charge_response( $result, $new_invoice ); |
|
658 | + $this->process_charge_response($result, $new_invoice); |
|
659 | 659 | |
660 | - if ( wpinv_get_errors() ) { |
|
660 | + if (wpinv_get_errors()) { |
|
661 | 661 | |
662 | 662 | $old_invoice->add_note( |
663 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
663 | + sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()), |
|
664 | 664 | true, |
665 | 665 | false, |
666 | 666 | true |
@@ -670,7 +670,7 @@ discard block |
||
670 | 670 | |
671 | 671 | } |
672 | 672 | |
673 | - $subscription->add_payment( array(), $new_invoice ); |
|
673 | + $subscription->add_payment(array(), $new_invoice); |
|
674 | 674 | $subscription->renew(); |
675 | 675 | } |
676 | 676 | |
@@ -680,7 +680,7 @@ discard block |
||
680 | 680 | public function sandbox_notice() { |
681 | 681 | |
682 | 682 | return sprintf( |
683 | - __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
683 | + __('SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing'), |
|
684 | 684 | '<a href="https://developer.authorize.net/hello_world/testing_guide.html">', |
685 | 685 | '</a>' |
686 | 686 | ); |
@@ -692,42 +692,42 @@ discard block |
||
692 | 692 | * |
693 | 693 | * @param array $admin_settings |
694 | 694 | */ |
695 | - public function admin_settings( $admin_settings ) { |
|
695 | + public function admin_settings($admin_settings) { |
|
696 | 696 | |
697 | 697 | $currencies = sprintf( |
698 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
699 | - implode( ', ', $this->currencies ) |
|
698 | + __('Supported Currencies: %s', 'invoicing'), |
|
699 | + implode(', ', $this->currencies) |
|
700 | 700 | ); |
701 | 701 | |
702 | 702 | $admin_settings['authorizenet_active']['desc'] .= " ($currencies)"; |
703 | - $admin_settings['authorizenet_desc']['std'] = __( 'Pay securely using your credit or debit card.', 'invoicing' ); |
|
703 | + $admin_settings['authorizenet_desc']['std'] = __('Pay securely using your credit or debit card.', 'invoicing'); |
|
704 | 704 | |
705 | 705 | $admin_settings['authorizenet_login_id'] = array( |
706 | 706 | 'type' => 'text', |
707 | 707 | 'id' => 'authorizenet_login_id', |
708 | - 'name' => __( 'API Login ID', 'invoicing' ), |
|
709 | - 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>', |
|
708 | + 'name' => __('API Login ID', 'invoicing'), |
|
709 | + 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>', |
|
710 | 710 | ); |
711 | 711 | |
712 | 712 | $admin_settings['authorizenet_transaction_key'] = array( |
713 | 713 | 'type' => 'text', |
714 | 714 | 'id' => 'authorizenet_transaction_key', |
715 | - 'name' => __( 'Transaction Key', 'invoicing' ), |
|
715 | + 'name' => __('Transaction Key', 'invoicing'), |
|
716 | 716 | ); |
717 | 717 | |
718 | 718 | $admin_settings['authorizenet_signature_key'] = array( |
719 | 719 | 'type' => 'text', |
720 | 720 | 'id' => 'authorizenet_signature_key', |
721 | - 'name' => __( 'Signature Key', 'invoicing' ), |
|
722 | - 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
721 | + 'name' => __('Signature Key', 'invoicing'), |
|
722 | + 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
723 | 723 | ); |
724 | 724 | |
725 | 725 | $admin_settings['authorizenet_ipn_url'] = array( |
726 | 726 | 'type' => 'ipn_url', |
727 | 727 | 'id' => 'authorizenet_ipn_url', |
728 | - 'name' => __( 'Webhook URL', 'invoicing' ), |
|
728 | + 'name' => __('Webhook URL', 'invoicing'), |
|
729 | 729 | 'std' => $this->notify_url, |
730 | - 'desc' => __( 'Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing' ) . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
730 | + 'desc' => __('Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing') . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
731 | 731 | 'custom' => 'authorizenet', |
732 | 732 | 'readonly' => true, |
733 | 733 | ); |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Retrieves the current invoice. |
@@ -14,15 +14,15 @@ discard block |
||
14 | 14 | function getpaid_get_current_invoice_id() { |
15 | 15 | |
16 | 16 | // Ensure that we have an invoice key. |
17 | - if ( empty( $_GET['invoice_key'] ) ) { |
|
17 | + if (empty($_GET['invoice_key'])) { |
|
18 | 18 | return 0; |
19 | 19 | } |
20 | 20 | |
21 | 21 | // Retrieve an invoice using the key. |
22 | - $invoice = new WPInv_Invoice( $_GET['invoice_key'] ); |
|
22 | + $invoice = new WPInv_Invoice($_GET['invoice_key']); |
|
23 | 23 | |
24 | 24 | // Compare the invoice key and the parsed key. |
25 | - if ( $invoice->get_id() != 0 && $invoice->get_key() == $_GET['invoice_key'] ) { |
|
25 | + if ($invoice->get_id() != 0 && $invoice->get_key() == $_GET['invoice_key']) { |
|
26 | 26 | return $invoice->get_id(); |
27 | 27 | } |
28 | 28 | |
@@ -32,42 +32,42 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * Checks if the current user cna view an invoice. |
34 | 34 | */ |
35 | -function wpinv_user_can_view_invoice( $invoice ) { |
|
36 | - $invoice = new WPInv_Invoice( $invoice ); |
|
35 | +function wpinv_user_can_view_invoice($invoice) { |
|
36 | + $invoice = new WPInv_Invoice($invoice); |
|
37 | 37 | |
38 | 38 | // Abort if the invoice does not exist. |
39 | - if ( 0 == $invoice->get_id() ) { |
|
39 | + if (0 == $invoice->get_id()) { |
|
40 | 40 | return false; |
41 | 41 | } |
42 | 42 | |
43 | 43 | // Don't allow trash, draft status |
44 | - if ( $invoice->is_draft() ) { |
|
44 | + if ($invoice->is_draft()) { |
|
45 | 45 | return false; |
46 | 46 | } |
47 | 47 | |
48 | 48 | // If users are not required to login to check out, compare the invoice keys. |
49 | - if ( ! wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && trim( $_GET['invoice_key'] ) == $invoice->get_key() ) { |
|
49 | + if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && trim($_GET['invoice_key']) == $invoice->get_key()) { |
|
50 | 50 | return true; |
51 | 51 | } |
52 | 52 | |
53 | 53 | // Always enable for admins.. |
54 | - if ( wpinv_current_user_can_manage_invoicing() || current_user_can( 'view_invoices', $invoice->get_id() ) ) { // Admin user |
|
54 | + if (wpinv_current_user_can_manage_invoicing() || current_user_can('view_invoices', $invoice->get_id())) { // Admin user |
|
55 | 55 | return true; |
56 | 56 | } |
57 | 57 | |
58 | 58 | // Else, ensure that this is their invoice. |
59 | - if ( is_user_logged_in() && $invoice->get_user_id() == get_current_user_id() ) { |
|
59 | + if (is_user_logged_in() && $invoice->get_user_id() == get_current_user_id()) { |
|
60 | 60 | return true; |
61 | 61 | } |
62 | 62 | |
63 | - return apply_filters( 'wpinv_current_user_can_view_invoice', false, $invoice ); |
|
63 | + return apply_filters('wpinv_current_user_can_view_invoice', false, $invoice); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * Checks if the current user cna view an invoice receipt. |
68 | 68 | */ |
69 | -function wpinv_can_view_receipt( $invoice ) { |
|
70 | - return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice ); |
|
69 | +function wpinv_can_view_receipt($invoice) { |
|
70 | + return (bool) apply_filters('wpinv_can_view_receipt', wpinv_user_can_view_invoice($invoice), $invoice); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -77,11 +77,11 @@ discard block |
||
77 | 77 | */ |
78 | 78 | function getpaid_get_invoice_post_types() { |
79 | 79 | $post_types = array( |
80 | - 'wpi_quote' => __( 'Quote', 'invoicing' ), |
|
81 | - 'wpi_invoice' => __( 'Invoice', 'invoicing' ), |
|
80 | + 'wpi_quote' => __('Quote', 'invoicing'), |
|
81 | + 'wpi_invoice' => __('Invoice', 'invoicing'), |
|
82 | 82 | ); |
83 | 83 | |
84 | - return apply_filters( 'getpaid_invoice_post_types', $post_types ); |
|
84 | + return apply_filters('getpaid_invoice_post_types', $post_types); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -90,8 +90,8 @@ discard block |
||
90 | 90 | * |
91 | 91 | * @param string $post_type The post type to check for. |
92 | 92 | */ |
93 | -function getpaid_is_invoice_post_type( $post_type ) { |
|
94 | - return ! empty( $post_type ) && array_key_exists( $post_type, getpaid_get_invoice_post_types() ); |
|
93 | +function getpaid_is_invoice_post_type($post_type) { |
|
94 | + return !empty($post_type) && array_key_exists($post_type, getpaid_get_invoice_post_types()); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | * @param bool $wp_error Whether to return false or WP_Error on failure. |
102 | 102 | * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success. |
103 | 103 | */ |
104 | -function wpinv_create_invoice( $data = array(), $deprecated = null, $wp_error = false ) { |
|
105 | - $data[ 'invoice_id' ] = 0; |
|
106 | - return wpinv_insert_invoice( $data, $wp_error ); |
|
104 | +function wpinv_create_invoice($data = array(), $deprecated = null, $wp_error = false) { |
|
105 | + $data['invoice_id'] = 0; |
|
106 | + return wpinv_insert_invoice($data, $wp_error); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -113,36 +113,36 @@ discard block |
||
113 | 113 | * @param bool $wp_error Whether to return false or WP_Error on failure. |
114 | 114 | * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success. |
115 | 115 | */ |
116 | -function wpinv_update_invoice( $data = array(), $wp_error = false ) { |
|
116 | +function wpinv_update_invoice($data = array(), $wp_error = false) { |
|
117 | 117 | |
118 | 118 | // Backwards compatibility. |
119 | - if ( ! empty( $data['ID'] ) ) { |
|
119 | + if (!empty($data['ID'])) { |
|
120 | 120 | $data['invoice_id'] = $data['ID']; |
121 | 121 | } |
122 | 122 | |
123 | 123 | // Do we have an invoice id? |
124 | - if ( empty( $data['invoice_id'] ) ) { |
|
125 | - return $wp_error ? new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) ) : 0; |
|
124 | + if (empty($data['invoice_id'])) { |
|
125 | + return $wp_error ? new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing')) : 0; |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | // Retrieve the invoice. |
129 | - $invoice = wpinv_get_invoice( $data['invoice_id'] ); |
|
129 | + $invoice = wpinv_get_invoice($data['invoice_id']); |
|
130 | 130 | |
131 | 131 | // And abort if it does not exist. |
132 | - if ( empty( $invoice ) ) { |
|
133 | - return $wp_error ? new WP_Error( 'missing_invoice', __( 'Invoice not found.', 'invoicing' ) ) : 0; |
|
132 | + if (empty($invoice)) { |
|
133 | + return $wp_error ? new WP_Error('missing_invoice', __('Invoice not found.', 'invoicing')) : 0; |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | // Do not update totals for paid / refunded invoices. |
137 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
137 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
138 | 138 | |
139 | - if ( ! empty( $data['items'] ) || ! empty( $data['cart_details'] ) ) { |
|
140 | - return $wp_error ? new WP_Error( 'paid_invoice', __( 'You can not update cart items for invoices that have already been paid for.', 'invoicing' ) ) : 0; |
|
139 | + if (!empty($data['items']) || !empty($data['cart_details'])) { |
|
140 | + return $wp_error ? new WP_Error('paid_invoice', __('You can not update cart items for invoices that have already been paid for.', 'invoicing')) : 0; |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | } |
144 | 144 | |
145 | - return wpinv_insert_invoice( $data, $wp_error ); |
|
145 | + return wpinv_insert_invoice($data, $wp_error); |
|
146 | 146 | |
147 | 147 | } |
148 | 148 | |
@@ -153,34 +153,34 @@ discard block |
||
153 | 153 | * @param bool $wp_error Whether to return false or WP_Error on failure. |
154 | 154 | * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success. |
155 | 155 | */ |
156 | -function wpinv_insert_invoice( $data = array(), $wp_error = false ) { |
|
156 | +function wpinv_insert_invoice($data = array(), $wp_error = false) { |
|
157 | 157 | |
158 | 158 | // Ensure that we have invoice data. |
159 | - if ( empty( $data ) ) { |
|
159 | + if (empty($data)) { |
|
160 | 160 | return false; |
161 | 161 | } |
162 | 162 | |
163 | 163 | // The invoice id will be provided when updating an invoice. |
164 | - $data['invoice_id'] = ! empty( $data['invoice_id'] ) ? (int) $data['invoice_id'] : false; |
|
164 | + $data['invoice_id'] = !empty($data['invoice_id']) ? (int) $data['invoice_id'] : false; |
|
165 | 165 | |
166 | 166 | // Retrieve the invoice. |
167 | - $invoice = new WPInv_Invoice( $data['invoice_id'] ); |
|
167 | + $invoice = new WPInv_Invoice($data['invoice_id']); |
|
168 | 168 | |
169 | 169 | // Do we have an error? |
170 | - if ( ! empty( $invoice->last_error ) ) { |
|
171 | - return $wp_error ? new WP_Error( 'invalid_invoice_id', $invoice->last_error ) : 0; |
|
170 | + if (!empty($invoice->last_error)) { |
|
171 | + return $wp_error ? new WP_Error('invalid_invoice_id', $invoice->last_error) : 0; |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | // Backwards compatibility (billing address). |
175 | - if ( ! empty( $data['user_info'] ) ) { |
|
175 | + if (!empty($data['user_info'])) { |
|
176 | 176 | |
177 | - foreach ( $data['user_info'] as $key => $value ) { |
|
177 | + foreach ($data['user_info'] as $key => $value) { |
|
178 | 178 | |
179 | - if ( $key == 'discounts' ) { |
|
179 | + if ($key == 'discounts') { |
|
180 | 180 | $value = (array) $value; |
181 | - $data[ 'discount_code' ] = empty( $value ) ? null : $value[0]; |
|
181 | + $data['discount_code'] = empty($value) ? null : $value[0]; |
|
182 | 182 | } else { |
183 | - $data[ $key ] = $value; |
|
183 | + $data[$key] = $value; |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | } |
@@ -188,30 +188,30 @@ discard block |
||
188 | 188 | } |
189 | 189 | |
190 | 190 | // Backwards compatibility. |
191 | - if ( ! empty( $data['payment_details'] ) ) { |
|
191 | + if (!empty($data['payment_details'])) { |
|
192 | 192 | |
193 | - foreach ( $data['payment_details'] as $key => $value ) { |
|
194 | - $data[ $key ] = $value; |
|
193 | + foreach ($data['payment_details'] as $key => $value) { |
|
194 | + $data[$key] = $value; |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | } |
198 | 198 | |
199 | 199 | // Set up the owner of the invoice. |
200 | - $user_id = ! empty( $data['user_id'] ) ? wpinv_clean( $data['user_id'] ) : get_current_user_id(); |
|
200 | + $user_id = !empty($data['user_id']) ? wpinv_clean($data['user_id']) : get_current_user_id(); |
|
201 | 201 | |
202 | 202 | // Make sure the user exists. |
203 | - if ( ! get_userdata( $user_id ) ) { |
|
204 | - return $wp_error ? new WP_Error( 'wpinv_invalid_user', __( 'There is no user with that ID.', 'invoicing' ) ) : 0; |
|
203 | + if (!get_userdata($user_id)) { |
|
204 | + return $wp_error ? new WP_Error('wpinv_invalid_user', __('There is no user with that ID.', 'invoicing')) : 0; |
|
205 | 205 | } |
206 | 206 | |
207 | - $address = wpinv_get_user_address( $user_id ); |
|
207 | + $address = wpinv_get_user_address($user_id); |
|
208 | 208 | |
209 | - foreach ( $address as $key => $value ) { |
|
209 | + foreach ($address as $key => $value) { |
|
210 | 210 | |
211 | - if ( $value == '' ) { |
|
212 | - $address[ $key ] = null; |
|
211 | + if ($value == '') { |
|
212 | + $address[$key] = null; |
|
213 | 213 | } else { |
214 | - $address[ $key ] = wpinv_clean( $value ); |
|
214 | + $address[$key] = wpinv_clean($value); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | } |
@@ -222,103 +222,103 @@ discard block |
||
222 | 222 | array( |
223 | 223 | |
224 | 224 | // Basic info. |
225 | - 'template' => isset( $data['template'] ) ? wpinv_clean( $data['template'] ) : null, |
|
226 | - 'email_cc' => isset( $data['email_cc'] ) ? wpinv_clean( $data['email_cc'] ) : null, |
|
227 | - 'date_created' => isset( $data['created_date'] ) ? wpinv_clean( $data['created_date'] ) : null, |
|
228 | - 'due_date' => isset( $data['due_date'] ) ? wpinv_clean( $data['due_date'] ) : null, |
|
229 | - 'date_completed' => isset( $data['date_completed'] ) ? wpinv_clean( $data['date_completed'] ) : null, |
|
230 | - 'number' => isset( $data['number'] ) ? wpinv_clean( $data['number'] ) : null, |
|
231 | - 'key' => isset( $data['key'] ) ? wpinv_clean( $data['key'] ) : null, |
|
232 | - 'status' => isset( $data['status'] ) ? wpinv_clean( $data['status'] ) : null, |
|
233 | - 'post_type' => isset( $data['post_type'] ) ? wpinv_clean( $data['post_type'] ) : null, |
|
234 | - 'user_ip' => isset( $data['ip'] ) ? wpinv_clean( $data['ip'] ) : wpinv_get_ip(), |
|
235 | - 'parent_id' => isset( $data['parent'] ) ? intval( $data['parent'] ) : null, |
|
236 | - 'mode' => isset( $data['mode'] ) ? wpinv_clean( $data['mode'] ) : null, |
|
237 | - 'description' => isset( $data['description'] ) ? wp_kses_post( $data['description'] ) : null, |
|
225 | + 'template' => isset($data['template']) ? wpinv_clean($data['template']) : null, |
|
226 | + 'email_cc' => isset($data['email_cc']) ? wpinv_clean($data['email_cc']) : null, |
|
227 | + 'date_created' => isset($data['created_date']) ? wpinv_clean($data['created_date']) : null, |
|
228 | + 'due_date' => isset($data['due_date']) ? wpinv_clean($data['due_date']) : null, |
|
229 | + 'date_completed' => isset($data['date_completed']) ? wpinv_clean($data['date_completed']) : null, |
|
230 | + 'number' => isset($data['number']) ? wpinv_clean($data['number']) : null, |
|
231 | + 'key' => isset($data['key']) ? wpinv_clean($data['key']) : null, |
|
232 | + 'status' => isset($data['status']) ? wpinv_clean($data['status']) : null, |
|
233 | + 'post_type' => isset($data['post_type']) ? wpinv_clean($data['post_type']) : null, |
|
234 | + 'user_ip' => isset($data['ip']) ? wpinv_clean($data['ip']) : wpinv_get_ip(), |
|
235 | + 'parent_id' => isset($data['parent']) ? intval($data['parent']) : null, |
|
236 | + 'mode' => isset($data['mode']) ? wpinv_clean($data['mode']) : null, |
|
237 | + 'description' => isset($data['description']) ? wp_kses_post($data['description']) : null, |
|
238 | 238 | |
239 | 239 | // Payment info. |
240 | - 'disable_taxes' => ! empty( $data['disable_taxes'] ), |
|
241 | - 'currency' => isset( $data['currency'] ) ? wpinv_clean( $data['currency'] ) : wpinv_get_currency(), |
|
242 | - 'gateway' => isset( $data['gateway'] ) ? wpinv_clean( $data['gateway'] ) : null, |
|
243 | - 'transaction_id' => isset( $data['transaction_id'] ) ? wpinv_clean( $data['transaction_id'] ) : null, |
|
244 | - 'discount_code' => isset( $data['discount_code'] ) ? wpinv_clean( $data['discount_code'] ) : null, |
|
245 | - 'payment_form' => isset( $data['payment_form'] ) ? intval( $data['payment_form'] ) : null, |
|
246 | - 'submission_id' => isset( $data['submission_id'] ) ? wpinv_clean( $data['submission_id'] ) : null, |
|
247 | - 'subscription_id' => isset( $data['subscription_id'] ) ? wpinv_clean( $data['subscription_id'] ) : null, |
|
248 | - 'is_viewed' => isset( $data['is_viewed'] ) ? wpinv_clean( $data['is_viewed'] ) : null, |
|
249 | - 'fees' => isset( $data['fees'] ) ? wpinv_clean( $data['fees'] ) : null, |
|
250 | - 'discounts' => isset( $data['discounts'] ) ? wpinv_clean( $data['discounts'] ) : null, |
|
251 | - 'taxes' => isset( $data['taxes'] ) ? wpinv_clean( $data['taxes'] ) : null, |
|
240 | + 'disable_taxes' => !empty($data['disable_taxes']), |
|
241 | + 'currency' => isset($data['currency']) ? wpinv_clean($data['currency']) : wpinv_get_currency(), |
|
242 | + 'gateway' => isset($data['gateway']) ? wpinv_clean($data['gateway']) : null, |
|
243 | + 'transaction_id' => isset($data['transaction_id']) ? wpinv_clean($data['transaction_id']) : null, |
|
244 | + 'discount_code' => isset($data['discount_code']) ? wpinv_clean($data['discount_code']) : null, |
|
245 | + 'payment_form' => isset($data['payment_form']) ? intval($data['payment_form']) : null, |
|
246 | + 'submission_id' => isset($data['submission_id']) ? wpinv_clean($data['submission_id']) : null, |
|
247 | + 'subscription_id' => isset($data['subscription_id']) ? wpinv_clean($data['subscription_id']) : null, |
|
248 | + 'is_viewed' => isset($data['is_viewed']) ? wpinv_clean($data['is_viewed']) : null, |
|
249 | + 'fees' => isset($data['fees']) ? wpinv_clean($data['fees']) : null, |
|
250 | + 'discounts' => isset($data['discounts']) ? wpinv_clean($data['discounts']) : null, |
|
251 | + 'taxes' => isset($data['taxes']) ? wpinv_clean($data['taxes']) : null, |
|
252 | 252 | |
253 | 253 | |
254 | 254 | // Billing details. |
255 | 255 | 'user_id' => $data['user_id'], |
256 | - 'first_name' => isset( $data['first_name'] ) ? wpinv_clean( $data['first_name'] ) : $address['first_name'], |
|
257 | - 'last_name' => isset( $data['last_name'] ) ? wpinv_clean( $data['last_name'] ) : $address['last_name'], |
|
258 | - 'address' => isset( $data['address'] ) ? wpinv_clean( $data['address'] ) : $address['address'] , |
|
259 | - 'vat_number' => isset( $data['vat_number'] ) ? wpinv_clean( $data['vat_number'] ) : $address['vat_number'], |
|
260 | - 'company' => isset( $data['company'] ) ? wpinv_clean( $data['company'] ) : $address['company'], |
|
261 | - 'zip' => isset( $data['zip'] ) ? wpinv_clean( $data['zip'] ) : $address['zip'], |
|
262 | - 'state' => isset( $data['state'] ) ? wpinv_clean( $data['state'] ) : $address['state'], |
|
263 | - 'city' => isset( $data['city'] ) ? wpinv_clean( $data['city'] ) : $address['city'], |
|
264 | - 'country' => isset( $data['country'] ) ? wpinv_clean( $data['country'] ) : $address['country'], |
|
265 | - 'phone' => isset( $data['phone'] ) ? wpinv_clean( $data['phone'] ) : $address['phone'], |
|
266 | - 'address_confirmed' => ! empty( $data['address_confirmed'] ), |
|
256 | + 'first_name' => isset($data['first_name']) ? wpinv_clean($data['first_name']) : $address['first_name'], |
|
257 | + 'last_name' => isset($data['last_name']) ? wpinv_clean($data['last_name']) : $address['last_name'], |
|
258 | + 'address' => isset($data['address']) ? wpinv_clean($data['address']) : $address['address'], |
|
259 | + 'vat_number' => isset($data['vat_number']) ? wpinv_clean($data['vat_number']) : $address['vat_number'], |
|
260 | + 'company' => isset($data['company']) ? wpinv_clean($data['company']) : $address['company'], |
|
261 | + 'zip' => isset($data['zip']) ? wpinv_clean($data['zip']) : $address['zip'], |
|
262 | + 'state' => isset($data['state']) ? wpinv_clean($data['state']) : $address['state'], |
|
263 | + 'city' => isset($data['city']) ? wpinv_clean($data['city']) : $address['city'], |
|
264 | + 'country' => isset($data['country']) ? wpinv_clean($data['country']) : $address['country'], |
|
265 | + 'phone' => isset($data['phone']) ? wpinv_clean($data['phone']) : $address['phone'], |
|
266 | + 'address_confirmed' => !empty($data['address_confirmed']), |
|
267 | 267 | |
268 | 268 | ) |
269 | 269 | |
270 | 270 | ); |
271 | 271 | |
272 | 272 | // Backwards compatibililty. |
273 | - if ( ! empty( $data['cart_details'] ) && is_array( $data['cart_details'] ) ) { |
|
273 | + if (!empty($data['cart_details']) && is_array($data['cart_details'])) { |
|
274 | 274 | $data['items'] = array(); |
275 | 275 | |
276 | - foreach( $data['cart_details'] as $_item ) { |
|
276 | + foreach ($data['cart_details'] as $_item) { |
|
277 | 277 | |
278 | 278 | // Ensure that we have an item id. |
279 | - if ( empty( $_item['id'] ) ) { |
|
279 | + if (empty($_item['id'])) { |
|
280 | 280 | continue; |
281 | 281 | } |
282 | 282 | |
283 | 283 | // Retrieve the item. |
284 | - $item = new GetPaid_Form_Item( $_item['id'] ); |
|
284 | + $item = new GetPaid_Form_Item($_item['id']); |
|
285 | 285 | |
286 | 286 | // Ensure that it is purchasable. |
287 | - if ( ! $item->can_purchase() ) { |
|
287 | + if (!$item->can_purchase()) { |
|
288 | 288 | continue; |
289 | 289 | } |
290 | 290 | |
291 | 291 | // Set quantity. |
292 | - if ( ! empty( $_item['quantity'] ) && is_numeric( $_item['quantity'] ) ) { |
|
293 | - $item->set_quantity( $_item['quantity'] ); |
|
292 | + if (!empty($_item['quantity']) && is_numeric($_item['quantity'])) { |
|
293 | + $item->set_quantity($_item['quantity']); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | // Set price. |
297 | - if ( isset( $_item['item_price'] ) ) { |
|
298 | - $item->set_price( $_item['item_price'] ); |
|
297 | + if (isset($_item['item_price'])) { |
|
298 | + $item->set_price($_item['item_price']); |
|
299 | 299 | } |
300 | 300 | |
301 | - if ( isset( $_item['custom_price'] ) ) { |
|
302 | - $item->set_price( $_item['custom_price'] ); |
|
301 | + if (isset($_item['custom_price'])) { |
|
302 | + $item->set_price($_item['custom_price']); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | // Set name. |
306 | - if ( ! empty( $_item['name'] ) ) { |
|
307 | - $item->set_name( $_item['name'] ); |
|
306 | + if (!empty($_item['name'])) { |
|
307 | + $item->set_name($_item['name']); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | // Set description. |
311 | - if ( isset( $_item['description'] ) ) { |
|
312 | - $item->set_custom_description( $_item['description'] ); |
|
311 | + if (isset($_item['description'])) { |
|
312 | + $item->set_custom_description($_item['description']); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | // Set meta. |
316 | - if ( isset( $_item['meta'] ) && is_array( $_item['meta'] ) ) { |
|
316 | + if (isset($_item['meta']) && is_array($_item['meta'])) { |
|
317 | 317 | |
318 | - $item->set_item_meta( $_item['meta'] ); |
|
318 | + $item->set_item_meta($_item['meta']); |
|
319 | 319 | |
320 | - if ( isset( $_item['meta']['description'] ) ) { |
|
321 | - $item->set_custom_description( $_item['meta']['description'] ); |
|
320 | + if (isset($_item['meta']['description'])) { |
|
321 | + $item->set_custom_description($_item['meta']['description']); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | } |
@@ -329,14 +329,14 @@ discard block |
||
329 | 329 | } |
330 | 330 | |
331 | 331 | // Add invoice items. |
332 | - if ( ! empty( $data['items'] ) && is_array( $data['items'] ) ) { |
|
332 | + if (!empty($data['items']) && is_array($data['items'])) { |
|
333 | 333 | |
334 | - $invoice->set_items( array() ); |
|
334 | + $invoice->set_items(array()); |
|
335 | 335 | |
336 | - foreach ( $data['items'] as $item ) { |
|
336 | + foreach ($data['items'] as $item) { |
|
337 | 337 | |
338 | - if ( is_object( $item ) && is_a( $item, 'GetPaid_Form_Item' ) && $item->can_purchase() ) { |
|
339 | - $invoice->add_item( $item ); |
|
338 | + if (is_object($item) && is_a($item, 'GetPaid_Form_Item') && $item->can_purchase()) { |
|
339 | + $invoice->add_item($item); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | } |
@@ -347,30 +347,30 @@ discard block |
||
347 | 347 | $invoice->recalculate_total(); |
348 | 348 | $invoice->save(); |
349 | 349 | |
350 | - if ( ! $invoice->get_id() ) { |
|
351 | - return $wp_error ? new WP_Error( 'wpinv_insert_invoice_error', __( 'An error occured when saving your invoice.', 'invoicing' ) ) : 0; |
|
350 | + if (!$invoice->get_id()) { |
|
351 | + return $wp_error ? new WP_Error('wpinv_insert_invoice_error', __('An error occured when saving your invoice.', 'invoicing')) : 0; |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | // Add private note. |
355 | - if ( ! empty( $data['private_note'] ) ) { |
|
356 | - $invoice->add_note( $data['private_note'] ); |
|
355 | + if (!empty($data['private_note'])) { |
|
356 | + $invoice->add_note($data['private_note']); |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | // User notes. |
360 | - if ( !empty( $data['user_note'] ) ) { |
|
361 | - $invoice->add_note( $data['user_note'], true ); |
|
360 | + if (!empty($data['user_note'])) { |
|
361 | + $invoice->add_note($data['user_note'], true); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | // Created via. |
365 | - if ( isset( $data['created_via'] ) ) { |
|
366 | - update_post_meta( $invoice->get_id(), 'wpinv_created_via', $data['created_via'] ); |
|
365 | + if (isset($data['created_via'])) { |
|
366 | + update_post_meta($invoice->get_id(), 'wpinv_created_via', $data['created_via']); |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | // Backwards compatiblity. |
370 | - if ( $invoice->is_quote() ) { |
|
370 | + if ($invoice->is_quote()) { |
|
371 | 371 | |
372 | - if ( isset( $data['valid_until'] ) ) { |
|
373 | - update_post_meta( $invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until'] ); |
|
372 | + if (isset($data['valid_until'])) { |
|
373 | + update_post_meta($invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until']); |
|
374 | 374 | } |
375 | 375 | return $invoice; |
376 | 376 | |
@@ -385,18 +385,18 @@ discard block |
||
385 | 385 | * @param $bool $deprecated |
386 | 386 | * @return WPInv_Invoice|null |
387 | 387 | */ |
388 | -function wpinv_get_invoice( $invoice = 0, $deprecated = false ) { |
|
388 | +function wpinv_get_invoice($invoice = 0, $deprecated = false) { |
|
389 | 389 | |
390 | 390 | // If we are retrieving the invoice from the cart... |
391 | - if ( $deprecated && empty( $invoice ) ) { |
|
391 | + if ($deprecated && empty($invoice)) { |
|
392 | 392 | $invoice = (int) getpaid_get_current_invoice_id(); |
393 | 393 | } |
394 | 394 | |
395 | 395 | // Retrieve the invoice. |
396 | - $invoice = new WPInv_Invoice( $invoice ); |
|
396 | + $invoice = new WPInv_Invoice($invoice); |
|
397 | 397 | |
398 | 398 | // Check if it exists. |
399 | - if ( $invoice->get_id() != 0 ) { |
|
399 | + if ($invoice->get_id() != 0) { |
|
400 | 400 | return $invoice; |
401 | 401 | } |
402 | 402 | |
@@ -409,15 +409,15 @@ discard block |
||
409 | 409 | * @param array $args Args to search for. |
410 | 410 | * @return WPInv_Invoice[]|int[]|object |
411 | 411 | */ |
412 | -function wpinv_get_invoices( $args ) { |
|
412 | +function wpinv_get_invoices($args) { |
|
413 | 413 | |
414 | 414 | // Prepare args. |
415 | 415 | $args = wp_parse_args( |
416 | 416 | $args, |
417 | 417 | array( |
418 | - 'status' => array_keys( wpinv_get_invoice_statuses() ), |
|
418 | + 'status' => array_keys(wpinv_get_invoice_statuses()), |
|
419 | 419 | 'type' => 'wpi_invoice', |
420 | - 'limit' => get_option( 'posts_per_page' ), |
|
420 | + 'limit' => get_option('posts_per_page'), |
|
421 | 421 | 'return' => 'objects', |
422 | 422 | ) |
423 | 423 | ); |
@@ -435,24 +435,24 @@ discard block |
||
435 | 435 | 'post__in' => 'include', |
436 | 436 | ); |
437 | 437 | |
438 | - foreach ( $map_legacy as $to => $from ) { |
|
439 | - if ( isset( $args[ $from ] ) ) { |
|
440 | - $args[ $to ] = $args[ $from ]; |
|
441 | - unset( $args[ $from ] ); |
|
438 | + foreach ($map_legacy as $to => $from) { |
|
439 | + if (isset($args[$from])) { |
|
440 | + $args[$to] = $args[$from]; |
|
441 | + unset($args[$from]); |
|
442 | 442 | } |
443 | 443 | } |
444 | 444 | |
445 | 445 | // Backwards compatibility. |
446 | - if ( ! empty( $args['email'] ) && empty( $args['user'] ) ) { |
|
446 | + if (!empty($args['email']) && empty($args['user'])) { |
|
447 | 447 | $args['user'] = $args['email']; |
448 | - unset( $args['email'] ); |
|
448 | + unset($args['email']); |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | // Handle cases where the user is set as an email. |
452 | - if ( ! empty( $args['author'] ) && is_email( $args['author'] ) ) { |
|
453 | - $user = get_user_by( 'email', $args['user'] ); |
|
452 | + if (!empty($args['author']) && is_email($args['author'])) { |
|
453 | + $user = get_user_by('email', $args['user']); |
|
454 | 454 | |
455 | - if ( $user ) { |
|
455 | + if ($user) { |
|
456 | 456 | $args['author'] = $user->user_email; |
457 | 457 | } |
458 | 458 | |
@@ -463,31 +463,31 @@ discard block |
||
463 | 463 | |
464 | 464 | // Show all posts. |
465 | 465 | $paginate = true; |
466 | - if ( isset( $args['paginate'] ) ) { |
|
466 | + if (isset($args['paginate'])) { |
|
467 | 467 | |
468 | 468 | $paginate = $args['paginate']; |
469 | - $args['no_found_rows'] = empty( $args['paginate'] ); |
|
470 | - unset( $args['paginate'] ); |
|
469 | + $args['no_found_rows'] = empty($args['paginate']); |
|
470 | + unset($args['paginate']); |
|
471 | 471 | |
472 | 472 | } |
473 | 473 | |
474 | 474 | // Whether to return objects or fields. |
475 | 475 | $return = $args['return']; |
476 | - unset( $args['return'] ); |
|
476 | + unset($args['return']); |
|
477 | 477 | |
478 | 478 | // Get invoices. |
479 | - $invoices = new WP_Query( apply_filters( 'wpinv_get_invoices_args', $args ) ); |
|
479 | + $invoices = new WP_Query(apply_filters('wpinv_get_invoices_args', $args)); |
|
480 | 480 | |
481 | 481 | // Prepare the results. |
482 | - if ( 'objects' === $return ) { |
|
483 | - $results = array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
484 | - } elseif ( 'self' === $return ) { |
|
482 | + if ('objects' === $return) { |
|
483 | + $results = array_map('wpinv_get_invoice', $invoices->posts); |
|
484 | + } elseif ('self' === $return) { |
|
485 | 485 | return $invoices; |
486 | 486 | } else { |
487 | 487 | $results = $invoices->posts; |
488 | 488 | } |
489 | 489 | |
490 | - if ( $paginate ) { |
|
490 | + if ($paginate) { |
|
491 | 491 | return (object) array( |
492 | 492 | 'invoices' => $results, |
493 | 493 | 'total' => $invoices->found_posts, |
@@ -505,8 +505,8 @@ discard block |
||
505 | 505 | * @param string $transaction_id The transaction id to check. |
506 | 506 | * @return int Invoice id on success or 0 on failure |
507 | 507 | */ |
508 | -function wpinv_get_id_by_transaction_id( $transaction_id ) { |
|
509 | - return WPInv_Invoice::get_invoice_id_by_field( $transaction_id, 'transaction_id' ); |
|
508 | +function wpinv_get_id_by_transaction_id($transaction_id) { |
|
509 | + return WPInv_Invoice::get_invoice_id_by_field($transaction_id, 'transaction_id'); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | /** |
@@ -515,8 +515,8 @@ discard block |
||
515 | 515 | * @param string $invoice_number The invoice number to check. |
516 | 516 | * @return int Invoice id on success or 0 on failure |
517 | 517 | */ |
518 | -function wpinv_get_id_by_invoice_number( $invoice_number ) { |
|
519 | - return WPInv_Invoice::get_invoice_id_by_field( $invoice_number, 'number' ); |
|
518 | +function wpinv_get_id_by_invoice_number($invoice_number) { |
|
519 | + return WPInv_Invoice::get_invoice_id_by_field($invoice_number, 'number'); |
|
520 | 520 | } |
521 | 521 | |
522 | 522 | /** |
@@ -525,8 +525,8 @@ discard block |
||
525 | 525 | * @param string $invoice_key The invoice key to check. |
526 | 526 | * @return int Invoice id on success or 0 on failure |
527 | 527 | */ |
528 | -function wpinv_get_invoice_id_by_key( $invoice_key ) { |
|
529 | - return WPInv_Invoice::get_invoice_id_by_field( $invoice_key, 'key' ); |
|
528 | +function wpinv_get_invoice_id_by_key($invoice_key) { |
|
529 | + return WPInv_Invoice::get_invoice_id_by_field($invoice_key, 'key'); |
|
530 | 530 | } |
531 | 531 | |
532 | 532 | /** |
@@ -536,19 +536,19 @@ discard block |
||
536 | 536 | * @param string $type Optionally filter by type i.e customer|system |
537 | 537 | * @return array|null |
538 | 538 | */ |
539 | -function wpinv_get_invoice_notes( $invoice = 0, $type = '' ) { |
|
539 | +function wpinv_get_invoice_notes($invoice = 0, $type = '') { |
|
540 | 540 | |
541 | 541 | // Prepare the invoice. |
542 | - $invoice = wpinv_get_invoice( $invoice ); |
|
543 | - if ( empty( $invoice ) ) { |
|
542 | + $invoice = wpinv_get_invoice($invoice); |
|
543 | + if (empty($invoice)) { |
|
544 | 544 | return NULL; |
545 | 545 | } |
546 | 546 | |
547 | 547 | // Fetch notes. |
548 | - $notes = getpaid_notes()->get_invoice_notes( $invoice->get_id(), $type ); |
|
548 | + $notes = getpaid_notes()->get_invoice_notes($invoice->get_id(), $type); |
|
549 | 549 | |
550 | 550 | // Filter the notes. |
551 | - return apply_filters( 'wpinv_invoice_notes', $notes, $invoice->get_id(), $type ); |
|
551 | + return apply_filters('wpinv_invoice_notes', $notes, $invoice->get_id(), $type); |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | /** |
@@ -556,10 +556,10 @@ discard block |
||
556 | 556 | * |
557 | 557 | * @param string $post_type |
558 | 558 | */ |
559 | -function wpinv_get_user_invoices_columns( $post_type = 'wpi_invoice' ) { |
|
559 | +function wpinv_get_user_invoices_columns($post_type = 'wpi_invoice') { |
|
560 | 560 | |
561 | - $label = getpaid_get_post_type_label( $post_type, false ); |
|
562 | - $label = empty( $label ) ? __( 'Invoice', 'invoicing' ) : sanitize_text_field( $label ); |
|
561 | + $label = getpaid_get_post_type_label($post_type, false); |
|
562 | + $label = empty($label) ? __('Invoice', 'invoicing') : sanitize_text_field($label); |
|
563 | 563 | $columns = array( |
564 | 564 | |
565 | 565 | 'invoice-number' => array( |
@@ -568,22 +568,22 @@ discard block |
||
568 | 568 | ), |
569 | 569 | |
570 | 570 | 'created-date' => array( |
571 | - 'title' => __( 'Created Date', 'invoicing' ), |
|
571 | + 'title' => __('Created Date', 'invoicing'), |
|
572 | 572 | 'class' => 'text-left' |
573 | 573 | ), |
574 | 574 | |
575 | 575 | 'payment-date' => array( |
576 | - 'title' => __( 'Payment Date', 'invoicing' ), |
|
576 | + 'title' => __('Payment Date', 'invoicing'), |
|
577 | 577 | 'class' => 'text-left' |
578 | 578 | ), |
579 | 579 | |
580 | 580 | 'invoice-status' => array( |
581 | - 'title' => __( 'Status', 'invoicing' ), |
|
581 | + 'title' => __('Status', 'invoicing'), |
|
582 | 582 | 'class' => 'text-center' |
583 | 583 | ), |
584 | 584 | |
585 | 585 | 'invoice-total' => array( |
586 | - 'title' => __( 'Total', 'invoicing' ), |
|
586 | + 'title' => __('Total', 'invoicing'), |
|
587 | 587 | 'class' => 'text-right' |
588 | 588 | ), |
589 | 589 | |
@@ -594,7 +594,7 @@ discard block |
||
594 | 594 | |
595 | 595 | ); |
596 | 596 | |
597 | - return apply_filters( 'wpinv_user_invoices_columns', $columns, $post_type ); |
|
597 | + return apply_filters('wpinv_user_invoices_columns', $columns, $post_type); |
|
598 | 598 | } |
599 | 599 | |
600 | 600 | /** |
@@ -604,59 +604,59 @@ discard block |
||
604 | 604 | |
605 | 605 | // Find the invoice. |
606 | 606 | $invoice_id = getpaid_get_current_invoice_id(); |
607 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
607 | + $invoice = new WPInv_Invoice($invoice_id); |
|
608 | 608 | |
609 | 609 | // Abort if non was found. |
610 | - if ( empty( $invoice_id ) || $invoice->is_draft() ) { |
|
610 | + if (empty($invoice_id) || $invoice->is_draft()) { |
|
611 | 611 | |
612 | 612 | return aui()->alert( |
613 | 613 | array( |
614 | 614 | 'type' => 'warning', |
615 | - 'content' => __( 'We could not find your invoice', 'invoicing' ), |
|
615 | + 'content' => __('We could not find your invoice', 'invoicing'), |
|
616 | 616 | ) |
617 | 617 | ); |
618 | 618 | |
619 | 619 | } |
620 | 620 | |
621 | 621 | // Can the user view this invoice? |
622 | - if ( ! wpinv_can_view_receipt( $invoice_id ) ) { |
|
622 | + if (!wpinv_can_view_receipt($invoice_id)) { |
|
623 | 623 | |
624 | 624 | return aui()->alert( |
625 | 625 | array( |
626 | 626 | 'type' => 'warning', |
627 | - 'content' => __( 'You are not allowed to view this receipt', 'invoicing' ), |
|
627 | + 'content' => __('You are not allowed to view this receipt', 'invoicing'), |
|
628 | 628 | ) |
629 | 629 | ); |
630 | 630 | |
631 | 631 | } |
632 | 632 | |
633 | 633 | // Load the template. |
634 | - return wpinv_get_template_html( 'invoice-receipt.php', compact( 'invoice' ) ); |
|
634 | + return wpinv_get_template_html('invoice-receipt.php', compact('invoice')); |
|
635 | 635 | |
636 | 636 | } |
637 | 637 | |
638 | 638 | /** |
639 | 639 | * Displays the invoice history. |
640 | 640 | */ |
641 | -function getpaid_invoice_history( $user_id = 0, $post_type = 'wpi_invoice' ) { |
|
641 | +function getpaid_invoice_history($user_id = 0, $post_type = 'wpi_invoice') { |
|
642 | 642 | |
643 | 643 | // Ensure that we have a user id. |
644 | - if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
|
644 | + if (empty($user_id) || !is_numeric($user_id)) { |
|
645 | 645 | $user_id = get_current_user_id(); |
646 | 646 | } |
647 | 647 | |
648 | - $label = getpaid_get_post_type_label( $post_type ); |
|
649 | - $label = empty( $label ) ? __( 'Invoices', 'invoicing' ) : sanitize_text_field( $label ); |
|
648 | + $label = getpaid_get_post_type_label($post_type); |
|
649 | + $label = empty($label) ? __('Invoices', 'invoicing') : sanitize_text_field($label); |
|
650 | 650 | |
651 | 651 | // View user id. |
652 | - if ( empty( $user_id ) ) { |
|
652 | + if (empty($user_id)) { |
|
653 | 653 | |
654 | 654 | return aui()->alert( |
655 | 655 | array( |
656 | 656 | 'type' => 'warning', |
657 | 657 | 'content' => sprintf( |
658 | - __( 'You must be logged in to view your %s.', 'invoicing' ), |
|
659 | - strtolower( $label ) |
|
658 | + __('You must be logged in to view your %s.', 'invoicing'), |
|
659 | + strtolower($label) |
|
660 | 660 | ) |
661 | 661 | ) |
662 | 662 | ); |
@@ -667,23 +667,23 @@ discard block |
||
667 | 667 | $invoices = wpinv_get_invoices( |
668 | 668 | |
669 | 669 | array( |
670 | - 'page' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
670 | + 'page' => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1, |
|
671 | 671 | 'user' => $user_id, |
672 | 672 | 'paginate' => true, |
673 | 673 | 'type' => $post_type, |
674 | - 'status' => array_keys( wpinv_get_invoice_statuses( false, false, $post_type ) ), |
|
674 | + 'status' => array_keys(wpinv_get_invoice_statuses(false, false, $post_type)), |
|
675 | 675 | ) |
676 | 676 | |
677 | 677 | ); |
678 | 678 | |
679 | - if ( empty( $invoices->total ) ) { |
|
679 | + if (empty($invoices->total)) { |
|
680 | 680 | |
681 | 681 | return aui()->alert( |
682 | 682 | array( |
683 | 683 | 'type' => 'info', |
684 | 684 | 'content' => sprintf( |
685 | - __( 'No %s found.', 'invoicing' ), |
|
686 | - strtolower( $label ) |
|
685 | + __('No %s found.', 'invoicing'), |
|
686 | + strtolower($label) |
|
687 | 687 | ) |
688 | 688 | ) |
689 | 689 | ); |
@@ -691,38 +691,38 @@ discard block |
||
691 | 691 | } |
692 | 692 | |
693 | 693 | // Load the template. |
694 | - return wpinv_get_template_html( 'invoice-history.php', compact( 'invoices', 'post_type' ) ); |
|
694 | + return wpinv_get_template_html('invoice-history.php', compact('invoices', 'post_type')); |
|
695 | 695 | |
696 | 696 | } |
697 | 697 | |
698 | 698 | /** |
699 | 699 | * Formats an invoice number given an invoice type. |
700 | 700 | */ |
701 | -function wpinv_format_invoice_number( $number, $type = '' ) { |
|
701 | +function wpinv_format_invoice_number($number, $type = '') { |
|
702 | 702 | |
703 | 703 | // Allow other plugins to overide this. |
704 | - $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type ); |
|
705 | - if ( null !== $check ) { |
|
704 | + $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type); |
|
705 | + if (null !== $check) { |
|
706 | 706 | return $check; |
707 | 707 | } |
708 | 708 | |
709 | 709 | // Ensure that we have a numeric number. |
710 | - if ( ! is_numeric( $number ) ) { |
|
710 | + if (!is_numeric($number)) { |
|
711 | 711 | return $number; |
712 | 712 | } |
713 | 713 | |
714 | 714 | // Format the number. |
715 | - $padd = absint( (int) wpinv_get_option( 'invoice_number_padd' ) ); |
|
716 | - $prefix = sanitize_text_field( (string) wpinv_get_option( 'invoice_number_prefix', 'INV-' ) ); |
|
717 | - $prefix = sanitize_text_field( apply_filters( 'getpaid_invoice_type_prefix', $prefix, $type ) ); |
|
718 | - $postfix = sanitize_text_field( (string) wpinv_get_option( 'invoice_number_postfix' ) ); |
|
719 | - $postfix = sanitize_text_field( apply_filters( 'getpaid_invoice_type_postfix', $postfix, $type ) ); |
|
720 | - $formatted_number = zeroise( absint( $number ), $padd ); |
|
715 | + $padd = absint((int) wpinv_get_option('invoice_number_padd')); |
|
716 | + $prefix = sanitize_text_field((string) wpinv_get_option('invoice_number_prefix', 'INV-')); |
|
717 | + $prefix = sanitize_text_field(apply_filters('getpaid_invoice_type_prefix', $prefix, $type)); |
|
718 | + $postfix = sanitize_text_field((string) wpinv_get_option('invoice_number_postfix')); |
|
719 | + $postfix = sanitize_text_field(apply_filters('getpaid_invoice_type_postfix', $postfix, $type)); |
|
720 | + $formatted_number = zeroise(absint($number), $padd); |
|
721 | 721 | |
722 | 722 | // Add the prefix and post fix. |
723 | 723 | $formatted_number = $prefix . $formatted_number . $postfix; |
724 | 724 | |
725 | - return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd ); |
|
725 | + return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd); |
|
726 | 726 | } |
727 | 727 | |
728 | 728 | /** |
@@ -731,58 +731,58 @@ discard block |
||
731 | 731 | * @param string $type. |
732 | 732 | * @return int|null|bool |
733 | 733 | */ |
734 | -function wpinv_get_next_invoice_number( $type = '' ) { |
|
734 | +function wpinv_get_next_invoice_number($type = '') { |
|
735 | 735 | |
736 | 736 | // Allow plugins to overide this. |
737 | - $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type ); |
|
738 | - if ( null !== $check ) { |
|
737 | + $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type); |
|
738 | + if (null !== $check) { |
|
739 | 739 | return $check; |
740 | 740 | } |
741 | 741 | |
742 | 742 | // Ensure sequential invoice numbers is active. |
743 | - if ( ! wpinv_sequential_number_active() ) { |
|
743 | + if (!wpinv_sequential_number_active()) { |
|
744 | 744 | return false; |
745 | 745 | } |
746 | 746 | |
747 | 747 | // Retrieve the current number and the start number. |
748 | - $number = (int) get_option( 'wpinv_last_invoice_number', 0 ); |
|
749 | - $start = absint( (int) wpinv_get_option( 'invoice_sequence_start', 1 ) ); |
|
748 | + $number = (int) get_option('wpinv_last_invoice_number', 0); |
|
749 | + $start = absint((int) wpinv_get_option('invoice_sequence_start', 1)); |
|
750 | 750 | |
751 | 751 | // Ensure that we are starting at a positive integer. |
752 | - $start = max( $start, 1 ); |
|
752 | + $start = max($start, 1); |
|
753 | 753 | |
754 | 754 | // If this is the first invoice, use the start number. |
755 | - $number = max( $start, $number ); |
|
755 | + $number = max($start, $number); |
|
756 | 756 | |
757 | 757 | // Format the invoice number. |
758 | - $formatted_number = wpinv_format_invoice_number( $number, $type ); |
|
758 | + $formatted_number = wpinv_format_invoice_number($number, $type); |
|
759 | 759 | |
760 | 760 | // Ensure that this number is unique. |
761 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $formatted_number, 'number' ); |
|
761 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field($formatted_number, 'number'); |
|
762 | 762 | |
763 | 763 | // We found a match. Nice. |
764 | - if ( empty( $invoice_id ) ) { |
|
765 | - update_option( 'wpinv_last_invoice_number', $number ); |
|
766 | - return apply_filters( 'wpinv_get_next_invoice_number', $number ); |
|
764 | + if (empty($invoice_id)) { |
|
765 | + update_option('wpinv_last_invoice_number', $number); |
|
766 | + return apply_filters('wpinv_get_next_invoice_number', $number); |
|
767 | 767 | } |
768 | 768 | |
769 | - update_option( 'wpinv_last_invoice_number', $number + 1 ); |
|
770 | - return wpinv_get_next_invoice_number( $type ); |
|
769 | + update_option('wpinv_last_invoice_number', $number + 1); |
|
770 | + return wpinv_get_next_invoice_number($type); |
|
771 | 771 | |
772 | 772 | } |
773 | 773 | |
774 | 774 | /** |
775 | 775 | * The prefix used for invoice paths. |
776 | 776 | */ |
777 | -function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) { |
|
778 | - return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type ); |
|
777 | +function wpinv_post_name_prefix($post_type = 'wpi_invoice') { |
|
778 | + return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type); |
|
779 | 779 | } |
780 | 780 | |
781 | -function wpinv_generate_post_name( $post_ID ) { |
|
782 | - $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) ); |
|
783 | - $post_name = sanitize_title( $prefix . $post_ID ); |
|
781 | +function wpinv_generate_post_name($post_ID) { |
|
782 | + $prefix = wpinv_post_name_prefix(get_post_type($post_ID)); |
|
783 | + $post_name = sanitize_title($prefix . $post_ID); |
|
784 | 784 | |
785 | - return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix ); |
|
785 | + return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix); |
|
786 | 786 | } |
787 | 787 | |
788 | 788 | /** |
@@ -790,8 +790,8 @@ discard block |
||
790 | 790 | * |
791 | 791 | * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object. |
792 | 792 | */ |
793 | -function wpinv_is_invoice_viewed( $invoice ) { |
|
794 | - $invoice = new WPInv_Invoice( $invoice ); |
|
793 | +function wpinv_is_invoice_viewed($invoice) { |
|
794 | + $invoice = new WPInv_Invoice($invoice); |
|
795 | 795 | return (bool) $invoice->get_is_viewed(); |
796 | 796 | } |
797 | 797 | |
@@ -800,17 +800,17 @@ discard block |
||
800 | 800 | * |
801 | 801 | * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object. |
802 | 802 | */ |
803 | -function getpaid_maybe_mark_invoice_as_viewed( $invoice ) { |
|
804 | - $invoice = new WPInv_Invoice( $invoice ); |
|
803 | +function getpaid_maybe_mark_invoice_as_viewed($invoice) { |
|
804 | + $invoice = new WPInv_Invoice($invoice); |
|
805 | 805 | |
806 | - if ( get_current_user_id() == $invoice->get_user_id() && ! $invoice->get_is_viewed() ) { |
|
807 | - $invoice->set_is_viewed( true ); |
|
806 | + if (get_current_user_id() == $invoice->get_user_id() && !$invoice->get_is_viewed()) { |
|
807 | + $invoice->set_is_viewed(true); |
|
808 | 808 | $invoice->save(); |
809 | 809 | } |
810 | 810 | |
811 | 811 | } |
812 | -add_action( 'wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed' ); |
|
813 | -add_action( 'wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed' ); |
|
812 | +add_action('wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed'); |
|
813 | +add_action('wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed'); |
|
814 | 814 | |
815 | 815 | /** |
816 | 816 | * Processes an invoice refund. |
@@ -819,27 +819,27 @@ discard block |
||
819 | 819 | * @param array $status_transition |
820 | 820 | * @todo: descrease customer/store earnings |
821 | 821 | */ |
822 | -function getpaid_maybe_process_refund( $invoice, $status_transition ) { |
|
822 | +function getpaid_maybe_process_refund($invoice, $status_transition) { |
|
823 | 823 | |
824 | - if ( empty( $status_transition['from'] ) || ! in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) { |
|
824 | + if (empty($status_transition['from']) || !in_array($status_transition['from'], array('publish', 'wpi-processing', 'wpi-renewal'))) { |
|
825 | 825 | return; |
826 | 826 | } |
827 | 827 | |
828 | 828 | $discount_code = $invoice->get_discount_code(); |
829 | - if ( ! empty( $discount_code ) ) { |
|
830 | - $discount = wpinv_get_discount_obj( $discount_code ); |
|
829 | + if (!empty($discount_code)) { |
|
830 | + $discount = wpinv_get_discount_obj($discount_code); |
|
831 | 831 | |
832 | - if ( $discount->exists() ) { |
|
832 | + if ($discount->exists()) { |
|
833 | 833 | $discount->increase_usage( -1 ); |
834 | 834 | } |
835 | 835 | |
836 | 836 | } |
837 | 837 | |
838 | - do_action( 'wpinv_pre_refund_invoice', $invoice, $invoice->get_id() ); |
|
839 | - do_action( 'wpinv_refund_invoice', $invoice, $invoice->get_id() ); |
|
840 | - do_action( 'wpinv_post_refund_invoice', $invoice, $invoice->get_id() ); |
|
838 | + do_action('wpinv_pre_refund_invoice', $invoice, $invoice->get_id()); |
|
839 | + do_action('wpinv_refund_invoice', $invoice, $invoice->get_id()); |
|
840 | + do_action('wpinv_post_refund_invoice', $invoice, $invoice->get_id()); |
|
841 | 841 | } |
842 | -add_action( 'getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 2 ); |
|
842 | +add_action('getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 2); |
|
843 | 843 | |
844 | 844 | |
845 | 845 | /** |
@@ -847,48 +847,48 @@ discard block |
||
847 | 847 | * |
848 | 848 | * @param int $invoice_id |
849 | 849 | */ |
850 | -function getpaid_process_invoice_payment( $invoice_id ) { |
|
850 | +function getpaid_process_invoice_payment($invoice_id) { |
|
851 | 851 | |
852 | 852 | // Fetch the invoice. |
853 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
853 | + $invoice = new WPInv_Invoice($invoice_id); |
|
854 | 854 | |
855 | 855 | // We only want to do this once. |
856 | - if ( 1 == get_post_meta( $invoice->get_id(), 'wpinv_processed_payment', true ) ) { |
|
856 | + if (1 == get_post_meta($invoice->get_id(), 'wpinv_processed_payment', true)) { |
|
857 | 857 | return; |
858 | 858 | } |
859 | 859 | |
860 | - update_post_meta( $invoice->get_id(), 'wpinv_processed_payment', 1 ); |
|
860 | + update_post_meta($invoice->get_id(), 'wpinv_processed_payment', 1); |
|
861 | 861 | |
862 | 862 | // Fires when processing a payment. |
863 | - do_action( 'getpaid_process_payment', $invoice ); |
|
863 | + do_action('getpaid_process_payment', $invoice); |
|
864 | 864 | |
865 | 865 | // Fire an action for each invoice item. |
866 | - foreach( $invoice->get_items() as $item ) { |
|
867 | - do_action( 'getpaid_process_item_payment', $item, $invoice ); |
|
866 | + foreach ($invoice->get_items() as $item) { |
|
867 | + do_action('getpaid_process_item_payment', $item, $invoice); |
|
868 | 868 | } |
869 | 869 | |
870 | 870 | // Increase discount usage. |
871 | 871 | $discount_code = $invoice->get_discount_code(); |
872 | - if ( ! empty( $discount_code ) && ! $invoice->is_renewal() ) { |
|
873 | - $discount = wpinv_get_discount_obj( $discount_code ); |
|
872 | + if (!empty($discount_code) && !$invoice->is_renewal()) { |
|
873 | + $discount = wpinv_get_discount_obj($discount_code); |
|
874 | 874 | |
875 | - if ( $discount->exists() ) { |
|
875 | + if ($discount->exists()) { |
|
876 | 876 | $discount->increase_usage(); |
877 | 877 | } |
878 | 878 | |
879 | 879 | } |
880 | 880 | |
881 | 881 | // Record reverse vat. |
882 | - if ( 'invoice' == $invoice->get_type() && wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
882 | + if ('invoice' == $invoice->get_type() && wpinv_use_taxes() && !$invoice->get_disable_taxes()) { |
|
883 | 883 | |
884 | - if ( wpinv_same_country_exempt_vat() && wpinv_is_base_country( $invoice->get_country() ) ) { |
|
885 | - $invoice->add_note( __( 'VAT was reverse charged', 'invoicing' ), false, false, true ); |
|
884 | + if (wpinv_same_country_exempt_vat() && wpinv_is_base_country($invoice->get_country())) { |
|
885 | + $invoice->add_note(__('VAT was reverse charged', 'invoicing'), false, false, true); |
|
886 | 886 | } |
887 | 887 | |
888 | 888 | } |
889 | 889 | |
890 | 890 | } |
891 | -add_action( 'getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment' ); |
|
891 | +add_action('getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment'); |
|
892 | 892 | |
893 | 893 | /** |
894 | 894 | * Returns an array of invoice item columns |
@@ -896,13 +896,13 @@ discard block |
||
896 | 896 | * @param int|WPInv_Invoice $invoice |
897 | 897 | * @return array |
898 | 898 | */ |
899 | -function getpaid_invoice_item_columns( $invoice ) { |
|
899 | +function getpaid_invoice_item_columns($invoice) { |
|
900 | 900 | |
901 | 901 | // Prepare the invoice. |
902 | - $invoice = new WPInv_Invoice( $invoice ); |
|
902 | + $invoice = new WPInv_Invoice($invoice); |
|
903 | 903 | |
904 | 904 | // Abort if there is no invoice. |
905 | - if ( 0 == $invoice->get_id() ) { |
|
905 | + if (0 == $invoice->get_id()) { |
|
906 | 906 | return array(); |
907 | 907 | } |
908 | 908 | |
@@ -910,47 +910,47 @@ discard block |
||
910 | 910 | $columns = apply_filters( |
911 | 911 | 'getpaid_invoice_item_columns', |
912 | 912 | array( |
913 | - 'name' => __( 'Item', 'invoicing' ), |
|
914 | - 'price' => __( 'Price', 'invoicing' ), |
|
915 | - 'quantity' => __( 'Quantity', 'invoicing' ), |
|
916 | - 'subtotal' => __( 'Subtotal', 'invoicing' ), |
|
913 | + 'name' => __('Item', 'invoicing'), |
|
914 | + 'price' => __('Price', 'invoicing'), |
|
915 | + 'quantity' => __('Quantity', 'invoicing'), |
|
916 | + 'subtotal' => __('Subtotal', 'invoicing'), |
|
917 | 917 | ), |
918 | 918 | $invoice |
919 | 919 | ); |
920 | 920 | |
921 | 921 | // Quantities. |
922 | - if ( isset( $columns[ 'quantity' ] ) ) { |
|
922 | + if (isset($columns['quantity'])) { |
|
923 | 923 | |
924 | - if ( 'hours' == $invoice->get_template() ) { |
|
925 | - $columns[ 'quantity' ] = __( 'Hours', 'invoicing' ); |
|
924 | + if ('hours' == $invoice->get_template()) { |
|
925 | + $columns['quantity'] = __('Hours', 'invoicing'); |
|
926 | 926 | } |
927 | 927 | |
928 | - if ( ! wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template() ) { |
|
929 | - unset( $columns[ 'quantity' ] ); |
|
928 | + if (!wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template()) { |
|
929 | + unset($columns['quantity']); |
|
930 | 930 | } |
931 | 931 | |
932 | 932 | } |
933 | 933 | |
934 | 934 | |
935 | 935 | // Price. |
936 | - if ( isset( $columns[ 'price' ] ) ) { |
|
936 | + if (isset($columns['price'])) { |
|
937 | 937 | |
938 | - if ( 'amount' == $invoice->get_template() ) { |
|
939 | - $columns[ 'price' ] = __( 'Amount', 'invoicing' ); |
|
938 | + if ('amount' == $invoice->get_template()) { |
|
939 | + $columns['price'] = __('Amount', 'invoicing'); |
|
940 | 940 | } |
941 | 941 | |
942 | - if ( 'hours' == $invoice->get_template() ) { |
|
943 | - $columns[ 'price' ] = __( 'Rate', 'invoicing' ); |
|
942 | + if ('hours' == $invoice->get_template()) { |
|
943 | + $columns['price'] = __('Rate', 'invoicing'); |
|
944 | 944 | } |
945 | 945 | |
946 | 946 | } |
947 | 947 | |
948 | 948 | |
949 | 949 | // Sub total. |
950 | - if ( isset( $columns[ 'subtotal' ] ) ) { |
|
950 | + if (isset($columns['subtotal'])) { |
|
951 | 951 | |
952 | - if ( 'amount' == $invoice->get_template() ) { |
|
953 | - unset( $columns[ 'subtotal' ] ); |
|
952 | + if ('amount' == $invoice->get_template()) { |
|
953 | + unset($columns['subtotal']); |
|
954 | 954 | } |
955 | 955 | |
956 | 956 | } |
@@ -964,30 +964,30 @@ discard block |
||
964 | 964 | * @param int|WPInv_Invoice $invoice |
965 | 965 | * @return array |
966 | 966 | */ |
967 | -function getpaid_invoice_totals_rows( $invoice ) { |
|
967 | +function getpaid_invoice_totals_rows($invoice) { |
|
968 | 968 | |
969 | 969 | // Prepare the invoice. |
970 | - $invoice = new WPInv_Invoice( $invoice ); |
|
970 | + $invoice = new WPInv_Invoice($invoice); |
|
971 | 971 | |
972 | 972 | // Abort if there is no invoice. |
973 | - if ( 0 == $invoice->get_id() ) { |
|
973 | + if (0 == $invoice->get_id()) { |
|
974 | 974 | return array(); |
975 | 975 | } |
976 | 976 | |
977 | 977 | $totals = apply_filters( |
978 | 978 | 'getpaid_invoice_totals_rows', |
979 | 979 | array( |
980 | - 'subtotal' => __( 'Subtotal', 'invoicing' ), |
|
981 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
982 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
983 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
984 | - 'total' => __( 'Total', 'invoicing' ), |
|
980 | + 'subtotal' => __('Subtotal', 'invoicing'), |
|
981 | + 'tax' => __('Tax', 'invoicing'), |
|
982 | + 'fee' => __('Fee', 'invoicing'), |
|
983 | + 'discount' => __('Discount', 'invoicing'), |
|
984 | + 'total' => __('Total', 'invoicing'), |
|
985 | 985 | ), |
986 | 986 | $invoice |
987 | 987 | ); |
988 | 988 | |
989 | - if ( ( $invoice->get_disable_taxes() || ! wpinv_use_taxes() ) && isset( $totals['tax'] ) ) { |
|
990 | - unset( $totals['tax'] ); |
|
989 | + if (($invoice->get_disable_taxes() || !wpinv_use_taxes()) && isset($totals['tax'])) { |
|
990 | + unset($totals['tax']); |
|
991 | 991 | } |
992 | 992 | |
993 | 993 | return $totals; |
@@ -998,47 +998,47 @@ discard block |
||
998 | 998 | * |
999 | 999 | * @param WPInv_Invoice $invoice |
1000 | 1000 | */ |
1001 | -function getpaid_new_invoice( $invoice ) { |
|
1001 | +function getpaid_new_invoice($invoice) { |
|
1002 | 1002 | |
1003 | - if ( ! $invoice->get_status() ) { |
|
1003 | + if (!$invoice->get_status()) { |
|
1004 | 1004 | return; |
1005 | 1005 | } |
1006 | 1006 | |
1007 | 1007 | // Add an invoice created note. |
1008 | 1008 | $invoice->add_note( |
1009 | 1009 | sprintf( |
1010 | - __( '%s created with the status "%s".', 'invoicing' ), |
|
1011 | - ucfirst( $invoice->get_type() ), |
|
1012 | - wpinv_status_nicename( $invoice->get_status(), $invoice ) |
|
1010 | + __('%s created with the status "%s".', 'invoicing'), |
|
1011 | + ucfirst($invoice->get_type()), |
|
1012 | + wpinv_status_nicename($invoice->get_status(), $invoice) |
|
1013 | 1013 | ) |
1014 | 1014 | ); |
1015 | 1015 | |
1016 | 1016 | } |
1017 | -add_action( 'getpaid_new_invoice', 'getpaid_new_invoice' ); |
|
1017 | +add_action('getpaid_new_invoice', 'getpaid_new_invoice'); |
|
1018 | 1018 | |
1019 | 1019 | /** |
1020 | 1020 | * This function updates invoice caches. |
1021 | 1021 | * |
1022 | 1022 | * @param WPInv_Invoice $invoice |
1023 | 1023 | */ |
1024 | -function getpaid_update_invoice_caches( $invoice ) { |
|
1024 | +function getpaid_update_invoice_caches($invoice) { |
|
1025 | 1025 | |
1026 | 1026 | // Cache invoice number. |
1027 | - wp_cache_set( $invoice->get_number(), $invoice->get_id(), "getpaid_invoice_numbers_to_invoice_ids" ); |
|
1027 | + wp_cache_set($invoice->get_number(), $invoice->get_id(), "getpaid_invoice_numbers_to_invoice_ids"); |
|
1028 | 1028 | |
1029 | 1029 | // Cache invoice key. |
1030 | - wp_cache_set( $invoice->get_key(), $invoice->get_id(), "getpaid_invoice_keys_to_invoice_ids" ); |
|
1030 | + wp_cache_set($invoice->get_key(), $invoice->get_id(), "getpaid_invoice_keys_to_invoice_ids"); |
|
1031 | 1031 | |
1032 | 1032 | // (Maybe) cache transaction id. |
1033 | 1033 | $transaction_id = $invoice->get_transaction_id(); |
1034 | 1034 | |
1035 | - if ( ! empty( $transaction_id ) ) { |
|
1036 | - wp_cache_set( $transaction_id, $invoice->get_id(), "getpaid_invoice_transaction_ids_to_invoice_ids" ); |
|
1035 | + if (!empty($transaction_id)) { |
|
1036 | + wp_cache_set($transaction_id, $invoice->get_id(), "getpaid_invoice_transaction_ids_to_invoice_ids"); |
|
1037 | 1037 | } |
1038 | 1038 | |
1039 | 1039 | } |
1040 | -add_action( 'getpaid_new_invoice', 'getpaid_update_invoice_caches', 5 ); |
|
1041 | -add_action( 'getpaid_update_invoice', 'getpaid_update_invoice_caches', 5 ); |
|
1040 | +add_action('getpaid_new_invoice', 'getpaid_update_invoice_caches', 5); |
|
1041 | +add_action('getpaid_update_invoice', 'getpaid_update_invoice_caches', 5); |
|
1042 | 1042 | |
1043 | 1043 | /** |
1044 | 1044 | * Duplicates an invoice. |
@@ -1048,7 +1048,7 @@ discard block |
||
1048 | 1048 | * @param WPInv_Invoice $old_invoice The invoice to duplicate |
1049 | 1049 | * @return WPInv_Invoice The new invoice. |
1050 | 1050 | */ |
1051 | -function getpaid_duplicate_invoice( $old_invoice ) { |
|
1051 | +function getpaid_duplicate_invoice($old_invoice) { |
|
1052 | 1052 | |
1053 | 1053 | // Create the new invoice. |
1054 | 1054 | $invoice = new WPInv_Invoice(); |
@@ -1109,123 +1109,123 @@ discard block |
||
1109 | 1109 | * @param WPInv_Invoice $invoice |
1110 | 1110 | * @return array |
1111 | 1111 | */ |
1112 | -function getpaid_get_invoice_meta( $invoice ) { |
|
1112 | +function getpaid_get_invoice_meta($invoice) { |
|
1113 | 1113 | |
1114 | 1114 | // Load the invoice meta. |
1115 | 1115 | $meta = array( |
1116 | 1116 | |
1117 | 1117 | 'number' => array( |
1118 | 1118 | 'label' => sprintf( |
1119 | - __( '%s Number', 'invoicing' ), |
|
1120 | - ucfirst( $invoice->get_type() ) |
|
1119 | + __('%s Number', 'invoicing'), |
|
1120 | + ucfirst($invoice->get_type()) |
|
1121 | 1121 | ), |
1122 | - 'value' => sanitize_text_field( $invoice->get_number() ), |
|
1122 | + 'value' => sanitize_text_field($invoice->get_number()), |
|
1123 | 1123 | ), |
1124 | 1124 | |
1125 | 1125 | 'status' => array( |
1126 | 1126 | 'label' => sprintf( |
1127 | - __( '%s Status', 'invoicing' ), |
|
1128 | - ucfirst( $invoice->get_type() ) |
|
1127 | + __('%s Status', 'invoicing'), |
|
1128 | + ucfirst($invoice->get_type()) |
|
1129 | 1129 | ), |
1130 | 1130 | 'value' => $invoice->get_status_label_html(), |
1131 | 1131 | ), |
1132 | 1132 | |
1133 | 1133 | 'date' => array( |
1134 | 1134 | 'label' => sprintf( |
1135 | - __( '%s Date', 'invoicing' ), |
|
1136 | - ucfirst( $invoice->get_type() ) |
|
1135 | + __('%s Date', 'invoicing'), |
|
1136 | + ucfirst($invoice->get_type()) |
|
1137 | 1137 | ), |
1138 | - 'value' => getpaid_format_date( $invoice->get_created_date() ), |
|
1138 | + 'value' => getpaid_format_date($invoice->get_created_date()), |
|
1139 | 1139 | ), |
1140 | 1140 | |
1141 | 1141 | 'date_paid' => array( |
1142 | - 'label' => __( 'Paid On', 'invoicing' ), |
|
1143 | - 'value' => getpaid_format_date( $invoice->get_completed_date() ), |
|
1142 | + 'label' => __('Paid On', 'invoicing'), |
|
1143 | + 'value' => getpaid_format_date($invoice->get_completed_date()), |
|
1144 | 1144 | ), |
1145 | 1145 | |
1146 | 1146 | 'gateway' => array( |
1147 | - 'label' => __( 'Payment Method', 'invoicing' ), |
|
1148 | - 'value' => sanitize_text_field( $invoice->get_gateway_title() ), |
|
1147 | + 'label' => __('Payment Method', 'invoicing'), |
|
1148 | + 'value' => sanitize_text_field($invoice->get_gateway_title()), |
|
1149 | 1149 | ), |
1150 | 1150 | |
1151 | 1151 | 'transaction_id' => array( |
1152 | - 'label' => __( 'Transaction ID', 'invoicing' ), |
|
1153 | - 'value' => sanitize_text_field( $invoice->get_transaction_id() ), |
|
1152 | + 'label' => __('Transaction ID', 'invoicing'), |
|
1153 | + 'value' => sanitize_text_field($invoice->get_transaction_id()), |
|
1154 | 1154 | ), |
1155 | 1155 | |
1156 | 1156 | 'due_date' => array( |
1157 | - 'label' => __( 'Due Date', 'invoicing' ), |
|
1158 | - 'value' => getpaid_format_date( $invoice->get_due_date() ), |
|
1157 | + 'label' => __('Due Date', 'invoicing'), |
|
1158 | + 'value' => getpaid_format_date($invoice->get_due_date()), |
|
1159 | 1159 | ), |
1160 | 1160 | |
1161 | 1161 | 'vat_number' => array( |
1162 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
1163 | - 'value' => sanitize_text_field( $invoice->get_vat_number() ), |
|
1162 | + 'label' => __('VAT Number', 'invoicing'), |
|
1163 | + 'value' => sanitize_text_field($invoice->get_vat_number()), |
|
1164 | 1164 | ), |
1165 | 1165 | |
1166 | 1166 | ); |
1167 | 1167 | |
1168 | 1168 | // If it is not paid, remove the date of payment. |
1169 | - if ( ! $invoice->is_paid() ) { |
|
1170 | - unset( $meta[ 'date_paid' ] ); |
|
1171 | - unset( $meta[ 'transaction_id' ] ); |
|
1169 | + if (!$invoice->is_paid()) { |
|
1170 | + unset($meta['date_paid']); |
|
1171 | + unset($meta['transaction_id']); |
|
1172 | 1172 | } |
1173 | 1173 | |
1174 | - if ( ! $invoice->is_paid() || 'none' == $invoice->get_gateway() ) { |
|
1175 | - unset( $meta[ 'gateway' ] ); |
|
1174 | + if (!$invoice->is_paid() || 'none' == $invoice->get_gateway()) { |
|
1175 | + unset($meta['gateway']); |
|
1176 | 1176 | } |
1177 | 1177 | |
1178 | 1178 | // Only display the due date if due dates are enabled. |
1179 | - if ( ! $invoice->needs_payment() || ! wpinv_get_option( 'overdue_active' ) ) { |
|
1180 | - unset( $meta[ 'due_date' ] ); |
|
1179 | + if (!$invoice->needs_payment() || !wpinv_get_option('overdue_active')) { |
|
1180 | + unset($meta['due_date']); |
|
1181 | 1181 | } |
1182 | 1182 | |
1183 | 1183 | // Only display the vat number if taxes are enabled. |
1184 | - if ( ! wpinv_use_taxes() ) { |
|
1185 | - unset( $meta[ 'vat_number' ] ); |
|
1184 | + if (!wpinv_use_taxes()) { |
|
1185 | + unset($meta['vat_number']); |
|
1186 | 1186 | } |
1187 | 1187 | |
1188 | - if ( $invoice->is_recurring() ) { |
|
1188 | + if ($invoice->is_recurring()) { |
|
1189 | 1189 | |
1190 | 1190 | // Link to the parent invoice. |
1191 | - if ( $invoice->is_renewal() ) { |
|
1191 | + if ($invoice->is_renewal()) { |
|
1192 | 1192 | |
1193 | - $meta[ 'parent' ] = array( |
|
1193 | + $meta['parent'] = array( |
|
1194 | 1194 | |
1195 | 1195 | 'label' => sprintf( |
1196 | - __( 'Parent %s', 'invoicing' ), |
|
1197 | - ucfirst( $invoice->get_type() ) |
|
1196 | + __('Parent %s', 'invoicing'), |
|
1197 | + ucfirst($invoice->get_type()) |
|
1198 | 1198 | ), |
1199 | 1199 | |
1200 | - 'value' => wpinv_invoice_link( $invoice->get_parent_id() ), |
|
1200 | + 'value' => wpinv_invoice_link($invoice->get_parent_id()), |
|
1201 | 1201 | |
1202 | 1202 | ); |
1203 | 1203 | |
1204 | 1204 | } |
1205 | 1205 | |
1206 | - $subscription = wpinv_get_subscription( $invoice ); |
|
1206 | + $subscription = wpinv_get_subscription($invoice); |
|
1207 | 1207 | |
1208 | - if ( ! empty ( $subscription ) ) { |
|
1208 | + if (!empty ($subscription)) { |
|
1209 | 1209 | |
1210 | 1210 | // Display the renewal date. |
1211 | - if ( $subscription->is_active() && 'cancelled' != $subscription->get_status() ) { |
|
1211 | + if ($subscription->is_active() && 'cancelled' != $subscription->get_status()) { |
|
1212 | 1212 | |
1213 | - $meta[ 'renewal_date' ] = array( |
|
1213 | + $meta['renewal_date'] = array( |
|
1214 | 1214 | |
1215 | - 'label' => __( 'Renews On', 'invoicing' ), |
|
1216 | - 'value' => getpaid_format_date( $subscription->get_expiration() ), |
|
1215 | + 'label' => __('Renews On', 'invoicing'), |
|
1216 | + 'value' => getpaid_format_date($subscription->get_expiration()), |
|
1217 | 1217 | |
1218 | 1218 | ); |
1219 | 1219 | |
1220 | 1220 | } |
1221 | 1221 | |
1222 | - if ( $invoice->is_parent() ) { |
|
1222 | + if ($invoice->is_parent()) { |
|
1223 | 1223 | |
1224 | 1224 | // Display the recurring amount. |
1225 | - $meta[ 'recurring_total' ] = array( |
|
1225 | + $meta['recurring_total'] = array( |
|
1226 | 1226 | |
1227 | - 'label' => __( 'Recurring Amount', 'invoicing' ), |
|
1228 | - 'value' => wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $invoice->get_currency() ), |
|
1227 | + 'label' => __('Recurring Amount', 'invoicing'), |
|
1228 | + 'value' => wpinv_price(wpinv_format_amount($subscription->get_recurring_amount()), $invoice->get_currency()), |
|
1229 | 1229 | |
1230 | 1230 | ); |
1231 | 1231 | |
@@ -1235,15 +1235,15 @@ discard block |
||
1235 | 1235 | } |
1236 | 1236 | |
1237 | 1237 | // Add the invoice total to the meta. |
1238 | - $meta[ 'invoice_total' ] = array( |
|
1238 | + $meta['invoice_total'] = array( |
|
1239 | 1239 | |
1240 | - 'label' => __( 'Total Amount', 'invoicing' ), |
|
1241 | - 'value' => wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() ), |
|
1240 | + 'label' => __('Total Amount', 'invoicing'), |
|
1241 | + 'value' => wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency()), |
|
1242 | 1242 | |
1243 | 1243 | ); |
1244 | 1244 | |
1245 | 1245 | // Provide a way for third party plugins to filter the meta. |
1246 | - $meta = apply_filters( 'getpaid_invoice_meta_data', $meta, $invoice ); |
|
1246 | + $meta = apply_filters('getpaid_invoice_meta_data', $meta, $invoice); |
|
1247 | 1247 | |
1248 | 1248 | return $meta; |
1249 | 1249 |
@@ -55,27 +55,27 @@ |
||
55 | 55 | public static function vat_rates_settings() {} |
56 | 56 | |
57 | 57 | /** |
58 | - * |
|
59 | - * @deprecated |
|
60 | - */ |
|
58 | + * |
|
59 | + * @deprecated |
|
60 | + */ |
|
61 | 61 | public static function vat_settings() {} |
62 | 62 | |
63 | 63 | /** |
64 | - * |
|
65 | - * @deprecated |
|
66 | - */ |
|
64 | + * |
|
65 | + * @deprecated |
|
66 | + */ |
|
67 | 67 | public static function maxmind_folder() {} |
68 | 68 | |
69 | 69 | /** |
70 | - * |
|
71 | - * @deprecated |
|
72 | - */ |
|
70 | + * |
|
71 | + * @deprecated |
|
72 | + */ |
|
73 | 73 | public static function geoip2_download_database() {} |
74 | 74 | |
75 | 75 | /** |
76 | - * |
|
77 | - * @deprecated |
|
78 | - */ |
|
76 | + * |
|
77 | + * @deprecated |
|
78 | + */ |
|
79 | 79 | public static function geoip2_download_file() {} |
80 | 80 | |
81 | 81 | /** |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * @deprecated |
@@ -38,15 +38,15 @@ discard block |
||
38 | 38 | /** |
39 | 39 | * @deprecated |
40 | 40 | */ |
41 | - public static function is_eu_state( $country_code ) { |
|
42 | - return getpaid_is_eu_state( $country_code ); |
|
41 | + public static function is_eu_state($country_code) { |
|
42 | + return getpaid_is_eu_state($country_code); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
46 | 46 | * @deprecated |
47 | 47 | */ |
48 | - public static function is_gst_country( $country_code ) { |
|
49 | - return getpaid_is_gst_country( $country_code ); |
|
48 | + public static function is_gst_country($country_code) { |
|
49 | + return getpaid_is_gst_country($country_code); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -14,485 +14,485 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class WPInv_Plugin { |
16 | 16 | |
17 | - /** |
|
18 | - * GetPaid version. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $version; |
|
23 | - |
|
24 | - /** |
|
25 | - * Data container. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $data = array(); |
|
30 | - |
|
31 | - /** |
|
32 | - * Form elements instance. |
|
33 | - * |
|
34 | - * @var WPInv_Payment_Form_Elements |
|
35 | - */ |
|
36 | - public $form_elements; |
|
37 | - |
|
38 | - /** |
|
39 | - * @param array An array of payment gateways. |
|
40 | - */ |
|
41 | - public $gateways; |
|
42 | - |
|
43 | - /** |
|
44 | - * Class constructor. |
|
45 | - */ |
|
46 | - public function __construct() { |
|
47 | - $this->define_constants(); |
|
48 | - $this->includes(); |
|
49 | - $this->init_hooks(); |
|
50 | - $this->set_properties(); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Sets a custom data property. |
|
55 | - * |
|
56 | - * @param string $prop The prop to set. |
|
57 | - * @param mixed $value The value to retrieve. |
|
58 | - */ |
|
59 | - public function set( $prop, $value ) { |
|
60 | - $this->data[ $prop ] = $value; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Gets a custom data property. |
|
65 | - * |
|
66 | - * @param string $prop The prop to set. |
|
67 | - * @return mixed The value. |
|
68 | - */ |
|
69 | - public function get( $prop ) { |
|
70 | - |
|
71 | - if ( isset( $this->data[ $prop ] ) ) { |
|
72 | - return $this->data[ $prop ]; |
|
73 | - } |
|
74 | - |
|
75 | - return null; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Define class properties. |
|
80 | - */ |
|
81 | - public function set_properties() { |
|
82 | - |
|
83 | - // Sessions. |
|
84 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
86 | - $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
87 | - |
|
88 | - // Init other objects. |
|
89 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
90 | - $this->set( 'notes', new WPInv_Notes() ); |
|
91 | - $this->set( 'api', new WPInv_API() ); |
|
92 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | - $this->set( 'template', new GetPaid_Template() ); |
|
94 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Define plugin constants. |
|
106 | - */ |
|
107 | - public function define_constants() { |
|
108 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
110 | - $this->version = WPINV_VERSION; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Hook into actions and filters. |
|
115 | - * |
|
116 | - * @since 1.0.19 |
|
117 | - */ |
|
118 | - protected function init_hooks() { |
|
119 | - /* Internationalize the text strings used. */ |
|
120 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
121 | - |
|
122 | - // Init the plugin after WordPress inits. |
|
123 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
127 | - |
|
128 | - if ( class_exists( 'BuddyPress' ) ) { |
|
129 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
130 | - } |
|
131 | - |
|
132 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
133 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
134 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
135 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
136 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
137 | - |
|
138 | - // Fires after registering actions. |
|
139 | - do_action( 'wpinv_actions', $this ); |
|
140 | - do_action( 'getpaid_actions', $this ); |
|
141 | - |
|
142 | - } |
|
143 | - |
|
144 | - public function plugins_loaded() { |
|
145 | - /* Internationalize the text strings used. */ |
|
146 | - $this->load_textdomain(); |
|
147 | - |
|
148 | - do_action( 'wpinv_loaded' ); |
|
149 | - |
|
150 | - // Fix oxygen page builder conflict |
|
151 | - if ( function_exists( 'ct_css_output' ) ) { |
|
152 | - wpinv_oxygen_fix_conflict(); |
|
153 | - } |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Load the translation of the plugin. |
|
158 | - * |
|
159 | - * @since 1.0 |
|
160 | - */ |
|
161 | - public function load_textdomain( $locale = NULL ) { |
|
162 | - if ( empty( $locale ) ) { |
|
163 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
164 | - } |
|
165 | - |
|
166 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
167 | - |
|
168 | - unload_textdomain( 'invoicing' ); |
|
169 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
170 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
171 | - |
|
172 | - /** |
|
173 | - * Define language constants. |
|
174 | - */ |
|
175 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Include required core files used in admin and on the frontend. |
|
180 | - */ |
|
181 | - public function includes() { |
|
182 | - |
|
183 | - // Start with the settings. |
|
184 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
185 | - |
|
186 | - // Packages/libraries. |
|
187 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
188 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
189 | - |
|
190 | - // Load functions. |
|
191 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
192 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
193 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
194 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
195 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
196 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
198 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
199 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
200 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
205 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
206 | - |
|
207 | - // Register autoloader. |
|
208 | - try { |
|
209 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
210 | - } catch ( Exception $e ) { |
|
211 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
212 | - } |
|
213 | - |
|
214 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
215 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
216 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
217 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
218 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
219 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
220 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
221 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
222 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
223 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
224 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
234 | - |
|
235 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
236 | - GetPaid_Post_Types_Admin::init(); |
|
237 | - |
|
238 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
239 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
240 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
241 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
242 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
243 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
244 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
245 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
246 | - // load the user class only on the users.php page |
|
247 | - global $pagenow; |
|
248 | - if($pagenow=='users.php'){ |
|
249 | - new WPInv_Admin_Users(); |
|
250 | - } |
|
251 | - } |
|
252 | - |
|
253 | - // Register cli commands |
|
254 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
255 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
256 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
257 | - } |
|
258 | - |
|
259 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Class autoloader |
|
264 | - * |
|
265 | - * @param string $class_name The name of the class to load. |
|
266 | - * @access public |
|
267 | - * @since 1.0.19 |
|
268 | - * @return void |
|
269 | - */ |
|
270 | - public function autoload( $class_name ) { |
|
271 | - |
|
272 | - // Normalize the class name... |
|
273 | - $class_name = strtolower( $class_name ); |
|
274 | - |
|
275 | - // ... and make sure it is our class. |
|
276 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
277 | - return; |
|
278 | - } |
|
279 | - |
|
280 | - // Next, prepare the file name from the class. |
|
281 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
282 | - |
|
283 | - // Base path of the classes. |
|
284 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
285 | - |
|
286 | - // And an array of possible locations in order of importance. |
|
287 | - $locations = array( |
|
288 | - "$plugin_path/includes", |
|
289 | - "$plugin_path/includes/data-stores", |
|
290 | - "$plugin_path/includes/gateways", |
|
291 | - "$plugin_path/includes/payments", |
|
292 | - "$plugin_path/includes/geolocation", |
|
293 | - "$plugin_path/includes/reports", |
|
294 | - "$plugin_path/includes/api", |
|
295 | - "$plugin_path/includes/admin", |
|
296 | - "$plugin_path/includes/admin/meta-boxes", |
|
297 | - ); |
|
298 | - |
|
299 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
300 | - |
|
301 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
302 | - include trailingslashit( $location ) . $file_name; |
|
303 | - break; |
|
304 | - } |
|
305 | - |
|
306 | - } |
|
307 | - |
|
308 | - } |
|
309 | - |
|
310 | - /** |
|
311 | - * Inits hooks etc. |
|
312 | - */ |
|
313 | - public function init() { |
|
314 | - |
|
315 | - // Fires before getpaid inits. |
|
316 | - do_action( 'before_getpaid_init', $this ); |
|
317 | - |
|
318 | - // Load default gateways. |
|
319 | - $gateways = apply_filters( |
|
320 | - 'getpaid_default_gateways', |
|
321 | - array( |
|
322 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
323 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
324 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
325 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
326 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
327 | - ) |
|
328 | - ); |
|
329 | - |
|
330 | - foreach ( $gateways as $id => $class ) { |
|
331 | - $this->gateways[ $id ] = new $class(); |
|
332 | - } |
|
333 | - |
|
334 | - // Fires after getpaid inits. |
|
335 | - do_action( 'getpaid_init', $this ); |
|
336 | - |
|
337 | - } |
|
338 | - |
|
339 | - /** |
|
340 | - * Checks if this is an IPN request and processes it. |
|
341 | - */ |
|
342 | - public function maybe_process_ipn() { |
|
343 | - |
|
344 | - // Ensure that this is an IPN request. |
|
345 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
346 | - return; |
|
347 | - } |
|
348 | - |
|
349 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
350 | - |
|
351 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
352 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
353 | - exit; |
|
354 | - |
|
355 | - } |
|
356 | - |
|
357 | - public function enqueue_scripts() { |
|
358 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
359 | - |
|
360 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
361 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
362 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
363 | - |
|
364 | - // Register scripts |
|
365 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
366 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
367 | - |
|
368 | - $localize = array(); |
|
369 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
370 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
371 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
372 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
373 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
374 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
375 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
376 | - |
|
377 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
378 | - |
|
379 | - wp_enqueue_script( 'jquery-blockui' ); |
|
380 | - |
|
381 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
382 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
383 | - |
|
384 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
385 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
386 | - |
|
387 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
388 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
389 | - } |
|
390 | - |
|
391 | - public function wpinv_actions() { |
|
392 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
393 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
394 | - } |
|
395 | - } |
|
17 | + /** |
|
18 | + * GetPaid version. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $version; |
|
23 | + |
|
24 | + /** |
|
25 | + * Data container. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $data = array(); |
|
30 | + |
|
31 | + /** |
|
32 | + * Form elements instance. |
|
33 | + * |
|
34 | + * @var WPInv_Payment_Form_Elements |
|
35 | + */ |
|
36 | + public $form_elements; |
|
37 | + |
|
38 | + /** |
|
39 | + * @param array An array of payment gateways. |
|
40 | + */ |
|
41 | + public $gateways; |
|
42 | + |
|
43 | + /** |
|
44 | + * Class constructor. |
|
45 | + */ |
|
46 | + public function __construct() { |
|
47 | + $this->define_constants(); |
|
48 | + $this->includes(); |
|
49 | + $this->init_hooks(); |
|
50 | + $this->set_properties(); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Sets a custom data property. |
|
55 | + * |
|
56 | + * @param string $prop The prop to set. |
|
57 | + * @param mixed $value The value to retrieve. |
|
58 | + */ |
|
59 | + public function set( $prop, $value ) { |
|
60 | + $this->data[ $prop ] = $value; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Gets a custom data property. |
|
65 | + * |
|
66 | + * @param string $prop The prop to set. |
|
67 | + * @return mixed The value. |
|
68 | + */ |
|
69 | + public function get( $prop ) { |
|
70 | + |
|
71 | + if ( isset( $this->data[ $prop ] ) ) { |
|
72 | + return $this->data[ $prop ]; |
|
73 | + } |
|
74 | + |
|
75 | + return null; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Define class properties. |
|
80 | + */ |
|
81 | + public function set_properties() { |
|
82 | + |
|
83 | + // Sessions. |
|
84 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
86 | + $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
87 | + |
|
88 | + // Init other objects. |
|
89 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
90 | + $this->set( 'notes', new WPInv_Notes() ); |
|
91 | + $this->set( 'api', new WPInv_API() ); |
|
92 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | + $this->set( 'template', new GetPaid_Template() ); |
|
94 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Define plugin constants. |
|
106 | + */ |
|
107 | + public function define_constants() { |
|
108 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
110 | + $this->version = WPINV_VERSION; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Hook into actions and filters. |
|
115 | + * |
|
116 | + * @since 1.0.19 |
|
117 | + */ |
|
118 | + protected function init_hooks() { |
|
119 | + /* Internationalize the text strings used. */ |
|
120 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
121 | + |
|
122 | + // Init the plugin after WordPress inits. |
|
123 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
127 | + |
|
128 | + if ( class_exists( 'BuddyPress' ) ) { |
|
129 | + add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
130 | + } |
|
131 | + |
|
132 | + add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
133 | + add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
134 | + add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
135 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
136 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
137 | + |
|
138 | + // Fires after registering actions. |
|
139 | + do_action( 'wpinv_actions', $this ); |
|
140 | + do_action( 'getpaid_actions', $this ); |
|
141 | + |
|
142 | + } |
|
143 | + |
|
144 | + public function plugins_loaded() { |
|
145 | + /* Internationalize the text strings used. */ |
|
146 | + $this->load_textdomain(); |
|
147 | + |
|
148 | + do_action( 'wpinv_loaded' ); |
|
149 | + |
|
150 | + // Fix oxygen page builder conflict |
|
151 | + if ( function_exists( 'ct_css_output' ) ) { |
|
152 | + wpinv_oxygen_fix_conflict(); |
|
153 | + } |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Load the translation of the plugin. |
|
158 | + * |
|
159 | + * @since 1.0 |
|
160 | + */ |
|
161 | + public function load_textdomain( $locale = NULL ) { |
|
162 | + if ( empty( $locale ) ) { |
|
163 | + $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
164 | + } |
|
165 | + |
|
166 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
167 | + |
|
168 | + unload_textdomain( 'invoicing' ); |
|
169 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
170 | + load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
171 | + |
|
172 | + /** |
|
173 | + * Define language constants. |
|
174 | + */ |
|
175 | + require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Include required core files used in admin and on the frontend. |
|
180 | + */ |
|
181 | + public function includes() { |
|
182 | + |
|
183 | + // Start with the settings. |
|
184 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
185 | + |
|
186 | + // Packages/libraries. |
|
187 | + require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
188 | + require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
189 | + |
|
190 | + // Load functions. |
|
191 | + require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
192 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
193 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
194 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
195 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
196 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
197 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
198 | + require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
199 | + require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
200 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
201 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
202 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
203 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
204 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
205 | + require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
206 | + |
|
207 | + // Register autoloader. |
|
208 | + try { |
|
209 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
210 | + } catch ( Exception $e ) { |
|
211 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
212 | + } |
|
213 | + |
|
214 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
215 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
216 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
217 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
218 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
219 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
220 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
221 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
222 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
223 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
224 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
225 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
226 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
227 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
228 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
229 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
230 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
231 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
232 | + require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
233 | + require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
234 | + |
|
235 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
236 | + GetPaid_Post_Types_Admin::init(); |
|
237 | + |
|
238 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
239 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
240 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
241 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
242 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
243 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
244 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
245 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
246 | + // load the user class only on the users.php page |
|
247 | + global $pagenow; |
|
248 | + if($pagenow=='users.php'){ |
|
249 | + new WPInv_Admin_Users(); |
|
250 | + } |
|
251 | + } |
|
252 | + |
|
253 | + // Register cli commands |
|
254 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
255 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
256 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
257 | + } |
|
258 | + |
|
259 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Class autoloader |
|
264 | + * |
|
265 | + * @param string $class_name The name of the class to load. |
|
266 | + * @access public |
|
267 | + * @since 1.0.19 |
|
268 | + * @return void |
|
269 | + */ |
|
270 | + public function autoload( $class_name ) { |
|
271 | + |
|
272 | + // Normalize the class name... |
|
273 | + $class_name = strtolower( $class_name ); |
|
396 | 274 | |
397 | - /** |
|
275 | + // ... and make sure it is our class. |
|
276 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
277 | + return; |
|
278 | + } |
|
279 | + |
|
280 | + // Next, prepare the file name from the class. |
|
281 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
282 | + |
|
283 | + // Base path of the classes. |
|
284 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
285 | + |
|
286 | + // And an array of possible locations in order of importance. |
|
287 | + $locations = array( |
|
288 | + "$plugin_path/includes", |
|
289 | + "$plugin_path/includes/data-stores", |
|
290 | + "$plugin_path/includes/gateways", |
|
291 | + "$plugin_path/includes/payments", |
|
292 | + "$plugin_path/includes/geolocation", |
|
293 | + "$plugin_path/includes/reports", |
|
294 | + "$plugin_path/includes/api", |
|
295 | + "$plugin_path/includes/admin", |
|
296 | + "$plugin_path/includes/admin/meta-boxes", |
|
297 | + ); |
|
298 | + |
|
299 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
300 | + |
|
301 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
302 | + include trailingslashit( $location ) . $file_name; |
|
303 | + break; |
|
304 | + } |
|
305 | + |
|
306 | + } |
|
307 | + |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * Inits hooks etc. |
|
312 | + */ |
|
313 | + public function init() { |
|
314 | + |
|
315 | + // Fires before getpaid inits. |
|
316 | + do_action( 'before_getpaid_init', $this ); |
|
317 | + |
|
318 | + // Load default gateways. |
|
319 | + $gateways = apply_filters( |
|
320 | + 'getpaid_default_gateways', |
|
321 | + array( |
|
322 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
323 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
324 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
325 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
326 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
327 | + ) |
|
328 | + ); |
|
329 | + |
|
330 | + foreach ( $gateways as $id => $class ) { |
|
331 | + $this->gateways[ $id ] = new $class(); |
|
332 | + } |
|
333 | + |
|
334 | + // Fires after getpaid inits. |
|
335 | + do_action( 'getpaid_init', $this ); |
|
336 | + |
|
337 | + } |
|
338 | + |
|
339 | + /** |
|
340 | + * Checks if this is an IPN request and processes it. |
|
341 | + */ |
|
342 | + public function maybe_process_ipn() { |
|
343 | + |
|
344 | + // Ensure that this is an IPN request. |
|
345 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
346 | + return; |
|
347 | + } |
|
348 | + |
|
349 | + $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
350 | + |
|
351 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
352 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
353 | + exit; |
|
354 | + |
|
355 | + } |
|
356 | + |
|
357 | + public function enqueue_scripts() { |
|
358 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
359 | + |
|
360 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
361 | + wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
362 | + wp_enqueue_style( 'wpinv_front_style' ); |
|
363 | + |
|
364 | + // Register scripts |
|
365 | + wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
366 | + wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
367 | + |
|
368 | + $localize = array(); |
|
369 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
370 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
371 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
372 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
373 | + $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
374 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
375 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
376 | + |
|
377 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
378 | + |
|
379 | + wp_enqueue_script( 'jquery-blockui' ); |
|
380 | + |
|
381 | + wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
382 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
383 | + |
|
384 | + wp_enqueue_script( 'wpinv-front-script' ); |
|
385 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
386 | + |
|
387 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
388 | + wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
389 | + } |
|
390 | + |
|
391 | + public function wpinv_actions() { |
|
392 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
393 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
394 | + } |
|
395 | + } |
|
396 | + |
|
397 | + /** |
|
398 | 398 | * Fires an action after verifying that a user can fire them. |
399 | - * |
|
400 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
401 | - * current user owns the invoice/subscription. |
|
399 | + * |
|
400 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
401 | + * current user owns the invoice/subscription. |
|
402 | 402 | */ |
403 | 403 | public function maybe_do_authenticated_action() { |
404 | 404 | |
405 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
405 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
406 | 406 | |
407 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
408 | - if ( is_user_logged_in() ) { |
|
409 | - do_action( "getpaid_authenticated_action_$key", $_REQUEST ); |
|
410 | - } |
|
407 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
408 | + if ( is_user_logged_in() ) { |
|
409 | + do_action( "getpaid_authenticated_action_$key", $_REQUEST ); |
|
410 | + } |
|
411 | 411 | |
412 | - do_action( "getpaid_unauthenticated_action_$key", $_REQUEST ); |
|
412 | + do_action( "getpaid_unauthenticated_action_$key", $_REQUEST ); |
|
413 | 413 | |
414 | - } |
|
414 | + } |
|
415 | 415 | |
416 | 416 | |
417 | 417 | } |
418 | 418 | |
419 | - public function pre_get_posts( $wp_query ) { |
|
420 | - |
|
421 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
422 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
423 | - } |
|
424 | - |
|
425 | - return $wp_query; |
|
426 | - } |
|
427 | - |
|
428 | - public function bp_invoicing_init() { |
|
429 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * Register widgets |
|
434 | - * |
|
435 | - */ |
|
436 | - public function register_widgets() { |
|
437 | - $widgets = apply_filters( |
|
438 | - 'getpaid_widget_classes', |
|
439 | - array( |
|
440 | - 'WPInv_Checkout_Widget', |
|
441 | - 'WPInv_History_Widget', |
|
442 | - 'WPInv_Receipt_Widget', |
|
443 | - 'WPInv_Subscriptions_Widget', |
|
444 | - 'WPInv_Buy_Item_Widget', |
|
445 | - 'WPInv_Messages_Widget', |
|
446 | - 'WPInv_GetPaid_Widget' |
|
447 | - ) |
|
448 | - ); |
|
449 | - |
|
450 | - foreach ( $widgets as $widget ) { |
|
451 | - register_widget( $widget ); |
|
452 | - } |
|
419 | + public function pre_get_posts( $wp_query ) { |
|
420 | + |
|
421 | + if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
422 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
423 | + } |
|
424 | + |
|
425 | + return $wp_query; |
|
426 | + } |
|
427 | + |
|
428 | + public function bp_invoicing_init() { |
|
429 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Register widgets |
|
434 | + * |
|
435 | + */ |
|
436 | + public function register_widgets() { |
|
437 | + $widgets = apply_filters( |
|
438 | + 'getpaid_widget_classes', |
|
439 | + array( |
|
440 | + 'WPInv_Checkout_Widget', |
|
441 | + 'WPInv_History_Widget', |
|
442 | + 'WPInv_Receipt_Widget', |
|
443 | + 'WPInv_Subscriptions_Widget', |
|
444 | + 'WPInv_Buy_Item_Widget', |
|
445 | + 'WPInv_Messages_Widget', |
|
446 | + 'WPInv_GetPaid_Widget' |
|
447 | + ) |
|
448 | + ); |
|
449 | + |
|
450 | + foreach ( $widgets as $widget ) { |
|
451 | + register_widget( $widget ); |
|
452 | + } |
|
453 | 453 | |
454 | - } |
|
454 | + } |
|
455 | 455 | |
456 | - /** |
|
457 | - * Remove our pages from yoast sitemaps. |
|
458 | - * |
|
459 | - * @since 1.0.19 |
|
460 | - * @param int[] $excluded_posts_ids |
|
461 | - */ |
|
462 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
456 | + /** |
|
457 | + * Remove our pages from yoast sitemaps. |
|
458 | + * |
|
459 | + * @since 1.0.19 |
|
460 | + * @param int[] $excluded_posts_ids |
|
461 | + */ |
|
462 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
463 | 463 | |
464 | - // Ensure that we have an array. |
|
465 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
466 | - $excluded_posts_ids = array(); |
|
467 | - } |
|
464 | + // Ensure that we have an array. |
|
465 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
466 | + $excluded_posts_ids = array(); |
|
467 | + } |
|
468 | 468 | |
469 | - // Prepare our pages. |
|
470 | - $our_pages = array(); |
|
469 | + // Prepare our pages. |
|
470 | + $our_pages = array(); |
|
471 | 471 | |
472 | - // Checkout page. |
|
473 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
472 | + // Checkout page. |
|
473 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
474 | 474 | |
475 | - // Success page. |
|
476 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
475 | + // Success page. |
|
476 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
477 | 477 | |
478 | - // Failure page. |
|
479 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
478 | + // Failure page. |
|
479 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
480 | 480 | |
481 | - // History page. |
|
482 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
481 | + // History page. |
|
482 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
483 | 483 | |
484 | - // Subscriptions page. |
|
485 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
484 | + // Subscriptions page. |
|
485 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
486 | 486 | |
487 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
487 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
488 | 488 | |
489 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
490 | - return array_unique( $excluded_posts_ids ); |
|
489 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
490 | + return array_unique( $excluded_posts_ids ); |
|
491 | 491 | |
492 | - } |
|
492 | + } |
|
493 | 493 | |
494 | - public function wp_footer() { |
|
495 | - echo ' |
|
494 | + public function wp_footer() { |
|
495 | + echo ' |
|
496 | 496 | <div class="bsui"> |
497 | 497 | <div id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog"> |
498 | 498 | <div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;"> |
@@ -508,6 +508,6 @@ discard block |
||
508 | 508 | </div> |
509 | 509 | </div> |
510 | 510 | '; |
511 | - } |
|
511 | + } |
|
512 | 512 | |
513 | 513 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 1.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Main Invoicing class. |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | * @param string $prop The prop to set. |
57 | 57 | * @param mixed $value The value to retrieve. |
58 | 58 | */ |
59 | - public function set( $prop, $value ) { |
|
60 | - $this->data[ $prop ] = $value; |
|
59 | + public function set($prop, $value) { |
|
60 | + $this->data[$prop] = $value; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | * @param string $prop The prop to set. |
67 | 67 | * @return mixed The value. |
68 | 68 | */ |
69 | - public function get( $prop ) { |
|
69 | + public function get($prop) { |
|
70 | 70 | |
71 | - if ( isset( $this->data[ $prop ] ) ) { |
|
72 | - return $this->data[ $prop ]; |
|
71 | + if (isset($this->data[$prop])) { |
|
72 | + return $this->data[$prop]; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | return null; |
@@ -81,23 +81,23 @@ discard block |
||
81 | 81 | public function set_properties() { |
82 | 82 | |
83 | 83 | // Sessions. |
84 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
84 | + $this->set('session', new WPInv_Session_Handler()); |
|
85 | + $GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility. |
|
86 | 86 | $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
87 | 87 | |
88 | 88 | // Init other objects. |
89 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
90 | - $this->set( 'notes', new WPInv_Notes() ); |
|
91 | - $this->set( 'api', new WPInv_API() ); |
|
92 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | - $this->set( 'template', new GetPaid_Template() ); |
|
94 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
89 | + $this->set('session', new WPInv_Session_Handler()); |
|
90 | + $this->set('notes', new WPInv_Notes()); |
|
91 | + $this->set('api', new WPInv_API()); |
|
92 | + $this->set('post_types', new GetPaid_Post_Types()); |
|
93 | + $this->set('template', new GetPaid_Template()); |
|
94 | + $this->set('admin', new GetPaid_Admin()); |
|
95 | + $this->set('subscriptions', new WPInv_Subscriptions()); |
|
96 | + $this->set('invoice_emails', new GetPaid_Invoice_Notification_Emails()); |
|
97 | + $this->set('subscription_emails', new GetPaid_Subscription_Notification_Emails()); |
|
98 | + $this->set('daily_maintenace', new GetPaid_Daily_Maintenance()); |
|
99 | + $this->set('payment_forms', new GetPaid_Payment_Forms()); |
|
100 | + $this->set('maxmind', new GetPaid_MaxMind_Geolocation()); |
|
101 | 101 | |
102 | 102 | } |
103 | 103 | |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | * Define plugin constants. |
106 | 106 | */ |
107 | 107 | public function define_constants() { |
108 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
108 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
109 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
110 | 110 | $this->version = WPINV_VERSION; |
111 | 111 | } |
112 | 112 | |
@@ -117,27 +117,27 @@ discard block |
||
117 | 117 | */ |
118 | 118 | protected function init_hooks() { |
119 | 119 | /* Internationalize the text strings used. */ |
120 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
120 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
121 | 121 | |
122 | 122 | // Init the plugin after WordPress inits. |
123 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
123 | + add_action('init', array($this, 'init'), 1); |
|
124 | + add_action('init', array($this, 'maybe_process_ipn'), 10); |
|
125 | + add_action('init', array($this, 'wpinv_actions')); |
|
126 | + add_action('init', array($this, 'maybe_do_authenticated_action'), 100); |
|
127 | 127 | |
128 | - if ( class_exists( 'BuddyPress' ) ) { |
|
129 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
128 | + if (class_exists('BuddyPress')) { |
|
129 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
130 | 130 | } |
131 | 131 | |
132 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
133 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
134 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
135 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
136 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
132 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
133 | + add_action('wp_footer', array(&$this, 'wp_footer')); |
|
134 | + add_action('widgets_init', array(&$this, 'register_widgets')); |
|
135 | + add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids')); |
|
136 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
137 | 137 | |
138 | 138 | // Fires after registering actions. |
139 | - do_action( 'wpinv_actions', $this ); |
|
140 | - do_action( 'getpaid_actions', $this ); |
|
139 | + do_action('wpinv_actions', $this); |
|
140 | + do_action('getpaid_actions', $this); |
|
141 | 141 | |
142 | 142 | } |
143 | 143 | |
@@ -145,10 +145,10 @@ discard block |
||
145 | 145 | /* Internationalize the text strings used. */ |
146 | 146 | $this->load_textdomain(); |
147 | 147 | |
148 | - do_action( 'wpinv_loaded' ); |
|
148 | + do_action('wpinv_loaded'); |
|
149 | 149 | |
150 | 150 | // Fix oxygen page builder conflict |
151 | - if ( function_exists( 'ct_css_output' ) ) { |
|
151 | + if (function_exists('ct_css_output')) { |
|
152 | 152 | wpinv_oxygen_fix_conflict(); |
153 | 153 | } |
154 | 154 | } |
@@ -158,21 +158,21 @@ discard block |
||
158 | 158 | * |
159 | 159 | * @since 1.0 |
160 | 160 | */ |
161 | - public function load_textdomain( $locale = NULL ) { |
|
162 | - if ( empty( $locale ) ) { |
|
163 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
161 | + public function load_textdomain($locale = NULL) { |
|
162 | + if (empty($locale)) { |
|
163 | + $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
|
164 | 164 | } |
165 | 165 | |
166 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
166 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
167 | 167 | |
168 | - unload_textdomain( 'invoicing' ); |
|
169 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
170 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
168 | + unload_textdomain('invoicing'); |
|
169 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
170 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
171 | 171 | |
172 | 172 | /** |
173 | 173 | * Define language constants. |
174 | 174 | */ |
175 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
175 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -181,82 +181,82 @@ discard block |
||
181 | 181 | public function includes() { |
182 | 182 | |
183 | 183 | // Start with the settings. |
184 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
184 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
185 | 185 | |
186 | 186 | // Packages/libraries. |
187 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
188 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
187 | + require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php'); |
|
188 | + require_once(WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'); |
|
189 | 189 | |
190 | 190 | // Load functions. |
191 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
192 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
193 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
194 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
195 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
196 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
198 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
199 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
200 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
205 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
191 | + require_once(WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'); |
|
192 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
193 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
194 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
195 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
196 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
197 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
198 | + require_once(WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'); |
|
199 | + require_once(WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'); |
|
200 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
201 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
202 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
203 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
204 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
205 | + require_once(WPINV_PLUGIN_DIR . 'includes/error-functions.php'); |
|
206 | 206 | |
207 | 207 | // Register autoloader. |
208 | 208 | try { |
209 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
210 | - } catch ( Exception $e ) { |
|
211 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
209 | + spl_autoload_register(array($this, 'autoload'), true); |
|
210 | + } catch (Exception $e) { |
|
211 | + wpinv_error_log($e->getMessage(), '', __FILE__, 149, true); |
|
212 | 212 | } |
213 | 213 | |
214 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
215 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
216 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
217 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
218 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
219 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
220 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
221 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
222 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
223 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
224 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
234 | - |
|
235 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
214 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'); |
|
215 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'); |
|
216 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
217 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
218 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'); |
|
219 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'); |
|
220 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'); |
|
221 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'); |
|
222 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'); |
|
223 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'); |
|
224 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'); |
|
225 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'); |
|
226 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'); |
|
227 | + require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php'); |
|
228 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'); |
|
229 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'); |
|
230 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'); |
|
231 | + require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'); |
|
232 | + require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php'); |
|
233 | + require_once(WPINV_PLUGIN_DIR . 'widgets/getpaid.php'); |
|
234 | + |
|
235 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
236 | 236 | GetPaid_Post_Types_Admin::init(); |
237 | 237 | |
238 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
239 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
240 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
241 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
242 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
243 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
244 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
245 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
238 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
239 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
240 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'); |
|
241 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
242 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
243 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'); |
|
244 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'); |
|
245 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'); |
|
246 | 246 | // load the user class only on the users.php page |
247 | 247 | global $pagenow; |
248 | - if($pagenow=='users.php'){ |
|
248 | + if ($pagenow == 'users.php') { |
|
249 | 249 | new WPInv_Admin_Users(); |
250 | 250 | } |
251 | 251 | } |
252 | 252 | |
253 | 253 | // Register cli commands |
254 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
255 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
256 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
254 | + if (defined('WP_CLI') && WP_CLI) { |
|
255 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'); |
|
256 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
257 | 257 | } |
258 | 258 | |
259 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
259 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -267,21 +267,21 @@ discard block |
||
267 | 267 | * @since 1.0.19 |
268 | 268 | * @return void |
269 | 269 | */ |
270 | - public function autoload( $class_name ) { |
|
270 | + public function autoload($class_name) { |
|
271 | 271 | |
272 | 272 | // Normalize the class name... |
273 | - $class_name = strtolower( $class_name ); |
|
273 | + $class_name = strtolower($class_name); |
|
274 | 274 | |
275 | 275 | // ... and make sure it is our class. |
276 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
276 | + if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) { |
|
277 | 277 | return; |
278 | 278 | } |
279 | 279 | |
280 | 280 | // Next, prepare the file name from the class. |
281 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
281 | + $file_name = 'class-' . str_replace('_', '-', $class_name) . '.php'; |
|
282 | 282 | |
283 | 283 | // Base path of the classes. |
284 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
284 | + $plugin_path = untrailingslashit(WPINV_PLUGIN_DIR); |
|
285 | 285 | |
286 | 286 | // And an array of possible locations in order of importance. |
287 | 287 | $locations = array( |
@@ -296,10 +296,10 @@ discard block |
||
296 | 296 | "$plugin_path/includes/admin/meta-boxes", |
297 | 297 | ); |
298 | 298 | |
299 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
299 | + foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) { |
|
300 | 300 | |
301 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
302 | - include trailingslashit( $location ) . $file_name; |
|
301 | + if (file_exists(trailingslashit($location) . $file_name)) { |
|
302 | + include trailingslashit($location) . $file_name; |
|
303 | 303 | break; |
304 | 304 | } |
305 | 305 | |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | public function init() { |
314 | 314 | |
315 | 315 | // Fires before getpaid inits. |
316 | - do_action( 'before_getpaid_init', $this ); |
|
316 | + do_action('before_getpaid_init', $this); |
|
317 | 317 | |
318 | 318 | // Load default gateways. |
319 | 319 | $gateways = apply_filters( |
@@ -327,12 +327,12 @@ discard block |
||
327 | 327 | ) |
328 | 328 | ); |
329 | 329 | |
330 | - foreach ( $gateways as $id => $class ) { |
|
331 | - $this->gateways[ $id ] = new $class(); |
|
330 | + foreach ($gateways as $id => $class) { |
|
331 | + $this->gateways[$id] = new $class(); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | // Fires after getpaid inits. |
335 | - do_action( 'getpaid_init', $this ); |
|
335 | + do_action('getpaid_init', $this); |
|
336 | 336 | |
337 | 337 | } |
338 | 338 | |
@@ -342,55 +342,55 @@ discard block |
||
342 | 342 | public function maybe_process_ipn() { |
343 | 343 | |
344 | 344 | // Ensure that this is an IPN request. |
345 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
345 | + if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) { |
|
346 | 346 | return; |
347 | 347 | } |
348 | 348 | |
349 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
349 | + $gateway = wpinv_clean($_GET['wpi-gateway']); |
|
350 | 350 | |
351 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
352 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
351 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
352 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
353 | 353 | exit; |
354 | 354 | |
355 | 355 | } |
356 | 356 | |
357 | 357 | public function enqueue_scripts() { |
358 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
358 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
359 | 359 | |
360 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
361 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
362 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
360 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css'); |
|
361 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version); |
|
362 | + wp_enqueue_style('wpinv_front_style'); |
|
363 | 363 | |
364 | 364 | // Register scripts |
365 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
366 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
365 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
366 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), filemtime(WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js')); |
|
367 | 367 | |
368 | 368 | $localize = array(); |
369 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
370 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
371 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
369 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
370 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
371 | + $localize['txtComplete'] = __('Continue', 'invoicing'); |
|
372 | 372 | $localize['UseTaxes'] = wpinv_use_taxes(); |
373 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
374 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
375 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
373 | + $localize['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce'); |
|
374 | + $localize['formNonce'] = wp_create_nonce('getpaid_form_nonce'); |
|
375 | + $localize['connectionError'] = __('Could not establish a connection to the server.', 'invoicing'); |
|
376 | 376 | |
377 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
377 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
378 | 378 | |
379 | - wp_enqueue_script( 'jquery-blockui' ); |
|
379 | + wp_enqueue_script('jquery-blockui'); |
|
380 | 380 | |
381 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
382 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
381 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all'); |
|
382 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
383 | 383 | |
384 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
385 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
384 | + wp_enqueue_script('wpinv-front-script'); |
|
385 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
386 | 386 | |
387 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
388 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
387 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js'); |
|
388 | + wp_enqueue_script('wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('wpinv-front-script', 'wp-hooks'), $version, true); |
|
389 | 389 | } |
390 | 390 | |
391 | 391 | public function wpinv_actions() { |
392 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
393 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
392 | + if (isset($_REQUEST['wpi_action'])) { |
|
393 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
394 | 394 | } |
395 | 395 | } |
396 | 396 | |
@@ -402,31 +402,31 @@ discard block |
||
402 | 402 | */ |
403 | 403 | public function maybe_do_authenticated_action() { |
404 | 404 | |
405 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
405 | + if (isset($_REQUEST['getpaid-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
406 | 406 | |
407 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
408 | - if ( is_user_logged_in() ) { |
|
409 | - do_action( "getpaid_authenticated_action_$key", $_REQUEST ); |
|
407 | + $key = sanitize_key($_REQUEST['getpaid-action']); |
|
408 | + if (is_user_logged_in()) { |
|
409 | + do_action("getpaid_authenticated_action_$key", $_REQUEST); |
|
410 | 410 | } |
411 | 411 | |
412 | - do_action( "getpaid_unauthenticated_action_$key", $_REQUEST ); |
|
412 | + do_action("getpaid_unauthenticated_action_$key", $_REQUEST); |
|
413 | 413 | |
414 | 414 | } |
415 | 415 | |
416 | 416 | |
417 | 417 | } |
418 | 418 | |
419 | - public function pre_get_posts( $wp_query ) { |
|
419 | + public function pre_get_posts($wp_query) { |
|
420 | 420 | |
421 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
422 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
421 | + if (!is_admin() && !empty($wp_query->query_vars['post_type']) && getpaid_is_invoice_post_type($wp_query->query_vars['post_type']) && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
422 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses(false, false, $wp_query->query_vars['post_type'])); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | return $wp_query; |
426 | 426 | } |
427 | 427 | |
428 | 428 | public function bp_invoicing_init() { |
429 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
429 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | /** |
@@ -447,8 +447,8 @@ discard block |
||
447 | 447 | ) |
448 | 448 | ); |
449 | 449 | |
450 | - foreach ( $widgets as $widget ) { |
|
451 | - register_widget( $widget ); |
|
450 | + foreach ($widgets as $widget) { |
|
451 | + register_widget($widget); |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | } |
@@ -459,10 +459,10 @@ discard block |
||
459 | 459 | * @since 1.0.19 |
460 | 460 | * @param int[] $excluded_posts_ids |
461 | 461 | */ |
462 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
462 | + public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) { |
|
463 | 463 | |
464 | 464 | // Ensure that we have an array. |
465 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
465 | + if (!is_array($excluded_posts_ids)) { |
|
466 | 466 | $excluded_posts_ids = array(); |
467 | 467 | } |
468 | 468 | |
@@ -470,24 +470,24 @@ discard block |
||
470 | 470 | $our_pages = array(); |
471 | 471 | |
472 | 472 | // Checkout page. |
473 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
473 | + $our_pages[] = wpinv_get_option('checkout_page', false); |
|
474 | 474 | |
475 | 475 | // Success page. |
476 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
476 | + $our_pages[] = wpinv_get_option('success_page', false); |
|
477 | 477 | |
478 | 478 | // Failure page. |
479 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
479 | + $our_pages[] = wpinv_get_option('failure_page', false); |
|
480 | 480 | |
481 | 481 | // History page. |
482 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
482 | + $our_pages[] = wpinv_get_option('invoice_history_page', false); |
|
483 | 483 | |
484 | 484 | // Subscriptions page. |
485 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
485 | + $our_pages[] = wpinv_get_option('invoice_subscription_page', false); |
|
486 | 486 | |
487 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
487 | + $our_pages = array_map('intval', array_filter($our_pages)); |
|
488 | 488 | |
489 | 489 | $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
490 | - return array_unique( $excluded_posts_ids ); |
|
490 | + return array_unique($excluded_posts_ids); |
|
491 | 491 | |
492 | 492 | } |
493 | 493 | |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | <div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;"> |
499 | 499 | <div class="modal-content"> |
500 | 500 | <div class="modal-body"> |
501 | - <button type="button" class="close p-2 getpaid-payment-modal-close d-sm-none" data-dismiss="modal" aria-label="' . esc_attr__( 'Close', 'invoicing' ) . '"> |
|
501 | + <button type="button" class="close p-2 getpaid-payment-modal-close d-sm-none" data-dismiss="modal" aria-label="' . esc_attr__('Close', 'invoicing') . '"> |
|
502 | 502 | <i class="fa fa-times" aria-hidden="true"></i> |
503 | 503 | </button> |
504 | 504 | <div class="modal-body-wrapper"></div> |
@@ -12,210 +12,210 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Taxes { |
14 | 14 | |
15 | - /** |
|
16 | - * Submission taxes. |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public $taxes = array(); |
|
15 | + /** |
|
16 | + * Submission taxes. |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public $taxes = array(); |
|
20 | + |
|
21 | + /** |
|
22 | + * Class constructor |
|
23 | + * |
|
24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
25 | + */ |
|
26 | + public function __construct( $submission ) { |
|
27 | + |
|
28 | + // Validate VAT number. |
|
29 | + $this->validate_vat( $submission ); |
|
30 | + |
|
31 | + foreach ( $submission->get_items() as $item ) { |
|
32 | + $this->process_item_tax( $item, $submission ); |
|
33 | + } |
|
34 | + |
|
35 | + // Process any existing invoice taxes. |
|
36 | + if ( $submission->has_invoice() ) { |
|
37 | + $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
38 | + } |
|
39 | + |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Maybe process tax. |
|
44 | + * |
|
45 | + * @since 1.0.19 |
|
46 | + * @param GetPaid_Form_Item $item |
|
47 | + * @param GetPaid_Payment_Form_Submission $submission |
|
48 | + */ |
|
49 | + public function process_item_tax( $item, $submission ) { |
|
50 | + |
|
51 | + $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
52 | + $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
53 | + $taxes = getpaid_calculate_item_taxes( $item->get_sub_total(), $rates ); |
|
54 | + $r_taxes = getpaid_calculate_item_taxes( $item->get_recurring_sub_total(), $rates ); |
|
55 | + |
|
56 | + foreach ( $taxes as $name => $amount ) { |
|
57 | + $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
58 | + $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
59 | + |
|
60 | + if ( ! isset( $this->taxes[ $name ] ) ) { |
|
61 | + $this->taxes[ $name ] = $tax; |
|
62 | + continue; |
|
63 | + } |
|
64 | + |
|
65 | + $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
66 | + $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
67 | + |
|
68 | + } |
|
69 | + |
|
70 | + } |
|
20 | 71 | |
21 | 72 | /** |
22 | - * Class constructor |
|
23 | - * |
|
24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
25 | - */ |
|
26 | - public function __construct( $submission ) { |
|
27 | - |
|
28 | - // Validate VAT number. |
|
29 | - $this->validate_vat( $submission ); |
|
30 | - |
|
31 | - foreach ( $submission->get_items() as $item ) { |
|
32 | - $this->process_item_tax( $item, $submission ); |
|
33 | - } |
|
34 | - |
|
35 | - // Process any existing invoice taxes. |
|
36 | - if ( $submission->has_invoice() ) { |
|
37 | - $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
38 | - } |
|
39 | - |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Maybe process tax. |
|
44 | - * |
|
45 | - * @since 1.0.19 |
|
46 | - * @param GetPaid_Form_Item $item |
|
47 | - * @param GetPaid_Payment_Form_Submission $submission |
|
48 | - */ |
|
49 | - public function process_item_tax( $item, $submission ) { |
|
50 | - |
|
51 | - $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
52 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
53 | - $taxes = getpaid_calculate_item_taxes( $item->get_sub_total(), $rates ); |
|
54 | - $r_taxes = getpaid_calculate_item_taxes( $item->get_recurring_sub_total(), $rates ); |
|
55 | - |
|
56 | - foreach ( $taxes as $name => $amount ) { |
|
57 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
58 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
59 | - |
|
60 | - if ( ! isset( $this->taxes[ $name ] ) ) { |
|
61 | - $this->taxes[ $name ] = $tax; |
|
62 | - continue; |
|
63 | - } |
|
64 | - |
|
65 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
66 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
67 | - |
|
68 | - } |
|
69 | - |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Checks if the submission has a digital item. |
|
74 | - * |
|
75 | - * @param GetPaid_Payment_Form_Submission $submission |
|
76 | - * @since 1.0.19 |
|
77 | - * @return bool |
|
78 | - */ |
|
79 | - public function has_digital_item( $submission ) { |
|
80 | - |
|
81 | - foreach ( $submission->get_items() as $item ) { |
|
82 | - |
|
83 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
84 | - return true; |
|
85 | - } |
|
86 | - |
|
87 | - } |
|
88 | - |
|
89 | - return false; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Checks if this is an eu store. |
|
94 | - * |
|
95 | - * @since 1.0.19 |
|
96 | - * @return bool |
|
97 | - */ |
|
98 | - public function is_eu_store() { |
|
99 | - return $this->is_eu_country( wpinv_get_default_country() ); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Checks if this is an eu country. |
|
104 | - * |
|
105 | - * @param string $country |
|
106 | - * @since 1.0.19 |
|
107 | - * @return bool |
|
108 | - */ |
|
109 | - public function is_eu_country( $country ) { |
|
110 | - return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Checks if this is an eu purchase. |
|
115 | - * |
|
116 | - * @param string $customer_country |
|
117 | - * @since 1.0.19 |
|
118 | - * @return bool |
|
119 | - */ |
|
120 | - public function is_eu_transaction( $customer_country ) { |
|
121 | - return $this->is_eu_country( $customer_country ) && $this->is_eu_store(); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Retrieves the vat number. |
|
126 | - * |
|
127 | - * @param GetPaid_Payment_Form_Submission $submission |
|
128 | - * @since 1.0.19 |
|
129 | - * @return string |
|
130 | - */ |
|
131 | - public function get_vat_number( $submission ) { |
|
132 | - |
|
133 | - // Retrieve from the posted number. |
|
134 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
135 | - if ( ! empty( $vat_number ) ) { |
|
136 | - return wpinv_clean( $vat_number ); |
|
137 | - } |
|
138 | - |
|
139 | - // Retrieve from the invoice. |
|
140 | - return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Retrieves the company. |
|
145 | - * |
|
146 | - * @param GetPaid_Payment_Form_Submission $submission |
|
147 | - * @since 1.0.19 |
|
148 | - * @return string |
|
149 | - */ |
|
150 | - public function get_company( $submission ) { |
|
151 | - |
|
152 | - // Retrieve from the posted data. |
|
153 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
154 | - if ( ! empty( $company ) ) { |
|
155 | - return wpinv_clean( $company ); |
|
156 | - } |
|
157 | - |
|
158 | - // Retrieve from the invoice. |
|
159 | - return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Checks if we require a VAT number. |
|
164 | - * |
|
165 | - * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
166 | - * @param bool $country_in_eu Whether the customer country is from the EU |
|
167 | - * @since 1.0.19 |
|
168 | - * @return string |
|
169 | - */ |
|
170 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
171 | - |
|
172 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
173 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
174 | - $is_eu = $ip_in_eu || $country_in_eu; |
|
175 | - |
|
176 | - return $prevent_b2c && $is_eu; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Validate VAT data. |
|
181 | - * |
|
182 | - * @param GetPaid_Payment_Form_Submission $submission |
|
183 | - * @since 1.0.19 |
|
184 | - */ |
|
185 | - public function validate_vat( $submission ) { |
|
186 | - |
|
187 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
188 | - |
|
189 | - // Abort if we are not validating vat numbers. |
|
190 | - if ( ! $in_eu ) { |
|
73 | + * Checks if the submission has a digital item. |
|
74 | + * |
|
75 | + * @param GetPaid_Payment_Form_Submission $submission |
|
76 | + * @since 1.0.19 |
|
77 | + * @return bool |
|
78 | + */ |
|
79 | + public function has_digital_item( $submission ) { |
|
80 | + |
|
81 | + foreach ( $submission->get_items() as $item ) { |
|
82 | + |
|
83 | + if ( 'digital' == $item->get_vat_rule() ) { |
|
84 | + return true; |
|
85 | + } |
|
86 | + |
|
87 | + } |
|
88 | + |
|
89 | + return false; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Checks if this is an eu store. |
|
94 | + * |
|
95 | + * @since 1.0.19 |
|
96 | + * @return bool |
|
97 | + */ |
|
98 | + public function is_eu_store() { |
|
99 | + return $this->is_eu_country( wpinv_get_default_country() ); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Checks if this is an eu country. |
|
104 | + * |
|
105 | + * @param string $country |
|
106 | + * @since 1.0.19 |
|
107 | + * @return bool |
|
108 | + */ |
|
109 | + public function is_eu_country( $country ) { |
|
110 | + return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Checks if this is an eu purchase. |
|
115 | + * |
|
116 | + * @param string $customer_country |
|
117 | + * @since 1.0.19 |
|
118 | + * @return bool |
|
119 | + */ |
|
120 | + public function is_eu_transaction( $customer_country ) { |
|
121 | + return $this->is_eu_country( $customer_country ) && $this->is_eu_store(); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Retrieves the vat number. |
|
126 | + * |
|
127 | + * @param GetPaid_Payment_Form_Submission $submission |
|
128 | + * @since 1.0.19 |
|
129 | + * @return string |
|
130 | + */ |
|
131 | + public function get_vat_number( $submission ) { |
|
132 | + |
|
133 | + // Retrieve from the posted number. |
|
134 | + $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
135 | + if ( ! empty( $vat_number ) ) { |
|
136 | + return wpinv_clean( $vat_number ); |
|
137 | + } |
|
138 | + |
|
139 | + // Retrieve from the invoice. |
|
140 | + return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Retrieves the company. |
|
145 | + * |
|
146 | + * @param GetPaid_Payment_Form_Submission $submission |
|
147 | + * @since 1.0.19 |
|
148 | + * @return string |
|
149 | + */ |
|
150 | + public function get_company( $submission ) { |
|
151 | + |
|
152 | + // Retrieve from the posted data. |
|
153 | + $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
154 | + if ( ! empty( $company ) ) { |
|
155 | + return wpinv_clean( $company ); |
|
156 | + } |
|
157 | + |
|
158 | + // Retrieve from the invoice. |
|
159 | + return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Checks if we require a VAT number. |
|
164 | + * |
|
165 | + * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
166 | + * @param bool $country_in_eu Whether the customer country is from the EU |
|
167 | + * @since 1.0.19 |
|
168 | + * @return string |
|
169 | + */ |
|
170 | + public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
171 | + |
|
172 | + $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
173 | + $prevent_b2c = ! empty( $prevent_b2c ); |
|
174 | + $is_eu = $ip_in_eu || $country_in_eu; |
|
175 | + |
|
176 | + return $prevent_b2c && $is_eu; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Validate VAT data. |
|
181 | + * |
|
182 | + * @param GetPaid_Payment_Form_Submission $submission |
|
183 | + * @since 1.0.19 |
|
184 | + */ |
|
185 | + public function validate_vat( $submission ) { |
|
186 | + |
|
187 | + $in_eu = $this->is_eu_transaction( $submission->country ); |
|
188 | + |
|
189 | + // Abort if we are not validating vat numbers. |
|
190 | + if ( ! $in_eu ) { |
|
191 | 191 | return; |
192 | - } |
|
192 | + } |
|
193 | 193 | |
194 | - // Prepare variables. |
|
195 | - $vat_number = $this->get_vat_number( $submission ); |
|
196 | - $ip_country = getpaid_get_ip_country(); |
|
194 | + // Prepare variables. |
|
195 | + $vat_number = $this->get_vat_number( $submission ); |
|
196 | + $ip_country = getpaid_get_ip_country(); |
|
197 | 197 | $is_eu = $this->is_eu_country( $submission->country ); |
198 | 198 | $is_ip_eu = $this->is_eu_country( $ip_country ); |
199 | 199 | |
200 | - // If we're preventing business to consumer purchases, |
|
201 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
200 | + // If we're preventing business to consumer purchases, |
|
201 | + if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
202 | 202 | |
203 | - // Ensure that a vat number has been specified. |
|
204 | - throw new Exception( |
|
205 | - __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) |
|
206 | - ); |
|
203 | + // Ensure that a vat number has been specified. |
|
204 | + throw new Exception( |
|
205 | + __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) |
|
206 | + ); |
|
207 | 207 | |
208 | - } |
|
208 | + } |
|
209 | 209 | |
210 | - // Abort if we are not validating vat (vat number should exist, user should be in eu and business too). |
|
211 | - if ( ! $in_eu ) { |
|
210 | + // Abort if we are not validating vat (vat number should exist, user should be in eu and business too). |
|
211 | + if ( ! $in_eu ) { |
|
212 | 212 | return; |
213 | - } |
|
213 | + } |
|
214 | 214 | |
215 | - if ( ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
216 | - throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
217 | - } |
|
215 | + if ( ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
216 | + throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
217 | + } |
|
218 | 218 | |
219 | - } |
|
219 | + } |
|
220 | 220 | |
221 | 221 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Payment form submission taxes class |
@@ -23,18 +23,18 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @param GetPaid_Payment_Form_Submission $submission |
25 | 25 | */ |
26 | - public function __construct( $submission ) { |
|
26 | + public function __construct($submission) { |
|
27 | 27 | |
28 | 28 | // Validate VAT number. |
29 | - $this->validate_vat( $submission ); |
|
29 | + $this->validate_vat($submission); |
|
30 | 30 | |
31 | - foreach ( $submission->get_items() as $item ) { |
|
32 | - $this->process_item_tax( $item, $submission ); |
|
31 | + foreach ($submission->get_items() as $item) { |
|
32 | + $this->process_item_tax($item, $submission); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | // Process any existing invoice taxes. |
36 | - if ( $submission->has_invoice() ) { |
|
37 | - $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
36 | + if ($submission->has_invoice()) { |
|
37 | + $this->taxes = array_replace($submission->get_invoice()->get_taxes(), $this->taxes); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | } |
@@ -46,24 +46,24 @@ discard block |
||
46 | 46 | * @param GetPaid_Form_Item $item |
47 | 47 | * @param GetPaid_Payment_Form_Submission $submission |
48 | 48 | */ |
49 | - public function process_item_tax( $item, $submission ) { |
|
49 | + public function process_item_tax($item, $submission) { |
|
50 | 50 | |
51 | - $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
52 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
53 | - $taxes = getpaid_calculate_item_taxes( $item->get_sub_total(), $rates ); |
|
54 | - $r_taxes = getpaid_calculate_item_taxes( $item->get_recurring_sub_total(), $rates ); |
|
51 | + $rates = getpaid_get_item_tax_rates($item, $submission->country, $submission->state); |
|
52 | + $rates = getpaid_filter_item_tax_rates($item, $rates); |
|
53 | + $taxes = getpaid_calculate_item_taxes($item->get_sub_total(), $rates); |
|
54 | + $r_taxes = getpaid_calculate_item_taxes($item->get_recurring_sub_total(), $rates); |
|
55 | 55 | |
56 | - foreach ( $taxes as $name => $amount ) { |
|
57 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
58 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
56 | + foreach ($taxes as $name => $amount) { |
|
57 | + $recurring = isset($r_taxes[$name]) ? $r_taxes[$name] : 0; |
|
58 | + $tax = getpaid_prepare_item_tax($item, $name, $amount, $recurring); |
|
59 | 59 | |
60 | - if ( ! isset( $this->taxes[ $name ] ) ) { |
|
61 | - $this->taxes[ $name ] = $tax; |
|
60 | + if (!isset($this->taxes[$name])) { |
|
61 | + $this->taxes[$name] = $tax; |
|
62 | 62 | continue; |
63 | 63 | } |
64 | 64 | |
65 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
66 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
65 | + $this->taxes[$name]['initial_tax'] += $tax['initial_tax']; |
|
66 | + $this->taxes[$name]['recurring_tax'] += $tax['recurring_tax']; |
|
67 | 67 | |
68 | 68 | } |
69 | 69 | |
@@ -76,11 +76,11 @@ discard block |
||
76 | 76 | * @since 1.0.19 |
77 | 77 | * @return bool |
78 | 78 | */ |
79 | - public function has_digital_item( $submission ) { |
|
79 | + public function has_digital_item($submission) { |
|
80 | 80 | |
81 | - foreach ( $submission->get_items() as $item ) { |
|
81 | + foreach ($submission->get_items() as $item) { |
|
82 | 82 | |
83 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
83 | + if ('digital' == $item->get_vat_rule()) { |
|
84 | 84 | return true; |
85 | 85 | } |
86 | 86 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * @return bool |
97 | 97 | */ |
98 | 98 | public function is_eu_store() { |
99 | - return $this->is_eu_country( wpinv_get_default_country() ); |
|
99 | + return $this->is_eu_country(wpinv_get_default_country()); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -106,8 +106,8 @@ discard block |
||
106 | 106 | * @since 1.0.19 |
107 | 107 | * @return bool |
108 | 108 | */ |
109 | - public function is_eu_country( $country ) { |
|
110 | - return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
109 | + public function is_eu_country($country) { |
|
110 | + return getpaid_is_eu_state($country) || getpaid_is_gst_country($country); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | * @since 1.0.19 |
118 | 118 | * @return bool |
119 | 119 | */ |
120 | - public function is_eu_transaction( $customer_country ) { |
|
121 | - return $this->is_eu_country( $customer_country ) && $this->is_eu_store(); |
|
120 | + public function is_eu_transaction($customer_country) { |
|
121 | + return $this->is_eu_country($customer_country) && $this->is_eu_store(); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -128,12 +128,12 @@ discard block |
||
128 | 128 | * @since 1.0.19 |
129 | 129 | * @return string |
130 | 130 | */ |
131 | - public function get_vat_number( $submission ) { |
|
131 | + public function get_vat_number($submission) { |
|
132 | 132 | |
133 | 133 | // Retrieve from the posted number. |
134 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
135 | - if ( ! empty( $vat_number ) ) { |
|
136 | - return wpinv_clean( $vat_number ); |
|
134 | + $vat_number = $submission->get_field('wpinv_vat_number', 'billing'); |
|
135 | + if (!empty($vat_number)) { |
|
136 | + return wpinv_clean($vat_number); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | // Retrieve from the invoice. |
@@ -147,12 +147,12 @@ discard block |
||
147 | 147 | * @since 1.0.19 |
148 | 148 | * @return string |
149 | 149 | */ |
150 | - public function get_company( $submission ) { |
|
150 | + public function get_company($submission) { |
|
151 | 151 | |
152 | 152 | // Retrieve from the posted data. |
153 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
154 | - if ( ! empty( $company ) ) { |
|
155 | - return wpinv_clean( $company ); |
|
153 | + $company = $submission->get_field('wpinv_company', 'billing'); |
|
154 | + if (!empty($company)) { |
|
155 | + return wpinv_clean($company); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | // Retrieve from the invoice. |
@@ -167,10 +167,10 @@ discard block |
||
167 | 167 | * @since 1.0.19 |
168 | 168 | * @return string |
169 | 169 | */ |
170 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
170 | + public function requires_vat($ip_in_eu, $country_in_eu) { |
|
171 | 171 | |
172 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
173 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
172 | + $prevent_b2c = wpinv_get_option('vat_prevent_b2c_purchase'); |
|
173 | + $prevent_b2c = !empty($prevent_b2c); |
|
174 | 174 | $is_eu = $ip_in_eu || $country_in_eu; |
175 | 175 | |
176 | 176 | return $prevent_b2c && $is_eu; |
@@ -182,38 +182,38 @@ discard block |
||
182 | 182 | * @param GetPaid_Payment_Form_Submission $submission |
183 | 183 | * @since 1.0.19 |
184 | 184 | */ |
185 | - public function validate_vat( $submission ) { |
|
185 | + public function validate_vat($submission) { |
|
186 | 186 | |
187 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
187 | + $in_eu = $this->is_eu_transaction($submission->country); |
|
188 | 188 | |
189 | 189 | // Abort if we are not validating vat numbers. |
190 | - if ( ! $in_eu ) { |
|
190 | + if (!$in_eu) { |
|
191 | 191 | return; |
192 | 192 | } |
193 | 193 | |
194 | 194 | // Prepare variables. |
195 | - $vat_number = $this->get_vat_number( $submission ); |
|
195 | + $vat_number = $this->get_vat_number($submission); |
|
196 | 196 | $ip_country = getpaid_get_ip_country(); |
197 | - $is_eu = $this->is_eu_country( $submission->country ); |
|
198 | - $is_ip_eu = $this->is_eu_country( $ip_country ); |
|
197 | + $is_eu = $this->is_eu_country($submission->country); |
|
198 | + $is_ip_eu = $this->is_eu_country($ip_country); |
|
199 | 199 | |
200 | 200 | // If we're preventing business to consumer purchases, |
201 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
201 | + if ($this->requires_vat($is_ip_eu, $is_eu) && empty($vat_number)) { |
|
202 | 202 | |
203 | 203 | // Ensure that a vat number has been specified. |
204 | 204 | throw new Exception( |
205 | - __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) |
|
205 | + __('Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing') |
|
206 | 206 | ); |
207 | 207 | |
208 | 208 | } |
209 | 209 | |
210 | 210 | // Abort if we are not validating vat (vat number should exist, user should be in eu and business too). |
211 | - if ( ! $in_eu ) { |
|
211 | + if (!$in_eu) { |
|
212 | 212 | return; |
213 | 213 | } |
214 | 214 | |
215 | - if ( ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
216 | - throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
215 | + if (!wpinv_validate_vat_number($vat_number, $submission->country)) { |
|
216 | + throw new Exception(__('Your VAT number is invalid', 'invoicing')); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | } |
@@ -9,32 +9,32 @@ |
||
9 | 9 | defined( 'ABSPATH' ) || exit; |
10 | 10 | |
11 | 11 | return array( |
12 | - 'AT', |
|
13 | - 'BE', |
|
14 | - 'BG', |
|
15 | - 'HR', |
|
16 | - 'CY', |
|
17 | - 'CZ', |
|
18 | - 'DK', |
|
19 | - 'EE', |
|
20 | - 'FI', |
|
21 | - 'FR', |
|
22 | - 'DE', |
|
23 | - 'GB', |
|
24 | - 'GR', |
|
25 | - 'HU', |
|
26 | - 'IE', |
|
27 | - 'IT', |
|
28 | - 'LV', |
|
29 | - 'LT', |
|
30 | - 'LU', |
|
31 | - 'MT', |
|
32 | - 'NL', |
|
33 | - 'PL', |
|
34 | - 'PT', |
|
35 | - 'RO', |
|
36 | - 'SK', |
|
37 | - 'SI', |
|
38 | - 'ES', |
|
39 | - 'SE' |
|
12 | + 'AT', |
|
13 | + 'BE', |
|
14 | + 'BG', |
|
15 | + 'HR', |
|
16 | + 'CY', |
|
17 | + 'CZ', |
|
18 | + 'DK', |
|
19 | + 'EE', |
|
20 | + 'FI', |
|
21 | + 'FR', |
|
22 | + 'DE', |
|
23 | + 'GB', |
|
24 | + 'GR', |
|
25 | + 'HU', |
|
26 | + 'IE', |
|
27 | + 'IT', |
|
28 | + 'LV', |
|
29 | + 'LT', |
|
30 | + 'LU', |
|
31 | + 'MT', |
|
32 | + 'NL', |
|
33 | + 'PL', |
|
34 | + 'PT', |
|
35 | + 'RO', |
|
36 | + 'SK', |
|
37 | + 'SI', |
|
38 | + 'ES', |
|
39 | + 'SE' |
|
40 | 40 | ); |
@@ -6,7 +6,7 @@ |
||
6 | 6 | * @version 1.0.19 |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | return array( |
12 | 12 | 'AT', |
@@ -13,233 +13,233 @@ |
||
13 | 13 | |
14 | 14 | return array( |
15 | 15 | |
16 | - 'id' => array( |
|
17 | - 'description' => __( 'Unique identifier for the item.', 'invoicing' ), |
|
18 | - 'type' => 'integer', |
|
19 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
20 | - 'readonly' => true, |
|
21 | - ), |
|
22 | - |
|
23 | - 'parent_id' => array( |
|
24 | - 'description' => __( 'Parent item ID.', 'invoicing' ), |
|
25 | - 'type' => 'integer', |
|
26 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
27 | - 'default' => 0, |
|
28 | - ), |
|
29 | - |
|
30 | - 'status' => array( |
|
31 | - 'description' => __( 'A named status for the item.', 'invoicing' ), |
|
32 | - 'type' => 'string', |
|
33 | - 'enum' => array( 'draft', 'pending', 'publish' ), |
|
34 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
35 | - 'default' => 'draft', |
|
36 | - ), |
|
37 | - |
|
38 | - 'version' => array( |
|
39 | - 'description' => __( 'Plugin version when the item was created.', 'invoicing' ), |
|
40 | - 'type' => 'string', |
|
41 | - 'context' => array( 'view', 'edit' ), |
|
42 | - 'readonly' => true, |
|
43 | - ), |
|
44 | - |
|
45 | - 'date_created' => array( |
|
46 | - 'description' => __( "The date the item was created, in the site's timezone.", 'invoicing' ), |
|
47 | - 'type' => 'string', |
|
48 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
49 | - ), |
|
50 | - |
|
51 | - 'date_created_gmt' => array( |
|
52 | - 'description' => __( 'The GMT date the item was created.', 'invoicing' ), |
|
53 | - 'type' => 'string', |
|
54 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
55 | - 'readonly' => true, |
|
56 | - ), |
|
57 | - |
|
58 | - 'date_modified' => array( |
|
59 | - 'description' => __( "The date the item was last modified, in the site's timezone.", 'invoicing' ), |
|
60 | - 'type' => 'string', |
|
61 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
62 | - 'readonly' => true, |
|
63 | - ), |
|
64 | - |
|
65 | - 'date_modified_gmt' => array( |
|
66 | - 'description' => __( 'The GMT date the item was last modified.', 'invoicing' ), |
|
67 | - 'type' => 'string', |
|
68 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
69 | - 'readonly' => true, |
|
70 | - ), |
|
71 | - |
|
72 | - 'name' => array( |
|
73 | - 'description' => __( "The item's name.", 'invoicing' ), |
|
74 | - 'type' => 'string', |
|
75 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
76 | - 'required' => true, |
|
77 | - ), |
|
78 | - |
|
79 | - 'description' => array( |
|
80 | - 'description' => __( "The item's description.", 'invoicing' ), |
|
81 | - 'type' => 'string', |
|
82 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
83 | - ), |
|
84 | - |
|
85 | - 'owner' => array( |
|
86 | - 'description' => __( 'The owner of the item (user id).', 'invoicing' ), |
|
87 | - 'type' => 'integer', |
|
88 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
89 | - ), |
|
90 | - |
|
91 | - 'price' => array( |
|
92 | - 'description' => __( 'The price of the item.', 'invoicing' ), |
|
93 | - 'type' => 'number', |
|
94 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
95 | - 'required' => true, |
|
96 | - ), |
|
97 | - |
|
98 | - 'the_price' => array( |
|
99 | - 'description' => __( 'The formatted price of the item.', 'invoicing' ), |
|
100 | - 'type' => 'string', |
|
101 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
102 | - 'readonly' => true, |
|
103 | - ), |
|
104 | - |
|
105 | - 'type' => array( |
|
106 | - 'description' => __( 'The item type.', 'invoicing' ), |
|
107 | - 'type' => 'string', |
|
108 | - 'enum' => wpinv_item_types(), |
|
109 | - 'default' => 'custom', |
|
110 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
111 | - ), |
|
112 | - |
|
113 | - 'vat_rule' => array( |
|
114 | - 'description' => __( 'VAT rule applied to the item.', 'invoicing' ), |
|
115 | - 'type' => 'string', |
|
116 | - 'enum' => array_keys( getpaid_get_tax_rules() ), |
|
117 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
118 | - ), |
|
119 | - |
|
120 | - 'vat_class' => array( |
|
121 | - 'description' => __( 'VAT class for the item.', 'invoicing' ), |
|
122 | - 'type' => 'string', |
|
123 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
124 | - 'enum' => array_keys( getpaid_get_tax_classes() ), |
|
125 | - ), |
|
126 | - |
|
127 | - 'custom_id' => array( |
|
128 | - 'description' => __( 'Custom id for the item.', 'invoicing' ), |
|
129 | - 'type' => 'string', |
|
130 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
131 | - ), |
|
16 | + 'id' => array( |
|
17 | + 'description' => __( 'Unique identifier for the item.', 'invoicing' ), |
|
18 | + 'type' => 'integer', |
|
19 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
20 | + 'readonly' => true, |
|
21 | + ), |
|
22 | + |
|
23 | + 'parent_id' => array( |
|
24 | + 'description' => __( 'Parent item ID.', 'invoicing' ), |
|
25 | + 'type' => 'integer', |
|
26 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
27 | + 'default' => 0, |
|
28 | + ), |
|
29 | + |
|
30 | + 'status' => array( |
|
31 | + 'description' => __( 'A named status for the item.', 'invoicing' ), |
|
32 | + 'type' => 'string', |
|
33 | + 'enum' => array( 'draft', 'pending', 'publish' ), |
|
34 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
35 | + 'default' => 'draft', |
|
36 | + ), |
|
37 | + |
|
38 | + 'version' => array( |
|
39 | + 'description' => __( 'Plugin version when the item was created.', 'invoicing' ), |
|
40 | + 'type' => 'string', |
|
41 | + 'context' => array( 'view', 'edit' ), |
|
42 | + 'readonly' => true, |
|
43 | + ), |
|
44 | + |
|
45 | + 'date_created' => array( |
|
46 | + 'description' => __( "The date the item was created, in the site's timezone.", 'invoicing' ), |
|
47 | + 'type' => 'string', |
|
48 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
49 | + ), |
|
50 | + |
|
51 | + 'date_created_gmt' => array( |
|
52 | + 'description' => __( 'The GMT date the item was created.', 'invoicing' ), |
|
53 | + 'type' => 'string', |
|
54 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
55 | + 'readonly' => true, |
|
56 | + ), |
|
57 | + |
|
58 | + 'date_modified' => array( |
|
59 | + 'description' => __( "The date the item was last modified, in the site's timezone.", 'invoicing' ), |
|
60 | + 'type' => 'string', |
|
61 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
62 | + 'readonly' => true, |
|
63 | + ), |
|
64 | + |
|
65 | + 'date_modified_gmt' => array( |
|
66 | + 'description' => __( 'The GMT date the item was last modified.', 'invoicing' ), |
|
67 | + 'type' => 'string', |
|
68 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
69 | + 'readonly' => true, |
|
70 | + ), |
|
71 | + |
|
72 | + 'name' => array( |
|
73 | + 'description' => __( "The item's name.", 'invoicing' ), |
|
74 | + 'type' => 'string', |
|
75 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
76 | + 'required' => true, |
|
77 | + ), |
|
78 | + |
|
79 | + 'description' => array( |
|
80 | + 'description' => __( "The item's description.", 'invoicing' ), |
|
81 | + 'type' => 'string', |
|
82 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
83 | + ), |
|
84 | + |
|
85 | + 'owner' => array( |
|
86 | + 'description' => __( 'The owner of the item (user id).', 'invoicing' ), |
|
87 | + 'type' => 'integer', |
|
88 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
89 | + ), |
|
90 | + |
|
91 | + 'price' => array( |
|
92 | + 'description' => __( 'The price of the item.', 'invoicing' ), |
|
93 | + 'type' => 'number', |
|
94 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
95 | + 'required' => true, |
|
96 | + ), |
|
97 | + |
|
98 | + 'the_price' => array( |
|
99 | + 'description' => __( 'The formatted price of the item.', 'invoicing' ), |
|
100 | + 'type' => 'string', |
|
101 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
102 | + 'readonly' => true, |
|
103 | + ), |
|
104 | + |
|
105 | + 'type' => array( |
|
106 | + 'description' => __( 'The item type.', 'invoicing' ), |
|
107 | + 'type' => 'string', |
|
108 | + 'enum' => wpinv_item_types(), |
|
109 | + 'default' => 'custom', |
|
110 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
111 | + ), |
|
112 | + |
|
113 | + 'vat_rule' => array( |
|
114 | + 'description' => __( 'VAT rule applied to the item.', 'invoicing' ), |
|
115 | + 'type' => 'string', |
|
116 | + 'enum' => array_keys( getpaid_get_tax_rules() ), |
|
117 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
118 | + ), |
|
119 | + |
|
120 | + 'vat_class' => array( |
|
121 | + 'description' => __( 'VAT class for the item.', 'invoicing' ), |
|
122 | + 'type' => 'string', |
|
123 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
124 | + 'enum' => array_keys( getpaid_get_tax_classes() ), |
|
125 | + ), |
|
126 | + |
|
127 | + 'custom_id' => array( |
|
128 | + 'description' => __( 'Custom id for the item.', 'invoicing' ), |
|
129 | + 'type' => 'string', |
|
130 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
131 | + ), |
|
132 | 132 | |
133 | - 'custom_name' => array( |
|
134 | - 'description' => __( 'Custom name for the item.', 'invoicing' ), |
|
135 | - 'type' => 'string', |
|
136 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
137 | - ), |
|
138 | - |
|
139 | - 'custom_singular_name' => array( |
|
140 | - 'description' => __( 'Custom singular name for the item.', 'invoicing' ), |
|
141 | - 'type' => 'string', |
|
142 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
143 | - ), |
|
144 | - |
|
145 | - 'is_dynamic_pricing' => array( |
|
146 | - 'description' => __( 'Whether or not customers can enter their own prices when checking out.', 'invoicing' ), |
|
147 | - 'type' => 'integer', |
|
148 | - 'enum' => array( 0, 1 ), |
|
149 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
150 | - ), |
|
151 | - |
|
152 | - 'minimum_price' => array( |
|
153 | - 'description' => __( 'For dynamic prices, this is the minimum price that a user can set.', 'invoicing' ), |
|
154 | - 'type' => 'number', |
|
155 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
156 | - ), |
|
157 | - |
|
158 | - 'is_recurring' => array( |
|
159 | - 'description' => __( 'Whether or not this is a subscription item.', 'invoicing' ), |
|
160 | - 'type' => 'integer', |
|
161 | - 'enum' => array( 0, 1 ), |
|
162 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
163 | - ), |
|
164 | - |
|
165 | - 'initial_price' => array( |
|
166 | - 'description' => __( 'The initial price of the item.', 'invoicing' ), |
|
167 | - 'type' => 'number', |
|
168 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
169 | - 'readonly' => true, |
|
170 | - ), |
|
171 | - |
|
172 | - 'the_initial_price' => array( |
|
173 | - 'description' => __( 'The formatted initial price of the item.', 'invoicing' ), |
|
174 | - 'type' => 'string', |
|
175 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
176 | - 'readonly' => true, |
|
177 | - ), |
|
178 | - |
|
179 | - 'recurring_price' => array( |
|
180 | - 'description' => __( 'The recurring price of the item.', 'invoicing' ), |
|
181 | - 'type' => 'number', |
|
182 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
183 | - 'readonly' => true, |
|
184 | - ), |
|
185 | - |
|
186 | - 'the_recurring_price' => array( |
|
187 | - 'description' => __( 'The formatted recurring price of the item.', 'invoicing' ), |
|
188 | - 'type' => 'string', |
|
189 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
190 | - 'readonly' => true, |
|
191 | - ), |
|
192 | - |
|
193 | - 'recurring_period' => array( |
|
194 | - 'description' => __( 'The recurring period for a recurring item.', 'invoicing' ), |
|
195 | - 'type' => 'string', |
|
196 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
197 | - 'enum' => array( 'D', 'W', 'M', 'Y' ), |
|
198 | - ), |
|
199 | - |
|
200 | - 'recurring_interval' => array( |
|
201 | - 'description' => __( 'The recurring interval for a subscription item.', 'invoicing' ), |
|
202 | - 'type' => 'integer', |
|
203 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
204 | - ), |
|
205 | - |
|
206 | - 'recurring_limit' => array( |
|
207 | - 'description' => __( 'The maximum number of renewals for a subscription item.', 'invoicing' ), |
|
208 | - 'type' => 'integer', |
|
209 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
210 | - ), |
|
211 | - |
|
212 | - 'is_free_trial' => array( |
|
213 | - 'description' => __( 'Whether the item has a free trial period.', 'invoicing' ), |
|
214 | - 'type' => 'integer', |
|
215 | - 'enum' => array( 0, 1 ), |
|
216 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
217 | - ), |
|
218 | - |
|
219 | - 'trial_period' => array( |
|
220 | - 'description' => __( 'The trial period.', 'invoicing' ), |
|
221 | - 'type' => 'string', |
|
222 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
223 | - 'enum' => array( 'D', 'W', 'M', 'Y' ), |
|
224 | - ), |
|
225 | - |
|
226 | - 'trial_interval' => array( |
|
227 | - 'description' => __( 'The trial interval.', 'invoicing' ), |
|
228 | - 'type' => 'integer', |
|
229 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
230 | - ), |
|
231 | - |
|
232 | - 'first_renewal_date' => array( |
|
233 | - 'description' => __( 'The first renewal date in case the item was to be bought today.', 'invoicing' ), |
|
234 | - 'type' => 'string', |
|
235 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
236 | - 'readonly' => true, |
|
237 | - ), |
|
238 | - |
|
239 | - 'edit_url' => array( |
|
240 | - 'description' => __( 'The URL to edit an item.', 'invoicing' ), |
|
241 | - 'type' => 'string', |
|
242 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
243 | - 'readonly' => true, |
|
244 | - ), |
|
133 | + 'custom_name' => array( |
|
134 | + 'description' => __( 'Custom name for the item.', 'invoicing' ), |
|
135 | + 'type' => 'string', |
|
136 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
137 | + ), |
|
138 | + |
|
139 | + 'custom_singular_name' => array( |
|
140 | + 'description' => __( 'Custom singular name for the item.', 'invoicing' ), |
|
141 | + 'type' => 'string', |
|
142 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
143 | + ), |
|
144 | + |
|
145 | + 'is_dynamic_pricing' => array( |
|
146 | + 'description' => __( 'Whether or not customers can enter their own prices when checking out.', 'invoicing' ), |
|
147 | + 'type' => 'integer', |
|
148 | + 'enum' => array( 0, 1 ), |
|
149 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
150 | + ), |
|
151 | + |
|
152 | + 'minimum_price' => array( |
|
153 | + 'description' => __( 'For dynamic prices, this is the minimum price that a user can set.', 'invoicing' ), |
|
154 | + 'type' => 'number', |
|
155 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
156 | + ), |
|
157 | + |
|
158 | + 'is_recurring' => array( |
|
159 | + 'description' => __( 'Whether or not this is a subscription item.', 'invoicing' ), |
|
160 | + 'type' => 'integer', |
|
161 | + 'enum' => array( 0, 1 ), |
|
162 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
163 | + ), |
|
164 | + |
|
165 | + 'initial_price' => array( |
|
166 | + 'description' => __( 'The initial price of the item.', 'invoicing' ), |
|
167 | + 'type' => 'number', |
|
168 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
169 | + 'readonly' => true, |
|
170 | + ), |
|
171 | + |
|
172 | + 'the_initial_price' => array( |
|
173 | + 'description' => __( 'The formatted initial price of the item.', 'invoicing' ), |
|
174 | + 'type' => 'string', |
|
175 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
176 | + 'readonly' => true, |
|
177 | + ), |
|
178 | + |
|
179 | + 'recurring_price' => array( |
|
180 | + 'description' => __( 'The recurring price of the item.', 'invoicing' ), |
|
181 | + 'type' => 'number', |
|
182 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
183 | + 'readonly' => true, |
|
184 | + ), |
|
185 | + |
|
186 | + 'the_recurring_price' => array( |
|
187 | + 'description' => __( 'The formatted recurring price of the item.', 'invoicing' ), |
|
188 | + 'type' => 'string', |
|
189 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
190 | + 'readonly' => true, |
|
191 | + ), |
|
192 | + |
|
193 | + 'recurring_period' => array( |
|
194 | + 'description' => __( 'The recurring period for a recurring item.', 'invoicing' ), |
|
195 | + 'type' => 'string', |
|
196 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
197 | + 'enum' => array( 'D', 'W', 'M', 'Y' ), |
|
198 | + ), |
|
199 | + |
|
200 | + 'recurring_interval' => array( |
|
201 | + 'description' => __( 'The recurring interval for a subscription item.', 'invoicing' ), |
|
202 | + 'type' => 'integer', |
|
203 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
204 | + ), |
|
205 | + |
|
206 | + 'recurring_limit' => array( |
|
207 | + 'description' => __( 'The maximum number of renewals for a subscription item.', 'invoicing' ), |
|
208 | + 'type' => 'integer', |
|
209 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
210 | + ), |
|
211 | + |
|
212 | + 'is_free_trial' => array( |
|
213 | + 'description' => __( 'Whether the item has a free trial period.', 'invoicing' ), |
|
214 | + 'type' => 'integer', |
|
215 | + 'enum' => array( 0, 1 ), |
|
216 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
217 | + ), |
|
218 | + |
|
219 | + 'trial_period' => array( |
|
220 | + 'description' => __( 'The trial period.', 'invoicing' ), |
|
221 | + 'type' => 'string', |
|
222 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
223 | + 'enum' => array( 'D', 'W', 'M', 'Y' ), |
|
224 | + ), |
|
225 | + |
|
226 | + 'trial_interval' => array( |
|
227 | + 'description' => __( 'The trial interval.', 'invoicing' ), |
|
228 | + 'type' => 'integer', |
|
229 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
230 | + ), |
|
231 | + |
|
232 | + 'first_renewal_date' => array( |
|
233 | + 'description' => __( 'The first renewal date in case the item was to be bought today.', 'invoicing' ), |
|
234 | + 'type' => 'string', |
|
235 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
236 | + 'readonly' => true, |
|
237 | + ), |
|
238 | + |
|
239 | + 'edit_url' => array( |
|
240 | + 'description' => __( 'The URL to edit an item.', 'invoicing' ), |
|
241 | + 'type' => 'string', |
|
242 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
243 | + 'readonly' => true, |
|
244 | + ), |
|
245 | 245 | ); |
@@ -9,237 +9,237 @@ |
||
9 | 9 | * @version 1.0.19 |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | return array( |
15 | 15 | |
16 | 16 | 'id' => array( |
17 | - 'description' => __( 'Unique identifier for the item.', 'invoicing' ), |
|
17 | + 'description' => __('Unique identifier for the item.', 'invoicing'), |
|
18 | 18 | 'type' => 'integer', |
19 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
19 | + 'context' => array('view', 'edit', 'embed'), |
|
20 | 20 | 'readonly' => true, |
21 | 21 | ), |
22 | 22 | |
23 | 23 | 'parent_id' => array( |
24 | - 'description' => __( 'Parent item ID.', 'invoicing' ), |
|
24 | + 'description' => __('Parent item ID.', 'invoicing'), |
|
25 | 25 | 'type' => 'integer', |
26 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
26 | + 'context' => array('view', 'edit', 'embed'), |
|
27 | 27 | 'default' => 0, |
28 | 28 | ), |
29 | 29 | |
30 | 30 | 'status' => array( |
31 | - 'description' => __( 'A named status for the item.', 'invoicing' ), |
|
31 | + 'description' => __('A named status for the item.', 'invoicing'), |
|
32 | 32 | 'type' => 'string', |
33 | - 'enum' => array( 'draft', 'pending', 'publish' ), |
|
34 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
33 | + 'enum' => array('draft', 'pending', 'publish'), |
|
34 | + 'context' => array('view', 'edit', 'embed'), |
|
35 | 35 | 'default' => 'draft', |
36 | 36 | ), |
37 | 37 | |
38 | 38 | 'version' => array( |
39 | - 'description' => __( 'Plugin version when the item was created.', 'invoicing' ), |
|
39 | + 'description' => __('Plugin version when the item was created.', 'invoicing'), |
|
40 | 40 | 'type' => 'string', |
41 | - 'context' => array( 'view', 'edit' ), |
|
41 | + 'context' => array('view', 'edit'), |
|
42 | 42 | 'readonly' => true, |
43 | 43 | ), |
44 | 44 | |
45 | 45 | 'date_created' => array( |
46 | - 'description' => __( "The date the item was created, in the site's timezone.", 'invoicing' ), |
|
46 | + 'description' => __("The date the item was created, in the site's timezone.", 'invoicing'), |
|
47 | 47 | 'type' => 'string', |
48 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
48 | + 'context' => array('view', 'edit', 'embed'), |
|
49 | 49 | ), |
50 | 50 | |
51 | 51 | 'date_created_gmt' => array( |
52 | - 'description' => __( 'The GMT date the item was created.', 'invoicing' ), |
|
52 | + 'description' => __('The GMT date the item was created.', 'invoicing'), |
|
53 | 53 | 'type' => 'string', |
54 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
54 | + 'context' => array('view', 'edit', 'embed'), |
|
55 | 55 | 'readonly' => true, |
56 | 56 | ), |
57 | 57 | |
58 | 58 | 'date_modified' => array( |
59 | - 'description' => __( "The date the item was last modified, in the site's timezone.", 'invoicing' ), |
|
59 | + 'description' => __("The date the item was last modified, in the site's timezone.", 'invoicing'), |
|
60 | 60 | 'type' => 'string', |
61 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
61 | + 'context' => array('view', 'edit', 'embed'), |
|
62 | 62 | 'readonly' => true, |
63 | 63 | ), |
64 | 64 | |
65 | 65 | 'date_modified_gmt' => array( |
66 | - 'description' => __( 'The GMT date the item was last modified.', 'invoicing' ), |
|
66 | + 'description' => __('The GMT date the item was last modified.', 'invoicing'), |
|
67 | 67 | 'type' => 'string', |
68 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
68 | + 'context' => array('view', 'edit', 'embed'), |
|
69 | 69 | 'readonly' => true, |
70 | 70 | ), |
71 | 71 | |
72 | 72 | 'name' => array( |
73 | - 'description' => __( "The item's name.", 'invoicing' ), |
|
73 | + 'description' => __("The item's name.", 'invoicing'), |
|
74 | 74 | 'type' => 'string', |
75 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
75 | + 'context' => array('view', 'edit', 'embed'), |
|
76 | 76 | 'required' => true, |
77 | 77 | ), |
78 | 78 | |
79 | 79 | 'description' => array( |
80 | - 'description' => __( "The item's description.", 'invoicing' ), |
|
80 | + 'description' => __("The item's description.", 'invoicing'), |
|
81 | 81 | 'type' => 'string', |
82 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
82 | + 'context' => array('view', 'edit', 'embed'), |
|
83 | 83 | ), |
84 | 84 | |
85 | 85 | 'owner' => array( |
86 | - 'description' => __( 'The owner of the item (user id).', 'invoicing' ), |
|
86 | + 'description' => __('The owner of the item (user id).', 'invoicing'), |
|
87 | 87 | 'type' => 'integer', |
88 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
88 | + 'context' => array('view', 'edit', 'embed'), |
|
89 | 89 | ), |
90 | 90 | |
91 | 91 | 'price' => array( |
92 | - 'description' => __( 'The price of the item.', 'invoicing' ), |
|
92 | + 'description' => __('The price of the item.', 'invoicing'), |
|
93 | 93 | 'type' => 'number', |
94 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
94 | + 'context' => array('view', 'edit', 'embed'), |
|
95 | 95 | 'required' => true, |
96 | 96 | ), |
97 | 97 | |
98 | 98 | 'the_price' => array( |
99 | - 'description' => __( 'The formatted price of the item.', 'invoicing' ), |
|
99 | + 'description' => __('The formatted price of the item.', 'invoicing'), |
|
100 | 100 | 'type' => 'string', |
101 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
101 | + 'context' => array('view', 'edit', 'embed'), |
|
102 | 102 | 'readonly' => true, |
103 | 103 | ), |
104 | 104 | |
105 | 105 | 'type' => array( |
106 | - 'description' => __( 'The item type.', 'invoicing' ), |
|
106 | + 'description' => __('The item type.', 'invoicing'), |
|
107 | 107 | 'type' => 'string', |
108 | 108 | 'enum' => wpinv_item_types(), |
109 | 109 | 'default' => 'custom', |
110 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
110 | + 'context' => array('view', 'edit', 'embed'), |
|
111 | 111 | ), |
112 | 112 | |
113 | 113 | 'vat_rule' => array( |
114 | - 'description' => __( 'VAT rule applied to the item.', 'invoicing' ), |
|
114 | + 'description' => __('VAT rule applied to the item.', 'invoicing'), |
|
115 | 115 | 'type' => 'string', |
116 | - 'enum' => array_keys( getpaid_get_tax_rules() ), |
|
117 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
116 | + 'enum' => array_keys(getpaid_get_tax_rules()), |
|
117 | + 'context' => array('view', 'edit', 'embed'), |
|
118 | 118 | ), |
119 | 119 | |
120 | 120 | 'vat_class' => array( |
121 | - 'description' => __( 'VAT class for the item.', 'invoicing' ), |
|
121 | + 'description' => __('VAT class for the item.', 'invoicing'), |
|
122 | 122 | 'type' => 'string', |
123 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
124 | - 'enum' => array_keys( getpaid_get_tax_classes() ), |
|
123 | + 'context' => array('view', 'edit', 'embed'), |
|
124 | + 'enum' => array_keys(getpaid_get_tax_classes()), |
|
125 | 125 | ), |
126 | 126 | |
127 | 127 | 'custom_id' => array( |
128 | - 'description' => __( 'Custom id for the item.', 'invoicing' ), |
|
128 | + 'description' => __('Custom id for the item.', 'invoicing'), |
|
129 | 129 | 'type' => 'string', |
130 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
130 | + 'context' => array('view', 'edit', 'embed'), |
|
131 | 131 | ), |
132 | 132 | |
133 | 133 | 'custom_name' => array( |
134 | - 'description' => __( 'Custom name for the item.', 'invoicing' ), |
|
134 | + 'description' => __('Custom name for the item.', 'invoicing'), |
|
135 | 135 | 'type' => 'string', |
136 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
136 | + 'context' => array('view', 'edit', 'embed'), |
|
137 | 137 | ), |
138 | 138 | |
139 | 139 | 'custom_singular_name' => array( |
140 | - 'description' => __( 'Custom singular name for the item.', 'invoicing' ), |
|
140 | + 'description' => __('Custom singular name for the item.', 'invoicing'), |
|
141 | 141 | 'type' => 'string', |
142 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
142 | + 'context' => array('view', 'edit', 'embed'), |
|
143 | 143 | ), |
144 | 144 | |
145 | 145 | 'is_dynamic_pricing' => array( |
146 | - 'description' => __( 'Whether or not customers can enter their own prices when checking out.', 'invoicing' ), |
|
146 | + 'description' => __('Whether or not customers can enter their own prices when checking out.', 'invoicing'), |
|
147 | 147 | 'type' => 'integer', |
148 | - 'enum' => array( 0, 1 ), |
|
149 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
148 | + 'enum' => array(0, 1), |
|
149 | + 'context' => array('view', 'edit', 'embed'), |
|
150 | 150 | ), |
151 | 151 | |
152 | 152 | 'minimum_price' => array( |
153 | - 'description' => __( 'For dynamic prices, this is the minimum price that a user can set.', 'invoicing' ), |
|
153 | + 'description' => __('For dynamic prices, this is the minimum price that a user can set.', 'invoicing'), |
|
154 | 154 | 'type' => 'number', |
155 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
155 | + 'context' => array('view', 'edit', 'embed'), |
|
156 | 156 | ), |
157 | 157 | |
158 | 158 | 'is_recurring' => array( |
159 | - 'description' => __( 'Whether or not this is a subscription item.', 'invoicing' ), |
|
159 | + 'description' => __('Whether or not this is a subscription item.', 'invoicing'), |
|
160 | 160 | 'type' => 'integer', |
161 | - 'enum' => array( 0, 1 ), |
|
162 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
161 | + 'enum' => array(0, 1), |
|
162 | + 'context' => array('view', 'edit', 'embed'), |
|
163 | 163 | ), |
164 | 164 | |
165 | 165 | 'initial_price' => array( |
166 | - 'description' => __( 'The initial price of the item.', 'invoicing' ), |
|
166 | + 'description' => __('The initial price of the item.', 'invoicing'), |
|
167 | 167 | 'type' => 'number', |
168 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
168 | + 'context' => array('view', 'edit', 'embed'), |
|
169 | 169 | 'readonly' => true, |
170 | 170 | ), |
171 | 171 | |
172 | 172 | 'the_initial_price' => array( |
173 | - 'description' => __( 'The formatted initial price of the item.', 'invoicing' ), |
|
173 | + 'description' => __('The formatted initial price of the item.', 'invoicing'), |
|
174 | 174 | 'type' => 'string', |
175 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
175 | + 'context' => array('view', 'edit', 'embed'), |
|
176 | 176 | 'readonly' => true, |
177 | 177 | ), |
178 | 178 | |
179 | 179 | 'recurring_price' => array( |
180 | - 'description' => __( 'The recurring price of the item.', 'invoicing' ), |
|
180 | + 'description' => __('The recurring price of the item.', 'invoicing'), |
|
181 | 181 | 'type' => 'number', |
182 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
182 | + 'context' => array('view', 'edit', 'embed'), |
|
183 | 183 | 'readonly' => true, |
184 | 184 | ), |
185 | 185 | |
186 | 186 | 'the_recurring_price' => array( |
187 | - 'description' => __( 'The formatted recurring price of the item.', 'invoicing' ), |
|
187 | + 'description' => __('The formatted recurring price of the item.', 'invoicing'), |
|
188 | 188 | 'type' => 'string', |
189 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
189 | + 'context' => array('view', 'edit', 'embed'), |
|
190 | 190 | 'readonly' => true, |
191 | 191 | ), |
192 | 192 | |
193 | 193 | 'recurring_period' => array( |
194 | - 'description' => __( 'The recurring period for a recurring item.', 'invoicing' ), |
|
194 | + 'description' => __('The recurring period for a recurring item.', 'invoicing'), |
|
195 | 195 | 'type' => 'string', |
196 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
197 | - 'enum' => array( 'D', 'W', 'M', 'Y' ), |
|
196 | + 'context' => array('view', 'edit', 'embed'), |
|
197 | + 'enum' => array('D', 'W', 'M', 'Y'), |
|
198 | 198 | ), |
199 | 199 | |
200 | 200 | 'recurring_interval' => array( |
201 | - 'description' => __( 'The recurring interval for a subscription item.', 'invoicing' ), |
|
201 | + 'description' => __('The recurring interval for a subscription item.', 'invoicing'), |
|
202 | 202 | 'type' => 'integer', |
203 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
203 | + 'context' => array('view', 'edit', 'embed'), |
|
204 | 204 | ), |
205 | 205 | |
206 | 206 | 'recurring_limit' => array( |
207 | - 'description' => __( 'The maximum number of renewals for a subscription item.', 'invoicing' ), |
|
207 | + 'description' => __('The maximum number of renewals for a subscription item.', 'invoicing'), |
|
208 | 208 | 'type' => 'integer', |
209 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
209 | + 'context' => array('view', 'edit', 'embed'), |
|
210 | 210 | ), |
211 | 211 | |
212 | 212 | 'is_free_trial' => array( |
213 | - 'description' => __( 'Whether the item has a free trial period.', 'invoicing' ), |
|
213 | + 'description' => __('Whether the item has a free trial period.', 'invoicing'), |
|
214 | 214 | 'type' => 'integer', |
215 | - 'enum' => array( 0, 1 ), |
|
216 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
215 | + 'enum' => array(0, 1), |
|
216 | + 'context' => array('view', 'edit', 'embed'), |
|
217 | 217 | ), |
218 | 218 | |
219 | 219 | 'trial_period' => array( |
220 | - 'description' => __( 'The trial period.', 'invoicing' ), |
|
220 | + 'description' => __('The trial period.', 'invoicing'), |
|
221 | 221 | 'type' => 'string', |
222 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
223 | - 'enum' => array( 'D', 'W', 'M', 'Y' ), |
|
222 | + 'context' => array('view', 'edit', 'embed'), |
|
223 | + 'enum' => array('D', 'W', 'M', 'Y'), |
|
224 | 224 | ), |
225 | 225 | |
226 | 226 | 'trial_interval' => array( |
227 | - 'description' => __( 'The trial interval.', 'invoicing' ), |
|
227 | + 'description' => __('The trial interval.', 'invoicing'), |
|
228 | 228 | 'type' => 'integer', |
229 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
229 | + 'context' => array('view', 'edit', 'embed'), |
|
230 | 230 | ), |
231 | 231 | |
232 | 232 | 'first_renewal_date' => array( |
233 | - 'description' => __( 'The first renewal date in case the item was to be bought today.', 'invoicing' ), |
|
233 | + 'description' => __('The first renewal date in case the item was to be bought today.', 'invoicing'), |
|
234 | 234 | 'type' => 'string', |
235 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
235 | + 'context' => array('view', 'edit', 'embed'), |
|
236 | 236 | 'readonly' => true, |
237 | 237 | ), |
238 | 238 | |
239 | 239 | 'edit_url' => array( |
240 | - 'description' => __( 'The URL to edit an item.', 'invoicing' ), |
|
240 | + 'description' => __('The URL to edit an item.', 'invoicing'), |
|
241 | 241 | 'type' => 'string', |
242 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
242 | + 'context' => array('view', 'edit', 'embed'), |
|
243 | 243 | 'readonly' => true, |
244 | 244 | ), |
245 | 245 | ); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Returns an array of eu states. |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * @return array |
13 | 13 | */ |
14 | 14 | function getpaid_get_eu_states() { |
15 | - return wpinv_get_data( 'eu-states' ); |
|
15 | + return wpinv_get_data('eu-states'); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | /** |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @return bool |
22 | 22 | */ |
23 | -function getpaid_is_eu_state( $country ) { |
|
24 | - return ! empty( $country ) && in_array( strtoupper( $country ), getpaid_get_eu_states() ) ? true : false; |
|
23 | +function getpaid_is_eu_state($country) { |
|
24 | + return !empty($country) && in_array(strtoupper($country), getpaid_get_eu_states()) ? true : false; |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @return array |
31 | 31 | */ |
32 | 32 | function getpaid_get_gst_states() { |
33 | - return array( 'AU', 'NZ', 'CA', 'CN' ); |
|
33 | + return array('AU', 'NZ', 'CA', 'CN'); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @return bool |
40 | 40 | */ |
41 | -function getpaid_is_gst_country( $country ) { |
|
42 | - return ! empty( $country ) && in_array( strtoupper( $country ), getpaid_get_gst_states() ) ? true : false; |
|
41 | +function getpaid_is_gst_country($country) { |
|
42 | + return !empty($country) && in_array(strtoupper($country), getpaid_get_gst_states()) ? true : false; |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | */ |
50 | 50 | function wpinv_use_taxes() { |
51 | 51 | |
52 | - $ret = wpinv_get_option( 'enable_taxes', false ); |
|
53 | - return (bool) apply_filters( 'wpinv_use_taxes', ! empty( $ret ) ); |
|
52 | + $ret = wpinv_get_option('enable_taxes', false); |
|
53 | + return (bool) apply_filters('wpinv_use_taxes', !empty($ret)); |
|
54 | 54 | |
55 | 55 | } |
56 | 56 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @param WPInv_Invoice $invoice |
61 | 61 | * @return bool |
62 | 62 | */ |
63 | -function wpinv_is_invoice_taxable( $invoice ) { |
|
63 | +function wpinv_is_invoice_taxable($invoice) { |
|
64 | 64 | return $invoice->is_taxable(); |
65 | 65 | } |
66 | 66 | |
@@ -70,11 +70,11 @@ discard block |
||
70 | 70 | * @param string $country |
71 | 71 | * @return bool |
72 | 72 | */ |
73 | -function wpinv_is_country_taxable( $country ) { |
|
74 | - $is_eu = getpaid_is_eu_state( $country ); |
|
75 | - $is_exempt = $is_eu && $country == wpinv_is_base_country( $country ) && wpinv_same_country_exempt_vat(); |
|
73 | +function wpinv_is_country_taxable($country) { |
|
74 | + $is_eu = getpaid_is_eu_state($country); |
|
75 | + $is_exempt = $is_eu && $country == wpinv_is_base_country($country) && wpinv_same_country_exempt_vat(); |
|
76 | 76 | |
77 | - return (bool) apply_filters( 'wpinv_is_country_taxable', ! $is_exempt, $country ); |
|
77 | + return (bool) apply_filters('wpinv_is_country_taxable', !$is_exempt, $country); |
|
78 | 78 | |
79 | 79 | } |
80 | 80 | |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @param WPInv_Item|GetPaid_Form_Item $item |
85 | 85 | * @return bool |
86 | 86 | */ |
87 | -function wpinv_is_item_taxable( $item ) { |
|
87 | +function wpinv_is_item_taxable($item) { |
|
88 | 88 | return '_exempt' != $item->get_vat_rule(); |
89 | 89 | } |
90 | 90 | |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | * @return bool |
95 | 95 | */ |
96 | 96 | function wpinv_use_store_address_as_tax_base() { |
97 | - $use_base = wpinv_get_option( 'tax_base', 'billing' ) == 'base'; |
|
98 | - return (bool) apply_filters( 'wpinv_use_store_address_as_tax_base', $use_base ); |
|
97 | + $use_base = wpinv_get_option('tax_base', 'billing') == 'base'; |
|
98 | + return (bool) apply_filters('wpinv_use_store_address_as_tax_base', $use_base); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | * @return bool |
105 | 105 | */ |
106 | 106 | function wpinv_prices_include_tax() { |
107 | - $is_inclusive = wpinv_get_option( 'prices_include_tax', 'no' ) == 'yes'; |
|
108 | - return (bool) apply_filters( 'wpinv_prices_include_tax', $is_inclusive ); |
|
107 | + $is_inclusive = wpinv_get_option('prices_include_tax', 'no') == 'yes'; |
|
108 | + return (bool) apply_filters('wpinv_prices_include_tax', $is_inclusive); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | * @return bool |
115 | 115 | */ |
116 | 116 | function wpinv_round_tax_per_tax_rate() { |
117 | - $subtotal_rounding = wpinv_get_option( 'tax_subtotal_rounding', 1 ); |
|
118 | - return (bool) apply_filters( 'wpinv_round_tax_per_tax_rate', empty( $subtotal_rounding ) ); |
|
117 | + $subtotal_rounding = wpinv_get_option('tax_subtotal_rounding', 1); |
|
118 | + return (bool) apply_filters('wpinv_round_tax_per_tax_rate', empty($subtotal_rounding)); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @return bool |
125 | 125 | */ |
126 | 126 | function wpinv_display_individual_tax_rates() { |
127 | - $individual = wpinv_get_option( 'tax_display_totals', 'single' ) == 'individual'; |
|
128 | - return (bool) apply_filters( 'wpinv_display_individual_tax_rates', $individual ); |
|
127 | + $individual = wpinv_get_option('tax_display_totals', 'single') == 'individual'; |
|
128 | + return (bool) apply_filters('wpinv_display_individual_tax_rates', $individual); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | * @return float |
135 | 135 | */ |
136 | 136 | function wpinv_get_default_tax_rate() { |
137 | - $rate = wpinv_get_option( 'tax_rate', false ); |
|
138 | - return (float) apply_filters( 'wpinv_get_default_tax_rate', floatval( $rate ) ); |
|
137 | + $rate = wpinv_get_option('tax_rate', false); |
|
138 | + return (float) apply_filters('wpinv_get_default_tax_rate', floatval($rate)); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @return bool |
145 | 145 | */ |
146 | 146 | function wpinv_same_country_exempt_vat() { |
147 | - return 'no' == wpinv_get_option( 'vat_same_country_rule' ); |
|
147 | + return 'no' == wpinv_get_option('vat_same_country_rule'); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -164,28 +164,28 @@ discard block |
||
164 | 164 | * @param string $state |
165 | 165 | * @return array |
166 | 166 | */ |
167 | -function getpaid_get_item_tax_rates( $item, $country = '', $state = '' ) { |
|
167 | +function getpaid_get_item_tax_rates($item, $country = '', $state = '') { |
|
168 | 168 | |
169 | 169 | // Abort if the item is not taxable. |
170 | - if ( ! wpinv_is_item_taxable( $item ) ) { |
|
170 | + if (!wpinv_is_item_taxable($item)) { |
|
171 | 171 | return array(); |
172 | 172 | } |
173 | 173 | |
174 | 174 | // Maybe use the store address. |
175 | - if ( wpinv_use_store_address_as_tax_base() ) { |
|
175 | + if (wpinv_use_store_address_as_tax_base()) { |
|
176 | 176 | $country = wpinv_get_default_country(); |
177 | 177 | $state = wpinv_get_default_state(); |
178 | 178 | } |
179 | 179 | |
180 | 180 | // Retrieve tax rates. |
181 | - $tax_rates = GetPaid_Tax::get_address_tax_rates( $country, $state ); |
|
181 | + $tax_rates = GetPaid_Tax::get_address_tax_rates($country, $state); |
|
182 | 182 | |
183 | 183 | // Fallback to the default tax rates if non were found. |
184 | - if ( empty( $tax_rates ) ) { |
|
184 | + if (empty($tax_rates)) { |
|
185 | 185 | $tax_rates = GetPaid_Tax::get_default_tax_rates(); |
186 | 186 | } |
187 | 187 | |
188 | - return apply_filters( 'getpaid_get_item_tax_rates', $tax_rates, $item, $country, $state ); |
|
188 | + return apply_filters('getpaid_get_item_tax_rates', $tax_rates, $item, $country, $state); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
@@ -195,23 +195,23 @@ discard block |
||
195 | 195 | * @param array $rates |
196 | 196 | * @return array |
197 | 197 | */ |
198 | -function getpaid_filter_item_tax_rates( $item, $rates ) { |
|
198 | +function getpaid_filter_item_tax_rates($item, $rates) { |
|
199 | 199 | |
200 | 200 | $tax_class = $item->get_vat_class(); |
201 | 201 | |
202 | - foreach ( $rates as $i => $rate ) { |
|
202 | + foreach ($rates as $i => $rate) { |
|
203 | 203 | |
204 | - if ( $tax_class == '_reduced' ) { |
|
205 | - $rates[ $i ]['rate'] = empty( $rate['reduced_rate'] ) ? 0 : $rate['reduced_rate']; |
|
204 | + if ($tax_class == '_reduced') { |
|
205 | + $rates[$i]['rate'] = empty($rate['reduced_rate']) ? 0 : $rate['reduced_rate']; |
|
206 | 206 | } |
207 | 207 | |
208 | - if ( $tax_class == '_exempt' ) { |
|
209 | - $rates[ $i ]['rate'] = 0; |
|
208 | + if ($tax_class == '_exempt') { |
|
209 | + $rates[$i]['rate'] = 0; |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | } |
213 | 213 | |
214 | - return apply_filters( 'getpaid_filter_item_tax_rates', $rates, $item ); |
|
214 | + return apply_filters('getpaid_filter_item_tax_rates', $rates, $item); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
@@ -221,12 +221,12 @@ discard block |
||
221 | 221 | * @param array $rates |
222 | 222 | * @return array |
223 | 223 | */ |
224 | -function getpaid_calculate_item_taxes( $amount, $rates ) { |
|
224 | +function getpaid_calculate_item_taxes($amount, $rates) { |
|
225 | 225 | |
226 | 226 | $is_inclusive = wpinv_prices_include_tax(); |
227 | - $taxes = GetPaid_Tax::calc_tax( $amount, $rates, $is_inclusive ); |
|
227 | + $taxes = GetPaid_Tax::calc_tax($amount, $rates, $is_inclusive); |
|
228 | 228 | |
229 | - return apply_filters( 'getpaid_calculate_taxes', $taxes, $amount, $rates ); |
|
229 | + return apply_filters('getpaid_calculate_taxes', $taxes, $amount, $rates); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -238,17 +238,17 @@ discard block |
||
238 | 238 | * @param float $recurring_tax_amount |
239 | 239 | * @return array |
240 | 240 | */ |
241 | -function getpaid_prepare_item_tax( $item, $tax_name, $tax_amount, $recurring_tax_amount ) { |
|
241 | +function getpaid_prepare_item_tax($item, $tax_name, $tax_amount, $recurring_tax_amount) { |
|
242 | 242 | |
243 | - $initial_tax = $tax_amount; |
|
243 | + $initial_tax = $tax_amount; |
|
244 | 244 | $recurring_tax = 0; |
245 | 245 | |
246 | - if ( $item->is_recurring() ) { |
|
246 | + if ($item->is_recurring()) { |
|
247 | 247 | $recurring_tax = $recurring_tax_amount; |
248 | 248 | } |
249 | 249 | |
250 | 250 | return array( |
251 | - 'name' => sanitize_text_field( $tax_name ), |
|
251 | + 'name' => sanitize_text_field($tax_name), |
|
252 | 252 | 'initial_tax' => $initial_tax, |
253 | 253 | 'recurring_tax' => $recurring_tax, |
254 | 254 | ); |
@@ -261,8 +261,8 @@ discard block |
||
261 | 261 | * @param string $vat_number |
262 | 262 | * @return string |
263 | 263 | */ |
264 | -function wpinv_sanitize_vat_number( $vat_number ) { |
|
265 | - return str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) ); |
|
264 | +function wpinv_sanitize_vat_number($vat_number) { |
|
265 | + return str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number))); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -271,22 +271,22 @@ discard block |
||
271 | 271 | * @param string $vat_number |
272 | 272 | * @return bool |
273 | 273 | */ |
274 | -function wpinv_regex_validate_vat_number( $vat_number ) { |
|
274 | +function wpinv_regex_validate_vat_number($vat_number) { |
|
275 | 275 | |
276 | - $country = substr( $vat_number, 0, 2 ); |
|
277 | - $vatin = substr( $vat_number, 2 ); |
|
278 | - $regexes = wpinv_get_data( 'vat-number-regexes' ); |
|
276 | + $country = substr($vat_number, 0, 2); |
|
277 | + $vatin = substr($vat_number, 2); |
|
278 | + $regexes = wpinv_get_data('vat-number-regexes'); |
|
279 | 279 | |
280 | - if ( isset( $regexes[ $country ] ) ) { |
|
280 | + if (isset($regexes[$country])) { |
|
281 | 281 | |
282 | - $regex = $regexes[ $country ]; |
|
282 | + $regex = $regexes[$country]; |
|
283 | 283 | $regex = '/^(?:' . $regex . ')$/'; |
284 | - return 1 === preg_match( $regex, $vatin ); |
|
284 | + return 1 === preg_match($regex, $vatin); |
|
285 | 285 | |
286 | 286 | } |
287 | 287 | |
288 | 288 | // Not an EU state, use filters to validate the number. |
289 | - return apply_filters( 'wpinv_regex_validate_vat_number', true, $vat_number ); |
|
289 | + return apply_filters('wpinv_regex_validate_vat_number', true, $vat_number); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
@@ -295,29 +295,29 @@ discard block |
||
295 | 295 | * @param string $vat_number |
296 | 296 | * @return bool |
297 | 297 | */ |
298 | -function wpinv_vies_validate_vat_number( $vat_number ) { |
|
298 | +function wpinv_vies_validate_vat_number($vat_number) { |
|
299 | 299 | |
300 | - $country = substr( $vat_number, 0, 2 ); |
|
301 | - $vatin = substr( $vat_number, 2 ); |
|
300 | + $country = substr($vat_number, 0, 2); |
|
301 | + $vatin = substr($vat_number, 2); |
|
302 | 302 | |
303 | 303 | $url = add_query_arg( |
304 | 304 | array( |
305 | - 'ms' => urlencode( $country ), |
|
306 | - 'iso' => urlencode( $country ), |
|
307 | - 'vat' => urlencode( $vatin ), |
|
305 | + 'ms' => urlencode($country), |
|
306 | + 'iso' => urlencode($country), |
|
307 | + 'vat' => urlencode($vatin), |
|
308 | 308 | ), |
309 | 309 | 'http://ec.europa.eu/taxation_customs/vies/viesquer.do' |
310 | 310 | ); |
311 | 311 | |
312 | - $response = wp_remote_get( $url ); |
|
313 | - $response = wp_remote_retrieve_body( $response ); |
|
312 | + $response = wp_remote_get($url); |
|
313 | + $response = wp_remote_retrieve_body($response); |
|
314 | 314 | |
315 | 315 | // Fallback gracefully if the VIES website is down. |
316 | - if ( empty( $response ) ) { |
|
316 | + if (empty($response)) { |
|
317 | 317 | return true; |
318 | 318 | } |
319 | 319 | |
320 | - return 1 !== preg_match( '/invalid VAT number/i', $response ); |
|
320 | + return 1 !== preg_match('/invalid VAT number/i', $response); |
|
321 | 321 | |
322 | 322 | } |
323 | 323 | |
@@ -328,23 +328,23 @@ discard block |
||
328 | 328 | * @param string $country |
329 | 329 | * @return bool |
330 | 330 | */ |
331 | -function wpinv_validate_vat_number( $vat_number, $country ) { |
|
331 | +function wpinv_validate_vat_number($vat_number, $country) { |
|
332 | 332 | |
333 | 333 | // Abort if we are not validating this. |
334 | - if ( ! wpinv_should_validate_vat_number() || empty( $vat_number ) ) { |
|
334 | + if (!wpinv_should_validate_vat_number() || empty($vat_number)) { |
|
335 | 335 | return true; |
336 | 336 | } |
337 | 337 | |
338 | 338 | // In case the vat number does not have a country code... |
339 | - $vat_number = wpinv_sanitize_vat_number( $vat_number ); |
|
340 | - $_country = substr( $vat_number, 0, 2 ); |
|
341 | - $_country = $_country == wpinv_country_name( $_country ); |
|
339 | + $vat_number = wpinv_sanitize_vat_number($vat_number); |
|
340 | + $_country = substr($vat_number, 0, 2); |
|
341 | + $_country = $_country == wpinv_country_name($_country); |
|
342 | 342 | |
343 | - if ( $_country ) { |
|
344 | - $vat_number = strtoupper( $country ) . $vat_number; |
|
343 | + if ($_country) { |
|
344 | + $vat_number = strtoupper($country) . $vat_number; |
|
345 | 345 | } |
346 | 346 | |
347 | - return wpinv_regex_validate_vat_number( $vat_number ) && wpinv_vies_validate_vat_number( $vat_number ); |
|
347 | + return wpinv_regex_validate_vat_number($vat_number) && wpinv_vies_validate_vat_number($vat_number); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | /** |
@@ -353,40 +353,40 @@ discard block |
||
353 | 353 | * @return bool |
354 | 354 | */ |
355 | 355 | function wpinv_should_validate_vat_number() { |
356 | - $validate = wpinv_get_option( 'validate_vat_number' ); |
|
357 | - return ! empty( $validate ); |
|
356 | + $validate = wpinv_get_option('validate_vat_number'); |
|
357 | + return !empty($validate); |
|
358 | 358 | } |
359 | 359 | |
360 | -function wpinv_sales_tax_for_year( $year = null ) { |
|
361 | - return wpinv_price( wpinv_format_amount( wpinv_get_sales_tax_for_year( $year ) ) ); |
|
360 | +function wpinv_sales_tax_for_year($year = null) { |
|
361 | + return wpinv_price(wpinv_format_amount(wpinv_get_sales_tax_for_year($year))); |
|
362 | 362 | } |
363 | 363 | |
364 | -function wpinv_get_sales_tax_for_year( $year = null ) { |
|
364 | +function wpinv_get_sales_tax_for_year($year = null) { |
|
365 | 365 | global $wpdb; |
366 | 366 | |
367 | 367 | // Start at zero |
368 | 368 | $tax = 0; |
369 | 369 | |
370 | - if ( ! empty( $year ) ) { |
|
370 | + if (!empty($year)) { |
|
371 | 371 | $args = array( |
372 | 372 | 'post_type' => 'wpi_invoice', |
373 | - 'post_status' => array( 'publish' ), |
|
373 | + 'post_status' => array('publish'), |
|
374 | 374 | 'posts_per_page' => -1, |
375 | 375 | 'year' => $year, |
376 | 376 | 'fields' => 'ids' |
377 | 377 | ); |
378 | 378 | |
379 | - $payments = get_posts( $args ); |
|
380 | - $payment_ids = implode( ',', $payments ); |
|
379 | + $payments = get_posts($args); |
|
380 | + $payment_ids = implode(',', $payments); |
|
381 | 381 | |
382 | - if ( count( $payments ) > 0 ) { |
|
382 | + if (count($payments) > 0) { |
|
383 | 383 | $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )"; |
384 | - $tax = $wpdb->get_var( $sql ); |
|
384 | + $tax = $wpdb->get_var($sql); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | } |
388 | 388 | |
389 | - return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year ); |
|
389 | + return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | function wpinv_is_cart_taxed() { |
@@ -395,33 +395,33 @@ discard block |
||
395 | 395 | |
396 | 396 | function wpinv_prices_show_tax_on_checkout() { |
397 | 397 | return false; // TODO |
398 | - $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
398 | + $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
399 | 399 | |
400 | - return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret ); |
|
400 | + return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | function wpinv_display_tax_rate() { |
404 | - $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false ); |
|
404 | + $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false); |
|
405 | 405 | |
406 | - return apply_filters( 'wpinv_display_tax_rate', $ret ); |
|
406 | + return apply_filters('wpinv_display_tax_rate', $ret); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | function wpinv_cart_needs_tax_address_fields() { |
410 | - if( !wpinv_is_cart_taxed() ) |
|
410 | + if (!wpinv_is_cart_taxed()) |
|
411 | 411 | return false; |
412 | 412 | |
413 | - return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' ); |
|
413 | + return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields'); |
|
414 | 414 | } |
415 | 415 | |
416 | -function wpinv_item_is_tax_exclusive( $item_id = 0 ) { |
|
417 | - $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false ); |
|
418 | - return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id ); |
|
416 | +function wpinv_item_is_tax_exclusive($item_id = 0) { |
|
417 | + $ret = (bool) get_post_meta($item_id, '_wpinv_tax_exclusive', false); |
|
418 | + return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id); |
|
419 | 419 | } |
420 | 420 | |
421 | -function wpinv_currency_decimal_filter( $decimals = 2 ) { |
|
421 | +function wpinv_currency_decimal_filter($decimals = 2) { |
|
422 | 422 | $currency = wpinv_get_currency(); |
423 | 423 | |
424 | - switch ( $currency ) { |
|
424 | + switch ($currency) { |
|
425 | 425 | case 'RIAL' : |
426 | 426 | case 'JPY' : |
427 | 427 | case 'TWD' : |
@@ -430,13 +430,13 @@ discard block |
||
430 | 430 | break; |
431 | 431 | } |
432 | 432 | |
433 | - return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency ); |
|
433 | + return apply_filters('wpinv_currency_decimal_count', $decimals, $currency); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | function wpinv_tax_amount() { |
437 | 437 | $output = 0.00; |
438 | 438 | |
439 | - return apply_filters( 'wpinv_tax_amount', $output ); |
|
439 | + return apply_filters('wpinv_tax_amount', $output); |
|
440 | 440 | } |
441 | 441 | |
442 | 442 | /** |
@@ -444,25 +444,25 @@ discard block |
||
444 | 444 | * |
445 | 445 | * @param string|bool|null $vat_rule |
446 | 446 | */ |
447 | -function getpaid_filter_vat_rule( $vat_rule ) { |
|
447 | +function getpaid_filter_vat_rule($vat_rule) { |
|
448 | 448 | |
449 | - if ( empty( $vat_rule ) ) { |
|
449 | + if (empty($vat_rule)) { |
|
450 | 450 | return 'digital'; |
451 | 451 | } |
452 | 452 | |
453 | 453 | return $vat_rule; |
454 | 454 | } |
455 | -add_filter( 'wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule' ); |
|
455 | +add_filter('wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule'); |
|
456 | 456 | |
457 | 457 | /** |
458 | 458 | * Filters the VAT class to ensure that each item has a VAT class. |
459 | 459 | * |
460 | 460 | * @param string|bool|null $vat_rule |
461 | 461 | */ |
462 | -function getpaid_filter_vat_class( $vat_class ) { |
|
463 | - return empty( $vat_class ) ? '_standard' : $vat_class; |
|
462 | +function getpaid_filter_vat_class($vat_class) { |
|
463 | + return empty($vat_class) ? '_standard' : $vat_class; |
|
464 | 464 | } |
465 | -add_filter( 'wpinv_get_item_vat_class', 'getpaid_filter_vat_class' ); |
|
465 | +add_filter('wpinv_get_item_vat_class', 'getpaid_filter_vat_class'); |
|
466 | 466 | |
467 | 467 | /** |
468 | 468 | * Returns a list of all tax classes. |
@@ -474,9 +474,9 @@ discard block |
||
474 | 474 | return apply_filters( |
475 | 475 | 'getpaid_tax_classes', |
476 | 476 | array( |
477 | - '_standard' => __( 'Standard Tax Rate', 'invoicing' ), |
|
478 | - '_reduced' => __( 'Reduced Tax Rate', 'invoicing' ), |
|
479 | - '_exempt' => __( 'Tax Exempt', 'invoicing' ), |
|
477 | + '_standard' => __('Standard Tax Rate', 'invoicing'), |
|
478 | + '_reduced' => __('Reduced Tax Rate', 'invoicing'), |
|
479 | + '_exempt' => __('Tax Exempt', 'invoicing'), |
|
480 | 480 | ) |
481 | 481 | ); |
482 | 482 | |
@@ -492,8 +492,8 @@ discard block |
||
492 | 492 | return apply_filters( |
493 | 493 | 'getpaid_tax_rules', |
494 | 494 | array( |
495 | - 'physical' => __( 'Physical Item', 'invoicing' ), |
|
496 | - 'digital' => __( 'Digital Item', 'invoicing' ), |
|
495 | + 'physical' => __('Physical Item', 'invoicing'), |
|
496 | + 'digital' => __('Digital Item', 'invoicing'), |
|
497 | 497 | ) |
498 | 498 | ); |
499 | 499 | |
@@ -505,15 +505,15 @@ discard block |
||
505 | 505 | * @param string $tax_class |
506 | 506 | * @return string |
507 | 507 | */ |
508 | -function getpaid_get_tax_class_label( $tax_class ) { |
|
508 | +function getpaid_get_tax_class_label($tax_class) { |
|
509 | 509 | |
510 | 510 | $classes = getpaid_get_tax_classes(); |
511 | 511 | |
512 | - if ( isset( $classes[ $tax_class ] ) ) { |
|
513 | - return sanitize_text_field( $classes[ $tax_class ] ); |
|
512 | + if (isset($classes[$tax_class])) { |
|
513 | + return sanitize_text_field($classes[$tax_class]); |
|
514 | 514 | } |
515 | 515 | |
516 | - return sanitize_text_field( $tax_class ); |
|
516 | + return sanitize_text_field($tax_class); |
|
517 | 517 | |
518 | 518 | } |
519 | 519 | |
@@ -523,14 +523,14 @@ discard block |
||
523 | 523 | * @param string $tax_rule |
524 | 524 | * @return string |
525 | 525 | */ |
526 | -function getpaid_get_tax_rule_label( $tax_rule ) { |
|
526 | +function getpaid_get_tax_rule_label($tax_rule) { |
|
527 | 527 | |
528 | 528 | $rules = getpaid_get_tax_rules(); |
529 | 529 | |
530 | - if ( isset( $rules[ $tax_rule ] ) ) { |
|
531 | - return sanitize_text_field( $rules[ $tax_rule ] ); |
|
530 | + if (isset($rules[$tax_rule])) { |
|
531 | + return sanitize_text_field($rules[$tax_rule]); |
|
532 | 532 | } |
533 | 533 | |
534 | - return sanitize_text_field( $tax_rule ); |
|
534 | + return sanitize_text_field($tax_rule); |
|
535 | 535 | |
536 | 536 | } |