@@ -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 refresh prices class |
@@ -23,29 +23,29 @@ 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 | $this->response = array( |
29 | 29 | 'submission_id' => $submission->id, |
30 | 30 | 'has_recurring' => $submission->has_recurring, |
31 | 31 | 'has_subscription_group' => $submission->has_subscription_group(), |
32 | 32 | 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
33 | - 'is_free' => ! $submission->should_collect_payment_details(), |
|
33 | + 'is_free' => !$submission->should_collect_payment_details(), |
|
34 | 34 | ); |
35 | 35 | |
36 | 36 | $payment_form = $submission->get_payment_form(); |
37 | - if ( ! empty( $payment_form->invoice ) ) { |
|
37 | + if (!empty($payment_form->invoice)) { |
|
38 | 38 | $this->response['invoice'] = $payment_form->invoice->get_id(); |
39 | 39 | } |
40 | 40 | |
41 | - $this->add_totals( $submission ); |
|
42 | - $this->add_texts( $submission ); |
|
43 | - $this->add_items( $submission ); |
|
44 | - $this->add_fees( $submission ); |
|
45 | - $this->add_discounts( $submission ); |
|
46 | - $this->add_taxes( $submission ); |
|
47 | - $this->add_gateways( $submission ); |
|
48 | - $this->add_data( $submission ); |
|
41 | + $this->add_totals($submission); |
|
42 | + $this->add_texts($submission); |
|
43 | + $this->add_items($submission); |
|
44 | + $this->add_fees($submission); |
|
45 | + $this->add_discounts($submission); |
|
46 | + $this->add_taxes($submission); |
|
47 | + $this->add_gateways($submission); |
|
48 | + $this->add_data($submission); |
|
49 | 49 | |
50 | 50 | } |
51 | 51 | |
@@ -54,30 +54,30 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @param GetPaid_Payment_Form_Submission $submission |
56 | 56 | */ |
57 | - public function add_totals( $submission ) { |
|
57 | + public function add_totals($submission) { |
|
58 | 58 | |
59 | 59 | $this->response = array_merge( |
60 | 60 | $this->response, |
61 | 61 | array( |
62 | 62 | |
63 | 63 | 'totals' => array( |
64 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
65 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
66 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
67 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
68 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
69 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
64 | + 'subtotal' => $submission->format_amount($submission->get_subtotal()), |
|
65 | + 'discount' => $submission->format_amount($submission->get_discount()), |
|
66 | + 'fees' => $submission->format_amount($submission->get_fee()), |
|
67 | + 'tax' => $submission->format_amount($submission->get_tax()), |
|
68 | + 'total' => $submission->format_amount($submission->get_total()), |
|
69 | + 'raw_total' => html_entity_decode(sanitize_text_field($submission->format_amount($submission->get_total())), ENT_QUOTES), |
|
70 | 70 | ), |
71 | 71 | |
72 | 72 | 'recurring' => array( |
73 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
74 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
75 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
76 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
77 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
73 | + 'subtotal' => $submission->format_amount($submission->get_recurring_subtotal()), |
|
74 | + 'discount' => $submission->format_amount($submission->get_recurring_discount()), |
|
75 | + 'fees' => $submission->format_amount($submission->get_recurring_fee()), |
|
76 | + 'tax' => $submission->format_amount($submission->get_recurring_tax()), |
|
77 | + 'total' => $submission->format_amount($submission->get_recurring_total()), |
|
78 | 78 | ), |
79 | 79 | |
80 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
80 | + 'initial_amt' => wpinv_round_amount($submission->get_total(), null, true), |
|
81 | 81 | 'currency' => $submission->get_currency(), |
82 | 82 | |
83 | 83 | ) |
@@ -90,53 +90,53 @@ discard block |
||
90 | 90 | * |
91 | 91 | * @param GetPaid_Payment_Form_Submission $submission |
92 | 92 | */ |
93 | - public function add_texts( $submission ) { |
|
93 | + public function add_texts($submission) { |
|
94 | 94 | |
95 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
96 | - $groups = getpaid_get_subscription_groups( $submission ); |
|
95 | + $payable = $submission->format_amount($submission->get_total()); |
|
96 | + $groups = getpaid_get_subscription_groups($submission); |
|
97 | 97 | |
98 | - if ( $submission->has_recurring && 2 > count( $groups ) ) { |
|
98 | + if ($submission->has_recurring && 2 > count($groups)) { |
|
99 | 99 | |
100 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
101 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
102 | - $main_item = reset( $groups ); |
|
100 | + $recurring = new WPInv_Item($submission->has_recurring); |
|
101 | + $period = getpaid_get_subscription_period_label($recurring->get_recurring_period(true), $recurring->get_recurring_interval(), ''); |
|
102 | + $main_item = reset($groups); |
|
103 | 103 | |
104 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
104 | + if ($submission->get_total() == $submission->get_recurring_total()) { |
|
105 | 105 | $payable = "$payable / $period"; |
106 | - } elseif ( $main_item ) { |
|
106 | + } elseif ($main_item) { |
|
107 | 107 | |
108 | - $main_item = reset( $main_item ); |
|
108 | + $main_item = reset($main_item); |
|
109 | 109 | |
110 | 110 | // Calculate the next renewal date. |
111 | - $_period = $main_item->get_recurring_period( true ); |
|
111 | + $_period = $main_item->get_recurring_period(true); |
|
112 | 112 | $_interval = $main_item->get_recurring_interval(); |
113 | 113 | |
114 | 114 | // If the subscription item has a trial period... |
115 | - if ( $main_item->has_free_trial() ) { |
|
116 | - $_period = $main_item->get_trial_period( true ); |
|
115 | + if ($main_item->has_free_trial()) { |
|
116 | + $_period = $main_item->get_trial_period(true); |
|
117 | 117 | $_interval = $main_item->get_trial_interval(); |
118 | 118 | } |
119 | 119 | |
120 | 120 | $payable = sprintf( |
121 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
122 | - $submission->format_amount( $submission->get_total() ), |
|
123 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
121 | + __('%1$s (renews at %2$s / %3$s)', 'invoicing'), |
|
122 | + $submission->format_amount($submission->get_total()), |
|
123 | + $submission->format_amount($submission->get_recurring_total()), |
|
124 | 124 | $period |
125 | 125 | ); |
126 | 126 | |
127 | 127 | $payable .= sprintf( |
128 | 128 | '<small class="text-muted form-text">%s</small>', |
129 | 129 | sprintf( |
130 | - __( 'First renewal on %s', 'invoicing' ), |
|
131 | - getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) ) |
|
130 | + __('First renewal on %s', 'invoicing'), |
|
131 | + getpaid_format_date(date('Y-m-d H:i:s', strtotime("+$_interval $_period", current_time('timestamp')))) |
|
132 | 132 | ) |
133 | 133 | ); |
134 | 134 | |
135 | 135 | } else { |
136 | 136 | $payable = sprintf( |
137 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
138 | - $submission->format_amount( $submission->get_total() ), |
|
139 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
137 | + __('%1$s (renews at %2$s / %3$s)', 'invoicing'), |
|
138 | + $submission->format_amount($submission->get_total()), |
|
139 | + $submission->format_amount($submission->get_recurring_total()), |
|
140 | 140 | $period |
141 | 141 | ); |
142 | 142 | } |
@@ -146,19 +146,19 @@ discard block |
||
146 | 146 | '.getpaid-checkout-total-payable' => $payable, |
147 | 147 | ); |
148 | 148 | |
149 | - foreach ( $submission->get_items() as $item ) { |
|
149 | + foreach ($submission->get_items() as $item) { |
|
150 | 150 | $item_id = $item->get_id(); |
151 | - $initial_price = $submission->format_amount( $item->get_sub_total() - $item->item_discount ); |
|
152 | - $recurring_price = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount ); |
|
153 | - $texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
154 | - $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) ); |
|
151 | + $initial_price = $submission->format_amount($item->get_sub_total() - $item->item_discount); |
|
152 | + $recurring_price = $submission->format_amount($item->get_recurring_sub_total() - $item->recurring_item_discount); |
|
153 | + $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text($item, $submission->get_currency(), $initial_price, $recurring_price); |
|
154 | + $texts[".item-$item_id .getpaid-mobile-item-subtotal"] = sprintf(__('Subtotal: %s', 'invoicing'), $submission->format_amount($item->get_sub_total())); |
|
155 | 155 | |
156 | - if ( $item->get_quantity() == 1 ) { |
|
157 | - $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = ''; |
|
156 | + if ($item->get_quantity() == 1) { |
|
157 | + $texts[".item-$item_id .getpaid-mobile-item-subtotal"] = ''; |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | |
161 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
161 | + $this->response = array_merge($this->response, array('texts' => $texts)); |
|
162 | 162 | |
163 | 163 | } |
164 | 164 | |
@@ -167,20 +167,20 @@ discard block |
||
167 | 167 | * |
168 | 168 | * @param GetPaid_Payment_Form_Submission $submission |
169 | 169 | */ |
170 | - public function add_items( $submission ) { |
|
170 | + public function add_items($submission) { |
|
171 | 171 | |
172 | 172 | // Add items. |
173 | 173 | $items = array(); |
174 | 174 | $selected_items = array(); |
175 | 175 | |
176 | - foreach ( $submission->get_items() as $item ) { |
|
176 | + foreach ($submission->get_items() as $item) { |
|
177 | 177 | $item_id = $item->get_id(); |
178 | - $items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() ); |
|
178 | + $items["$item_id"] = $submission->format_amount($item->get_sub_total()); |
|
179 | 179 | |
180 | - $selected_items[ "$item_id" ] = array( |
|
180 | + $selected_items["$item_id"] = array( |
|
181 | 181 | 'quantity' => $item->get_quantity(), |
182 | 182 | 'price' => $item->get_price(), |
183 | - 'price_fmt' => $submission->format_amount( $item->get_price() ), |
|
183 | + 'price_fmt' => $submission->format_amount($item->get_price()), |
|
184 | 184 | ); |
185 | 185 | } |
186 | 186 | |
@@ -199,17 +199,17 @@ discard block |
||
199 | 199 | * |
200 | 200 | * @param GetPaid_Payment_Form_Submission $submission |
201 | 201 | */ |
202 | - public function add_fees( $submission ) { |
|
202 | + public function add_fees($submission) { |
|
203 | 203 | |
204 | 204 | $fees = array(); |
205 | 205 | |
206 | - foreach ( $submission->get_fees() as $name => $data ) { |
|
207 | - $fees[ $name ] = $submission->format_amount( $data['initial_fee'] ); |
|
206 | + foreach ($submission->get_fees() as $name => $data) { |
|
207 | + $fees[$name] = $submission->format_amount($data['initial_fee']); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | $this->response = array_merge( |
211 | 211 | $this->response, |
212 | - array( 'fees' => $fees ) |
|
212 | + array('fees' => $fees) |
|
213 | 213 | ); |
214 | 214 | |
215 | 215 | } |
@@ -219,17 +219,17 @@ discard block |
||
219 | 219 | * |
220 | 220 | * @param GetPaid_Payment_Form_Submission $submission |
221 | 221 | */ |
222 | - public function add_discounts( $submission ) { |
|
222 | + public function add_discounts($submission) { |
|
223 | 223 | |
224 | 224 | $discounts = array(); |
225 | 225 | |
226 | - foreach ( $submission->get_discounts() as $name => $data ) { |
|
227 | - $discounts[ $name ] = $submission->format_amount( $data['initial_discount'] ); |
|
226 | + foreach ($submission->get_discounts() as $name => $data) { |
|
227 | + $discounts[$name] = $submission->format_amount($data['initial_discount']); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | $this->response = array_merge( |
231 | 231 | $this->response, |
232 | - array( 'discounts' => $discounts ) |
|
232 | + array('discounts' => $discounts) |
|
233 | 233 | ); |
234 | 234 | |
235 | 235 | } |
@@ -239,20 +239,20 @@ discard block |
||
239 | 239 | * |
240 | 240 | * @param GetPaid_Payment_Form_Submission $submission |
241 | 241 | */ |
242 | - public function add_taxes( $submission ) { |
|
242 | + public function add_taxes($submission) { |
|
243 | 243 | |
244 | 244 | $taxes = array(); |
245 | 245 | $markup = ''; |
246 | - foreach ( $submission->get_taxes() as $name => $data ) { |
|
247 | - $name = sanitize_text_field( $name ); |
|
248 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
249 | - $taxes[ $name ] = $amount; |
|
246 | + foreach ($submission->get_taxes() as $name => $data) { |
|
247 | + $name = sanitize_text_field($name); |
|
248 | + $amount = $submission->format_amount($data['initial_tax']); |
|
249 | + $taxes[$name] = $amount; |
|
250 | 250 | $markup .= "<small class='form-text'>$name : $amount</small>"; |
251 | 251 | } |
252 | 252 | |
253 | 253 | $this->response = array_merge( |
254 | 254 | $this->response, |
255 | - array( 'taxes' => $taxes ) |
|
255 | + array('taxes' => $taxes) |
|
256 | 256 | ); |
257 | 257 | |
258 | 258 | } |
@@ -262,27 +262,27 @@ discard block |
||
262 | 262 | * |
263 | 263 | * @param GetPaid_Payment_Form_Submission $submission |
264 | 264 | */ |
265 | - public function add_gateways( $submission ) { |
|
265 | + public function add_gateways($submission) { |
|
266 | 266 | |
267 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
267 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
268 | 268 | |
269 | - if ( $this->response['has_recurring'] ) { |
|
269 | + if ($this->response['has_recurring']) { |
|
270 | 270 | |
271 | - foreach ( $gateways as $i => $gateway ) { |
|
271 | + foreach ($gateways as $i => $gateway) { |
|
272 | 272 | |
273 | 273 | if ( |
274 | - ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
275 | - || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
276 | - || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
277 | - unset( $gateways[ $i ] ); |
|
274 | + !getpaid_payment_gateway_supports($gateway, 'subscription') |
|
275 | + || ($this->response['has_subscription_group'] && !getpaid_payment_gateway_supports($gateway, 'single_subscription_group')) |
|
276 | + || ($this->response['has_multiple_subscription_groups'] && !getpaid_payment_gateway_supports($gateway, 'multiple_subscription_groups')) ) { |
|
277 | + unset($gateways[$i]); |
|
278 | 278 | } |
279 | 279 | } |
280 | 280 | } |
281 | 281 | |
282 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
282 | + $gateways = apply_filters('getpaid_submission_gateways', $gateways, $submission); |
|
283 | 283 | $this->response = array_merge( |
284 | 284 | $this->response, |
285 | - array( 'gateways' => $gateways ) |
|
285 | + array('gateways' => $gateways) |
|
286 | 286 | ); |
287 | 287 | |
288 | 288 | } |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | * |
293 | 293 | * @param GetPaid_Payment_Form_Submission $submission |
294 | 294 | */ |
295 | - public function add_data( $submission ) { |
|
295 | + public function add_data($submission) { |
|
296 | 296 | |
297 | 297 | $this->response = array_merge( |
298 | 298 | $this->response, |
@@ -7,17 +7,17 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | // Totals rows. |
13 | 13 | $cart_totals = apply_filters( |
14 | 14 | 'getpaid_payment_form_cart_table_totals', |
15 | 15 | array( |
16 | - 'subtotal' => __( 'Subtotal', 'invoicing' ), |
|
17 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
18 | - 'fees' => __( 'Fee', 'invoicing' ), |
|
19 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
20 | - 'total' => __( 'Total', 'invoicing' ), |
|
16 | + 'subtotal' => __('Subtotal', 'invoicing'), |
|
17 | + 'tax' => __('Tax', 'invoicing'), |
|
18 | + 'fees' => __('Fee', 'invoicing'), |
|
19 | + 'discount' => __('Discount', 'invoicing'), |
|
20 | + 'total' => __('Total', 'invoicing'), |
|
21 | 21 | ), |
22 | 22 | $form |
23 | 23 | ); |
@@ -25,15 +25,15 @@ discard block |
||
25 | 25 | $currency = $form->get_currency(); |
26 | 26 | $country = wpinv_get_default_country(); |
27 | 27 | |
28 | -if ( ! empty( $form->invoice ) ) { |
|
29 | - $country = $form->invoice->get_country(); |
|
28 | +if (!empty($form->invoice)) { |
|
29 | + $country = $form->invoice->get_country(); |
|
30 | 30 | } |
31 | 31 | |
32 | -if ( ! wpinv_use_taxes() && isset( $cart_totals['tax'] ) ) { |
|
33 | - unset( $cart_totals['tax'] ); |
|
32 | +if (!wpinv_use_taxes() && isset($cart_totals['tax'])) { |
|
33 | + unset($cart_totals['tax']); |
|
34 | 34 | } |
35 | 35 | |
36 | -do_action( 'getpaid_before_payment_form_cart_totals', $form, $cart_totals ); |
|
36 | +do_action('getpaid_before_payment_form_cart_totals', $form, $cart_totals); |
|
37 | 37 | |
38 | 38 | ?> |
39 | 39 | <style> |
@@ -47,26 +47,26 @@ discard block |
||
47 | 47 | <div class="row"> |
48 | 48 | <div class="col-12 offset-sm-6 col-sm-6 border-sm-left pl-sm-0"> |
49 | 49 | |
50 | - <?php foreach ( $cart_totals as $key => $label ) : ?> |
|
50 | + <?php foreach ($cart_totals as $key => $label) : ?> |
|
51 | 51 | |
52 | - <div class="getpaid-form-cart-totals-col getpaid-form-cart-totals-<?php echo esc_attr( $key ); ?> font-weight-bold py-2 px-3 <?php echo 'total' === $key ? 'bg-light' : 'border-bottom'; ?> <?php echo 'tax' === $key && wpinv_display_individual_tax_rates() ? 'getpaid-tax-template d-none' : ''; ?>"> |
|
52 | + <div class="getpaid-form-cart-totals-col getpaid-form-cart-totals-<?php echo esc_attr($key); ?> font-weight-bold py-2 px-3 <?php echo 'total' === $key ? 'bg-light' : 'border-bottom'; ?> <?php echo 'tax' === $key && wpinv_display_individual_tax_rates() ? 'getpaid-tax-template d-none' : ''; ?>"> |
|
53 | 53 | |
54 | 54 | <div class="form-row row"> |
55 | 55 | |
56 | 56 | <div class="col-8 pl-sm-0 getpaid-payment-form-line-totals-label"> |
57 | - <?php echo esc_html( $label ); ?> |
|
57 | + <?php echo esc_html($label); ?> |
|
58 | 58 | </div> |
59 | 59 | |
60 | - <div class="col-4 getpaid-payment-form-line-totals-value getpaid-form-cart-totals-total-<?php echo esc_attr( $key ); ?>"> |
|
60 | + <div class="col-4 getpaid-payment-form-line-totals-value getpaid-form-cart-totals-total-<?php echo esc_attr($key); ?>"> |
|
61 | 61 | |
62 | 62 | <?php |
63 | 63 | |
64 | 64 | // Total tax. |
65 | - if ( in_array( $key, array( 'tax', 'discount', 'subtotal', 'total', 'fees' ), true ) ) { |
|
66 | - wpinv_the_price( 0, $currency ); |
|
65 | + if (in_array($key, array('tax', 'discount', 'subtotal', 'total', 'fees'), true)) { |
|
66 | + wpinv_the_price(0, $currency); |
|
67 | 67 | } |
68 | 68 | |
69 | - do_action( "getpaid_payment_form_cart_totals_$key", $form ); |
|
69 | + do_action("getpaid_payment_form_cart_totals_$key", $form); |
|
70 | 70 | ?> |
71 | 71 | |
72 | 72 | </div> |
@@ -82,4 +82,4 @@ discard block |
||
82 | 82 | </div> |
83 | 83 | |
84 | 84 | <?php |
85 | -do_action( 'getpaid_payment_form_cart_totals', $form, $cart_totals ); |
|
85 | +do_action('getpaid_payment_form_cart_totals', $form, $cart_totals); |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @var WPInv_Invoice $invoice |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | ?> |
14 | 14 | |
@@ -16,48 +16,48 @@ discard block |
||
16 | 16 | |
17 | 17 | <?php |
18 | 18 | |
19 | - $actions = array(); |
|
19 | + $actions = array(); |
|
20 | 20 | |
21 | 21 | echo sprintf( |
22 | 22 | '<a href="javascript:void(0)" class="btn btn-sm m-1 d-inline-block btn-secondary text-white invoice-action-print d-none d-lg-inline-block" onclick="window.print();">%s</a>', |
23 | 23 | sprintf( |
24 | - esc_html__( 'Print %s', 'invoicing' ), |
|
25 | - esc_html( ucfirst( $invoice->get_invoice_quote_type() ) ) |
|
24 | + esc_html__('Print %s', 'invoicing'), |
|
25 | + esc_html(ucfirst($invoice->get_invoice_quote_type())) |
|
26 | 26 | ) |
27 | 27 | ); |
28 | 28 | |
29 | - if ( is_user_logged_in() ) { |
|
29 | + if (is_user_logged_in()) { |
|
30 | 30 | |
31 | 31 | $actions[] = sprintf( |
32 | 32 | '<a href="%s" class="btn btn-sm btn-secondary text-white m-1 d-inline-block invoice-action-history">%s</a>', |
33 | - esc_url( wpinv_get_history_page_uri( $invoice->get_post_type() ) ), |
|
33 | + esc_url(wpinv_get_history_page_uri($invoice->get_post_type())), |
|
34 | 34 | sprintf( |
35 | - __( '%s History', 'invoicing' ), |
|
36 | - esc_html( ucfirst( $invoice->get_invoice_quote_type() ) ) |
|
35 | + __('%s History', 'invoicing'), |
|
36 | + esc_html(ucfirst($invoice->get_invoice_quote_type())) |
|
37 | 37 | ) |
38 | 38 | ); |
39 | 39 | |
40 | 40 | } |
41 | 41 | |
42 | - if ( wpinv_current_user_can_manage_invoicing() ) { |
|
42 | + if (wpinv_current_user_can_manage_invoicing()) { |
|
43 | 43 | |
44 | 44 | $actions[] = sprintf( |
45 | 45 | '<a href="%s" class="btn btn-sm btn-secondary text-white m-1 d-inline-block invoice-action-edit">%s</a>', |
46 | - esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
46 | + esc_url(get_edit_post_link($invoice->get_id())), |
|
47 | 47 | sprintf( |
48 | - __( 'Edit %s', 'invoicing' ), |
|
49 | - esc_html( ucfirst( $invoice->get_invoice_quote_type() ) ) |
|
48 | + __('Edit %s', 'invoicing'), |
|
49 | + esc_html(ucfirst($invoice->get_invoice_quote_type())) |
|
50 | 50 | ) |
51 | 51 | ); |
52 | 52 | |
53 | 53 | } |
54 | 54 | |
55 | - $actions = apply_filters( 'getpaid_invoice_header_right_actions_array', $actions, $invoice ); |
|
56 | - echo wp_kses_post( implode( '', $actions ) ); |
|
55 | + $actions = apply_filters('getpaid_invoice_header_right_actions_array', $actions, $invoice); |
|
56 | + echo wp_kses_post(implode('', $actions)); |
|
57 | 57 | |
58 | 58 | ?> |
59 | 59 | |
60 | - <?php do_action( 'wpinv_invoice_display_right_actions', $invoice ); ?> |
|
60 | + <?php do_action('wpinv_invoice_display_right_actions', $invoice); ?> |
|
61 | 61 | </div> |
62 | 62 | |
63 | 63 | <?php |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 | |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | <?php |
19 | 19 | |
20 | 20 | // Fires when printing the header. |
21 | - do_action( 'getpaid_invoice_header', $invoice ); |
|
21 | + do_action('getpaid_invoice_header', $invoice); |
|
22 | 22 | |
23 | 23 | // Print the opening wrapper. |
24 | 24 | echo '<div class="container bg-white getpaid-print-no-border border mt-4 mb-4 p-4 position-relative flex-grow-1">'; |
@@ -27,16 +27,16 @@ discard block |
||
27 | 27 | wpinv_print_errors(); |
28 | 28 | |
29 | 29 | // Fires when printing the invoice details. |
30 | - do_action( 'getpaid_invoice_details', $invoice ); |
|
30 | + do_action('getpaid_invoice_details', $invoice); |
|
31 | 31 | |
32 | 32 | // Fires when printing the invoice line items. |
33 | - do_action( 'getpaid_invoice_line_items', $invoice ); |
|
33 | + do_action('getpaid_invoice_line_items', $invoice); |
|
34 | 34 | |
35 | 35 | // Print the closing wrapper. |
36 | 36 | echo '</div>'; |
37 | 37 | |
38 | 38 | // Fires when printing the invoice footer. |
39 | - do_action( 'getpaid_invoice_footer', $invoice ); |
|
39 | + do_action('getpaid_invoice_footer', $invoice); |
|
40 | 40 | |
41 | 41 | ?> |
42 | 42 |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | * |
98 | 98 | * @param null|string|array $query Optional. The query variables. |
99 | 99 | */ |
100 | - public function __construct( $query = null ) { |
|
101 | - if ( ! is_null( $query ) ) { |
|
102 | - $this->prepare_query( $query ); |
|
100 | + public function __construct($query = null) { |
|
101 | + if (!is_null($query)) { |
|
102 | + $this->prepare_query($query); |
|
103 | 103 | $this->query(); |
104 | 104 | } |
105 | 105 | } |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | * @param string|array $args Query vars, as passed to `GetPaid_Subscriptions_Query`. |
113 | 113 | * @return array Complete query variables with undefined ones filled in with defaults. |
114 | 114 | */ |
115 | - public static function fill_query_vars( $args ) { |
|
115 | + public static function fill_query_vars($args) { |
|
116 | 116 | $defaults = array( |
117 | 117 | 'include' => array(), |
118 | 118 | 'exclude' => array(), |
@@ -126,16 +126,16 @@ discard block |
||
126 | 126 | 's' => '', |
127 | 127 | ); |
128 | 128 | |
129 | - foreach ( GetPaid_Customer_Data_Store::get_database_fields() as $field => $type ) { |
|
130 | - $defaults[ $field ] = 'any'; |
|
129 | + foreach (GetPaid_Customer_Data_Store::get_database_fields() as $field => $type) { |
|
130 | + $defaults[$field] = 'any'; |
|
131 | 131 | |
132 | - if ( '%f' === $type || '%d' === $type ) { |
|
133 | - $defaults[ $field . '_min' ] = ''; |
|
134 | - $defaults[ $field . '_max' ] = ''; |
|
132 | + if ('%f' === $type || '%d' === $type) { |
|
133 | + $defaults[$field . '_min'] = ''; |
|
134 | + $defaults[$field . '_max'] = ''; |
|
135 | 135 | } |
136 | 136 | } |
137 | 137 | |
138 | - return wp_parse_args( $args, $defaults ); |
|
138 | + return wp_parse_args($args, $defaults); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -145,45 +145,45 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @see self::fill_query_vars() For allowede args and their defaults. |
147 | 147 | */ |
148 | - public function prepare_query( $query = array() ) { |
|
148 | + public function prepare_query($query = array()) { |
|
149 | 149 | global $wpdb; |
150 | 150 | |
151 | - if ( empty( $this->query_vars ) || ! empty( $query ) ) { |
|
151 | + if (empty($this->query_vars) || !empty($query)) { |
|
152 | 152 | $this->query_limit = null; |
153 | - $this->query_vars = $this->fill_query_vars( $query ); |
|
153 | + $this->query_vars = $this->fill_query_vars($query); |
|
154 | 154 | } |
155 | 155 | |
156 | - if ( ! empty( $this->query_vars['fields'] ) && 'all' !== $this->query_vars['fields'] ) { |
|
157 | - $this->query_vars['fields'] = wpinv_parse_list( $this->query_vars['fields'] ); |
|
156 | + if (!empty($this->query_vars['fields']) && 'all' !== $this->query_vars['fields']) { |
|
157 | + $this->query_vars['fields'] = wpinv_parse_list($this->query_vars['fields']); |
|
158 | 158 | } |
159 | 159 | |
160 | - do_action( 'getpaid_pre_get_customers', array( &$this ) ); |
|
160 | + do_action('getpaid_pre_get_customers', array(&$this)); |
|
161 | 161 | |
162 | 162 | // Ensure that query vars are filled after 'getpaid_pre_get_customers'. |
163 | 163 | $qv = & $this->query_vars; |
164 | - $qv = $this->fill_query_vars( $qv ); |
|
164 | + $qv = $this->fill_query_vars($qv); |
|
165 | 165 | $table = $wpdb->prefix . 'getpaid_customers'; |
166 | 166 | $this->query_from = "FROM $table"; |
167 | 167 | |
168 | 168 | // Prepare query fields. |
169 | - $this->prepare_query_fields( $qv, $table ); |
|
169 | + $this->prepare_query_fields($qv, $table); |
|
170 | 170 | |
171 | 171 | // Prepare query where. |
172 | - $this->prepare_query_where( $qv, $table ); |
|
172 | + $this->prepare_query_where($qv, $table); |
|
173 | 173 | |
174 | 174 | // Prepare query order. |
175 | - $this->prepare_query_order( $qv, $table ); |
|
175 | + $this->prepare_query_order($qv, $table); |
|
176 | 176 | |
177 | 177 | // limit |
178 | - if ( isset( $qv['number'] ) && $qv['number'] > 0 ) { |
|
179 | - if ( $qv['offset'] ) { |
|
180 | - $this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['offset'], $qv['number'] ); |
|
178 | + if (isset($qv['number']) && $qv['number'] > 0) { |
|
179 | + if ($qv['offset']) { |
|
180 | + $this->query_limit = $wpdb->prepare('LIMIT %d, %d', $qv['offset'], $qv['number']); |
|
181 | 181 | } else { |
182 | - $this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] ); |
|
182 | + $this->query_limit = $wpdb->prepare('LIMIT %d, %d', $qv['number'] * ($qv['paged'] - 1), $qv['number']); |
|
183 | 183 | } |
184 | 184 | } |
185 | 185 | |
186 | - do_action_ref_array( 'getpaid_after_customers_query', array( &$this ) ); |
|
186 | + do_action_ref_array('getpaid_after_customers_query', array(&$this)); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
@@ -194,27 +194,27 @@ discard block |
||
194 | 194 | * @param array $qv Query vars. |
195 | 195 | * @param string $table Table name. |
196 | 196 | */ |
197 | - protected function prepare_query_fields( &$qv, $table ) { |
|
197 | + protected function prepare_query_fields(&$qv, $table) { |
|
198 | 198 | |
199 | - if ( is_array( $qv['fields'] ) ) { |
|
200 | - $qv['fields'] = array_unique( $qv['fields'] ); |
|
201 | - $allowed_fields = array_keys( GetPaid_Customer_Data_Store::get_database_fields() ); |
|
199 | + if (is_array($qv['fields'])) { |
|
200 | + $qv['fields'] = array_unique($qv['fields']); |
|
201 | + $allowed_fields = array_keys(GetPaid_Customer_Data_Store::get_database_fields()); |
|
202 | 202 | |
203 | 203 | $query_fields = array(); |
204 | - foreach ( $qv['fields'] as $field ) { |
|
205 | - if ( ! in_array( $field, $allowed_fields ) ) { |
|
204 | + foreach ($qv['fields'] as $field) { |
|
205 | + if (!in_array($field, $allowed_fields)) { |
|
206 | 206 | continue; |
207 | 207 | } |
208 | 208 | |
209 | - $field = sanitize_key( $field ); |
|
209 | + $field = sanitize_key($field); |
|
210 | 210 | $query_fields[] = "$table.`$field`"; |
211 | 211 | } |
212 | - $this->query_fields = implode( ',', $query_fields ); |
|
212 | + $this->query_fields = implode(',', $query_fields); |
|
213 | 213 | } else { |
214 | 214 | $this->query_fields = "$table.*"; |
215 | 215 | } |
216 | 216 | |
217 | - if ( isset( $qv['count_total'] ) && $qv['count_total'] ) { |
|
217 | + if (isset($qv['count_total']) && $qv['count_total']) { |
|
218 | 218 | $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields; |
219 | 219 | } |
220 | 220 | |
@@ -228,55 +228,55 @@ discard block |
||
228 | 228 | * @param array $qv Query vars. |
229 | 229 | * @param string $table Table name. |
230 | 230 | */ |
231 | - protected function prepare_query_where( &$qv, $table ) { |
|
231 | + protected function prepare_query_where(&$qv, $table) { |
|
232 | 232 | global $wpdb; |
233 | 233 | $this->query_where = 'WHERE 1=1'; |
234 | 234 | |
235 | 235 | // Fields. |
236 | - foreach ( GetPaid_Customer_Data_Store::get_database_fields() as $field => $type ) { |
|
237 | - if ( 'any' !== $qv[ $field ] ) { |
|
236 | + foreach (GetPaid_Customer_Data_Store::get_database_fields() as $field => $type) { |
|
237 | + if ('any' !== $qv[$field]) { |
|
238 | 238 | |
239 | 239 | // In. |
240 | - if ( is_array( $qv[ $field ] ) ) { |
|
241 | - $in = join( ',', array_fill( 0, count( $qv[ $field ] ), $type ) ); |
|
242 | - $this->query_where .= $wpdb->prepare( " AND $table.`status` IN ( $in )", $qv[ $field ] ); |
|
243 | - } elseif ( ! empty( $qv[ $field ] ) ) { |
|
244 | - $this->query_where .= $wpdb->prepare( " AND $table.`$field` = $type", $qv[ $field ] ); |
|
240 | + if (is_array($qv[$field])) { |
|
241 | + $in = join(',', array_fill(0, count($qv[$field]), $type)); |
|
242 | + $this->query_where .= $wpdb->prepare(" AND $table.`status` IN ( $in )", $qv[$field]); |
|
243 | + } elseif (!empty($qv[$field])) { |
|
244 | + $this->query_where .= $wpdb->prepare(" AND $table.`$field` = $type", $qv[$field]); |
|
245 | 245 | } |
246 | 246 | } |
247 | 247 | |
248 | 248 | // Min/Max. |
249 | - if ( '%f' === $type || '%d' === $type ) { |
|
249 | + if ('%f' === $type || '%d' === $type) { |
|
250 | 250 | |
251 | 251 | // Min. |
252 | - if ( is_numeric( $qv[ $field . '_min' ] ) ) { |
|
253 | - $this->query_where .= $wpdb->prepare( " AND $table.`$field` >= $type", $qv[ $field . '_min' ] ); |
|
252 | + if (is_numeric($qv[$field . '_min'])) { |
|
253 | + $this->query_where .= $wpdb->prepare(" AND $table.`$field` >= $type", $qv[$field . '_min']); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | // Max. |
257 | - if ( is_numeric( $qv[ $field . '_max' ] ) ) { |
|
258 | - $this->query_where .= $wpdb->prepare( " AND $table.`$field` <= $type", $qv[ $field . '_max' ] ); |
|
257 | + if (is_numeric($qv[$field . '_max'])) { |
|
258 | + $this->query_where .= $wpdb->prepare(" AND $table.`$field` <= $type", $qv[$field . '_max']); |
|
259 | 259 | } |
260 | 260 | } |
261 | 261 | } |
262 | 262 | |
263 | - if ( ! empty( $qv['include'] ) ) { |
|
264 | - $include = implode( ',', wp_parse_id_list( $qv['include'] ) ); |
|
263 | + if (!empty($qv['include'])) { |
|
264 | + $include = implode(',', wp_parse_id_list($qv['include'])); |
|
265 | 265 | $this->query_where .= " AND $table.`id` IN ($include)"; |
266 | - } elseif ( ! empty( $qv['exclude'] ) ) { |
|
267 | - $exclude = implode( ',', wp_parse_id_list( $qv['exclude'] ) ); |
|
266 | + } elseif (!empty($qv['exclude'])) { |
|
267 | + $exclude = implode(',', wp_parse_id_list($qv['exclude'])); |
|
268 | 268 | $this->query_where .= " AND $table.`id` NOT IN ($exclude)"; |
269 | 269 | } |
270 | 270 | |
271 | 271 | // Date queries are allowed for the customer creation date. |
272 | - if ( ! empty( $qv['date_created_query'] ) && is_array( $qv['date_created_query'] ) ) { |
|
273 | - $date_created_query = new WP_Date_Query( $qv['date_created_query'], "$table.date_created" ); |
|
272 | + if (!empty($qv['date_created_query']) && is_array($qv['date_created_query'])) { |
|
273 | + $date_created_query = new WP_Date_Query($qv['date_created_query'], "$table.date_created"); |
|
274 | 274 | $this->query_where .= $date_created_query->get_sql(); |
275 | 275 | } |
276 | 276 | |
277 | 277 | // Search. |
278 | - if ( ! empty( $qv['s'] ) ) { |
|
279 | - $this->query_where .= $this->get_search_sql( $qv['s'] ); |
|
278 | + if (!empty($qv['s'])) { |
|
279 | + $this->query_where .= $this->get_search_sql($qv['s']); |
|
280 | 280 | } |
281 | 281 | } |
282 | 282 | |
@@ -290,22 +290,22 @@ discard block |
||
290 | 290 | * @param string $string The string to search for. |
291 | 291 | * @return string |
292 | 292 | */ |
293 | - protected function get_search_sql( $string ) { |
|
293 | + protected function get_search_sql($string) { |
|
294 | 294 | global $wpdb; |
295 | 295 | |
296 | 296 | $searches = array(); |
297 | - $string = trim( $string, '%' ); |
|
298 | - $like = '%' . $wpdb->esc_like( $string ) . '%'; |
|
297 | + $string = trim($string, '%'); |
|
298 | + $like = '%' . $wpdb->esc_like($string) . '%'; |
|
299 | 299 | |
300 | - foreach ( array_keys( GetPaid_Customer_Data_Store::get_database_fields() ) as $col ) { |
|
301 | - if ( 'id' === $col || 'user_id' === $col ) { |
|
302 | - $searches[] = $wpdb->prepare( "$col = %s", $string ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
300 | + foreach (array_keys(GetPaid_Customer_Data_Store::get_database_fields()) as $col) { |
|
301 | + if ('id' === $col || 'user_id' === $col) { |
|
302 | + $searches[] = $wpdb->prepare("$col = %s", $string); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
303 | 303 | } else { |
304 | - $searches[] = $wpdb->prepare( "$col LIKE %s", $like ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
304 | + $searches[] = $wpdb->prepare("$col LIKE %s", $like); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
305 | 305 | } |
306 | 306 | } |
307 | 307 | |
308 | - return ' AND (' . implode( ' OR ', $searches ) . ')'; |
|
308 | + return ' AND (' . implode(' OR ', $searches) . ')'; |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | /** |
@@ -316,24 +316,24 @@ discard block |
||
316 | 316 | * @param array $qv Query vars. |
317 | 317 | * @param string $table Table name. |
318 | 318 | */ |
319 | - protected function prepare_query_order( &$qv, $table ) { |
|
319 | + protected function prepare_query_order(&$qv, $table) { |
|
320 | 320 | |
321 | 321 | // sorting. |
322 | - $qv['order'] = isset( $qv['order'] ) ? strtoupper( $qv['order'] ) : ''; |
|
323 | - $order = $this->parse_order( $qv['order'] ); |
|
322 | + $qv['order'] = isset($qv['order']) ? strtoupper($qv['order']) : ''; |
|
323 | + $order = $this->parse_order($qv['order']); |
|
324 | 324 | |
325 | 325 | // Default order is by 'id' (latest customers). |
326 | - if ( empty( $qv['orderby'] ) ) { |
|
327 | - $qv['orderby'] = array( 'id' ); |
|
326 | + if (empty($qv['orderby'])) { |
|
327 | + $qv['orderby'] = array('id'); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | // 'orderby' values may be an array, comma- or space-separated list. |
331 | - $ordersby = array_filter( wpinv_parse_list( $qv['orderby'] ) ); |
|
331 | + $ordersby = array_filter(wpinv_parse_list($qv['orderby'])); |
|
332 | 332 | |
333 | 333 | $orderby_array = array(); |
334 | - foreach ( $ordersby as $_key => $_value ) { |
|
334 | + foreach ($ordersby as $_key => $_value) { |
|
335 | 335 | |
336 | - if ( is_int( $_key ) ) { |
|
336 | + if (is_int($_key)) { |
|
337 | 337 | // Integer key means this is a flat array of 'orderby' fields. |
338 | 338 | $_orderby = $_value; |
339 | 339 | $_order = $order; |
@@ -343,19 +343,19 @@ discard block |
||
343 | 343 | $_order = $_value; |
344 | 344 | } |
345 | 345 | |
346 | - $parsed = $this->parse_orderby( $_orderby, $table ); |
|
346 | + $parsed = $this->parse_orderby($_orderby, $table); |
|
347 | 347 | |
348 | - if ( $parsed ) { |
|
349 | - $orderby_array[] = $parsed . ' ' . $this->parse_order( $_order ); |
|
348 | + if ($parsed) { |
|
349 | + $orderby_array[] = $parsed . ' ' . $this->parse_order($_order); |
|
350 | 350 | } |
351 | 351 | } |
352 | 352 | |
353 | 353 | // If no valid clauses were found, order by id. |
354 | - if ( empty( $orderby_array ) ) { |
|
354 | + if (empty($orderby_array)) { |
|
355 | 355 | $orderby_array[] = "id $order"; |
356 | 356 | } |
357 | 357 | |
358 | - $this->query_orderby = 'ORDER BY ' . implode( ', ', $orderby_array ); |
|
358 | + $this->query_orderby = 'ORDER BY ' . implode(', ', $orderby_array); |
|
359 | 359 | |
360 | 360 | } |
361 | 361 | |
@@ -369,33 +369,33 @@ discard block |
||
369 | 369 | public function query() { |
370 | 370 | global $wpdb; |
371 | 371 | |
372 | - $qv =& $this->query_vars; |
|
372 | + $qv = & $this->query_vars; |
|
373 | 373 | |
374 | 374 | // Return a non-null value to bypass the default GetPaid customers query and remember to set the |
375 | 375 | // total_customers property. |
376 | - $this->results = apply_filters_ref_array( 'getpaid_customers_pre_query', array( null, &$this ) ); |
|
376 | + $this->results = apply_filters_ref_array('getpaid_customers_pre_query', array(null, &$this)); |
|
377 | 377 | |
378 | - if ( null === $this->results ) { |
|
378 | + if (null === $this->results) { |
|
379 | 379 | $this->request = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit"; |
380 | 380 | |
381 | - if ( ( is_array( $qv['fields'] ) && 1 !== count( $qv['fields'] ) ) || 'all' === $qv['fields'] ) { |
|
382 | - $this->results = $wpdb->get_results( $this->request ); |
|
381 | + if ((is_array($qv['fields']) && 1 !== count($qv['fields'])) || 'all' === $qv['fields']) { |
|
382 | + $this->results = $wpdb->get_results($this->request); |
|
383 | 383 | } else { |
384 | - $this->results = $wpdb->get_col( $this->request ); |
|
384 | + $this->results = $wpdb->get_col($this->request); |
|
385 | 385 | } |
386 | 386 | |
387 | - if ( isset( $qv['count_total'] ) && $qv['count_total'] ) { |
|
388 | - $found_customers_query = apply_filters( 'getpaid_found_customers_query', 'SELECT FOUND_ROWS()', $this ); |
|
389 | - $this->total_customers = (int) $wpdb->get_var( $found_customers_query ); |
|
387 | + if (isset($qv['count_total']) && $qv['count_total']) { |
|
388 | + $found_customers_query = apply_filters('getpaid_found_customers_query', 'SELECT FOUND_ROWS()', $this); |
|
389 | + $this->total_customers = (int) $wpdb->get_var($found_customers_query); |
|
390 | 390 | } |
391 | 391 | } |
392 | 392 | |
393 | - if ( 'all' === $qv['fields'] ) { |
|
394 | - foreach ( $this->results as $key => $customer ) { |
|
395 | - $this->set_cache( $customer->id, $customer, 'getpaid_customers' ); |
|
396 | - $this->set_cache( $customer->user_id, $customer->id, 'getpaid_customer_ids_by_user_id' ); |
|
397 | - $this->set_cache( $customer->email, $customer->id, 'getpaid_customer_ids_by_email' ); |
|
398 | - $this->results[ $key ] = new GetPaid_Customer( $customer ); |
|
393 | + if ('all' === $qv['fields']) { |
|
394 | + foreach ($this->results as $key => $customer) { |
|
395 | + $this->set_cache($customer->id, $customer, 'getpaid_customers'); |
|
396 | + $this->set_cache($customer->user_id, $customer->id, 'getpaid_customer_ids_by_user_id'); |
|
397 | + $this->set_cache($customer->email, $customer->id, 'getpaid_customer_ids_by_email'); |
|
398 | + $this->results[$key] = new GetPaid_Customer($customer); |
|
399 | 399 | } |
400 | 400 | } |
401 | 401 | |
@@ -410,13 +410,13 @@ discard block |
||
410 | 410 | * @param integer $expire |
411 | 411 | * @return boolean |
412 | 412 | */ |
413 | - public function set_cache( $key, $data, $group = '', $expire = 0 ) { |
|
413 | + public function set_cache($key, $data, $group = '', $expire = 0) { |
|
414 | 414 | |
415 | - if ( empty( $key ) ) { |
|
415 | + if (empty($key)) { |
|
416 | 416 | return false; |
417 | 417 | } |
418 | 418 | |
419 | - wp_cache_set( $key, $data, $group, $expire ); |
|
419 | + wp_cache_set($key, $data, $group, $expire); |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | /** |
@@ -427,9 +427,9 @@ discard block |
||
427 | 427 | * @param string $query_var Query variable key. |
428 | 428 | * @return mixed |
429 | 429 | */ |
430 | - public function get( $query_var ) { |
|
431 | - if ( isset( $this->query_vars[ $query_var ] ) ) { |
|
432 | - return $this->query_vars[ $query_var ]; |
|
430 | + public function get($query_var) { |
|
431 | + if (isset($this->query_vars[$query_var])) { |
|
432 | + return $this->query_vars[$query_var]; |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | return null; |
@@ -443,8 +443,8 @@ discard block |
||
443 | 443 | * @param string $query_var Query variable key. |
444 | 444 | * @param mixed $value Query variable value. |
445 | 445 | */ |
446 | - public function set( $query_var, $value ) { |
|
447 | - $this->query_vars[ $query_var ] = $value; |
|
446 | + public function set($query_var, $value) { |
|
447 | + $this->query_vars[$query_var] = $value; |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | /** |
@@ -478,16 +478,16 @@ discard block |
||
478 | 478 | * @param string $table The current table. |
479 | 479 | * @return string Value to use in the ORDER clause, if `$orderby` is valid. |
480 | 480 | */ |
481 | - protected function parse_orderby( $orderby, $table ) { |
|
481 | + protected function parse_orderby($orderby, $table) { |
|
482 | 482 | |
483 | 483 | $_orderby = ''; |
484 | - if ( in_array( $orderby, array_keys( GetPaid_Customer_Data_Store::get_database_fields() ), true ) ) { |
|
484 | + if (in_array($orderby, array_keys(GetPaid_Customer_Data_Store::get_database_fields()), true)) { |
|
485 | 485 | $_orderby = "$table.`$orderby`"; |
486 | - } elseif ( 'id' === strtolower( $orderby ) ) { |
|
486 | + } elseif ('id' === strtolower($orderby)) { |
|
487 | 487 | $_orderby = "$table.id"; |
488 | - } elseif ( 'include' === $orderby && ! empty( $this->query_vars['include'] ) ) { |
|
489 | - $include = wp_parse_id_list( $this->query_vars['include'] ); |
|
490 | - $include_sql = implode( ',', $include ); |
|
488 | + } elseif ('include' === $orderby && !empty($this->query_vars['include'])) { |
|
489 | + $include = wp_parse_id_list($this->query_vars['include']); |
|
490 | + $include_sql = implode(',', $include); |
|
491 | 491 | $_orderby = "FIELD( $table.id, $include_sql )"; |
492 | 492 | } |
493 | 493 | |
@@ -502,12 +502,12 @@ discard block |
||
502 | 502 | * @param string $order The 'order' query variable. |
503 | 503 | * @return string The sanitized 'order' query variable. |
504 | 504 | */ |
505 | - protected function parse_order( $order ) { |
|
506 | - if ( ! is_string( $order ) || empty( $order ) ) { |
|
505 | + protected function parse_order($order) { |
|
506 | + if (!is_string($order) || empty($order)) { |
|
507 | 507 | return 'DESC'; |
508 | 508 | } |
509 | 509 | |
510 | - if ( 'ASC' === strtoupper( $order ) ) { |
|
510 | + if ('ASC' === strtoupper($order)) { |
|
511 | 511 | return 'ASC'; |
512 | 512 | } else { |
513 | 513 | return 'DESC'; |
@@ -5,12 +5,12 @@ discard block |
||
5 | 5 | */ |
6 | 6 | |
7 | 7 | // Exit if accessed directly |
8 | -if ( ! defined( 'ABSPATH' ) ) { |
|
8 | +if (!defined('ABSPATH')) { |
|
9 | 9 | exit; |
10 | 10 | } |
11 | 11 | |
12 | 12 | // Load WP_List_Table if not loaded |
13 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
13 | +if (!class_exists('WP_List_Table')) { |
|
14 | 14 | require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
15 | 15 | } |
16 | 16 | |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @return string Column Name |
80 | 80 | */ |
81 | - public function column_default( $customer, $column_name ) { |
|
82 | - $value = esc_html( $customer->get( $column_name ) ); |
|
83 | - return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $customer ); |
|
81 | + public function column_default($customer, $column_name) { |
|
82 | + $value = esc_html($customer->get($column_name)); |
|
83 | + return apply_filters('wpinv_customers_table_column' . $column_name, $value, $customer); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -92,12 +92,12 @@ discard block |
||
92 | 92 | * |
93 | 93 | * @return string Column Name |
94 | 94 | */ |
95 | - public function column_country( $customer ) { |
|
96 | - $country = wpinv_sanitize_country( $customer->get( 'country' ) ); |
|
97 | - if ( $country ) { |
|
98 | - $country = wpinv_country_name( $country ); |
|
95 | + public function column_country($customer) { |
|
96 | + $country = wpinv_sanitize_country($customer->get('country')); |
|
97 | + if ($country) { |
|
98 | + $country = wpinv_country_name($country); |
|
99 | 99 | } |
100 | - return esc_html( $country ); |
|
100 | + return esc_html($country); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -109,14 +109,14 @@ discard block |
||
109 | 109 | * |
110 | 110 | * @return string Column Name |
111 | 111 | */ |
112 | - public function column_state( $customer ) { |
|
113 | - $country = wpinv_sanitize_country( $customer->get( 'country' ) ); |
|
114 | - $state = $customer->get( 'state' ); |
|
115 | - if ( $state ) { |
|
116 | - $state = wpinv_state_name( $state, $country ); |
|
112 | + public function column_state($customer) { |
|
113 | + $country = wpinv_sanitize_country($customer->get('country')); |
|
114 | + $state = $customer->get('state'); |
|
115 | + if ($state) { |
|
116 | + $state = wpinv_state_name($state, $country); |
|
117 | 117 | } |
118 | 118 | |
119 | - return esc_html( $state ); |
|
119 | + return esc_html($state); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -128,8 +128,8 @@ discard block |
||
128 | 128 | * |
129 | 129 | * @return string Column Name |
130 | 130 | */ |
131 | - public function column_date_created( $customer ) { |
|
132 | - return getpaid_format_date_value( $customer->get( 'date_created' ) ); |
|
131 | + public function column_date_created($customer) { |
|
132 | + return getpaid_format_date_value($customer->get('date_created')); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -141,8 +141,8 @@ discard block |
||
141 | 141 | * |
142 | 142 | * @return string Column Name |
143 | 143 | */ |
144 | - public function column_purchase_value( $customer ) { |
|
145 | - return wpinv_price( (float) $customer->get( 'purchase_value' ) ); |
|
144 | + public function column_purchase_value($customer) { |
|
145 | + return wpinv_price((float) $customer->get('purchase_value')); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -154,11 +154,11 @@ discard block |
||
154 | 154 | * |
155 | 155 | * @return string Column Name |
156 | 156 | */ |
157 | - public function column_purchase_count( $customer ) { |
|
158 | - $value = $customer->get( 'purchase_count' ); |
|
159 | - $url = $customer->get( 'user_id' ) ? add_query_arg( array( 'post_type' => 'wpi_invoice', 'author' => $customer->get( 'user_id' ), ), admin_url( 'edit.php' ) ) : ''; |
|
157 | + public function column_purchase_count($customer) { |
|
158 | + $value = $customer->get('purchase_count'); |
|
159 | + $url = $customer->get('user_id') ? add_query_arg(array('post_type' => 'wpi_invoice', 'author' => $customer->get('user_id'),), admin_url('edit.php')) : ''; |
|
160 | 160 | |
161 | - return ( empty( $value ) || empty( $url ) ) ? (int) $value : '<a href="' . esc_url( $url ) . '">' . absint( $value ) . '</a>'; |
|
161 | + return (empty($value) || empty($url)) ? (int) $value : '<a href="' . esc_url($url) . '">' . absint($value) . '</a>'; |
|
162 | 162 | |
163 | 163 | } |
164 | 164 | |
@@ -168,25 +168,25 @@ discard block |
||
168 | 168 | * @param GetPaid_Customer $customer customer. |
169 | 169 | * @return string |
170 | 170 | */ |
171 | - public function column_customer( $customer ) { |
|
171 | + public function column_customer($customer) { |
|
172 | 172 | |
173 | - $first_name = $customer->get( 'first_name' ); |
|
174 | - $last_name = $customer->get( 'last_name' ); |
|
175 | - $email = $customer->get( 'email' ); |
|
176 | - $avatar = get_avatar( $customer->get( 'user_id' ) ? $customer->get( 'user_id' ) : $email, 32 ); |
|
173 | + $first_name = $customer->get('first_name'); |
|
174 | + $last_name = $customer->get('last_name'); |
|
175 | + $email = $customer->get('email'); |
|
176 | + $avatar = get_avatar($customer->get('user_id') ? $customer->get('user_id') : $email, 32); |
|
177 | 177 | |
178 | 178 | // Customer view URL. |
179 | - $view_url = $customer->get( 'user_id' ) ? esc_url( add_query_arg( 'user_id', $customer->get( 'user_id' ), admin_url( 'user-edit.php' ) ) ) : false; |
|
179 | + $view_url = $customer->get('user_id') ? esc_url(add_query_arg('user_id', $customer->get('user_id'), admin_url('user-edit.php'))) : false; |
|
180 | 180 | $row_actions = $view_url ? $this->row_actions( |
181 | 181 | array( |
182 | - 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
182 | + 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __('Edit Details', 'invoicing') . '</a>', |
|
183 | 183 | ) |
184 | 184 | ) : ''; |
185 | 185 | |
186 | 186 | // Customer's name. |
187 | - $name = esc_html( trim( "$first_name $last_name" ) ); |
|
187 | + $name = esc_html(trim("$first_name $last_name")); |
|
188 | 188 | |
189 | - if ( ! empty( $name ) ) { |
|
189 | + if (!empty($name)) { |
|
190 | 190 | $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
191 | 191 | } |
192 | 192 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @return int Current page number |
204 | 204 | */ |
205 | 205 | public function get_paged() { |
206 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
206 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | * @since 1.0.19 |
213 | 213 | * @return void |
214 | 214 | */ |
215 | - public function bulk_actions( $which = '' ) { |
|
215 | + public function bulk_actions($which = '') { |
|
216 | 216 | return array(); |
217 | 217 | } |
218 | 218 | |
@@ -227,33 +227,33 @@ discard block |
||
227 | 227 | 'paged' => $this->get_paged(), |
228 | 228 | ); |
229 | 229 | |
230 | - foreach ( array( 'orderby', 'order', 's' ) as $field ) { |
|
231 | - if ( isset( $_GET[ $field ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
232 | - $query[ $field ] = wpinv_clean( rawurlencode_deep( $_GET[ $field ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
230 | + foreach (array('orderby', 'order', 's') as $field) { |
|
231 | + if (isset($_GET[$field])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
232 | + $query[$field] = wpinv_clean(rawurlencode_deep($_GET[$field])); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
233 | 233 | } |
234 | 234 | } |
235 | 235 | |
236 | - foreach ( GetPaid_Customer_Data_Store::get_database_fields() as $field => $type ) { |
|
236 | + foreach (GetPaid_Customer_Data_Store::get_database_fields() as $field => $type) { |
|
237 | 237 | |
238 | - if ( isset( $_GET[ $field ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
239 | - $query[ $field ] = wpinv_clean( rawurlencode_deep( $_GET[ $field ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
238 | + if (isset($_GET[$field])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
239 | + $query[$field] = wpinv_clean(rawurlencode_deep($_GET[$field])); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | // Min max. |
243 | - if ( '%f' === $type || '%d' === $type ) { |
|
243 | + if ('%f' === $type || '%d' === $type) { |
|
244 | 244 | |
245 | - if ( isset( $_GET[ $field . '_min' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
246 | - $query[ $field . '_min' ] = floatval( $_GET[ $field . '_min' ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
245 | + if (isset($_GET[$field . '_min'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
246 | + $query[$field . '_min'] = floatval($_GET[$field . '_min']); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
247 | 247 | } |
248 | 248 | |
249 | - if ( isset( $_GET[ $field . '_max' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
250 | - $query[ $field . '_max' ] = floatval( $_GET[ $field . '_max' ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
249 | + if (isset($_GET[$field . '_max'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
250 | + $query[$field . '_max'] = floatval($_GET[$field . '_max']); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 | } |
254 | 254 | |
255 | 255 | // Prepare class properties. |
256 | - $this->query = getpaid_get_customers( $query, 'query' ); |
|
256 | + $this->query = getpaid_get_customers($query, 'query'); |
|
257 | 257 | $this->total_count = $this->query->get_total(); |
258 | 258 | $this->items = $this->query->get_results(); |
259 | 259 | } |
@@ -269,13 +269,13 @@ discard block |
||
269 | 269 | $sortable = $this->get_sortable_columns(); |
270 | 270 | $this->prepare_query(); |
271 | 271 | |
272 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
272 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
273 | 273 | |
274 | 274 | $this->set_pagination_args( |
275 | 275 | array( |
276 | 276 | 'total_items' => $this->total_count, |
277 | 277 | 'per_page' => $this->per_page, |
278 | - 'total_pages' => ceil( $this->total_count / $this->per_page ), |
|
278 | + 'total_pages' => ceil($this->total_count / $this->per_page), |
|
279 | 279 | ) |
280 | 280 | ); |
281 | 281 | } |
@@ -287,14 +287,14 @@ discard block |
||
287 | 287 | */ |
288 | 288 | public function get_sortable_columns() { |
289 | 289 | $sortable = array( |
290 | - 'customer' => array( 'first_name', true ), |
|
290 | + 'customer' => array('first_name', true), |
|
291 | 291 | ); |
292 | 292 | |
293 | - foreach ( GetPaid_Customer_Data_Store::get_database_fields() as $field => $type ) { |
|
294 | - $sortable[ $field ] = array( $field, true ); |
|
293 | + foreach (GetPaid_Customer_Data_Store::get_database_fields() as $field => $type) { |
|
294 | + $sortable[$field] = array($field, true); |
|
295 | 295 | } |
296 | 296 | |
297 | - return apply_filters( 'manage_getpaid_customers_sortable_table_columns', $sortable ); |
|
297 | + return apply_filters('manage_getpaid_customers_sortable_table_columns', $sortable); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | /** |
@@ -304,22 +304,22 @@ discard block |
||
304 | 304 | */ |
305 | 305 | public function get_columns() { |
306 | 306 | $columns = array( |
307 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
307 | + 'customer' => __('Customer', 'invoicing'), |
|
308 | 308 | ); |
309 | 309 | |
310 | 310 | // Add address fields. |
311 | - foreach ( getpaid_user_address_fields() as $key => $value ) { |
|
311 | + foreach (getpaid_user_address_fields() as $key => $value) { |
|
312 | 312 | |
313 | 313 | // Skip id, user_id and email. |
314 | - if ( ! in_array( $key, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid', 'first_name', 'last_name' ), true ) ) { |
|
315 | - $columns[ $key ] = $value; |
|
314 | + if (!in_array($key, array('id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid', 'first_name', 'last_name'), true)) { |
|
315 | + $columns[$key] = $value; |
|
316 | 316 | } |
317 | 317 | } |
318 | 318 | |
319 | - $columns['purchase_value'] = __( 'Total Spend', 'invoicing' ); |
|
320 | - $columns['purchase_count'] = __( 'Invoices', 'invoicing' ); |
|
321 | - $columns['date_created'] = __( 'Date created', 'invoicing' ); |
|
319 | + $columns['purchase_value'] = __('Total Spend', 'invoicing'); |
|
320 | + $columns['purchase_count'] = __('Invoices', 'invoicing'); |
|
321 | + $columns['date_created'] = __('Date created', 'invoicing'); |
|
322 | 322 | |
323 | - return apply_filters( 'manage_getpaid_customers_table_columns', $columns ); |
|
323 | + return apply_filters('manage_getpaid_customers_table_columns', $columns); |
|
324 | 324 | } |
325 | 325 | } |
@@ -7,44 +7,44 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 | |
14 | 14 | <div class='form-group mb-3'> |
15 | 15 | <label class="form-label d-block"> |
16 | - <span><?php esc_html_e( 'Input Label', 'invoicing' ); ?></span> |
|
16 | + <span><?php esc_html_e('Input Label', 'invoicing'); ?></span> |
|
17 | 17 | <input v-model='active_form_element.input_label' class='form-control' type="text"/> |
18 | 18 | </label> |
19 | 19 | </div> |
20 | 20 | |
21 | 21 | <div class='form-group mb-3'> |
22 | 22 | <label class="form-label d-block"> |
23 | - <span><?php esc_html_e( 'Button Label', 'invoicing' ); ?></span> |
|
23 | + <span><?php esc_html_e('Button Label', 'invoicing'); ?></span> |
|
24 | 24 | <input v-model='active_form_element.button_label' class='form-control' type="text"/> |
25 | 25 | </label> |
26 | 26 | </div> |
27 | 27 | |
28 | 28 | <div class='form-group mb-3'> |
29 | - <label class="form-label" :for="active_form_element.id + '_edit_type'"><?php esc_html_e( 'Button Type', 'invoicing' ); ?></label> |
|
29 | + <label class="form-label" :for="active_form_element.id + '_edit_type'"><?php esc_html_e('Button Type', 'invoicing'); ?></label> |
|
30 | 30 | <select class='form-control custom-select' :id="active_form_element.id + '_edit_type'" v-model='active_form_element.class'> |
31 | - <option disabled><?php esc_html_e( 'Select button type', 'invoicing' ); ?></option> |
|
32 | - <option value='btn-primary'><?php esc_html_e( 'Primary', 'invoicing' ); ?></option> |
|
33 | - <option value='btn-secondary'><?php esc_html_e( 'Secondary', 'invoicing' ); ?></option> |
|
34 | - <option value='btn-success'><?php esc_html_e( 'Success', 'invoicing' ); ?></option> |
|
35 | - <option value='btn-danger'><?php esc_html_e( 'Danger', 'invoicing' ); ?></option> |
|
36 | - <option value='btn-warning'><?php esc_html_e( 'Warning', 'invoicing' ); ?></option> |
|
37 | - <option value='btn-info'><?php esc_html_e( 'Info', 'invoicing' ); ?></option> |
|
38 | - <option value='btn-light'><?php esc_html_e( 'Light', 'invoicing' ); ?></option> |
|
39 | - <option value='btn-dark'><?php esc_html_e( 'Dark', 'invoicing' ); ?></option> |
|
40 | - <option value='btn-link'><?php esc_html_e( 'Link', 'invoicing' ); ?></option> |
|
31 | + <option disabled><?php esc_html_e('Select button type', 'invoicing'); ?></option> |
|
32 | + <option value='btn-primary'><?php esc_html_e('Primary', 'invoicing'); ?></option> |
|
33 | + <option value='btn-secondary'><?php esc_html_e('Secondary', 'invoicing'); ?></option> |
|
34 | + <option value='btn-success'><?php esc_html_e('Success', 'invoicing'); ?></option> |
|
35 | + <option value='btn-danger'><?php esc_html_e('Danger', 'invoicing'); ?></option> |
|
36 | + <option value='btn-warning'><?php esc_html_e('Warning', 'invoicing'); ?></option> |
|
37 | + <option value='btn-info'><?php esc_html_e('Info', 'invoicing'); ?></option> |
|
38 | + <option value='btn-light'><?php esc_html_e('Light', 'invoicing'); ?></option> |
|
39 | + <option value='btn-dark'><?php esc_html_e('Dark', 'invoicing'); ?></option> |
|
40 | + <option value='btn-link'><?php esc_html_e('Link', 'invoicing'); ?></option> |
|
41 | 41 | </select> |
42 | 42 | </div> |
43 | 43 | |
44 | 44 | <div class='form-group mb-3'> |
45 | 45 | <label class="form-label d-block"> |
46 | - <span><?php esc_html_e( 'Help Text', 'invoicing' ); ?></span> |
|
47 | - <textarea placeholder='<?php esc_attr_e( 'Add some help text for this field', 'invoicing' ); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea> |
|
48 | - <small class="form-text text-muted"><?php esc_html_e( 'HTML is allowed', 'invoicing' ); ?></small> |
|
46 | + <span><?php esc_html_e('Help Text', 'invoicing'); ?></span> |
|
47 | + <textarea placeholder='<?php esc_attr_e('Add some help text for this field', 'invoicing'); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea> |
|
48 | + <small class="form-text text-muted"><?php esc_html_e('HTML is allowed', 'invoicing'); ?></small> |
|
49 | 49 | </label> |
50 | 50 | </div> |
@@ -8,35 +8,35 @@ |
||
8 | 8 | * @var GetPaid_Payment_Form $form The current payment form |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | -if ( ! getpaid_has_published_discount() ) { |
|
13 | +if (!getpaid_has_published_discount()) { |
|
14 | 14 | return; |
15 | 15 | } |
16 | 16 | |
17 | -if ( ! empty( $description ) ) { |
|
17 | +if (!empty($description)) { |
|
18 | 18 | $description = "<small class='form-text text-muted'>$description</small>"; |
19 | 19 | } else { |
20 | 20 | $description = ''; |
21 | 21 | } |
22 | 22 | |
23 | 23 | $discount_code = ''; |
24 | -if ( ! empty( $form->invoice ) ) { |
|
24 | +if (!empty($form->invoice)) { |
|
25 | 25 | $discount_code = $form->invoice->get_discount_code(); |
26 | 26 | } |
27 | 27 | |
28 | -$class = empty( $class ) ? 'btn-secondary' : sanitize_html_class( $class ); |
|
28 | +$class = empty($class) ? 'btn-secondary' : sanitize_html_class($class); |
|
29 | 29 | ?> |
30 | 30 | |
31 | 31 | <div class="form-group mb-3"> |
32 | 32 | <div class="getpaid-discount-field border rounded p-3"> |
33 | 33 | <div class="getpaid-discount-field-inner d-flex flex-column flex-md-row"> |
34 | - <input name="discount" placeholder="<?php echo esc_attr( $input_label ); ?>" value="<?php echo esc_attr( $discount_code ); ?>" class="form-control mr-2 mb-2 getpaid-discount-field-input" style="flex: 1;" type="text"> |
|
35 | - <a href="#" class="btn <?php echo esc_attr( $class ); ?> submit-button mb-2 getpaid-discount-button"><?php echo esc_html( $button_label ); ?></a> |
|
34 | + <input name="discount" placeholder="<?php echo esc_attr($input_label); ?>" value="<?php echo esc_attr($discount_code); ?>" class="form-control mr-2 mb-2 getpaid-discount-field-input" style="flex: 1;" type="text"> |
|
35 | + <a href="#" class="btn <?php echo esc_attr($class); ?> submit-button mb-2 getpaid-discount-button"><?php echo esc_html($button_label); ?></a> |
|
36 | 36 | </div> |
37 | - <?php echo wp_kses_post( $description ); ?> |
|
37 | + <?php echo wp_kses_post($description); ?> |
|
38 | 38 | <div class="getpaid-custom-payment-form-errors alert alert-danger d-none"></div> |
39 | - <div class="getpaid-custom-payment-form-success alert alert-success d-none"><?php esc_html_e( 'Discount code applied!', 'invoicing' ); ?></div> |
|
39 | + <div class="getpaid-custom-payment-form-success alert alert-success d-none"><?php esc_html_e('Discount code applied!', 'invoicing'); ?></div> |
|
40 | 40 | </div> |
41 | 41 | </div> |
42 | 42 |
@@ -7,15 +7,15 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( ! defined( 'WPINC' ) ) { |
|
10 | +if (!defined('WPINC')) { |
|
11 | 11 | exit; |
12 | 12 | } |
13 | 13 | |
14 | 14 | |
15 | 15 | function wpinv_get_default_country() { |
16 | - $country = wpinv_get_option( 'default_country', 'UK' ); |
|
16 | + $country = wpinv_get_option('default_country', 'UK'); |
|
17 | 17 | |
18 | - return apply_filters( 'wpinv_default_country', $country ); |
|
18 | + return apply_filters('wpinv_default_country', $country); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @return string |
25 | 25 | */ |
26 | -function getpaid_get_ip_country( $ip_address = '' ) { |
|
27 | - $country = GetPaid_Geolocation::geolocate_ip( $ip_address, true ); |
|
26 | +function getpaid_get_ip_country($ip_address = '') { |
|
27 | + $country = GetPaid_Geolocation::geolocate_ip($ip_address, true); |
|
28 | 28 | return $country['country']; |
29 | 29 | } |
30 | 30 | |
@@ -34,59 +34,59 @@ discard block |
||
34 | 34 | * @param string $country The country code to sanitize |
35 | 35 | * @return array |
36 | 36 | */ |
37 | -function wpinv_sanitize_country( $country ) { |
|
37 | +function wpinv_sanitize_country($country) { |
|
38 | 38 | |
39 | 39 | // Enure the country is specified |
40 | - if ( empty( $country ) ) { |
|
40 | + if (empty($country)) { |
|
41 | 41 | $country = wpinv_get_default_country(); |
42 | 42 | } |
43 | - return trim( wpinv_utf8_strtoupper( $country ) ); |
|
43 | + return trim(wpinv_utf8_strtoupper($country)); |
|
44 | 44 | |
45 | 45 | } |
46 | 46 | |
47 | -function wpinv_is_base_country( $country ) { |
|
47 | +function wpinv_is_base_country($country) { |
|
48 | 48 | $base_country = wpinv_get_default_country(); |
49 | 49 | |
50 | - if ( $base_country === 'UK' ) { |
|
50 | + if ($base_country === 'UK') { |
|
51 | 51 | $base_country = 'GB'; |
52 | 52 | } |
53 | - if ( $country == 'UK' ) { |
|
53 | + if ($country == 'UK') { |
|
54 | 54 | $country = 'GB'; |
55 | 55 | } |
56 | 56 | |
57 | - return ( $country && $country === $base_country ) ? true : false; |
|
57 | + return ($country && $country === $base_country) ? true : false; |
|
58 | 58 | } |
59 | 59 | |
60 | -function wpinv_country_name( $country_code = '' ) { |
|
60 | +function wpinv_country_name($country_code = '') { |
|
61 | 61 | $countries = wpinv_get_country_list(); |
62 | 62 | $country_code = $country_code == 'UK' ? 'GB' : $country_code; |
63 | - $country = isset( $countries[ $country_code ] ) ? $countries[ $country_code ] : $country_code; |
|
63 | + $country = isset($countries[$country_code]) ? $countries[$country_code] : $country_code; |
|
64 | 64 | |
65 | - return apply_filters( 'wpinv_country_name', $country, $country_code ); |
|
65 | + return apply_filters('wpinv_country_name', $country, $country_code); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | function wpinv_get_default_state() { |
69 | - $state = wpinv_get_option( 'default_state', '' ); |
|
69 | + $state = wpinv_get_option('default_state', ''); |
|
70 | 70 | |
71 | - return apply_filters( 'wpinv_default_state', $state ); |
|
71 | + return apply_filters('wpinv_default_state', $state); |
|
72 | 72 | } |
73 | 73 | |
74 | -function wpinv_state_name( $state_code = '', $country_code = '' ) { |
|
74 | +function wpinv_state_name($state_code = '', $country_code = '') { |
|
75 | 75 | $state = $state_code; |
76 | 76 | |
77 | - if ( ! empty( $country_code ) ) { |
|
78 | - $states = wpinv_get_country_states( $country_code ); |
|
77 | + if (!empty($country_code)) { |
|
78 | + $states = wpinv_get_country_states($country_code); |
|
79 | 79 | |
80 | - $state = ! empty( $states ) && isset( $states[ $state_code ] ) ? $states[ $state_code ] : $state; |
|
80 | + $state = !empty($states) && isset($states[$state_code]) ? $states[$state_code] : $state; |
|
81 | 81 | } |
82 | 82 | |
83 | - return apply_filters( 'wpinv_state_name', $state, $state_code, $country_code ); |
|
83 | + return apply_filters('wpinv_state_name', $state, $state_code, $country_code); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | function wpinv_store_address() { |
87 | - $address = wpinv_get_option( 'store_address', '' ); |
|
87 | + $address = wpinv_get_option('store_address', ''); |
|
88 | 88 | |
89 | - return apply_filters( 'wpinv_store_address', $address ); |
|
89 | + return apply_filters('wpinv_store_address', $address); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -94,24 +94,24 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @param WPInv_Invoice $invoice |
96 | 96 | */ |
97 | -function getpaid_maybe_add_default_address( &$invoice ) { |
|
97 | +function getpaid_maybe_add_default_address(&$invoice) { |
|
98 | 98 | |
99 | 99 | $user_id = $invoice->get_user_id(); |
100 | 100 | |
101 | 101 | // Abort if the invoice belongs to no one. |
102 | - if ( empty( $user_id ) ) { |
|
102 | + if (empty($user_id)) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Fill in defaults whenever necessary. |
107 | - foreach ( wpinv_get_user_address( $user_id ) as $key => $value ) { |
|
107 | + foreach (wpinv_get_user_address($user_id) as $key => $value) { |
|
108 | 108 | |
109 | - if ( is_callable( $invoice, "get_$key" ) ) { |
|
110 | - $current = call_user_func( array( $invoice, "get_$key" ) ); |
|
109 | + if (is_callable($invoice, "get_$key")) { |
|
110 | + $current = call_user_func(array($invoice, "get_$key")); |
|
111 | 111 | |
112 | - if ( empty( $current ) ) { |
|
112 | + if (empty($current)) { |
|
113 | 113 | $method = "set_$key"; |
114 | - $invoice->$method( $value ); |
|
114 | + $invoice->$method($value); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | } |
@@ -123,27 +123,27 @@ discard block |
||
123 | 123 | * |
124 | 124 | * @return array |
125 | 125 | */ |
126 | -function getpaid_user_address_fields( $force_vat = false ) { |
|
126 | +function getpaid_user_address_fields($force_vat = false) { |
|
127 | 127 | |
128 | 128 | $address_fields = apply_filters( |
129 | 129 | 'getpaid_user_address_fields', |
130 | 130 | array( |
131 | - 'first_name' => __( 'First Name', 'invoicing' ), |
|
132 | - 'last_name' => __( 'Last Name', 'invoicing' ), |
|
133 | - 'address' => __( 'Address', 'invoicing' ), |
|
134 | - 'city' => __( 'City', 'invoicing' ), |
|
135 | - 'country' => __( 'Country', 'invoicing' ), |
|
136 | - 'state' => __( 'State', 'invoicing' ), |
|
137 | - 'zip' => __( 'Zip/Postal Code', 'invoicing' ), |
|
138 | - 'phone' => __( 'Phone Number', 'invoicing' ), |
|
139 | - 'company' => __( 'Company', 'invoicing' ), |
|
140 | - 'company_id' => __( 'Company ID', 'invoicing' ), |
|
141 | - 'vat_number' => __( 'VAT Number', 'invoicing' ), |
|
131 | + 'first_name' => __('First Name', 'invoicing'), |
|
132 | + 'last_name' => __('Last Name', 'invoicing'), |
|
133 | + 'address' => __('Address', 'invoicing'), |
|
134 | + 'city' => __('City', 'invoicing'), |
|
135 | + 'country' => __('Country', 'invoicing'), |
|
136 | + 'state' => __('State', 'invoicing'), |
|
137 | + 'zip' => __('Zip/Postal Code', 'invoicing'), |
|
138 | + 'phone' => __('Phone Number', 'invoicing'), |
|
139 | + 'company' => __('Company', 'invoicing'), |
|
140 | + 'company_id' => __('Company ID', 'invoicing'), |
|
141 | + 'vat_number' => __('VAT Number', 'invoicing'), |
|
142 | 142 | ) |
143 | 143 | ); |
144 | 144 | |
145 | - if ( ! wpinv_use_taxes() && isset( $address_fields['vat_number'] ) && ! wp_doing_ajax() && ! $force_vat ) { |
|
146 | - unset( $address_fields['vat_number'] ); |
|
145 | + if (!wpinv_use_taxes() && isset($address_fields['vat_number']) && !wp_doing_ajax() && !$force_vat) { |
|
146 | + unset($address_fields['vat_number']); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | return $address_fields; |
@@ -154,8 +154,8 @@ discard block |
||
154 | 154 | * |
155 | 155 | * @return bool |
156 | 156 | */ |
157 | -function getpaid_is_address_field_whitelisted( $key ) { |
|
158 | - return array_key_exists( $key, getpaid_user_address_fields() ); |
|
157 | +function getpaid_is_address_field_whitelisted($key) { |
|
158 | + return array_key_exists($key, getpaid_user_address_fields()); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -165,44 +165,44 @@ discard block |
||
165 | 165 | * |
166 | 166 | * @param WPInv_Invoice $invoice |
167 | 167 | */ |
168 | -function getpaid_save_invoice_user_address( $invoice ) { |
|
168 | +function getpaid_save_invoice_user_address($invoice) { |
|
169 | 169 | |
170 | 170 | // Retrieve the invoice. |
171 | - $invoice = wpinv_get_invoice( $invoice ); |
|
171 | + $invoice = wpinv_get_invoice($invoice); |
|
172 | 172 | |
173 | 173 | // Abort if it does not exist. |
174 | - if ( empty( $invoice ) || $invoice->is_renewal() ) { |
|
174 | + if (empty($invoice) || $invoice->is_renewal()) { |
|
175 | 175 | return; |
176 | 176 | } |
177 | 177 | |
178 | - $customer = getpaid_get_customer_by_user_id( $invoice->get_user_id() ); |
|
178 | + $customer = getpaid_get_customer_by_user_id($invoice->get_user_id()); |
|
179 | 179 | |
180 | - if ( empty( $customer ) ) { |
|
181 | - $customer = new GetPaid_Customer( 0 ); |
|
182 | - $customer->clone_user( $invoice->get_user_id() ); |
|
180 | + if (empty($customer)) { |
|
181 | + $customer = new GetPaid_Customer(0); |
|
182 | + $customer->clone_user($invoice->get_user_id()); |
|
183 | 183 | } |
184 | 184 | |
185 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
185 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
186 | 186 | |
187 | - if ( is_callable( array( $invoice, "get_$field" ) ) ) { |
|
188 | - $value = call_user_func( array( $invoice, "get_$field" ) ); |
|
187 | + if (is_callable(array($invoice, "get_$field"))) { |
|
188 | + $value = call_user_func(array($invoice, "get_$field")); |
|
189 | 189 | |
190 | 190 | // Only save if it is not empty. |
191 | - if ( ! empty( $value ) ) { |
|
192 | - $customer->set( $field, sanitize_text_field( $value ) ); |
|
191 | + if (!empty($value)) { |
|
192 | + $customer->set($field, sanitize_text_field($value)); |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | } |
196 | 196 | |
197 | 197 | $customer->save(); |
198 | 198 | |
199 | - if ( ! $invoice->get_customer_id() ) { |
|
200 | - $invoice->set_customer_id( $customer->get_id() ); |
|
199 | + if (!$invoice->get_customer_id()) { |
|
200 | + $invoice->set_customer_id($customer->get_id()); |
|
201 | 201 | $invoice->save(); |
202 | 202 | } |
203 | 203 | } |
204 | -add_action( 'getpaid_new_invoice', 'getpaid_save_invoice_user_address' ); |
|
205 | -add_action( 'getpaid_update_invoice', 'getpaid_save_invoice_user_address' ); |
|
204 | +add_action('getpaid_new_invoice', 'getpaid_save_invoice_user_address'); |
|
205 | +add_action('getpaid_update_invoice', 'getpaid_save_invoice_user_address'); |
|
206 | 206 | |
207 | 207 | /** |
208 | 208 | * Retrieves a saved user address. |
@@ -210,36 +210,36 @@ discard block |
||
210 | 210 | * @param int $user_id The user id whose address we should get. Defaults to the current user id. |
211 | 211 | * @return array |
212 | 212 | */ |
213 | -function wpinv_get_user_address( $user_id = 0 ) { |
|
213 | +function wpinv_get_user_address($user_id = 0) { |
|
214 | 214 | |
215 | 215 | // Prepare the user id. |
216 | - $user_id = empty( $user_id ) ? get_current_user_id() : $user_id; |
|
217 | - $user_info = get_userdata( $user_id ); |
|
216 | + $user_id = empty($user_id) ? get_current_user_id() : $user_id; |
|
217 | + $user_info = get_userdata($user_id); |
|
218 | 218 | |
219 | 219 | // Abort if non exists. |
220 | - if ( empty( $user_info ) ) { |
|
220 | + if (empty($user_info)) { |
|
221 | 221 | return array(); |
222 | 222 | } |
223 | 223 | |
224 | - $customer = getpaid_get_customer_by_user_id( $user_id ); |
|
224 | + $customer = getpaid_get_customer_by_user_id($user_id); |
|
225 | 225 | |
226 | - if ( empty( $customer ) ) { |
|
227 | - $customer = new GetPaid_Customer( 0 ); |
|
228 | - $customer->clone_user( $user_id ); |
|
226 | + if (empty($customer)) { |
|
227 | + $customer = new GetPaid_Customer(0); |
|
228 | + $customer->clone_user($user_id); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | // Prepare the address. |
232 | 232 | $address = array( |
233 | 233 | 'user_id' => $user_id, |
234 | - 'email' => $customer->get( 'email' ), |
|
234 | + 'email' => $customer->get('email'), |
|
235 | 235 | 'display_name' => $user_info->display_name, |
236 | 236 | ); |
237 | 237 | |
238 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
239 | - $address[ $field ] = $customer->get( $field ); |
|
238 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
239 | + $address[$field] = $customer->get($field); |
|
240 | 240 | } |
241 | 241 | |
242 | - $address = array_filter( $address ); |
|
242 | + $address = array_filter($address); |
|
243 | 243 | |
244 | 244 | $defaults = array( |
245 | 245 | 'first_name' => $user_info->first_name, |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | 'country' => wpinv_get_default_country(), |
249 | 249 | ); |
250 | 250 | |
251 | - return getpaid_array_merge_if_empty( $address, $defaults ); |
|
251 | + return getpaid_array_merge_if_empty($address, $defaults); |
|
252 | 252 | |
253 | 253 | } |
254 | 254 | |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | * @return string|null |
261 | 261 | * @deprecated |
262 | 262 | */ |
263 | -function getpaid_get_user_address_field( $user_id, $field ) { |
|
263 | +function getpaid_get_user_address_field($user_id, $field) { |
|
264 | 264 | |
265 | 265 | $prefixes = array( |
266 | 266 | '_wpinv_', |
@@ -268,15 +268,15 @@ discard block |
||
268 | 268 | '', |
269 | 269 | ); |
270 | 270 | |
271 | - foreach ( $prefixes as $prefix ) { |
|
271 | + foreach ($prefixes as $prefix) { |
|
272 | 272 | |
273 | 273 | // Meta table. |
274 | - $value = get_user_meta( $user_id, $prefix . $field, true ); |
|
274 | + $value = get_user_meta($user_id, $prefix . $field, true); |
|
275 | 275 | |
276 | 276 | // UWP table. |
277 | - $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value; |
|
277 | + $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value; |
|
278 | 278 | |
279 | - if ( ! empty( $value ) ) { |
|
279 | + if (!empty($value)) { |
|
280 | 280 | return $value; |
281 | 281 | } |
282 | 282 | } |
@@ -292,16 +292,16 @@ discard block |
||
292 | 292 | * @param string $return What to return. |
293 | 293 | * @return array |
294 | 294 | */ |
295 | -function wpinv_get_continents( $return = 'all' ) { |
|
295 | +function wpinv_get_continents($return = 'all') { |
|
296 | 296 | |
297 | - $continents = wpinv_get_data( 'continents' ); |
|
297 | + $continents = wpinv_get_data('continents'); |
|
298 | 298 | |
299 | - switch ( $return ) { |
|
299 | + switch ($return) { |
|
300 | 300 | case 'name': |
301 | - return wp_list_pluck( $continents, 'name' ); |
|
301 | + return wp_list_pluck($continents, 'name'); |
|
302 | 302 | break; |
303 | 303 | case 'countries': |
304 | - return wp_list_pluck( $continents, 'countries' ); |
|
304 | + return wp_list_pluck($continents, 'countries'); |
|
305 | 305 | break; |
306 | 306 | default: |
307 | 307 | return $continents; |
@@ -317,12 +317,12 @@ discard block |
||
317 | 317 | * @param string $country Country code. If no code is specified, defaults to the default country. |
318 | 318 | * @return string |
319 | 319 | */ |
320 | -function wpinv_get_continent_code_for_country( $country = false ) { |
|
320 | +function wpinv_get_continent_code_for_country($country = false) { |
|
321 | 321 | |
322 | - $country = wpinv_sanitize_country( $country ); |
|
322 | + $country = wpinv_sanitize_country($country); |
|
323 | 323 | |
324 | - foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
325 | - if ( false !== array_search( $country, $countries, true ) ) { |
|
324 | + foreach (wpinv_get_continents('countries') as $continent_code => $countries) { |
|
325 | + if (false !== array_search($country, $countries, true)) { |
|
326 | 326 | return $continent_code; |
327 | 327 | } |
328 | 328 | } |
@@ -338,13 +338,13 @@ discard block |
||
338 | 338 | * @param string $country Country code. If no code is specified, defaults to the default country. |
339 | 339 | * @return array |
340 | 340 | */ |
341 | -function wpinv_get_country_calling_code( $country = null ) { |
|
341 | +function wpinv_get_country_calling_code($country = null) { |
|
342 | 342 | |
343 | - $country = wpinv_sanitize_country( $country ); |
|
344 | - $codes = wpinv_get_data( 'phone-codes' ); |
|
345 | - $code = isset( $codes[ $country ] ) ? $codes[ $country ] : ''; |
|
343 | + $country = wpinv_sanitize_country($country); |
|
344 | + $codes = wpinv_get_data('phone-codes'); |
|
345 | + $code = isset($codes[$country]) ? $codes[$country] : ''; |
|
346 | 346 | |
347 | - if ( is_array( $code ) ) { |
|
347 | + if (is_array($code)) { |
|
348 | 348 | return $code[0]; |
349 | 349 | } |
350 | 350 | return $code; |
@@ -357,8 +357,8 @@ discard block |
||
357 | 357 | * @param bool $first_empty Whether or not the first item in the list should be empty |
358 | 358 | * @return array |
359 | 359 | */ |
360 | -function wpinv_get_country_list( $first_empty = false ) { |
|
361 | - return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty ); |
|
360 | +function wpinv_get_country_list($first_empty = false) { |
|
361 | + return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | /** |
@@ -368,22 +368,22 @@ discard block |
||
368 | 368 | * @param bool $first_empty Whether or not the first item in the list should be empty |
369 | 369 | * @return array |
370 | 370 | */ |
371 | -function wpinv_get_country_states( $country = null, $first_empty = false ) { |
|
371 | +function wpinv_get_country_states($country = null, $first_empty = false) { |
|
372 | 372 | |
373 | 373 | // Prepare the country. |
374 | - $country = wpinv_sanitize_country( $country ); |
|
374 | + $country = wpinv_sanitize_country($country); |
|
375 | 375 | |
376 | 376 | // Fetch all states. |
377 | - $all_states = wpinv_get_data( 'states' ); |
|
377 | + $all_states = wpinv_get_data('states'); |
|
378 | 378 | |
379 | 379 | // Fetch the specified country's states. |
380 | - $states = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array(); |
|
381 | - $states = apply_filters( "wpinv_{$country}_states", $states ); |
|
382 | - $states = apply_filters( 'wpinv_country_states', $states, $country ); |
|
380 | + $states = isset($all_states[$country]) ? $all_states[$country] : array(); |
|
381 | + $states = apply_filters("wpinv_{$country}_states", $states); |
|
382 | + $states = apply_filters('wpinv_country_states', $states, $country); |
|
383 | 383 | |
384 | - asort( $states ); |
|
384 | + asort($states); |
|
385 | 385 | |
386 | - return wpinv_maybe_add_empty_option( $states, $first_empty ); |
|
386 | + return wpinv_maybe_add_empty_option($states, $first_empty); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | /** |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | * @return array |
394 | 394 | */ |
395 | 395 | function wpinv_get_us_states_list() { |
396 | - return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) ); |
|
396 | + return apply_filters('wpinv_usa_states', wpinv_get_country_states('US')); |
|
397 | 397 | } |
398 | 398 | |
399 | 399 | /** |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | * @return array |
404 | 404 | */ |
405 | 405 | function wpinv_get_canada_states_list() { |
406 | - return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) ); |
|
406 | + return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA')); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | * @return array |
414 | 414 | */ |
415 | 415 | function wpinv_get_australia_states_list() { |
416 | - return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) ); |
|
416 | + return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU')); |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | /** |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | * @return array |
424 | 424 | */ |
425 | 425 | function wpinv_get_bangladesh_states_list() { |
426 | - return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) ); |
|
426 | + return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD')); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | /** |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | * @return array |
434 | 434 | */ |
435 | 435 | function wpinv_get_brazil_states_list() { |
436 | - return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) ); |
|
436 | + return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR')); |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | /** |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | * @return array |
444 | 444 | */ |
445 | 445 | function wpinv_get_bulgaria_states_list() { |
446 | - return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) ); |
|
446 | + return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG')); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | * @return array |
454 | 454 | */ |
455 | 455 | function wpinv_get_hong_kong_states_list() { |
456 | - return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) ); |
|
456 | + return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK')); |
|
457 | 457 | } |
458 | 458 | |
459 | 459 | /** |
@@ -463,7 +463,7 @@ discard block |
||
463 | 463 | * @return array |
464 | 464 | */ |
465 | 465 | function wpinv_get_hungary_states_list() { |
466 | - return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) ); |
|
466 | + return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU')); |
|
467 | 467 | } |
468 | 468 | |
469 | 469 | /** |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | * @return array |
474 | 474 | */ |
475 | 475 | function wpinv_get_japan_states_list() { |
476 | - return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) ); |
|
476 | + return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP')); |
|
477 | 477 | } |
478 | 478 | |
479 | 479 | /** |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | * @return array |
484 | 484 | */ |
485 | 485 | function wpinv_get_china_states_list() { |
486 | - return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) ); |
|
486 | + return apply_filters('wpinv_china_states', wpinv_get_country_states('CN')); |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | /** |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | * @return array |
494 | 494 | */ |
495 | 495 | function wpinv_get_new_zealand_states_list() { |
496 | - return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) ); |
|
496 | + return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ')); |
|
497 | 497 | } |
498 | 498 | |
499 | 499 | /** |
@@ -503,7 +503,7 @@ discard block |
||
503 | 503 | * @return array |
504 | 504 | */ |
505 | 505 | function wpinv_get_peru_states_list() { |
506 | - return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) ); |
|
506 | + return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE')); |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | /** |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | * @return array |
514 | 514 | */ |
515 | 515 | function wpinv_get_indonesia_states_list() { |
516 | - return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) ); |
|
516 | + return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID')); |
|
517 | 517 | } |
518 | 518 | |
519 | 519 | /** |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | * @return array |
524 | 524 | */ |
525 | 525 | function wpinv_get_india_states_list() { |
526 | - return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) ); |
|
526 | + return apply_filters('wpinv_india_states', wpinv_get_country_states('IN')); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | * @return array |
534 | 534 | */ |
535 | 535 | function wpinv_get_iran_states_list() { |
536 | - return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) ); |
|
536 | + return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR')); |
|
537 | 537 | } |
538 | 538 | |
539 | 539 | /** |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | * @return array |
544 | 544 | */ |
545 | 545 | function wpinv_get_italy_states_list() { |
546 | - return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) ); |
|
546 | + return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT')); |
|
547 | 547 | } |
548 | 548 | |
549 | 549 | /** |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | * @return array |
554 | 554 | */ |
555 | 555 | function wpinv_get_malaysia_states_list() { |
556 | - return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) ); |
|
556 | + return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY')); |
|
557 | 557 | } |
558 | 558 | |
559 | 559 | /** |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | * @return array |
564 | 564 | */ |
565 | 565 | function wpinv_get_mexico_states_list() { |
566 | - return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) ); |
|
566 | + return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX')); |
|
567 | 567 | } |
568 | 568 | |
569 | 569 | /** |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | * @return array |
574 | 574 | */ |
575 | 575 | function wpinv_get_nepal_states_list() { |
576 | - return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) ); |
|
576 | + return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP')); |
|
577 | 577 | } |
578 | 578 | |
579 | 579 | /** |
@@ -583,7 +583,7 @@ discard block |
||
583 | 583 | * @return array |
584 | 584 | */ |
585 | 585 | function wpinv_get_south_africa_states_list() { |
586 | - return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) ); |
|
586 | + return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA')); |
|
587 | 587 | } |
588 | 588 | |
589 | 589 | /** |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | * @return array |
594 | 594 | */ |
595 | 595 | function wpinv_get_thailand_states_list() { |
596 | - return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) ); |
|
596 | + return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH')); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | /** |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | * @return array |
604 | 604 | */ |
605 | 605 | function wpinv_get_turkey_states_list() { |
606 | - return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) ); |
|
606 | + return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR')); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | /** |
@@ -613,31 +613,31 @@ discard block |
||
613 | 613 | * @return array |
614 | 614 | */ |
615 | 615 | function wpinv_get_spain_states_list() { |
616 | - return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) ); |
|
616 | + return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES')); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | function wpinv_get_states_field() { |
620 | - if ( empty( $_POST['country'] ) ) { |
|
620 | + if (empty($_POST['country'])) { |
|
621 | 621 | $_POST['country'] = wpinv_get_default_country(); |
622 | 622 | } |
623 | - $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
623 | + $states = wpinv_get_country_states(sanitize_text_field($_POST['country'])); |
|
624 | 624 | |
625 | - if ( ! empty( $states ) ) { |
|
626 | - $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
625 | + if (!empty($states)) { |
|
626 | + $sanitized_field_name = sanitize_text_field($_POST['field_name']); |
|
627 | 627 | |
628 | - $class = isset( $_POST['class'] ) ? esc_attr( sanitize_text_field( $_POST['class'] ) ) : ''; |
|
628 | + $class = isset($_POST['class']) ? esc_attr(sanitize_text_field($_POST['class'])) : ''; |
|
629 | 629 | $class .= " $sanitized_field_name getpaid_js_field-state custom-select wpinv-select wpi_select2"; |
630 | 630 | |
631 | - $args = array( |
|
631 | + $args = array( |
|
632 | 632 | 'name' => $sanitized_field_name, |
633 | 633 | 'id' => $sanitized_field_name, |
634 | - 'class' => implode( ' ', array_unique( explode( ' ', $class ) ) ), |
|
635 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
634 | + 'class' => implode(' ', array_unique(explode(' ', $class))), |
|
635 | + 'options' => array_merge(array('' => ''), $states), |
|
636 | 636 | 'show_option_all' => false, |
637 | 637 | 'show_option_none' => false, |
638 | 638 | ); |
639 | 639 | |
640 | - wpinv_html_select( $args ); |
|
640 | + wpinv_html_select($args); |
|
641 | 641 | |
642 | 642 | } else { |
643 | 643 | echo 'nostates'; |
@@ -645,10 +645,10 @@ discard block |
||
645 | 645 | |
646 | 646 | } |
647 | 647 | |
648 | -function wpinv_default_billing_country( $country = '', $user_id = 0 ) { |
|
649 | - $country = ! empty( $country ) ? $country : wpinv_get_default_country(); |
|
648 | +function wpinv_default_billing_country($country = '', $user_id = 0) { |
|
649 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
650 | 650 | |
651 | - return apply_filters( 'wpinv_default_billing_country', $country, $user_id ); |
|
651 | + return apply_filters('wpinv_default_billing_country', $country, $user_id); |
|
652 | 652 | } |
653 | 653 | |
654 | 654 | /** |
@@ -710,9 +710,9 @@ discard block |
||
710 | 710 | * @see `wpinv_get_invoice_address_replacements` |
711 | 711 | * @return string |
712 | 712 | */ |
713 | -function wpinv_get_full_address_format( $country = false ) { |
|
713 | +function wpinv_get_full_address_format($country = false) { |
|
714 | 714 | |
715 | - if ( empty( $country ) ) { |
|
715 | + if (empty($country)) { |
|
716 | 716 | $country = wpinv_get_default_country(); |
717 | 717 | } |
718 | 718 | |
@@ -720,7 +720,7 @@ discard block |
||
720 | 720 | $formats = wpinv_get_address_formats(); |
721 | 721 | |
722 | 722 | // Get format for the specified country. |
723 | - $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
723 | + $format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default']; |
|
724 | 724 | |
725 | 725 | /** |
726 | 726 | * Filters the address format to use on Invoices. |
@@ -732,7 +732,7 @@ discard block |
||
732 | 732 | * @param string $format The address format to use. |
733 | 733 | * @param string $country The country who's address format is being retrieved. |
734 | 734 | */ |
735 | - return apply_filters( 'wpinv_get_full_address_format', $format, $country ); |
|
735 | + return apply_filters('wpinv_get_full_address_format', $format, $country); |
|
736 | 736 | } |
737 | 737 | |
738 | 738 | /** |
@@ -743,7 +743,7 @@ discard block |
||
743 | 743 | * @param array $billing_details customer's billing details |
744 | 744 | * @return array |
745 | 745 | */ |
746 | -function wpinv_get_invoice_address_replacements( $billing_details ) { |
|
746 | +function wpinv_get_invoice_address_replacements($billing_details) { |
|
747 | 747 | |
748 | 748 | $default_args = array( |
749 | 749 | 'address' => '', |
@@ -756,15 +756,15 @@ discard block |
||
756 | 756 | 'company' => '', |
757 | 757 | ); |
758 | 758 | |
759 | - $args = map_deep( wp_parse_args( array_filter( $billing_details ), $default_args ), 'trim' ); |
|
759 | + $args = map_deep(wp_parse_args(array_filter($billing_details), $default_args), 'trim'); |
|
760 | 760 | $state = $args['state']; |
761 | 761 | $country = $args['country']; |
762 | 762 | |
763 | 763 | // Handle full country name. |
764 | - $full_country = empty( $country ) ? $country : wpinv_country_name( $country ); |
|
764 | + $full_country = empty($country) ? $country : wpinv_country_name($country); |
|
765 | 765 | |
766 | 766 | // Handle full state name. |
767 | - $full_state = ( $country && $state ) ? wpinv_state_name( $state, $country ) : $state; |
|
767 | + $full_state = ($country && $state) ? wpinv_state_name($state, $country) : $state; |
|
768 | 768 | |
769 | 769 | $args['postcode'] = $args['zip']; |
770 | 770 | $args['name'] = $args['first_name'] . ' ' . $args['last_name']; |
@@ -782,14 +782,14 @@ discard block |
||
782 | 782 | * @param array $replacements The address replacements to use. |
783 | 783 | * @param array $billing_details The billing details to use. |
784 | 784 | */ |
785 | - $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details ); |
|
785 | + $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details); |
|
786 | 786 | |
787 | 787 | $return = array(); |
788 | 788 | |
789 | - foreach ( $replacements as $key => $value ) { |
|
790 | - $value = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : ''; |
|
791 | - $return[ '{{' . $key . '}}' ] = $value; |
|
792 | - $return[ '{{' . $key . '_upper}}' ] = wpinv_utf8_strtoupper( $value ); |
|
789 | + foreach ($replacements as $key => $value) { |
|
790 | + $value = is_scalar($value) ? trim(sanitize_text_field($value)) : ''; |
|
791 | + $return['{{' . $key . '}}'] = $value; |
|
792 | + $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value); |
|
793 | 793 | } |
794 | 794 | |
795 | 795 | return $return; |
@@ -803,6 +803,6 @@ discard block |
||
803 | 803 | * @since 1.0.14 |
804 | 804 | * @return string |
805 | 805 | */ |
806 | -function wpinv_trim_formatted_address_line( $line ) { |
|
807 | - return trim( $line, ', ' ); |
|
806 | +function wpinv_trim_formatted_address_line($line) { |
|
807 | + return trim($line, ', '); |
|
808 | 808 | } |