@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Payment form submission taxes class |
@@ -29,22 +29,22 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @param GetPaid_Payment_Form_Submission $submission |
31 | 31 | */ |
32 | - public function __construct( $submission ) { |
|
32 | + public function __construct($submission) { |
|
33 | 33 | |
34 | 34 | // Validate VAT number. |
35 | - $this->validate_vat( $submission ); |
|
35 | + $this->validate_vat($submission); |
|
36 | 36 | |
37 | - if ( $this->skip_taxes ) { |
|
37 | + if ($this->skip_taxes) { |
|
38 | 38 | return; |
39 | 39 | } |
40 | 40 | |
41 | - foreach ( $submission->get_items() as $item ) { |
|
42 | - $this->process_item_tax( $item, $submission ); |
|
41 | + foreach ($submission->get_items() as $item) { |
|
42 | + $this->process_item_tax($item, $submission); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | // Process any existing invoice taxes. |
46 | - if ( $submission->has_invoice() ) { |
|
47 | - $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
46 | + if ($submission->has_invoice()) { |
|
47 | + $this->taxes = array_replace($submission->get_invoice()->get_taxes(), $this->taxes); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | } |
@@ -56,26 +56,26 @@ discard block |
||
56 | 56 | * @param GetPaid_Form_Item $item |
57 | 57 | * @param GetPaid_Payment_Form_Submission $submission |
58 | 58 | */ |
59 | - public function process_item_tax( $item, $submission ) { |
|
59 | + public function process_item_tax($item, $submission) { |
|
60 | 60 | |
61 | - $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
62 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
63 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
64 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
61 | + $rates = getpaid_get_item_tax_rates($item, $submission->country, $submission->state); |
|
62 | + $rates = getpaid_filter_item_tax_rates($item, $rates); |
|
63 | + $taxes = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, false), $rates); |
|
64 | + $r_taxes = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, true), $rates); |
|
65 | 65 | |
66 | - foreach ( $taxes as $name => $amount ) { |
|
67 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
68 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
66 | + foreach ($taxes as $name => $amount) { |
|
67 | + $recurring = isset($r_taxes[$name]) ? $r_taxes[$name] : 0; |
|
68 | + $tax = getpaid_prepare_item_tax($item, $name, $amount, $recurring); |
|
69 | 69 | |
70 | - $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
70 | + $item->item_tax += wpinv_sanitize_amount($tax['initial_tax']); |
|
71 | 71 | |
72 | - if ( ! isset( $this->taxes[ $name ] ) ) { |
|
73 | - $this->taxes[ $name ] = $tax; |
|
72 | + if (!isset($this->taxes[$name])) { |
|
73 | + $this->taxes[$name] = $tax; |
|
74 | 74 | continue; |
75 | 75 | } |
76 | 76 | |
77 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
78 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
77 | + $this->taxes[$name]['initial_tax'] += $tax['initial_tax']; |
|
78 | + $this->taxes[$name]['recurring_tax'] += $tax['recurring_tax']; |
|
79 | 79 | |
80 | 80 | } |
81 | 81 | |
@@ -88,11 +88,11 @@ discard block |
||
88 | 88 | * @since 1.0.19 |
89 | 89 | * @return bool |
90 | 90 | */ |
91 | - public function has_digital_item( $submission ) { |
|
91 | + public function has_digital_item($submission) { |
|
92 | 92 | |
93 | - foreach ( $submission->get_items() as $item ) { |
|
93 | + foreach ($submission->get_items() as $item) { |
|
94 | 94 | |
95 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
95 | + if ('digital' == $item->get_vat_rule()) { |
|
96 | 96 | return true; |
97 | 97 | } |
98 | 98 | |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * @return bool |
109 | 109 | */ |
110 | 110 | public static function is_eu_store() { |
111 | - return self::is_eu_country( wpinv_get_default_country() ); |
|
111 | + return self::is_eu_country(wpinv_get_default_country()); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | * @since 1.0.19 |
119 | 119 | * @return bool |
120 | 120 | */ |
121 | - public static function is_eu_country( $country ) { |
|
122 | - return getpaid_is_eu_state( $country ); |
|
121 | + public static function is_eu_country($country) { |
|
122 | + return getpaid_is_eu_state($country); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | * @since 1.0.19 |
130 | 130 | * @return bool |
131 | 131 | */ |
132 | - public static function is_eu_transaction( $customer_country ) { |
|
133 | - return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
132 | + public static function is_eu_transaction($customer_country) { |
|
133 | + return self::is_eu_country($customer_country) && self::is_eu_store(); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -140,12 +140,12 @@ discard block |
||
140 | 140 | * @since 1.0.19 |
141 | 141 | * @return string |
142 | 142 | */ |
143 | - public function get_vat_number( $submission ) { |
|
143 | + public function get_vat_number($submission) { |
|
144 | 144 | |
145 | 145 | // Retrieve from the posted number. |
146 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
147 | - if ( ! is_null( $vat_number ) ) { |
|
148 | - return wpinv_clean( $vat_number ); |
|
146 | + $vat_number = $submission->get_field('wpinv_vat_number', 'billing'); |
|
147 | + if (!is_null($vat_number)) { |
|
148 | + return wpinv_clean($vat_number); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
@@ -158,12 +158,12 @@ discard block |
||
158 | 158 | * @since 1.0.19 |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - public function get_company( $submission ) { |
|
161 | + public function get_company($submission) { |
|
162 | 162 | |
163 | 163 | // Retrieve from the posted data. |
164 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
165 | - if ( ! empty( $company ) ) { |
|
166 | - return wpinv_clean( $company ); |
|
164 | + $company = $submission->get_field('wpinv_company', 'billing'); |
|
165 | + if (!empty($company)) { |
|
166 | + return wpinv_clean($company); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | // Retrieve from the invoice. |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | * @since 1.0.19 |
179 | 179 | * @return string |
180 | 180 | */ |
181 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
181 | + public function requires_vat($ip_in_eu, $country_in_eu) { |
|
182 | 182 | |
183 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
184 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
183 | + $prevent_b2c = wpinv_get_option('vat_prevent_b2c_purchase'); |
|
184 | + $prevent_b2c = !empty($prevent_b2c); |
|
185 | 185 | $is_eu = $ip_in_eu || $country_in_eu; |
186 | 186 | |
187 | 187 | return $prevent_b2c && $is_eu; |
@@ -193,45 +193,45 @@ discard block |
||
193 | 193 | * @param GetPaid_Payment_Form_Submission $submission |
194 | 194 | * @since 1.0.19 |
195 | 195 | */ |
196 | - public function validate_vat( $submission ) { |
|
196 | + public function validate_vat($submission) { |
|
197 | 197 | |
198 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
198 | + $in_eu = $this->is_eu_transaction($submission->country); |
|
199 | 199 | |
200 | 200 | // Abort if we are not validating vat numbers. |
201 | - if ( ! $in_eu ) { |
|
201 | + if (!$in_eu) { |
|
202 | 202 | return; |
203 | 203 | } |
204 | 204 | |
205 | 205 | // Prepare variables. |
206 | - $vat_number = $this->get_vat_number( $submission ); |
|
206 | + $vat_number = $this->get_vat_number($submission); |
|
207 | 207 | $ip_country = getpaid_get_ip_country(); |
208 | - $is_eu = $this->is_eu_country( $submission->country ); |
|
209 | - $is_ip_eu = $this->is_eu_country( $ip_country ); |
|
208 | + $is_eu = $this->is_eu_country($submission->country); |
|
209 | + $is_ip_eu = $this->is_eu_country($ip_country); |
|
210 | 210 | |
211 | 211 | // Maybe abort early for initial fetches. |
212 | - if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
212 | + if ($submission->is_initial_fetch() && empty($vat_number)) { |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 | |
216 | 216 | // If we're preventing business to consumer purchases, |
217 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
217 | + if ($this->requires_vat($is_ip_eu, $is_eu) && empty($vat_number)) { |
|
218 | 218 | |
219 | 219 | // Ensure that a vat number has been specified. |
220 | 220 | throw new Exception( |
221 | - __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) |
|
221 | + __('Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing') |
|
222 | 222 | ); |
223 | 223 | |
224 | 224 | } |
225 | 225 | |
226 | - if ( empty( $vat_number ) ) { |
|
226 | + if (empty($vat_number)) { |
|
227 | 227 | return; |
228 | 228 | } |
229 | 229 | |
230 | - if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
231 | - throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
230 | + if (wpinv_should_validate_vat_number() && !wpinv_validate_vat_number($vat_number, $submission->country)) { |
|
231 | + throw new Exception(__('Your VAT number is invalid', 'invoicing')); |
|
232 | 232 | } |
233 | 233 | |
234 | - if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
234 | + if (wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option('vat_same_country_rule', 'vat_too')) { |
|
235 | 235 | return; |
236 | 236 | } |
237 | 237 |
@@ -7,15 +7,15 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | |
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 | } |
@@ -130,21 +130,21 @@ discard block |
||
130 | 130 | $address_fields = apply_filters( |
131 | 131 | 'getpaid_user_address_fields', |
132 | 132 | array( |
133 | - 'first_name' => __( 'First Name', 'invoicing' ), |
|
134 | - 'last_name' => __( 'Last Name', 'invoicing' ), |
|
135 | - 'address' => __( 'Address', 'invoicing' ), |
|
136 | - 'city' => __( 'City', 'invoicing' ), |
|
137 | - 'country' => __( 'Country', 'invoicing' ), |
|
138 | - 'state' => __( 'State', 'invoicing' ), |
|
139 | - 'zip' => __( 'Zip/Postal Code', 'invoicing' ), |
|
140 | - 'phone' => __( 'Phone Number', 'invoicing' ), |
|
141 | - 'company' => __( 'Company', 'invoicing' ), |
|
142 | - 'vat_number' => __( 'VAT Number', 'invoicing' ), |
|
133 | + 'first_name' => __('First Name', 'invoicing'), |
|
134 | + 'last_name' => __('Last Name', 'invoicing'), |
|
135 | + 'address' => __('Address', 'invoicing'), |
|
136 | + 'city' => __('City', 'invoicing'), |
|
137 | + 'country' => __('Country', 'invoicing'), |
|
138 | + 'state' => __('State', 'invoicing'), |
|
139 | + 'zip' => __('Zip/Postal Code', 'invoicing'), |
|
140 | + 'phone' => __('Phone Number', 'invoicing'), |
|
141 | + 'company' => __('Company', 'invoicing'), |
|
142 | + 'vat_number' => __('VAT Number', 'invoicing'), |
|
143 | 143 | ) |
144 | 144 | ); |
145 | 145 | |
146 | - if ( ! wpinv_use_taxes() && isset( $address_fields['vat_number'] ) ) { |
|
147 | - unset( $address_fields['vat_number'] ); |
|
146 | + if (!wpinv_use_taxes() && isset($address_fields['vat_number'])) { |
|
147 | + unset($address_fields['vat_number']); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | return $address_fields; |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | * |
156 | 156 | * @return bool |
157 | 157 | */ |
158 | -function getpaid_is_address_field_whitelisted( $key ) { |
|
159 | - return array_key_exists( $key, getpaid_user_address_fields() ); |
|
158 | +function getpaid_is_address_field_whitelisted($key) { |
|
159 | + return array_key_exists($key, getpaid_user_address_fields()); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
@@ -166,24 +166,24 @@ discard block |
||
166 | 166 | * |
167 | 167 | * @param WPInv_Invoice $invoice |
168 | 168 | */ |
169 | -function getpaid_save_invoice_user_address( $invoice ) { |
|
169 | +function getpaid_save_invoice_user_address($invoice) { |
|
170 | 170 | |
171 | 171 | // Retrieve the invoice. |
172 | - $invoice = wpinv_get_invoice( $invoice ); |
|
172 | + $invoice = wpinv_get_invoice($invoice); |
|
173 | 173 | |
174 | 174 | // Abort if it does not exist. |
175 | - if ( empty( $invoice ) || $invoice->is_renewal() ) { |
|
175 | + if (empty($invoice) || $invoice->is_renewal()) { |
|
176 | 176 | return; |
177 | 177 | } |
178 | 178 | |
179 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
179 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
180 | 180 | |
181 | - if ( is_callable( array( $invoice, "get_$field" ) ) ) { |
|
182 | - $value = call_user_func( array( $invoice, "get_$field" ) ); |
|
181 | + if (is_callable(array($invoice, "get_$field"))) { |
|
182 | + $value = call_user_func(array($invoice, "get_$field")); |
|
183 | 183 | |
184 | 184 | // Only save if it is not empty. |
185 | - if ( ! empty( $value ) ) { |
|
186 | - update_user_meta( $invoice->get_user_id(), '_wpinv_' . $field, $value ); |
|
185 | + if (!empty($value)) { |
|
186 | + update_user_meta($invoice->get_user_id(), '_wpinv_' . $field, $value); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | } |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | } |
192 | 192 | |
193 | 193 | } |
194 | -add_action( 'getpaid_checkout_invoice_updated', 'getpaid_save_invoice_user_address' ); |
|
194 | +add_action('getpaid_checkout_invoice_updated', 'getpaid_save_invoice_user_address'); |
|
195 | 195 | |
196 | 196 | /** |
197 | 197 | * Retrieves a saved user address. |
@@ -200,14 +200,14 @@ discard block |
||
200 | 200 | * @param bool $with_default Whether or not we should use the default country and state. |
201 | 201 | * @return array |
202 | 202 | */ |
203 | -function wpinv_get_user_address( $user_id = 0, $with_default = true ) { |
|
203 | +function wpinv_get_user_address($user_id = 0, $with_default = true) { |
|
204 | 204 | |
205 | 205 | // Prepare the user id. |
206 | - $user_id = empty( $user_id ) ? get_current_user_id() : $user_id; |
|
207 | - $user_info = get_userdata( $user_id ); |
|
206 | + $user_id = empty($user_id) ? get_current_user_id() : $user_id; |
|
207 | + $user_info = get_userdata($user_id); |
|
208 | 208 | |
209 | 209 | // Abort if non exists. |
210 | - if ( empty( $user_info ) ) { |
|
210 | + if (empty($user_info)) { |
|
211 | 211 | return array(); |
212 | 212 | } |
213 | 213 | |
@@ -217,11 +217,11 @@ discard block |
||
217 | 217 | 'email' => $user_info->user_email, |
218 | 218 | ); |
219 | 219 | |
220 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
221 | - $address[$field] = getpaid_get_user_address_field( $user_id, $field ); |
|
220 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
221 | + $address[$field] = getpaid_get_user_address_field($user_id, $field); |
|
222 | 222 | } |
223 | 223 | |
224 | - if ( ! $with_default ) { |
|
224 | + if (!$with_default) { |
|
225 | 225 | return $address; |
226 | 226 | } |
227 | 227 | |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | 'country' => wpinv_get_default_country(), |
233 | 233 | ); |
234 | 234 | |
235 | - return getpaid_array_merge_if_empty( $address, $defaults ); |
|
235 | + return getpaid_array_merge_if_empty($address, $defaults); |
|
236 | 236 | |
237 | 237 | } |
238 | 238 | |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | * @param string $field The field to use. |
244 | 244 | * @return string|null |
245 | 245 | */ |
246 | -function getpaid_get_user_address_field( $user_id, $field ) { |
|
246 | +function getpaid_get_user_address_field($user_id, $field) { |
|
247 | 247 | |
248 | 248 | $prefixes = array( |
249 | 249 | '_wpinv_', |
@@ -251,15 +251,15 @@ discard block |
||
251 | 251 | '' |
252 | 252 | ); |
253 | 253 | |
254 | - foreach ( $prefixes as $prefix ) { |
|
254 | + foreach ($prefixes as $prefix) { |
|
255 | 255 | |
256 | 256 | // Meta table. |
257 | - $value = get_user_meta( $user_id, $prefix . $field, true ); |
|
257 | + $value = get_user_meta($user_id, $prefix . $field, true); |
|
258 | 258 | |
259 | 259 | // UWP table. |
260 | - $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value; |
|
260 | + $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value; |
|
261 | 261 | |
262 | - if ( ! empty( $value ) ) { |
|
262 | + if (!empty($value)) { |
|
263 | 263 | return $value; |
264 | 264 | } |
265 | 265 | |
@@ -276,16 +276,16 @@ discard block |
||
276 | 276 | * @param string $return What to return. |
277 | 277 | * @return array |
278 | 278 | */ |
279 | -function wpinv_get_continents( $return = 'all' ) { |
|
279 | +function wpinv_get_continents($return = 'all') { |
|
280 | 280 | |
281 | - $continents = wpinv_get_data( 'continents' ); |
|
281 | + $continents = wpinv_get_data('continents'); |
|
282 | 282 | |
283 | - switch( $return ) { |
|
283 | + switch ($return) { |
|
284 | 284 | case 'name' : |
285 | - return wp_list_pluck( $continents, 'name' ); |
|
285 | + return wp_list_pluck($continents, 'name'); |
|
286 | 286 | break; |
287 | 287 | case 'countries' : |
288 | - return wp_list_pluck( $continents, 'countries' ); |
|
288 | + return wp_list_pluck($continents, 'countries'); |
|
289 | 289 | break; |
290 | 290 | default : |
291 | 291 | return $continents; |
@@ -301,12 +301,12 @@ discard block |
||
301 | 301 | * @param string $country Country code. If no code is specified, defaults to the default country. |
302 | 302 | * @return string |
303 | 303 | */ |
304 | -function wpinv_get_continent_code_for_country( $country = false ) { |
|
304 | +function wpinv_get_continent_code_for_country($country = false) { |
|
305 | 305 | |
306 | - $country = wpinv_sanitize_country( $country ); |
|
306 | + $country = wpinv_sanitize_country($country); |
|
307 | 307 | |
308 | - foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
309 | - if ( false !== array_search( $country, $countries, true ) ) { |
|
308 | + foreach (wpinv_get_continents('countries') as $continent_code => $countries) { |
|
309 | + if (false !== array_search($country, $countries, true)) { |
|
310 | 310 | return $continent_code; |
311 | 311 | } |
312 | 312 | } |
@@ -322,13 +322,13 @@ discard block |
||
322 | 322 | * @param string $country Country code. If no code is specified, defaults to the default country. |
323 | 323 | * @return array |
324 | 324 | */ |
325 | -function wpinv_get_country_calling_code( $country = null) { |
|
325 | +function wpinv_get_country_calling_code($country = null) { |
|
326 | 326 | |
327 | - $country = wpinv_sanitize_country( $country ); |
|
328 | - $codes = wpinv_get_data( 'phone-codes' ); |
|
329 | - $code = isset( $codes[ $country ] ) ? $codes[ $country ] : ''; |
|
327 | + $country = wpinv_sanitize_country($country); |
|
328 | + $codes = wpinv_get_data('phone-codes'); |
|
329 | + $code = isset($codes[$country]) ? $codes[$country] : ''; |
|
330 | 330 | |
331 | - if ( is_array( $code ) ) { |
|
331 | + if (is_array($code)) { |
|
332 | 332 | return $code[0]; |
333 | 333 | } |
334 | 334 | return $code; |
@@ -341,8 +341,8 @@ discard block |
||
341 | 341 | * @param bool $first_empty Whether or not the first item in the list should be empty |
342 | 342 | * @return array |
343 | 343 | */ |
344 | -function wpinv_get_country_list( $first_empty = false ) { |
|
345 | - return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty ); |
|
344 | +function wpinv_get_country_list($first_empty = false) { |
|
345 | + return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | /** |
@@ -352,22 +352,22 @@ discard block |
||
352 | 352 | * @param bool $first_empty Whether or not the first item in the list should be empty |
353 | 353 | * @return array |
354 | 354 | */ |
355 | -function wpinv_get_country_states( $country = null, $first_empty = false ) { |
|
355 | +function wpinv_get_country_states($country = null, $first_empty = false) { |
|
356 | 356 | |
357 | 357 | // Prepare the country. |
358 | - $country = wpinv_sanitize_country( $country ); |
|
358 | + $country = wpinv_sanitize_country($country); |
|
359 | 359 | |
360 | 360 | // Fetch all states. |
361 | - $all_states = wpinv_get_data( 'states' ); |
|
361 | + $all_states = wpinv_get_data('states'); |
|
362 | 362 | |
363 | 363 | // Fetch the specified country's states. |
364 | - $states = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array() ; |
|
365 | - $states = apply_filters( "wpinv_{$country}_states", $states ); |
|
366 | - $states = apply_filters( 'wpinv_country_states', $states, $country ); |
|
364 | + $states = isset($all_states[$country]) ? $all_states[$country] : array(); |
|
365 | + $states = apply_filters("wpinv_{$country}_states", $states); |
|
366 | + $states = apply_filters('wpinv_country_states', $states, $country); |
|
367 | 367 | |
368 | - asort( $states ); |
|
368 | + asort($states); |
|
369 | 369 | |
370 | - return wpinv_maybe_add_empty_option( $states, $first_empty ); |
|
370 | + return wpinv_maybe_add_empty_option($states, $first_empty); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | /** |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | * @return array |
378 | 378 | */ |
379 | 379 | function wpinv_get_us_states_list() { |
380 | - return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) ); |
|
380 | + return apply_filters('wpinv_usa_states', wpinv_get_country_states('US')); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | * @return array |
388 | 388 | */ |
389 | 389 | function wpinv_get_canada_states_list() { |
390 | - return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) ); |
|
390 | + return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA')); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | /** |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | * @return array |
398 | 398 | */ |
399 | 399 | function wpinv_get_australia_states_list() { |
400 | - return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) ); |
|
400 | + return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU')); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | /** |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | * @return array |
408 | 408 | */ |
409 | 409 | function wpinv_get_bangladesh_states_list() { |
410 | - return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) ); |
|
410 | + return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD')); |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | /** |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | * @return array |
418 | 418 | */ |
419 | 419 | function wpinv_get_brazil_states_list() { |
420 | - return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) ); |
|
420 | + return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR')); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | /** |
@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | * @return array |
428 | 428 | */ |
429 | 429 | function wpinv_get_bulgaria_states_list() { |
430 | - return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) ); |
|
430 | + return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG')); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | /** |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | * @return array |
438 | 438 | */ |
439 | 439 | function wpinv_get_hong_kong_states_list() { |
440 | - return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) ); |
|
440 | + return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK')); |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | /** |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | * @return array |
448 | 448 | */ |
449 | 449 | function wpinv_get_hungary_states_list() { |
450 | - return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) ); |
|
450 | + return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU')); |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | /** |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | * @return array |
458 | 458 | */ |
459 | 459 | function wpinv_get_japan_states_list() { |
460 | - return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) ); |
|
460 | + return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP')); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | /** |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | * @return array |
468 | 468 | */ |
469 | 469 | function wpinv_get_china_states_list() { |
470 | - return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) ); |
|
470 | + return apply_filters('wpinv_china_states', wpinv_get_country_states('CN')); |
|
471 | 471 | } |
472 | 472 | |
473 | 473 | /** |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | * @return array |
478 | 478 | */ |
479 | 479 | function wpinv_get_new_zealand_states_list() { |
480 | - return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) ); |
|
480 | + return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ')); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | /** |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | * @return array |
488 | 488 | */ |
489 | 489 | function wpinv_get_peru_states_list() { |
490 | - return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) ); |
|
490 | + return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE')); |
|
491 | 491 | } |
492 | 492 | |
493 | 493 | /** |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | * @return array |
498 | 498 | */ |
499 | 499 | function wpinv_get_indonesia_states_list() { |
500 | - return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) ); |
|
500 | + return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID')); |
|
501 | 501 | } |
502 | 502 | |
503 | 503 | /** |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | * @return array |
508 | 508 | */ |
509 | 509 | function wpinv_get_india_states_list() { |
510 | - return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) ); |
|
510 | + return apply_filters('wpinv_india_states', wpinv_get_country_states('IN')); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | /** |
@@ -517,7 +517,7 @@ discard block |
||
517 | 517 | * @return array |
518 | 518 | */ |
519 | 519 | function wpinv_get_iran_states_list() { |
520 | - return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) ); |
|
520 | + return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR')); |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | /** |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | * @return array |
528 | 528 | */ |
529 | 529 | function wpinv_get_italy_states_list() { |
530 | - return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) ); |
|
530 | + return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT')); |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | /** |
@@ -537,7 +537,7 @@ discard block |
||
537 | 537 | * @return array |
538 | 538 | */ |
539 | 539 | function wpinv_get_malaysia_states_list() { |
540 | - return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) ); |
|
540 | + return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY')); |
|
541 | 541 | } |
542 | 542 | |
543 | 543 | /** |
@@ -547,7 +547,7 @@ discard block |
||
547 | 547 | * @return array |
548 | 548 | */ |
549 | 549 | function wpinv_get_mexico_states_list() { |
550 | - return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) ); |
|
550 | + return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX')); |
|
551 | 551 | } |
552 | 552 | |
553 | 553 | /** |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | * @return array |
558 | 558 | */ |
559 | 559 | function wpinv_get_nepal_states_list() { |
560 | - return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) ); |
|
560 | + return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP')); |
|
561 | 561 | } |
562 | 562 | |
563 | 563 | /** |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | * @return array |
568 | 568 | */ |
569 | 569 | function wpinv_get_south_africa_states_list() { |
570 | - return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) ); |
|
570 | + return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA')); |
|
571 | 571 | } |
572 | 572 | |
573 | 573 | /** |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | * @return array |
578 | 578 | */ |
579 | 579 | function wpinv_get_thailand_states_list() { |
580 | - return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) ); |
|
580 | + return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH')); |
|
581 | 581 | } |
582 | 582 | |
583 | 583 | /** |
@@ -587,7 +587,7 @@ discard block |
||
587 | 587 | * @return array |
588 | 588 | */ |
589 | 589 | function wpinv_get_turkey_states_list() { |
590 | - return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) ); |
|
590 | + return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR')); |
|
591 | 591 | } |
592 | 592 | |
593 | 593 | /** |
@@ -597,28 +597,28 @@ discard block |
||
597 | 597 | * @return array |
598 | 598 | */ |
599 | 599 | function wpinv_get_spain_states_list() { |
600 | - return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) ); |
|
600 | + return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES')); |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | function wpinv_get_states_field() { |
604 | - if( empty( $_POST['country'] ) ) { |
|
604 | + if (empty($_POST['country'])) { |
|
605 | 605 | $_POST['country'] = wpinv_get_default_country(); |
606 | 606 | } |
607 | - $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
607 | + $states = wpinv_get_country_states(sanitize_text_field($_POST['country'])); |
|
608 | 608 | |
609 | - if( !empty( $states ) ) { |
|
610 | - $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
609 | + if (!empty($states)) { |
|
610 | + $sanitized_field_name = sanitize_text_field($_POST['field_name']); |
|
611 | 611 | |
612 | 612 | $args = array( |
613 | 613 | 'name' => $sanitized_field_name, |
614 | 614 | 'id' => $sanitized_field_name, |
615 | 615 | 'class' => $sanitized_field_name . 'custom-select wpinv-select wpi_select2', |
616 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
616 | + 'options' => array_merge(array('' => ''), $states), |
|
617 | 617 | 'show_option_all' => false, |
618 | 618 | 'show_option_none' => false |
619 | 619 | ); |
620 | 620 | |
621 | - $response = wpinv_html_select( $args ); |
|
621 | + $response = wpinv_html_select($args); |
|
622 | 622 | |
623 | 623 | } else { |
624 | 624 | $response = 'nostates'; |
@@ -627,10 +627,10 @@ discard block |
||
627 | 627 | return $response; |
628 | 628 | } |
629 | 629 | |
630 | -function wpinv_default_billing_country( $country = '', $user_id = 0 ) { |
|
631 | - $country = !empty( $country ) ? $country : wpinv_get_default_country(); |
|
630 | +function wpinv_default_billing_country($country = '', $user_id = 0) { |
|
631 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
632 | 632 | |
633 | - return apply_filters( 'wpinv_default_billing_country', $country, $user_id ); |
|
633 | + return apply_filters('wpinv_default_billing_country', $country, $user_id); |
|
634 | 634 | } |
635 | 635 | |
636 | 636 | /** |
@@ -642,7 +642,7 @@ discard block |
||
642 | 642 | */ |
643 | 643 | function wpinv_get_address_formats() { |
644 | 644 | |
645 | - return apply_filters( 'wpinv_localisation_address_formats', |
|
645 | + return apply_filters('wpinv_localisation_address_formats', |
|
646 | 646 | array( |
647 | 647 | 'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}", |
648 | 648 | 'AU' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}", |
@@ -691,9 +691,9 @@ discard block |
||
691 | 691 | * @see `wpinv_get_invoice_address_replacements` |
692 | 692 | * @return string |
693 | 693 | */ |
694 | -function wpinv_get_full_address_format( $country = false) { |
|
694 | +function wpinv_get_full_address_format($country = false) { |
|
695 | 695 | |
696 | - if( empty( $country ) ) { |
|
696 | + if (empty($country)) { |
|
697 | 697 | $country = wpinv_get_default_country(); |
698 | 698 | } |
699 | 699 | |
@@ -701,7 +701,7 @@ discard block |
||
701 | 701 | $formats = wpinv_get_address_formats(); |
702 | 702 | |
703 | 703 | // Get format for the specified country. |
704 | - $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
704 | + $format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default']; |
|
705 | 705 | |
706 | 706 | /** |
707 | 707 | * Filters the address format to use on Invoices. |
@@ -713,7 +713,7 @@ discard block |
||
713 | 713 | * @param string $format The address format to use. |
714 | 714 | * @param string $country The country who's address format is being retrieved. |
715 | 715 | */ |
716 | - return apply_filters( 'wpinv_get_full_address_format', $format, $country ); |
|
716 | + return apply_filters('wpinv_get_full_address_format', $format, $country); |
|
717 | 717 | } |
718 | 718 | |
719 | 719 | /** |
@@ -724,7 +724,7 @@ discard block |
||
724 | 724 | * @param array $billing_details customer's billing details |
725 | 725 | * @return array |
726 | 726 | */ |
727 | -function wpinv_get_invoice_address_replacements( $billing_details ) { |
|
727 | +function wpinv_get_invoice_address_replacements($billing_details) { |
|
728 | 728 | |
729 | 729 | $default_args = array( |
730 | 730 | 'address' => '', |
@@ -737,22 +737,22 @@ discard block |
||
737 | 737 | 'company' => '', |
738 | 738 | ); |
739 | 739 | |
740 | - $args = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' ); |
|
740 | + $args = map_deep(wp_parse_args($billing_details, $default_args), 'trim'); |
|
741 | 741 | $state = $args['state']; |
742 | 742 | $country = $args['country']; |
743 | 743 | |
744 | 744 | // Handle full country name. |
745 | - $full_country = empty( $country ) ? $country : wpinv_country_name( $country ); |
|
745 | + $full_country = empty($country) ? $country : wpinv_country_name($country); |
|
746 | 746 | |
747 | 747 | // Handle full state name. |
748 | - $full_state = ( $country && $state ) ? wpinv_state_name( $state, $country ) : $state; |
|
748 | + $full_state = ($country && $state) ? wpinv_state_name($state, $country) : $state; |
|
749 | 749 | |
750 | 750 | $args['postcode'] = $args['zip']; |
751 | 751 | $args['name'] = $args['first_name'] . ' ' . $args['last_name']; |
752 | 752 | $args['state'] = $full_state; |
753 | 753 | $args['state_code'] = $state; |
754 | 754 | $args['country'] = $full_country; |
755 | - $args['country_code']= $country; |
|
755 | + $args['country_code'] = $country; |
|
756 | 756 | |
757 | 757 | /** |
758 | 758 | * Filters the address format replacements to use on Invoices. |
@@ -763,14 +763,14 @@ discard block |
||
763 | 763 | * @param array $replacements The address replacements to use. |
764 | 764 | * @param array $billing_details The billing details to use. |
765 | 765 | */ |
766 | - $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details ); |
|
766 | + $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details); |
|
767 | 767 | |
768 | 768 | $return = array(); |
769 | 769 | |
770 | - foreach( $replacements as $key => $value ) { |
|
771 | - $value = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : ''; |
|
770 | + foreach ($replacements as $key => $value) { |
|
771 | + $value = is_scalar($value) ? trim(sanitize_text_field($value)) : ''; |
|
772 | 772 | $return['{{' . $key . '}}'] = $value; |
773 | - $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper( $value ); |
|
773 | + $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value); |
|
774 | 774 | } |
775 | 775 | |
776 | 776 | return $return; |
@@ -784,6 +784,6 @@ discard block |
||
784 | 784 | * @since 1.0.14 |
785 | 785 | * @return string |
786 | 786 | */ |
787 | -function wpinv_trim_formatted_address_line( $line ) { |
|
788 | - return trim( $line, ', ' ); |
|
787 | +function wpinv_trim_formatted_address_line($line) { |
|
788 | + return trim($line, ', '); |
|
789 | 789 | } |
790 | 790 | \ No newline at end of file |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Retrieves the current invoice. |
@@ -14,15 +14,15 @@ discard block |
||
14 | 14 | function getpaid_get_current_invoice_id() { |
15 | 15 | |
16 | 16 | // Ensure that we have an invoice key. |
17 | - if ( empty( $_GET['invoice_key'] ) ) { |
|
17 | + if (empty($_GET['invoice_key'])) { |
|
18 | 18 | return 0; |
19 | 19 | } |
20 | 20 | |
21 | 21 | // Retrieve an invoice using the key. |
22 | - $invoice = new WPInv_Invoice( $_GET['invoice_key'] ); |
|
22 | + $invoice = new WPInv_Invoice($_GET['invoice_key']); |
|
23 | 23 | |
24 | 24 | // Compare the invoice key and the parsed key. |
25 | - if ( $invoice->get_id() != 0 && $invoice->get_key() == $_GET['invoice_key'] ) { |
|
25 | + if ($invoice->get_id() != 0 && $invoice->get_key() == $_GET['invoice_key']) { |
|
26 | 26 | return $invoice->get_id(); |
27 | 27 | } |
28 | 28 | |
@@ -32,42 +32,42 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * Checks if the current user cna view an invoice. |
34 | 34 | */ |
35 | -function wpinv_user_can_view_invoice( $invoice ) { |
|
36 | - $invoice = new WPInv_Invoice( $invoice ); |
|
35 | +function wpinv_user_can_view_invoice($invoice) { |
|
36 | + $invoice = new WPInv_Invoice($invoice); |
|
37 | 37 | |
38 | 38 | // Abort if the invoice does not exist. |
39 | - if ( 0 == $invoice->get_id() ) { |
|
39 | + if (0 == $invoice->get_id()) { |
|
40 | 40 | return false; |
41 | 41 | } |
42 | 42 | |
43 | 43 | // Don't allow trash, draft status |
44 | - if ( $invoice->is_draft() ) { |
|
44 | + if ($invoice->is_draft()) { |
|
45 | 45 | return false; |
46 | 46 | } |
47 | 47 | |
48 | 48 | // If users are not required to login to check out, compare the invoice keys. |
49 | - if ( ! wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && trim( $_GET['invoice_key'] ) == $invoice->get_key() ) { |
|
49 | + if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && trim($_GET['invoice_key']) == $invoice->get_key()) { |
|
50 | 50 | return true; |
51 | 51 | } |
52 | 52 | |
53 | 53 | // Always enable for admins.. |
54 | - if ( wpinv_current_user_can_manage_invoicing() || current_user_can( 'view_invoices', $invoice->get_id() ) ) { // Admin user |
|
54 | + if (wpinv_current_user_can_manage_invoicing() || current_user_can('view_invoices', $invoice->get_id())) { // Admin user |
|
55 | 55 | return true; |
56 | 56 | } |
57 | 57 | |
58 | 58 | // Else, ensure that this is their invoice. |
59 | - if ( is_user_logged_in() && $invoice->get_user_id() == get_current_user_id() ) { |
|
59 | + if (is_user_logged_in() && $invoice->get_user_id() == get_current_user_id()) { |
|
60 | 60 | return true; |
61 | 61 | } |
62 | 62 | |
63 | - return apply_filters( 'wpinv_current_user_can_view_invoice', false, $invoice ); |
|
63 | + return apply_filters('wpinv_current_user_can_view_invoice', false, $invoice); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * Checks if the current user cna view an invoice receipt. |
68 | 68 | */ |
69 | -function wpinv_can_view_receipt( $invoice ) { |
|
70 | - return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice ); |
|
69 | +function wpinv_can_view_receipt($invoice) { |
|
70 | + return (bool) apply_filters('wpinv_can_view_receipt', wpinv_user_can_view_invoice($invoice), $invoice); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -77,16 +77,16 @@ discard block |
||
77 | 77 | */ |
78 | 78 | function getpaid_get_invoice_post_types() { |
79 | 79 | $post_types = array( |
80 | - 'wpi_quote' => __( 'Quote', 'invoicing' ), |
|
81 | - 'wpi_invoice' => __( 'Invoice', 'invoicing' ), |
|
80 | + 'wpi_quote' => __('Quote', 'invoicing'), |
|
81 | + 'wpi_invoice' => __('Invoice', 'invoicing'), |
|
82 | 82 | ); |
83 | 83 | |
84 | 84 | // Ensure the quotes addon is installed. |
85 | - if ( ! defined( 'WPINV_QUOTES_VERSION' ) ) { |
|
86 | - unset( $post_types['wpi_quote'] ); |
|
85 | + if (!defined('WPINV_QUOTES_VERSION')) { |
|
86 | + unset($post_types['wpi_quote']); |
|
87 | 87 | } |
88 | 88 | |
89 | - return apply_filters( 'getpaid_invoice_post_types', $post_types ); |
|
89 | + return apply_filters('getpaid_invoice_post_types', $post_types); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -95,8 +95,8 @@ discard block |
||
95 | 95 | * |
96 | 96 | * @param string $post_type The post type to check for. |
97 | 97 | */ |
98 | -function getpaid_is_invoice_post_type( $post_type ) { |
|
99 | - return is_scalar( $post_type ) && ! empty( $post_type ) && array_key_exists( $post_type, getpaid_get_invoice_post_types() ); |
|
98 | +function getpaid_is_invoice_post_type($post_type) { |
|
99 | + return is_scalar($post_type) && !empty($post_type) && array_key_exists($post_type, getpaid_get_invoice_post_types()); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | * @param bool $wp_error Whether to return false or WP_Error on failure. |
107 | 107 | * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success. |
108 | 108 | */ |
109 | -function wpinv_create_invoice( $data = array(), $deprecated = null, $wp_error = false ) { |
|
110 | - $data[ 'invoice_id' ] = 0; |
|
111 | - return wpinv_insert_invoice( $data, $wp_error ); |
|
109 | +function wpinv_create_invoice($data = array(), $deprecated = null, $wp_error = false) { |
|
110 | + $data['invoice_id'] = 0; |
|
111 | + return wpinv_insert_invoice($data, $wp_error); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -118,36 +118,36 @@ discard block |
||
118 | 118 | * @param bool $wp_error Whether to return false or WP_Error on failure. |
119 | 119 | * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success. |
120 | 120 | */ |
121 | -function wpinv_update_invoice( $data = array(), $wp_error = false ) { |
|
121 | +function wpinv_update_invoice($data = array(), $wp_error = false) { |
|
122 | 122 | |
123 | 123 | // Backwards compatibility. |
124 | - if ( ! empty( $data['ID'] ) ) { |
|
124 | + if (!empty($data['ID'])) { |
|
125 | 125 | $data['invoice_id'] = $data['ID']; |
126 | 126 | } |
127 | 127 | |
128 | 128 | // Do we have an invoice id? |
129 | - if ( empty( $data['invoice_id'] ) ) { |
|
130 | - return $wp_error ? new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) ) : 0; |
|
129 | + if (empty($data['invoice_id'])) { |
|
130 | + return $wp_error ? new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing')) : 0; |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | // Retrieve the invoice. |
134 | - $invoice = wpinv_get_invoice( $data['invoice_id'] ); |
|
134 | + $invoice = wpinv_get_invoice($data['invoice_id']); |
|
135 | 135 | |
136 | 136 | // And abort if it does not exist. |
137 | - if ( empty( $invoice ) ) { |
|
138 | - return $wp_error ? new WP_Error( 'missing_invoice', __( 'Invoice not found.', 'invoicing' ) ) : 0; |
|
137 | + if (empty($invoice)) { |
|
138 | + return $wp_error ? new WP_Error('missing_invoice', __('Invoice not found.', 'invoicing')) : 0; |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | // Do not update totals for paid / refunded invoices. |
142 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
142 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
143 | 143 | |
144 | - if ( ! empty( $data['items'] ) || ! empty( $data['cart_details'] ) ) { |
|
145 | - return $wp_error ? new WP_Error( 'paid_invoice', __( 'You can not update cart items for invoices that have already been paid for.', 'invoicing' ) ) : 0; |
|
144 | + if (!empty($data['items']) || !empty($data['cart_details'])) { |
|
145 | + return $wp_error ? new WP_Error('paid_invoice', __('You can not update cart items for invoices that have already been paid for.', 'invoicing')) : 0; |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | } |
149 | 149 | |
150 | - return wpinv_insert_invoice( $data, $wp_error ); |
|
150 | + return wpinv_insert_invoice($data, $wp_error); |
|
151 | 151 | |
152 | 152 | } |
153 | 153 | |
@@ -158,34 +158,34 @@ discard block |
||
158 | 158 | * @param bool $wp_error Whether to return false or WP_Error on failure. |
159 | 159 | * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success. |
160 | 160 | */ |
161 | -function wpinv_insert_invoice( $data = array(), $wp_error = false ) { |
|
161 | +function wpinv_insert_invoice($data = array(), $wp_error = false) { |
|
162 | 162 | |
163 | 163 | // Ensure that we have invoice data. |
164 | - if ( empty( $data ) ) { |
|
164 | + if (empty($data)) { |
|
165 | 165 | return false; |
166 | 166 | } |
167 | 167 | |
168 | 168 | // The invoice id will be provided when updating an invoice. |
169 | - $data['invoice_id'] = ! empty( $data['invoice_id'] ) ? (int) $data['invoice_id'] : false; |
|
169 | + $data['invoice_id'] = !empty($data['invoice_id']) ? (int) $data['invoice_id'] : false; |
|
170 | 170 | |
171 | 171 | // Retrieve the invoice. |
172 | - $invoice = new WPInv_Invoice( $data['invoice_id'] ); |
|
172 | + $invoice = new WPInv_Invoice($data['invoice_id']); |
|
173 | 173 | |
174 | 174 | // Do we have an error? |
175 | - if ( ! empty( $invoice->last_error ) ) { |
|
176 | - return $wp_error ? new WP_Error( 'invalid_invoice_id', $invoice->last_error ) : 0; |
|
175 | + if (!empty($invoice->last_error)) { |
|
176 | + return $wp_error ? new WP_Error('invalid_invoice_id', $invoice->last_error) : 0; |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | // Backwards compatibility (billing address). |
180 | - if ( ! empty( $data['user_info'] ) ) { |
|
180 | + if (!empty($data['user_info'])) { |
|
181 | 181 | |
182 | - foreach ( $data['user_info'] as $key => $value ) { |
|
182 | + foreach ($data['user_info'] as $key => $value) { |
|
183 | 183 | |
184 | - if ( $key == 'discounts' ) { |
|
184 | + if ($key == 'discounts') { |
|
185 | 185 | $value = (array) $value; |
186 | - $data[ 'discount_code' ] = empty( $value ) ? null : $value[0]; |
|
186 | + $data['discount_code'] = empty($value) ? null : $value[0]; |
|
187 | 187 | } else { |
188 | - $data[ $key ] = $value; |
|
188 | + $data[$key] = $value; |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | } |
@@ -193,30 +193,30 @@ discard block |
||
193 | 193 | } |
194 | 194 | |
195 | 195 | // Backwards compatibility. |
196 | - if ( ! empty( $data['payment_details'] ) ) { |
|
196 | + if (!empty($data['payment_details'])) { |
|
197 | 197 | |
198 | - foreach ( $data['payment_details'] as $key => $value ) { |
|
199 | - $data[ $key ] = $value; |
|
198 | + foreach ($data['payment_details'] as $key => $value) { |
|
199 | + $data[$key] = $value; |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | } |
203 | 203 | |
204 | 204 | // Set up the owner of the invoice. |
205 | - $user_id = ! empty( $data['user_id'] ) ? wpinv_clean( $data['user_id'] ) : get_current_user_id(); |
|
205 | + $user_id = !empty($data['user_id']) ? wpinv_clean($data['user_id']) : get_current_user_id(); |
|
206 | 206 | |
207 | 207 | // Make sure the user exists. |
208 | - if ( ! get_userdata( $user_id ) ) { |
|
209 | - return $wp_error ? new WP_Error( 'wpinv_invalid_user', __( 'There is no user with that ID.', 'invoicing' ) ) : 0; |
|
208 | + if (!get_userdata($user_id)) { |
|
209 | + return $wp_error ? new WP_Error('wpinv_invalid_user', __('There is no user with that ID.', 'invoicing')) : 0; |
|
210 | 210 | } |
211 | 211 | |
212 | - $address = wpinv_get_user_address( $user_id ); |
|
212 | + $address = wpinv_get_user_address($user_id); |
|
213 | 213 | |
214 | - foreach ( $address as $key => $value ) { |
|
214 | + foreach ($address as $key => $value) { |
|
215 | 215 | |
216 | - if ( $value == '' ) { |
|
217 | - $address[ $key ] = null; |
|
216 | + if ($value == '') { |
|
217 | + $address[$key] = null; |
|
218 | 218 | } else { |
219 | - $address[ $key ] = wpinv_clean( $value ); |
|
219 | + $address[$key] = wpinv_clean($value); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | } |
@@ -227,103 +227,103 @@ discard block |
||
227 | 227 | array( |
228 | 228 | |
229 | 229 | // Basic info. |
230 | - 'template' => isset( $data['template'] ) ? wpinv_clean( $data['template'] ) : null, |
|
231 | - 'email_cc' => isset( $data['email_cc'] ) ? wpinv_clean( $data['email_cc'] ) : null, |
|
232 | - 'date_created' => isset( $data['created_date'] ) ? wpinv_clean( $data['created_date'] ) : null, |
|
233 | - 'due_date' => isset( $data['due_date'] ) ? wpinv_clean( $data['due_date'] ) : null, |
|
234 | - 'date_completed' => isset( $data['date_completed'] ) ? wpinv_clean( $data['date_completed'] ) : null, |
|
235 | - 'number' => isset( $data['number'] ) ? wpinv_clean( $data['number'] ) : null, |
|
236 | - 'key' => isset( $data['key'] ) ? wpinv_clean( $data['key'] ) : null, |
|
237 | - 'status' => isset( $data['status'] ) ? wpinv_clean( $data['status'] ) : null, |
|
238 | - 'post_type' => isset( $data['post_type'] ) ? wpinv_clean( $data['post_type'] ) : null, |
|
239 | - 'user_ip' => isset( $data['ip'] ) ? wpinv_clean( $data['ip'] ) : wpinv_get_ip(), |
|
240 | - 'parent_id' => isset( $data['parent'] ) ? intval( $data['parent'] ) : null, |
|
241 | - 'mode' => isset( $data['mode'] ) ? wpinv_clean( $data['mode'] ) : null, |
|
242 | - 'description' => isset( $data['description'] ) ? wp_kses_post( $data['description'] ) : null, |
|
230 | + 'template' => isset($data['template']) ? wpinv_clean($data['template']) : null, |
|
231 | + 'email_cc' => isset($data['email_cc']) ? wpinv_clean($data['email_cc']) : null, |
|
232 | + 'date_created' => isset($data['created_date']) ? wpinv_clean($data['created_date']) : null, |
|
233 | + 'due_date' => isset($data['due_date']) ? wpinv_clean($data['due_date']) : null, |
|
234 | + 'date_completed' => isset($data['date_completed']) ? wpinv_clean($data['date_completed']) : null, |
|
235 | + 'number' => isset($data['number']) ? wpinv_clean($data['number']) : null, |
|
236 | + 'key' => isset($data['key']) ? wpinv_clean($data['key']) : null, |
|
237 | + 'status' => isset($data['status']) ? wpinv_clean($data['status']) : null, |
|
238 | + 'post_type' => isset($data['post_type']) ? wpinv_clean($data['post_type']) : null, |
|
239 | + 'user_ip' => isset($data['ip']) ? wpinv_clean($data['ip']) : wpinv_get_ip(), |
|
240 | + 'parent_id' => isset($data['parent']) ? intval($data['parent']) : null, |
|
241 | + 'mode' => isset($data['mode']) ? wpinv_clean($data['mode']) : null, |
|
242 | + 'description' => isset($data['description']) ? wp_kses_post($data['description']) : null, |
|
243 | 243 | |
244 | 244 | // Payment info. |
245 | - 'disable_taxes' => ! empty( $data['disable_taxes'] ), |
|
246 | - 'currency' => isset( $data['currency'] ) ? wpinv_clean( $data['currency'] ) : wpinv_get_currency(), |
|
247 | - 'gateway' => isset( $data['gateway'] ) ? wpinv_clean( $data['gateway'] ) : null, |
|
248 | - 'transaction_id' => isset( $data['transaction_id'] ) ? wpinv_clean( $data['transaction_id'] ) : null, |
|
249 | - 'discount_code' => isset( $data['discount_code'] ) ? wpinv_clean( $data['discount_code'] ) : null, |
|
250 | - 'payment_form' => isset( $data['payment_form'] ) ? intval( $data['payment_form'] ) : null, |
|
251 | - 'submission_id' => isset( $data['submission_id'] ) ? wpinv_clean( $data['submission_id'] ) : null, |
|
252 | - 'subscription_id' => isset( $data['subscription_id'] ) ? wpinv_clean( $data['subscription_id'] ) : null, |
|
253 | - 'is_viewed' => isset( $data['is_viewed'] ) ? wpinv_clean( $data['is_viewed'] ) : null, |
|
254 | - 'fees' => isset( $data['fees'] ) ? wpinv_clean( $data['fees'] ) : null, |
|
255 | - 'discounts' => isset( $data['discounts'] ) ? wpinv_clean( $data['discounts'] ) : null, |
|
256 | - 'taxes' => isset( $data['taxes'] ) ? wpinv_clean( $data['taxes'] ) : null, |
|
245 | + 'disable_taxes' => !empty($data['disable_taxes']), |
|
246 | + 'currency' => isset($data['currency']) ? wpinv_clean($data['currency']) : wpinv_get_currency(), |
|
247 | + 'gateway' => isset($data['gateway']) ? wpinv_clean($data['gateway']) : null, |
|
248 | + 'transaction_id' => isset($data['transaction_id']) ? wpinv_clean($data['transaction_id']) : null, |
|
249 | + 'discount_code' => isset($data['discount_code']) ? wpinv_clean($data['discount_code']) : null, |
|
250 | + 'payment_form' => isset($data['payment_form']) ? intval($data['payment_form']) : null, |
|
251 | + 'submission_id' => isset($data['submission_id']) ? wpinv_clean($data['submission_id']) : null, |
|
252 | + 'subscription_id' => isset($data['subscription_id']) ? wpinv_clean($data['subscription_id']) : null, |
|
253 | + 'is_viewed' => isset($data['is_viewed']) ? wpinv_clean($data['is_viewed']) : null, |
|
254 | + 'fees' => isset($data['fees']) ? wpinv_clean($data['fees']) : null, |
|
255 | + 'discounts' => isset($data['discounts']) ? wpinv_clean($data['discounts']) : null, |
|
256 | + 'taxes' => isset($data['taxes']) ? wpinv_clean($data['taxes']) : null, |
|
257 | 257 | |
258 | 258 | |
259 | 259 | // Billing details. |
260 | 260 | 'user_id' => $data['user_id'], |
261 | - 'first_name' => isset( $data['first_name'] ) ? wpinv_clean( $data['first_name'] ) : $address['first_name'], |
|
262 | - 'last_name' => isset( $data['last_name'] ) ? wpinv_clean( $data['last_name'] ) : $address['last_name'], |
|
263 | - 'address' => isset( $data['address'] ) ? wpinv_clean( $data['address'] ) : $address['address'] , |
|
264 | - 'vat_number' => isset( $data['vat_number'] ) ? wpinv_clean( $data['vat_number'] ) : $address['vat_number'], |
|
265 | - 'company' => isset( $data['company'] ) ? wpinv_clean( $data['company'] ) : $address['company'], |
|
266 | - 'zip' => isset( $data['zip'] ) ? wpinv_clean( $data['zip'] ) : $address['zip'], |
|
267 | - 'state' => isset( $data['state'] ) ? wpinv_clean( $data['state'] ) : $address['state'], |
|
268 | - 'city' => isset( $data['city'] ) ? wpinv_clean( $data['city'] ) : $address['city'], |
|
269 | - 'country' => isset( $data['country'] ) ? wpinv_clean( $data['country'] ) : $address['country'], |
|
270 | - 'phone' => isset( $data['phone'] ) ? wpinv_clean( $data['phone'] ) : $address['phone'], |
|
271 | - 'address_confirmed' => ! empty( $data['address_confirmed'] ), |
|
261 | + 'first_name' => isset($data['first_name']) ? wpinv_clean($data['first_name']) : $address['first_name'], |
|
262 | + 'last_name' => isset($data['last_name']) ? wpinv_clean($data['last_name']) : $address['last_name'], |
|
263 | + 'address' => isset($data['address']) ? wpinv_clean($data['address']) : $address['address'], |
|
264 | + 'vat_number' => isset($data['vat_number']) ? wpinv_clean($data['vat_number']) : $address['vat_number'], |
|
265 | + 'company' => isset($data['company']) ? wpinv_clean($data['company']) : $address['company'], |
|
266 | + 'zip' => isset($data['zip']) ? wpinv_clean($data['zip']) : $address['zip'], |
|
267 | + 'state' => isset($data['state']) ? wpinv_clean($data['state']) : $address['state'], |
|
268 | + 'city' => isset($data['city']) ? wpinv_clean($data['city']) : $address['city'], |
|
269 | + 'country' => isset($data['country']) ? wpinv_clean($data['country']) : $address['country'], |
|
270 | + 'phone' => isset($data['phone']) ? wpinv_clean($data['phone']) : $address['phone'], |
|
271 | + 'address_confirmed' => !empty($data['address_confirmed']), |
|
272 | 272 | |
273 | 273 | ) |
274 | 274 | |
275 | 275 | ); |
276 | 276 | |
277 | 277 | // Backwards compatibililty. |
278 | - if ( ! empty( $data['cart_details'] ) && is_array( $data['cart_details'] ) ) { |
|
278 | + if (!empty($data['cart_details']) && is_array($data['cart_details'])) { |
|
279 | 279 | $data['items'] = array(); |
280 | 280 | |
281 | - foreach( $data['cart_details'] as $_item ) { |
|
281 | + foreach ($data['cart_details'] as $_item) { |
|
282 | 282 | |
283 | 283 | // Ensure that we have an item id. |
284 | - if ( empty( $_item['id'] ) ) { |
|
284 | + if (empty($_item['id'])) { |
|
285 | 285 | continue; |
286 | 286 | } |
287 | 287 | |
288 | 288 | // Retrieve the item. |
289 | - $item = new GetPaid_Form_Item( $_item['id'] ); |
|
289 | + $item = new GetPaid_Form_Item($_item['id']); |
|
290 | 290 | |
291 | 291 | // Ensure that it is purchasable. |
292 | - if ( ! $item->can_purchase() ) { |
|
292 | + if (!$item->can_purchase()) { |
|
293 | 293 | continue; |
294 | 294 | } |
295 | 295 | |
296 | 296 | // Set quantity. |
297 | - if ( ! empty( $_item['quantity'] ) && is_numeric( $_item['quantity'] ) ) { |
|
298 | - $item->set_quantity( $_item['quantity'] ); |
|
297 | + if (!empty($_item['quantity']) && is_numeric($_item['quantity'])) { |
|
298 | + $item->set_quantity($_item['quantity']); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | // Set price. |
302 | - if ( isset( $_item['item_price'] ) ) { |
|
303 | - $item->set_price( $_item['item_price'] ); |
|
302 | + if (isset($_item['item_price'])) { |
|
303 | + $item->set_price($_item['item_price']); |
|
304 | 304 | } |
305 | 305 | |
306 | - if ( isset( $_item['custom_price'] ) ) { |
|
307 | - $item->set_price( $_item['custom_price'] ); |
|
306 | + if (isset($_item['custom_price'])) { |
|
307 | + $item->set_price($_item['custom_price']); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | // Set name. |
311 | - if ( ! empty( $_item['name'] ) ) { |
|
312 | - $item->set_name( $_item['name'] ); |
|
311 | + if (!empty($_item['name'])) { |
|
312 | + $item->set_name($_item['name']); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | // Set description. |
316 | - if ( isset( $_item['description'] ) ) { |
|
317 | - $item->set_custom_description( $_item['description'] ); |
|
316 | + if (isset($_item['description'])) { |
|
317 | + $item->set_custom_description($_item['description']); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | // Set meta. |
321 | - if ( isset( $_item['meta'] ) && is_array( $_item['meta'] ) ) { |
|
321 | + if (isset($_item['meta']) && is_array($_item['meta'])) { |
|
322 | 322 | |
323 | - $item->set_item_meta( $_item['meta'] ); |
|
323 | + $item->set_item_meta($_item['meta']); |
|
324 | 324 | |
325 | - if ( isset( $_item['meta']['description'] ) ) { |
|
326 | - $item->set_custom_description( $_item['meta']['description'] ); |
|
325 | + if (isset($_item['meta']['description'])) { |
|
326 | + $item->set_custom_description($_item['meta']['description']); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | } |
@@ -334,14 +334,14 @@ discard block |
||
334 | 334 | } |
335 | 335 | |
336 | 336 | // Add invoice items. |
337 | - if ( ! empty( $data['items'] ) && is_array( $data['items'] ) ) { |
|
337 | + if (!empty($data['items']) && is_array($data['items'])) { |
|
338 | 338 | |
339 | - $invoice->set_items( array() ); |
|
339 | + $invoice->set_items(array()); |
|
340 | 340 | |
341 | - foreach ( $data['items'] as $item ) { |
|
341 | + foreach ($data['items'] as $item) { |
|
342 | 342 | |
343 | - if ( is_object( $item ) && is_a( $item, 'GetPaid_Form_Item' ) && $item->can_purchase() ) { |
|
344 | - $invoice->add_item( $item ); |
|
343 | + if (is_object($item) && is_a($item, 'GetPaid_Form_Item') && $item->can_purchase()) { |
|
344 | + $invoice->add_item($item); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | } |
@@ -352,30 +352,30 @@ discard block |
||
352 | 352 | $invoice->recalculate_total(); |
353 | 353 | $invoice->save(); |
354 | 354 | |
355 | - if ( ! $invoice->get_id() ) { |
|
356 | - return $wp_error ? new WP_Error( 'wpinv_insert_invoice_error', __( 'An error occured when saving your invoice.', 'invoicing' ) ) : 0; |
|
355 | + if (!$invoice->get_id()) { |
|
356 | + return $wp_error ? new WP_Error('wpinv_insert_invoice_error', __('An error occured when saving your invoice.', 'invoicing')) : 0; |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | // Add private note. |
360 | - if ( ! empty( $data['private_note'] ) ) { |
|
361 | - $invoice->add_note( $data['private_note'] ); |
|
360 | + if (!empty($data['private_note'])) { |
|
361 | + $invoice->add_note($data['private_note']); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | // User notes. |
365 | - if ( !empty( $data['user_note'] ) ) { |
|
366 | - $invoice->add_note( $data['user_note'], true ); |
|
365 | + if (!empty($data['user_note'])) { |
|
366 | + $invoice->add_note($data['user_note'], true); |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | // Created via. |
370 | - if ( isset( $data['created_via'] ) ) { |
|
371 | - update_post_meta( $invoice->get_id(), 'wpinv_created_via', $data['created_via'] ); |
|
370 | + if (isset($data['created_via'])) { |
|
371 | + update_post_meta($invoice->get_id(), 'wpinv_created_via', $data['created_via']); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | // Backwards compatiblity. |
375 | - if ( $invoice->is_quote() ) { |
|
375 | + if ($invoice->is_quote()) { |
|
376 | 376 | |
377 | - if ( isset( $data['valid_until'] ) ) { |
|
378 | - update_post_meta( $invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until'] ); |
|
377 | + if (isset($data['valid_until'])) { |
|
378 | + update_post_meta($invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until']); |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | } |
@@ -390,20 +390,20 @@ discard block |
||
390 | 390 | * @param $bool $deprecated |
391 | 391 | * @return WPInv_Invoice|null |
392 | 392 | */ |
393 | -function wpinv_get_invoice( $invoice = 0, $deprecated = false ) { |
|
393 | +function wpinv_get_invoice($invoice = 0, $deprecated = false) { |
|
394 | 394 | |
395 | 395 | // If we are retrieving the invoice from the cart... |
396 | - if ( $deprecated && empty( $invoice ) ) { |
|
396 | + if ($deprecated && empty($invoice)) { |
|
397 | 397 | $invoice = (int) getpaid_get_current_invoice_id(); |
398 | 398 | } |
399 | 399 | |
400 | 400 | // Retrieve the invoice. |
401 | - if ( ! is_a( $invoice, 'WPInv_Invoice' ) ) { |
|
402 | - $invoice = new WPInv_Invoice( $invoice ); |
|
401 | + if (!is_a($invoice, 'WPInv_Invoice')) { |
|
402 | + $invoice = new WPInv_Invoice($invoice); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | // Check if it exists. |
406 | - if ( $invoice->exists() ) { |
|
406 | + if ($invoice->exists()) { |
|
407 | 407 | return $invoice; |
408 | 408 | } |
409 | 409 | |
@@ -416,15 +416,15 @@ discard block |
||
416 | 416 | * @param array $args Args to search for. |
417 | 417 | * @return WPInv_Invoice[]|int[]|object |
418 | 418 | */ |
419 | -function wpinv_get_invoices( $args ) { |
|
419 | +function wpinv_get_invoices($args) { |
|
420 | 420 | |
421 | 421 | // Prepare args. |
422 | 422 | $args = wp_parse_args( |
423 | 423 | $args, |
424 | 424 | array( |
425 | - 'status' => array_keys( wpinv_get_invoice_statuses() ), |
|
425 | + 'status' => array_keys(wpinv_get_invoice_statuses()), |
|
426 | 426 | 'type' => 'wpi_invoice', |
427 | - 'limit' => get_option( 'posts_per_page' ), |
|
427 | + 'limit' => get_option('posts_per_page'), |
|
428 | 428 | 'return' => 'objects', |
429 | 429 | ) |
430 | 430 | ); |
@@ -442,24 +442,24 @@ discard block |
||
442 | 442 | 'post__in' => 'include', |
443 | 443 | ); |
444 | 444 | |
445 | - foreach ( $map_legacy as $to => $from ) { |
|
446 | - if ( isset( $args[ $from ] ) ) { |
|
447 | - $args[ $to ] = $args[ $from ]; |
|
448 | - unset( $args[ $from ] ); |
|
445 | + foreach ($map_legacy as $to => $from) { |
|
446 | + if (isset($args[$from])) { |
|
447 | + $args[$to] = $args[$from]; |
|
448 | + unset($args[$from]); |
|
449 | 449 | } |
450 | 450 | } |
451 | 451 | |
452 | 452 | // Backwards compatibility. |
453 | - if ( ! empty( $args['email'] ) && empty( $args['user'] ) ) { |
|
453 | + if (!empty($args['email']) && empty($args['user'])) { |
|
454 | 454 | $args['user'] = $args['email']; |
455 | - unset( $args['email'] ); |
|
455 | + unset($args['email']); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | // Handle cases where the user is set as an email. |
459 | - if ( ! empty( $args['author'] ) && is_email( $args['author'] ) ) { |
|
460 | - $user = get_user_by( 'email', $args['user'] ); |
|
459 | + if (!empty($args['author']) && is_email($args['author'])) { |
|
460 | + $user = get_user_by('email', $args['user']); |
|
461 | 461 | |
462 | - if ( $user ) { |
|
462 | + if ($user) { |
|
463 | 463 | $args['author'] = $user->user_email; |
464 | 464 | } |
465 | 465 | |
@@ -470,31 +470,31 @@ discard block |
||
470 | 470 | |
471 | 471 | // Show all posts. |
472 | 472 | $paginate = true; |
473 | - if ( isset( $args['paginate'] ) ) { |
|
473 | + if (isset($args['paginate'])) { |
|
474 | 474 | |
475 | 475 | $paginate = $args['paginate']; |
476 | - $args['no_found_rows'] = empty( $args['paginate'] ); |
|
477 | - unset( $args['paginate'] ); |
|
476 | + $args['no_found_rows'] = empty($args['paginate']); |
|
477 | + unset($args['paginate']); |
|
478 | 478 | |
479 | 479 | } |
480 | 480 | |
481 | 481 | // Whether to return objects or fields. |
482 | 482 | $return = $args['return']; |
483 | - unset( $args['return'] ); |
|
483 | + unset($args['return']); |
|
484 | 484 | |
485 | 485 | // Get invoices. |
486 | - $invoices = new WP_Query( apply_filters( 'wpinv_get_invoices_args', $args ) ); |
|
486 | + $invoices = new WP_Query(apply_filters('wpinv_get_invoices_args', $args)); |
|
487 | 487 | |
488 | 488 | // Prepare the results. |
489 | - if ( 'objects' === $return ) { |
|
490 | - $results = array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
491 | - } elseif ( 'self' === $return ) { |
|
489 | + if ('objects' === $return) { |
|
490 | + $results = array_map('wpinv_get_invoice', $invoices->posts); |
|
491 | + } elseif ('self' === $return) { |
|
492 | 492 | return $invoices; |
493 | 493 | } else { |
494 | 494 | $results = $invoices->posts; |
495 | 495 | } |
496 | 496 | |
497 | - if ( $paginate ) { |
|
497 | + if ($paginate) { |
|
498 | 498 | return (object) array( |
499 | 499 | 'invoices' => $results, |
500 | 500 | 'total' => $invoices->found_posts, |
@@ -512,8 +512,8 @@ discard block |
||
512 | 512 | * @param string $transaction_id The transaction id to check. |
513 | 513 | * @return int Invoice id on success or 0 on failure |
514 | 514 | */ |
515 | -function wpinv_get_id_by_transaction_id( $transaction_id ) { |
|
516 | - return WPInv_Invoice::get_invoice_id_by_field( $transaction_id, 'transaction_id' ); |
|
515 | +function wpinv_get_id_by_transaction_id($transaction_id) { |
|
516 | + return WPInv_Invoice::get_invoice_id_by_field($transaction_id, 'transaction_id'); |
|
517 | 517 | } |
518 | 518 | |
519 | 519 | /** |
@@ -522,8 +522,8 @@ discard block |
||
522 | 522 | * @param string $invoice_number The invoice number to check. |
523 | 523 | * @return int Invoice id on success or 0 on failure |
524 | 524 | */ |
525 | -function wpinv_get_id_by_invoice_number( $invoice_number ) { |
|
526 | - return WPInv_Invoice::get_invoice_id_by_field( $invoice_number, 'number' ); |
|
525 | +function wpinv_get_id_by_invoice_number($invoice_number) { |
|
526 | + return WPInv_Invoice::get_invoice_id_by_field($invoice_number, 'number'); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
@@ -532,8 +532,8 @@ discard block |
||
532 | 532 | * @param string $invoice_key The invoice key to check. |
533 | 533 | * @return int Invoice id on success or 0 on failure |
534 | 534 | */ |
535 | -function wpinv_get_invoice_id_by_key( $invoice_key ) { |
|
536 | - return WPInv_Invoice::get_invoice_id_by_field( $invoice_key, 'key' ); |
|
535 | +function wpinv_get_invoice_id_by_key($invoice_key) { |
|
536 | + return WPInv_Invoice::get_invoice_id_by_field($invoice_key, 'key'); |
|
537 | 537 | } |
538 | 538 | |
539 | 539 | /** |
@@ -543,19 +543,19 @@ discard block |
||
543 | 543 | * @param string $type Optionally filter by type i.e customer|system |
544 | 544 | * @return array|null |
545 | 545 | */ |
546 | -function wpinv_get_invoice_notes( $invoice = 0, $type = '' ) { |
|
546 | +function wpinv_get_invoice_notes($invoice = 0, $type = '') { |
|
547 | 547 | |
548 | 548 | // Prepare the invoice. |
549 | - $invoice = wpinv_get_invoice( $invoice ); |
|
550 | - if ( empty( $invoice ) ) { |
|
549 | + $invoice = wpinv_get_invoice($invoice); |
|
550 | + if (empty($invoice)) { |
|
551 | 551 | return NULL; |
552 | 552 | } |
553 | 553 | |
554 | 554 | // Fetch notes. |
555 | - $notes = getpaid_notes()->get_invoice_notes( $invoice->get_id(), $type ); |
|
555 | + $notes = getpaid_notes()->get_invoice_notes($invoice->get_id(), $type); |
|
556 | 556 | |
557 | 557 | // Filter the notes. |
558 | - return apply_filters( 'wpinv_invoice_notes', $notes, $invoice->get_id(), $type ); |
|
558 | + return apply_filters('wpinv_invoice_notes', $notes, $invoice->get_id(), $type); |
|
559 | 559 | } |
560 | 560 | |
561 | 561 | /** |
@@ -563,10 +563,10 @@ discard block |
||
563 | 563 | * |
564 | 564 | * @param string $post_type |
565 | 565 | */ |
566 | -function wpinv_get_user_invoices_columns( $post_type = 'wpi_invoice' ) { |
|
566 | +function wpinv_get_user_invoices_columns($post_type = 'wpi_invoice') { |
|
567 | 567 | |
568 | - $label = getpaid_get_post_type_label( $post_type, false ); |
|
569 | - $label = empty( $label ) ? __( 'Invoice', 'invoicing' ) : sanitize_text_field( $label ); |
|
568 | + $label = getpaid_get_post_type_label($post_type, false); |
|
569 | + $label = empty($label) ? __('Invoice', 'invoicing') : sanitize_text_field($label); |
|
570 | 570 | $columns = array( |
571 | 571 | |
572 | 572 | 'invoice-number' => array( |
@@ -575,22 +575,22 @@ discard block |
||
575 | 575 | ), |
576 | 576 | |
577 | 577 | 'created-date' => array( |
578 | - 'title' => __( 'Created Date', 'invoicing' ), |
|
578 | + 'title' => __('Created Date', 'invoicing'), |
|
579 | 579 | 'class' => 'text-left' |
580 | 580 | ), |
581 | 581 | |
582 | 582 | 'payment-date' => array( |
583 | - 'title' => __( 'Payment Date', 'invoicing' ), |
|
583 | + 'title' => __('Payment Date', 'invoicing'), |
|
584 | 584 | 'class' => 'text-left' |
585 | 585 | ), |
586 | 586 | |
587 | 587 | 'invoice-status' => array( |
588 | - 'title' => __( 'Status', 'invoicing' ), |
|
588 | + 'title' => __('Status', 'invoicing'), |
|
589 | 589 | 'class' => 'text-center' |
590 | 590 | ), |
591 | 591 | |
592 | 592 | 'invoice-total' => array( |
593 | - 'title' => __( 'Total', 'invoicing' ), |
|
593 | + 'title' => __('Total', 'invoicing'), |
|
594 | 594 | 'class' => 'text-right' |
595 | 595 | ), |
596 | 596 | |
@@ -601,7 +601,7 @@ discard block |
||
601 | 601 | |
602 | 602 | ); |
603 | 603 | |
604 | - return apply_filters( 'wpinv_user_invoices_columns', $columns, $post_type ); |
|
604 | + return apply_filters('wpinv_user_invoices_columns', $columns, $post_type); |
|
605 | 605 | } |
606 | 606 | |
607 | 607 | /** |
@@ -611,59 +611,59 @@ discard block |
||
611 | 611 | |
612 | 612 | // Find the invoice. |
613 | 613 | $invoice_id = getpaid_get_current_invoice_id(); |
614 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
614 | + $invoice = new WPInv_Invoice($invoice_id); |
|
615 | 615 | |
616 | 616 | // Abort if non was found. |
617 | - if ( empty( $invoice_id ) || $invoice->is_draft() ) { |
|
617 | + if (empty($invoice_id) || $invoice->is_draft()) { |
|
618 | 618 | |
619 | 619 | return aui()->alert( |
620 | 620 | array( |
621 | 621 | 'type' => 'warning', |
622 | - 'content' => __( 'We could not find your invoice', 'invoicing' ), |
|
622 | + 'content' => __('We could not find your invoice', 'invoicing'), |
|
623 | 623 | ) |
624 | 624 | ); |
625 | 625 | |
626 | 626 | } |
627 | 627 | |
628 | 628 | // Can the user view this invoice? |
629 | - if ( ! wpinv_can_view_receipt( $invoice_id ) ) { |
|
629 | + if (!wpinv_can_view_receipt($invoice_id)) { |
|
630 | 630 | |
631 | 631 | return aui()->alert( |
632 | 632 | array( |
633 | 633 | 'type' => 'warning', |
634 | - 'content' => __( 'You are not allowed to view this receipt', 'invoicing' ), |
|
634 | + 'content' => __('You are not allowed to view this receipt', 'invoicing'), |
|
635 | 635 | ) |
636 | 636 | ); |
637 | 637 | |
638 | 638 | } |
639 | 639 | |
640 | 640 | // Load the template. |
641 | - return wpinv_get_template_html( 'invoice-receipt.php', compact( 'invoice' ) ); |
|
641 | + return wpinv_get_template_html('invoice-receipt.php', compact('invoice')); |
|
642 | 642 | |
643 | 643 | } |
644 | 644 | |
645 | 645 | /** |
646 | 646 | * Displays the invoice history. |
647 | 647 | */ |
648 | -function getpaid_invoice_history( $user_id = 0, $post_type = 'wpi_invoice' ) { |
|
648 | +function getpaid_invoice_history($user_id = 0, $post_type = 'wpi_invoice') { |
|
649 | 649 | |
650 | 650 | // Ensure that we have a user id. |
651 | - if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
|
651 | + if (empty($user_id) || !is_numeric($user_id)) { |
|
652 | 652 | $user_id = get_current_user_id(); |
653 | 653 | } |
654 | 654 | |
655 | - $label = getpaid_get_post_type_label( $post_type ); |
|
656 | - $label = empty( $label ) ? __( 'Invoices', 'invoicing' ) : sanitize_text_field( $label ); |
|
655 | + $label = getpaid_get_post_type_label($post_type); |
|
656 | + $label = empty($label) ? __('Invoices', 'invoicing') : sanitize_text_field($label); |
|
657 | 657 | |
658 | 658 | // View user id. |
659 | - if ( empty( $user_id ) ) { |
|
659 | + if (empty($user_id)) { |
|
660 | 660 | |
661 | 661 | return aui()->alert( |
662 | 662 | array( |
663 | 663 | 'type' => 'warning', |
664 | 664 | 'content' => sprintf( |
665 | - __( 'You must be logged in to view your %s.', 'invoicing' ), |
|
666 | - strtolower( $label ) |
|
665 | + __('You must be logged in to view your %s.', 'invoicing'), |
|
666 | + strtolower($label) |
|
667 | 667 | ) |
668 | 668 | ) |
669 | 669 | ); |
@@ -674,23 +674,23 @@ discard block |
||
674 | 674 | $invoices = wpinv_get_invoices( |
675 | 675 | |
676 | 676 | array( |
677 | - 'page' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
677 | + 'page' => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1, |
|
678 | 678 | 'user' => $user_id, |
679 | 679 | 'paginate' => true, |
680 | 680 | 'type' => $post_type, |
681 | - 'status' => array_keys( wpinv_get_invoice_statuses( false, false, $post_type ) ), |
|
681 | + 'status' => array_keys(wpinv_get_invoice_statuses(false, false, $post_type)), |
|
682 | 682 | ) |
683 | 683 | |
684 | 684 | ); |
685 | 685 | |
686 | - if ( empty( $invoices->total ) ) { |
|
686 | + if (empty($invoices->total)) { |
|
687 | 687 | |
688 | 688 | return aui()->alert( |
689 | 689 | array( |
690 | 690 | 'type' => 'info', |
691 | 691 | 'content' => sprintf( |
692 | - __( 'No %s found.', 'invoicing' ), |
|
693 | - strtolower( $label ) |
|
692 | + __('No %s found.', 'invoicing'), |
|
693 | + strtolower($label) |
|
694 | 694 | ) |
695 | 695 | ) |
696 | 696 | ); |
@@ -698,38 +698,38 @@ discard block |
||
698 | 698 | } |
699 | 699 | |
700 | 700 | // Load the template. |
701 | - return wpinv_get_template_html( 'invoice-history.php', compact( 'invoices', 'post_type' ) ); |
|
701 | + return wpinv_get_template_html('invoice-history.php', compact('invoices', 'post_type')); |
|
702 | 702 | |
703 | 703 | } |
704 | 704 | |
705 | 705 | /** |
706 | 706 | * Formats an invoice number given an invoice type. |
707 | 707 | */ |
708 | -function wpinv_format_invoice_number( $number, $type = '' ) { |
|
708 | +function wpinv_format_invoice_number($number, $type = '') { |
|
709 | 709 | |
710 | 710 | // Allow other plugins to overide this. |
711 | - $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type ); |
|
712 | - if ( null !== $check ) { |
|
711 | + $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type); |
|
712 | + if (null !== $check) { |
|
713 | 713 | return $check; |
714 | 714 | } |
715 | 715 | |
716 | 716 | // Ensure that we have a numeric number. |
717 | - if ( ! is_numeric( $number ) ) { |
|
717 | + if (!is_numeric($number)) { |
|
718 | 718 | return $number; |
719 | 719 | } |
720 | 720 | |
721 | 721 | // Format the number. |
722 | - $padd = absint( (int) wpinv_get_option( 'invoice_number_padd', 5 ) ); |
|
723 | - $prefix = sanitize_text_field( (string) wpinv_get_option( 'invoice_number_prefix', 'INV-' ) ); |
|
724 | - $prefix = sanitize_text_field( apply_filters( 'getpaid_invoice_type_prefix', $prefix, $type ) ); |
|
725 | - $postfix = sanitize_text_field( (string) wpinv_get_option( 'invoice_number_postfix' ) ); |
|
726 | - $postfix = sanitize_text_field( apply_filters( 'getpaid_invoice_type_postfix', $postfix, $type ) ); |
|
727 | - $formatted_number = zeroise( absint( $number ), $padd ); |
|
722 | + $padd = absint((int) wpinv_get_option('invoice_number_padd', 5)); |
|
723 | + $prefix = sanitize_text_field((string) wpinv_get_option('invoice_number_prefix', 'INV-')); |
|
724 | + $prefix = sanitize_text_field(apply_filters('getpaid_invoice_type_prefix', $prefix, $type)); |
|
725 | + $postfix = sanitize_text_field((string) wpinv_get_option('invoice_number_postfix')); |
|
726 | + $postfix = sanitize_text_field(apply_filters('getpaid_invoice_type_postfix', $postfix, $type)); |
|
727 | + $formatted_number = zeroise(absint($number), $padd); |
|
728 | 728 | |
729 | 729 | // Add the prefix and post fix. |
730 | 730 | $formatted_number = $prefix . $formatted_number . $postfix; |
731 | 731 | |
732 | - return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd ); |
|
732 | + return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd); |
|
733 | 733 | } |
734 | 734 | |
735 | 735 | /** |
@@ -738,58 +738,58 @@ discard block |
||
738 | 738 | * @param string $type. |
739 | 739 | * @return int|null|bool |
740 | 740 | */ |
741 | -function wpinv_get_next_invoice_number( $type = '' ) { |
|
741 | +function wpinv_get_next_invoice_number($type = '') { |
|
742 | 742 | |
743 | 743 | // Allow plugins to overide this. |
744 | - $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type ); |
|
745 | - if ( null !== $check ) { |
|
744 | + $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type); |
|
745 | + if (null !== $check) { |
|
746 | 746 | return $check; |
747 | 747 | } |
748 | 748 | |
749 | 749 | // Ensure sequential invoice numbers is active. |
750 | - if ( ! wpinv_sequential_number_active() ) { |
|
750 | + if (!wpinv_sequential_number_active()) { |
|
751 | 751 | return false; |
752 | 752 | } |
753 | 753 | |
754 | 754 | // Retrieve the current number and the start number. |
755 | - $number = (int) get_option( 'wpinv_last_invoice_number', 0 ); |
|
756 | - $start = absint( (int) wpinv_get_option( 'invoice_sequence_start', 1 ) ); |
|
755 | + $number = (int) get_option('wpinv_last_invoice_number', 0); |
|
756 | + $start = absint((int) wpinv_get_option('invoice_sequence_start', 1)); |
|
757 | 757 | |
758 | 758 | // Ensure that we are starting at a positive integer. |
759 | - $start = max( $start, 1 ); |
|
759 | + $start = max($start, 1); |
|
760 | 760 | |
761 | 761 | // If this is the first invoice, use the start number. |
762 | - $number = max( $start, $number ); |
|
762 | + $number = max($start, $number); |
|
763 | 763 | |
764 | 764 | // Format the invoice number. |
765 | - $formatted_number = wpinv_format_invoice_number( $number, $type ); |
|
765 | + $formatted_number = wpinv_format_invoice_number($number, $type); |
|
766 | 766 | |
767 | 767 | // Ensure that this number is unique. |
768 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $formatted_number, 'number' ); |
|
768 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field($formatted_number, 'number'); |
|
769 | 769 | |
770 | 770 | // We found a match. Nice. |
771 | - if ( empty( $invoice_id ) ) { |
|
772 | - update_option( 'wpinv_last_invoice_number', $number ); |
|
773 | - return apply_filters( 'wpinv_get_next_invoice_number', $number ); |
|
771 | + if (empty($invoice_id)) { |
|
772 | + update_option('wpinv_last_invoice_number', $number); |
|
773 | + return apply_filters('wpinv_get_next_invoice_number', $number); |
|
774 | 774 | } |
775 | 775 | |
776 | - update_option( 'wpinv_last_invoice_number', $number + 1 ); |
|
777 | - return wpinv_get_next_invoice_number( $type ); |
|
776 | + update_option('wpinv_last_invoice_number', $number + 1); |
|
777 | + return wpinv_get_next_invoice_number($type); |
|
778 | 778 | |
779 | 779 | } |
780 | 780 | |
781 | 781 | /** |
782 | 782 | * The prefix used for invoice paths. |
783 | 783 | */ |
784 | -function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) { |
|
785 | - return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type ); |
|
784 | +function wpinv_post_name_prefix($post_type = 'wpi_invoice') { |
|
785 | + return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type); |
|
786 | 786 | } |
787 | 787 | |
788 | -function wpinv_generate_post_name( $post_ID ) { |
|
789 | - $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) ); |
|
790 | - $post_name = sanitize_title( $prefix . $post_ID ); |
|
788 | +function wpinv_generate_post_name($post_ID) { |
|
789 | + $prefix = wpinv_post_name_prefix(get_post_type($post_ID)); |
|
790 | + $post_name = sanitize_title($prefix . $post_ID); |
|
791 | 791 | |
792 | - return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix ); |
|
792 | + return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix); |
|
793 | 793 | } |
794 | 794 | |
795 | 795 | /** |
@@ -797,8 +797,8 @@ discard block |
||
797 | 797 | * |
798 | 798 | * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object. |
799 | 799 | */ |
800 | -function wpinv_is_invoice_viewed( $invoice ) { |
|
801 | - $invoice = new WPInv_Invoice( $invoice ); |
|
800 | +function wpinv_is_invoice_viewed($invoice) { |
|
801 | + $invoice = new WPInv_Invoice($invoice); |
|
802 | 802 | return (bool) $invoice->get_is_viewed(); |
803 | 803 | } |
804 | 804 | |
@@ -807,17 +807,17 @@ discard block |
||
807 | 807 | * |
808 | 808 | * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object. |
809 | 809 | */ |
810 | -function getpaid_maybe_mark_invoice_as_viewed( $invoice ) { |
|
811 | - $invoice = new WPInv_Invoice( $invoice ); |
|
810 | +function getpaid_maybe_mark_invoice_as_viewed($invoice) { |
|
811 | + $invoice = new WPInv_Invoice($invoice); |
|
812 | 812 | |
813 | - if ( get_current_user_id() == $invoice->get_user_id() && ! $invoice->get_is_viewed() ) { |
|
814 | - $invoice->set_is_viewed( true ); |
|
813 | + if (get_current_user_id() == $invoice->get_user_id() && !$invoice->get_is_viewed()) { |
|
814 | + $invoice->set_is_viewed(true); |
|
815 | 815 | $invoice->save(); |
816 | 816 | } |
817 | 817 | |
818 | 818 | } |
819 | -add_action( 'wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed' ); |
|
820 | -add_action( 'wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed' ); |
|
819 | +add_action('wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed'); |
|
820 | +add_action('wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed'); |
|
821 | 821 | |
822 | 822 | /** |
823 | 823 | * Processes an invoice refund. |
@@ -826,27 +826,27 @@ discard block |
||
826 | 826 | * @param array $status_transition |
827 | 827 | * @todo: descrease customer/store earnings |
828 | 828 | */ |
829 | -function getpaid_maybe_process_refund( $invoice, $status_transition ) { |
|
829 | +function getpaid_maybe_process_refund($invoice, $status_transition) { |
|
830 | 830 | |
831 | - if ( empty( $status_transition['from'] ) || ! in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) { |
|
831 | + if (empty($status_transition['from']) || !in_array($status_transition['from'], array('publish', 'wpi-processing', 'wpi-renewal'))) { |
|
832 | 832 | return; |
833 | 833 | } |
834 | 834 | |
835 | 835 | $discount_code = $invoice->get_discount_code(); |
836 | - if ( ! empty( $discount_code ) ) { |
|
837 | - $discount = wpinv_get_discount_obj( $discount_code ); |
|
836 | + if (!empty($discount_code)) { |
|
837 | + $discount = wpinv_get_discount_obj($discount_code); |
|
838 | 838 | |
839 | - if ( $discount->exists() ) { |
|
839 | + if ($discount->exists()) { |
|
840 | 840 | $discount->increase_usage( -1 ); |
841 | 841 | } |
842 | 842 | |
843 | 843 | } |
844 | 844 | |
845 | - do_action( 'wpinv_pre_refund_invoice', $invoice, $invoice->get_id() ); |
|
846 | - do_action( 'wpinv_refund_invoice', $invoice, $invoice->get_id() ); |
|
847 | - do_action( 'wpinv_post_refund_invoice', $invoice, $invoice->get_id() ); |
|
845 | + do_action('wpinv_pre_refund_invoice', $invoice, $invoice->get_id()); |
|
846 | + do_action('wpinv_refund_invoice', $invoice, $invoice->get_id()); |
|
847 | + do_action('wpinv_post_refund_invoice', $invoice, $invoice->get_id()); |
|
848 | 848 | } |
849 | -add_action( 'getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 2 ); |
|
849 | +add_action('getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 2); |
|
850 | 850 | |
851 | 851 | |
852 | 852 | /** |
@@ -854,49 +854,49 @@ discard block |
||
854 | 854 | * |
855 | 855 | * @param int $invoice_id |
856 | 856 | */ |
857 | -function getpaid_process_invoice_payment( $invoice_id ) { |
|
857 | +function getpaid_process_invoice_payment($invoice_id) { |
|
858 | 858 | |
859 | 859 | // Fetch the invoice. |
860 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
860 | + $invoice = new WPInv_Invoice($invoice_id); |
|
861 | 861 | |
862 | 862 | // We only want to do this once. |
863 | - if ( 1 == get_post_meta( $invoice->get_id(), 'wpinv_processed_payment', true ) ) { |
|
863 | + if (1 == get_post_meta($invoice->get_id(), 'wpinv_processed_payment', true)) { |
|
864 | 864 | return; |
865 | 865 | } |
866 | 866 | |
867 | - update_post_meta( $invoice->get_id(), 'wpinv_processed_payment', 1 ); |
|
867 | + update_post_meta($invoice->get_id(), 'wpinv_processed_payment', 1); |
|
868 | 868 | |
869 | 869 | // Fires when processing a payment. |
870 | - do_action( 'getpaid_process_payment', $invoice ); |
|
870 | + do_action('getpaid_process_payment', $invoice); |
|
871 | 871 | |
872 | 872 | // Fire an action for each invoice item. |
873 | - foreach( $invoice->get_items() as $item ) { |
|
874 | - do_action( 'getpaid_process_item_payment', $item, $invoice ); |
|
873 | + foreach ($invoice->get_items() as $item) { |
|
874 | + do_action('getpaid_process_item_payment', $item, $invoice); |
|
875 | 875 | } |
876 | 876 | |
877 | 877 | // Increase discount usage. |
878 | 878 | $discount_code = $invoice->get_discount_code(); |
879 | - if ( ! empty( $discount_code ) && ! $invoice->is_renewal() ) { |
|
880 | - $discount = wpinv_get_discount_obj( $discount_code ); |
|
879 | + if (!empty($discount_code) && !$invoice->is_renewal()) { |
|
880 | + $discount = wpinv_get_discount_obj($discount_code); |
|
881 | 881 | |
882 | - if ( $discount->exists() ) { |
|
882 | + if ($discount->exists()) { |
|
883 | 883 | $discount->increase_usage(); |
884 | 884 | } |
885 | 885 | |
886 | 886 | } |
887 | 887 | |
888 | 888 | // Record reverse vat. |
889 | - if ( 'invoice' == $invoice->get_type() && wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
889 | + if ('invoice' == $invoice->get_type() && wpinv_use_taxes() && !$invoice->get_disable_taxes()) { |
|
890 | 890 | |
891 | 891 | $taxes = $invoice->get_total_tax(); |
892 | - if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) { |
|
893 | - $invoice->add_note( __( 'VAT was reverse charged', 'invoicing' ), false, false, true ); |
|
892 | + if (empty($taxes) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction($invoice->get_country())) { |
|
893 | + $invoice->add_note(__('VAT was reverse charged', 'invoicing'), false, false, true); |
|
894 | 894 | } |
895 | 895 | |
896 | 896 | } |
897 | 897 | |
898 | 898 | } |
899 | -add_action( 'getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment' ); |
|
899 | +add_action('getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment'); |
|
900 | 900 | |
901 | 901 | /** |
902 | 902 | * Returns an array of invoice item columns |
@@ -904,13 +904,13 @@ discard block |
||
904 | 904 | * @param int|WPInv_Invoice $invoice |
905 | 905 | * @return array |
906 | 906 | */ |
907 | -function getpaid_invoice_item_columns( $invoice ) { |
|
907 | +function getpaid_invoice_item_columns($invoice) { |
|
908 | 908 | |
909 | 909 | // Prepare the invoice. |
910 | - $invoice = new WPInv_Invoice( $invoice ); |
|
910 | + $invoice = new WPInv_Invoice($invoice); |
|
911 | 911 | |
912 | 912 | // Abort if there is no invoice. |
913 | - if ( 0 == $invoice->get_id() ) { |
|
913 | + if (0 == $invoice->get_id()) { |
|
914 | 914 | return array(); |
915 | 915 | } |
916 | 916 | |
@@ -918,57 +918,57 @@ discard block |
||
918 | 918 | $columns = apply_filters( |
919 | 919 | 'getpaid_invoice_item_columns', |
920 | 920 | array( |
921 | - 'name' => __( 'Item', 'invoicing' ), |
|
922 | - 'price' => __( 'Price', 'invoicing' ), |
|
923 | - 'tax_rate' => __( 'Tax Rate', 'invoicing' ), |
|
924 | - 'quantity' => __( 'Quantity', 'invoicing' ), |
|
925 | - 'subtotal' => __( 'Item Subtotal', 'invoicing' ), |
|
921 | + 'name' => __('Item', 'invoicing'), |
|
922 | + 'price' => __('Price', 'invoicing'), |
|
923 | + 'tax_rate' => __('Tax Rate', 'invoicing'), |
|
924 | + 'quantity' => __('Quantity', 'invoicing'), |
|
925 | + 'subtotal' => __('Item Subtotal', 'invoicing'), |
|
926 | 926 | ), |
927 | 927 | $invoice |
928 | 928 | ); |
929 | 929 | |
930 | 930 | // Quantities. |
931 | - if ( isset( $columns[ 'quantity' ] ) ) { |
|
931 | + if (isset($columns['quantity'])) { |
|
932 | 932 | |
933 | - if ( 'hours' == $invoice->get_template() ) { |
|
934 | - $columns[ 'quantity' ] = __( 'Hours', 'invoicing' ); |
|
933 | + if ('hours' == $invoice->get_template()) { |
|
934 | + $columns['quantity'] = __('Hours', 'invoicing'); |
|
935 | 935 | } |
936 | 936 | |
937 | - if ( ! wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template() ) { |
|
938 | - unset( $columns[ 'quantity' ] ); |
|
937 | + if (!wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template()) { |
|
938 | + unset($columns['quantity']); |
|
939 | 939 | } |
940 | 940 | |
941 | 941 | } |
942 | 942 | |
943 | 943 | |
944 | 944 | // Price. |
945 | - if ( isset( $columns[ 'price' ] ) ) { |
|
945 | + if (isset($columns['price'])) { |
|
946 | 946 | |
947 | - if ( 'amount' == $invoice->get_template() ) { |
|
948 | - $columns[ 'price' ] = __( 'Amount', 'invoicing' ); |
|
947 | + if ('amount' == $invoice->get_template()) { |
|
948 | + $columns['price'] = __('Amount', 'invoicing'); |
|
949 | 949 | } |
950 | 950 | |
951 | - if ( 'hours' == $invoice->get_template() ) { |
|
952 | - $columns[ 'price' ] = __( 'Rate', 'invoicing' ); |
|
951 | + if ('hours' == $invoice->get_template()) { |
|
952 | + $columns['price'] = __('Rate', 'invoicing'); |
|
953 | 953 | } |
954 | 954 | |
955 | 955 | } |
956 | 956 | |
957 | 957 | |
958 | 958 | // Sub total. |
959 | - if ( isset( $columns[ 'subtotal' ] ) ) { |
|
959 | + if (isset($columns['subtotal'])) { |
|
960 | 960 | |
961 | - if ( 'amount' == $invoice->get_template() ) { |
|
962 | - unset( $columns[ 'subtotal' ] ); |
|
961 | + if ('amount' == $invoice->get_template()) { |
|
962 | + unset($columns['subtotal']); |
|
963 | 963 | } |
964 | 964 | |
965 | 965 | } |
966 | 966 | |
967 | 967 | // Tax rates. |
968 | - if ( isset( $columns[ 'tax_rate' ] ) ) { |
|
968 | + if (isset($columns['tax_rate'])) { |
|
969 | 969 | |
970 | - if ( 0 == $invoice->get_tax() ) { |
|
971 | - unset( $columns[ 'tax_rate' ] ); |
|
970 | + if (0 == $invoice->get_tax()) { |
|
971 | + unset($columns['tax_rate']); |
|
972 | 972 | } |
973 | 973 | |
974 | 974 | } |
@@ -982,38 +982,38 @@ discard block |
||
982 | 982 | * @param int|WPInv_Invoice $invoice |
983 | 983 | * @return array |
984 | 984 | */ |
985 | -function getpaid_invoice_totals_rows( $invoice ) { |
|
985 | +function getpaid_invoice_totals_rows($invoice) { |
|
986 | 986 | |
987 | 987 | // Prepare the invoice. |
988 | - $invoice = new WPInv_Invoice( $invoice ); |
|
988 | + $invoice = new WPInv_Invoice($invoice); |
|
989 | 989 | |
990 | 990 | // Abort if there is no invoice. |
991 | - if ( 0 == $invoice->get_id() ) { |
|
991 | + if (0 == $invoice->get_id()) { |
|
992 | 992 | return array(); |
993 | 993 | } |
994 | 994 | |
995 | 995 | $totals = apply_filters( |
996 | 996 | 'getpaid_invoice_totals_rows', |
997 | 997 | array( |
998 | - 'subtotal' => __( 'Subtotal', 'invoicing' ), |
|
999 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
1000 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
1001 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
1002 | - 'total' => __( 'Total', 'invoicing' ), |
|
998 | + 'subtotal' => __('Subtotal', 'invoicing'), |
|
999 | + 'tax' => __('Tax', 'invoicing'), |
|
1000 | + 'fee' => __('Fee', 'invoicing'), |
|
1001 | + 'discount' => __('Discount', 'invoicing'), |
|
1002 | + 'total' => __('Total', 'invoicing'), |
|
1003 | 1003 | ), |
1004 | 1004 | $invoice |
1005 | 1005 | ); |
1006 | 1006 | |
1007 | - if ( ( $invoice->get_disable_taxes() || ! wpinv_use_taxes() ) && isset( $totals['tax'] ) ) { |
|
1008 | - unset( $totals['tax'] ); |
|
1007 | + if (($invoice->get_disable_taxes() || !wpinv_use_taxes()) && isset($totals['tax'])) { |
|
1008 | + unset($totals['tax']); |
|
1009 | 1009 | } |
1010 | 1010 | |
1011 | - if ( 0 == $invoice->get_total_fees() && isset( $totals['fee'] ) ) { |
|
1012 | - unset( $totals['fee'] ); |
|
1011 | + if (0 == $invoice->get_total_fees() && isset($totals['fee'])) { |
|
1012 | + unset($totals['fee']); |
|
1013 | 1013 | } |
1014 | 1014 | |
1015 | - if ( 0 == $invoice->get_total_discount() && isset( $totals['discount'] ) ) { |
|
1016 | - unset( $totals['discount'] ); |
|
1015 | + if (0 == $invoice->get_total_discount() && isset($totals['discount'])) { |
|
1016 | + unset($totals['discount']); |
|
1017 | 1017 | } |
1018 | 1018 | |
1019 | 1019 | return $totals; |
@@ -1024,47 +1024,47 @@ discard block |
||
1024 | 1024 | * |
1025 | 1025 | * @param WPInv_Invoice $invoice |
1026 | 1026 | */ |
1027 | -function getpaid_new_invoice( $invoice ) { |
|
1027 | +function getpaid_new_invoice($invoice) { |
|
1028 | 1028 | |
1029 | - if ( ! $invoice->get_status() ) { |
|
1029 | + if (!$invoice->get_status()) { |
|
1030 | 1030 | return; |
1031 | 1031 | } |
1032 | 1032 | |
1033 | 1033 | // Add an invoice created note. |
1034 | 1034 | $invoice->add_note( |
1035 | 1035 | sprintf( |
1036 | - __( '%s created with the status "%s".', 'invoicing' ), |
|
1037 | - ucfirst( $invoice->get_invoice_quote_type() ), |
|
1038 | - wpinv_status_nicename( $invoice->get_status(), $invoice ) |
|
1036 | + __('%s created with the status "%s".', 'invoicing'), |
|
1037 | + ucfirst($invoice->get_invoice_quote_type()), |
|
1038 | + wpinv_status_nicename($invoice->get_status(), $invoice) |
|
1039 | 1039 | ) |
1040 | 1040 | ); |
1041 | 1041 | |
1042 | 1042 | } |
1043 | -add_action( 'getpaid_new_invoice', 'getpaid_new_invoice' ); |
|
1043 | +add_action('getpaid_new_invoice', 'getpaid_new_invoice'); |
|
1044 | 1044 | |
1045 | 1045 | /** |
1046 | 1046 | * This function updates invoice caches. |
1047 | 1047 | * |
1048 | 1048 | * @param WPInv_Invoice $invoice |
1049 | 1049 | */ |
1050 | -function getpaid_update_invoice_caches( $invoice ) { |
|
1050 | +function getpaid_update_invoice_caches($invoice) { |
|
1051 | 1051 | |
1052 | 1052 | // Cache invoice number. |
1053 | - wp_cache_set( $invoice->get_number(), $invoice->get_id(), "getpaid_invoice_numbers_to_invoice_ids" ); |
|
1053 | + wp_cache_set($invoice->get_number(), $invoice->get_id(), "getpaid_invoice_numbers_to_invoice_ids"); |
|
1054 | 1054 | |
1055 | 1055 | // Cache invoice key. |
1056 | - wp_cache_set( $invoice->get_key(), $invoice->get_id(), "getpaid_invoice_keys_to_invoice_ids" ); |
|
1056 | + wp_cache_set($invoice->get_key(), $invoice->get_id(), "getpaid_invoice_keys_to_invoice_ids"); |
|
1057 | 1057 | |
1058 | 1058 | // (Maybe) cache transaction id. |
1059 | 1059 | $transaction_id = $invoice->get_transaction_id(); |
1060 | 1060 | |
1061 | - if ( ! empty( $transaction_id ) ) { |
|
1062 | - wp_cache_set( $transaction_id, $invoice->get_id(), "getpaid_invoice_transaction_ids_to_invoice_ids" ); |
|
1061 | + if (!empty($transaction_id)) { |
|
1062 | + wp_cache_set($transaction_id, $invoice->get_id(), "getpaid_invoice_transaction_ids_to_invoice_ids"); |
|
1063 | 1063 | } |
1064 | 1064 | |
1065 | 1065 | } |
1066 | -add_action( 'getpaid_new_invoice', 'getpaid_update_invoice_caches', 5 ); |
|
1067 | -add_action( 'getpaid_update_invoice', 'getpaid_update_invoice_caches', 5 ); |
|
1066 | +add_action('getpaid_new_invoice', 'getpaid_update_invoice_caches', 5); |
|
1067 | +add_action('getpaid_update_invoice', 'getpaid_update_invoice_caches', 5); |
|
1068 | 1068 | |
1069 | 1069 | /** |
1070 | 1070 | * Duplicates an invoice. |
@@ -1074,7 +1074,7 @@ discard block |
||
1074 | 1074 | * @param WPInv_Invoice $old_invoice The invoice to duplicate |
1075 | 1075 | * @return WPInv_Invoice The new invoice. |
1076 | 1076 | */ |
1077 | -function getpaid_duplicate_invoice( $old_invoice ) { |
|
1077 | +function getpaid_duplicate_invoice($old_invoice) { |
|
1078 | 1078 | |
1079 | 1079 | // Create the new invoice. |
1080 | 1080 | $invoice = new WPInv_Invoice(); |
@@ -1135,121 +1135,121 @@ discard block |
||
1135 | 1135 | * @param WPInv_Invoice $invoice |
1136 | 1136 | * @return array |
1137 | 1137 | */ |
1138 | -function getpaid_get_invoice_meta( $invoice ) { |
|
1138 | +function getpaid_get_invoice_meta($invoice) { |
|
1139 | 1139 | |
1140 | 1140 | // Load the invoice meta. |
1141 | 1141 | $meta = array( |
1142 | 1142 | |
1143 | 1143 | 'number' => array( |
1144 | 1144 | 'label' => sprintf( |
1145 | - __( '%s Number', 'invoicing' ), |
|
1146 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
1145 | + __('%s Number', 'invoicing'), |
|
1146 | + ucfirst($invoice->get_invoice_quote_type()) |
|
1147 | 1147 | ), |
1148 | - 'value' => sanitize_text_field( $invoice->get_number() ), |
|
1148 | + 'value' => sanitize_text_field($invoice->get_number()), |
|
1149 | 1149 | ), |
1150 | 1150 | |
1151 | 1151 | 'status' => array( |
1152 | 1152 | 'label' => sprintf( |
1153 | - __( '%s Status', 'invoicing' ), |
|
1154 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
1153 | + __('%s Status', 'invoicing'), |
|
1154 | + ucfirst($invoice->get_invoice_quote_type()) |
|
1155 | 1155 | ), |
1156 | 1156 | 'value' => $invoice->get_status_label_html(), |
1157 | 1157 | ), |
1158 | 1158 | |
1159 | 1159 | 'date' => array( |
1160 | 1160 | 'label' => sprintf( |
1161 | - __( '%s Date', 'invoicing' ), |
|
1162 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
1161 | + __('%s Date', 'invoicing'), |
|
1162 | + ucfirst($invoice->get_invoice_quote_type()) |
|
1163 | 1163 | ), |
1164 | - 'value' => getpaid_format_date( $invoice->get_created_date() ), |
|
1164 | + 'value' => getpaid_format_date($invoice->get_created_date()), |
|
1165 | 1165 | ), |
1166 | 1166 | |
1167 | 1167 | 'date_paid' => array( |
1168 | - 'label' => __( 'Paid On', 'invoicing' ), |
|
1169 | - 'value' => getpaid_format_date( $invoice->get_completed_date() ), |
|
1168 | + 'label' => __('Paid On', 'invoicing'), |
|
1169 | + 'value' => getpaid_format_date($invoice->get_completed_date()), |
|
1170 | 1170 | ), |
1171 | 1171 | |
1172 | 1172 | 'gateway' => array( |
1173 | - 'label' => __( 'Payment Method', 'invoicing' ), |
|
1174 | - 'value' => sanitize_text_field( $invoice->get_gateway_title() ), |
|
1173 | + 'label' => __('Payment Method', 'invoicing'), |
|
1174 | + 'value' => sanitize_text_field($invoice->get_gateway_title()), |
|
1175 | 1175 | ), |
1176 | 1176 | |
1177 | 1177 | 'transaction_id' => array( |
1178 | - 'label' => __( 'Transaction ID', 'invoicing' ), |
|
1179 | - 'value' => sanitize_text_field( $invoice->get_transaction_id() ), |
|
1178 | + 'label' => __('Transaction ID', 'invoicing'), |
|
1179 | + 'value' => sanitize_text_field($invoice->get_transaction_id()), |
|
1180 | 1180 | ), |
1181 | 1181 | |
1182 | 1182 | 'due_date' => array( |
1183 | - 'label' => __( 'Due Date', 'invoicing' ), |
|
1184 | - 'value' => getpaid_format_date( $invoice->get_due_date() ), |
|
1183 | + 'label' => __('Due Date', 'invoicing'), |
|
1184 | + 'value' => getpaid_format_date($invoice->get_due_date()), |
|
1185 | 1185 | ), |
1186 | 1186 | |
1187 | 1187 | 'vat_number' => array( |
1188 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
1189 | - 'value' => sanitize_text_field( $invoice->get_vat_number() ), |
|
1188 | + 'label' => __('VAT Number', 'invoicing'), |
|
1189 | + 'value' => sanitize_text_field($invoice->get_vat_number()), |
|
1190 | 1190 | ), |
1191 | 1191 | |
1192 | 1192 | ); |
1193 | 1193 | |
1194 | 1194 | // If it is not paid, remove the date of payment. |
1195 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
1196 | - unset( $meta[ 'date_paid' ] ); |
|
1197 | - unset( $meta[ 'transaction_id' ] ); |
|
1195 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
1196 | + unset($meta['date_paid']); |
|
1197 | + unset($meta['transaction_id']); |
|
1198 | 1198 | } |
1199 | 1199 | |
1200 | - if ( ! $invoice->is_paid() || 'none' == $invoice->get_gateway() ) { |
|
1201 | - unset( $meta[ 'gateway' ] ); |
|
1200 | + if (!$invoice->is_paid() || 'none' == $invoice->get_gateway()) { |
|
1201 | + unset($meta['gateway']); |
|
1202 | 1202 | } |
1203 | 1203 | |
1204 | 1204 | // Only display the due date if due dates are enabled. |
1205 | - if ( ! $invoice->needs_payment() || ! wpinv_get_option( 'overdue_active' ) ) { |
|
1206 | - unset( $meta[ 'due_date' ] ); |
|
1205 | + if (!$invoice->needs_payment() || !wpinv_get_option('overdue_active')) { |
|
1206 | + unset($meta['due_date']); |
|
1207 | 1207 | } |
1208 | 1208 | |
1209 | 1209 | // Only display the vat number if taxes are enabled. |
1210 | - if ( ! wpinv_use_taxes() ) { |
|
1211 | - unset( $meta[ 'vat_number' ] ); |
|
1210 | + if (!wpinv_use_taxes()) { |
|
1211 | + unset($meta['vat_number']); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | // Link to the parent invoice. |
1215 | - if ( $invoice->get_parent_id() > 0 ) { |
|
1215 | + if ($invoice->get_parent_id() > 0) { |
|
1216 | 1216 | |
1217 | - $meta[ 'parent' ] = array( |
|
1217 | + $meta['parent'] = array( |
|
1218 | 1218 | |
1219 | 1219 | 'label' => sprintf( |
1220 | - __( 'Parent %s', 'invoicing' ), |
|
1221 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
1220 | + __('Parent %s', 'invoicing'), |
|
1221 | + ucfirst($invoice->get_invoice_quote_type()) |
|
1222 | 1222 | ), |
1223 | 1223 | |
1224 | - 'value' => wpinv_invoice_link( $invoice->get_parent_id() ), |
|
1224 | + 'value' => wpinv_invoice_link($invoice->get_parent_id()), |
|
1225 | 1225 | |
1226 | 1226 | ); |
1227 | 1227 | |
1228 | 1228 | } |
1229 | 1229 | |
1230 | 1230 | |
1231 | - if ( $invoice->is_recurring() ) { |
|
1231 | + if ($invoice->is_recurring()) { |
|
1232 | 1232 | |
1233 | - $subscription = getpaid_get_invoice_subscriptions( $invoice ); |
|
1234 | - if ( ! empty ( $subscription ) && ! is_array( $subscription ) && $subscription->exists() ) { |
|
1233 | + $subscription = getpaid_get_invoice_subscriptions($invoice); |
|
1234 | + if (!empty ($subscription) && !is_array($subscription) && $subscription->exists()) { |
|
1235 | 1235 | |
1236 | 1236 | // Display the renewal date. |
1237 | - if ( $subscription->is_active() && 'cancelled' != $subscription->get_status() ) { |
|
1237 | + if ($subscription->is_active() && 'cancelled' != $subscription->get_status()) { |
|
1238 | 1238 | |
1239 | - $meta[ 'renewal_date' ] = array( |
|
1240 | - 'label' => __( 'Renews On', 'invoicing' ), |
|
1241 | - 'value' => getpaid_format_date( $subscription->get_expiration() ), |
|
1239 | + $meta['renewal_date'] = array( |
|
1240 | + 'label' => __('Renews On', 'invoicing'), |
|
1241 | + 'value' => getpaid_format_date($subscription->get_expiration()), |
|
1242 | 1242 | ); |
1243 | 1243 | |
1244 | 1244 | } |
1245 | 1245 | |
1246 | - if ( $invoice->is_parent() ) { |
|
1246 | + if ($invoice->is_parent()) { |
|
1247 | 1247 | |
1248 | 1248 | // Display the recurring amount. |
1249 | - $meta[ 'recurring_total' ] = array( |
|
1249 | + $meta['recurring_total'] = array( |
|
1250 | 1250 | |
1251 | - 'label' => __( 'Recurring Amount', 'invoicing' ), |
|
1252 | - 'value' => wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ), |
|
1251 | + 'label' => __('Recurring Amount', 'invoicing'), |
|
1252 | + 'value' => wpinv_price($subscription->get_recurring_amount(), $invoice->get_currency()), |
|
1253 | 1253 | |
1254 | 1254 | ); |
1255 | 1255 | |
@@ -1259,15 +1259,15 @@ discard block |
||
1259 | 1259 | } |
1260 | 1260 | |
1261 | 1261 | // Add the invoice total to the meta. |
1262 | - $meta[ 'invoice_total' ] = array( |
|
1262 | + $meta['invoice_total'] = array( |
|
1263 | 1263 | |
1264 | - 'label' => __( 'Total Amount', 'invoicing' ), |
|
1265 | - 'value' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ), |
|
1264 | + 'label' => __('Total Amount', 'invoicing'), |
|
1265 | + 'value' => wpinv_price($invoice->get_total(), $invoice->get_currency()), |
|
1266 | 1266 | |
1267 | 1267 | ); |
1268 | 1268 | |
1269 | 1269 | // Provide a way for third party plugins to filter the meta. |
1270 | - $meta = apply_filters( 'getpaid_invoice_meta_data', $meta, $invoice ); |
|
1270 | + $meta = apply_filters('getpaid_invoice_meta_data', $meta, $invoice); |
|
1271 | 1271 | |
1272 | 1272 | return $meta; |
1273 | 1273 | |
@@ -1306,12 +1306,12 @@ discard block |
||
1306 | 1306 | * @param GetPaid_Form_Item $item |
1307 | 1307 | * @return float |
1308 | 1308 | */ |
1309 | -function getpaid_get_invoice_tax_rate( $invoice, $item ) { |
|
1309 | +function getpaid_get_invoice_tax_rate($invoice, $item) { |
|
1310 | 1310 | |
1311 | - $rates = getpaid_get_item_tax_rates( $item, $invoice->get_country(), $invoice->get_state() ); |
|
1312 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
1313 | - $rates = wp_list_pluck( $rates, 'rate' ); |
|
1311 | + $rates = getpaid_get_item_tax_rates($item, $invoice->get_country(), $invoice->get_state()); |
|
1312 | + $rates = getpaid_filter_item_tax_rates($item, $rates); |
|
1313 | + $rates = wp_list_pluck($rates, 'rate'); |
|
1314 | 1314 | |
1315 | - return array_sum( $rates ); |
|
1315 | + return array_sum($rates); |
|
1316 | 1316 | |
1317 | 1317 | } |
@@ -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 | * Main Checkout Class. |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @param GetPaid_Payment_Form_Submission $submission |
24 | 24 | */ |
25 | - public function __construct( $submission ) { |
|
25 | + public function __construct($submission) { |
|
26 | 26 | $this->payment_form_submission = $submission; |
27 | 27 | } |
28 | 28 | |
@@ -38,22 +38,22 @@ discard block |
||
38 | 38 | // Prepare the invoice. |
39 | 39 | $items = $this->get_submission_items(); |
40 | 40 | $invoice = $this->get_submission_invoice(); |
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
41 | + $invoice = $this->process_submission_invoice($invoice, $items); |
|
42 | 42 | $prepared = $this->prepare_submission_data_for_saving(); |
43 | 43 | |
44 | - $this->prepare_billing_info( $invoice ); |
|
44 | + $this->prepare_billing_info($invoice); |
|
45 | 45 | |
46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
46 | + $shipping = $this->prepare_shipping_info($invoice); |
|
47 | 47 | |
48 | 48 | // Save the invoice. |
49 | - $invoice->set_is_viewed( true ); |
|
49 | + $invoice->set_is_viewed(true); |
|
50 | 50 | $invoice->recalculate_total(); |
51 | 51 | $invoice->save(); |
52 | 52 | |
53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
53 | + do_action('getpaid_checkout_invoice_updated', $invoice); |
|
54 | 54 | |
55 | 55 | // Send to the gateway. |
56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
56 | + $this->post_process_submission($invoice, $prepared, $shipping); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -66,34 +66,34 @@ discard block |
||
66 | 66 | $data = $submission->get_data(); |
67 | 67 | |
68 | 68 | // Do we have an error? |
69 | - if ( ! empty( $submission->last_error ) ) { |
|
70 | - wp_send_json_error( $submission->last_error ); |
|
69 | + if (!empty($submission->last_error)) { |
|
70 | + wp_send_json_error($submission->last_error); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // We need a billing email. |
74 | - if ( ! $submission->has_billing_email() ) { |
|
75 | - wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
|
74 | + if (!$submission->has_billing_email()) { |
|
75 | + wp_send_json_error(__('Provide a valid billing email.', 'invoicing')); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // Non-recurring gateways should not be allowed to process recurring invoices. |
79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
79 | + if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) { |
|
80 | + wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing')); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | // Ensure the gateway is active. |
84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
84 | + if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) { |
|
85 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not active', 'invoicing')); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | // Clear any existing errors. |
89 | 89 | wpinv_clear_errors(); |
90 | 90 | |
91 | 91 | // Allow themes and plugins to hook to errors |
92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
92 | + do_action('getpaid_checkout_error_checks', $submission); |
|
93 | 93 | |
94 | 94 | // Do we have any errors? |
95 | - if ( wpinv_get_errors() ) { |
|
96 | - wp_send_json_error( getpaid_get_errors_html() ); |
|
95 | + if (wpinv_get_errors()) { |
|
96 | + wp_send_json_error(getpaid_get_errors_html()); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | } |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | $items = $this->payment_form_submission->get_items(); |
109 | 109 | |
110 | 110 | // Ensure that we have items. |
111 | - if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
|
112 | - wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
|
111 | + if (empty($items) && !$this->payment_form_submission->has_fees()) { |
|
112 | + wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing')); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | return $items; |
@@ -123,17 +123,17 @@ discard block |
||
123 | 123 | protected function get_submission_invoice() { |
124 | 124 | $submission = $this->payment_form_submission; |
125 | 125 | |
126 | - if ( ! $submission->has_invoice() ) { |
|
126 | + if (!$submission->has_invoice()) { |
|
127 | 127 | $invoice = new WPInv_Invoice(); |
128 | - $invoice->set_created_via( 'payment_form' ); |
|
128 | + $invoice->set_created_via('payment_form'); |
|
129 | 129 | return $invoice; |
130 | 130 | } |
131 | 131 | |
132 | 132 | $invoice = $submission->get_invoice(); |
133 | 133 | |
134 | 134 | // Make sure that it is neither paid or refunded. |
135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
135 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
136 | + wp_send_json_error(__('This invoice has already been paid for.', 'invoicing')); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | return $invoice; |
@@ -146,29 +146,29 @@ discard block |
||
146 | 146 | * @param GetPaid_Form_Item[] $items |
147 | 147 | * @return WPInv_Invoice |
148 | 148 | */ |
149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
149 | + protected function process_submission_invoice($invoice, $items) { |
|
150 | 150 | |
151 | 151 | $submission = $this->payment_form_submission; |
152 | 152 | $data = $submission->get_data(); |
153 | 153 | |
154 | 154 | // Set-up the invoice details. |
155 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
156 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
157 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
158 | - $invoice->set_items( $items ); |
|
159 | - $invoice->set_fees( $submission->get_fees() ); |
|
160 | - $invoice->set_taxes( $submission->get_taxes() ); |
|
161 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
162 | - $invoice->set_gateway( $data['wpi-gateway'] ); |
|
163 | - |
|
164 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
165 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
166 | - |
|
167 | - if ( $submission->has_discount_code() ) { |
|
168 | - $invoice->set_discount_code( $submission->get_discount_code() ); |
|
155 | + $invoice->set_email(sanitize_email($submission->get_billing_email())); |
|
156 | + $invoice->set_user_id($this->get_submission_customer()); |
|
157 | + $invoice->set_payment_form(absint($submission->get_payment_form()->get_id())); |
|
158 | + $invoice->set_items($items); |
|
159 | + $invoice->set_fees($submission->get_fees()); |
|
160 | + $invoice->set_taxes($submission->get_taxes()); |
|
161 | + $invoice->set_discounts($submission->get_discounts()); |
|
162 | + $invoice->set_gateway($data['wpi-gateway']); |
|
163 | + |
|
164 | + $address_confirmed = $submission->get_field('confirm-address'); |
|
165 | + $invoice->set_address_confirmed(!empty($address_confirmed)); |
|
166 | + |
|
167 | + if ($submission->has_discount_code()) { |
|
168 | + $invoice->set_discount_code($submission->get_discount_code()); |
|
169 | 169 | } |
170 | 170 | |
171 | - getpaid_maybe_add_default_address( $invoice ); |
|
171 | + getpaid_maybe_add_default_address($invoice); |
|
172 | 172 | return $invoice; |
173 | 173 | } |
174 | 174 | |
@@ -181,33 +181,33 @@ discard block |
||
181 | 181 | $submission = $this->payment_form_submission; |
182 | 182 | |
183 | 183 | // If this is an existing invoice... |
184 | - if ( $submission->has_invoice() ) { |
|
184 | + if ($submission->has_invoice()) { |
|
185 | 185 | return $submission->get_invoice()->get_user_id(); |
186 | 186 | } |
187 | 187 | |
188 | 188 | // (Maybe) create the user. |
189 | 189 | $user = get_current_user_id(); |
190 | 190 | |
191 | - if ( empty( $user ) ) { |
|
192 | - $user = get_user_by( 'email', $submission->get_billing_email() ); |
|
191 | + if (empty($user)) { |
|
192 | + $user = get_user_by('email', $submission->get_billing_email()); |
|
193 | 193 | } |
194 | 194 | |
195 | - if ( empty( $user ) ) { |
|
196 | - $user = wpinv_create_user( $submission->get_billing_email() ); |
|
195 | + if (empty($user)) { |
|
196 | + $user = wpinv_create_user($submission->get_billing_email()); |
|
197 | 197 | |
198 | 198 | // (Maybe) send new user notification. |
199 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
200 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) { |
|
201 | - wp_send_new_user_notifications( $user, 'user' ); |
|
199 | + $should_send_notification = wpinv_get_option('disable_new_user_emails'); |
|
200 | + if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification))) { |
|
201 | + wp_send_new_user_notifications($user, 'user'); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | } |
205 | 205 | |
206 | - if ( is_wp_error( $user ) ) { |
|
207 | - wp_send_json_error( $user->get_error_message() ); |
|
206 | + if (is_wp_error($user)) { |
|
207 | + wp_send_json_error($user->get_error_message()); |
|
208 | 208 | } |
209 | 209 | |
210 | - if ( is_numeric( $user ) ) { |
|
210 | + if (is_numeric($user)) { |
|
211 | 211 | return $user; |
212 | 212 | } |
213 | 213 | |
@@ -228,30 +228,30 @@ discard block |
||
228 | 228 | $prepared = array(); |
229 | 229 | |
230 | 230 | // Raw submission details. |
231 | - $data = $submission->get_data(); |
|
231 | + $data = $submission->get_data(); |
|
232 | 232 | |
233 | 233 | // Loop through the submitted details. |
234 | - foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
|
234 | + foreach ($submission->get_payment_form()->get_elements() as $field) { |
|
235 | 235 | |
236 | 236 | // Skip premade fields. |
237 | - if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) { |
|
237 | + if (!empty($field['premade']) || $field['type'] == 'address') { |
|
238 | 238 | continue; |
239 | 239 | } |
240 | 240 | |
241 | 241 | // If it is required and not set, abort. |
242 | - if ( ! $submission->is_required_field_set( $field ) ) { |
|
243 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
242 | + if (!$submission->is_required_field_set($field)) { |
|
243 | + wp_send_json_error(__('Please fill all required fields.', 'invoicing')); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | // Handle misc fields. |
247 | - if ( isset( $data[ $field['id'] ] ) ) { |
|
247 | + if (isset($data[$field['id']])) { |
|
248 | 248 | $label = $field['id']; |
249 | 249 | |
250 | - if ( isset( $field['label'] ) ) { |
|
250 | + if (isset($field['label'])) { |
|
251 | 251 | $label = $field['label']; |
252 | 252 | } |
253 | 253 | |
254 | - $prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] ); |
|
254 | + $prepared[wpinv_clean($label)] = wp_kses_post($data[$field['id']]); |
|
255 | 255 | |
256 | 256 | } |
257 | 257 | |
@@ -268,30 +268,30 @@ discard block |
||
268 | 268 | * @param WPInv_Invoice $invoice |
269 | 269 | * @param string $type |
270 | 270 | */ |
271 | - public function prepare_address_details( $invoice, $type = 'billing' ) { |
|
271 | + public function prepare_address_details($invoice, $type = 'billing') { |
|
272 | 272 | |
273 | 273 | $data = $this->payment_form_submission->get_data(); |
274 | - $type = sanitize_key( $type ); |
|
274 | + $type = sanitize_key($type); |
|
275 | 275 | $address = array(); |
276 | 276 | $prepared = array(); |
277 | 277 | |
278 | - if ( ! empty( $data[ $type ] ) ) { |
|
279 | - $address = $data[ $type ]; |
|
278 | + if (!empty($data[$type])) { |
|
279 | + $address = $data[$type]; |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | // Clean address details. |
283 | - foreach ( $address as $key => $value ) { |
|
284 | - $key = sanitize_key( $key ); |
|
285 | - $key = str_replace( 'wpinv_', '', $key ); |
|
286 | - $value = wpinv_clean( $value ); |
|
287 | - $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
283 | + foreach ($address as $key => $value) { |
|
284 | + $key = sanitize_key($key); |
|
285 | + $key = str_replace('wpinv_', '', $key); |
|
286 | + $value = wpinv_clean($value); |
|
287 | + $prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | // Filter address details. |
291 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
291 | + $prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice); |
|
292 | 292 | |
293 | 293 | // Remove non-whitelisted values. |
294 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
294 | + return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY); |
|
295 | 295 | |
296 | 296 | } |
297 | 297 | |
@@ -301,12 +301,12 @@ discard block |
||
301 | 301 | * @return array |
302 | 302 | * @param WPInv_Invoice $invoice |
303 | 303 | */ |
304 | - protected function prepare_billing_info( &$invoice ) { |
|
304 | + protected function prepare_billing_info(&$invoice) { |
|
305 | 305 | |
306 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
306 | + $billing_address = $this->prepare_address_details($invoice, 'billing'); |
|
307 | 307 | |
308 | 308 | // Update the invoice with the billing details. |
309 | - $invoice->set_props( $billing_address ); |
|
309 | + $invoice->set_props($billing_address); |
|
310 | 310 | |
311 | 311 | } |
312 | 312 | |
@@ -316,15 +316,15 @@ discard block |
||
316 | 316 | * @return array |
317 | 317 | * @param WPInv_Invoice $invoice |
318 | 318 | */ |
319 | - protected function prepare_shipping_info( $invoice ) { |
|
319 | + protected function prepare_shipping_info($invoice) { |
|
320 | 320 | |
321 | 321 | $data = $this->payment_form_submission->get_data(); |
322 | 322 | |
323 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
324 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
323 | + if (empty($data['same-shipping-address'])) { |
|
324 | + return $this->prepare_address_details($invoice, 'shipping'); |
|
325 | 325 | } |
326 | 326 | |
327 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
327 | + return $this->prepare_address_details($invoice, 'billing'); |
|
328 | 328 | |
329 | 329 | } |
330 | 330 | |
@@ -335,31 +335,31 @@ discard block |
||
335 | 335 | * @param array $prepared_payment_form_data |
336 | 336 | * @param array $shipping |
337 | 337 | */ |
338 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
338 | + protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) { |
|
339 | 339 | |
340 | 340 | // Ensure the invoice exists. |
341 | - if ( ! $invoice->exists() ) { |
|
342 | - wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
|
341 | + if (!$invoice->exists()) { |
|
342 | + wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing')); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | // Save payment form data. |
346 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
347 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
348 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data ); |
|
346 | + $prepared_payment_form_data = apply_filters('getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice); |
|
347 | + if (!empty($prepared_payment_form_data)) { |
|
348 | + update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data); |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | // Save payment form data. |
352 | - if ( ! empty( $shipping ) ) { |
|
353 | - update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
|
352 | + if (!empty($shipping)) { |
|
353 | + update_post_meta($invoice->get_id(), 'shipping_address', $shipping); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | // Backwards compatibility. |
357 | - add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
|
357 | + add_filter('wp_redirect', array($this, 'send_redirect_response')); |
|
358 | 358 | |
359 | - $this->process_payment( $invoice ); |
|
359 | + $this->process_payment($invoice); |
|
360 | 360 | |
361 | 361 | // If we are here, there was an error. |
362 | - wpinv_send_back_to_checkout( $invoice ); |
|
362 | + wpinv_send_back_to_checkout($invoice); |
|
363 | 363 | |
364 | 364 | } |
365 | 365 | |
@@ -368,41 +368,41 @@ discard block |
||
368 | 368 | * |
369 | 369 | * @param WPInv_Invoice $invoice |
370 | 370 | */ |
371 | - protected function process_payment( $invoice ) { |
|
371 | + protected function process_payment($invoice) { |
|
372 | 372 | |
373 | 373 | // Clear any checkout errors. |
374 | 374 | wpinv_clear_errors(); |
375 | 375 | |
376 | 376 | // No need to send free invoices to the gateway. |
377 | - if ( $invoice->is_free() ) { |
|
378 | - $this->process_free_payment( $invoice ); |
|
377 | + if ($invoice->is_free()) { |
|
378 | + $this->process_free_payment($invoice); |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | $submission = $this->payment_form_submission; |
382 | 382 | |
383 | 383 | // Fires before sending to the gateway. |
384 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
384 | + do_action('getpaid_checkout_before_gateway', $invoice, $submission); |
|
385 | 385 | |
386 | 386 | // Allow the sumission data to be modified before it is sent to the gateway. |
387 | 387 | $submission_data = $submission->get_data(); |
388 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
389 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
388 | + $submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice); |
|
389 | + $submission_data = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice); |
|
390 | 390 | |
391 | 391 | // Validate the currency. |
392 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
393 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
392 | + if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) { |
|
393 | + wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support this currency', 'invoicing')); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | // Check to see if we have any errors. |
397 | - if ( wpinv_get_errors() ) { |
|
398 | - wpinv_send_back_to_checkout( $invoice ); |
|
397 | + if (wpinv_get_errors()) { |
|
398 | + wpinv_send_back_to_checkout($invoice); |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | // Send info to the gateway for payment processing |
402 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
402 | + do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission); |
|
403 | 403 | |
404 | 404 | // Backwards compatibility. |
405 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
405 | + wpinv_send_to_gateway($submission_gateway, $invoice); |
|
406 | 406 | |
407 | 407 | } |
408 | 408 | |
@@ -411,12 +411,12 @@ discard block |
||
411 | 411 | * |
412 | 412 | * @param WPInv_Invoice $invoice |
413 | 413 | */ |
414 | - protected function process_free_payment( $invoice ) { |
|
414 | + protected function process_free_payment($invoice) { |
|
415 | 415 | |
416 | - $invoice->set_gateway( 'none' ); |
|
417 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
416 | + $invoice->set_gateway('none'); |
|
417 | + $invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true); |
|
418 | 418 | $invoice->mark_paid(); |
419 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
419 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
420 | 420 | |
421 | 421 | } |
422 | 422 | |
@@ -424,9 +424,9 @@ discard block |
||
424 | 424 | * Sends a redrect response to payment details. |
425 | 425 | * |
426 | 426 | */ |
427 | - public function send_redirect_response( $url ) { |
|
428 | - $url = urlencode( $url ); |
|
429 | - wp_send_json_success( $url ); |
|
427 | + public function send_redirect_response($url) { |
|
428 | + $url = urlencode($url); |
|
429 | + wp_send_json_success($url); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if (!defined('ABSPATH')) { |
|
11 | 11 | exit; // Exit if accessed directly |
12 | 12 | } |
13 | 13 | |
@@ -21,14 +21,14 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param WP_Post $post |
23 | 23 | */ |
24 | - public static function output( $post ) { |
|
24 | + public static function output($post) { |
|
25 | 25 | |
26 | 26 | // Prepare the invoice. |
27 | - $invoice = new WPInv_Invoice( $post ); |
|
28 | - $customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id(); |
|
29 | - $customer = new WP_User( $customer ); |
|
30 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ); |
|
31 | - wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
27 | + $invoice = new WPInv_Invoice($post); |
|
28 | + $customer = $invoice->exists() ? $invoice->get_user_id('edit') : get_current_user_id(); |
|
29 | + $customer = new WP_User($customer); |
|
30 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email); |
|
31 | + wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce'); |
|
32 | 32 | |
33 | 33 | ?> |
34 | 34 | |
@@ -43,11 +43,11 @@ discard block |
||
43 | 43 | <div class="col-12 col-sm-6"> |
44 | 44 | <div id="getpaid-invoice-user-id-wrapper" class="form-group"> |
45 | 45 | <div> |
46 | - <label for="post_author_override"><?php _e( 'Customer', 'invoicing' );?></label> |
|
46 | + <label for="post_author_override"><?php _e('Customer', 'invoicing'); ?></label> |
|
47 | 47 | </div> |
48 | 48 | <div> |
49 | - <select name="post_author_override" id="wpinv_post_author_override" class="getpaid-customer-search form-control regular-text" data-placeholder="<?php esc_attr_e( 'Search for a customer by email or name', 'invoicing' ); ?>"> |
|
50 | - <option selected="selected" value="<?php echo (int) $customer->ID; ?>"><?php echo sanitize_text_field( $display ); ?> </option>) |
|
49 | + <select name="post_author_override" id="wpinv_post_author_override" class="getpaid-customer-search form-control regular-text" data-placeholder="<?php esc_attr_e('Search for a customer by email or name', 'invoicing'); ?>"> |
|
50 | + <option selected="selected" value="<?php echo (int) $customer->ID; ?>"><?php echo sanitize_text_field($display); ?> </option>) |
|
51 | 51 | </select> |
52 | 52 | </div> |
53 | 53 | </div> |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | 'type' => 'text', |
61 | 61 | 'id' => 'getpaid-invoice-new-user-email', |
62 | 62 | 'name' => 'wpinv_email', |
63 | - 'label' => __( 'Email', 'invoicing' ) . '<span class="required">*</span>', |
|
63 | + 'label' => __('Email', 'invoicing') . '<span class="required">*</span>', |
|
64 | 64 | 'label_type' => 'vertical', |
65 | 65 | 'placeholder' => '[email protected]', |
66 | 66 | 'class' => 'form-control-sm', |
@@ -70,18 +70,18 @@ discard block |
||
70 | 70 | </div> |
71 | 71 | </div> |
72 | 72 | <div class="col-12 col-sm-6 form-group mt-sm-4"> |
73 | - <?php if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) : ?> |
|
73 | + <?php if (!$invoice->is_paid() && !$invoice->is_refunded()) : ?> |
|
74 | 74 | <a id="getpaid-invoice-fill-user-details" class="button button-small button-secondary" href="javascript:void(0)"> |
75 | 75 | <i aria-hidden="true" class="fa fa-refresh"></i> |
76 | - <?php _e( 'Fill User Details', 'invoicing' );?> |
|
76 | + <?php _e('Fill User Details', 'invoicing'); ?> |
|
77 | 77 | </a> |
78 | 78 | <a id="getpaid-invoice-create-new-user-button" class="button button-small button-secondary" href="javascript:void(0)"> |
79 | 79 | <i aria-hidden="true" class="fa fa-plus"></i> |
80 | - <?php _e( 'Add New User', 'invoicing' );?> |
|
80 | + <?php _e('Add New User', 'invoicing'); ?> |
|
81 | 81 | </a> |
82 | 82 | <a id="getpaid-invoice-cancel-create-new-user" class="button button-small button-secondary d-none" href="javascript:void(0)"> |
83 | 83 | <i aria-hidden="true" class="fa fa-close"></i> |
84 | - <?php _e( 'Cancel', 'invoicing' );?> |
|
84 | + <?php _e('Cancel', 'invoicing'); ?> |
|
85 | 85 | </a> |
86 | 86 | <?php endif; ?> |
87 | 87 | </div> |
@@ -94,11 +94,11 @@ discard block |
||
94 | 94 | 'type' => 'text', |
95 | 95 | 'id' => 'wpinv_first_name', |
96 | 96 | 'name' => 'wpinv_first_name', |
97 | - 'label' => __( 'First Name', 'invoicing' ), |
|
97 | + 'label' => __('First Name', 'invoicing'), |
|
98 | 98 | 'label_type' => 'vertical', |
99 | 99 | 'placeholder' => '', |
100 | 100 | 'class' => 'form-control-sm', |
101 | - 'value' => $invoice->get_first_name( 'edit' ), |
|
101 | + 'value' => $invoice->get_first_name('edit'), |
|
102 | 102 | ) |
103 | 103 | ); |
104 | 104 | ?> |
@@ -110,11 +110,11 @@ discard block |
||
110 | 110 | 'type' => 'text', |
111 | 111 | 'id' => 'wpinv_last_name', |
112 | 112 | 'name' => 'wpinv_last_name', |
113 | - 'label' => __( 'Last Name', 'invoicing' ), |
|
113 | + 'label' => __('Last Name', 'invoicing'), |
|
114 | 114 | 'label_type' => 'vertical', |
115 | 115 | 'placeholder' => '', |
116 | 116 | 'class' => 'form-control-sm', |
117 | - 'value' => $invoice->get_last_name( 'edit' ), |
|
117 | + 'value' => $invoice->get_last_name('edit'), |
|
118 | 118 | ) |
119 | 119 | ); |
120 | 120 | ?> |
@@ -129,11 +129,11 @@ discard block |
||
129 | 129 | 'type' => 'text', |
130 | 130 | 'id' => 'wpinv_company', |
131 | 131 | 'name' => 'wpinv_company', |
132 | - 'label' => __( 'Company', 'invoicing' ), |
|
132 | + 'label' => __('Company', 'invoicing'), |
|
133 | 133 | 'label_type' => 'vertical', |
134 | 134 | 'placeholder' => '', |
135 | 135 | 'class' => 'form-control-sm', |
136 | - 'value' => $invoice->get_company( 'edit' ), |
|
136 | + 'value' => $invoice->get_company('edit'), |
|
137 | 137 | ) |
138 | 138 | ); |
139 | 139 | ?> |
@@ -145,11 +145,11 @@ discard block |
||
145 | 145 | 'type' => 'text', |
146 | 146 | 'id' => 'wpinv_vat_number', |
147 | 147 | 'name' => 'wpinv_vat_number', |
148 | - 'label' => __( 'Vat Number', 'invoicing' ), |
|
148 | + 'label' => __('Vat Number', 'invoicing'), |
|
149 | 149 | 'label_type' => 'vertical', |
150 | 150 | 'placeholder' => '', |
151 | 151 | 'class' => 'form-control-sm', |
152 | - 'value' => $invoice->get_vat_number( 'edit' ), |
|
152 | + 'value' => $invoice->get_vat_number('edit'), |
|
153 | 153 | ) |
154 | 154 | ); |
155 | 155 | ?> |
@@ -164,11 +164,11 @@ discard block |
||
164 | 164 | 'type' => 'text', |
165 | 165 | 'id' => 'wpinv_address', |
166 | 166 | 'name' => 'wpinv_address', |
167 | - 'label' => __( 'Address', 'invoicing' ), |
|
167 | + 'label' => __('Address', 'invoicing'), |
|
168 | 168 | 'label_type' => 'vertical', |
169 | 169 | 'placeholder' => '', |
170 | 170 | 'class' => 'form-control-sm', |
171 | - 'value' => $invoice->get_address( 'edit' ), |
|
171 | + 'value' => $invoice->get_address('edit'), |
|
172 | 172 | ) |
173 | 173 | ); |
174 | 174 | ?> |
@@ -180,11 +180,11 @@ discard block |
||
180 | 180 | 'type' => 'text', |
181 | 181 | 'id' => 'wpinv_city', |
182 | 182 | 'name' => 'wpinv_city', |
183 | - 'label' => __( 'City', 'invoicing' ), |
|
183 | + 'label' => __('City', 'invoicing'), |
|
184 | 184 | 'label_type' => 'vertical', |
185 | 185 | 'placeholder' => '', |
186 | 186 | 'class' => 'form-control-sm', |
187 | - 'value' => $invoice->get_city( 'edit' ), |
|
187 | + 'value' => $invoice->get_city('edit'), |
|
188 | 188 | ) |
189 | 189 | ); |
190 | 190 | ?> |
@@ -198,11 +198,11 @@ discard block |
||
198 | 198 | array( |
199 | 199 | 'id' => 'wpinv_country', |
200 | 200 | 'name' => 'wpinv_country', |
201 | - 'label' => __( 'Country', 'invoicing' ), |
|
201 | + 'label' => __('Country', 'invoicing'), |
|
202 | 202 | 'label_type' => 'vertical', |
203 | - 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
203 | + 'placeholder' => __('Choose a country', 'invoicing'), |
|
204 | 204 | 'class' => 'form-control-sm', |
205 | - 'value' => $invoice->get_country( 'edit' ), |
|
205 | + 'value' => $invoice->get_country('edit'), |
|
206 | 206 | 'options' => wpinv_get_country_list(), |
207 | 207 | 'data-allow-clear' => 'false', |
208 | 208 | 'select2' => true, |
@@ -213,20 +213,20 @@ discard block |
||
213 | 213 | <div class="col-12 col-sm-6"> |
214 | 214 | <?php |
215 | 215 | |
216 | - $states = wpinv_get_country_states( $invoice->get_country( 'edit' ) ); |
|
216 | + $states = wpinv_get_country_states($invoice->get_country('edit')); |
|
217 | 217 | |
218 | - if ( empty( $states ) ) { |
|
218 | + if (empty($states)) { |
|
219 | 219 | |
220 | 220 | echo aui()->input( |
221 | 221 | array( |
222 | 222 | 'type' => 'text', |
223 | 223 | 'id' => 'wpinv_state', |
224 | 224 | 'name' => 'wpinv_state', |
225 | - 'label' => __( 'State', 'invoicing' ), |
|
225 | + 'label' => __('State', 'invoicing'), |
|
226 | 226 | 'label_type' => 'vertical', |
227 | 227 | 'placeholder' => '', |
228 | 228 | 'class' => 'form-control-sm', |
229 | - 'value' => $invoice->get_state( 'edit' ), |
|
229 | + 'value' => $invoice->get_state('edit'), |
|
230 | 230 | ) |
231 | 231 | ); |
232 | 232 | |
@@ -236,11 +236,11 @@ discard block |
||
236 | 236 | array( |
237 | 237 | 'id' => 'wpinv_state', |
238 | 238 | 'name' => 'wpinv_state', |
239 | - 'label' => __( 'State', 'invoicing' ), |
|
239 | + 'label' => __('State', 'invoicing'), |
|
240 | 240 | 'label_type' => 'vertical', |
241 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
241 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
242 | 242 | 'class' => 'form-control-sm', |
243 | - 'value' => $invoice->get_state( 'edit' ), |
|
243 | + 'value' => $invoice->get_state('edit'), |
|
244 | 244 | 'options' => $states, |
245 | 245 | 'data-allow-clear' => 'false', |
246 | 246 | 'select2' => true, |
@@ -261,11 +261,11 @@ discard block |
||
261 | 261 | 'type' => 'text', |
262 | 262 | 'id' => 'wpinv_zip', |
263 | 263 | 'name' => 'wpinv_zip', |
264 | - 'label' => __( 'Zip / Postal Code', 'invoicing' ), |
|
264 | + 'label' => __('Zip / Postal Code', 'invoicing'), |
|
265 | 265 | 'label_type' => 'vertical', |
266 | 266 | 'placeholder' => '', |
267 | 267 | 'class' => 'form-control-sm', |
268 | - 'value' => $invoice->get_zip( 'edit' ), |
|
268 | + 'value' => $invoice->get_zip('edit'), |
|
269 | 269 | ) |
270 | 270 | ); |
271 | 271 | ?> |
@@ -277,18 +277,18 @@ discard block |
||
277 | 277 | 'type' => 'text', |
278 | 278 | 'id' => 'wpinv_phone', |
279 | 279 | 'name' => 'wpinv_phone', |
280 | - 'label' => __( 'Phone', 'invoicing' ), |
|
280 | + 'label' => __('Phone', 'invoicing'), |
|
281 | 281 | 'label_type' => 'vertical', |
282 | 282 | 'placeholder' => '', |
283 | 283 | 'class' => 'form-control-sm', |
284 | - 'value' => $invoice->get_phone( 'edit' ), |
|
284 | + 'value' => $invoice->get_phone('edit'), |
|
285 | 285 | ) |
286 | 286 | ); |
287 | 287 | ?> |
288 | 288 | </div> |
289 | 289 | </div> |
290 | 290 | |
291 | - <?php do_action( 'getpaid_after_metabox_invoice_address', $invoice ); ?> |
|
291 | + <?php do_action('getpaid_after_metabox_invoice_address', $invoice); ?> |
|
292 | 292 | </div> |
293 | 293 | <?php |
294 | 294 | } |
@@ -298,50 +298,50 @@ discard block |
||
298 | 298 | * |
299 | 299 | * @param int $post_id |
300 | 300 | */ |
301 | - public static function save( $post_id ) { |
|
301 | + public static function save($post_id) { |
|
302 | 302 | |
303 | 303 | // Prepare the invoice. |
304 | - $invoice = new WPInv_Invoice( $post_id ); |
|
304 | + $invoice = new WPInv_Invoice($post_id); |
|
305 | 305 | |
306 | 306 | // Load new data. |
307 | 307 | $invoice->set_props( |
308 | 308 | array( |
309 | - 'template' => isset( $_POST['wpinv_template'] ) ? wpinv_clean( $_POST['wpinv_template'] ) : null, |
|
310 | - 'email_cc' => isset( $_POST['wpinv_cc'] ) ? wpinv_clean( $_POST['wpinv_cc'] ) : null, |
|
311 | - 'disable_taxes' => isset( $_POST['disable_taxes'] ), |
|
312 | - 'currency' => isset( $_POST['wpinv_currency'] ) ? wpinv_clean( $_POST['wpinv_currency'] ) : null, |
|
313 | - 'gateway' => ( $invoice->needs_payment() && isset( $_POST['wpinv_gateway'] ) ) ? wpinv_clean( $_POST['wpinv_gateway'] ) : null, |
|
314 | - 'address' => isset( $_POST['wpinv_address'] ) ? wpinv_clean( $_POST['wpinv_address'] ) : null, |
|
315 | - 'vat_number' => isset( $_POST['wpinv_vat_number'] ) ? wpinv_clean( $_POST['wpinv_vat_number'] ) : null, |
|
316 | - 'company' => isset( $_POST['wpinv_company'] ) ? wpinv_clean( $_POST['wpinv_company'] ) : null, |
|
317 | - 'zip' => isset( $_POST['wpinv_zip'] ) ? wpinv_clean( $_POST['wpinv_zip'] ) : null, |
|
318 | - 'state' => isset( $_POST['wpinv_state'] ) ? wpinv_clean( $_POST['wpinv_state'] ) : null, |
|
319 | - 'city' => isset( $_POST['wpinv_city'] ) ? wpinv_clean( $_POST['wpinv_city'] ) : null, |
|
320 | - 'country' => isset( $_POST['wpinv_country'] ) ? wpinv_clean( $_POST['wpinv_country'] ) : null, |
|
321 | - 'phone' => isset( $_POST['wpinv_phone'] ) ? wpinv_clean( $_POST['wpinv_phone'] ) : null, |
|
322 | - 'first_name' => isset( $_POST['wpinv_first_name'] ) ? wpinv_clean( $_POST['wpinv_first_name'] ) : null, |
|
323 | - 'last_name' => isset( $_POST['wpinv_last_name'] ) ? wpinv_clean( $_POST['wpinv_last_name'] ) : null, |
|
324 | - 'author' => isset( $_POST['post_author_override'] ) ? wpinv_clean( $_POST['post_author_override'] ) : null, |
|
325 | - 'date_created' => isset( $_POST['date_created'] ) ? wpinv_clean( $_POST['date_created'] ) : null, |
|
326 | - 'date_completed' => isset( $_POST['wpinv_date_completed'] ) ? wpinv_clean( $_POST['wpinv_date_completed'] ) : null, |
|
327 | - 'due_date' => isset( $_POST['wpinv_due_date'] ) ? wpinv_clean( $_POST['wpinv_due_date'] ) : null, |
|
328 | - 'number' => isset( $_POST['wpinv_number'] ) ? wpinv_clean( $_POST['wpinv_number'] ) : null, |
|
329 | - 'status' => isset( $_POST['wpinv_status'] ) ? wpinv_clean( $_POST['wpinv_status'] ) : null, |
|
309 | + 'template' => isset($_POST['wpinv_template']) ? wpinv_clean($_POST['wpinv_template']) : null, |
|
310 | + 'email_cc' => isset($_POST['wpinv_cc']) ? wpinv_clean($_POST['wpinv_cc']) : null, |
|
311 | + 'disable_taxes' => isset($_POST['disable_taxes']), |
|
312 | + 'currency' => isset($_POST['wpinv_currency']) ? wpinv_clean($_POST['wpinv_currency']) : null, |
|
313 | + 'gateway' => ($invoice->needs_payment() && isset($_POST['wpinv_gateway'])) ? wpinv_clean($_POST['wpinv_gateway']) : null, |
|
314 | + 'address' => isset($_POST['wpinv_address']) ? wpinv_clean($_POST['wpinv_address']) : null, |
|
315 | + 'vat_number' => isset($_POST['wpinv_vat_number']) ? wpinv_clean($_POST['wpinv_vat_number']) : null, |
|
316 | + 'company' => isset($_POST['wpinv_company']) ? wpinv_clean($_POST['wpinv_company']) : null, |
|
317 | + 'zip' => isset($_POST['wpinv_zip']) ? wpinv_clean($_POST['wpinv_zip']) : null, |
|
318 | + 'state' => isset($_POST['wpinv_state']) ? wpinv_clean($_POST['wpinv_state']) : null, |
|
319 | + 'city' => isset($_POST['wpinv_city']) ? wpinv_clean($_POST['wpinv_city']) : null, |
|
320 | + 'country' => isset($_POST['wpinv_country']) ? wpinv_clean($_POST['wpinv_country']) : null, |
|
321 | + 'phone' => isset($_POST['wpinv_phone']) ? wpinv_clean($_POST['wpinv_phone']) : null, |
|
322 | + 'first_name' => isset($_POST['wpinv_first_name']) ? wpinv_clean($_POST['wpinv_first_name']) : null, |
|
323 | + 'last_name' => isset($_POST['wpinv_last_name']) ? wpinv_clean($_POST['wpinv_last_name']) : null, |
|
324 | + 'author' => isset($_POST['post_author_override']) ? wpinv_clean($_POST['post_author_override']) : null, |
|
325 | + 'date_created' => isset($_POST['date_created']) ? wpinv_clean($_POST['date_created']) : null, |
|
326 | + 'date_completed' => isset($_POST['wpinv_date_completed']) ? wpinv_clean($_POST['wpinv_date_completed']) : null, |
|
327 | + 'due_date' => isset($_POST['wpinv_due_date']) ? wpinv_clean($_POST['wpinv_due_date']) : null, |
|
328 | + 'number' => isset($_POST['wpinv_number']) ? wpinv_clean($_POST['wpinv_number']) : null, |
|
329 | + 'status' => isset($_POST['wpinv_status']) ? wpinv_clean($_POST['wpinv_status']) : null, |
|
330 | 330 | ) |
331 | 331 | ); |
332 | 332 | |
333 | 333 | // Discount code. |
334 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
334 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
335 | 335 | |
336 | - if ( isset( $_POST['wpinv_discount_code'] ) ) { |
|
337 | - $invoice->set_discount_code( $_POST['wpinv_discount_code'] ); |
|
336 | + if (isset($_POST['wpinv_discount_code'])) { |
|
337 | + $invoice->set_discount_code($_POST['wpinv_discount_code']); |
|
338 | 338 | } |
339 | 339 | |
340 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
341 | - if ( $discount->exists() ) { |
|
342 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
340 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
341 | + if ($discount->exists()) { |
|
342 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
343 | 343 | } else { |
344 | - $invoice->remove_discount( 'discount_code' ); |
|
344 | + $invoice->remove_discount('discount_code'); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | // Recalculate totals. |
@@ -350,17 +350,17 @@ discard block |
||
350 | 350 | } |
351 | 351 | |
352 | 352 | // If we're creating a new user... |
353 | - if ( ! empty( $_POST['wpinv_new_user'] ) && is_email( $_POST['wpinv_email'] ) ) { |
|
353 | + if (!empty($_POST['wpinv_new_user']) && is_email($_POST['wpinv_email'])) { |
|
354 | 354 | |
355 | 355 | // Attempt to create the user. |
356 | - $user = wpinv_create_user( sanitize_email( $_POST['wpinv_email'] ) ); |
|
356 | + $user = wpinv_create_user(sanitize_email($_POST['wpinv_email'])); |
|
357 | 357 | |
358 | 358 | |
359 | 359 | // If successful, update the invoice author. |
360 | - if ( is_numeric( $user ) ) { |
|
361 | - $invoice->set_author( $user ); |
|
360 | + if (is_numeric($user)) { |
|
361 | + $invoice->set_author($user); |
|
362 | 362 | } else { |
363 | - wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ ); |
|
363 | + wpinv_error_log($user->get_error_message(), __('Invoice add new user', 'invoicing'), __FILE__, __LINE__); |
|
364 | 364 | } |
365 | 365 | } |
366 | 366 | |
@@ -374,24 +374,24 @@ discard block |
||
374 | 374 | $GLOBALS['wpinv_skip_invoice_notification'] = false; |
375 | 375 | |
376 | 376 | // (Maybe) send new user notification. |
377 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
378 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) { |
|
379 | - wp_send_new_user_notifications( $user, 'user' ); |
|
377 | + $should_send_notification = wpinv_get_option('disable_new_user_emails'); |
|
378 | + if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification))) { |
|
379 | + wp_send_new_user_notifications($user, 'user'); |
|
380 | 380 | } |
381 | 381 | |
382 | - if ( ! empty( $_POST['send_to_customer'] ) && ! $invoice->is_draft() ) { |
|
382 | + if (!empty($_POST['send_to_customer']) && !$invoice->is_draft()) { |
|
383 | 383 | |
384 | - $sent = getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true ); |
|
384 | + $sent = getpaid()->get('invoice_emails')->user_invoice($invoice, true); |
|
385 | 385 | |
386 | - if ( $sent ) { |
|
387 | - getpaid_admin()->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
386 | + if ($sent) { |
|
387 | + getpaid_admin()->show_success(__('Invoice was successfully sent to the customer', 'invoicing')); |
|
388 | 388 | } else { |
389 | - getpaid_admin()->show_error( __( 'Could not send the invoice to the customer', 'invoicing' ) ); |
|
389 | + getpaid_admin()->show_error(__('Could not send the invoice to the customer', 'invoicing')); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | } |
393 | 393 | |
394 | 394 | // Fires after an invoice is saved. |
395 | - do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
395 | + do_action('wpinv_invoice_metabox_saved', $invoice); |
|
396 | 396 | } |
397 | 397 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package GetPaid |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Generates a users select dropdown. |
@@ -16,13 +16,13 @@ discard block |
||
16 | 16 | * @param array $args |
17 | 17 | * @see wp_dropdown_users |
18 | 18 | */ |
19 | -function wpinv_dropdown_users( $args = '' ) { |
|
19 | +function wpinv_dropdown_users($args = '') { |
|
20 | 20 | |
21 | - if ( is_array( $args ) && ! empty( $args['show'] ) && 'display_name_with_email' == $args['show'] ) { |
|
21 | + if (is_array($args) && !empty($args['show']) && 'display_name_with_email' == $args['show']) { |
|
22 | 22 | $args['show'] = 'display_name_with_login'; |
23 | 23 | } |
24 | 24 | |
25 | - return wp_dropdown_users( $args ); |
|
25 | + return wp_dropdown_users($args); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -32,9 +32,9 @@ discard block |
||
32 | 32 | * @return string capability to check against |
33 | 33 | * @param string $capalibilty Optional. The alternative capability to check against. |
34 | 34 | */ |
35 | -function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) { |
|
35 | +function wpinv_get_capability($capalibilty = 'manage_invoicing') { |
|
36 | 36 | |
37 | - if ( current_user_can( 'manage_options' ) ) { |
|
37 | + if (current_user_can('manage_options')) { |
|
38 | 38 | return 'manage_options'; |
39 | 39 | }; |
40 | 40 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @return bool |
49 | 49 | */ |
50 | 50 | function wpinv_current_user_can_manage_invoicing() { |
51 | - return current_user_can( wpinv_get_capability() ); |
|
51 | + return current_user_can(wpinv_get_capability()); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -57,19 +57,19 @@ discard block |
||
57 | 57 | * @since 1.0.19 |
58 | 58 | * @return int|WP_Error |
59 | 59 | */ |
60 | -function wpinv_create_user( $email, $prefix = '' ) { |
|
60 | +function wpinv_create_user($email, $prefix = '') { |
|
61 | 61 | |
62 | 62 | // Prepare user values. |
63 | - $prefix = preg_replace( '/\s+/', '', $prefix ); |
|
64 | - $prefix = empty( $prefix ) ? $email : $prefix; |
|
65 | - $args = array( |
|
66 | - 'user_login' => wpinv_generate_user_name( $prefix ), |
|
63 | + $prefix = preg_replace('/\s+/', '', $prefix); |
|
64 | + $prefix = empty($prefix) ? $email : $prefix; |
|
65 | + $args = array( |
|
66 | + 'user_login' => wpinv_generate_user_name($prefix), |
|
67 | 67 | 'user_pass' => wp_generate_password(), |
68 | 68 | 'user_email' => $email, |
69 | 69 | 'role' => 'subscriber', |
70 | 70 | ); |
71 | 71 | |
72 | - return wp_insert_user( $args ); |
|
72 | + return wp_insert_user($args); |
|
73 | 73 | |
74 | 74 | } |
75 | 75 | |
@@ -79,26 +79,26 @@ discard block |
||
79 | 79 | * @since 1.0.19 |
80 | 80 | * @return bool|WP_User |
81 | 81 | */ |
82 | -function wpinv_generate_user_name( $prefix = '' ) { |
|
82 | +function wpinv_generate_user_name($prefix = '') { |
|
83 | 83 | |
84 | 84 | // If prefix is an email, retrieve the part before the email. |
85 | - $prefix = strtok( $prefix, '@' ); |
|
86 | - $prefix = trim( $prefix, '.' ); |
|
85 | + $prefix = strtok($prefix, '@'); |
|
86 | + $prefix = trim($prefix, '.'); |
|
87 | 87 | |
88 | 88 | // Sanitize the username. |
89 | - $prefix = sanitize_user( $prefix, true ); |
|
89 | + $prefix = sanitize_user($prefix, true); |
|
90 | 90 | |
91 | - $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
92 | - if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
93 | - $prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
91 | + $illegal_logins = (array) apply_filters('illegal_user_logins', array()); |
|
92 | + if (empty($prefix) || in_array(strtolower($prefix), array_map('strtolower', $illegal_logins), true)) { |
|
93 | + $prefix = 'gtp_' . zeroise(wp_rand(0, 9999), 4); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | $username = $prefix; |
97 | 97 | $postfix = 2; |
98 | 98 | |
99 | - while ( username_exists( $username ) ) { |
|
99 | + while (username_exists($username)) { |
|
100 | 100 | $username = $prefix + $postfix; |
101 | - $postfix ++; |
|
101 | + $postfix++; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | return $username; |
@@ -115,31 +115,31 @@ discard block |
||
115 | 115 | $tabs = array( |
116 | 116 | |
117 | 117 | 'gp-invoices' => array( |
118 | - 'label' => __( 'Invoices', 'invoicing' ), // Name of the tab. |
|
118 | + 'label' => __('Invoices', 'invoicing'), // Name of the tab. |
|
119 | 119 | 'content' => '[wpinv_history]', // Content of the tab. Or specify "callback" to provide a callback instead. |
120 | 120 | 'icon' => 'fas fa-file-invoice', // Shown on some profile plugins. |
121 | 121 | ), |
122 | 122 | |
123 | 123 | 'gp-subscriptions' => array( |
124 | - 'label' => __( 'Subscriptions', 'invoicing' ), |
|
124 | + 'label' => __('Subscriptions', 'invoicing'), |
|
125 | 125 | 'content' => '[wpinv_subscriptions]', |
126 | 126 | 'icon' => 'fas fa-redo', |
127 | 127 | ), |
128 | 128 | |
129 | 129 | 'gp-edit-address' => array( |
130 | - 'label' => __( 'Billing Address', 'invoicing' ), |
|
130 | + 'label' => __('Billing Address', 'invoicing'), |
|
131 | 131 | 'callback' => 'getpaid_display_address_edit_tab', |
132 | 132 | 'icon' => 'fas fa-credit-card', |
133 | 133 | ), |
134 | 134 | |
135 | 135 | ); |
136 | 136 | |
137 | - $tabs = apply_filters( 'getpaid_user_content_tabs', $tabs ); |
|
137 | + $tabs = apply_filters('getpaid_user_content_tabs', $tabs); |
|
138 | 138 | |
139 | 139 | // Make sure address editing is last on the list. |
140 | - if ( isset( $tabs['gp-edit-address'] ) ) { |
|
140 | + if (isset($tabs['gp-edit-address'])) { |
|
141 | 141 | $address = $tabs['gp-edit-address']; |
142 | - unset( $tabs['gp-edit-address'] ); |
|
142 | + unset($tabs['gp-edit-address']); |
|
143 | 143 | $tabs['gp-edit-address'] = $address; |
144 | 144 | } |
145 | 145 | |
@@ -153,19 +153,19 @@ discard block |
||
153 | 153 | * @param array $tab |
154 | 154 | * @return array |
155 | 155 | */ |
156 | -function getpaid_prepare_user_content_tab( $tab ) { |
|
156 | +function getpaid_prepare_user_content_tab($tab) { |
|
157 | 157 | |
158 | - if ( ! empty( $tab['callback'] ) ) { |
|
159 | - return call_user_func( $tab['callback'] ); |
|
158 | + if (!empty($tab['callback'])) { |
|
159 | + return call_user_func($tab['callback']); |
|
160 | 160 | } |
161 | 161 | |
162 | - if ( ! empty( $tab['content'] ) ) { |
|
163 | - return convert_smilies( capital_P_dangit( wp_filter_content_tags( do_shortcode( shortcode_unautop( wpautop( wptexturize( do_blocks( $tab['content'] ) ) ) ) ) ) ) ); |
|
162 | + if (!empty($tab['content'])) { |
|
163 | + return convert_smilies(capital_P_dangit(wp_filter_content_tags(do_shortcode(shortcode_unautop(wpautop(wptexturize(do_blocks($tab['content'])))))))); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | $notice = aui()->alert( |
167 | 167 | array( |
168 | - 'content' => __( 'This tab has no content or content callback.', 'invoicing' ), |
|
168 | + 'content' => __('This tab has no content or content callback.', 'invoicing'), |
|
169 | 169 | 'type' => 'error', |
170 | 170 | ) |
171 | 171 | ); |
@@ -181,14 +181,14 @@ discard block |
||
181 | 181 | * @param string $default |
182 | 182 | * @return array |
183 | 183 | */ |
184 | -function getpaid_get_tab_url( $tab, $default ) { |
|
184 | +function getpaid_get_tab_url($tab, $default) { |
|
185 | 185 | global $getpaid_tab_url; |
186 | 186 | |
187 | - if ( empty( $getpaid_tab_url ) ) { |
|
187 | + if (empty($getpaid_tab_url)) { |
|
188 | 188 | return $default; |
189 | 189 | } |
190 | 190 | |
191 | - return sprintf( $getpaid_tab_url, $tab ); |
|
191 | + return sprintf($getpaid_tab_url, $tab); |
|
192 | 192 | |
193 | 193 | } |
194 | 194 | |
@@ -208,19 +208,19 @@ discard block |
||
208 | 208 | |
209 | 209 | <?php |
210 | 210 | |
211 | - foreach ( getpaid_user_address_fields() as $key => $label ) { |
|
211 | + foreach (getpaid_user_address_fields() as $key => $label) { |
|
212 | 212 | |
213 | 213 | // Display the country. |
214 | - if ( 'country' == $key ) { |
|
214 | + if ('country' == $key) { |
|
215 | 215 | |
216 | 216 | echo aui()->select( |
217 | 217 | array( |
218 | 218 | 'options' => wpinv_get_country_list(), |
219 | - 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
|
220 | - 'id' => 'wpinv-' . sanitize_html_class( $key ), |
|
221 | - 'value' => sanitize_text_field( getpaid_get_user_address_field( get_current_user_id(), $key ) ), |
|
219 | + 'name' => 'getpaid_address[' . esc_attr($key) . ']', |
|
220 | + 'id' => 'wpinv-' . sanitize_html_class($key), |
|
221 | + 'value' => sanitize_text_field(getpaid_get_user_address_field(get_current_user_id(), $key)), |
|
222 | 222 | 'placeholder' => $label, |
223 | - 'label' => wp_kses_post( $label ), |
|
223 | + 'label' => wp_kses_post($label), |
|
224 | 224 | 'label_type' => 'vertical', |
225 | 225 | 'class' => 'getpaid-address-field', |
226 | 226 | ) |
@@ -229,30 +229,30 @@ discard block |
||
229 | 229 | } |
230 | 230 | |
231 | 231 | // Display the state. |
232 | - else if ( 'state' == $key ) { |
|
232 | + else if ('state' == $key) { |
|
233 | 233 | |
234 | - echo getpaid_get_states_select_markup ( |
|
235 | - getpaid_get_user_address_field( get_current_user_id(), 'country' ), |
|
236 | - getpaid_get_user_address_field( get_current_user_id(), 'state' ), |
|
234 | + echo getpaid_get_states_select_markup( |
|
235 | + getpaid_get_user_address_field(get_current_user_id(), 'country'), |
|
236 | + getpaid_get_user_address_field(get_current_user_id(), 'state'), |
|
237 | 237 | $label, |
238 | 238 | $label, |
239 | 239 | '', |
240 | 240 | false, |
241 | 241 | '', |
242 | - 'getpaid_address[' . esc_attr( $key ) . ']' |
|
242 | + 'getpaid_address[' . esc_attr($key) . ']' |
|
243 | 243 | ); |
244 | 244 | |
245 | 245 | } else { |
246 | 246 | |
247 | 247 | echo aui()->input( |
248 | 248 | array( |
249 | - 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
|
250 | - 'id' => 'wpinv-' . sanitize_html_class( $key ), |
|
249 | + 'name' => 'getpaid_address[' . esc_attr($key) . ']', |
|
250 | + 'id' => 'wpinv-' . sanitize_html_class($key), |
|
251 | 251 | 'placeholder' => $label, |
252 | - 'label' => wp_kses_post( $label ), |
|
252 | + 'label' => wp_kses_post($label), |
|
253 | 253 | 'label_type' => 'vertical', |
254 | 254 | 'type' => 'text', |
255 | - 'value' => sanitize_text_field( getpaid_get_user_address_field( get_current_user_id(), $key ) ), |
|
255 | + 'value' => sanitize_text_field(getpaid_get_user_address_field(get_current_user_id(), $key)), |
|
256 | 256 | 'class' => 'getpaid-address-field', |
257 | 257 | ) |
258 | 258 | ); |
@@ -261,21 +261,21 @@ discard block |
||
261 | 261 | |
262 | 262 | } |
263 | 263 | |
264 | - do_action( 'getpaid_display_address_edit_tab' ); |
|
264 | + do_action('getpaid_display_address_edit_tab'); |
|
265 | 265 | |
266 | 266 | echo aui()->input( |
267 | 267 | array( |
268 | 268 | 'name' => 'getpaid_profile_edit_submit_button', |
269 | 269 | 'id' => 'getpaid_profile_edit_submit_button', |
270 | - 'value' => __( 'Save Address', 'invoicing' ), |
|
271 | - 'help_text' => __( 'New invoices will use this address as the billing address.', 'invoicing' ), |
|
270 | + 'value' => __('Save Address', 'invoicing'), |
|
271 | + 'help_text' => __('New invoices will use this address as the billing address.', 'invoicing'), |
|
272 | 272 | 'type' => 'submit', |
273 | 273 | 'class' => 'btn btn-primary btn-block submit-button', |
274 | 274 | ) |
275 | 275 | ); |
276 | 276 | |
277 | - wp_nonce_field( 'getpaid-nonce', 'getpaid-nonce' ); |
|
278 | - getpaid_hidden_field( 'getpaid-action', 'edit_billing_details' ); |
|
277 | + wp_nonce_field('getpaid-nonce', 'getpaid-nonce'); |
|
278 | + getpaid_hidden_field('getpaid-action', 'edit_billing_details'); |
|
279 | 279 | ?> |
280 | 280 | |
281 | 281 | </form> |
@@ -292,27 +292,27 @@ discard block |
||
292 | 292 | * @since 2.1.4 |
293 | 293 | * @param array $data |
294 | 294 | */ |
295 | -function getpaid_save_address_edit_tab( $data ) { |
|
295 | +function getpaid_save_address_edit_tab($data) { |
|
296 | 296 | |
297 | - if ( empty( $data['getpaid_address'] ) || ! is_array( $data['getpaid_address'] ) ) { |
|
297 | + if (empty($data['getpaid_address']) || !is_array($data['getpaid_address'])) { |
|
298 | 298 | return; |
299 | 299 | } |
300 | 300 | |
301 | 301 | $data = $data['getpaid_address']; |
302 | 302 | $user_id = get_current_user_id(); |
303 | 303 | |
304 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
304 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
305 | 305 | |
306 | - if ( isset( $data[ $field ] ) ) { |
|
307 | - $value = sanitize_text_field( $data[ $field ] ); |
|
308 | - update_user_meta( $user_id, '_wpinv_' . $field, $value ); |
|
306 | + if (isset($data[$field])) { |
|
307 | + $value = sanitize_text_field($data[$field]); |
|
308 | + update_user_meta($user_id, '_wpinv_' . $field, $value); |
|
309 | 309 | } |
310 | 310 | |
311 | - wpinv_set_error( 'address_updated', __( 'Your billing address has been updated', 'invoicing' ), 'success'); |
|
311 | + wpinv_set_error('address_updated', __('Your billing address has been updated', 'invoicing'), 'success'); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | } |
315 | -add_action( 'getpaid_authenticated_action_edit_billing_details', 'getpaid_save_address_edit_tab' ); |
|
315 | +add_action('getpaid_authenticated_action_edit_billing_details', 'getpaid_save_address_edit_tab'); |
|
316 | 316 | |
317 | 317 | |
318 | 318 | /* |
@@ -330,27 +330,27 @@ discard block |
||
330 | 330 | * @param array $tabs |
331 | 331 | * @return array |
332 | 332 | */ |
333 | -function getpaid_filter_userswp_account_tabs( $tabs ) { |
|
333 | +function getpaid_filter_userswp_account_tabs($tabs) { |
|
334 | 334 | |
335 | 335 | // Abort if the integration is inactive. |
336 | - if ( ! getpaid_is_userswp_integration_active() ) { |
|
336 | + if (!getpaid_is_userswp_integration_active()) { |
|
337 | 337 | return $tabs; |
338 | 338 | } |
339 | 339 | |
340 | - $new_tabs = array(); |
|
340 | + $new_tabs = array(); |
|
341 | 341 | |
342 | - foreach ( getpaid_get_user_content_tabs() as $slug => $tab ) { |
|
342 | + foreach (getpaid_get_user_content_tabs() as $slug => $tab) { |
|
343 | 343 | |
344 | - $new_tabs[ $slug ] = array( |
|
345 | - 'title' => $tab[ 'label'], |
|
346 | - 'icon' => $tab[ 'icon'], |
|
344 | + $new_tabs[$slug] = array( |
|
345 | + 'title' => $tab['label'], |
|
346 | + 'icon' => $tab['icon'], |
|
347 | 347 | ); |
348 | 348 | |
349 | 349 | } |
350 | 350 | |
351 | - return array_merge( $tabs, $new_tabs ); |
|
351 | + return array_merge($tabs, $new_tabs); |
|
352 | 352 | } |
353 | -add_filter( 'uwp_account_available_tabs', 'getpaid_filter_userswp_account_tabs' ); |
|
353 | +add_filter('uwp_account_available_tabs', 'getpaid_filter_userswp_account_tabs'); |
|
354 | 354 | |
355 | 355 | /** |
356 | 356 | * Display our UsersWP account tabs. |
@@ -359,18 +359,18 @@ discard block |
||
359 | 359 | * @param array $tabs |
360 | 360 | * @return array |
361 | 361 | */ |
362 | -function getpaid_display_userswp_account_tabs( $tab ) { |
|
362 | +function getpaid_display_userswp_account_tabs($tab) { |
|
363 | 363 | global $getpaid_tab_url; |
364 | 364 | |
365 | 365 | $our_tabs = getpaid_get_user_content_tabs(); |
366 | 366 | |
367 | - if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) { |
|
368 | - $getpaid_tab_url = add_query_arg( 'type', '%s', uwp_get_account_page_url() ); |
|
369 | - echo getpaid_prepare_user_content_tab( $our_tabs[ $tab ] ); |
|
367 | + if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) { |
|
368 | + $getpaid_tab_url = add_query_arg('type', '%s', uwp_get_account_page_url()); |
|
369 | + echo getpaid_prepare_user_content_tab($our_tabs[$tab]); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | } |
373 | -add_action( 'uwp_account_form_display', 'getpaid_display_userswp_account_tabs' ); |
|
373 | +add_action('uwp_account_form_display', 'getpaid_display_userswp_account_tabs'); |
|
374 | 374 | |
375 | 375 | |
376 | 376 | /** |
@@ -381,17 +381,17 @@ discard block |
||
381 | 381 | * @param string $tab Current tab. |
382 | 382 | * @return string Title. |
383 | 383 | */ |
384 | -function getpaid_filter_userswp_account_title( $title, $tab ) { |
|
384 | +function getpaid_filter_userswp_account_title($title, $tab) { |
|
385 | 385 | |
386 | - $our_tabs = getpaid_get_user_content_tabs(); |
|
386 | + $our_tabs = getpaid_get_user_content_tabs(); |
|
387 | 387 | |
388 | - if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) { |
|
389 | - return $our_tabs[ $tab ]['label']; |
|
388 | + if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) { |
|
389 | + return $our_tabs[$tab]['label']; |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | return $title; |
393 | 393 | } |
394 | -add_filter( 'uwp_account_page_title', 'getpaid_filter_userswp_account_title', 10, 2 ); |
|
394 | +add_filter('uwp_account_page_title', 'getpaid_filter_userswp_account_title', 10, 2); |
|
395 | 395 | |
396 | 396 | /** |
397 | 397 | * Registers the UsersWP integration settings. |
@@ -400,26 +400,26 @@ discard block |
||
400 | 400 | * @param array $settings An array of integration settings. |
401 | 401 | * @return array |
402 | 402 | */ |
403 | -function getpaid_register_userswp_settings( $settings ) { |
|
403 | +function getpaid_register_userswp_settings($settings) { |
|
404 | 404 | |
405 | - if ( defined( 'USERSWP_PLUGIN_FILE' ) ) { |
|
405 | + if (defined('USERSWP_PLUGIN_FILE')) { |
|
406 | 406 | |
407 | 407 | $settings[] = array( |
408 | 408 | |
409 | 409 | 'id' => 'userswp', |
410 | - 'label' => __( 'UsersWP', 'invoicing' ), |
|
410 | + 'label' => __('UsersWP', 'invoicing'), |
|
411 | 411 | 'settings' => array( |
412 | 412 | |
413 | 413 | 'userswp_settings' => array( |
414 | 414 | 'id' => 'userswp_settings', |
415 | - 'name' => '<h3>' . __( 'UsersWP', 'invoicing' ) . '</h3>', |
|
415 | + 'name' => '<h3>' . __('UsersWP', 'invoicing') . '</h3>', |
|
416 | 416 | 'type' => 'header', |
417 | 417 | ), |
418 | 418 | |
419 | 419 | 'enable_userswp' => array( |
420 | 420 | 'id' => 'enable_userswp', |
421 | - 'name' => __( 'Enable Integration', 'invoicing' ), |
|
422 | - 'desc' => __( 'Display GetPaid items on UsersWP account page.', 'invoicing' ), |
|
421 | + 'name' => __('Enable Integration', 'invoicing'), |
|
422 | + 'desc' => __('Display GetPaid items on UsersWP account page.', 'invoicing'), |
|
423 | 423 | 'type' => 'checkbox', |
424 | 424 | 'std' => 1, |
425 | 425 | ) |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | |
433 | 433 | return $settings; |
434 | 434 | } |
435 | -add_filter( 'getpaid_integration_settings', 'getpaid_register_userswp_settings' ); |
|
435 | +add_filter('getpaid_integration_settings', 'getpaid_register_userswp_settings'); |
|
436 | 436 | |
437 | 437 | /** |
438 | 438 | * Ovewrites the invoices history page to UsersWP. |
@@ -440,18 +440,18 @@ discard block |
||
440 | 440 | * @since 2.3.1 |
441 | 441 | * @return bool |
442 | 442 | */ |
443 | -function getpaid_userswp_overwrite_invoice_history_page( $url, $post_type ) { |
|
443 | +function getpaid_userswp_overwrite_invoice_history_page($url, $post_type) { |
|
444 | 444 | |
445 | 445 | $our_tabs = getpaid_get_user_content_tabs(); |
446 | 446 | $tab = "gp-{$post_type}s"; |
447 | - if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) { |
|
448 | - return add_query_arg( 'type', $tab, uwp_get_account_page_url() ); |
|
447 | + if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) { |
|
448 | + return add_query_arg('type', $tab, uwp_get_account_page_url()); |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | return $url; |
452 | 452 | |
453 | 453 | } |
454 | -add_filter( 'wpinv_get_history_page_uri', 'getpaid_userswp_overwrite_invoice_history_page', 10, 2 ); |
|
454 | +add_filter('wpinv_get_history_page_uri', 'getpaid_userswp_overwrite_invoice_history_page', 10, 2); |
|
455 | 455 | |
456 | 456 | /** |
457 | 457 | * Checks if the integration is enabled. |
@@ -460,8 +460,8 @@ discard block |
||
460 | 460 | * @return bool |
461 | 461 | */ |
462 | 462 | function getpaid_is_userswp_integration_active() { |
463 | - $enabled = wpinv_get_option( 'enable_userswp', 1 ); |
|
464 | - return defined( 'USERSWP_PLUGIN_FILE' ) && ! empty( $enabled ); |
|
463 | + $enabled = wpinv_get_option('enable_userswp', 1); |
|
464 | + return defined('USERSWP_PLUGIN_FILE') && !empty($enabled); |
|
465 | 465 | } |
466 | 466 | |
467 | 467 | /* |
@@ -479,26 +479,26 @@ discard block |
||
479 | 479 | * @param array $settings An array of integration settings. |
480 | 480 | * @return array |
481 | 481 | */ |
482 | -function getpaid_register_buddypress_settings( $settings ) { |
|
482 | +function getpaid_register_buddypress_settings($settings) { |
|
483 | 483 | |
484 | - if ( class_exists( 'BuddyPress' ) ) { |
|
484 | + if (class_exists('BuddyPress')) { |
|
485 | 485 | |
486 | 486 | $settings[] = array( |
487 | 487 | |
488 | 488 | 'id' => 'buddypress', |
489 | - 'label' => __( 'BuddyPress', 'invoicing' ), |
|
489 | + 'label' => __('BuddyPress', 'invoicing'), |
|
490 | 490 | 'settings' => array( |
491 | 491 | |
492 | 492 | 'buddypress_settings' => array( |
493 | 493 | 'id' => 'buddypress_settings', |
494 | - 'name' => '<h3>' . __( 'BuddyPress', 'invoicing' ) . '</h3>', |
|
494 | + 'name' => '<h3>' . __('BuddyPress', 'invoicing') . '</h3>', |
|
495 | 495 | 'type' => 'header', |
496 | 496 | ), |
497 | 497 | |
498 | 498 | 'enable_buddypress' => array( |
499 | 499 | 'id' => 'enable_buddypress', |
500 | - 'name' => __( 'Enable Integration', 'invoicing' ), |
|
501 | - 'desc' => __( 'Display GetPaid items on BuddyPress account pages.', 'invoicing' ), |
|
500 | + 'name' => __('Enable Integration', 'invoicing'), |
|
501 | + 'desc' => __('Display GetPaid items on BuddyPress account pages.', 'invoicing'), |
|
502 | 502 | 'type' => 'checkbox', |
503 | 503 | 'std' => 1, |
504 | 504 | ) |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | |
512 | 512 | return $settings; |
513 | 513 | } |
514 | -add_filter( 'getpaid_integration_settings', 'getpaid_register_buddypress_settings' ); |
|
514 | +add_filter('getpaid_integration_settings', 'getpaid_register_buddypress_settings'); |
|
515 | 515 | |
516 | 516 | /** |
517 | 517 | * Checks if the integration is enabled. |
@@ -520,8 +520,8 @@ discard block |
||
520 | 520 | * @return bool |
521 | 521 | */ |
522 | 522 | function getpaid_is_buddypress_integration_active() { |
523 | - $enabled = wpinv_get_option( 'enable_buddypress', 1 ); |
|
524 | - return class_exists( 'BuddyPress' ) && ! empty( $enabled ); |
|
523 | + $enabled = wpinv_get_option('enable_buddypress', 1); |
|
524 | + return class_exists('BuddyPress') && !empty($enabled); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | /** |
@@ -532,10 +532,10 @@ discard block |
||
532 | 532 | */ |
533 | 533 | function getpaid_setup_buddypress_integration() { |
534 | 534 | |
535 | - if ( getpaid_is_buddypress_integration_active() ) { |
|
536 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-bp-getpaid-component.php' ); |
|
535 | + if (getpaid_is_buddypress_integration_active()) { |
|
536 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-bp-getpaid-component.php'); |
|
537 | 537 | buddypress()->getpaid = new BP_GetPaid_Component(); |
538 | 538 | } |
539 | 539 | |
540 | 540 | } |
541 | -add_action( 'bp_setup_components', 'getpaid_setup_buddypress_integration' ); |
|
541 | +add_action('bp_setup_components', 'getpaid_setup_buddypress_integration'); |
@@ -4,99 +4,99 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Displays an invoice. |
11 | 11 | * |
12 | 12 | * @param WPInv_Invoice $invoice. |
13 | 13 | */ |
14 | -function getpaid_invoice( $invoice ) { |
|
15 | - if ( ! empty( $invoice ) ) { |
|
16 | - wpinv_get_template( 'invoice/invoice.php', compact( 'invoice' ) ); |
|
14 | +function getpaid_invoice($invoice) { |
|
15 | + if (!empty($invoice)) { |
|
16 | + wpinv_get_template('invoice/invoice.php', compact('invoice')); |
|
17 | 17 | } |
18 | 18 | } |
19 | -add_action( 'getpaid_invoice', 'getpaid_invoice', 10 ); |
|
19 | +add_action('getpaid_invoice', 'getpaid_invoice', 10); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Displays the invoice footer. |
23 | 23 | */ |
24 | -function getpaid_invoice_footer( $invoice ) { |
|
25 | - if ( ! empty( $invoice ) ) { |
|
26 | - wpinv_get_template( 'invoice/footer.php', compact( 'invoice' ) ); |
|
24 | +function getpaid_invoice_footer($invoice) { |
|
25 | + if (!empty($invoice)) { |
|
26 | + wpinv_get_template('invoice/footer.php', compact('invoice')); |
|
27 | 27 | } |
28 | 28 | } |
29 | -add_action( 'getpaid_invoice_footer', 'getpaid_invoice_footer', 10 ); |
|
29 | +add_action('getpaid_invoice_footer', 'getpaid_invoice_footer', 10); |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Displays the invoice top bar. |
33 | 33 | */ |
34 | -function getpaid_invoice_header( $invoice ) { |
|
35 | - if ( ! empty( $invoice ) ) { |
|
36 | - wpinv_get_template( 'invoice/header.php', compact( 'invoice' ) ); |
|
34 | +function getpaid_invoice_header($invoice) { |
|
35 | + if (!empty($invoice)) { |
|
36 | + wpinv_get_template('invoice/header.php', compact('invoice')); |
|
37 | 37 | } |
38 | 38 | } |
39 | -add_action( 'getpaid_invoice_header', 'getpaid_invoice_header', 10 ); |
|
39 | +add_action('getpaid_invoice_header', 'getpaid_invoice_header', 10); |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Displays actions on the left side of the header. |
43 | 43 | */ |
44 | -function getpaid_invoice_header_left_actions( $invoice ) { |
|
45 | - if ( ! empty( $invoice ) ) { |
|
46 | - wpinv_get_template( 'invoice/header-left-actions.php', compact( 'invoice' ) ); |
|
44 | +function getpaid_invoice_header_left_actions($invoice) { |
|
45 | + if (!empty($invoice)) { |
|
46 | + wpinv_get_template('invoice/header-left-actions.php', compact('invoice')); |
|
47 | 47 | } |
48 | 48 | } |
49 | -add_action( 'getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10 ); |
|
49 | +add_action('getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10); |
|
50 | 50 | |
51 | 51 | /** |
52 | 52 | * Displays actions on the right side of the invoice top bar. |
53 | 53 | */ |
54 | -function getpaid_invoice_header_right_actions( $invoice ) { |
|
55 | - if ( ! empty( $invoice ) ) { |
|
56 | - wpinv_get_template( 'invoice/header-right-actions.php', compact( 'invoice' ) ); |
|
54 | +function getpaid_invoice_header_right_actions($invoice) { |
|
55 | + if (!empty($invoice)) { |
|
56 | + wpinv_get_template('invoice/header-right-actions.php', compact('invoice')); |
|
57 | 57 | } |
58 | 58 | } |
59 | -add_action( 'getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10 ); |
|
59 | +add_action('getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10); |
|
60 | 60 | |
61 | 61 | /** |
62 | 62 | * Displays the invoice title, logo etc. |
63 | 63 | */ |
64 | -function getpaid_invoice_details_top( $invoice ) { |
|
65 | - if ( ! empty( $invoice ) ) { |
|
66 | - wpinv_get_template( 'invoice/details-top.php', compact( 'invoice' ) ); |
|
64 | +function getpaid_invoice_details_top($invoice) { |
|
65 | + if (!empty($invoice)) { |
|
66 | + wpinv_get_template('invoice/details-top.php', compact('invoice')); |
|
67 | 67 | } |
68 | 68 | } |
69 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_top', 10 ); |
|
69 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_top', 10); |
|
70 | 70 | |
71 | 71 | /** |
72 | 72 | * Displays the company logo. |
73 | 73 | */ |
74 | -function getpaid_invoice_logo( $invoice ) { |
|
75 | - if ( ! empty( $invoice ) ) { |
|
76 | - wpinv_get_template( 'invoice/invoice-logo.php', compact( 'invoice' ) ); |
|
74 | +function getpaid_invoice_logo($invoice) { |
|
75 | + if (!empty($invoice)) { |
|
76 | + wpinv_get_template('invoice/invoice-logo.php', compact('invoice')); |
|
77 | 77 | } |
78 | 78 | } |
79 | -add_action( 'getpaid_invoice_details_top_left', 'getpaid_invoice_logo' ); |
|
79 | +add_action('getpaid_invoice_details_top_left', 'getpaid_invoice_logo'); |
|
80 | 80 | |
81 | 81 | /** |
82 | 82 | * Displays the type of invoice. |
83 | 83 | */ |
84 | -function getpaid_invoice_type( $invoice ) { |
|
85 | - if ( ! empty( $invoice ) ) { |
|
86 | - wpinv_get_template( 'invoice/invoice-type.php', compact( 'invoice' ) ); |
|
84 | +function getpaid_invoice_type($invoice) { |
|
85 | + if (!empty($invoice)) { |
|
86 | + wpinv_get_template('invoice/invoice-type.php', compact('invoice')); |
|
87 | 87 | } |
88 | 88 | } |
89 | -add_action( 'getpaid_invoice_details_top_right', 'getpaid_invoice_type' ); |
|
89 | +add_action('getpaid_invoice_details_top_right', 'getpaid_invoice_type'); |
|
90 | 90 | |
91 | 91 | /** |
92 | 92 | * Displays the invoice details. |
93 | 93 | */ |
94 | -function getpaid_invoice_details_main( $invoice ) { |
|
95 | - if ( ! empty( $invoice ) ) { |
|
96 | - wpinv_get_template( 'invoice/details.php', compact( 'invoice' ) ); |
|
94 | +function getpaid_invoice_details_main($invoice) { |
|
95 | + if (!empty($invoice)) { |
|
96 | + wpinv_get_template('invoice/details.php', compact('invoice')); |
|
97 | 97 | } |
98 | 98 | } |
99 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_main', 50 ); |
|
99 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_main', 50); |
|
100 | 100 | |
101 | 101 | /** |
102 | 102 | * Returns a path to the templates directory. |
@@ -125,8 +125,8 @@ discard block |
||
125 | 125 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
126 | 126 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
127 | 127 | */ |
128 | -function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
129 | - getpaid_template()->display_template( $template_name, $args, $template_path, $default_path ); |
|
128 | +function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
129 | + getpaid_template()->display_template($template_name, $args, $template_path, $default_path); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
140 | 140 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
141 | 141 | */ |
142 | -function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
143 | - return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
142 | +function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
143 | + return getpaid_template()->get_template($template_name, $args, $template_path, $default_path); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @return string |
150 | 150 | */ |
151 | 151 | function wpinv_template_path() { |
152 | - return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() ); |
|
152 | + return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name()); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | function wpinv_get_theme_template_dir_name() { |
161 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
161 | + return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing')); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -170,56 +170,56 @@ discard block |
||
170 | 170 | * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'. |
171 | 171 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
172 | 172 | */ |
173 | -function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
174 | - return getpaid_template()->locate_template( $template_name, $template_path, $default_path ); |
|
173 | +function wpinv_locate_template($template_name, $template_path = '', $default_path = '') { |
|
174 | + return getpaid_template()->locate_template($template_name, $template_path, $default_path); |
|
175 | 175 | } |
176 | 176 | |
177 | -function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
|
178 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
177 | +function wpinv_get_template_part($slug, $name = null, $load = true) { |
|
178 | + do_action('get_template_part_' . $slug, $slug, $name); |
|
179 | 179 | |
180 | 180 | // Setup possible parts |
181 | 181 | $templates = array(); |
182 | - if ( isset( $name ) ) |
|
182 | + if (isset($name)) |
|
183 | 183 | $templates[] = $slug . '-' . $name . '.php'; |
184 | 184 | $templates[] = $slug . '.php'; |
185 | 185 | |
186 | 186 | // Allow template parts to be filtered |
187 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
187 | + $templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name); |
|
188 | 188 | |
189 | 189 | // Return the part that is found |
190 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
190 | + return wpinv_locate_tmpl($templates, $load, false); |
|
191 | 191 | } |
192 | 192 | |
193 | -function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
|
193 | +function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) { |
|
194 | 194 | // No file found yet |
195 | 195 | $located = false; |
196 | 196 | |
197 | 197 | // Try to find a template file |
198 | - foreach ( (array)$template_names as $template_name ) { |
|
198 | + foreach ((array) $template_names as $template_name) { |
|
199 | 199 | |
200 | 200 | // Continue if template is empty |
201 | - if ( empty( $template_name ) ) |
|
201 | + if (empty($template_name)) |
|
202 | 202 | continue; |
203 | 203 | |
204 | 204 | // Trim off any slashes from the template name |
205 | - $template_name = ltrim( $template_name, '/' ); |
|
205 | + $template_name = ltrim($template_name, '/'); |
|
206 | 206 | |
207 | 207 | // try locating this template file by looping through the template paths |
208 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
208 | + foreach (wpinv_get_theme_template_paths() as $template_path) { |
|
209 | 209 | |
210 | - if( file_exists( $template_path . $template_name ) ) { |
|
210 | + if (file_exists($template_path . $template_name)) { |
|
211 | 211 | $located = $template_path . $template_name; |
212 | 212 | break; |
213 | 213 | } |
214 | 214 | } |
215 | 215 | |
216 | - if( !empty( $located ) ) { |
|
216 | + if (!empty($located)) { |
|
217 | 217 | break; |
218 | 218 | } |
219 | 219 | } |
220 | 220 | |
221 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
222 | - load_template( $located, $require_once ); |
|
221 | + if ((true == $load) && !empty($located)) |
|
222 | + load_template($located, $require_once); |
|
223 | 223 | |
224 | 224 | return $located; |
225 | 225 | } |
@@ -228,127 +228,127 @@ discard block |
||
228 | 228 | $template_dir = wpinv_get_theme_template_dir_name(); |
229 | 229 | |
230 | 230 | $file_paths = array( |
231 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
232 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
231 | + 1 => trailingslashit(get_stylesheet_directory()) . $template_dir, |
|
232 | + 10 => trailingslashit(get_template_directory()) . $template_dir, |
|
233 | 233 | 100 => wpinv_get_templates_dir() |
234 | 234 | ); |
235 | 235 | |
236 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
236 | + $file_paths = apply_filters('wpinv_template_paths', $file_paths); |
|
237 | 237 | |
238 | 238 | // sort the file paths based on priority |
239 | - ksort( $file_paths, SORT_NUMERIC ); |
|
239 | + ksort($file_paths, SORT_NUMERIC); |
|
240 | 240 | |
241 | - return array_map( 'trailingslashit', $file_paths ); |
|
241 | + return array_map('trailingslashit', $file_paths); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | function wpinv_checkout_meta_tags() { |
245 | 245 | |
246 | 246 | $pages = array(); |
247 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
248 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
249 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
250 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
247 | + $pages[] = wpinv_get_option('success_page'); |
|
248 | + $pages[] = wpinv_get_option('failure_page'); |
|
249 | + $pages[] = wpinv_get_option('invoice_history_page'); |
|
250 | + $pages[] = wpinv_get_option('invoice_subscription_page'); |
|
251 | 251 | |
252 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
252 | + if (!wpinv_is_checkout() && !is_page($pages)) { |
|
253 | 253 | return; |
254 | 254 | } |
255 | 255 | |
256 | 256 | echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
257 | 257 | } |
258 | -add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
|
258 | +add_action('wp_head', 'wpinv_checkout_meta_tags'); |
|
259 | 259 | |
260 | -function wpinv_add_body_classes( $class ) { |
|
261 | - $classes = (array)$class; |
|
260 | +function wpinv_add_body_classes($class) { |
|
261 | + $classes = (array) $class; |
|
262 | 262 | |
263 | - if( wpinv_is_checkout() ) { |
|
263 | + if (wpinv_is_checkout()) { |
|
264 | 264 | $classes[] = 'wpinv-checkout'; |
265 | 265 | $classes[] = 'wpinv-page'; |
266 | 266 | } |
267 | 267 | |
268 | - if( wpinv_is_success_page() ) { |
|
268 | + if (wpinv_is_success_page()) { |
|
269 | 269 | $classes[] = 'wpinv-success'; |
270 | 270 | $classes[] = 'wpinv-page'; |
271 | 271 | } |
272 | 272 | |
273 | - if( wpinv_is_failed_transaction_page() ) { |
|
273 | + if (wpinv_is_failed_transaction_page()) { |
|
274 | 274 | $classes[] = 'wpinv-failed-transaction'; |
275 | 275 | $classes[] = 'wpinv-page'; |
276 | 276 | } |
277 | 277 | |
278 | - if( wpinv_is_invoice_history_page() ) { |
|
278 | + if (wpinv_is_invoice_history_page()) { |
|
279 | 279 | $classes[] = 'wpinv-history'; |
280 | 280 | $classes[] = 'wpinv-page'; |
281 | 281 | } |
282 | 282 | |
283 | - if( wpinv_is_subscriptions_history_page() ) { |
|
283 | + if (wpinv_is_subscriptions_history_page()) { |
|
284 | 284 | $classes[] = 'wpinv-subscription'; |
285 | 285 | $classes[] = 'wpinv-page'; |
286 | 286 | } |
287 | 287 | |
288 | - if( wpinv_is_test_mode() ) { |
|
288 | + if (wpinv_is_test_mode()) { |
|
289 | 289 | $classes[] = 'wpinv-test-mode'; |
290 | 290 | $classes[] = 'wpinv-page'; |
291 | 291 | } |
292 | 292 | |
293 | - return array_unique( $classes ); |
|
293 | + return array_unique($classes); |
|
294 | 294 | } |
295 | -add_filter( 'body_class', 'wpinv_add_body_classes' ); |
|
295 | +add_filter('body_class', 'wpinv_add_body_classes'); |
|
296 | 296 | |
297 | -function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) { |
|
298 | - $current = date( 'Y' ); |
|
299 | - $start_year = $current - absint( $years_before ); |
|
300 | - $end_year = $current + absint( $years_after ); |
|
301 | - $selected = empty( $selected ) ? date( 'Y' ) : $selected; |
|
297 | +function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) { |
|
298 | + $current = date('Y'); |
|
299 | + $start_year = $current - absint($years_before); |
|
300 | + $end_year = $current + absint($years_after); |
|
301 | + $selected = empty($selected) ? date('Y') : $selected; |
|
302 | 302 | $options = array(); |
303 | 303 | |
304 | - while ( $start_year <= $end_year ) { |
|
305 | - $options[ absint( $start_year ) ] = $start_year; |
|
304 | + while ($start_year <= $end_year) { |
|
305 | + $options[absint($start_year)] = $start_year; |
|
306 | 306 | $start_year++; |
307 | 307 | } |
308 | 308 | |
309 | - $output = wpinv_html_select( array( |
|
309 | + $output = wpinv_html_select(array( |
|
310 | 310 | 'name' => $name, |
311 | 311 | 'selected' => $selected, |
312 | 312 | 'options' => $options, |
313 | 313 | 'show_option_all' => false, |
314 | 314 | 'show_option_none' => false |
315 | - ) ); |
|
315 | + )); |
|
316 | 316 | |
317 | 317 | return $output; |
318 | 318 | } |
319 | 319 | |
320 | -function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) { |
|
320 | +function wpinv_html_month_dropdown($name = 'month', $selected = 0) { |
|
321 | 321 | |
322 | 322 | $options = array( |
323 | - '1' => __( 'January', 'invoicing' ), |
|
324 | - '2' => __( 'February', 'invoicing' ), |
|
325 | - '3' => __( 'March', 'invoicing' ), |
|
326 | - '4' => __( 'April', 'invoicing' ), |
|
327 | - '5' => __( 'May', 'invoicing' ), |
|
328 | - '6' => __( 'June', 'invoicing' ), |
|
329 | - '7' => __( 'July', 'invoicing' ), |
|
330 | - '8' => __( 'August', 'invoicing' ), |
|
331 | - '9' => __( 'September', 'invoicing' ), |
|
332 | - '10' => __( 'October', 'invoicing' ), |
|
333 | - '11' => __( 'November', 'invoicing' ), |
|
334 | - '12' => __( 'December', 'invoicing' ), |
|
323 | + '1' => __('January', 'invoicing'), |
|
324 | + '2' => __('February', 'invoicing'), |
|
325 | + '3' => __('March', 'invoicing'), |
|
326 | + '4' => __('April', 'invoicing'), |
|
327 | + '5' => __('May', 'invoicing'), |
|
328 | + '6' => __('June', 'invoicing'), |
|
329 | + '7' => __('July', 'invoicing'), |
|
330 | + '8' => __('August', 'invoicing'), |
|
331 | + '9' => __('September', 'invoicing'), |
|
332 | + '10' => __('October', 'invoicing'), |
|
333 | + '11' => __('November', 'invoicing'), |
|
334 | + '12' => __('December', 'invoicing'), |
|
335 | 335 | ); |
336 | 336 | |
337 | 337 | // If no month is selected, default to the current month |
338 | - $selected = empty( $selected ) ? date( 'n' ) : $selected; |
|
338 | + $selected = empty($selected) ? date('n') : $selected; |
|
339 | 339 | |
340 | - $output = wpinv_html_select( array( |
|
340 | + $output = wpinv_html_select(array( |
|
341 | 341 | 'name' => $name, |
342 | 342 | 'selected' => $selected, |
343 | 343 | 'options' => $options, |
344 | 344 | 'show_option_all' => false, |
345 | 345 | 'show_option_none' => false |
346 | - ) ); |
|
346 | + )); |
|
347 | 347 | |
348 | 348 | return $output; |
349 | 349 | } |
350 | 350 | |
351 | -function wpinv_html_select( $args = array() ) { |
|
351 | +function wpinv_html_select($args = array()) { |
|
352 | 352 | $defaults = array( |
353 | 353 | 'options' => array(), |
354 | 354 | 'name' => null, |
@@ -357,8 +357,8 @@ discard block |
||
357 | 357 | 'selected' => 0, |
358 | 358 | 'placeholder' => null, |
359 | 359 | 'multiple' => false, |
360 | - 'show_option_all' => _x( 'All', 'all dropdown items', 'invoicing' ), |
|
361 | - 'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ), |
|
360 | + 'show_option_all' => _x('All', 'all dropdown items', 'invoicing'), |
|
361 | + 'show_option_none' => _x('None', 'no dropdown items', 'invoicing'), |
|
362 | 362 | 'data' => array(), |
363 | 363 | 'onchange' => null, |
364 | 364 | 'required' => false, |
@@ -366,74 +366,74 @@ discard block |
||
366 | 366 | 'readonly' => false, |
367 | 367 | ); |
368 | 368 | |
369 | - $args = wp_parse_args( $args, $defaults ); |
|
369 | + $args = wp_parse_args($args, $defaults); |
|
370 | 370 | |
371 | 371 | $data_elements = ''; |
372 | - foreach ( $args['data'] as $key => $value ) { |
|
373 | - $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
372 | + foreach ($args['data'] as $key => $value) { |
|
373 | + $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"'; |
|
374 | 374 | } |
375 | 375 | |
376 | - if( $args['multiple'] ) { |
|
376 | + if ($args['multiple']) { |
|
377 | 377 | $multiple = ' MULTIPLE'; |
378 | 378 | } else { |
379 | 379 | $multiple = ''; |
380 | 380 | } |
381 | 381 | |
382 | - if( $args['placeholder'] ) { |
|
382 | + if ($args['placeholder']) { |
|
383 | 383 | $placeholder = $args['placeholder']; |
384 | 384 | } else { |
385 | 385 | $placeholder = ''; |
386 | 386 | } |
387 | 387 | |
388 | 388 | $options = ''; |
389 | - if( !empty( $args['onchange'] ) ) { |
|
390 | - $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
389 | + if (!empty($args['onchange'])) { |
|
390 | + $options .= ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
391 | 391 | } |
392 | 392 | |
393 | - if( !empty( $args['required'] ) ) { |
|
393 | + if (!empty($args['required'])) { |
|
394 | 394 | $options .= ' required="required"'; |
395 | 395 | } |
396 | 396 | |
397 | - if( !empty( $args['disabled'] ) ) { |
|
397 | + if (!empty($args['disabled'])) { |
|
398 | 398 | $options .= ' disabled'; |
399 | 399 | } |
400 | 400 | |
401 | - if( !empty( $args['readonly'] ) ) { |
|
401 | + if (!empty($args['readonly'])) { |
|
402 | 402 | $options .= ' readonly'; |
403 | 403 | } |
404 | 404 | |
405 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
406 | - $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>'; |
|
405 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
406 | + $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>'; |
|
407 | 407 | |
408 | - if ( $args['show_option_all'] ) { |
|
409 | - if( $args['multiple'] ) { |
|
410 | - $selected = selected( true, in_array( 0, $args['selected'] ), false ); |
|
408 | + if ($args['show_option_all']) { |
|
409 | + if ($args['multiple']) { |
|
410 | + $selected = selected(true, in_array(0, $args['selected']), false); |
|
411 | 411 | } else { |
412 | - $selected = selected( $args['selected'], 0, false ); |
|
412 | + $selected = selected($args['selected'], 0, false); |
|
413 | 413 | } |
414 | - $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
414 | + $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>'; |
|
415 | 415 | } |
416 | 416 | |
417 | - if ( !empty( $args['options'] ) ) { |
|
417 | + if (!empty($args['options'])) { |
|
418 | 418 | |
419 | - if ( $args['show_option_none'] ) { |
|
420 | - if( $args['multiple'] ) { |
|
421 | - $selected = selected( true, in_array( "", $args['selected'] ), false ); |
|
419 | + if ($args['show_option_none']) { |
|
420 | + if ($args['multiple']) { |
|
421 | + $selected = selected(true, in_array("", $args['selected']), false); |
|
422 | 422 | } else { |
423 | - $selected = selected( $args['selected'] === "", true, false ); |
|
423 | + $selected = selected($args['selected'] === "", true, false); |
|
424 | 424 | } |
425 | - $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
425 | + $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>'; |
|
426 | 426 | } |
427 | 427 | |
428 | - foreach( $args['options'] as $key => $option ) { |
|
428 | + foreach ($args['options'] as $key => $option) { |
|
429 | 429 | |
430 | - if( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
431 | - $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false ); |
|
430 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
431 | + $selected = selected(true, (bool) in_array($key, $args['selected']), false); |
|
432 | 432 | } else { |
433 | - $selected = selected( $args['selected'], $key, false ); |
|
433 | + $selected = selected($args['selected'], $key, false); |
|
434 | 434 | } |
435 | 435 | |
436 | - $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; |
|
436 | + $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>'; |
|
437 | 437 | } |
438 | 438 | } |
439 | 439 | |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | return $output; |
443 | 443 | } |
444 | 444 | |
445 | -function wpinv_item_dropdown( $args = array() ) { |
|
445 | +function wpinv_item_dropdown($args = array()) { |
|
446 | 446 | $defaults = array( |
447 | 447 | 'name' => 'wpi_item', |
448 | 448 | 'id' => 'wpi_item', |
@@ -450,14 +450,14 @@ discard block |
||
450 | 450 | 'multiple' => false, |
451 | 451 | 'selected' => 0, |
452 | 452 | 'number' => 100, |
453 | - 'placeholder' => __( 'Choose a item', 'invoicing' ), |
|
454 | - 'data' => array( 'search-type' => 'item' ), |
|
453 | + 'placeholder' => __('Choose a item', 'invoicing'), |
|
454 | + 'data' => array('search-type' => 'item'), |
|
455 | 455 | 'show_option_all' => false, |
456 | 456 | 'show_option_none' => false, |
457 | 457 | 'show_recurring' => false, |
458 | 458 | ); |
459 | 459 | |
460 | - $args = wp_parse_args( $args, $defaults ); |
|
460 | + $args = wp_parse_args($args, $defaults); |
|
461 | 461 | |
462 | 462 | $item_args = array( |
463 | 463 | 'post_type' => 'wpi_item', |
@@ -466,44 +466,44 @@ discard block |
||
466 | 466 | 'posts_per_page' => $args['number'] |
467 | 467 | ); |
468 | 468 | |
469 | - $item_args = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults ); |
|
469 | + $item_args = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults); |
|
470 | 470 | |
471 | - $items = get_posts( $item_args ); |
|
471 | + $items = get_posts($item_args); |
|
472 | 472 | $options = array(); |
473 | - if ( $items ) { |
|
474 | - foreach ( $items as $item ) { |
|
475 | - $title = esc_html( $item->post_title ); |
|
473 | + if ($items) { |
|
474 | + foreach ($items as $item) { |
|
475 | + $title = esc_html($item->post_title); |
|
476 | 476 | |
477 | - if ( !empty( $args['show_recurring'] ) ) { |
|
478 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
477 | + if (!empty($args['show_recurring'])) { |
|
478 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
479 | 479 | } |
480 | 480 | |
481 | - $options[ absint( $item->ID ) ] = $title; |
|
481 | + $options[absint($item->ID)] = $title; |
|
482 | 482 | } |
483 | 483 | } |
484 | 484 | |
485 | 485 | // This ensures that any selected items are included in the drop down |
486 | - if( is_array( $args['selected'] ) ) { |
|
487 | - foreach( $args['selected'] as $item ) { |
|
488 | - if( ! in_array( $item, $options ) ) { |
|
489 | - $title = get_the_title( $item ); |
|
490 | - if ( !empty( $args['show_recurring'] ) ) { |
|
491 | - $title .= wpinv_get_item_suffix( $item, false ); |
|
486 | + if (is_array($args['selected'])) { |
|
487 | + foreach ($args['selected'] as $item) { |
|
488 | + if (!in_array($item, $options)) { |
|
489 | + $title = get_the_title($item); |
|
490 | + if (!empty($args['show_recurring'])) { |
|
491 | + $title .= wpinv_get_item_suffix($item, false); |
|
492 | 492 | } |
493 | 493 | $options[$item] = $title; |
494 | 494 | } |
495 | 495 | } |
496 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
497 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
498 | - $title = get_the_title( $args['selected'] ); |
|
499 | - if ( !empty( $args['show_recurring'] ) ) { |
|
500 | - $title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
496 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
497 | + if (!in_array($args['selected'], $options)) { |
|
498 | + $title = get_the_title($args['selected']); |
|
499 | + if (!empty($args['show_recurring'])) { |
|
500 | + $title .= wpinv_get_item_suffix($args['selected'], false); |
|
501 | 501 | } |
502 | - $options[$args['selected']] = get_the_title( $args['selected'] ); |
|
502 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
503 | 503 | } |
504 | 504 | } |
505 | 505 | |
506 | - $output = wpinv_html_select( array( |
|
506 | + $output = wpinv_html_select(array( |
|
507 | 507 | 'name' => $args['name'], |
508 | 508 | 'selected' => $args['selected'], |
509 | 509 | 'id' => $args['id'], |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | 'show_option_all' => $args['show_option_all'], |
515 | 515 | 'show_option_none' => $args['show_option_none'], |
516 | 516 | 'data' => $args['data'], |
517 | - ) ); |
|
517 | + )); |
|
518 | 518 | |
519 | 519 | return $output; |
520 | 520 | } |
@@ -534,16 +534,16 @@ discard block |
||
534 | 534 | ); |
535 | 535 | |
536 | 536 | $options = array(); |
537 | - if ( $items ) { |
|
538 | - foreach ( $items as $item ) { |
|
539 | - $options[ $item->ID ] = esc_html( $item->post_title ) . wpinv_get_item_suffix( $item->ID, false ); |
|
537 | + if ($items) { |
|
538 | + foreach ($items as $item) { |
|
539 | + $options[$item->ID] = esc_html($item->post_title) . wpinv_get_item_suffix($item->ID, false); |
|
540 | 540 | } |
541 | 541 | } |
542 | 542 | |
543 | 543 | return $options; |
544 | 544 | } |
545 | 545 | |
546 | -function wpinv_html_checkbox( $args = array() ) { |
|
546 | +function wpinv_html_checkbox($args = array()) { |
|
547 | 547 | $defaults = array( |
548 | 548 | 'name' => null, |
549 | 549 | 'current' => null, |
@@ -554,17 +554,17 @@ discard block |
||
554 | 554 | ) |
555 | 555 | ); |
556 | 556 | |
557 | - $args = wp_parse_args( $args, $defaults ); |
|
557 | + $args = wp_parse_args($args, $defaults); |
|
558 | 558 | |
559 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
559 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
560 | 560 | $options = ''; |
561 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
561 | + if (!empty($args['options']['disabled'])) { |
|
562 | 562 | $options .= ' disabled="disabled"'; |
563 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
563 | + } elseif (!empty($args['options']['readonly'])) { |
|
564 | 564 | $options .= ' readonly'; |
565 | 565 | } |
566 | 566 | |
567 | - $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />'; |
|
567 | + $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />'; |
|
568 | 568 | |
569 | 569 | return $output; |
570 | 570 | } |
@@ -572,9 +572,9 @@ discard block |
||
572 | 572 | /** |
573 | 573 | * Displays a hidden field. |
574 | 574 | */ |
575 | -function getpaid_hidden_field( $name, $value ) { |
|
576 | - $name = sanitize_text_field( $name ); |
|
577 | - $value = esc_attr( $value ); |
|
575 | +function getpaid_hidden_field($name, $value) { |
|
576 | + $name = sanitize_text_field($name); |
|
577 | + $value = esc_attr($value); |
|
578 | 578 | |
579 | 579 | echo "<input type='hidden' name='$name' value='$value' />"; |
580 | 580 | } |
@@ -582,31 +582,31 @@ discard block |
||
582 | 582 | /** |
583 | 583 | * Displays a submit field. |
584 | 584 | */ |
585 | -function getpaid_submit_field( $value, $name = 'submit', $class = 'btn-primary' ) { |
|
586 | - $name = sanitize_text_field( $name ); |
|
587 | - $value = esc_attr( $value ); |
|
588 | - $class = esc_attr( $class ); |
|
585 | +function getpaid_submit_field($value, $name = 'submit', $class = 'btn-primary') { |
|
586 | + $name = sanitize_text_field($name); |
|
587 | + $value = esc_attr($value); |
|
588 | + $class = esc_attr($class); |
|
589 | 589 | |
590 | 590 | echo "<input type='submit' name='$name' value='$value' class='btn $class' />"; |
591 | 591 | } |
592 | 592 | |
593 | -function wpinv_html_text( $args = array() ) { |
|
593 | +function wpinv_html_text($args = array()) { |
|
594 | 594 | // Backwards compatibility |
595 | - if ( func_num_args() > 1 ) { |
|
595 | + if (func_num_args() > 1) { |
|
596 | 596 | $args = func_get_args(); |
597 | 597 | |
598 | 598 | $name = $args[0]; |
599 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
600 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
601 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
599 | + $value = isset($args[1]) ? $args[1] : ''; |
|
600 | + $label = isset($args[2]) ? $args[2] : ''; |
|
601 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
602 | 602 | } |
603 | 603 | |
604 | 604 | $defaults = array( |
605 | 605 | 'id' => '', |
606 | - 'name' => isset( $name ) ? $name : 'text', |
|
607 | - 'value' => isset( $value ) ? $value : null, |
|
608 | - 'label' => isset( $label ) ? $label : null, |
|
609 | - 'desc' => isset( $desc ) ? $desc : null, |
|
606 | + 'name' => isset($name) ? $name : 'text', |
|
607 | + 'value' => isset($value) ? $value : null, |
|
608 | + 'label' => isset($label) ? $label : null, |
|
609 | + 'desc' => isset($desc) ? $desc : null, |
|
610 | 610 | 'placeholder' => '', |
611 | 611 | 'class' => 'regular-text', |
612 | 612 | 'disabled' => false, |
@@ -616,41 +616,41 @@ discard block |
||
616 | 616 | 'data' => false |
617 | 617 | ); |
618 | 618 | |
619 | - $args = wp_parse_args( $args, $defaults ); |
|
619 | + $args = wp_parse_args($args, $defaults); |
|
620 | 620 | |
621 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
621 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
622 | 622 | $options = ''; |
623 | - if( $args['required'] ) { |
|
623 | + if ($args['required']) { |
|
624 | 624 | $options .= ' required="required"'; |
625 | 625 | } |
626 | - if( $args['readonly'] ) { |
|
626 | + if ($args['readonly']) { |
|
627 | 627 | $options .= ' readonly'; |
628 | 628 | } |
629 | - if( $args['readonly'] ) { |
|
629 | + if ($args['readonly']) { |
|
630 | 630 | $options .= ' readonly'; |
631 | 631 | } |
632 | 632 | |
633 | 633 | $data = ''; |
634 | - if ( !empty( $args['data'] ) ) { |
|
635 | - foreach ( $args['data'] as $key => $value ) { |
|
636 | - $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
634 | + if (!empty($args['data'])) { |
|
635 | + foreach ($args['data'] as $key => $value) { |
|
636 | + $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" '; |
|
637 | 637 | } |
638 | 638 | } |
639 | 639 | |
640 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
641 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
642 | - if ( ! empty( $args['desc'] ) ) { |
|
643 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
640 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
641 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>'; |
|
642 | + if (!empty($args['desc'])) { |
|
643 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
644 | 644 | } |
645 | 645 | |
646 | - $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>'; |
|
646 | + $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>'; |
|
647 | 647 | |
648 | 648 | $output .= '</span>'; |
649 | 649 | |
650 | 650 | return $output; |
651 | 651 | } |
652 | 652 | |
653 | -function wpinv_html_textarea( $args = array() ) { |
|
653 | +function wpinv_html_textarea($args = array()) { |
|
654 | 654 | $defaults = array( |
655 | 655 | 'name' => 'textarea', |
656 | 656 | 'value' => null, |
@@ -661,31 +661,31 @@ discard block |
||
661 | 661 | 'placeholder' => '', |
662 | 662 | ); |
663 | 663 | |
664 | - $args = wp_parse_args( $args, $defaults ); |
|
664 | + $args = wp_parse_args($args, $defaults); |
|
665 | 665 | |
666 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
666 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
667 | 667 | $disabled = ''; |
668 | - if( $args['disabled'] ) { |
|
668 | + if ($args['disabled']) { |
|
669 | 669 | $disabled = ' disabled="disabled"'; |
670 | 670 | } |
671 | 671 | |
672 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
673 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
674 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
672 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
673 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>'; |
|
674 | + $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>'; |
|
675 | 675 | |
676 | - if ( ! empty( $args['desc'] ) ) { |
|
677 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
676 | + if (!empty($args['desc'])) { |
|
677 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
678 | 678 | } |
679 | 679 | $output .= '</span>'; |
680 | 680 | |
681 | 681 | return $output; |
682 | 682 | } |
683 | 683 | |
684 | -function wpinv_html_ajax_user_search( $args = array() ) { |
|
684 | +function wpinv_html_ajax_user_search($args = array()) { |
|
685 | 685 | $defaults = array( |
686 | 686 | 'name' => 'user_id', |
687 | 687 | 'value' => null, |
688 | - 'placeholder' => __( 'Enter username', 'invoicing' ), |
|
688 | + 'placeholder' => __('Enter username', 'invoicing'), |
|
689 | 689 | 'label' => null, |
690 | 690 | 'desc' => null, |
691 | 691 | 'class' => '', |
@@ -694,13 +694,13 @@ discard block |
||
694 | 694 | 'data' => false |
695 | 695 | ); |
696 | 696 | |
697 | - $args = wp_parse_args( $args, $defaults ); |
|
697 | + $args = wp_parse_args($args, $defaults); |
|
698 | 698 | |
699 | 699 | $args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
700 | 700 | |
701 | 701 | $output = '<span class="wpinv_user_search_wrap">'; |
702 | - $output .= wpinv_html_text( $args ); |
|
703 | - $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>'; |
|
702 | + $output .= wpinv_html_text($args); |
|
703 | + $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>'; |
|
704 | 704 | $output .= '</span>'; |
705 | 705 | |
706 | 706 | return $output; |
@@ -711,20 +711,20 @@ discard block |
||
711 | 711 | * |
712 | 712 | * @param string $template the template that is currently being used. |
713 | 713 | */ |
714 | -function wpinv_template( $template ) { |
|
714 | +function wpinv_template($template) { |
|
715 | 715 | global $post; |
716 | 716 | |
717 | - if ( ! is_admin() && ( is_single() || is_404() ) && ! empty( $post->ID ) && getpaid_is_invoice_post_type( get_post_type( $post->ID ) ) ) { |
|
717 | + if (!is_admin() && (is_single() || is_404()) && !empty($post->ID) && getpaid_is_invoice_post_type(get_post_type($post->ID))) { |
|
718 | 718 | |
719 | 719 | // If the user can view this invoice, display it. |
720 | - if ( wpinv_user_can_view_invoice( $post->ID ) ) { |
|
720 | + if (wpinv_user_can_view_invoice($post->ID)) { |
|
721 | 721 | |
722 | - return wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
722 | + return wpinv_get_template_part('wpinv-invoice-print', false, false); |
|
723 | 723 | |
724 | 724 | // Else display an error message. |
725 | 725 | } else { |
726 | 726 | |
727 | - return wpinv_get_template_part( 'wpinv-invalid-access', false, false ); |
|
727 | + return wpinv_get_template_part('wpinv-invalid-access', false, false); |
|
728 | 728 | |
729 | 729 | } |
730 | 730 | |
@@ -732,24 +732,24 @@ discard block |
||
732 | 732 | |
733 | 733 | return $template; |
734 | 734 | } |
735 | -add_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
735 | +add_filter('template_include', 'wpinv_template', 10, 1); |
|
736 | 736 | |
737 | 737 | function wpinv_get_business_address() { |
738 | 738 | $business_address = wpinv_store_address(); |
739 | - $business_address = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : ''; |
|
739 | + $business_address = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : ''; |
|
740 | 740 | |
741 | 741 | $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
742 | 742 | |
743 | - return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
743 | + return apply_filters('wpinv_get_business_address', $business_address); |
|
744 | 744 | } |
745 | 745 | |
746 | 746 | /** |
747 | 747 | * Displays the company address. |
748 | 748 | */ |
749 | 749 | function wpinv_display_from_address() { |
750 | - wpinv_get_template( 'invoice/company-address.php' ); |
|
750 | + wpinv_get_template('invoice/company-address.php'); |
|
751 | 751 | } |
752 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_from_address', 10 ); |
|
752 | +add_action('getpaid_invoice_details_left', 'wpinv_display_from_address', 10); |
|
753 | 753 | |
754 | 754 | /** |
755 | 755 | * Generates a watermark text for an invoice. |
@@ -757,9 +757,9 @@ discard block |
||
757 | 757 | * @param WPInv_Invoice $invoice |
758 | 758 | * @return string |
759 | 759 | */ |
760 | -function wpinv_watermark( $invoice ) { |
|
761 | - $watermark = wpinv_get_watermark( $invoice ); |
|
762 | - return apply_filters( 'wpinv_get_watermark', $watermark, $invoice ); |
|
760 | +function wpinv_watermark($invoice) { |
|
761 | + $watermark = wpinv_get_watermark($invoice); |
|
762 | + return apply_filters('wpinv_get_watermark', $watermark, $invoice); |
|
763 | 763 | } |
764 | 764 | |
765 | 765 | /** |
@@ -768,37 +768,37 @@ discard block |
||
768 | 768 | * @param WPInv_Invoice $invoice |
769 | 769 | * @return string |
770 | 770 | */ |
771 | -function wpinv_get_watermark( $invoice ) { |
|
771 | +function wpinv_get_watermark($invoice) { |
|
772 | 772 | return $invoice->get_status_nicename(); |
773 | 773 | } |
774 | 774 | |
775 | 775 | /** |
776 | 776 | * @deprecated |
777 | 777 | */ |
778 | -function wpinv_display_invoice_details( $invoice ) { |
|
779 | - return getpaid_invoice_meta( $invoice ); |
|
778 | +function wpinv_display_invoice_details($invoice) { |
|
779 | + return getpaid_invoice_meta($invoice); |
|
780 | 780 | } |
781 | 781 | |
782 | 782 | /** |
783 | 783 | * Displays invoice meta. |
784 | 784 | */ |
785 | -function getpaid_invoice_meta( $invoice ) { |
|
785 | +function getpaid_invoice_meta($invoice) { |
|
786 | 786 | |
787 | - $invoice = new WPInv_Invoice( $invoice ); |
|
787 | + $invoice = new WPInv_Invoice($invoice); |
|
788 | 788 | |
789 | 789 | // Ensure that we have an invoice. |
790 | - if ( 0 == $invoice->get_id() ) { |
|
790 | + if (0 == $invoice->get_id()) { |
|
791 | 791 | return; |
792 | 792 | } |
793 | 793 | |
794 | 794 | // Get the invoice meta. |
795 | - $meta = getpaid_get_invoice_meta( $invoice ); |
|
795 | + $meta = getpaid_get_invoice_meta($invoice); |
|
796 | 796 | |
797 | 797 | // Display the meta. |
798 | - wpinv_get_template( 'invoice/invoice-meta.php', compact( 'invoice', 'meta' ) ); |
|
798 | + wpinv_get_template('invoice/invoice-meta.php', compact('invoice', 'meta')); |
|
799 | 799 | |
800 | 800 | } |
801 | -add_action( 'getpaid_invoice_details_right', 'getpaid_invoice_meta', 10 ); |
|
801 | +add_action('getpaid_invoice_details_right', 'getpaid_invoice_meta', 10); |
|
802 | 802 | |
803 | 803 | /** |
804 | 804 | * Retrieves the address markup to use on Invoices. |
@@ -810,29 +810,29 @@ discard block |
||
810 | 810 | * @param string $separator How to separate address lines. |
811 | 811 | * @return string |
812 | 812 | */ |
813 | -function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) { |
|
813 | +function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') { |
|
814 | 814 | |
815 | 815 | // Retrieve the address markup... |
816 | - $country= empty( $billing_details['country'] ) ? '' : $billing_details['country']; |
|
817 | - $format = wpinv_get_full_address_format( $country ); |
|
816 | + $country = empty($billing_details['country']) ? '' : $billing_details['country']; |
|
817 | + $format = wpinv_get_full_address_format($country); |
|
818 | 818 | |
819 | 819 | // ... and the replacements. |
820 | - $replacements = wpinv_get_invoice_address_replacements( $billing_details ); |
|
820 | + $replacements = wpinv_get_invoice_address_replacements($billing_details); |
|
821 | 821 | |
822 | - $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
|
822 | + $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format); |
|
823 | 823 | |
824 | 824 | // Remove unavailable tags. |
825 | - $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address ); |
|
825 | + $formatted_address = preg_replace("/\{\{\w+\}\}/", '', $formatted_address); |
|
826 | 826 | |
827 | 827 | // Clean up white space. |
828 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
829 | - $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
|
828 | + $formatted_address = preg_replace('/ +/', ' ', trim($formatted_address)); |
|
829 | + $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address); |
|
830 | 830 | |
831 | 831 | // Break newlines apart and remove empty lines/trim commas and white space. |
832 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
832 | + $formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address))); |
|
833 | 833 | |
834 | 834 | // Add html breaks. |
835 | - $formatted_address = implode( $separator, $formatted_address ); |
|
835 | + $formatted_address = implode($separator, $formatted_address); |
|
836 | 836 | |
837 | 837 | // We're done! |
838 | 838 | return $formatted_address; |
@@ -844,118 +844,118 @@ discard block |
||
844 | 844 | * |
845 | 845 | * @param WPInv_Invoice $invoice |
846 | 846 | */ |
847 | -function wpinv_display_to_address( $invoice = 0 ) { |
|
848 | - if ( ! empty( $invoice ) ) { |
|
849 | - wpinv_get_template( 'invoice/billing-address.php', compact( 'invoice' ) ); |
|
847 | +function wpinv_display_to_address($invoice = 0) { |
|
848 | + if (!empty($invoice)) { |
|
849 | + wpinv_get_template('invoice/billing-address.php', compact('invoice')); |
|
850 | 850 | } |
851 | 851 | } |
852 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_to_address', 40 ); |
|
852 | +add_action('getpaid_invoice_details_left', 'wpinv_display_to_address', 40); |
|
853 | 853 | |
854 | 854 | |
855 | 855 | /** |
856 | 856 | * Displays invoice line items. |
857 | 857 | */ |
858 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
858 | +function wpinv_display_line_items($invoice_id = 0) { |
|
859 | 859 | |
860 | 860 | // Prepare the invoice. |
861 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
861 | + $invoice = new WPInv_Invoice($invoice_id); |
|
862 | 862 | |
863 | 863 | // Abort if there is no invoice. |
864 | - if ( 0 == $invoice->get_id() ) { |
|
864 | + if (0 == $invoice->get_id()) { |
|
865 | 865 | return; |
866 | 866 | } |
867 | 867 | |
868 | 868 | // Line item columns. |
869 | - $columns = getpaid_invoice_item_columns( $invoice ); |
|
870 | - $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice ); |
|
869 | + $columns = getpaid_invoice_item_columns($invoice); |
|
870 | + $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice); |
|
871 | 871 | |
872 | - wpinv_get_template( 'invoice/line-items.php', compact( 'invoice', 'columns' ) ); |
|
872 | + wpinv_get_template('invoice/line-items.php', compact('invoice', 'columns')); |
|
873 | 873 | } |
874 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_line_items', 10 ); |
|
874 | +add_action('getpaid_invoice_line_items', 'wpinv_display_line_items', 10); |
|
875 | 875 | |
876 | 876 | /** |
877 | 877 | * Displays invoice subscriptions. |
878 | 878 | * |
879 | 879 | * @param WPInv_Invoice $invoice |
880 | 880 | */ |
881 | -function getpaid_display_invoice_subscriptions( $invoice ) { |
|
881 | +function getpaid_display_invoice_subscriptions($invoice) { |
|
882 | 882 | |
883 | 883 | // Subscriptions. |
884 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
884 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
885 | 885 | |
886 | - if ( empty( $subscriptions ) || ! $invoice->is_recurring() ) { |
|
886 | + if (empty($subscriptions) || !$invoice->is_recurring()) { |
|
887 | 887 | return; |
888 | 888 | } |
889 | 889 | |
890 | - $main_subscription = getpaid_get_invoice_subscription( $invoice ); |
|
890 | + $main_subscription = getpaid_get_invoice_subscription($invoice); |
|
891 | 891 | |
892 | 892 | // Display related subscriptions. |
893 | - if ( is_array( $subscriptions ) ) { |
|
894 | - printf( '<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__( 'Related Subscriptions', 'invoicing' ) ); |
|
895 | - getpaid_admin_subscription_related_subscriptions_metabox( $main_subscription, false ); |
|
893 | + if (is_array($subscriptions)) { |
|
894 | + printf('<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__('Related Subscriptions', 'invoicing')); |
|
895 | + getpaid_admin_subscription_related_subscriptions_metabox($main_subscription, false); |
|
896 | 896 | } |
897 | 897 | |
898 | - if ( $main_subscription->get_total_payments() > 1 ) { |
|
899 | - printf( '<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__( 'Related Invoices', 'invoicing' ) ); |
|
900 | - getpaid_admin_subscription_invoice_details_metabox( $main_subscription, false ); |
|
898 | + if ($main_subscription->get_total_payments() > 1) { |
|
899 | + printf('<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__('Related Invoices', 'invoicing')); |
|
900 | + getpaid_admin_subscription_invoice_details_metabox($main_subscription, false); |
|
901 | 901 | } |
902 | 902 | |
903 | 903 | } |
904 | -add_action( 'getpaid_invoice_line_items', 'getpaid_display_invoice_subscriptions', 15 ); |
|
904 | +add_action('getpaid_invoice_line_items', 'getpaid_display_invoice_subscriptions', 15); |
|
905 | 905 | |
906 | 906 | /** |
907 | 907 | * Displays invoice notices on invoices. |
908 | 908 | */ |
909 | 909 | function wpinv_display_invoice_notice() { |
910 | 910 | |
911 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
912 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
911 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
912 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
913 | 913 | |
914 | - if ( empty( $label ) && empty( $notice ) ) { |
|
914 | + if (empty($label) && empty($notice)) { |
|
915 | 915 | return; |
916 | 916 | } |
917 | 917 | |
918 | 918 | echo '<div class="mt-4 mb-4 wpinv-vat-notice">'; |
919 | 919 | |
920 | - if ( ! empty( $label ) ) { |
|
921 | - $label = sanitize_text_field( $label ); |
|
920 | + if (!empty($label)) { |
|
921 | + $label = sanitize_text_field($label); |
|
922 | 922 | echo "<h5>$label</h5>"; |
923 | 923 | } |
924 | 924 | |
925 | - if ( ! empty( $notice ) ) { |
|
926 | - echo '<small class="form-text text-muted">' . wpautop( wptexturize( $notice ) ) . '</small>'; |
|
925 | + if (!empty($notice)) { |
|
926 | + echo '<small class="form-text text-muted">' . wpautop(wptexturize($notice)) . '</small>'; |
|
927 | 927 | } |
928 | 928 | |
929 | 929 | echo '</div>'; |
930 | 930 | } |
931 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100 ); |
|
931 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100); |
|
932 | 932 | |
933 | 933 | /** |
934 | 934 | * @param WPInv_Invoice $invoice |
935 | 935 | */ |
936 | -function wpinv_display_invoice_notes( $invoice ) { |
|
936 | +function wpinv_display_invoice_notes($invoice) { |
|
937 | 937 | |
938 | 938 | // Retrieve the notes. |
939 | - $notes = wpinv_get_invoice_notes( $invoice->get_id(), 'customer' ); |
|
939 | + $notes = wpinv_get_invoice_notes($invoice->get_id(), 'customer'); |
|
940 | 940 | |
941 | 941 | // Abort if we have non. |
942 | - if ( empty( $notes ) ) { |
|
942 | + if (empty($notes)) { |
|
943 | 943 | return; |
944 | 944 | } |
945 | 945 | |
946 | 946 | // Echo the note. |
947 | 947 | echo '<div class="getpaid-invoice-notes-wrapper position-relative my-4">'; |
948 | - echo '<h2 class="getpaid-invoice-notes-title mb-1 p-0 h4">' . __( 'Notes', 'invoicing' ) .'</h2>'; |
|
948 | + echo '<h2 class="getpaid-invoice-notes-title mb-1 p-0 h4">' . __('Notes', 'invoicing') . '</h2>'; |
|
949 | 949 | echo '<ul class="getpaid-invoice-notes text-break overflow-auto list-unstyled p-0 m-0">'; |
950 | 950 | |
951 | - foreach( $notes as $note ) { |
|
952 | - wpinv_get_invoice_note_line_item( $note ); |
|
951 | + foreach ($notes as $note) { |
|
952 | + wpinv_get_invoice_note_line_item($note); |
|
953 | 953 | } |
954 | 954 | |
955 | 955 | echo '</ul>'; |
956 | 956 | echo '</div>'; |
957 | 957 | } |
958 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60 ); |
|
958 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60); |
|
959 | 959 | |
960 | 960 | /** |
961 | 961 | * Loads scripts on our invoice templates. |
@@ -963,31 +963,31 @@ discard block |
||
963 | 963 | function wpinv_display_style() { |
964 | 964 | |
965 | 965 | // Make sure that all scripts have been loaded. |
966 | - if ( ! did_action( 'wp_enqueue_scripts' ) ) { |
|
967 | - do_action( 'wp_enqueue_scripts' ); |
|
966 | + if (!did_action('wp_enqueue_scripts')) { |
|
967 | + do_action('wp_enqueue_scripts'); |
|
968 | 968 | } |
969 | 969 | |
970 | 970 | // Register the invoices style. |
971 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice.css' ) ); |
|
971 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice.css')); |
|
972 | 972 | |
973 | 973 | // Load required styles |
974 | - wp_print_styles( 'wpinv-single-style' ); |
|
975 | - wp_print_styles( 'ayecode-ui' ); |
|
974 | + wp_print_styles('wpinv-single-style'); |
|
975 | + wp_print_styles('ayecode-ui'); |
|
976 | 976 | |
977 | 977 | // Maybe load custom css. |
978 | - $custom_css = wpinv_get_option( 'template_custom_css' ); |
|
978 | + $custom_css = wpinv_get_option('template_custom_css'); |
|
979 | 979 | |
980 | - if ( isset( $custom_css ) && ! empty( $custom_css ) ) { |
|
981 | - $custom_css = wp_kses( $custom_css, array( '\'', '\"' ) ); |
|
982 | - $custom_css = str_replace( '>', '>', $custom_css ); |
|
980 | + if (isset($custom_css) && !empty($custom_css)) { |
|
981 | + $custom_css = wp_kses($custom_css, array('\'', '\"')); |
|
982 | + $custom_css = str_replace('>', '>', $custom_css); |
|
983 | 983 | echo '<style type="text/css">'; |
984 | 984 | echo $custom_css; |
985 | 985 | echo '</style>'; |
986 | 986 | } |
987 | 987 | |
988 | 988 | } |
989 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
990 | -add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' ); |
|
989 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
990 | +add_action('wpinv_invalid_invoice_head', 'wpinv_display_style'); |
|
991 | 991 | |
992 | 992 | |
993 | 993 | /** |
@@ -999,41 +999,41 @@ discard block |
||
999 | 999 | // Retrieve the current invoice. |
1000 | 1000 | $invoice_id = getpaid_get_current_invoice_id(); |
1001 | 1001 | |
1002 | - if ( empty( $invoice_id ) ) { |
|
1002 | + if (empty($invoice_id)) { |
|
1003 | 1003 | |
1004 | 1004 | return aui()->alert( |
1005 | 1005 | array( |
1006 | 1006 | 'type' => 'warning', |
1007 | - 'content' => __( 'Invalid invoice', 'invoicing' ), |
|
1007 | + 'content' => __('Invalid invoice', 'invoicing'), |
|
1008 | 1008 | ) |
1009 | 1009 | ); |
1010 | 1010 | |
1011 | 1011 | } |
1012 | 1012 | |
1013 | 1013 | // Can the user view this invoice? |
1014 | - if ( ! wpinv_user_can_view_invoice( $invoice_id ) ) { |
|
1014 | + if (!wpinv_user_can_view_invoice($invoice_id)) { |
|
1015 | 1015 | |
1016 | 1016 | return aui()->alert( |
1017 | 1017 | array( |
1018 | 1018 | 'type' => 'warning', |
1019 | - 'content' => __( 'You are not allowed to view this invoice', 'invoicing' ), |
|
1019 | + 'content' => __('You are not allowed to view this invoice', 'invoicing'), |
|
1020 | 1020 | ) |
1021 | 1021 | ); |
1022 | 1022 | |
1023 | 1023 | } |
1024 | 1024 | |
1025 | 1025 | // Ensure that it is not yet paid for. |
1026 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
1026 | + $invoice = new WPInv_Invoice($invoice_id); |
|
1027 | 1027 | |
1028 | 1028 | // Maybe mark it as viewed. |
1029 | - getpaid_maybe_mark_invoice_as_viewed( $invoice ); |
|
1029 | + getpaid_maybe_mark_invoice_as_viewed($invoice); |
|
1030 | 1030 | |
1031 | - if ( $invoice->is_paid() ) { |
|
1031 | + if ($invoice->is_paid()) { |
|
1032 | 1032 | |
1033 | 1033 | return aui()->alert( |
1034 | 1034 | array( |
1035 | 1035 | 'type' => 'success', |
1036 | - 'content' => __( 'This invoice has already been paid.', 'invoicing' ), |
|
1036 | + 'content' => __('This invoice has already been paid.', 'invoicing'), |
|
1037 | 1037 | ) |
1038 | 1038 | ); |
1039 | 1039 | |
@@ -1043,15 +1043,15 @@ discard block |
||
1043 | 1043 | $wpi_checkout_id = $invoice_id; |
1044 | 1044 | |
1045 | 1045 | // Retrieve appropriate payment form. |
1046 | - $payment_form = new GetPaid_Payment_Form( $invoice->get_meta( 'force_payment_form' ) ); |
|
1047 | - $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1046 | + $payment_form = new GetPaid_Payment_Form($invoice->get_meta('force_payment_form')); |
|
1047 | + $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1048 | 1048 | |
1049 | - if ( ! $payment_form->exists() ) { |
|
1049 | + if (!$payment_form->exists()) { |
|
1050 | 1050 | |
1051 | 1051 | return aui()->alert( |
1052 | 1052 | array( |
1053 | 1053 | 'type' => 'warning', |
1054 | - 'content' => __( 'Error loading the payment form', 'invoicing' ), |
|
1054 | + 'content' => __('Error loading the payment form', 'invoicing'), |
|
1055 | 1055 | ) |
1056 | 1056 | ); |
1057 | 1057 | |
@@ -1060,29 +1060,29 @@ discard block |
||
1060 | 1060 | // Set the invoice. |
1061 | 1061 | $payment_form->invoice = $invoice; |
1062 | 1062 | |
1063 | - if ( ! $payment_form->is_default() ) { |
|
1063 | + if (!$payment_form->is_default()) { |
|
1064 | 1064 | |
1065 | 1065 | $items = array(); |
1066 | 1066 | $item_ids = array(); |
1067 | 1067 | |
1068 | - foreach ( $invoice->get_items() as $item ) { |
|
1069 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
1068 | + foreach ($invoice->get_items() as $item) { |
|
1069 | + if (!in_array($item->get_id(), $item_ids)) { |
|
1070 | 1070 | $item_ids[] = $item->get_id(); |
1071 | 1071 | $items[] = $item; |
1072 | 1072 | } |
1073 | 1073 | } |
1074 | 1074 | |
1075 | - foreach ( $payment_form->get_items() as $item ) { |
|
1076 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
1075 | + foreach ($payment_form->get_items() as $item) { |
|
1076 | + if (!in_array($item->get_id(), $item_ids)) { |
|
1077 | 1077 | $item_ids[] = $item->get_id(); |
1078 | 1078 | $items[] = $item; |
1079 | 1079 | } |
1080 | 1080 | } |
1081 | 1081 | |
1082 | - $payment_form->set_items( $items ); |
|
1082 | + $payment_form->set_items($items); |
|
1083 | 1083 | |
1084 | 1084 | } else { |
1085 | - $payment_form->set_items( $invoice->get_items() ); |
|
1085 | + $payment_form->set_items($invoice->get_items()); |
|
1086 | 1086 | } |
1087 | 1087 | |
1088 | 1088 | // Generate the html. |
@@ -1091,7 +1091,7 @@ discard block |
||
1091 | 1091 | } |
1092 | 1092 | |
1093 | 1093 | function wpinv_empty_cart_message() { |
1094 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1094 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
1095 | 1095 | } |
1096 | 1096 | |
1097 | 1097 | /** |
@@ -1108,76 +1108,76 @@ discard block |
||
1108 | 1108 | ) |
1109 | 1109 | ); |
1110 | 1110 | } |
1111 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
1111 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
1112 | 1112 | |
1113 | 1113 | /** |
1114 | 1114 | * Filters the receipt page. |
1115 | 1115 | */ |
1116 | -function wpinv_filter_success_page_content( $content ) { |
|
1116 | +function wpinv_filter_success_page_content($content) { |
|
1117 | 1117 | |
1118 | 1118 | // Maybe abort early. |
1119 | - if ( is_admin() || ! is_singular() || ! in_the_loop() || ! is_main_query() || is_preview() ) { |
|
1119 | + if (is_admin() || !is_singular() || !in_the_loop() || !is_main_query() || is_preview()) { |
|
1120 | 1120 | return $content; |
1121 | 1121 | } |
1122 | 1122 | |
1123 | 1123 | // Ensure this is our page. |
1124 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
1124 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
1125 | 1125 | |
1126 | - $gateway = sanitize_text_field( $_GET['payment-confirm'] ); |
|
1127 | - return apply_filters( "wpinv_payment_confirm_$gateway", $content ); |
|
1126 | + $gateway = sanitize_text_field($_GET['payment-confirm']); |
|
1127 | + return apply_filters("wpinv_payment_confirm_$gateway", $content); |
|
1128 | 1128 | |
1129 | 1129 | } |
1130 | 1130 | |
1131 | 1131 | return $content; |
1132 | 1132 | } |
1133 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
1133 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
1134 | 1134 | |
1135 | -function wpinv_invoice_link( $invoice_id ) { |
|
1136 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1135 | +function wpinv_invoice_link($invoice_id) { |
|
1136 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1137 | 1137 | |
1138 | - if ( empty( $invoice ) ) { |
|
1138 | + if (empty($invoice)) { |
|
1139 | 1139 | return NULL; |
1140 | 1140 | } |
1141 | 1141 | |
1142 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
1142 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
1143 | 1143 | |
1144 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
1144 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
1145 | 1145 | } |
1146 | 1146 | |
1147 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
1148 | - if ( empty( $note ) ) { |
|
1147 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
1148 | + if (empty($note)) { |
|
1149 | 1149 | return NULL; |
1150 | 1150 | } |
1151 | 1151 | |
1152 | - if ( is_int( $note ) ) { |
|
1153 | - $note = get_comment( $note ); |
|
1152 | + if (is_int($note)) { |
|
1153 | + $note = get_comment($note); |
|
1154 | 1154 | } |
1155 | 1155 | |
1156 | - if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
1156 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
1157 | 1157 | return NULL; |
1158 | 1158 | } |
1159 | 1159 | |
1160 | - $note_classes = array( 'note' ); |
|
1161 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
1160 | + $note_classes = array('note'); |
|
1161 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
1162 | 1162 | $note_classes[] = $note->comment_author === 'System' ? 'system-note' : ''; |
1163 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
1164 | - $note_classes = !empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
1163 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
1164 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
1165 | 1165 | |
1166 | 1166 | ob_start(); |
1167 | 1167 | ?> |
1168 | - <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?> mb-2"> |
|
1168 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?> mb-2"> |
|
1169 | 1169 | <div class="note_content"> |
1170 | 1170 | |
1171 | - <?php echo wptexturize( wp_kses_post( $note->comment_content ) ); ?> |
|
1171 | + <?php echo wptexturize(wp_kses_post($note->comment_content)); ?> |
|
1172 | 1172 | |
1173 | - <?php if ( ! is_admin() ) : ?> |
|
1173 | + <?php if (!is_admin()) : ?> |
|
1174 | 1174 | <em class="small form-text text-muted mt-0"> |
1175 | 1175 | <?php |
1176 | 1176 | printf( |
1177 | - __( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
1177 | + __('%1$s - %2$s at %3$s', 'invoicing'), |
|
1178 | 1178 | $note->comment_author, |
1179 | - getpaid_format_date_value( $note->comment_date ), |
|
1180 | - date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) |
|
1179 | + getpaid_format_date_value($note->comment_date), |
|
1180 | + date_i18n(get_option('time_format'), strtotime($note->comment_date)) |
|
1181 | 1181 | ); |
1182 | 1182 | ?> |
1183 | 1183 | </em> |
@@ -1185,21 +1185,21 @@ discard block |
||
1185 | 1185 | |
1186 | 1186 | </div> |
1187 | 1187 | |
1188 | - <?php if ( is_admin() ) : ?> |
|
1188 | + <?php if (is_admin()) : ?> |
|
1189 | 1189 | |
1190 | 1190 | <p class="meta px-4 py-2"> |
1191 | - <abbr class="exact-date" title="<?php echo esc_attr( $note->comment_date ); ?>"> |
|
1191 | + <abbr class="exact-date" title="<?php echo esc_attr($note->comment_date); ?>"> |
|
1192 | 1192 | <?php |
1193 | 1193 | printf( |
1194 | - __( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
1194 | + __('%1$s - %2$s at %3$s', 'invoicing'), |
|
1195 | 1195 | $note->comment_author, |
1196 | - getpaid_format_date_value( $note->comment_date ), |
|
1197 | - date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) |
|
1196 | + getpaid_format_date_value($note->comment_date), |
|
1197 | + date_i18n(get_option('time_format'), strtotime($note->comment_date)) |
|
1198 | 1198 | ); |
1199 | 1199 | ?> |
1200 | 1200 | </abbr> |
1201 | - <?php if ( $note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing() ) { ?> |
|
1202 | - <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a> |
|
1201 | + <?php if ($note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing()) { ?> |
|
1202 | + <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a> |
|
1203 | 1203 | <?php } ?> |
1204 | 1204 | </p> |
1205 | 1205 | |
@@ -1208,9 +1208,9 @@ discard block |
||
1208 | 1208 | </li> |
1209 | 1209 | <?php |
1210 | 1210 | $note_content = ob_get_clean(); |
1211 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
1211 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
1212 | 1212 | |
1213 | - if ( $echo ) { |
|
1213 | + if ($echo) { |
|
1214 | 1214 | echo $note_content; |
1215 | 1215 | } else { |
1216 | 1216 | return $note_content; |
@@ -1224,21 +1224,21 @@ discard block |
||
1224 | 1224 | * @return string |
1225 | 1225 | */ |
1226 | 1226 | function wpinv_get_policy_text() { |
1227 | - $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 ); |
|
1227 | + $privacy_page_id = get_option('wp_page_for_privacy_policy', 0); |
|
1228 | 1228 | |
1229 | - $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' )); |
|
1229 | + $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]')); |
|
1230 | 1230 | |
1231 | - if(!$privacy_page_id){ |
|
1232 | - $privacy_page_id = wpinv_get_option( 'privacy_page', 0 ); |
|
1231 | + if (!$privacy_page_id) { |
|
1232 | + $privacy_page_id = wpinv_get_option('privacy_page', 0); |
|
1233 | 1233 | } |
1234 | 1234 | |
1235 | - $privacy_link = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' ); |
|
1235 | + $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing'); |
|
1236 | 1236 | |
1237 | 1237 | $find_replace = array( |
1238 | 1238 | '[wpinv_privacy_policy]' => $privacy_link, |
1239 | 1239 | ); |
1240 | 1240 | |
1241 | - $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text ); |
|
1241 | + $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text); |
|
1242 | 1242 | |
1243 | 1243 | return wp_kses_post(wpautop($privacy_text)); |
1244 | 1244 | } |
@@ -1246,21 +1246,21 @@ discard block |
||
1246 | 1246 | function wpinv_oxygen_fix_conflict() { |
1247 | 1247 | global $ct_ignore_post_types; |
1248 | 1248 | |
1249 | - if ( ! is_array( $ct_ignore_post_types ) ) { |
|
1249 | + if (!is_array($ct_ignore_post_types)) { |
|
1250 | 1250 | $ct_ignore_post_types = array(); |
1251 | 1251 | } |
1252 | 1252 | |
1253 | - $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item', 'wpi_payment_form' ); |
|
1253 | + $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item', 'wpi_payment_form'); |
|
1254 | 1254 | |
1255 | - foreach ( $post_types as $post_type ) { |
|
1255 | + foreach ($post_types as $post_type) { |
|
1256 | 1256 | $ct_ignore_post_types[] = $post_type; |
1257 | 1257 | |
1258 | 1258 | // Ignore post type |
1259 | - add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 ); |
|
1259 | + add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999); |
|
1260 | 1260 | } |
1261 | 1261 | |
1262 | - remove_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
1263 | - add_filter( 'template_include', 'wpinv_template', 999, 1 ); |
|
1262 | + remove_filter('template_include', 'wpinv_template', 10, 1); |
|
1263 | + add_filter('template_include', 'wpinv_template', 999, 1); |
|
1264 | 1264 | } |
1265 | 1265 | |
1266 | 1266 | /** |
@@ -1268,10 +1268,10 @@ discard block |
||
1268 | 1268 | * |
1269 | 1269 | * @param GetPaid_Payment_Form $form |
1270 | 1270 | */ |
1271 | -function getpaid_display_payment_form( $form ) { |
|
1271 | +function getpaid_display_payment_form($form) { |
|
1272 | 1272 | |
1273 | - if ( is_numeric( $form ) ) { |
|
1274 | - $form = new GetPaid_Payment_Form( $form ); |
|
1273 | + if (is_numeric($form)) { |
|
1274 | + $form = new GetPaid_Payment_Form($form); |
|
1275 | 1275 | } |
1276 | 1276 | |
1277 | 1277 | $form->display(); |
@@ -1281,55 +1281,55 @@ discard block |
||
1281 | 1281 | /** |
1282 | 1282 | * Helper function to display a item payment form on the frontend. |
1283 | 1283 | */ |
1284 | -function getpaid_display_item_payment_form( $items ) { |
|
1284 | +function getpaid_display_item_payment_form($items) { |
|
1285 | 1285 | |
1286 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1287 | - $form->set_items( $items ); |
|
1286 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1287 | + $form->set_items($items); |
|
1288 | 1288 | |
1289 | - if ( 0 == count( $form->get_items() ) ) { |
|
1289 | + if (0 == count($form->get_items())) { |
|
1290 | 1290 | echo aui()->alert( |
1291 | 1291 | array( |
1292 | 1292 | 'type' => 'warning', |
1293 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
1293 | + 'content' => __('No published items found', 'invoicing'), |
|
1294 | 1294 | ) |
1295 | 1295 | ); |
1296 | 1296 | return; |
1297 | 1297 | } |
1298 | 1298 | |
1299 | - $form_items = esc_attr( getpaid_convert_items_to_string( $items ) ); |
|
1299 | + $form_items = esc_attr(getpaid_convert_items_to_string($items)); |
|
1300 | 1300 | $form_items = "<input type='hidden' name='getpaid-form-items' value='$form_items' />"; |
1301 | - $form->display( $form_items ); |
|
1301 | + $form->display($form_items); |
|
1302 | 1302 | } |
1303 | 1303 | |
1304 | 1304 | /** |
1305 | 1305 | * Helper function to display an invoice payment form on the frontend. |
1306 | 1306 | */ |
1307 | -function getpaid_display_invoice_payment_form( $invoice_id ) { |
|
1307 | +function getpaid_display_invoice_payment_form($invoice_id) { |
|
1308 | 1308 | |
1309 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1309 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1310 | 1310 | |
1311 | - if ( empty( $invoice ) ) { |
|
1311 | + if (empty($invoice)) { |
|
1312 | 1312 | echo aui()->alert( |
1313 | 1313 | array( |
1314 | 1314 | 'type' => 'warning', |
1315 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1315 | + 'content' => __('Invoice not found', 'invoicing'), |
|
1316 | 1316 | ) |
1317 | 1317 | ); |
1318 | 1318 | return; |
1319 | 1319 | } |
1320 | 1320 | |
1321 | - if ( $invoice->is_paid() ) { |
|
1321 | + if ($invoice->is_paid()) { |
|
1322 | 1322 | echo aui()->alert( |
1323 | 1323 | array( |
1324 | 1324 | 'type' => 'warning', |
1325 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1325 | + 'content' => __('Invoice has already been paid', 'invoicing'), |
|
1326 | 1326 | ) |
1327 | 1327 | ); |
1328 | 1328 | return; |
1329 | 1329 | } |
1330 | 1330 | |
1331 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1332 | - $form->set_items( $invoice->get_items() ); |
|
1331 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1332 | + $form->set_items($invoice->get_items()); |
|
1333 | 1333 | |
1334 | 1334 | $form->display(); |
1335 | 1335 | } |
@@ -1337,23 +1337,23 @@ discard block |
||
1337 | 1337 | /** |
1338 | 1338 | * Helper function to convert item string to array. |
1339 | 1339 | */ |
1340 | -function getpaid_convert_items_to_array( $items ) { |
|
1341 | - $items = array_filter( array_map( 'trim', explode( ',', $items ) ) ); |
|
1340 | +function getpaid_convert_items_to_array($items) { |
|
1341 | + $items = array_filter(array_map('trim', explode(',', $items))); |
|
1342 | 1342 | $prepared = array(); |
1343 | 1343 | |
1344 | - foreach ( $items as $item ) { |
|
1345 | - $data = array_map( 'trim', explode( '|', $item ) ); |
|
1344 | + foreach ($items as $item) { |
|
1345 | + $data = array_map('trim', explode('|', $item)); |
|
1346 | 1346 | |
1347 | - if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) { |
|
1347 | + if (empty($data[0]) || !is_numeric($data[0])) { |
|
1348 | 1348 | continue; |
1349 | 1349 | } |
1350 | 1350 | |
1351 | 1351 | $quantity = 1; |
1352 | - if ( isset( $data[1] ) && is_numeric( $data[1] ) ) { |
|
1352 | + if (isset($data[1]) && is_numeric($data[1])) { |
|
1353 | 1353 | $quantity = (float) $data[1]; |
1354 | 1354 | } |
1355 | 1355 | |
1356 | - $prepared[ $data[0] ] = $quantity; |
|
1356 | + $prepared[$data[0]] = $quantity; |
|
1357 | 1357 | |
1358 | 1358 | } |
1359 | 1359 | |
@@ -1363,13 +1363,13 @@ discard block |
||
1363 | 1363 | /** |
1364 | 1364 | * Helper function to convert item array to string. |
1365 | 1365 | */ |
1366 | -function getpaid_convert_items_to_string( $items ) { |
|
1366 | +function getpaid_convert_items_to_string($items) { |
|
1367 | 1367 | $prepared = array(); |
1368 | 1368 | |
1369 | - foreach ( $items as $item => $quantity ) { |
|
1369 | + foreach ($items as $item => $quantity) { |
|
1370 | 1370 | $prepared[] = "$item|$quantity"; |
1371 | 1371 | } |
1372 | - return implode( ',', $prepared ); |
|
1372 | + return implode(',', $prepared); |
|
1373 | 1373 | } |
1374 | 1374 | |
1375 | 1375 | /** |
@@ -1377,21 +1377,21 @@ discard block |
||
1377 | 1377 | * |
1378 | 1378 | * Provide a label and one of $form, $items or $invoice. |
1379 | 1379 | */ |
1380 | -function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) { |
|
1381 | - $label = sanitize_text_field( $label ); |
|
1380 | +function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) { |
|
1381 | + $label = sanitize_text_field($label); |
|
1382 | 1382 | |
1383 | - if ( ! empty( $form ) ) { |
|
1384 | - $form = esc_attr( $form ); |
|
1383 | + if (!empty($form)) { |
|
1384 | + $form = esc_attr($form); |
|
1385 | 1385 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>"; |
1386 | 1386 | } |
1387 | 1387 | |
1388 | - if ( ! empty( $items ) ) { |
|
1389 | - $items = esc_attr( $items ); |
|
1388 | + if (!empty($items)) { |
|
1389 | + $items = esc_attr($items); |
|
1390 | 1390 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>"; |
1391 | 1391 | } |
1392 | 1392 | |
1393 | - if ( ! empty( $invoice ) ) { |
|
1394 | - $invoice = esc_attr( $invoice ); |
|
1393 | + if (!empty($invoice)) { |
|
1394 | + $invoice = esc_attr($invoice); |
|
1395 | 1395 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-invoice='$invoice'>$label</button>"; |
1396 | 1396 | } |
1397 | 1397 | |
@@ -1402,18 +1402,18 @@ discard block |
||
1402 | 1402 | * |
1403 | 1403 | * @param WPInv_Invoice $invoice |
1404 | 1404 | */ |
1405 | -function getpaid_the_invoice_description( $invoice ) { |
|
1405 | +function getpaid_the_invoice_description($invoice) { |
|
1406 | 1406 | $description = $invoice->get_description(); |
1407 | 1407 | |
1408 | - if ( empty( $description ) ) { |
|
1408 | + if (empty($description)) { |
|
1409 | 1409 | return; |
1410 | 1410 | } |
1411 | 1411 | |
1412 | - $description = wp_kses_post( $description ); |
|
1412 | + $description = wp_kses_post($description); |
|
1413 | 1413 | echo "<small class='getpaid-invoice-description text-dark p-2 form-text' style='margin-bottom: 20px; border-left: 2px solid #2196F3;'><em>$description</em></small>"; |
1414 | 1414 | } |
1415 | -add_action( 'getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100 ); |
|
1416 | -add_action( 'wpinv_email_billing_details', 'getpaid_the_invoice_description', 100 ); |
|
1415 | +add_action('getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100); |
|
1416 | +add_action('wpinv_email_billing_details', 'getpaid_the_invoice_description', 100); |
|
1417 | 1417 | |
1418 | 1418 | /** |
1419 | 1419 | * Render element on a form. |
@@ -1421,60 +1421,60 @@ discard block |
||
1421 | 1421 | * @param array $element |
1422 | 1422 | * @param GetPaid_Payment_Form $form |
1423 | 1423 | */ |
1424 | -function getpaid_payment_form_element( $element, $form ) { |
|
1424 | +function getpaid_payment_form_element($element, $form) { |
|
1425 | 1425 | |
1426 | 1426 | // Set up the args. |
1427 | - $element_type = trim( $element['type'] ); |
|
1427 | + $element_type = trim($element['type']); |
|
1428 | 1428 | $element['form'] = $form; |
1429 | - extract( $element ); |
|
1429 | + extract($element); |
|
1430 | 1430 | |
1431 | 1431 | // Try to locate the appropriate template. |
1432 | - $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" ); |
|
1432 | + $located = wpinv_locate_template("payment-forms/elements/$element_type.php"); |
|
1433 | 1433 | |
1434 | 1434 | // Abort if this is not our element. |
1435 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1435 | + if (empty($located) || !file_exists($located)) { |
|
1436 | 1436 | return; |
1437 | 1437 | } |
1438 | 1438 | |
1439 | 1439 | // Generate the class and id of the element. |
1440 | - $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) ); |
|
1441 | - $id = isset( $id ) ? $id : uniqid( 'gp' ); |
|
1440 | + $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type)); |
|
1441 | + $id = isset($id) ? $id : uniqid('gp'); |
|
1442 | 1442 | |
1443 | 1443 | // Echo the opening wrapper. |
1444 | 1444 | echo "<div class='getpaid-payment-form-element $wrapper_class'>"; |
1445 | 1445 | |
1446 | 1446 | // Fires before displaying a given element type's content. |
1447 | - do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form ); |
|
1447 | + do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form); |
|
1448 | 1448 | |
1449 | 1449 | // Include the template for the element. |
1450 | 1450 | include $located; |
1451 | 1451 | |
1452 | 1452 | // Fires after displaying a given element type's content. |
1453 | - do_action( "getpaid_payment_form_{$element_type}_element", $element, $form ); |
|
1453 | + do_action("getpaid_payment_form_{$element_type}_element", $element, $form); |
|
1454 | 1454 | |
1455 | 1455 | // Echo the closing wrapper. |
1456 | 1456 | echo '</div>'; |
1457 | 1457 | } |
1458 | -add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 ); |
|
1458 | +add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2); |
|
1459 | 1459 | |
1460 | 1460 | /** |
1461 | 1461 | * Render an element's edit page. |
1462 | 1462 | * |
1463 | 1463 | * @param WP_Post $post |
1464 | 1464 | */ |
1465 | -function getpaid_payment_form_edit_element_template( $post ) { |
|
1465 | +function getpaid_payment_form_edit_element_template($post) { |
|
1466 | 1466 | |
1467 | 1467 | // Retrieve all elements. |
1468 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
1468 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
1469 | 1469 | |
1470 | - foreach ( $all_elements as $element ) { |
|
1470 | + foreach ($all_elements as $element) { |
|
1471 | 1471 | |
1472 | 1472 | // Try to locate the appropriate template. |
1473 | - $element = sanitize_key( $element ); |
|
1474 | - $located = wpinv_locate_template( "payment-forms-admin/edit/$element.php" ); |
|
1473 | + $element = sanitize_key($element); |
|
1474 | + $located = wpinv_locate_template("payment-forms-admin/edit/$element.php"); |
|
1475 | 1475 | |
1476 | 1476 | // Continue if this is not our element. |
1477 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1477 | + if (empty($located) || !file_exists($located)) { |
|
1478 | 1478 | continue; |
1479 | 1479 | } |
1480 | 1480 | |
@@ -1485,7 +1485,7 @@ discard block |
||
1485 | 1485 | } |
1486 | 1486 | |
1487 | 1487 | } |
1488 | -add_action( 'getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template' ); |
|
1488 | +add_action('getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template'); |
|
1489 | 1489 | |
1490 | 1490 | /** |
1491 | 1491 | * Render an element's preview. |
@@ -1494,16 +1494,16 @@ discard block |
||
1494 | 1494 | function getpaid_payment_form_render_element_preview_template() { |
1495 | 1495 | |
1496 | 1496 | // Retrieve all elements. |
1497 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
1497 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
1498 | 1498 | |
1499 | - foreach ( $all_elements as $element ) { |
|
1499 | + foreach ($all_elements as $element) { |
|
1500 | 1500 | |
1501 | 1501 | // Try to locate the appropriate template. |
1502 | - $element = sanitize_key( $element ); |
|
1503 | - $located = wpinv_locate_template( "payment-forms-admin/previews/$element.php" ); |
|
1502 | + $element = sanitize_key($element); |
|
1503 | + $located = wpinv_locate_template("payment-forms-admin/previews/$element.php"); |
|
1504 | 1504 | |
1505 | 1505 | // Continue if this is not our element. |
1506 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1506 | + if (empty($located) || !file_exists($located)) { |
|
1507 | 1507 | continue; |
1508 | 1508 | } |
1509 | 1509 | |
@@ -1514,7 +1514,7 @@ discard block |
||
1514 | 1514 | } |
1515 | 1515 | |
1516 | 1516 | } |
1517 | -add_action( 'wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template' ); |
|
1517 | +add_action('wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template'); |
|
1518 | 1518 | |
1519 | 1519 | /** |
1520 | 1520 | * Shows a list of gateways that support recurring payments. |
@@ -1522,17 +1522,17 @@ discard block |
||
1522 | 1522 | function wpinv_get_recurring_gateways_text() { |
1523 | 1523 | $gateways = array(); |
1524 | 1524 | |
1525 | - foreach ( wpinv_get_payment_gateways() as $key => $gateway ) { |
|
1526 | - if ( wpinv_gateway_support_subscription( $key ) ) { |
|
1527 | - $gateways[] = sanitize_text_field( $gateway['admin_label'] ); |
|
1525 | + foreach (wpinv_get_payment_gateways() as $key => $gateway) { |
|
1526 | + if (wpinv_gateway_support_subscription($key)) { |
|
1527 | + $gateways[] = sanitize_text_field($gateway['admin_label']); |
|
1528 | 1528 | } |
1529 | 1529 | } |
1530 | 1530 | |
1531 | - if ( empty( $gateways ) ) { |
|
1532 | - return "<span class='form-text text-danger'>" . __( 'No active gateways support subscription payments.', 'invoicing' ) ."</span>"; |
|
1531 | + if (empty($gateways)) { |
|
1532 | + return "<span class='form-text text-danger'>" . __('No active gateways support subscription payments.', 'invoicing') . "</span>"; |
|
1533 | 1533 | } |
1534 | 1534 | |
1535 | - return "<span class='form-text text-muted'>" . wp_sprintf( __( 'Subscription payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ) ."</span>"; |
|
1535 | + return "<span class='form-text text-muted'>" . wp_sprintf(__('Subscription payments only supported by: %s', 'invoicing'), implode(', ', $gateways)) . "</span>"; |
|
1536 | 1536 | |
1537 | 1537 | } |
1538 | 1538 | |
@@ -1542,7 +1542,7 @@ discard block |
||
1542 | 1542 | * @return GetPaid_Template |
1543 | 1543 | */ |
1544 | 1544 | function getpaid_template() { |
1545 | - return getpaid()->get( 'template' ); |
|
1545 | + return getpaid()->get('template'); |
|
1546 | 1546 | } |
1547 | 1547 | |
1548 | 1548 | /** |
@@ -1551,8 +1551,8 @@ discard block |
||
1551 | 1551 | * @param array args |
1552 | 1552 | * @return string |
1553 | 1553 | */ |
1554 | -function getpaid_paginate_links( $args ) { |
|
1555 | - return str_replace( 'page-link dots', 'page-link text-dark', aui()->pagination( $args ) ); |
|
1554 | +function getpaid_paginate_links($args) { |
|
1555 | + return str_replace('page-link dots', 'page-link text-dark', aui()->pagination($args)); |
|
1556 | 1556 | } |
1557 | 1557 | |
1558 | 1558 | /** |
@@ -1562,21 +1562,21 @@ discard block |
||
1562 | 1562 | * @param string state |
1563 | 1563 | * @return string |
1564 | 1564 | */ |
1565 | -function getpaid_get_states_select_markup( $country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state' ) { |
|
1565 | +function getpaid_get_states_select_markup($country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state') { |
|
1566 | 1566 | |
1567 | - $states = wpinv_get_country_states( $country ); |
|
1568 | - $uniqid = uniqid( '_' ); |
|
1567 | + $states = wpinv_get_country_states($country); |
|
1568 | + $uniqid = uniqid('_'); |
|
1569 | 1569 | |
1570 | - if ( ! empty( $states ) ) { |
|
1570 | + if (!empty($states)) { |
|
1571 | 1571 | |
1572 | - return aui()->select( array( |
|
1572 | + return aui()->select(array( |
|
1573 | 1573 | 'options' => $states, |
1574 | - 'name' => esc_attr( $field_name ), |
|
1575 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
1576 | - 'value' => sanitize_text_field( $state ), |
|
1574 | + 'name' => esc_attr($field_name), |
|
1575 | + 'id' => sanitize_html_class($field_name) . $uniqid, |
|
1576 | + 'value' => sanitize_text_field($state), |
|
1577 | 1577 | 'placeholder' => $placeholder, |
1578 | 1578 | 'required' => $required, |
1579 | - 'label' => wp_kses_post( $label ), |
|
1579 | + 'label' => wp_kses_post($label), |
|
1580 | 1580 | 'label_type' => 'vertical', |
1581 | 1581 | 'help_text' => $help_text, |
1582 | 1582 | 'class' => 'getpaid-address-field wpinv_state', |
@@ -1591,14 +1591,14 @@ discard block |
||
1591 | 1591 | |
1592 | 1592 | return aui()->input( |
1593 | 1593 | array( |
1594 | - 'name' => esc_attr( $field_name ), |
|
1595 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
1594 | + 'name' => esc_attr($field_name), |
|
1595 | + 'id' => sanitize_html_class($field_name) . $uniqid, |
|
1596 | 1596 | 'placeholder' => $placeholder, |
1597 | 1597 | 'required' => $required, |
1598 | - 'label' => wp_kses_post( $label ), |
|
1598 | + 'label' => wp_kses_post($label), |
|
1599 | 1599 | 'label_type' => 'vertical', |
1600 | 1600 | 'help_text' => $help_text, |
1601 | - 'value' => sanitize_text_field( $state ), |
|
1601 | + 'value' => sanitize_text_field($state), |
|
1602 | 1602 | 'class' => 'getpaid-address-field wpinv_state', |
1603 | 1603 | 'wrap_class' => "$wrapper_class getpaid-address-field-wrapper__state", |
1604 | 1604 | 'label_class' => 'getpaid-address-field-label getpaid-address-field-label__state', |
@@ -1616,16 +1616,16 @@ discard block |
||
1616 | 1616 | * @param array $element |
1617 | 1617 | * @return string |
1618 | 1618 | */ |
1619 | -function getpaid_get_form_element_grid_class( $element ) { |
|
1619 | +function getpaid_get_form_element_grid_class($element) { |
|
1620 | 1620 | |
1621 | 1621 | $class = "col-12"; |
1622 | - $width = empty( $element['grid_width'] ) ? 'full' : $element['grid_width']; |
|
1622 | + $width = empty($element['grid_width']) ? 'full' : $element['grid_width']; |
|
1623 | 1623 | |
1624 | - if ( $width == 'half' ) { |
|
1624 | + if ($width == 'half') { |
|
1625 | 1625 | $class = "col-12 col-md-6"; |
1626 | 1626 | } |
1627 | 1627 | |
1628 | - if ( $width == 'third' ) { |
|
1628 | + if ($width == 'third') { |
|
1629 | 1629 | $class = "col-12 col-md-4"; |
1630 | 1630 | } |
1631 | 1631 |
@@ -1,155 +1,155 @@ discard block |
||
1 | 1 | <?php |
2 | -function wpinv_is_subscription_payment( $invoice = '' ) { |
|
3 | - if ( empty( $invoice ) ) { |
|
2 | +function wpinv_is_subscription_payment($invoice = '') { |
|
3 | + if (empty($invoice)) { |
|
4 | 4 | return false; |
5 | 5 | } |
6 | 6 | |
7 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
8 | - $invoice = wpinv_get_invoice( $invoice ); |
|
7 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
8 | + $invoice = wpinv_get_invoice($invoice); |
|
9 | 9 | } |
10 | 10 | |
11 | - if ( empty( $invoice ) ) { |
|
11 | + if (empty($invoice)) { |
|
12 | 12 | return false; |
13 | 13 | } |
14 | 14 | |
15 | - if ( $invoice->is_renewal() ) { |
|
15 | + if ($invoice->is_renewal()) { |
|
16 | 16 | return true; |
17 | 17 | } |
18 | 18 | |
19 | 19 | return false; |
20 | 20 | } |
21 | 21 | |
22 | -function wpinv_payment_link_transaction_id( $invoice = '' ) { |
|
23 | - if ( empty( $invoice ) ) { |
|
22 | +function wpinv_payment_link_transaction_id($invoice = '') { |
|
23 | + if (empty($invoice)) { |
|
24 | 24 | return false; |
25 | 25 | } |
26 | 26 | |
27 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
28 | - $invoice = wpinv_get_invoice( $invoice ); |
|
27 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
28 | + $invoice = wpinv_get_invoice($invoice); |
|
29 | 29 | } |
30 | 30 | |
31 | - if ( empty( $invoice ) ) { |
|
31 | + if (empty($invoice)) { |
|
32 | 32 | return false; |
33 | 33 | } |
34 | 34 | |
35 | - return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice ); |
|
35 | + return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice); |
|
36 | 36 | } |
37 | 37 | |
38 | -function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) { |
|
39 | - $interval = (int)$interval > 0 ? (int)$interval : 1; |
|
38 | +function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) { |
|
39 | + $interval = (int) $interval > 0 ? (int) $interval : 1; |
|
40 | 40 | |
41 | - if ( $trial_interval > 0 && !empty( $trial_period ) ) { |
|
42 | - $amount = __( 'Free', 'invoicing' ); |
|
41 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
42 | + $amount = __('Free', 'invoicing'); |
|
43 | 43 | $interval = $trial_interval; |
44 | 44 | $period = $trial_period; |
45 | 45 | } |
46 | 46 | |
47 | 47 | $description = ''; |
48 | - switch ( $period ) { |
|
48 | + switch ($period) { |
|
49 | 49 | case 'D' : |
50 | 50 | case 'day' : |
51 | - $description = wp_sprintf( _n( '%s for the first day.', '%s for the first %d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
51 | + $description = wp_sprintf(_n('%s for the first day.', '%s for the first %d days.', $interval, 'invoicing'), $amount, $interval); |
|
52 | 52 | break; |
53 | 53 | case 'W' : |
54 | 54 | case 'week' : |
55 | - $description = wp_sprintf( _n( '%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
55 | + $description = wp_sprintf(_n('%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
56 | 56 | break; |
57 | 57 | case 'M' : |
58 | 58 | case 'month' : |
59 | - $description = wp_sprintf( _n( '%s for the first month.', '%s for the first %d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
59 | + $description = wp_sprintf(_n('%s for the first month.', '%s for the first %d months.', $interval, 'invoicing'), $amount, $interval); |
|
60 | 60 | break; |
61 | 61 | case 'Y' : |
62 | 62 | case 'year' : |
63 | - $description = wp_sprintf( _n( '%s for the first year.', '%s for the first %d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
63 | + $description = wp_sprintf(_n('%s for the first year.', '%s for the first %d years.', $interval, 'invoicing'), $amount, $interval); |
|
64 | 64 | break; |
65 | 65 | } |
66 | 66 | |
67 | - return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval ); |
|
67 | + return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval); |
|
68 | 68 | } |
69 | 69 | |
70 | -function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) { |
|
71 | - $interval = (int)$interval > 0 ? (int)$interval : 1; |
|
72 | - $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0; |
|
70 | +function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) { |
|
71 | + $interval = (int) $interval > 0 ? (int) $interval : 1; |
|
72 | + $bill_times = (int) $bill_times > 0 ? (int) $bill_times : 0; |
|
73 | 73 | |
74 | 74 | $description = ''; |
75 | - switch ( $period ) { |
|
75 | + switch ($period) { |
|
76 | 76 | case 'D' : |
77 | 77 | case 'day' : |
78 | - if ( (int)$bill_times > 0 ) { |
|
79 | - if ( $interval > 1 ) { |
|
80 | - if ( $bill_times > 1 ) { |
|
81 | - $description = wp_sprintf( __( '%s for each %d days, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
78 | + if ((int) $bill_times > 0) { |
|
79 | + if ($interval > 1) { |
|
80 | + if ($bill_times > 1) { |
|
81 | + $description = wp_sprintf(__('%s for each %d days, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
82 | 82 | } else { |
83 | - $description = wp_sprintf( __( '%s for %d days.', 'invoicing' ), $amount, $interval ); |
|
83 | + $description = wp_sprintf(__('%s for %d days.', 'invoicing'), $amount, $interval); |
|
84 | 84 | } |
85 | 85 | } else { |
86 | - $description = wp_sprintf( _n( '%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
86 | + $description = wp_sprintf(_n('%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
87 | 87 | } |
88 | 88 | } else { |
89 | - $description = wp_sprintf( _n( '%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval ); |
|
89 | + $description = wp_sprintf(_n('%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval); |
|
90 | 90 | } |
91 | 91 | break; |
92 | 92 | case 'W' : |
93 | 93 | case 'week' : |
94 | - if ( (int)$bill_times > 0 ) { |
|
95 | - if ( $interval > 1 ) { |
|
96 | - if ( $bill_times > 1 ) { |
|
97 | - $description = wp_sprintf( __( '%s for each %d weeks, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
94 | + if ((int) $bill_times > 0) { |
|
95 | + if ($interval > 1) { |
|
96 | + if ($bill_times > 1) { |
|
97 | + $description = wp_sprintf(__('%s for each %d weeks, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
98 | 98 | } else { |
99 | - $description = wp_sprintf( __( '%s for %d weeks.', 'invoicing' ), $amount, $interval ); |
|
99 | + $description = wp_sprintf(__('%s for %d weeks.', 'invoicing'), $amount, $interval); |
|
100 | 100 | } |
101 | 101 | } else { |
102 | - $description = wp_sprintf( _n( '%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
102 | + $description = wp_sprintf(_n('%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
103 | 103 | } |
104 | 104 | } else { |
105 | - $description = wp_sprintf( _n( '%s for each week.', '%s for each %d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
105 | + $description = wp_sprintf(_n('%s for each week.', '%s for each %d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
106 | 106 | } |
107 | 107 | break; |
108 | 108 | case 'M' : |
109 | 109 | case 'month' : |
110 | - if ( (int)$bill_times > 0 ) { |
|
111 | - if ( $interval > 1 ) { |
|
112 | - if ( $bill_times > 1 ) { |
|
113 | - $description = wp_sprintf( __( '%s for each %d months, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
110 | + if ((int) $bill_times > 0) { |
|
111 | + if ($interval > 1) { |
|
112 | + if ($bill_times > 1) { |
|
113 | + $description = wp_sprintf(__('%s for each %d months, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
114 | 114 | } else { |
115 | - $description = wp_sprintf( __( '%s for %d months.', 'invoicing' ), $amount, $interval ); |
|
115 | + $description = wp_sprintf(__('%s for %d months.', 'invoicing'), $amount, $interval); |
|
116 | 116 | } |
117 | 117 | } else { |
118 | - $description = wp_sprintf( _n( '%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
118 | + $description = wp_sprintf(_n('%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
119 | 119 | } |
120 | 120 | } else { |
121 | - $description = wp_sprintf( _n( '%s for each month.', '%s for each %d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
121 | + $description = wp_sprintf(_n('%s for each month.', '%s for each %d months.', $interval, 'invoicing'), $amount, $interval); |
|
122 | 122 | } |
123 | 123 | break; |
124 | 124 | case 'Y' : |
125 | 125 | case 'year' : |
126 | - if ( (int)$bill_times > 0 ) { |
|
127 | - if ( $interval > 1 ) { |
|
128 | - if ( $bill_times > 1 ) { |
|
129 | - $description = wp_sprintf( __( '%s for each %d years, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
126 | + if ((int) $bill_times > 0) { |
|
127 | + if ($interval > 1) { |
|
128 | + if ($bill_times > 1) { |
|
129 | + $description = wp_sprintf(__('%s for each %d years, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
130 | 130 | } else { |
131 | - $description = wp_sprintf( __( '%s for %d years.', 'invoicing'), $amount, $interval ); |
|
131 | + $description = wp_sprintf(__('%s for %d years.', 'invoicing'), $amount, $interval); |
|
132 | 132 | } |
133 | 133 | } else { |
134 | - $description = wp_sprintf( _n( '%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
134 | + $description = wp_sprintf(_n('%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
135 | 135 | } |
136 | 136 | } else { |
137 | - $description = wp_sprintf( _n( '%s for each year.', '%s for each %d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
137 | + $description = wp_sprintf(_n('%s for each year.', '%s for each %d years.', $interval, 'invoicing'), $amount, $interval); |
|
138 | 138 | } |
139 | 139 | break; |
140 | 140 | } |
141 | 141 | |
142 | - return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
142 | + return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
143 | 143 | } |
144 | 144 | |
145 | -function wpinv_subscription_payment_desc( $invoice ) { |
|
146 | - if ( empty( $invoice ) ) { |
|
145 | +function wpinv_subscription_payment_desc($invoice) { |
|
146 | + if (empty($invoice)) { |
|
147 | 147 | return NULL; |
148 | 148 | } |
149 | 149 | |
150 | 150 | $description = ''; |
151 | - if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) { |
|
152 | - if ( $item->has_free_trial() ) { |
|
151 | + if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) { |
|
152 | + if ($item->has_free_trial()) { |
|
153 | 153 | $trial_period = $item->get_trial_period(); |
154 | 154 | $trial_interval = $item->get_trial_interval(); |
155 | 155 | } else { |
@@ -157,40 +157,40 @@ discard block |
||
157 | 157 | $trial_interval = 0; |
158 | 158 | } |
159 | 159 | |
160 | - $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() ); |
|
160 | + $description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency()); |
|
161 | 161 | } |
162 | 162 | |
163 | - return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice ); |
|
163 | + return apply_filters('wpinv_subscription_payment_desc', $description, $invoice); |
|
164 | 164 | } |
165 | 165 | |
166 | -function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) { |
|
167 | - $initial_total = wpinv_round_amount( $initial ); |
|
168 | - $recurring_total = wpinv_round_amount( $recurring ); |
|
166 | +function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') { |
|
167 | + $initial_total = wpinv_round_amount($initial); |
|
168 | + $recurring_total = wpinv_round_amount($recurring); |
|
169 | 169 | |
170 | - if ( $trial_interval > 0 && !empty( $trial_period ) ) { |
|
170 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
171 | 171 | // Free trial |
172 | 172 | } else { |
173 | - if ( $bill_times == 1 ) { |
|
173 | + if ($bill_times == 1) { |
|
174 | 174 | $recurring_total = $initial_total; |
175 | - } else if ( $bill_times > 1 && $initial_total != $recurring_total ) { |
|
175 | + } else if ($bill_times > 1 && $initial_total != $recurring_total) { |
|
176 | 176 | $bill_times--; |
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
180 | - $initial_amount = wpinv_price( $initial_total, $currency ); |
|
181 | - $recurring_amount = wpinv_price( $recurring_total, $currency ); |
|
180 | + $initial_amount = wpinv_price($initial_total, $currency); |
|
181 | + $recurring_amount = wpinv_price($recurring_total, $currency); |
|
182 | 182 | |
183 | - $recurring = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
183 | + $recurring = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
184 | 184 | |
185 | - if ( $initial_total != $recurring_total ) { |
|
186 | - $initial = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval ); |
|
185 | + if ($initial_total != $recurring_total) { |
|
186 | + $initial = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval); |
|
187 | 187 | |
188 | - $description = wp_sprintf( __( '%s Then %s', 'invoicing' ), $initial, $recurring ); |
|
188 | + $description = wp_sprintf(__('%s Then %s', 'invoicing'), $initial, $recurring); |
|
189 | 189 | } else { |
190 | 190 | $description = $recurring; |
191 | 191 | } |
192 | 192 | |
193 | - return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency ); |
|
193 | + return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -200,27 +200,27 @@ discard block |
||
200 | 200 | * @param string $card_number Card number. |
201 | 201 | * @return string |
202 | 202 | */ |
203 | -function getpaid_get_card_name( $card_number ) { |
|
203 | +function getpaid_get_card_name($card_number) { |
|
204 | 204 | |
205 | 205 | // Known regexes. |
206 | 206 | $regexes = array( |
207 | - '/^4/' => __( 'Visa', 'invoicing' ), |
|
208 | - '/^5[1-5]/' => __( 'Mastercard', 'invoicing' ), |
|
209 | - '/^3[47]/' => __( 'Amex', 'invoicing' ), |
|
210 | - '/^3(?:0[0-5]|[68])/' => __( 'Diners Club', 'invoicing' ), |
|
211 | - '/^6(?:011|5)/' => __( 'Discover', 'invoicing' ), |
|
212 | - '/^(?:2131|1800|35\d{3})/' => __( 'JCB', 'invoicing' ), |
|
207 | + '/^4/' => __('Visa', 'invoicing'), |
|
208 | + '/^5[1-5]/' => __('Mastercard', 'invoicing'), |
|
209 | + '/^3[47]/' => __('Amex', 'invoicing'), |
|
210 | + '/^3(?:0[0-5]|[68])/' => __('Diners Club', 'invoicing'), |
|
211 | + '/^6(?:011|5)/' => __('Discover', 'invoicing'), |
|
212 | + '/^(?:2131|1800|35\d{3})/' => __('JCB', 'invoicing'), |
|
213 | 213 | ); |
214 | 214 | |
215 | 215 | // Confirm if one matches. |
216 | - foreach ( $regexes as $regex => $card ) { |
|
217 | - if ( preg_match ( $regex, $card_number ) >= 1 ) { |
|
216 | + foreach ($regexes as $regex => $card) { |
|
217 | + if (preg_match($regex, $card_number) >= 1) { |
|
218 | 218 | return $card; |
219 | 219 | } |
220 | 220 | } |
221 | 221 | |
222 | 222 | // None matched. |
223 | - return __( 'Card', 'invoicing' ); |
|
223 | + return __('Card', 'invoicing'); |
|
224 | 224 | |
225 | 225 | } |
226 | 226 | |
@@ -229,23 +229,23 @@ discard block |
||
229 | 229 | * |
230 | 230 | * @param WPInv_Invoice|int|null $invoice |
231 | 231 | */ |
232 | -function wpinv_send_back_to_checkout( $invoice = null ) { |
|
233 | - $response = array( 'success' => false ); |
|
234 | - $invoice = wpinv_get_invoice( $invoice ); |
|
232 | +function wpinv_send_back_to_checkout($invoice = null) { |
|
233 | + $response = array('success' => false); |
|
234 | + $invoice = wpinv_get_invoice($invoice); |
|
235 | 235 | |
236 | 236 | // Was an invoice created? |
237 | - if ( ! empty( $invoice ) ) { |
|
238 | - $invoice = is_scalar( $invoice ) ? new WPInv_Invoice( $invoice ) : $invoice; |
|
237 | + if (!empty($invoice)) { |
|
238 | + $invoice = is_scalar($invoice) ? new WPInv_Invoice($invoice) : $invoice; |
|
239 | 239 | $response['invoice'] = $invoice->get_id(); |
240 | - do_action( 'getpaid_checkout_invoice_exception', $invoice ); |
|
240 | + do_action('getpaid_checkout_invoice_exception', $invoice); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | // Do we have any errors? |
244 | - if ( wpinv_get_errors() ) { |
|
245 | - $response['data'] = getpaid_get_errors_html( true, false ); |
|
244 | + if (wpinv_get_errors()) { |
|
245 | + $response['data'] = getpaid_get_errors_html(true, false); |
|
246 | 246 | } else { |
247 | - $response['data'] = __( 'An error occured while processing your payment. Please try again.', 'invoicing' ); |
|
247 | + $response['data'] = __('An error occured while processing your payment. Please try again.', 'invoicing'); |
|
248 | 248 | } |
249 | 249 | |
250 | - wp_send_json( $response ); |
|
250 | + wp_send_json($response); |
|
251 | 251 | } |
@@ -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 itemss class |
@@ -23,26 +23,26 @@ 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 | $data = $submission->get_data(); |
29 | 29 | $payment_form = $submission->get_payment_form(); |
30 | 30 | |
31 | 31 | // Prepare the selected items. |
32 | 32 | $selected_items = array(); |
33 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
34 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
33 | + if (!empty($data['getpaid-items'])) { |
|
34 | + $selected_items = wpinv_clean($data['getpaid-items']); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | // For default forms, ensure that an item has been set. |
38 | - if ( $payment_form->is_default() && ( ! $submission->has_invoice() || 'payment_form' == $submission->get_invoice()->get_created_via() ) && isset( $data['getpaid-form-items'] ) ) { |
|
39 | - $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
40 | - $payment_form->set_items( getpaid_convert_items_to_array( $form_items ) ); |
|
38 | + if ($payment_form->is_default() && (!$submission->has_invoice() || 'payment_form' == $submission->get_invoice()->get_created_via()) && isset($data['getpaid-form-items'])) { |
|
39 | + $form_items = wpinv_clean($data['getpaid-form-items']); |
|
40 | + $payment_form->set_items(getpaid_convert_items_to_array($form_items)); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | // Process each individual item. |
44 | - foreach ( $payment_form->get_items() as $item ) { |
|
45 | - $this->process_item( $item, $selected_items ); |
|
44 | + foreach ($payment_form->get_items() as $item) { |
|
45 | + $this->process_item($item, $selected_items); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | } |
@@ -53,30 +53,30 @@ discard block |
||
53 | 53 | * @param GetPaid_Form_Item $item |
54 | 54 | * @param array $selected_items |
55 | 55 | */ |
56 | - public function process_item( $item, $selected_items ) { |
|
56 | + public function process_item($item, $selected_items) { |
|
57 | 57 | |
58 | 58 | // Abort if this is an optional item and it has not been selected. |
59 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
59 | + if (!$item->is_required() && !isset($selected_items[$item->get_id()])) { |
|
60 | 60 | return; |
61 | 61 | } |
62 | 62 | |
63 | 63 | // (maybe) let customers change the quantities and prices. |
64 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
64 | + if (isset($selected_items[$item->get_id()])) { |
|
65 | 65 | |
66 | 66 | // Maybe change the quantities. |
67 | - if ( $item->allows_quantities() ) { |
|
68 | - $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
67 | + if ($item->allows_quantities()) { |
|
68 | + $item->set_quantity((float) $selected_items[$item->get_id()]['quantity']); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | // Maybe change the price. |
72 | - if ( $item->user_can_set_their_price() ) { |
|
73 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
72 | + if ($item->user_can_set_their_price()) { |
|
73 | + $price = (float) wpinv_sanitize_amount($selected_items[$item->get_id()]['price']); |
|
74 | 74 | |
75 | - if ( $item->get_minimum_price() > $price ) { |
|
76 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), wpinv_sanitize_amount( $item->get_minimum_price() ) ) ); |
|
75 | + if ($item->get_minimum_price() > $price) { |
|
76 | + throw new Exception(sprintf(__('The minimum allowed amount is %s', 'invoicing'), wpinv_sanitize_amount($item->get_minimum_price()))); |
|
77 | 77 | } |
78 | 78 | |
79 | - $item->set_price( $price ); |
|
79 | + $item->set_price($price); |
|
80 | 80 | |
81 | 81 | } |
82 | 82 |