@@ -7,40 +7,40 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_get_invoice_cart_id() { |
15 | 15 | $wpinv_checkout = wpinv_get_checkout_session(); |
16 | 16 | |
17 | - if ( !empty( $wpinv_checkout['invoice_id'] ) ) { |
|
17 | + if (!empty($wpinv_checkout['invoice_id'])) { |
|
18 | 18 | return $wpinv_checkout['invoice_id']; |
19 | 19 | } |
20 | 20 | |
21 | 21 | return NULL; |
22 | 22 | } |
23 | 23 | |
24 | -function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) { |
|
25 | - if ( empty( $invoice_data ) ) { |
|
24 | +function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) { |
|
25 | + if (empty($invoice_data)) { |
|
26 | 26 | return false; |
27 | 27 | } |
28 | 28 | |
29 | - if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) { |
|
30 | - return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast on item.', 'invoicing' ) ) : 0; |
|
29 | + if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) { |
|
30 | + return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast on item.', 'invoicing')) : 0; |
|
31 | 31 | } |
32 | 32 | |
33 | - if ( empty( $invoice_data['user_id'] ) ) { |
|
33 | + if (empty($invoice_data['user_id'])) { |
|
34 | 34 | $invoice_data['user_id'] = get_current_user_id(); |
35 | 35 | } |
36 | 36 | |
37 | - $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0; |
|
37 | + $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int)$invoice_data['invoice_id'] : 0; |
|
38 | 38 | |
39 | - if ( empty( $invoice_data['status'] ) ) { |
|
39 | + if (empty($invoice_data['status'])) { |
|
40 | 40 | $invoice_data['status'] = 'pending'; |
41 | 41 | } |
42 | 42 | |
43 | - if ( empty( $invoice_data['ip'] ) ) { |
|
43 | + if (empty($invoice_data['ip'])) { |
|
44 | 44 | $invoice_data['ip'] = wpinv_get_ip(); |
45 | 45 | } |
46 | 46 | |
@@ -51,12 +51,12 @@ discard block |
||
51 | 51 | 'status' => $invoice_data['status'], |
52 | 52 | ); |
53 | 53 | |
54 | - $invoice = wpinv_create_invoice( $default_args, $invoice_data, true ); |
|
55 | - if ( is_wp_error( $invoice ) ) { |
|
54 | + $invoice = wpinv_create_invoice($default_args, $invoice_data, true); |
|
55 | + if (is_wp_error($invoice)) { |
|
56 | 56 | return $wp_error ? $invoice : 0; |
57 | 57 | } |
58 | 58 | |
59 | - if ( empty( $invoice_data['invoice_id'] ) ) { |
|
59 | + if (empty($invoice_data['invoice_id'])) { |
|
60 | 60 | //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) ); |
61 | 61 | } |
62 | 62 | |
@@ -79,20 +79,20 @@ discard block |
||
79 | 79 | 'discount' => array(), |
80 | 80 | ); |
81 | 81 | |
82 | - if ( $user_id = (int)$invoice->get_user_id() ) { |
|
83 | - if ( $user_address = wpinv_get_user_address( $user_id ) ) { |
|
84 | - $default_user_info = wp_parse_args( $user_address, $default_user_info ); |
|
82 | + if ($user_id = (int)$invoice->get_user_id()) { |
|
83 | + if ($user_address = wpinv_get_user_address($user_id)) { |
|
84 | + $default_user_info = wp_parse_args($user_address, $default_user_info); |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
88 | - $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info ); |
|
88 | + $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info); |
|
89 | 89 | |
90 | - if ( empty( $user_info['first_name'] ) ) { |
|
90 | + if (empty($user_info['first_name'])) { |
|
91 | 91 | $user_info['first_name'] = $default_user_info['first_name']; |
92 | 92 | $user_info['last_name'] = $default_user_info['last_name']; |
93 | 93 | } |
94 | 94 | |
95 | - if ( empty( $user_info['country'] ) ) { |
|
95 | + if (empty($user_info['country'])) { |
|
96 | 96 | $user_info['country'] = $default_user_info['country']; |
97 | 97 | $user_info['state'] = $default_user_info['state']; |
98 | 98 | $user_info['city'] = $default_user_info['city']; |
@@ -101,13 +101,13 @@ discard block |
||
101 | 101 | $user_info['phone'] = $default_user_info['phone']; |
102 | 102 | } |
103 | 103 | |
104 | - if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) { |
|
104 | + if (!empty($user_info['discount']) && !is_array($user_info['discount'])) { |
|
105 | 105 | $user_info['discount'] = (array)$user_info['discount']; |
106 | 106 | } |
107 | 107 | |
108 | 108 | // Payment details |
109 | 109 | $payment_details = array(); |
110 | - if ( !empty( $invoice_data['payment_details'] ) ) { |
|
110 | + if (!empty($invoice_data['payment_details'])) { |
|
111 | 111 | $default_payment_details = array( |
112 | 112 | 'gateway' => 'manual', |
113 | 113 | 'gateway_title' => '', |
@@ -115,59 +115,59 @@ discard block |
||
115 | 115 | 'transaction_id' => '', |
116 | 116 | ); |
117 | 117 | |
118 | - $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details ); |
|
118 | + $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details); |
|
119 | 119 | |
120 | - if ( empty( $payment_details['gateway'] ) ) { |
|
120 | + if (empty($payment_details['gateway'])) { |
|
121 | 121 | $payment_details['gateway'] = 'manual'; |
122 | 122 | } |
123 | 123 | |
124 | - if ( empty( $payment_details['currency'] ) ) { |
|
124 | + if (empty($payment_details['currency'])) { |
|
125 | 125 | $payment_details['currency'] = geodir_get_currency_type(); |
126 | 126 | } |
127 | 127 | |
128 | - if ( empty( $payment_details['gateway_title'] ) ) { |
|
129 | - $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] ); |
|
128 | + if (empty($payment_details['gateway_title'])) { |
|
129 | + $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
133 | - $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'pending' ) ); |
|
134 | - |
|
135 | - if ( !empty( $payment_details ) ) { |
|
136 | - $invoice->set( 'currency', $payment_details['currency'] ); |
|
137 | - $invoice->set( 'gateway', $payment_details['gateway'] ); |
|
138 | - $invoice->set( 'gateway_title', $payment_details['gateway_title'] ); |
|
139 | - $invoice->set( 'transaction_id', $payment_details['transaction_id'] ); |
|
140 | - } |
|
141 | - |
|
142 | - $invoice->set( 'user_info', $user_info ); |
|
143 | - $invoice->set( 'first_name', $user_info['first_name'] ); |
|
144 | - $invoice->set( 'last_name', $user_info['last_name'] ); |
|
145 | - $invoice->set( 'address', $user_info['address'] ); |
|
146 | - $invoice->set( 'company', $user_info['company'] ); |
|
147 | - $invoice->set( 'vat_number', $user_info['vat_number'] ); |
|
148 | - $invoice->set( 'phone', $user_info['phone'] ); |
|
149 | - $invoice->set( 'city', $user_info['city'] ); |
|
150 | - $invoice->set( 'country', $user_info['country'] ); |
|
151 | - $invoice->set( 'state', $user_info['state'] ); |
|
152 | - $invoice->set( 'zip', $user_info['zip'] ); |
|
153 | - $invoice->set( 'discounts', $user_info['discount'] ); |
|
154 | - $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) ); |
|
155 | - if ( !empty( $invoice_data['invoice_key'] ) ) { |
|
156 | - $invoice->set( 'key', $invoice_data['invoice_key'] ); |
|
157 | - } |
|
158 | - $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) ); |
|
159 | - $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) ); |
|
160 | - |
|
161 | - if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) { |
|
162 | - foreach ( $invoice_data['cart_details'] as $key => $item ) { |
|
163 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
164 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
165 | - $name = !empty( $item['name'] ) ? $item['name'] : ''; |
|
166 | - $item_price = isset( $item['item_price'] ) ? $item['item_price'] : ''; |
|
133 | + $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'pending')); |
|
134 | + |
|
135 | + if (!empty($payment_details)) { |
|
136 | + $invoice->set('currency', $payment_details['currency']); |
|
137 | + $invoice->set('gateway', $payment_details['gateway']); |
|
138 | + $invoice->set('gateway_title', $payment_details['gateway_title']); |
|
139 | + $invoice->set('transaction_id', $payment_details['transaction_id']); |
|
140 | + } |
|
141 | + |
|
142 | + $invoice->set('user_info', $user_info); |
|
143 | + $invoice->set('first_name', $user_info['first_name']); |
|
144 | + $invoice->set('last_name', $user_info['last_name']); |
|
145 | + $invoice->set('address', $user_info['address']); |
|
146 | + $invoice->set('company', $user_info['company']); |
|
147 | + $invoice->set('vat_number', $user_info['vat_number']); |
|
148 | + $invoice->set('phone', $user_info['phone']); |
|
149 | + $invoice->set('city', $user_info['city']); |
|
150 | + $invoice->set('country', $user_info['country']); |
|
151 | + $invoice->set('state', $user_info['state']); |
|
152 | + $invoice->set('zip', $user_info['zip']); |
|
153 | + $invoice->set('discounts', $user_info['discount']); |
|
154 | + $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip())); |
|
155 | + if (!empty($invoice_data['invoice_key'])) { |
|
156 | + $invoice->set('key', $invoice_data['invoice_key']); |
|
157 | + } |
|
158 | + $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live')); |
|
159 | + $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : '')); |
|
160 | + |
|
161 | + if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) { |
|
162 | + foreach ($invoice_data['cart_details'] as $key => $item) { |
|
163 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
164 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
165 | + $name = !empty($item['name']) ? $item['name'] : ''; |
|
166 | + $item_price = isset($item['item_price']) ? $item['item_price'] : ''; |
|
167 | 167 | |
168 | - $post_item = new WPInv_Item( $item_id ); |
|
169 | - if ( !empty( $post_item ) ) { |
|
170 | - $name = !empty( $name ) ? $name : $post_item->get_name(); |
|
168 | + $post_item = new WPInv_Item($item_id); |
|
169 | + if (!empty($post_item)) { |
|
170 | + $name = !empty($name) ? $name : $post_item->get_name(); |
|
171 | 171 | $item_price = $item_price !== '' ? $item_price : $post_item->get_price(); |
172 | 172 | } else { |
173 | 173 | continue; |
@@ -177,494 +177,494 @@ discard block |
||
177 | 177 | 'name' => $name, |
178 | 178 | 'quantity' => $quantity, |
179 | 179 | 'item_price' => $item_price, |
180 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
181 | - 'tax' => !empty( $item['tax'] ) ? $item['tax'] : 0.00, |
|
182 | - 'discount' => isset( $item['discount'] ) ? $item['discount'] : 0, |
|
183 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
184 | - 'fees' => isset( $item['fees'] ) ? $item['fees'] : array(), |
|
180 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
181 | + 'tax' => !empty($item['tax']) ? $item['tax'] : 0.00, |
|
182 | + 'discount' => isset($item['discount']) ? $item['discount'] : 0, |
|
183 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
184 | + 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
|
185 | 185 | ); |
186 | 186 | |
187 | - $invoice->add_item( $item_id, $args ); |
|
187 | + $invoice->add_item($item_id, $args); |
|
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
191 | - $invoice->increase_tax( wpinv_get_cart_fee_tax() ); |
|
191 | + $invoice->increase_tax(wpinv_get_cart_fee_tax()); |
|
192 | 192 | |
193 | - if ( isset( $invoice_data['post_date'] ) ) { |
|
194 | - $invoice->set( 'date', $invoice_data['post_date'] ); |
|
193 | + if (isset($invoice_data['post_date'])) { |
|
194 | + $invoice->set('date', $invoice_data['post_date']); |
|
195 | 195 | } |
196 | 196 | |
197 | - $number = wpinv_format_invoice_number( $invoice->ID ); |
|
198 | - $invoice->set( 'number', $number ); |
|
199 | - update_option( 'wpinv_last_invoice_number', $number ); |
|
197 | + $number = wpinv_format_invoice_number($invoice->ID); |
|
198 | + $invoice->set('number', $number); |
|
199 | + update_option('wpinv_last_invoice_number', $number); |
|
200 | 200 | |
201 | 201 | $invoice->save(); |
202 | 202 | |
203 | 203 | // Add notes |
204 | - if ( !empty( $invoice_data['private_note'] ) ) { |
|
205 | - $invoice->add_note( $invoice_data['private_note'] ); |
|
204 | + if (!empty($invoice_data['private_note'])) { |
|
205 | + $invoice->add_note($invoice_data['private_note']); |
|
206 | 206 | } |
207 | - if ( !empty( $invoice_data['user_note'] ) ) { |
|
208 | - $invoice->add_note( $invoice_data['user_note'], true ); |
|
207 | + if (!empty($invoice_data['user_note'])) { |
|
208 | + $invoice->add_note($invoice_data['user_note'], true); |
|
209 | 209 | } |
210 | 210 | |
211 | - do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data ); |
|
211 | + do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data); |
|
212 | 212 | |
213 | - if ( ! empty( $invoice->ID ) ) { |
|
213 | + if (!empty($invoice->ID)) { |
|
214 | 214 | global $wpi_userID, $wpinv_ip_address_country; |
215 | 215 | |
216 | 216 | $checkout_session = wpinv_get_checkout_session(); |
217 | 217 | |
218 | 218 | $data_session = array(); |
219 | 219 | $data_session['invoice_id'] = $invoice->ID; |
220 | - $data_session['cart_discounts'] = $invoice->get_discounts( true ); |
|
220 | + $data_session['cart_discounts'] = $invoice->get_discounts(true); |
|
221 | 221 | |
222 | - wpinv_set_checkout_session( $data_session ); |
|
222 | + wpinv_set_checkout_session($data_session); |
|
223 | 223 | |
224 | 224 | $wpi_userID = (int)$invoice->get_user_id(); |
225 | 225 | |
226 | - $_POST['country'] = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country(); |
|
226 | + $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
|
227 | 227 | $_POST['state'] = $invoice->state; |
228 | 228 | |
229 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
230 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
229 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
230 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
231 | 231 | |
232 | 232 | $wpinv_ip_address_country = $invoice->country; |
233 | 233 | |
234 | - $invoice = $invoice->recalculate_totals( true ); |
|
234 | + $invoice = $invoice->recalculate_totals(true); |
|
235 | 235 | |
236 | - wpinv_set_checkout_session( $checkout_session ); |
|
236 | + wpinv_set_checkout_session($checkout_session); |
|
237 | 237 | |
238 | 238 | return $invoice; |
239 | 239 | } |
240 | 240 | |
241 | - if ( $wp_error ) { |
|
242 | - if ( is_wp_error( $invoice ) ) { |
|
241 | + if ($wp_error) { |
|
242 | + if (is_wp_error($invoice)) { |
|
243 | 243 | return $invoice; |
244 | 244 | } else { |
245 | - return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) ); |
|
245 | + return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing')); |
|
246 | 246 | } |
247 | 247 | } else { |
248 | 248 | return 0; |
249 | 249 | } |
250 | 250 | } |
251 | 251 | |
252 | -function wpinv_get_invoice( $invoice_id = 0, $cart = false ) { |
|
253 | - if ( $cart && empty( $invoice_id ) ) { |
|
252 | +function wpinv_get_invoice($invoice_id = 0, $cart = false) { |
|
253 | + if ($cart && empty($invoice_id)) { |
|
254 | 254 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
255 | 255 | } |
256 | 256 | |
257 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
257 | + $invoice = new WPInv_Invoice($invoice_id); |
|
258 | 258 | return $invoice; |
259 | 259 | } |
260 | 260 | |
261 | -function wpinv_get_invoice_cart( $invoice_id = 0 ) { |
|
262 | - return wpinv_get_invoice( $invoice_id, true ); |
|
261 | +function wpinv_get_invoice_cart($invoice_id = 0) { |
|
262 | + return wpinv_get_invoice($invoice_id, true); |
|
263 | 263 | } |
264 | 264 | |
265 | -function wpinv_get_invoice_description( $invoice_id = 0 ) { |
|
266 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
265 | +function wpinv_get_invoice_description($invoice_id = 0) { |
|
266 | + $invoice = new WPInv_Invoice($invoice_id); |
|
267 | 267 | return $invoice->get_description(); |
268 | 268 | } |
269 | 269 | |
270 | -function wpinv_get_invoice_currency_code( $invoice_id = 0 ) { |
|
271 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
270 | +function wpinv_get_invoice_currency_code($invoice_id = 0) { |
|
271 | + $invoice = new WPInv_Invoice($invoice_id); |
|
272 | 272 | return $invoice->get_currency(); |
273 | 273 | } |
274 | 274 | |
275 | -function wpinv_get_payment_user_email( $invoice_id ) { |
|
276 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
275 | +function wpinv_get_payment_user_email($invoice_id) { |
|
276 | + $invoice = new WPInv_Invoice($invoice_id); |
|
277 | 277 | return $invoice->get_email(); |
278 | 278 | } |
279 | 279 | |
280 | -function wpinv_get_user_id( $invoice_id ) { |
|
281 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
280 | +function wpinv_get_user_id($invoice_id) { |
|
281 | + $invoice = new WPInv_Invoice($invoice_id); |
|
282 | 282 | return $invoice->get_user_id(); |
283 | 283 | } |
284 | 284 | |
285 | -function wpinv_get_invoice_status( $invoice_id, $return_label = false ) { |
|
286 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
285 | +function wpinv_get_invoice_status($invoice_id, $return_label = false) { |
|
286 | + $invoice = new WPInv_Invoice($invoice_id); |
|
287 | 287 | |
288 | - return $invoice->get_status( $return_label ); |
|
288 | + return $invoice->get_status($return_label); |
|
289 | 289 | } |
290 | 290 | |
291 | -function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) { |
|
292 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
291 | +function wpinv_get_payment_gateway($invoice_id, $return_label = false) { |
|
292 | + $invoice = new WPInv_Invoice($invoice_id); |
|
293 | 293 | |
294 | - return $invoice->get_gateway( $return_label ); |
|
294 | + return $invoice->get_gateway($return_label); |
|
295 | 295 | } |
296 | 296 | |
297 | -function wpinv_get_payment_gateway_name( $invoice_id ) { |
|
298 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
297 | +function wpinv_get_payment_gateway_name($invoice_id) { |
|
298 | + $invoice = new WPInv_Invoice($invoice_id); |
|
299 | 299 | |
300 | 300 | return $invoice->get_gateway_title(); |
301 | 301 | } |
302 | 302 | |
303 | -function wpinv_get_payment_transaction_id( $invoice_id ) { |
|
304 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
303 | +function wpinv_get_payment_transaction_id($invoice_id) { |
|
304 | + $invoice = new WPInv_Invoice($invoice_id); |
|
305 | 305 | |
306 | 306 | return $invoice->get_transaction_id(); |
307 | 307 | } |
308 | 308 | |
309 | -function wpinv_get_id_by_transaction_id( $key ) { |
|
309 | +function wpinv_get_id_by_transaction_id($key) { |
|
310 | 310 | global $wpdb; |
311 | 311 | |
312 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) ); |
|
312 | + $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key)); |
|
313 | 313 | |
314 | - if ( $invoice_id != NULL ) |
|
314 | + if ($invoice_id != NULL) |
|
315 | 315 | return $invoice_id; |
316 | 316 | |
317 | 317 | return 0; |
318 | 318 | } |
319 | 319 | |
320 | -function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
321 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
320 | +function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) { |
|
321 | + $invoice = new WPInv_Invoice($invoice_id); |
|
322 | 322 | |
323 | - return $invoice->get_meta( $meta_key, $single ); |
|
323 | + return $invoice->get_meta($meta_key, $single); |
|
324 | 324 | } |
325 | 325 | |
326 | -function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
327 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
326 | +function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') { |
|
327 | + $invoice = new WPInv_Invoice($invoice_id); |
|
328 | 328 | |
329 | - return $invoice->update_meta( $meta_key, $meta_value, $prev_value ); |
|
329 | + return $invoice->update_meta($meta_key, $meta_value, $prev_value); |
|
330 | 330 | } |
331 | 331 | |
332 | -function wpinv_get_items( $invoice_id = 0 ) { |
|
333 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
332 | +function wpinv_get_items($invoice_id = 0) { |
|
333 | + $invoice = wpinv_get_invoice($invoice_id); |
|
334 | 334 | |
335 | 335 | $items = $invoice->get_items(); |
336 | 336 | $invoice_currency = $invoice->get_currency(); |
337 | 337 | |
338 | - if ( !empty( $items ) && is_array( $items ) ) { |
|
339 | - foreach ( $items as $key => $item ) { |
|
338 | + if (!empty($items) && is_array($items)) { |
|
339 | + foreach ($items as $key => $item) { |
|
340 | 340 | $items[$key]['currency'] = $invoice_currency; |
341 | 341 | |
342 | - if ( !isset( $cart_item['subtotal'] ) ) { |
|
342 | + if (!isset($cart_item['subtotal'])) { |
|
343 | 343 | $items[$key]['subtotal'] = $items[$key]['amount'] * 1; |
344 | 344 | } |
345 | 345 | } |
346 | 346 | } |
347 | 347 | |
348 | - return apply_filters( 'wpinv_get_items', $items, $invoice_id ); |
|
348 | + return apply_filters('wpinv_get_items', $items, $invoice_id); |
|
349 | 349 | } |
350 | 350 | |
351 | -function wpinv_get_fees( $invoice_id = 0 ) { |
|
352 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
351 | +function wpinv_get_fees($invoice_id = 0) { |
|
352 | + $invoice = wpinv_get_invoice($invoice_id); |
|
353 | 353 | $fees = $invoice->get_fees(); |
354 | 354 | |
355 | - return apply_filters( 'wpinv_get_fees', $fees, $invoice_id ); |
|
355 | + return apply_filters('wpinv_get_fees', $fees, $invoice_id); |
|
356 | 356 | } |
357 | 357 | |
358 | -function wpinv_get_invoice_ip( $invoice_id ) { |
|
359 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
358 | +function wpinv_get_invoice_ip($invoice_id) { |
|
359 | + $invoice = new WPInv_Invoice($invoice_id); |
|
360 | 360 | return $invoice->get_ip(); |
361 | 361 | } |
362 | 362 | |
363 | -function wpinv_get_invoice_user_info( $invoice_id ) { |
|
364 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
363 | +function wpinv_get_invoice_user_info($invoice_id) { |
|
364 | + $invoice = new WPInv_Invoice($invoice_id); |
|
365 | 365 | return $invoice->get_user_info(); |
366 | 366 | } |
367 | 367 | |
368 | -function wpinv_subtotal( $invoice_id = 0, $currency = false ) { |
|
369 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
368 | +function wpinv_subtotal($invoice_id = 0, $currency = false) { |
|
369 | + $invoice = new WPInv_Invoice($invoice_id); |
|
370 | 370 | |
371 | - return $invoice->get_subtotal( $currency ); |
|
371 | + return $invoice->get_subtotal($currency); |
|
372 | 372 | } |
373 | 373 | |
374 | -function wpinv_tax( $invoice_id = 0, $currency = false ) { |
|
375 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
374 | +function wpinv_tax($invoice_id = 0, $currency = false) { |
|
375 | + $invoice = new WPInv_Invoice($invoice_id); |
|
376 | 376 | |
377 | - return $invoice->get_tax( $currency ); |
|
377 | + return $invoice->get_tax($currency); |
|
378 | 378 | } |
379 | 379 | |
380 | -function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) { |
|
381 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
380 | +function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) { |
|
381 | + $invoice = wpinv_get_invoice($invoice_id); |
|
382 | 382 | |
383 | - return $invoice->get_discount( $currency, $dash ); |
|
383 | + return $invoice->get_discount($currency, $dash); |
|
384 | 384 | } |
385 | 385 | |
386 | -function wpinv_discount_code( $invoice_id = 0 ) { |
|
387 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
386 | +function wpinv_discount_code($invoice_id = 0) { |
|
387 | + $invoice = new WPInv_Invoice($invoice_id); |
|
388 | 388 | |
389 | 389 | return $invoice->get_discount_code(); |
390 | 390 | } |
391 | 391 | |
392 | -function wpinv_payment_total( $invoice_id = 0, $currency = false ) { |
|
393 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
392 | +function wpinv_payment_total($invoice_id = 0, $currency = false) { |
|
393 | + $invoice = new WPInv_Invoice($invoice_id); |
|
394 | 394 | |
395 | - return $invoice->get_total( $currency ); |
|
395 | + return $invoice->get_total($currency); |
|
396 | 396 | } |
397 | 397 | |
398 | -function wpinv_get_date_created( $invoice_id = 0 ) { |
|
399 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
398 | +function wpinv_get_date_created($invoice_id = 0) { |
|
399 | + $invoice = new WPInv_Invoice($invoice_id); |
|
400 | 400 | |
401 | 401 | $date_created = $invoice->get_created_date(); |
402 | - $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ), strtotime( $date_created ) ) : ''; |
|
402 | + $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format'), strtotime($date_created)) : ''; |
|
403 | 403 | |
404 | 404 | return $date_created; |
405 | 405 | } |
406 | 406 | |
407 | -function wpinv_get_invoice_date( $invoice_id = 0, $format = '' ) { |
|
408 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
407 | +function wpinv_get_invoice_date($invoice_id = 0, $format = '') { |
|
408 | + $invoice = new WPInv_Invoice($invoice_id); |
|
409 | 409 | |
410 | - $format = !empty( $format ) ? $format : get_option( 'date_format' ); |
|
410 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
411 | 411 | $date_completed = $invoice->get_completed_date(); |
412 | - $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : ''; |
|
413 | - if ( $invoice_date == '' ) { |
|
412 | + $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : ''; |
|
413 | + if ($invoice_date == '') { |
|
414 | 414 | $date_created = $invoice->get_created_date(); |
415 | - $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : ''; |
|
415 | + $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : ''; |
|
416 | 416 | } |
417 | 417 | |
418 | 418 | return $invoice_date; |
419 | 419 | } |
420 | 420 | |
421 | -function wpinv_get_invoice_vat_number( $invoice_id = 0 ) { |
|
422 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
421 | +function wpinv_get_invoice_vat_number($invoice_id = 0) { |
|
422 | + $invoice = new WPInv_Invoice($invoice_id); |
|
423 | 423 | |
424 | 424 | return $invoice->vat_number; |
425 | 425 | } |
426 | 426 | |
427 | -function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false ) { |
|
428 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
427 | +function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false) { |
|
428 | + $invoice = new WPInv_Invoice($invoice_id); |
|
429 | 429 | |
430 | - return $invoice->add_note( $note, $user_type, $added_by_user ); |
|
430 | + return $invoice->add_note($note, $user_type, $added_by_user); |
|
431 | 431 | } |
432 | 432 | |
433 | -function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) { |
|
433 | +function wpinv_get_invoice_notes($invoice_id = 0, $type = '') { |
|
434 | 434 | global $invoicing; |
435 | 435 | |
436 | - if ( empty( $invoice_id ) ) { |
|
436 | + if (empty($invoice_id)) { |
|
437 | 437 | return NULL; |
438 | 438 | } |
439 | 439 | |
440 | - $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type ); |
|
440 | + $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type); |
|
441 | 441 | |
442 | - return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type ); |
|
442 | + return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type); |
|
443 | 443 | } |
444 | 444 | |
445 | -function wpinv_get_payment_key( $invoice_id = 0 ) { |
|
446 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
445 | +function wpinv_get_payment_key($invoice_id = 0) { |
|
446 | + $invoice = new WPInv_Invoice($invoice_id); |
|
447 | 447 | return $invoice->get_key(); |
448 | 448 | } |
449 | 449 | |
450 | -function wpinv_get_invoice_number( $invoice_id = 0 ) { |
|
451 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
450 | +function wpinv_get_invoice_number($invoice_id = 0) { |
|
451 | + $invoice = new WPInv_Invoice($invoice_id); |
|
452 | 452 | return $invoice->get_number(); |
453 | 453 | } |
454 | 454 | |
455 | -function wpinv_get_cart_discountable_subtotal( $code_id ) { |
|
455 | +function wpinv_get_cart_discountable_subtotal($code_id) { |
|
456 | 456 | $cart_items = wpinv_get_cart_content_details(); |
457 | 457 | $items = array(); |
458 | 458 | |
459 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
459 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
460 | 460 | |
461 | - if( $cart_items ) { |
|
461 | + if ($cart_items) { |
|
462 | 462 | |
463 | - foreach( $cart_items as $item ) { |
|
463 | + foreach ($cart_items as $item) { |
|
464 | 464 | |
465 | - if( ! in_array( $item['id'], $excluded_items ) ) { |
|
466 | - $items[] = $item; |
|
465 | + if (!in_array($item['id'], $excluded_items)) { |
|
466 | + $items[] = $item; |
|
467 | 467 | } |
468 | 468 | } |
469 | 469 | } |
470 | 470 | |
471 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
471 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
472 | 472 | |
473 | - return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal ); |
|
473 | + return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal); |
|
474 | 474 | } |
475 | 475 | |
476 | -function wpinv_get_cart_items_subtotal( $items ) { |
|
476 | +function wpinv_get_cart_items_subtotal($items) { |
|
477 | 477 | $subtotal = 0.00; |
478 | 478 | |
479 | - if ( is_array( $items ) && ! empty( $items ) ) { |
|
480 | - $prices = wp_list_pluck( $items, 'subtotal' ); |
|
479 | + if (is_array($items) && !empty($items)) { |
|
480 | + $prices = wp_list_pluck($items, 'subtotal'); |
|
481 | 481 | |
482 | - if( is_array( $prices ) ) { |
|
483 | - $subtotal = array_sum( $prices ); |
|
482 | + if (is_array($prices)) { |
|
483 | + $subtotal = array_sum($prices); |
|
484 | 484 | } else { |
485 | 485 | $subtotal = 0.00; |
486 | 486 | } |
487 | 487 | |
488 | - if( $subtotal < 0 ) { |
|
488 | + if ($subtotal < 0) { |
|
489 | 489 | $subtotal = 0.00; |
490 | 490 | } |
491 | 491 | } |
492 | 492 | |
493 | - return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal ); |
|
493 | + return apply_filters('wpinv_get_cart_items_subtotal', $subtotal); |
|
494 | 494 | } |
495 | 495 | |
496 | -function wpinv_get_cart_subtotal( $items = array() ) { |
|
497 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
498 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
496 | +function wpinv_get_cart_subtotal($items = array()) { |
|
497 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
498 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
499 | 499 | |
500 | - return apply_filters( 'wpinv_get_cart_subtotal', $subtotal ); |
|
500 | + return apply_filters('wpinv_get_cart_subtotal', $subtotal); |
|
501 | 501 | } |
502 | 502 | |
503 | -function wpinv_cart_subtotal( $items = array() ) { |
|
504 | - $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ) ); |
|
503 | +function wpinv_cart_subtotal($items = array()) { |
|
504 | + $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items))); |
|
505 | 505 | |
506 | 506 | return $price; |
507 | 507 | } |
508 | 508 | |
509 | -function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) { |
|
510 | - $subtotal = (float)wpinv_get_cart_subtotal( $items ); |
|
511 | - $discounts = (float)wpinv_get_cart_discounted_amount( $items ); |
|
512 | - $cart_tax = (float)wpinv_get_cart_tax( $items ); |
|
509 | +function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) { |
|
510 | + $subtotal = (float)wpinv_get_cart_subtotal($items); |
|
511 | + $discounts = (float)wpinv_get_cart_discounted_amount($items); |
|
512 | + $cart_tax = (float)wpinv_get_cart_tax($items); |
|
513 | 513 | $fees = (float)wpinv_get_cart_fee_total(); |
514 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
514 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
515 | 515 | $total = 0; |
516 | 516 | } else { |
517 | - $total = $subtotal - $discounts + $cart_tax + $fees; |
|
517 | + $total = $subtotal - $discounts + $cart_tax + $fees; |
|
518 | 518 | } |
519 | 519 | |
520 | - if ( $total < 0 ) { |
|
520 | + if ($total < 0) { |
|
521 | 521 | $total = 0.00; |
522 | 522 | } |
523 | 523 | |
524 | - $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items ); |
|
524 | + $total = (float)apply_filters('wpinv_get_cart_total', $total, $items); |
|
525 | 525 | |
526 | - return wpinv_sanitize_amount( $total ); |
|
526 | + return wpinv_sanitize_amount($total); |
|
527 | 527 | } |
528 | 528 | |
529 | -function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) { |
|
529 | +function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) { |
|
530 | 530 | global $cart_total; |
531 | - $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ) ); |
|
532 | - $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice ); |
|
531 | + $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice))); |
|
532 | + $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice); |
|
533 | 533 | |
534 | 534 | $cart_total = $total; |
535 | 535 | |
536 | - if ( !$echo ) { |
|
536 | + if (!$echo) { |
|
537 | 537 | return $total; |
538 | 538 | } |
539 | 539 | |
540 | 540 | echo $total; |
541 | 541 | } |
542 | 542 | |
543 | -function wpinv_get_cart_tax( $items = array() ) { |
|
543 | +function wpinv_get_cart_tax($items = array()) { |
|
544 | 544 | $cart_tax = 0; |
545 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
545 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
546 | 546 | |
547 | - if ( $items ) { |
|
548 | - $taxes = wp_list_pluck( $items, 'tax' ); |
|
547 | + if ($items) { |
|
548 | + $taxes = wp_list_pluck($items, 'tax'); |
|
549 | 549 | |
550 | - if( is_array( $taxes ) ) { |
|
551 | - $cart_tax = array_sum( $taxes ); |
|
550 | + if (is_array($taxes)) { |
|
551 | + $cart_tax = array_sum($taxes); |
|
552 | 552 | } |
553 | 553 | } |
554 | 554 | |
555 | 555 | $cart_tax += wpinv_get_cart_fee_tax(); |
556 | 556 | |
557 | - return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) ); |
|
557 | + return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax)); |
|
558 | 558 | } |
559 | 559 | |
560 | -function wpinv_cart_tax( $items = array(), $echo = false ) { |
|
561 | - $cart_tax = wpinv_get_cart_tax( $items ); |
|
562 | - $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ) ); |
|
560 | +function wpinv_cart_tax($items = array(), $echo = false) { |
|
561 | + $cart_tax = wpinv_get_cart_tax($items); |
|
562 | + $cart_tax = wpinv_price(wpinv_format_amount($cart_tax)); |
|
563 | 563 | |
564 | - $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items ); |
|
564 | + $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items); |
|
565 | 565 | |
566 | - if ( !$echo ) { |
|
566 | + if (!$echo) { |
|
567 | 567 | return $tax; |
568 | 568 | } |
569 | 569 | |
570 | 570 | echo $tax; |
571 | 571 | } |
572 | 572 | |
573 | -function wpinv_get_cart_discount_code( $items = array() ) { |
|
573 | +function wpinv_get_cart_discount_code($items = array()) { |
|
574 | 574 | $invoice = wpinv_get_invoice_cart(); |
575 | - $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : ''; |
|
575 | + $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : ''; |
|
576 | 576 | |
577 | - return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code ); |
|
577 | + return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code); |
|
578 | 578 | } |
579 | 579 | |
580 | -function wpinv_cart_discount_code( $items = array(), $echo = false ) { |
|
581 | - $cart_discount_code = wpinv_get_cart_discount_code( $items ); |
|
580 | +function wpinv_cart_discount_code($items = array(), $echo = false) { |
|
581 | + $cart_discount_code = wpinv_get_cart_discount_code($items); |
|
582 | 582 | |
583 | - if ( $cart_discount_code != '' ) { |
|
583 | + if ($cart_discount_code != '') { |
|
584 | 584 | $cart_discount_code = ' (' . $cart_discount_code . ')'; |
585 | 585 | } |
586 | 586 | |
587 | - $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items ); |
|
587 | + $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items); |
|
588 | 588 | |
589 | - if ( !$echo ) { |
|
589 | + if (!$echo) { |
|
590 | 590 | return $discount_code; |
591 | 591 | } |
592 | 592 | |
593 | 593 | echo $discount_code; |
594 | 594 | } |
595 | 595 | |
596 | -function wpinv_get_cart_discount( $items = array() ) { |
|
596 | +function wpinv_get_cart_discount($items = array()) { |
|
597 | 597 | $invoice = wpinv_get_invoice_cart(); |
598 | - $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0; |
|
598 | + $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0; |
|
599 | 599 | |
600 | - return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items ); |
|
600 | + return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items); |
|
601 | 601 | } |
602 | 602 | |
603 | -function wpinv_cart_discount( $items = array(), $echo = false ) { |
|
604 | - $cart_discount = wpinv_get_cart_discount( $items ); |
|
605 | - $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) ); |
|
603 | +function wpinv_cart_discount($items = array(), $echo = false) { |
|
604 | + $cart_discount = wpinv_get_cart_discount($items); |
|
605 | + $cart_discount = wpinv_price(wpinv_format_amount($cart_discount)); |
|
606 | 606 | |
607 | - $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items ); |
|
607 | + $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items); |
|
608 | 608 | |
609 | - if ( !$echo ) { |
|
609 | + if (!$echo) { |
|
610 | 610 | return $discount; |
611 | 611 | } |
612 | 612 | |
613 | 613 | echo $discount; |
614 | 614 | } |
615 | 615 | |
616 | -function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) { |
|
617 | - $item = new WPInv_Item( $item_id ); |
|
616 | +function wpinv_get_cart_fees($type = 'all', $item_id = 0) { |
|
617 | + $item = new WPInv_Item($item_id); |
|
618 | 618 | |
619 | - return $item->get_fees( $type, $item_id ); |
|
619 | + return $item->get_fees($type, $item_id); |
|
620 | 620 | } |
621 | 621 | |
622 | 622 | function wpinv_get_cart_fee_total() { |
623 | - $total = 0; |
|
623 | + $total = 0; |
|
624 | 624 | $fees = wpinv_get_cart_fees(); |
625 | 625 | |
626 | - if ( $fees ) { |
|
627 | - foreach ( $fees as $fee_id => $fee ) { |
|
626 | + if ($fees) { |
|
627 | + foreach ($fees as $fee_id => $fee) { |
|
628 | 628 | $total += $fee['amount']; |
629 | 629 | } |
630 | 630 | } |
631 | 631 | |
632 | - return apply_filters( 'wpinv_get_cart_fee_total', $total ); |
|
632 | + return apply_filters('wpinv_get_cart_fee_total', $total); |
|
633 | 633 | } |
634 | 634 | |
635 | 635 | function wpinv_get_cart_fee_tax() { |
636 | 636 | $tax = 0; |
637 | 637 | $fees = wpinv_get_cart_fees(); |
638 | 638 | |
639 | - if ( $fees ) { |
|
640 | - foreach ( $fees as $fee_id => $fee ) { |
|
641 | - if( ! empty( $fee['no_tax'] ) ) { |
|
639 | + if ($fees) { |
|
640 | + foreach ($fees as $fee_id => $fee) { |
|
641 | + if (!empty($fee['no_tax'])) { |
|
642 | 642 | continue; |
643 | 643 | } |
644 | 644 | |
645 | - $tax += wpinv_calculate_tax( $fee['amount'] ); |
|
645 | + $tax += wpinv_calculate_tax($fee['amount']); |
|
646 | 646 | } |
647 | 647 | } |
648 | 648 | |
649 | - return apply_filters( 'wpinv_get_cart_fee_tax', $tax ); |
|
649 | + return apply_filters('wpinv_get_cart_fee_tax', $tax); |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | function wpinv_cart_has_recurring_item() { |
653 | 653 | $cart_items = wpinv_get_cart_contents(); |
654 | 654 | |
655 | - if ( empty( $cart_items ) ) { |
|
655 | + if (empty($cart_items)) { |
|
656 | 656 | return false; |
657 | 657 | } |
658 | 658 | |
659 | 659 | $has_subscription = false; |
660 | - foreach( $cart_items as $cart_item ) { |
|
661 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
660 | + foreach ($cart_items as $cart_item) { |
|
661 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
662 | 662 | $has_subscription = true; |
663 | 663 | break; |
664 | 664 | } |
665 | 665 | } |
666 | 666 | |
667 | - return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items ); |
|
667 | + return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items); |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | function wpinv_cart_has_free_trial() { |
@@ -672,94 +672,94 @@ discard block |
||
672 | 672 | |
673 | 673 | $free_trial = false; |
674 | 674 | |
675 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
675 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
676 | 676 | $free_trial = true; |
677 | 677 | } |
678 | 678 | |
679 | - return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice ); |
|
679 | + return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice); |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | function wpinv_get_cart_contents() { |
683 | 683 | $cart_details = wpinv_get_cart_details(); |
684 | 684 | |
685 | - return apply_filters( 'wpinv_get_cart_contents', $cart_details ); |
|
685 | + return apply_filters('wpinv_get_cart_contents', $cart_details); |
|
686 | 686 | } |
687 | 687 | |
688 | 688 | function wpinv_get_cart_content_details() { |
689 | 689 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
690 | 690 | $cart_items = wpinv_get_cart_contents(); |
691 | 691 | |
692 | - if ( empty( $cart_items ) ) { |
|
692 | + if (empty($cart_items)) { |
|
693 | 693 | return false; |
694 | 694 | } |
695 | 695 | $invoice = wpinv_get_invoice_cart(); |
696 | 696 | |
697 | 697 | $details = array(); |
698 | - $length = count( $cart_items ) - 1; |
|
698 | + $length = count($cart_items) - 1; |
|
699 | 699 | |
700 | - if ( empty( $_POST['country'] ) ) { |
|
700 | + if (empty($_POST['country'])) { |
|
701 | 701 | $_POST['country'] = $invoice->country; |
702 | 702 | } |
703 | - if ( !isset( $_POST['state'] ) ) { |
|
703 | + if (!isset($_POST['state'])) { |
|
704 | 704 | $_POST['state'] = $invoice->state; |
705 | 705 | } |
706 | 706 | |
707 | - foreach( $cart_items as $key => $item ) { |
|
708 | - $item_id = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : ''; |
|
709 | - if ( empty( $item_id ) ) { |
|
707 | + foreach ($cart_items as $key => $item) { |
|
708 | + $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : ''; |
|
709 | + if (empty($item_id)) { |
|
710 | 710 | continue; |
711 | 711 | } |
712 | 712 | |
713 | 713 | $wpi_current_id = $invoice->ID; |
714 | 714 | $wpi_item_id = $item_id; |
715 | 715 | |
716 | - if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) { |
|
716 | + if (isset($item['custom_price']) && $item['custom_price'] !== '') { |
|
717 | 717 | $item_price = $item['custom_price']; |
718 | 718 | } else { |
719 | - if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) { |
|
719 | + if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) { |
|
720 | 720 | $item_price = $item['item_price']; |
721 | 721 | } else { |
722 | - $item_price = wpinv_get_item_price( $item_id ); |
|
722 | + $item_price = wpinv_get_item_price($item_id); |
|
723 | 723 | } |
724 | 724 | } |
725 | - $discount = wpinv_get_cart_item_discount_amount( $item ); |
|
726 | - $discount = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item ); |
|
727 | - $quantity = wpinv_get_cart_item_quantity( $item ); |
|
728 | - $fees = wpinv_get_cart_fees( 'fee', $item_id ); |
|
725 | + $discount = wpinv_get_cart_item_discount_amount($item); |
|
726 | + $discount = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item); |
|
727 | + $quantity = wpinv_get_cart_item_quantity($item); |
|
728 | + $fees = wpinv_get_cart_fees('fee', $item_id); |
|
729 | 729 | |
730 | 730 | $subtotal = $item_price * $quantity; |
731 | - $tax_rate = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id ); |
|
732 | - $tax_class = $wpinv_euvat->get_item_class( $item_id ); |
|
733 | - $tax = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount ); |
|
731 | + $tax_rate = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id); |
|
732 | + $tax_class = $wpinv_euvat->get_item_class($item_id); |
|
733 | + $tax = wpinv_get_cart_item_tax($item_id, $subtotal - $discount); |
|
734 | 734 | |
735 | - if ( wpinv_prices_include_tax() ) { |
|
736 | - $subtotal -= wpinv_round_amount( $tax ); |
|
735 | + if (wpinv_prices_include_tax()) { |
|
736 | + $subtotal -= wpinv_round_amount($tax); |
|
737 | 737 | } |
738 | 738 | |
739 | - $total = $subtotal - $discount + $tax; |
|
739 | + $total = $subtotal - $discount + $tax; |
|
740 | 740 | |
741 | 741 | // Do not allow totals to go negatve |
742 | - if( $total < 0 ) { |
|
742 | + if ($total < 0) { |
|
743 | 743 | $total = 0; |
744 | 744 | } |
745 | 745 | |
746 | - $details[ $key ] = array( |
|
746 | + $details[$key] = array( |
|
747 | 747 | 'id' => $item_id, |
748 | - 'name' => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ), |
|
749 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
750 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
748 | + 'name' => !empty($item['name']) ? $item['name'] : get_the_title($item_id), |
|
749 | + 'item_price' => wpinv_round_amount($item_price), |
|
750 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
751 | 751 | 'quantity' => $quantity, |
752 | - 'discount' => wpinv_round_amount( $discount ), |
|
753 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
754 | - 'tax' => wpinv_round_amount( $tax ), |
|
755 | - 'price' => wpinv_round_amount( $total ), |
|
752 | + 'discount' => wpinv_round_amount($discount), |
|
753 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
754 | + 'tax' => wpinv_round_amount($tax), |
|
755 | + 'price' => wpinv_round_amount($total), |
|
756 | 756 | 'vat_rates_class' => $tax_class, |
757 | 757 | 'vat_rate' => $tax_rate, |
758 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
758 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
759 | 759 | 'fees' => $fees, |
760 | 760 | ); |
761 | 761 | |
762 | - if ( $wpinv_is_last_cart_item ) { |
|
762 | + if ($wpinv_is_last_cart_item) { |
|
763 | 763 | $wpinv_is_last_cart_item = false; |
764 | 764 | $wpinv_flat_discount_total = 0.00; |
765 | 765 | } |
@@ -768,60 +768,60 @@ discard block |
||
768 | 768 | return $details; |
769 | 769 | } |
770 | 770 | |
771 | -function wpinv_get_cart_details( $invoice_id = 0 ) { |
|
771 | +function wpinv_get_cart_details($invoice_id = 0) { |
|
772 | 772 | global $ajax_cart_details; |
773 | 773 | |
774 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
775 | - $cart_details = !empty( $ajax_cart_details ) ? $ajax_cart_details : $invoice->cart_details; |
|
774 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
775 | + $cart_details = !empty($ajax_cart_details) ? $ajax_cart_details : $invoice->cart_details; |
|
776 | 776 | |
777 | 777 | $invoice_currency = $invoice->currency; |
778 | 778 | |
779 | - if ( ! empty( $cart_details ) && is_array( $cart_details ) ) { |
|
780 | - foreach ( $cart_details as $key => $cart_item ) { |
|
781 | - $cart_details[ $key ]['currency'] = $invoice_currency; |
|
779 | + if (!empty($cart_details) && is_array($cart_details)) { |
|
780 | + foreach ($cart_details as $key => $cart_item) { |
|
781 | + $cart_details[$key]['currency'] = $invoice_currency; |
|
782 | 782 | |
783 | - if ( ! isset( $cart_item['subtotal'] ) ) { |
|
784 | - $cart_details[ $key ]['subtotal'] = $cart_item['price']; |
|
783 | + if (!isset($cart_item['subtotal'])) { |
|
784 | + $cart_details[$key]['subtotal'] = $cart_item['price']; |
|
785 | 785 | } |
786 | 786 | } |
787 | 787 | } |
788 | 788 | |
789 | - return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id ); |
|
789 | + return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id); |
|
790 | 790 | } |
791 | 791 | |
792 | -function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) { |
|
793 | - if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) { |
|
792 | +function wpinv_record_status_change($invoice_id, $new_status, $old_status) { |
|
793 | + if ('wpi_invoice' != get_post_type($invoice_id)) { |
|
794 | 794 | return; |
795 | 795 | } |
796 | 796 | |
797 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
797 | + $invoice = wpinv_get_invoice($invoice_id); |
|
798 | 798 | |
799 | - $old_status = wpinv_status_nicename( $old_status ); |
|
800 | - $new_status = wpinv_status_nicename( $new_status ); |
|
799 | + $old_status = wpinv_status_nicename($old_status); |
|
800 | + $new_status = wpinv_status_nicename($new_status); |
|
801 | 801 | |
802 | - $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status ); |
|
802 | + $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status); |
|
803 | 803 | |
804 | 804 | // Add note |
805 | - return $invoice->add_note( $status_change, false, false, true ); |
|
805 | + return $invoice->add_note($status_change, false, false, true); |
|
806 | 806 | } |
807 | -add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 ); |
|
807 | +add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3); |
|
808 | 808 | |
809 | -function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) { |
|
809 | +function wpinv_complete_payment($invoice_id, $new_status, $old_status) { |
|
810 | 810 | global $wpi_has_free_trial; |
811 | 811 | |
812 | 812 | $wpi_has_free_trial = false; |
813 | 813 | |
814 | - if ( $old_status == 'publish' ) { |
|
814 | + if ($old_status == 'publish') { |
|
815 | 815 | return; // Make sure that payments are only paid once |
816 | 816 | } |
817 | 817 | |
818 | 818 | // Make sure the payment completion is only processed when new status is paid |
819 | - if ( $new_status != 'publish' ) { |
|
819 | + if ($new_status != 'publish') { |
|
820 | 820 | return; |
821 | 821 | } |
822 | 822 | |
823 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
824 | - if ( empty( $invoice ) ) { |
|
823 | + $invoice = new WPInv_Invoice($invoice_id); |
|
824 | + if (empty($invoice)) { |
|
825 | 825 | return; |
826 | 826 | } |
827 | 827 | |
@@ -829,58 +829,58 @@ discard block |
||
829 | 829 | $completed_date = $invoice->completed_date; |
830 | 830 | $cart_details = $invoice->cart_details; |
831 | 831 | |
832 | - do_action( 'wpinv_pre_complete_payment', $invoice_id ); |
|
832 | + do_action('wpinv_pre_complete_payment', $invoice_id); |
|
833 | 833 | |
834 | - if ( is_array( $cart_details ) ) { |
|
834 | + if (is_array($cart_details)) { |
|
835 | 835 | // Increase purchase count and earnings |
836 | - foreach ( $cart_details as $cart_index => $item ) { |
|
836 | + foreach ($cart_details as $cart_index => $item) { |
|
837 | 837 | // Ensure these actions only run once, ever |
838 | - if ( empty( $completed_date ) ) { |
|
839 | - do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index ); |
|
838 | + if (empty($completed_date)) { |
|
839 | + do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index); |
|
840 | 840 | } |
841 | 841 | } |
842 | 842 | } |
843 | 843 | |
844 | 844 | // Check for discount codes and increment their use counts |
845 | - if ( $discounts = $invoice->get_discounts( true ) ) { |
|
846 | - if( ! empty( $discounts ) ) { |
|
847 | - foreach( $discounts as $code ) { |
|
848 | - wpinv_increase_discount_usage( $code ); |
|
845 | + if ($discounts = $invoice->get_discounts(true)) { |
|
846 | + if (!empty($discounts)) { |
|
847 | + foreach ($discounts as $code) { |
|
848 | + wpinv_increase_discount_usage($code); |
|
849 | 849 | } |
850 | 850 | } |
851 | 851 | } |
852 | 852 | |
853 | 853 | // Ensure this action only runs once ever |
854 | - if( empty( $completed_date ) ) { |
|
854 | + if (empty($completed_date)) { |
|
855 | 855 | // Save the completed date |
856 | - $invoice->set( 'completed_date', current_time( 'mysql', 0 ) ); |
|
856 | + $invoice->set('completed_date', current_time('mysql', 0)); |
|
857 | 857 | $invoice->save(); |
858 | 858 | |
859 | - do_action( 'wpinv_complete_payment', $invoice_id ); |
|
859 | + do_action('wpinv_complete_payment', $invoice_id); |
|
860 | 860 | } |
861 | 861 | |
862 | 862 | // Empty the shopping cart |
863 | 863 | wpinv_empty_cart(); |
864 | 864 | } |
865 | -add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 ); |
|
865 | +add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3); |
|
866 | 866 | |
867 | -function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) { |
|
868 | - $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id ); |
|
867 | +function wpinv_update_payment_status($invoice_id, $new_status = 'publish') { |
|
868 | + $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int)$invoice_id); |
|
869 | 869 | |
870 | - if ( empty( $invoice ) ) { |
|
870 | + if (empty($invoice)) { |
|
871 | 871 | return false; |
872 | 872 | } |
873 | 873 | |
874 | - return $invoice->update_status( $new_status ); |
|
874 | + return $invoice->update_status($new_status); |
|
875 | 875 | } |
876 | 876 | |
877 | -function wpinv_cart_has_fees( $type = 'all' ) { |
|
877 | +function wpinv_cart_has_fees($type = 'all') { |
|
878 | 878 | return false; |
879 | 879 | } |
880 | 880 | |
881 | 881 | function wpinv_validate_checkout_fields() { |
882 | 882 | // Check if there is $_POST |
883 | - if ( empty( $_POST ) ) { |
|
883 | + if (empty($_POST)) { |
|
884 | 884 | return false; |
885 | 885 | } |
886 | 886 | |
@@ -892,11 +892,11 @@ discard block |
||
892 | 892 | ); |
893 | 893 | |
894 | 894 | // Validate agree to terms |
895 | - if ( wpinv_get_option( 'show_agree_to_terms', false ) ) { |
|
895 | + if (wpinv_get_option('show_agree_to_terms', false)) { |
|
896 | 896 | wpinv_checkout_validate_agree_to_terms(); |
897 | 897 | } |
898 | 898 | |
899 | - $valid_data['logged_in_user'] = wpinv_checkout_validate_logged_in_user(); |
|
899 | + $valid_data['logged_in_user'] = wpinv_checkout_validate_logged_in_user(); |
|
900 | 900 | |
901 | 901 | // Return collected data |
902 | 902 | return $valid_data; |
@@ -907,26 +907,26 @@ discard block |
||
907 | 907 | |
908 | 908 | $invoice = wpinv_get_invoice_cart(); |
909 | 909 | $has_subscription = $invoice->is_recurring(); |
910 | - if ( empty( $invoice ) ) { |
|
911 | - wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) ); |
|
910 | + if (empty($invoice)) { |
|
911 | + wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing')); |
|
912 | 912 | return $gateway; |
913 | 913 | } |
914 | 914 | |
915 | 915 | // Check if a gateway value is present |
916 | - if ( !empty( $_REQUEST['wpi-gateway'] ) ) { |
|
917 | - $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] ); |
|
916 | + if (!empty($_REQUEST['wpi-gateway'])) { |
|
917 | + $gateway = sanitize_text_field($_REQUEST['wpi-gateway']); |
|
918 | 918 | |
919 | - if ( $invoice->is_free() ) { |
|
919 | + if ($invoice->is_free()) { |
|
920 | 920 | $gateway = 'manual'; |
921 | - } elseif ( !wpinv_is_gateway_active( $gateway ) ) { |
|
922 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) ); |
|
923 | - } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) { |
|
924 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway doesnot support subscription payment', 'invoicing' ) ); |
|
921 | + } elseif (!wpinv_is_gateway_active($gateway)) { |
|
922 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing')); |
|
923 | + } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) { |
|
924 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway doesnot support subscription payment', 'invoicing')); |
|
925 | 925 | } |
926 | 926 | } |
927 | 927 | |
928 | - if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) { |
|
929 | - wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) ); |
|
928 | + if ($has_subscription && count(wpinv_get_cart_contents()) > 1) { |
|
929 | + wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing')); |
|
930 | 930 | } |
931 | 931 | |
932 | 932 | return $gateway; |
@@ -938,10 +938,10 @@ discard block |
||
938 | 938 | |
939 | 939 | $error = false; |
940 | 940 | // If we have discounts, loop through them |
941 | - if ( ! empty( $discounts ) ) { |
|
942 | - foreach ( $discounts as $discount ) { |
|
941 | + if (!empty($discounts)) { |
|
942 | + foreach ($discounts as $discount) { |
|
943 | 943 | // Check if valid |
944 | - if ( !wpinv_is_discount_valid( $discount, get_current_user_id() ) ) { |
|
944 | + if (!wpinv_is_discount_valid($discount, get_current_user_id())) { |
|
945 | 945 | // Discount is not valid |
946 | 946 | $error = true; |
947 | 947 | } |
@@ -951,20 +951,20 @@ discard block |
||
951 | 951 | return NULL; |
952 | 952 | } |
953 | 953 | |
954 | - if ( $error && !wpinv_get_errors() ) { |
|
955 | - wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) ); |
|
954 | + if ($error && !wpinv_get_errors()) { |
|
955 | + wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing')); |
|
956 | 956 | } |
957 | 957 | |
958 | - return implode( ',', $discounts ); |
|
958 | + return implode(',', $discounts); |
|
959 | 959 | } |
960 | 960 | |
961 | 961 | function wpinv_checkout_validate_cc() { |
962 | 962 | $card_data = wpinv_checkout_get_cc_info(); |
963 | 963 | |
964 | 964 | // Validate the card zip |
965 | - if ( !empty( $card_data['wpinv_zip'] ) ) { |
|
966 | - if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) { |
|
967 | - wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) ); |
|
965 | + if (!empty($card_data['wpinv_zip'])) { |
|
966 | + if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) { |
|
967 | + wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing')); |
|
968 | 968 | } |
969 | 969 | } |
970 | 970 | |
@@ -974,28 +974,28 @@ discard block |
||
974 | 974 | |
975 | 975 | function wpinv_checkout_get_cc_info() { |
976 | 976 | $cc_info = array(); |
977 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
978 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
979 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
980 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
981 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
982 | - $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
983 | - $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
984 | - $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
985 | - $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
986 | - $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
977 | + $cc_info['card_name'] = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : ''; |
|
978 | + $cc_info['card_number'] = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : ''; |
|
979 | + $cc_info['card_cvc'] = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : ''; |
|
980 | + $cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : ''; |
|
981 | + $cc_info['card_exp_year'] = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : ''; |
|
982 | + $cc_info['card_address'] = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : ''; |
|
983 | + $cc_info['card_city'] = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : ''; |
|
984 | + $cc_info['card_state'] = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : ''; |
|
985 | + $cc_info['card_country'] = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : ''; |
|
986 | + $cc_info['card_zip'] = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : ''; |
|
987 | 987 | |
988 | 988 | // Return cc info |
989 | 989 | return $cc_info; |
990 | 990 | } |
991 | 991 | |
992 | -function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
992 | +function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') { |
|
993 | 993 | $ret = false; |
994 | 994 | |
995 | - if ( empty( $zip ) || empty( $country_code ) ) |
|
995 | + if (empty($zip) || empty($country_code)) |
|
996 | 996 | return $ret; |
997 | 997 | |
998 | - $country_code = strtoupper( $country_code ); |
|
998 | + $country_code = strtoupper($country_code); |
|
999 | 999 | |
1000 | 1000 | $zip_regex = array( |
1001 | 1001 | "AD" => "AD\d{3}", |
@@ -1155,17 +1155,17 @@ discard block |
||
1155 | 1155 | "ZM" => "\d{5}" |
1156 | 1156 | ); |
1157 | 1157 | |
1158 | - if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) |
|
1158 | + if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip)) |
|
1159 | 1159 | $ret = true; |
1160 | 1160 | |
1161 | - return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code ); |
|
1161 | + return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code); |
|
1162 | 1162 | } |
1163 | 1163 | |
1164 | 1164 | function wpinv_checkout_validate_agree_to_terms() { |
1165 | 1165 | // Validate agree to terms |
1166 | - if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) { |
|
1166 | + if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) { |
|
1167 | 1167 | // User did not agree |
1168 | - wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) ); |
|
1168 | + wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing'))); |
|
1169 | 1169 | } |
1170 | 1170 | } |
1171 | 1171 | |
@@ -1178,36 +1178,36 @@ discard block |
||
1178 | 1178 | ); |
1179 | 1179 | |
1180 | 1180 | // Verify there is a user_ID |
1181 | - if ( $user_ID > 0 ) { |
|
1181 | + if ($user_ID > 0) { |
|
1182 | 1182 | // Get the logged in user data |
1183 | - $user_data = get_userdata( $user_ID ); |
|
1184 | - $required_fields = wpinv_checkout_required_fields(); |
|
1183 | + $user_data = get_userdata($user_ID); |
|
1184 | + $required_fields = wpinv_checkout_required_fields(); |
|
1185 | 1185 | |
1186 | 1186 | // Loop through required fields and show error messages |
1187 | - if ( !empty( $required_fields ) ) { |
|
1188 | - foreach ( $required_fields as $field_name => $value ) { |
|
1189 | - if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) { |
|
1190 | - wpinv_set_error( $value['error_id'], $value['error_message'] ); |
|
1187 | + if (!empty($required_fields)) { |
|
1188 | + foreach ($required_fields as $field_name => $value) { |
|
1189 | + if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) { |
|
1190 | + wpinv_set_error($value['error_id'], $value['error_message']); |
|
1191 | 1191 | } |
1192 | 1192 | } |
1193 | 1193 | } |
1194 | 1194 | |
1195 | 1195 | // Verify data |
1196 | - if ( $user_data ) { |
|
1196 | + if ($user_data) { |
|
1197 | 1197 | // Collected logged in user data |
1198 | 1198 | $valid_user_data = array( |
1199 | 1199 | 'user_id' => $user_ID, |
1200 | - 'email' => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email, |
|
1201 | - 'first_name' => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name, |
|
1202 | - 'last_name' => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name'] ) ? sanitize_text_field( $_POST['wpinv_last_name'] ) : $user_data->last_name, |
|
1200 | + 'email' => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email, |
|
1201 | + 'first_name' => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name, |
|
1202 | + 'last_name' => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name, |
|
1203 | 1203 | ); |
1204 | 1204 | |
1205 | - if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) { |
|
1206 | - wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) ); |
|
1205 | + if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) { |
|
1206 | + wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing')); |
|
1207 | 1207 | } |
1208 | 1208 | } else { |
1209 | 1209 | // Set invalid user error |
1210 | - wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) ); |
|
1210 | + wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing')); |
|
1211 | 1211 | } |
1212 | 1212 | } |
1213 | 1213 | |
@@ -1215,21 +1215,21 @@ discard block |
||
1215 | 1215 | return $valid_user_data; |
1216 | 1216 | } |
1217 | 1217 | |
1218 | -function wpinv_checkout_form_get_user( $valid_data = array() ) { |
|
1218 | +function wpinv_checkout_form_get_user($valid_data = array()) { |
|
1219 | 1219 | // Initialize user |
1220 | 1220 | $user = false; |
1221 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
1221 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
1222 | 1222 | |
1223 | 1223 | /*if ( $is_ajax ) { |
1224 | 1224 | // Do not create or login the user during the ajax submission (check for errors only) |
1225 | 1225 | return true; |
1226 | - } else */if ( is_user_logged_in() ) { |
|
1226 | + } else */if (is_user_logged_in()) { |
|
1227 | 1227 | // Set the valid user as the logged in collected data |
1228 | 1228 | $user = $valid_data['logged_in_user']; |
1229 | 1229 | } |
1230 | 1230 | |
1231 | 1231 | // Verify we have an user |
1232 | - if ( false === $user || empty( $user ) ) { |
|
1232 | + if (false === $user || empty($user)) { |
|
1233 | 1233 | // Return false |
1234 | 1234 | return false; |
1235 | 1235 | } |
@@ -1248,11 +1248,11 @@ discard block |
||
1248 | 1248 | 'zip', |
1249 | 1249 | ); |
1250 | 1250 | |
1251 | - foreach ( $address_fields as $field ) { |
|
1252 | - $user[$field] = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false; |
|
1251 | + foreach ($address_fields as $field) { |
|
1252 | + $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false; |
|
1253 | 1253 | |
1254 | - if ( !empty( $user['user_id'] ) ) { |
|
1255 | - update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] ); |
|
1254 | + if (!empty($user['user_id'])) { |
|
1255 | + update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]); |
|
1256 | 1256 | } |
1257 | 1257 | } |
1258 | 1258 | |
@@ -1260,28 +1260,28 @@ discard block |
||
1260 | 1260 | return $user; |
1261 | 1261 | } |
1262 | 1262 | |
1263 | -function wpinv_set_checkout_session( $invoice_data = array() ) { |
|
1263 | +function wpinv_set_checkout_session($invoice_data = array()) { |
|
1264 | 1264 | global $wpi_session; |
1265 | 1265 | |
1266 | - return $wpi_session->set( 'wpinv_checkout', $invoice_data ); |
|
1266 | + return $wpi_session->set('wpinv_checkout', $invoice_data); |
|
1267 | 1267 | } |
1268 | 1268 | |
1269 | 1269 | function wpinv_get_checkout_session() { |
1270 | 1270 | global $wpi_session; |
1271 | 1271 | |
1272 | - return $wpi_session->get( 'wpinv_checkout' ); |
|
1272 | + return $wpi_session->get('wpinv_checkout'); |
|
1273 | 1273 | } |
1274 | 1274 | |
1275 | 1275 | function wpinv_empty_cart() { |
1276 | 1276 | global $wpi_session; |
1277 | 1277 | |
1278 | 1278 | // Remove cart contents |
1279 | - $wpi_session->set( 'wpinv_checkout', NULL ); |
|
1279 | + $wpi_session->set('wpinv_checkout', NULL); |
|
1280 | 1280 | |
1281 | 1281 | // Remove all cart fees |
1282 | - $wpi_session->set( 'wpi_cart_fees', NULL ); |
|
1282 | + $wpi_session->set('wpi_cart_fees', NULL); |
|
1283 | 1283 | |
1284 | - do_action( 'wpinv_empty_cart' ); |
|
1284 | + do_action('wpinv_empty_cart'); |
|
1285 | 1285 | } |
1286 | 1286 | |
1287 | 1287 | function wpinv_process_checkout() { |
@@ -1293,42 +1293,42 @@ discard block |
||
1293 | 1293 | |
1294 | 1294 | $wpi_checkout_id = $invoice->ID; |
1295 | 1295 | |
1296 | - do_action( 'wpinv_pre_process_checkout' ); |
|
1296 | + do_action('wpinv_pre_process_checkout'); |
|
1297 | 1297 | |
1298 | - if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty |
|
1298 | + if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty |
|
1299 | 1299 | $valid_data = false; |
1300 | - wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) ); |
|
1300 | + wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing')); |
|
1301 | 1301 | } else { |
1302 | 1302 | // Validate the form $_POST data |
1303 | 1303 | $valid_data = wpinv_validate_checkout_fields(); |
1304 | 1304 | |
1305 | 1305 | // Allow themes and plugins to hook to errors |
1306 | - do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST ); |
|
1306 | + do_action('wpinv_checkout_error_checks', $valid_data, $_POST); |
|
1307 | 1307 | } |
1308 | 1308 | |
1309 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
1309 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
1310 | 1310 | |
1311 | 1311 | // Validate the user |
1312 | - $user = wpinv_checkout_form_get_user( $valid_data ); |
|
1312 | + $user = wpinv_checkout_form_get_user($valid_data); |
|
1313 | 1313 | |
1314 | 1314 | // Let extensions validate fields after user is logged in if user has used login/registration form |
1315 | - do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST ); |
|
1315 | + do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST); |
|
1316 | 1316 | |
1317 | - if ( false === $valid_data || wpinv_get_errors() || ! $user ) { |
|
1318 | - if ( $is_ajax ) { |
|
1319 | - do_action( 'wpinv_ajax_checkout_errors' ); |
|
1317 | + if (false === $valid_data || wpinv_get_errors() || !$user) { |
|
1318 | + if ($is_ajax) { |
|
1319 | + do_action('wpinv_ajax_checkout_errors'); |
|
1320 | 1320 | die(); |
1321 | 1321 | } else { |
1322 | 1322 | return false; |
1323 | 1323 | } |
1324 | 1324 | } |
1325 | 1325 | |
1326 | - if ( $is_ajax ) { |
|
1326 | + if ($is_ajax) { |
|
1327 | 1327 | // Save address fields. |
1328 | - $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' ); |
|
1329 | - foreach ( $address_fields as $field ) { |
|
1330 | - if ( isset( $user[$field] ) ) { |
|
1331 | - $invoice->set( $field, $user[$field] ); |
|
1328 | + $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company'); |
|
1329 | + foreach ($address_fields as $field) { |
|
1330 | + if (isset($user[$field])) { |
|
1331 | + $invoice->set($field, $user[$field]); |
|
1332 | 1332 | } |
1333 | 1333 | |
1334 | 1334 | $invoice->save(); |
@@ -1336,15 +1336,15 @@ discard block |
||
1336 | 1336 | |
1337 | 1337 | $response['success'] = true; |
1338 | 1338 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
1339 | - $response['data']['subtotalf'] = $invoice->get_subtotal( true ); |
|
1339 | + $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
|
1340 | 1340 | $response['data']['discount'] = $invoice->get_discount(); |
1341 | - $response['data']['discountf'] = $invoice->get_discount( true ); |
|
1341 | + $response['data']['discountf'] = $invoice->get_discount(true); |
|
1342 | 1342 | $response['data']['tax'] = $invoice->get_tax(); |
1343 | - $response['data']['taxf'] = $invoice->get_tax( true ); |
|
1343 | + $response['data']['taxf'] = $invoice->get_tax(true); |
|
1344 | 1344 | $response['data']['total'] = $invoice->get_total(); |
1345 | - $response['data']['totalf'] = $invoice->get_total( true ); |
|
1345 | + $response['data']['totalf'] = $invoice->get_total(true); |
|
1346 | 1346 | |
1347 | - wp_send_json( $response ); |
|
1347 | + wp_send_json($response); |
|
1348 | 1348 | } |
1349 | 1349 | |
1350 | 1350 | $user_info = array( |
@@ -1366,42 +1366,42 @@ discard block |
||
1366 | 1366 | |
1367 | 1367 | // Setup invoice information |
1368 | 1368 | $invoice_data = array( |
1369 | - 'invoice_id' => !empty( $invoice ) ? $invoice->ID : 0, |
|
1369 | + 'invoice_id' => !empty($invoice) ? $invoice->ID : 0, |
|
1370 | 1370 | 'items' => $cart_items, |
1371 | 1371 | 'cart_discounts' => $discounts, |
1372 | - 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
1373 | - 'subtotal' => wpinv_get_cart_subtotal( $cart_items ), // Amount before taxes and discounts |
|
1374 | - 'discount' => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount |
|
1375 | - 'tax' => wpinv_get_cart_tax( $cart_items ), // Taxed amount |
|
1376 | - 'price' => wpinv_get_cart_total( $cart_items, $discounts ), // Amount after taxes |
|
1372 | + 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
1373 | + 'subtotal' => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts |
|
1374 | + 'discount' => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount |
|
1375 | + 'tax' => wpinv_get_cart_tax($cart_items), // Taxed amount |
|
1376 | + 'price' => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes |
|
1377 | 1377 | 'invoice_key' => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(), |
1378 | 1378 | 'user_email' => $user['email'], |
1379 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
1380 | - 'user_info' => stripslashes_deep( $user_info ), |
|
1379 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
1380 | + 'user_info' => stripslashes_deep($user_info), |
|
1381 | 1381 | 'post_data' => $_POST, |
1382 | 1382 | 'cart_details' => $cart_items, |
1383 | 1383 | 'gateway' => $valid_data['gateway'], |
1384 | 1384 | 'card_info' => $valid_data['cc_info'] |
1385 | 1385 | ); |
1386 | 1386 | |
1387 | - $vat_info = $wpinv_euvat->current_vat_data(); |
|
1388 | - if ( is_array( $vat_info ) ) { |
|
1387 | + $vat_info = $wpinv_euvat->current_vat_data(); |
|
1388 | + if (is_array($vat_info)) { |
|
1389 | 1389 | $invoice_data['user_info']['vat_number'] = $vat_info['number']; |
1390 | 1390 | $invoice_data['user_info']['vat_rate'] = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']); |
1391 | - $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
1391 | + $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
1392 | 1392 | |
1393 | 1393 | // Add the VAT rate to each item in the cart |
1394 | - foreach( $invoice_data['cart_details'] as $key => $item_data) { |
|
1394 | + foreach ($invoice_data['cart_details'] as $key => $item_data) { |
|
1395 | 1395 | $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']); |
1396 | - $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 ); |
|
1396 | + $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4); |
|
1397 | 1397 | } |
1398 | 1398 | } |
1399 | 1399 | |
1400 | 1400 | // Save vat fields. |
1401 | - $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' ); |
|
1402 | - foreach ( $address_fields as $field ) { |
|
1403 | - if ( isset( $invoice_data['user_info'][$field] ) ) { |
|
1404 | - $invoice->set( $field, $invoice_data['user_info'][$field] ); |
|
1401 | + $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed'); |
|
1402 | + foreach ($address_fields as $field) { |
|
1403 | + if (isset($invoice_data['user_info'][$field])) { |
|
1404 | + $invoice->set($field, $invoice_data['user_info'][$field]); |
|
1405 | 1405 | } |
1406 | 1406 | |
1407 | 1407 | $invoice->save(); |
@@ -1411,49 +1411,49 @@ discard block |
||
1411 | 1411 | $valid_data['user'] = $user; |
1412 | 1412 | |
1413 | 1413 | // Allow themes and plugins to hook before the gateway |
1414 | - do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data ); |
|
1414 | + do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data); |
|
1415 | 1415 | |
1416 | 1416 | // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice |
1417 | - if ( !$invoice_data['price'] ) { |
|
1417 | + if (!$invoice_data['price']) { |
|
1418 | 1418 | // Revert to manual |
1419 | 1419 | $invoice_data['gateway'] = 'manual'; |
1420 | 1420 | $_POST['wpi-gateway'] = 'manual'; |
1421 | 1421 | } |
1422 | 1422 | |
1423 | 1423 | // Allow the invoice data to be modified before it is sent to the gateway |
1424 | - $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data ); |
|
1424 | + $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data); |
|
1425 | 1425 | |
1426 | 1426 | // Setup the data we're storing in the purchase session |
1427 | 1427 | $session_data = $invoice_data; |
1428 | 1428 | // Make sure credit card numbers are never stored in sessions |
1429 | - if ( !empty( $session_data['card_info']['card_number'] ) ) { |
|
1430 | - unset( $session_data['card_info']['card_number'] ); |
|
1429 | + if (!empty($session_data['card_info']['card_number'])) { |
|
1430 | + unset($session_data['card_info']['card_number']); |
|
1431 | 1431 | } |
1432 | 1432 | |
1433 | 1433 | // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data. |
1434 | - wpinv_set_checkout_session( $invoice_data ); |
|
1434 | + wpinv_set_checkout_session($invoice_data); |
|
1435 | 1435 | |
1436 | 1436 | // Set gateway |
1437 | - $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] ); |
|
1438 | - $invoice->update_meta( '_wpinv_mode', ( wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live' ) ); |
|
1439 | - $invoice->update_meta( '_wpinv_checkout', true ); |
|
1437 | + $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']); |
|
1438 | + $invoice->update_meta('_wpinv_mode', (wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live')); |
|
1439 | + $invoice->update_meta('_wpinv_checkout', true); |
|
1440 | 1440 | |
1441 | - do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data ); |
|
1441 | + do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data); |
|
1442 | 1442 | |
1443 | 1443 | // Send info to the gateway for payment processing |
1444 | - wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data ); |
|
1444 | + wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data); |
|
1445 | 1445 | die(); |
1446 | 1446 | } |
1447 | -add_action( 'wpinv_payment', 'wpinv_process_checkout' ); |
|
1447 | +add_action('wpinv_payment', 'wpinv_process_checkout'); |
|
1448 | 1448 | |
1449 | -function wpinv_get_invoices( $args ) { |
|
1450 | - $args = wp_parse_args( $args, array( |
|
1451 | - 'status' => array_keys( wpinv_get_invoice_statuses() ), |
|
1449 | +function wpinv_get_invoices($args) { |
|
1450 | + $args = wp_parse_args($args, array( |
|
1451 | + 'status' => array_keys(wpinv_get_invoice_statuses()), |
|
1452 | 1452 | 'type' => 'wpi_invoice', |
1453 | 1453 | 'parent' => null, |
1454 | 1454 | 'user' => null, |
1455 | 1455 | 'email' => '', |
1456 | - 'limit' => get_option( 'posts_per_page' ), |
|
1456 | + 'limit' => get_option('posts_per_page'), |
|
1457 | 1457 | 'offset' => null, |
1458 | 1458 | 'page' => 1, |
1459 | 1459 | 'exclude' => array(), |
@@ -1461,7 +1461,7 @@ discard block |
||
1461 | 1461 | 'order' => 'DESC', |
1462 | 1462 | 'return' => 'objects', |
1463 | 1463 | 'paginate' => false, |
1464 | - ) ); |
|
1464 | + )); |
|
1465 | 1465 | |
1466 | 1466 | // Handle some BW compatibility arg names where wp_query args differ in naming. |
1467 | 1467 | $map_legacy = array( |
@@ -1474,20 +1474,20 @@ discard block |
||
1474 | 1474 | 'paged' => 'page', |
1475 | 1475 | ); |
1476 | 1476 | |
1477 | - foreach ( $map_legacy as $from => $to ) { |
|
1478 | - if ( isset( $args[ $from ] ) ) { |
|
1479 | - $args[ $to ] = $args[ $from ]; |
|
1477 | + foreach ($map_legacy as $from => $to) { |
|
1478 | + if (isset($args[$from])) { |
|
1479 | + $args[$to] = $args[$from]; |
|
1480 | 1480 | } |
1481 | 1481 | } |
1482 | 1482 | |
1483 | - $wpinv_cpt = isset( $_REQUEST[ 'wpinv-cpt' ] ) ? $_REQUEST[ 'wpinv-cpt' ] : ''; |
|
1483 | + $wpinv_cpt = isset($_REQUEST['wpinv-cpt']) ? $_REQUEST['wpinv-cpt'] : ''; |
|
1484 | 1484 | |
1485 | - if ( get_query_var( 'paged' ) && 'wpi_invoice' == $wpinv_cpt ) |
|
1485 | + if (get_query_var('paged') && 'wpi_invoice' == $wpinv_cpt) |
|
1486 | 1486 | $args['page'] = get_query_var('paged'); |
1487 | - else if ( get_query_var( 'page' ) && 'wpi_invoice' == $wpinv_cpt ) |
|
1488 | - $args['page'] = get_query_var( 'page' ); |
|
1489 | - else if ( !empty( $args[ 'page' ] ) ) |
|
1490 | - $args['page'] = $args[ 'page' ]; |
|
1487 | + else if (get_query_var('page') && 'wpi_invoice' == $wpinv_cpt) |
|
1488 | + $args['page'] = get_query_var('page'); |
|
1489 | + else if (!empty($args['page'])) |
|
1490 | + $args['page'] = $args['page']; |
|
1491 | 1491 | else |
1492 | 1492 | $args['page'] = 1; |
1493 | 1493 | |
@@ -1500,47 +1500,47 @@ discard block |
||
1500 | 1500 | 'post_status' => $args['status'], |
1501 | 1501 | 'posts_per_page' => $args['limit'], |
1502 | 1502 | 'meta_query' => array(), |
1503 | - 'date_query' => !empty( $args['date_query'] ) ? $args['date_query'] : array(), |
|
1503 | + 'date_query' => !empty($args['date_query']) ? $args['date_query'] : array(), |
|
1504 | 1504 | 'fields' => 'ids', |
1505 | 1505 | 'orderby' => $args['orderby'], |
1506 | 1506 | 'order' => $args['order'], |
1507 | 1507 | ); |
1508 | 1508 | |
1509 | - if ( !empty( $args['user'] ) ) { |
|
1510 | - $wp_query_args['author'] = absint( $args['user'] ); |
|
1509 | + if (!empty($args['user'])) { |
|
1510 | + $wp_query_args['author'] = absint($args['user']); |
|
1511 | 1511 | } |
1512 | 1512 | |
1513 | - if ( ! is_null( $args['parent'] ) ) { |
|
1514 | - $wp_query_args['post_parent'] = absint( $args['parent'] ); |
|
1513 | + if (!is_null($args['parent'])) { |
|
1514 | + $wp_query_args['post_parent'] = absint($args['parent']); |
|
1515 | 1515 | } |
1516 | 1516 | |
1517 | - if ( ! is_null( $args['offset'] ) ) { |
|
1518 | - $wp_query_args['offset'] = absint( $args['offset'] ); |
|
1517 | + if (!is_null($args['offset'])) { |
|
1518 | + $wp_query_args['offset'] = absint($args['offset']); |
|
1519 | 1519 | } else { |
1520 | - $wp_query_args['paged'] = absint( $args['page'] ); |
|
1520 | + $wp_query_args['paged'] = absint($args['page']); |
|
1521 | 1521 | } |
1522 | 1522 | |
1523 | - if ( ! empty( $args['exclude'] ) ) { |
|
1524 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
1523 | + if (!empty($args['exclude'])) { |
|
1524 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
1525 | 1525 | } |
1526 | 1526 | |
1527 | - if ( ! $args['paginate' ] ) { |
|
1527 | + if (!$args['paginate']) { |
|
1528 | 1528 | $wp_query_args['no_found_rows'] = true; |
1529 | 1529 | } |
1530 | 1530 | |
1531 | 1531 | // Get results. |
1532 | - $invoices = new WP_Query( $wp_query_args ); |
|
1532 | + $invoices = new WP_Query($wp_query_args); |
|
1533 | 1533 | |
1534 | - if ( 'objects' === $args['return'] ) { |
|
1535 | - $return = array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
1536 | - } elseif ( 'self' === $args['return'] ) { |
|
1534 | + if ('objects' === $args['return']) { |
|
1535 | + $return = array_map('wpinv_get_invoice', $invoices->posts); |
|
1536 | + } elseif ('self' === $args['return']) { |
|
1537 | 1537 | return $invoices; |
1538 | 1538 | } else { |
1539 | 1539 | $return = $invoices->posts; |
1540 | 1540 | } |
1541 | 1541 | |
1542 | - if ( $args['paginate' ] ) { |
|
1543 | - return (object) array( |
|
1542 | + if ($args['paginate']) { |
|
1543 | + return (object)array( |
|
1544 | 1544 | 'invoices' => $return, |
1545 | 1545 | 'total' => $invoices->found_posts, |
1546 | 1546 | 'max_num_pages' => $invoices->max_num_pages, |
@@ -1552,21 +1552,21 @@ discard block |
||
1552 | 1552 | |
1553 | 1553 | function wpinv_get_user_invoices_columns() { |
1554 | 1554 | $columns = array( |
1555 | - 'invoice-number' => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ), |
|
1556 | - 'invoice-date' => array( 'title' => __( 'Date', 'invoicing' ), 'class' => 'text-left' ), |
|
1557 | - 'invoice-status' => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ), |
|
1558 | - 'invoice-total' => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ), |
|
1559 | - 'invoice-actions' => array( 'title' => ' ', 'class' => 'text-center' ), |
|
1555 | + 'invoice-number' => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'), |
|
1556 | + 'invoice-date' => array('title' => __('Date', 'invoicing'), 'class' => 'text-left'), |
|
1557 | + 'invoice-status' => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'), |
|
1558 | + 'invoice-total' => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'), |
|
1559 | + 'invoice-actions' => array('title' => ' ', 'class' => 'text-center'), |
|
1560 | 1560 | ); |
1561 | 1561 | |
1562 | - return apply_filters( 'wpinv_user_invoices_columns', $columns ); |
|
1562 | + return apply_filters('wpinv_user_invoices_columns', $columns); |
|
1563 | 1563 | } |
1564 | 1564 | |
1565 | -function wpinv_payment_receipt( $atts, $content = null ) { |
|
1565 | +function wpinv_payment_receipt($atts, $content = null) { |
|
1566 | 1566 | global $wpinv_receipt_args; |
1567 | 1567 | |
1568 | - $wpinv_receipt_args = shortcode_atts( array( |
|
1569 | - 'error' => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ), |
|
1568 | + $wpinv_receipt_args = shortcode_atts(array( |
|
1569 | + 'error' => __('Sorry, trouble retrieving payment receipt.', 'invoicing'), |
|
1570 | 1570 | 'price' => true, |
1571 | 1571 | 'discount' => true, |
1572 | 1572 | 'items' => true, |
@@ -1575,185 +1575,185 @@ discard block |
||
1575 | 1575 | 'invoice_key' => false, |
1576 | 1576 | 'payment_method' => true, |
1577 | 1577 | 'invoice_id' => true |
1578 | - ), $atts, 'wpinv_receipt' ); |
|
1578 | + ), $atts, 'wpinv_receipt'); |
|
1579 | 1579 | |
1580 | 1580 | $session = wpinv_get_checkout_session(); |
1581 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
1582 | - $invoice_key = urldecode( $_GET['invoice_key'] ); |
|
1583 | - } else if ( $session && isset( $session['invoice_key'] ) ) { |
|
1581 | + if (isset($_GET['invoice_key'])) { |
|
1582 | + $invoice_key = urldecode($_GET['invoice_key']); |
|
1583 | + } else if ($session && isset($session['invoice_key'])) { |
|
1584 | 1584 | $invoice_key = $session['invoice_key']; |
1585 | - } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) { |
|
1585 | + } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) { |
|
1586 | 1586 | $invoice_key = $wpinv_receipt_args['invoice_key']; |
1587 | - } else if ( isset( $_GET['invoice-id'] ) ) { |
|
1588 | - $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] ); |
|
1587 | + } else if (isset($_GET['invoice-id'])) { |
|
1588 | + $invoice_key = wpinv_get_payment_key((int)$_GET['invoice-id']); |
|
1589 | 1589 | } |
1590 | 1590 | |
1591 | 1591 | // No key found |
1592 | - if ( ! isset( $invoice_key ) ) { |
|
1592 | + if (!isset($invoice_key)) { |
|
1593 | 1593 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
1594 | 1594 | } |
1595 | 1595 | |
1596 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1597 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
1598 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
1596 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
1597 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
1598 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
1599 | 1599 | $invoice_id = (int)$_GET['invoice-id']; |
1600 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
1600 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false; |
|
1601 | 1601 | } |
1602 | 1602 | |
1603 | 1603 | // Key was provided, but user is logged out. Offer them the ability to login and view the receipt |
1604 | - if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) { |
|
1604 | + if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) { |
|
1605 | 1605 | // login redirect |
1606 | - return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>'; |
|
1606 | + return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>'; |
|
1607 | 1607 | } |
1608 | 1608 | |
1609 | - if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) { |
|
1609 | + if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) { |
|
1610 | 1610 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
1611 | 1611 | } |
1612 | 1612 | |
1613 | 1613 | ob_start(); |
1614 | 1614 | |
1615 | - wpinv_get_template_part( 'wpinv-invoice-receipt' ); |
|
1615 | + wpinv_get_template_part('wpinv-invoice-receipt'); |
|
1616 | 1616 | |
1617 | 1617 | $display = ob_get_clean(); |
1618 | 1618 | |
1619 | 1619 | return $display; |
1620 | 1620 | } |
1621 | 1621 | |
1622 | -function wpinv_get_invoice_id_by_key( $key ) { |
|
1622 | +function wpinv_get_invoice_id_by_key($key) { |
|
1623 | 1623 | global $wpdb; |
1624 | 1624 | |
1625 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) ); |
|
1625 | + $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key)); |
|
1626 | 1626 | |
1627 | - if ( $invoice_id != NULL ) |
|
1627 | + if ($invoice_id != NULL) |
|
1628 | 1628 | return $invoice_id; |
1629 | 1629 | |
1630 | 1630 | return 0; |
1631 | 1631 | } |
1632 | 1632 | |
1633 | -function wpinv_can_view_receipt( $invoice_key = '' ) { |
|
1633 | +function wpinv_can_view_receipt($invoice_key = '') { |
|
1634 | 1634 | $return = false; |
1635 | 1635 | |
1636 | - if ( empty( $invoice_key ) ) { |
|
1636 | + if (empty($invoice_key)) { |
|
1637 | 1637 | return $return; |
1638 | 1638 | } |
1639 | 1639 | |
1640 | 1640 | global $wpinv_receipt_args; |
1641 | 1641 | |
1642 | - $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1643 | - if ( isset( $_GET['invoice-id'] ) ) { |
|
1644 | - $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
1642 | + $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key); |
|
1643 | + if (isset($_GET['invoice-id'])) { |
|
1644 | + $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? (int)$_GET['invoice-id'] : 0; |
|
1645 | 1645 | } |
1646 | 1646 | |
1647 | - $user_id = (int) wpinv_get_user_id( $wpinv_receipt_args['id'] ); |
|
1648 | - $invoice_meta = wpinv_get_invoice_meta( $wpinv_receipt_args['id'] ); |
|
1647 | + $user_id = (int)wpinv_get_user_id($wpinv_receipt_args['id']); |
|
1648 | + $invoice_meta = wpinv_get_invoice_meta($wpinv_receipt_args['id']); |
|
1649 | 1649 | |
1650 | - if ( is_user_logged_in() ) { |
|
1651 | - if ( $user_id === (int) get_current_user_id() ) { |
|
1650 | + if (is_user_logged_in()) { |
|
1651 | + if ($user_id === (int)get_current_user_id()) { |
|
1652 | 1652 | $return = true; |
1653 | 1653 | } |
1654 | 1654 | } |
1655 | 1655 | |
1656 | 1656 | $session = wpinv_get_checkout_session(); |
1657 | - if ( ! empty( $session ) && ! is_user_logged_in() ) { |
|
1658 | - if ( $session['invoice_key'] === $invoice_meta['key'] ) { |
|
1657 | + if (!empty($session) && !is_user_logged_in()) { |
|
1658 | + if ($session['invoice_key'] === $invoice_meta['key']) { |
|
1659 | 1659 | $return = true; |
1660 | 1660 | } |
1661 | 1661 | } |
1662 | 1662 | |
1663 | - return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
1663 | + return (bool)apply_filters('wpinv_can_view_receipt', $return, $invoice_key); |
|
1664 | 1664 | } |
1665 | 1665 | |
1666 | 1666 | function wpinv_pay_for_invoice() { |
1667 | 1667 | global $wpinv_euvat; |
1668 | 1668 | |
1669 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
1669 | + if (isset($_GET['invoice_key'])) { |
|
1670 | 1670 | $checkout_uri = wpinv_get_checkout_uri(); |
1671 | - $invoice_key = sanitize_text_field( $_GET['invoice_key'] ); |
|
1671 | + $invoice_key = sanitize_text_field($_GET['invoice_key']); |
|
1672 | 1672 | |
1673 | - if ( empty( $invoice_key ) ) { |
|
1674 | - wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) ); |
|
1675 | - wp_redirect( $checkout_uri ); |
|
1673 | + if (empty($invoice_key)) { |
|
1674 | + wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing')); |
|
1675 | + wp_redirect($checkout_uri); |
|
1676 | 1676 | wpinv_die(); |
1677 | 1677 | } |
1678 | 1678 | |
1679 | - do_action( 'wpinv_check_pay_for_invoice', $invoice_key ); |
|
1679 | + do_action('wpinv_check_pay_for_invoice', $invoice_key); |
|
1680 | 1680 | |
1681 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1682 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
1683 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
1681 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
1682 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
1683 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
1684 | 1684 | $invoice_id = (int)$_GET['invoice-id']; |
1685 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
1685 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false; |
|
1686 | 1686 | } |
1687 | 1687 | |
1688 | - if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) { |
|
1689 | - if ( $invoice->needs_payment() ) { |
|
1688 | + if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) { |
|
1689 | + if ($invoice->needs_payment()) { |
|
1690 | 1690 | $data = array(); |
1691 | 1691 | $data['invoice_id'] = $invoice_id; |
1692 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
1692 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
1693 | 1693 | |
1694 | - wpinv_set_checkout_session( $data ); |
|
1694 | + wpinv_set_checkout_session($data); |
|
1695 | 1695 | |
1696 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
1696 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
1697 | 1697 | $_POST['country'] = $wpinv_euvat->get_country_by_ip(); |
1698 | 1698 | $_POST['state'] = $_POST['country'] == $invoice->country ? $invoice->state : ''; |
1699 | 1699 | |
1700 | - wpinv_recalculate_tax( true ); |
|
1700 | + wpinv_recalculate_tax(true); |
|
1701 | 1701 | } |
1702 | 1702 | |
1703 | 1703 | } else { |
1704 | 1704 | $checkout_uri = $invoice->get_view_url(); |
1705 | 1705 | } |
1706 | 1706 | } else { |
1707 | - wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) ); |
|
1707 | + wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing')); |
|
1708 | 1708 | |
1709 | - $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() ); |
|
1709 | + $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink()); |
|
1710 | 1710 | } |
1711 | 1711 | |
1712 | - wp_redirect( $checkout_uri ); |
|
1712 | + wp_redirect($checkout_uri); |
|
1713 | 1713 | wpinv_die(); |
1714 | 1714 | } |
1715 | 1715 | } |
1716 | -add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' ); |
|
1716 | +add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice'); |
|
1717 | 1717 | |
1718 | -function wpinv_handle_pay_via_invoice_link( $invoice_key ) { |
|
1719 | - if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) { |
|
1720 | - if ( $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
1718 | +function wpinv_handle_pay_via_invoice_link($invoice_key) { |
|
1719 | + if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) { |
|
1720 | + if ($invoice = wpinv_get_invoice($invoice_id)) { |
|
1721 | 1721 | $user_id = $invoice->get_user_id(); |
1722 | - $secret = sanitize_text_field( $_GET['_wpipay'] ); |
|
1722 | + $secret = sanitize_text_field($_GET['_wpipay']); |
|
1723 | 1723 | |
1724 | - if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link |
|
1725 | - $redirect_to = remove_query_arg( '_wpipay', get_permalink() ); |
|
1724 | + if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link |
|
1725 | + $redirect_to = remove_query_arg('_wpipay', get_permalink()); |
|
1726 | 1726 | |
1727 | - wpinv_guest_redirect( $redirect_to, $user_id ); |
|
1727 | + wpinv_guest_redirect($redirect_to, $user_id); |
|
1728 | 1728 | wpinv_die(); |
1729 | 1729 | } |
1730 | 1730 | } |
1731 | 1731 | } |
1732 | 1732 | } |
1733 | -add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' ); |
|
1733 | +add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link'); |
|
1734 | 1734 | |
1735 | -function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) { |
|
1736 | - $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id; |
|
1735 | +function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') { |
|
1736 | + $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id; |
|
1737 | 1737 | |
1738 | - if ( empty( $invoice_id ) && $invoice_id > 0 ) { |
|
1738 | + if (empty($invoice_id) && $invoice_id > 0) { |
|
1739 | 1739 | return false; |
1740 | 1740 | } |
1741 | 1741 | |
1742 | - if ( empty( $transaction_id ) ) { |
|
1742 | + if (empty($transaction_id)) { |
|
1743 | 1743 | $transaction_id = $invoice_id; |
1744 | 1744 | } |
1745 | 1745 | |
1746 | - $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id ); |
|
1746 | + $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id); |
|
1747 | 1747 | |
1748 | - return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id ); |
|
1748 | + return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id); |
|
1749 | 1749 | } |
1750 | 1750 | |
1751 | -function wpinv_invoice_status_label( $status, $status_display = '' ) { |
|
1752 | - if ( empty( $status_display ) ) { |
|
1753 | - $status_display = wpinv_status_nicename( $status ); |
|
1751 | +function wpinv_invoice_status_label($status, $status_display = '') { |
|
1752 | + if (empty($status_display)) { |
|
1753 | + $status_display = wpinv_status_nicename($status); |
|
1754 | 1754 | } |
1755 | 1755 | |
1756 | - switch ( $status ) { |
|
1756 | + switch ($status) { |
|
1757 | 1757 | case 'publish' : |
1758 | 1758 | case 'wpi-renewal' : |
1759 | 1759 | $class = 'label-success'; |
@@ -1778,28 +1778,28 @@ discard block |
||
1778 | 1778 | |
1779 | 1779 | $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>'; |
1780 | 1780 | |
1781 | - return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display ); |
|
1781 | + return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display); |
|
1782 | 1782 | } |
1783 | 1783 | |
1784 | -function wpinv_format_invoice_number( $number ) { |
|
1785 | - $padd = wpinv_get_option( 'invoice_number_padd' ); |
|
1784 | +function wpinv_format_invoice_number($number) { |
|
1785 | + $padd = wpinv_get_option('invoice_number_padd'); |
|
1786 | 1786 | |
1787 | 1787 | // TODO maintain old invoice numbers if invoice number settings not saved. Should be removed before stable release. |
1788 | - if ( $padd === '' || $padd === false || $padd === NULL ) { |
|
1789 | - return wp_sprintf( __( 'WPINV-%d', 'invoicing' ), $number ); |
|
1788 | + if ($padd === '' || $padd === false || $padd === NULL) { |
|
1789 | + return wp_sprintf(__('WPINV-%d', 'invoicing'), $number); |
|
1790 | 1790 | } |
1791 | 1791 | |
1792 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
1793 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
1792 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
1793 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
1794 | 1794 | |
1795 | - $padd = absint( $padd ); |
|
1796 | - $formatted_number = absint( $number ); |
|
1795 | + $padd = absint($padd); |
|
1796 | + $formatted_number = absint($number); |
|
1797 | 1797 | |
1798 | - if ( $padd > 0 ) { |
|
1799 | - $formatted_number = zeroise( $formatted_number, $padd ); |
|
1798 | + if ($padd > 0) { |
|
1799 | + $formatted_number = zeroise($formatted_number, $padd); |
|
1800 | 1800 | } |
1801 | 1801 | |
1802 | 1802 | $formatted_number = $prefix . $formatted_number . $postfix; |
1803 | 1803 | |
1804 | - return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd ); |
|
1804 | + return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd); |
|
1805 | 1805 | } |
1806 | 1806 | \ No newline at end of file |
@@ -1,28 +1,28 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -function wpinv_user_invoices( $current_page = 1 ) { |
|
5 | +function wpinv_user_invoices($current_page = 1) { |
|
6 | 6 | global $current_page; |
7 | - do_action( 'wpinv_before_user_invoices_template', $current_page ); |
|
8 | - wpinv_get_template_part( 'wpinv-invoice-history' ); |
|
9 | - do_action( 'wpinv_after_user_invoices_template', $current_page ); |
|
7 | + do_action('wpinv_before_user_invoices_template', $current_page); |
|
8 | + wpinv_get_template_part('wpinv-invoice-history'); |
|
9 | + do_action('wpinv_after_user_invoices_template', $current_page); |
|
10 | 10 | } |
11 | 11 | |
12 | -function wpinv_get_users_invoices( $user = 0, $number = 20, $pagination = false, $status = 'publish' ) { |
|
13 | - if ( empty( $user ) ) { |
|
12 | +function wpinv_get_users_invoices($user = 0, $number = 20, $pagination = false, $status = 'publish') { |
|
13 | + if (empty($user)) { |
|
14 | 14 | $user = get_current_user_id(); |
15 | 15 | } |
16 | 16 | |
17 | - if ( 0 === $user ) { |
|
17 | + if (0 === $user) { |
|
18 | 18 | return false; |
19 | 19 | } |
20 | 20 | |
21 | - if ( $pagination ) { |
|
22 | - if ( get_query_var( 'paged' ) ) |
|
21 | + if ($pagination) { |
|
22 | + if (get_query_var('paged')) |
|
23 | 23 | $paged = get_query_var('paged'); |
24 | - else if ( get_query_var( 'page' ) ) |
|
25 | - $paged = get_query_var( 'page' ); |
|
24 | + else if (get_query_var('page')) |
|
25 | + $paged = get_query_var('page'); |
|
26 | 26 | else |
27 | 27 | $paged = 1; |
28 | 28 | } |
@@ -31,21 +31,21 @@ discard block |
||
31 | 31 | 'post_type' => 'wpi_invoice', |
32 | 32 | 'posts_per_page' => 20, |
33 | 33 | 'paged' => null, |
34 | - 'post_status' => array( 'publish', 'pending' ), |
|
34 | + 'post_status' => array('publish', 'pending'), |
|
35 | 35 | 'user' => $user, |
36 | 36 | 'order' => 'date', |
37 | 37 | ); |
38 | 38 | |
39 | - $invoices = get_posts( $args ); |
|
39 | + $invoices = get_posts($args); |
|
40 | 40 | |
41 | 41 | // No invoices |
42 | - if ( ! $invoices ) |
|
42 | + if (!$invoices) |
|
43 | 43 | return false; |
44 | 44 | |
45 | 45 | return $invoices; |
46 | 46 | } |
47 | 47 | |
48 | -function wpinv_dropdown_users( $args = '' ) { |
|
48 | +function wpinv_dropdown_users($args = '') { |
|
49 | 49 | $defaults = array( |
50 | 50 | 'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '', |
51 | 51 | 'orderby' => 'display_name', 'order' => 'ASC', |
@@ -56,18 +56,18 @@ discard block |
||
56 | 56 | 'option_none_value' => -1 |
57 | 57 | ); |
58 | 58 | |
59 | - $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0; |
|
59 | + $defaults['selected'] = is_author() ? get_query_var('author') : 0; |
|
60 | 60 | |
61 | - $r = wp_parse_args( $args, $defaults ); |
|
61 | + $r = wp_parse_args($args, $defaults); |
|
62 | 62 | |
63 | - $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) ); |
|
63 | + $query_args = wp_array_slice_assoc($r, array('blog_id', 'include', 'exclude', 'orderby', 'order', 'who')); |
|
64 | 64 | |
65 | - $fields = array( 'ID', 'user_login', 'user_email' ); |
|
65 | + $fields = array('ID', 'user_login', 'user_email'); |
|
66 | 66 | |
67 | - $show = ! empty( $r['show'] ) ? $r['show'] : 'display_name'; |
|
68 | - if ( 'display_name_with_login' === $show ) { |
|
67 | + $show = !empty($r['show']) ? $r['show'] : 'display_name'; |
|
68 | + if ('display_name_with_login' === $show) { |
|
69 | 69 | $fields[] = 'display_name'; |
70 | - } else if ( 'display_name_with_email' === $show ) { |
|
70 | + } else if ('display_name_with_email' === $show) { |
|
71 | 71 | $fields[] = 'display_name'; |
72 | 72 | } else { |
73 | 73 | $fields[] = $show; |
@@ -79,99 +79,99 @@ discard block |
||
79 | 79 | $show_option_none = $r['show_option_none']; |
80 | 80 | $option_none_value = $r['option_none_value']; |
81 | 81 | |
82 | - $query_args = apply_filters( 'wpinv_dropdown_users_args', $query_args, $r ); |
|
82 | + $query_args = apply_filters('wpinv_dropdown_users_args', $query_args, $r); |
|
83 | 83 | |
84 | - $users = get_users( $query_args ); |
|
84 | + $users = get_users($query_args); |
|
85 | 85 | |
86 | 86 | $output = ''; |
87 | - if ( ! empty( $users ) && ( empty( $r['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) { |
|
88 | - $name = esc_attr( $r['name'] ); |
|
89 | - if ( $r['multi'] && ! $r['id'] ) { |
|
87 | + if (!empty($users) && (empty($r['hide_if_only_one_author']) || count($users) > 1)) { |
|
88 | + $name = esc_attr($r['name']); |
|
89 | + if ($r['multi'] && !$r['id']) { |
|
90 | 90 | $id = ''; |
91 | 91 | } else { |
92 | - $id = $r['id'] ? " id='" . esc_attr( $r['id'] ) . "'" : " id='$name'"; |
|
92 | + $id = $r['id'] ? " id='" . esc_attr($r['id']) . "'" : " id='$name'"; |
|
93 | 93 | } |
94 | 94 | $output = "<select name='{$name}'{$id} class='" . $r['class'] . "'>\n"; |
95 | 95 | |
96 | - if ( $show_option_all ) { |
|
96 | + if ($show_option_all) { |
|
97 | 97 | $output .= "\t<option value='0'>$show_option_all</option>\n"; |
98 | 98 | } |
99 | 99 | |
100 | - if ( $show_option_none ) { |
|
101 | - $_selected = selected( $option_none_value, $r['selected'], false ); |
|
102 | - $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n"; |
|
100 | + if ($show_option_none) { |
|
101 | + $_selected = selected($option_none_value, $r['selected'], false); |
|
102 | + $output .= "\t<option value='" . esc_attr($option_none_value) . "'$_selected>$show_option_none</option>\n"; |
|
103 | 103 | } |
104 | 104 | |
105 | - if ( $r['include_selected'] && ( $r['selected'] > 0 ) ) { |
|
105 | + if ($r['include_selected'] && ($r['selected'] > 0)) { |
|
106 | 106 | $found_selected = false; |
107 | - $r['selected'] = (int) $r['selected']; |
|
108 | - foreach ( (array) $users as $user ) { |
|
109 | - $user->ID = (int) $user->ID; |
|
110 | - if ( $user->ID === $r['selected'] ) { |
|
107 | + $r['selected'] = (int)$r['selected']; |
|
108 | + foreach ((array)$users as $user) { |
|
109 | + $user->ID = (int)$user->ID; |
|
110 | + if ($user->ID === $r['selected']) { |
|
111 | 111 | $found_selected = true; |
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
115 | - if ( ! $found_selected ) { |
|
116 | - $users[] = get_userdata( $r['selected'] ); |
|
115 | + if (!$found_selected) { |
|
116 | + $users[] = get_userdata($r['selected']); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | - foreach ( (array) $users as $user ) { |
|
121 | - if ( 'display_name_with_login' === $show ) { |
|
120 | + foreach ((array)$users as $user) { |
|
121 | + if ('display_name_with_login' === $show) { |
|
122 | 122 | /* translators: 1: display name, 2: user_login */ |
123 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login ); |
|
124 | - } elseif ( 'display_name_with_email' === $show ) { |
|
123 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_login); |
|
124 | + } elseif ('display_name_with_email' === $show) { |
|
125 | 125 | /* translators: 1: display name, 2: user_email */ |
126 | - if ( $user->display_name == $user->user_email ) { |
|
126 | + if ($user->display_name == $user->user_email) { |
|
127 | 127 | $display = $user->display_name; |
128 | 128 | } else { |
129 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_email ); |
|
129 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_email); |
|
130 | 130 | } |
131 | - } elseif ( ! empty( $user->$show ) ) { |
|
131 | + } elseif (!empty($user->$show)) { |
|
132 | 132 | $display = $user->$show; |
133 | 133 | } else { |
134 | 134 | $display = '(' . $user->user_login . ')'; |
135 | 135 | } |
136 | 136 | |
137 | - $_selected = selected( $user->ID, $r['selected'], false ); |
|
138 | - $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n"; |
|
137 | + $_selected = selected($user->ID, $r['selected'], false); |
|
138 | + $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n"; |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | $output .= "</select>"; |
142 | 142 | } |
143 | 143 | |
144 | - $html = apply_filters( 'wpinv_dropdown_users', $output ); |
|
144 | + $html = apply_filters('wpinv_dropdown_users', $output); |
|
145 | 145 | |
146 | - if ( $r['echo'] ) { |
|
146 | + if ($r['echo']) { |
|
147 | 147 | echo $html; |
148 | 148 | } |
149 | 149 | return $html; |
150 | 150 | } |
151 | 151 | |
152 | -function wpinv_guest_redirect( $redirect_to, $user_id = 0 ) { |
|
153 | - if ( (int)wpinv_get_option( 'guest_checkout' ) && $user_id > 0 ) { |
|
154 | - wpinv_login_user( $user_id ); |
|
152 | +function wpinv_guest_redirect($redirect_to, $user_id = 0) { |
|
153 | + if ((int)wpinv_get_option('guest_checkout') && $user_id > 0) { |
|
154 | + wpinv_login_user($user_id); |
|
155 | 155 | } else { |
156 | - $redirect_to = wp_login_url( $redirect_to ); |
|
156 | + $redirect_to = wp_login_url($redirect_to); |
|
157 | 157 | } |
158 | 158 | |
159 | - $redirect_to = apply_filters( 'wpinv_invoice_link_guest_redirect', $redirect_to, $user_id ); |
|
159 | + $redirect_to = apply_filters('wpinv_invoice_link_guest_redirect', $redirect_to, $user_id); |
|
160 | 160 | |
161 | - wp_redirect( $redirect_to ); |
|
161 | + wp_redirect($redirect_to); |
|
162 | 162 | } |
163 | 163 | |
164 | -function wpinv_login_user( $user_id ) { |
|
165 | - if ( is_user_logged_in() ) { |
|
164 | +function wpinv_login_user($user_id) { |
|
165 | + if (is_user_logged_in()) { |
|
166 | 166 | return true; |
167 | 167 | } |
168 | 168 | |
169 | - $user = get_user_by( 'id', $user_id ); |
|
169 | + $user = get_user_by('id', $user_id); |
|
170 | 170 | |
171 | - if ( !empty( $user ) && !is_wp_error( $user ) && !empty( $user->user_login ) ) { |
|
172 | - wp_set_current_user( $user_id, $user->user_login ); |
|
173 | - wp_set_auth_cookie( $user_id ); |
|
174 | - do_action( 'wp_login', $user->user_login ); |
|
171 | + if (!empty($user) && !is_wp_error($user) && !empty($user->user_login)) { |
|
172 | + wp_set_current_user($user_id, $user->user_login); |
|
173 | + wp_set_auth_cookie($user_id); |
|
174 | + do_action('wp_login', $user->user_login); |
|
175 | 175 | |
176 | 176 | return true; |
177 | 177 | } |
@@ -7,12 +7,12 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_init_transactional_emails() { |
15 | - $email_actions = apply_filters( 'wpinv_email_actions', array( |
|
15 | + $email_actions = apply_filters('wpinv_email_actions', array( |
|
16 | 16 | 'wpinv_status_pending_to_processing', |
17 | 17 | 'wpinv_status_pending_to_publish', |
18 | 18 | 'wpinv_status_pending_to_cancelled', |
@@ -28,79 +28,79 @@ discard block |
||
28 | 28 | 'wpinv_fully_refunded', |
29 | 29 | 'wpinv_partially_refunded', |
30 | 30 | 'wpinv_new_invoice_note' |
31 | - ) ); |
|
31 | + )); |
|
32 | 32 | |
33 | - foreach ( $email_actions as $action ) { |
|
34 | - add_action( $action, 'wpinv_send_transactional_email', 10, 10 ); |
|
33 | + foreach ($email_actions as $action) { |
|
34 | + add_action($action, 'wpinv_send_transactional_email', 10, 10); |
|
35 | 35 | } |
36 | 36 | } |
37 | -add_action( 'init', 'wpinv_init_transactional_emails' ); |
|
37 | +add_action('init', 'wpinv_init_transactional_emails'); |
|
38 | 38 | |
39 | 39 | // New invoice email |
40 | -add_action( 'wpinv_status_pending_to_processing_notification', 'wpinv_new_invoice_notification' ); |
|
41 | -add_action( 'wpinv_status_pending_to_publish_notification', 'wpinv_new_invoice_notification' ); |
|
42 | -add_action( 'wpinv_status_pending_to_onhold_notification', 'wpinv_new_invoice_notification' ); |
|
43 | -add_action( 'wpinv_status_failed_to_processing_notification', 'wpinv_new_invoice_notification' ); |
|
44 | -add_action( 'wpinv_status_failed_to_publish_notification', 'wpinv_new_invoice_notification' ); |
|
45 | -add_action( 'wpinv_status_failed_to_onhold_notification', 'wpinv_new_invoice_notification' ); |
|
40 | +add_action('wpinv_status_pending_to_processing_notification', 'wpinv_new_invoice_notification'); |
|
41 | +add_action('wpinv_status_pending_to_publish_notification', 'wpinv_new_invoice_notification'); |
|
42 | +add_action('wpinv_status_pending_to_onhold_notification', 'wpinv_new_invoice_notification'); |
|
43 | +add_action('wpinv_status_failed_to_processing_notification', 'wpinv_new_invoice_notification'); |
|
44 | +add_action('wpinv_status_failed_to_publish_notification', 'wpinv_new_invoice_notification'); |
|
45 | +add_action('wpinv_status_failed_to_onhold_notification', 'wpinv_new_invoice_notification'); |
|
46 | 46 | |
47 | 47 | // Cancelled invoice email |
48 | -add_action( 'wpinv_status_pending_to_cancelled_notification', 'wpinv_cancelled_invoice_notification' ); |
|
49 | -add_action( 'wpinv_status_onhold_to_cancelled_notification', 'wpinv_cancelled_invoice_notification' ); |
|
48 | +add_action('wpinv_status_pending_to_cancelled_notification', 'wpinv_cancelled_invoice_notification'); |
|
49 | +add_action('wpinv_status_onhold_to_cancelled_notification', 'wpinv_cancelled_invoice_notification'); |
|
50 | 50 | |
51 | 51 | // Failed invoice email |
52 | -add_action( 'wpinv_status_pending_to_failed_notification', 'wpinv_failed_invoice_notification' ); |
|
53 | -add_action( 'wpinv_status_onhold_to_failed_notification', 'wpinv_failed_invoice_notification' ); |
|
52 | +add_action('wpinv_status_pending_to_failed_notification', 'wpinv_failed_invoice_notification'); |
|
53 | +add_action('wpinv_status_onhold_to_failed_notification', 'wpinv_failed_invoice_notification'); |
|
54 | 54 | |
55 | 55 | // On hold invoice email |
56 | -add_action( 'wpinv_status_pending_to_onhold_notification', 'wpinv_onhold_invoice_notification' ); |
|
57 | -add_action( 'wpinv_status_failed_to_onhold_notification', 'wpinv_onhold_invoice_notification' ); |
|
56 | +add_action('wpinv_status_pending_to_onhold_notification', 'wpinv_onhold_invoice_notification'); |
|
57 | +add_action('wpinv_status_failed_to_onhold_notification', 'wpinv_onhold_invoice_notification'); |
|
58 | 58 | |
59 | 59 | // Processing invoice email |
60 | -add_action( 'wpinv_status_pending_to_processing_notification', 'wpinv_processing_invoice_notification' ); |
|
60 | +add_action('wpinv_status_pending_to_processing_notification', 'wpinv_processing_invoice_notification'); |
|
61 | 61 | |
62 | 62 | // Paid invoice email |
63 | -add_action( 'wpinv_status_publish_notification', 'wpinv_completed_invoice_notification' ); |
|
63 | +add_action('wpinv_status_publish_notification', 'wpinv_completed_invoice_notification'); |
|
64 | 64 | |
65 | 65 | // Refunded invoice email |
66 | -add_action( 'wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification' ); |
|
67 | -add_action( 'wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification' ); |
|
66 | +add_action('wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification'); |
|
67 | +add_action('wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification'); |
|
68 | 68 | |
69 | 69 | // Invoice note |
70 | -add_action( 'wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification' ); |
|
70 | +add_action('wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification'); |
|
71 | 71 | |
72 | -add_action( 'wpinv_email_header', 'wpinv_email_header' ); |
|
73 | -add_action( 'wpinv_email_footer', 'wpinv_email_footer' ); |
|
74 | -add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 ); |
|
75 | -add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 ); |
|
76 | -add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 ); |
|
77 | -add_action( 'wpinv_email_before_note_details', 'wpinv_email_before_note_details', 10, 4 ); |
|
72 | +add_action('wpinv_email_header', 'wpinv_email_header'); |
|
73 | +add_action('wpinv_email_footer', 'wpinv_email_footer'); |
|
74 | +add_action('wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3); |
|
75 | +add_action('wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3); |
|
76 | +add_action('wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3); |
|
77 | +add_action('wpinv_email_before_note_details', 'wpinv_email_before_note_details', 10, 4); |
|
78 | 78 | |
79 | 79 | function wpinv_send_transactional_email() { |
80 | 80 | $args = func_get_args(); |
81 | 81 | $function = current_filter() . '_notification'; |
82 | - do_action_ref_array( $function, $args ); |
|
82 | + do_action_ref_array($function, $args); |
|
83 | 83 | } |
84 | 84 | |
85 | -function wpinv_new_invoice_notification( $invoice_id, $new_status = '' ) { |
|
85 | +function wpinv_new_invoice_notification($invoice_id, $new_status = '') { |
|
86 | 86 | global $wpinv_email_search, $wpinv_email_replace; |
87 | 87 | |
88 | 88 | $email_type = 'new_invoice'; |
89 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
89 | + if (!wpinv_email_is_enabled($email_type)) { |
|
90 | 90 | return false; |
91 | 91 | } |
92 | 92 | |
93 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
94 | - if ( empty( $invoice ) ) { |
|
93 | + $invoice = wpinv_get_invoice($invoice_id); |
|
94 | + if (empty($invoice)) { |
|
95 | 95 | return false; |
96 | 96 | } |
97 | 97 | |
98 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
98 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
99 | 99 | return false; |
100 | 100 | } |
101 | 101 | |
102 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
103 | - if ( !is_email( $recipient ) ) { |
|
102 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
103 | + if (!is_email($recipient)) { |
|
104 | 104 | return false; |
105 | 105 | } |
106 | 106 | |
@@ -117,41 +117,41 @@ discard block |
||
117 | 117 | $wpinv_email_search = $search; |
118 | 118 | $wpinv_email_replace = $replace; |
119 | 119 | |
120 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
121 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
122 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
123 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
120 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
121 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
122 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
123 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
124 | 124 | |
125 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
125 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
126 | 126 | 'invoice' => $invoice, |
127 | 127 | 'email_type' => $email_type, |
128 | 128 | 'email_heading' => $email_heading, |
129 | 129 | 'sent_to_admin' => true, |
130 | 130 | 'plain_text' => false, |
131 | - ) ); |
|
131 | + )); |
|
132 | 132 | |
133 | - return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
133 | + return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
134 | 134 | } |
135 | 135 | |
136 | -function wpinv_cancelled_invoice_notification( $invoice_id, $new_status = '' ) { |
|
136 | +function wpinv_cancelled_invoice_notification($invoice_id, $new_status = '') { |
|
137 | 137 | global $wpinv_email_search, $wpinv_email_replace; |
138 | 138 | |
139 | 139 | $email_type = 'cancelled_invoice'; |
140 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
140 | + if (!wpinv_email_is_enabled($email_type)) { |
|
141 | 141 | return false; |
142 | 142 | } |
143 | 143 | |
144 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
145 | - if ( empty( $invoice ) ) { |
|
144 | + $invoice = wpinv_get_invoice($invoice_id); |
|
145 | + if (empty($invoice)) { |
|
146 | 146 | return false; |
147 | 147 | } |
148 | 148 | |
149 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
149 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
150 | 150 | return false; |
151 | 151 | } |
152 | 152 | |
153 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
154 | - if ( !is_email( $recipient ) ) { |
|
153 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
154 | + if (!is_email($recipient)) { |
|
155 | 155 | return false; |
156 | 156 | } |
157 | 157 | |
@@ -168,41 +168,41 @@ discard block |
||
168 | 168 | $wpinv_email_search = $search; |
169 | 169 | $wpinv_email_replace = $replace; |
170 | 170 | |
171 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
172 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
173 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
174 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
171 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
172 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
173 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
174 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
175 | 175 | |
176 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
176 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
177 | 177 | 'invoice' => $invoice, |
178 | 178 | 'email_type' => $email_type, |
179 | 179 | 'email_heading' => $email_heading, |
180 | 180 | 'sent_to_admin' => true, |
181 | 181 | 'plain_text' => false, |
182 | - ) ); |
|
182 | + )); |
|
183 | 183 | |
184 | - return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
184 | + return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
185 | 185 | } |
186 | 186 | |
187 | -function wpinv_failed_invoice_notification( $invoice_id, $new_status = '' ) { |
|
187 | +function wpinv_failed_invoice_notification($invoice_id, $new_status = '') { |
|
188 | 188 | global $wpinv_email_search, $wpinv_email_replace; |
189 | 189 | |
190 | 190 | $email_type = 'failed_invoice'; |
191 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
191 | + if (!wpinv_email_is_enabled($email_type)) { |
|
192 | 192 | return false; |
193 | 193 | } |
194 | 194 | |
195 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
196 | - if ( empty( $invoice ) ) { |
|
195 | + $invoice = wpinv_get_invoice($invoice_id); |
|
196 | + if (empty($invoice)) { |
|
197 | 197 | return false; |
198 | 198 | } |
199 | 199 | |
200 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
200 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
201 | 201 | return false; |
202 | 202 | } |
203 | 203 | |
204 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
205 | - if ( !is_email( $recipient ) ) { |
|
204 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
205 | + if (!is_email($recipient)) { |
|
206 | 206 | return false; |
207 | 207 | } |
208 | 208 | |
@@ -219,41 +219,41 @@ discard block |
||
219 | 219 | $wpinv_email_search = $search; |
220 | 220 | $wpinv_email_replace = $replace; |
221 | 221 | |
222 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
223 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
224 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
225 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
222 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
223 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
224 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
225 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
226 | 226 | |
227 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
227 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
228 | 228 | 'invoice' => $invoice, |
229 | 229 | 'email_type' => $email_type, |
230 | 230 | 'email_heading' => $email_heading, |
231 | 231 | 'sent_to_admin' => true, |
232 | 232 | 'plain_text' => false, |
233 | - ) ); |
|
233 | + )); |
|
234 | 234 | |
235 | - return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
235 | + return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
236 | 236 | } |
237 | 237 | |
238 | -function wpinv_onhold_invoice_notification( $invoice_id, $new_status = '' ) { |
|
238 | +function wpinv_onhold_invoice_notification($invoice_id, $new_status = '') { |
|
239 | 239 | global $wpinv_email_search, $wpinv_email_replace; |
240 | 240 | |
241 | 241 | $email_type = 'onhold_invoice'; |
242 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
242 | + if (!wpinv_email_is_enabled($email_type)) { |
|
243 | 243 | return false; |
244 | 244 | } |
245 | 245 | |
246 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
247 | - if ( empty( $invoice ) ) { |
|
246 | + $invoice = wpinv_get_invoice($invoice_id); |
|
247 | + if (empty($invoice)) { |
|
248 | 248 | return false; |
249 | 249 | } |
250 | 250 | |
251 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
251 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
252 | 252 | return false; |
253 | 253 | } |
254 | 254 | |
255 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
256 | - if ( !is_email( $recipient ) ) { |
|
255 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
256 | + if (!is_email($recipient)) { |
|
257 | 257 | return false; |
258 | 258 | } |
259 | 259 | |
@@ -270,49 +270,49 @@ discard block |
||
270 | 270 | $wpinv_email_search = $search; |
271 | 271 | $wpinv_email_replace = $replace; |
272 | 272 | |
273 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
274 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
275 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
276 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
273 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
274 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
275 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
276 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
277 | 277 | |
278 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
278 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
279 | 279 | 'invoice' => $invoice, |
280 | 280 | 'email_type' => $email_type, |
281 | 281 | 'email_heading' => $email_heading, |
282 | 282 | 'sent_to_admin' => false, |
283 | 283 | 'plain_text' => false, |
284 | - ) ); |
|
284 | + )); |
|
285 | 285 | |
286 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
286 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
287 | 287 | |
288 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
289 | - $recipient = wpinv_get_admin_email(); |
|
290 | - $subject .= ' - ADMIN BCC COPY'; |
|
291 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
288 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
289 | + $recipient = wpinv_get_admin_email(); |
|
290 | + $subject .= ' - ADMIN BCC COPY'; |
|
291 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | return $sent; |
295 | 295 | } |
296 | 296 | |
297 | -function wpinv_processing_invoice_notification( $invoice_id, $new_status = '' ) { |
|
297 | +function wpinv_processing_invoice_notification($invoice_id, $new_status = '') { |
|
298 | 298 | global $wpinv_email_search, $wpinv_email_replace; |
299 | 299 | |
300 | 300 | $email_type = 'processing_invoice'; |
301 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
301 | + if (!wpinv_email_is_enabled($email_type)) { |
|
302 | 302 | return false; |
303 | 303 | } |
304 | 304 | |
305 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
306 | - if ( empty( $invoice ) ) { |
|
305 | + $invoice = wpinv_get_invoice($invoice_id); |
|
306 | + if (empty($invoice)) { |
|
307 | 307 | return false; |
308 | 308 | } |
309 | 309 | |
310 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
310 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
311 | 311 | return false; |
312 | 312 | } |
313 | 313 | |
314 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
315 | - if ( !is_email( $recipient ) ) { |
|
314 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
315 | + if (!is_email($recipient)) { |
|
316 | 316 | return false; |
317 | 317 | } |
318 | 318 | |
@@ -329,49 +329,49 @@ discard block |
||
329 | 329 | $wpinv_email_search = $search; |
330 | 330 | $wpinv_email_replace = $replace; |
331 | 331 | |
332 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
333 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
334 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
335 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
332 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
333 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
334 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
335 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
336 | 336 | |
337 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
337 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
338 | 338 | 'invoice' => $invoice, |
339 | 339 | 'email_type' => $email_type, |
340 | 340 | 'email_heading' => $email_heading, |
341 | 341 | 'sent_to_admin' => false, |
342 | 342 | 'plain_text' => false, |
343 | - ) ); |
|
343 | + )); |
|
344 | 344 | |
345 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
345 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
346 | 346 | |
347 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
348 | - $recipient = wpinv_get_admin_email(); |
|
349 | - $subject .= ' - ADMIN BCC COPY'; |
|
350 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
347 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
348 | + $recipient = wpinv_get_admin_email(); |
|
349 | + $subject .= ' - ADMIN BCC COPY'; |
|
350 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | return $sent; |
354 | 354 | } |
355 | 355 | |
356 | -function wpinv_completed_invoice_notification( $invoice_id, $new_status = '' ) { |
|
356 | +function wpinv_completed_invoice_notification($invoice_id, $new_status = '') { |
|
357 | 357 | global $wpinv_email_search, $wpinv_email_replace; |
358 | 358 | |
359 | 359 | $email_type = 'completed_invoice'; |
360 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
360 | + if (!wpinv_email_is_enabled($email_type)) { |
|
361 | 361 | return false; |
362 | 362 | } |
363 | 363 | |
364 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
365 | - if ( empty( $invoice ) ) { |
|
364 | + $invoice = wpinv_get_invoice($invoice_id); |
|
365 | + if (empty($invoice)) { |
|
366 | 366 | return false; |
367 | 367 | } |
368 | 368 | |
369 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
369 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
370 | 370 | return false; |
371 | 371 | } |
372 | 372 | |
373 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
374 | - if ( !is_email( $recipient ) ) { |
|
373 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
374 | + if (!is_email($recipient)) { |
|
375 | 375 | return false; |
376 | 376 | } |
377 | 377 | |
@@ -388,49 +388,49 @@ discard block |
||
388 | 388 | $wpinv_email_search = $search; |
389 | 389 | $wpinv_email_replace = $replace; |
390 | 390 | |
391 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
392 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
393 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
394 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
391 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
392 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
393 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
394 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
395 | 395 | |
396 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
396 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
397 | 397 | 'invoice' => $invoice, |
398 | 398 | 'email_type' => $email_type, |
399 | 399 | 'email_heading' => $email_heading, |
400 | 400 | 'sent_to_admin' => false, |
401 | 401 | 'plain_text' => false, |
402 | - ) ); |
|
402 | + )); |
|
403 | 403 | |
404 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
404 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
405 | 405 | |
406 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
407 | - $recipient = wpinv_get_admin_email(); |
|
408 | - $subject .= ' - ADMIN BCC COPY'; |
|
409 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
406 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
407 | + $recipient = wpinv_get_admin_email(); |
|
408 | + $subject .= ' - ADMIN BCC COPY'; |
|
409 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | return $sent; |
413 | 413 | } |
414 | 414 | |
415 | -function wpinv_fully_refunded_notification( $invoice_id, $new_status = '' ) { |
|
415 | +function wpinv_fully_refunded_notification($invoice_id, $new_status = '') { |
|
416 | 416 | global $wpinv_email_search, $wpinv_email_replace; |
417 | 417 | |
418 | 418 | $email_type = 'refunded_invoice'; |
419 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
419 | + if (!wpinv_email_is_enabled($email_type)) { |
|
420 | 420 | return false; |
421 | 421 | } |
422 | 422 | |
423 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
424 | - if ( empty( $invoice ) ) { |
|
423 | + $invoice = wpinv_get_invoice($invoice_id); |
|
424 | + if (empty($invoice)) { |
|
425 | 425 | return false; |
426 | 426 | } |
427 | 427 | |
428 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
428 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
429 | 429 | return false; |
430 | 430 | } |
431 | 431 | |
432 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
433 | - if ( !is_email( $recipient ) ) { |
|
432 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
433 | + if (!is_email($recipient)) { |
|
434 | 434 | return false; |
435 | 435 | } |
436 | 436 | |
@@ -447,50 +447,50 @@ discard block |
||
447 | 447 | $wpinv_email_search = $search; |
448 | 448 | $wpinv_email_replace = $replace; |
449 | 449 | |
450 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
451 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
452 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
453 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
450 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
451 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
452 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
453 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
454 | 454 | |
455 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
455 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
456 | 456 | 'invoice' => $invoice, |
457 | 457 | 'email_type' => $email_type, |
458 | 458 | 'email_heading' => $email_heading, |
459 | 459 | 'sent_to_admin' => false, |
460 | 460 | 'plain_text' => false, |
461 | 461 | 'partial_refund' => false |
462 | - ) ); |
|
462 | + )); |
|
463 | 463 | |
464 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
464 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
465 | 465 | |
466 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
467 | - $recipient = wpinv_get_admin_email(); |
|
468 | - $subject .= ' - ADMIN BCC COPY'; |
|
469 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
466 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
467 | + $recipient = wpinv_get_admin_email(); |
|
468 | + $subject .= ' - ADMIN BCC COPY'; |
|
469 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | return $sent; |
473 | 473 | } |
474 | 474 | |
475 | -function wpinv_partially_refunded_notification( $invoice_id, $new_status = '' ) { |
|
475 | +function wpinv_partially_refunded_notification($invoice_id, $new_status = '') { |
|
476 | 476 | global $wpinv_email_search, $wpinv_email_replace; |
477 | 477 | |
478 | 478 | $email_type = 'refunded_invoice'; |
479 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
479 | + if (!wpinv_email_is_enabled($email_type)) { |
|
480 | 480 | return false; |
481 | 481 | } |
482 | 482 | |
483 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
484 | - if ( empty( $invoice ) ) { |
|
483 | + $invoice = wpinv_get_invoice($invoice_id); |
|
484 | + if (empty($invoice)) { |
|
485 | 485 | return false; |
486 | 486 | } |
487 | 487 | |
488 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
488 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
489 | 489 | return false; |
490 | 490 | } |
491 | 491 | |
492 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
493 | - if ( !is_email( $recipient ) ) { |
|
492 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
493 | + if (!is_email($recipient)) { |
|
494 | 494 | return false; |
495 | 495 | } |
496 | 496 | |
@@ -507,53 +507,53 @@ discard block |
||
507 | 507 | $wpinv_email_search = $search; |
508 | 508 | $wpinv_email_replace = $replace; |
509 | 509 | |
510 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
511 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
512 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
513 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
510 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
511 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
512 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
513 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
514 | 514 | |
515 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
515 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
516 | 516 | 'invoice' => $invoice, |
517 | 517 | 'email_type' => $email_type, |
518 | 518 | 'email_heading' => $email_heading, |
519 | 519 | 'sent_to_admin' => false, |
520 | 520 | 'plain_text' => false, |
521 | 521 | 'partial_refund' => true |
522 | - ) ); |
|
522 | + )); |
|
523 | 523 | |
524 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
524 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
525 | 525 | |
526 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
527 | - $recipient = wpinv_get_admin_email(); |
|
528 | - $subject .= ' - ADMIN BCC COPY'; |
|
529 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
526 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
527 | + $recipient = wpinv_get_admin_email(); |
|
528 | + $subject .= ' - ADMIN BCC COPY'; |
|
529 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
530 | 530 | } |
531 | 531 | |
532 | 532 | return $sent; |
533 | 533 | } |
534 | 534 | |
535 | -function wpinv_new_invoice_note_notification( $invoice_id, $new_status = '' ) { |
|
535 | +function wpinv_new_invoice_note_notification($invoice_id, $new_status = '') { |
|
536 | 536 | } |
537 | 537 | |
538 | -function wpinv_user_invoice_notification( $invoice_id ) { |
|
538 | +function wpinv_user_invoice_notification($invoice_id) { |
|
539 | 539 | global $wpinv_email_search, $wpinv_email_replace; |
540 | 540 | |
541 | 541 | $email_type = 'user_invoice'; |
542 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
542 | + if (!wpinv_email_is_enabled($email_type)) { |
|
543 | 543 | return false; |
544 | 544 | } |
545 | 545 | |
546 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
547 | - if ( empty( $invoice ) ) { |
|
546 | + $invoice = wpinv_get_invoice($invoice_id); |
|
547 | + if (empty($invoice)) { |
|
548 | 548 | return false; |
549 | 549 | } |
550 | 550 | |
551 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
551 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
552 | 552 | return false; |
553 | 553 | } |
554 | 554 | |
555 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
556 | - if ( !is_email( $recipient ) ) { |
|
555 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
556 | + if (!is_email($recipient)) { |
|
557 | 557 | return false; |
558 | 558 | } |
559 | 559 | |
@@ -570,53 +570,53 @@ discard block |
||
570 | 570 | $wpinv_email_search = $search; |
571 | 571 | $wpinv_email_replace = $replace; |
572 | 572 | |
573 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
574 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
575 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
576 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
573 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
574 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
575 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
576 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
577 | 577 | |
578 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
578 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
579 | 579 | 'invoice' => $invoice, |
580 | 580 | 'email_type' => $email_type, |
581 | 581 | 'email_heading' => $email_heading, |
582 | 582 | 'sent_to_admin' => false, |
583 | 583 | 'plain_text' => false, |
584 | - ) ); |
|
584 | + )); |
|
585 | 585 | |
586 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
586 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
587 | 587 | |
588 | - if ( $sent ) { |
|
589 | - $note = __( 'Invoice has been emailed to the user.', 'invoicing' ); |
|
588 | + if ($sent) { |
|
589 | + $note = __('Invoice has been emailed to the user.', 'invoicing'); |
|
590 | 590 | } else { |
591 | - $note = __( 'Fail to send invoice to the user!', 'invoicing' ); |
|
591 | + $note = __('Fail to send invoice to the user!', 'invoicing'); |
|
592 | 592 | } |
593 | 593 | |
594 | - $invoice->add_note( $note, '', '', true ); // Add system note. |
|
594 | + $invoice->add_note($note, '', '', true); // Add system note. |
|
595 | 595 | |
596 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
597 | - $recipient = wpinv_get_admin_email(); |
|
598 | - $subject .= ' - ADMIN BCC COPY'; |
|
599 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
596 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
597 | + $recipient = wpinv_get_admin_email(); |
|
598 | + $subject .= ' - ADMIN BCC COPY'; |
|
599 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
600 | 600 | } |
601 | 601 | |
602 | 602 | return $sent; |
603 | 603 | } |
604 | 604 | |
605 | -function wpinv_user_note_notification( $invoice_id, $args = array() ) { |
|
605 | +function wpinv_user_note_notification($invoice_id, $args = array()) { |
|
606 | 606 | global $wpinv_email_search, $wpinv_email_replace; |
607 | 607 | |
608 | 608 | $email_type = 'user_note'; |
609 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
609 | + if (!wpinv_email_is_enabled($email_type)) { |
|
610 | 610 | return false; |
611 | 611 | } |
612 | 612 | |
613 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
614 | - if ( empty( $invoice ) ) { |
|
613 | + $invoice = wpinv_get_invoice($invoice_id); |
|
614 | + if (empty($invoice)) { |
|
615 | 615 | return false; |
616 | 616 | } |
617 | 617 | |
618 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
619 | - if ( !is_email( $recipient ) ) { |
|
618 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
619 | + if (!is_email($recipient)) { |
|
620 | 620 | return false; |
621 | 621 | } |
622 | 622 | |
@@ -624,7 +624,7 @@ discard block |
||
624 | 624 | 'user_note' => '' |
625 | 625 | ); |
626 | 626 | |
627 | - $args = wp_parse_args( $args, $defaults ); |
|
627 | + $args = wp_parse_args($args, $defaults); |
|
628 | 628 | |
629 | 629 | $search = array(); |
630 | 630 | $search['invoice_number'] = '{invoice_number}'; |
@@ -643,46 +643,46 @@ discard block |
||
643 | 643 | $wpinv_email_search = $search; |
644 | 644 | $wpinv_email_replace = $replace; |
645 | 645 | |
646 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
647 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
648 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
649 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
646 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
647 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
648 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
649 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
650 | 650 | |
651 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
651 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
652 | 652 | 'invoice' => $invoice, |
653 | 653 | 'email_type' => $email_type, |
654 | 654 | 'email_heading' => $email_heading, |
655 | 655 | 'sent_to_admin' => false, |
656 | 656 | 'plain_text' => false, |
657 | 657 | 'customer_note' => $args['user_note'] |
658 | - ) ); |
|
658 | + )); |
|
659 | 659 | |
660 | - $content = wpinv_email_format_text( $content ); |
|
660 | + $content = wpinv_email_format_text($content); |
|
661 | 661 | |
662 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
662 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
663 | 663 | |
664 | 664 | return $sent; |
665 | 665 | } |
666 | 666 | |
667 | 667 | function wpinv_mail_get_from_address() { |
668 | - $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from' ) ); |
|
669 | - return sanitize_email( $from_address ); |
|
668 | + $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from')); |
|
669 | + return sanitize_email($from_address); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | function wpinv_mail_get_from_name() { |
673 | - $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name' ) ); |
|
674 | - return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES ); |
|
673 | + $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name')); |
|
674 | + return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES); |
|
675 | 675 | } |
676 | 676 | |
677 | -function wpinv_mail_admin_bcc_active( $mail_type = '' ) { |
|
678 | - $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) ); |
|
679 | - return ( $active ? true : false ); |
|
677 | +function wpinv_mail_admin_bcc_active($mail_type = '') { |
|
678 | + $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc')); |
|
679 | + return ($active ? true : false); |
|
680 | 680 | } |
681 | 681 | |
682 | -function wpinv_mail_get_content_type( $content_type = 'text/html', $email_type = 'html' ) { |
|
683 | - $email_type = apply_filters( 'wpinv_mail_content_type', $email_type ); |
|
682 | +function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') { |
|
683 | + $email_type = apply_filters('wpinv_mail_content_type', $email_type); |
|
684 | 684 | |
685 | - switch ( $email_type ) { |
|
685 | + switch ($email_type) { |
|
686 | 686 | case 'html' : |
687 | 687 | $content_type = 'text/html'; |
688 | 688 | break; |
@@ -697,35 +697,35 @@ discard block |
||
697 | 697 | return $content_type; |
698 | 698 | } |
699 | 699 | |
700 | -function wpinv_mail_send( $to, $subject, $message, $headers, $attachments ) { |
|
701 | - add_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' ); |
|
702 | - add_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' ); |
|
703 | - add_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' ); |
|
700 | +function wpinv_mail_send($to, $subject, $message, $headers, $attachments) { |
|
701 | + add_filter('wp_mail_from', 'wpinv_mail_get_from_address'); |
|
702 | + add_filter('wp_mail_from_name', 'wpinv_mail_get_from_name'); |
|
703 | + add_filter('wp_mail_content_type', 'wpinv_mail_get_content_type'); |
|
704 | 704 | |
705 | - $message = wpinv_email_style_body( $message ); |
|
706 | - $message = apply_filters( 'wpinv_mail_content', $message ); |
|
705 | + $message = wpinv_email_style_body($message); |
|
706 | + $message = apply_filters('wpinv_mail_content', $message); |
|
707 | 707 | |
708 | - $sent = wp_mail( $to, $subject, $message, $headers, $attachments ); |
|
708 | + $sent = wp_mail($to, $subject, $message, $headers, $attachments); |
|
709 | 709 | |
710 | - if ( !$sent ) { |
|
711 | - $log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), ( is_array( $to ) ? implode( ', ', $to ) : $to ), $subject ); |
|
712 | - wpinv_error_log( $log_message, __( "Email from Invoicing plugin failed to send", 'invoicing' ), __FILE__, __LINE__ ); |
|
710 | + if (!$sent) { |
|
711 | + $log_message = wp_sprintf(__("\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing'), date_i18n('F j Y H:i:s', current_time('timestamp')), (is_array($to) ? implode(', ', $to) : $to), $subject); |
|
712 | + wpinv_error_log($log_message, __("Email from Invoicing plugin failed to send", 'invoicing'), __FILE__, __LINE__); |
|
713 | 713 | } |
714 | 714 | |
715 | - remove_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' ); |
|
716 | - remove_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' ); |
|
717 | - remove_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' ); |
|
715 | + remove_filter('wp_mail_from', 'wpinv_mail_get_from_address'); |
|
716 | + remove_filter('wp_mail_from_name', 'wpinv_mail_get_from_name'); |
|
717 | + remove_filter('wp_mail_content_type', 'wpinv_mail_get_content_type'); |
|
718 | 718 | |
719 | 719 | return $sent; |
720 | 720 | } |
721 | 721 | |
722 | 722 | function wpinv_get_emails() { |
723 | 723 | $overdue_days_options = array(); |
724 | - $overdue_days_options[0] = __( 'On the Due Date', 'invoicing' ); |
|
725 | - $overdue_days_options[1] = __( '1 day after Due Date', 'invoicing' ); |
|
724 | + $overdue_days_options[0] = __('On the Due Date', 'invoicing'); |
|
725 | + $overdue_days_options[1] = __('1 day after Due Date', 'invoicing'); |
|
726 | 726 | |
727 | - for ( $i = 2; $i <= 10; $i++ ) { |
|
728 | - $overdue_days_options[$i] = wp_sprintf( __( '%d days after Due Date', 'invoicing' ), $i ); |
|
727 | + for ($i = 2; $i <= 10; $i++) { |
|
728 | + $overdue_days_options[$i] = wp_sprintf(__('%d days after Due Date', 'invoicing'), $i); |
|
729 | 729 | } |
730 | 730 | |
731 | 731 | // Default, built-in gateways |
@@ -733,130 +733,130 @@ discard block |
||
733 | 733 | 'new_invoice' => array( |
734 | 734 | 'email_new_invoice_header' => array( |
735 | 735 | 'id' => 'email_new_invoice_header', |
736 | - 'name' => '<h3>' . __( 'New Invoice', 'invoicing' ) . '</h3>', |
|
737 | - 'desc' => __( 'New invoice emails are sent to admin when a new invoice is received.', 'invoicing' ), |
|
736 | + 'name' => '<h3>' . __('New Invoice', 'invoicing') . '</h3>', |
|
737 | + 'desc' => __('New invoice emails are sent to admin when a new invoice is received.', 'invoicing'), |
|
738 | 738 | 'type' => 'header', |
739 | 739 | ), |
740 | 740 | 'email_new_invoice_active' => array( |
741 | 741 | 'id' => 'email_new_invoice_active', |
742 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
743 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
742 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
743 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
744 | 744 | 'type' => 'checkbox', |
745 | 745 | 'std' => 1 |
746 | 746 | ), |
747 | 747 | 'email_new_invoice_subject' => array( |
748 | 748 | 'id' => 'email_new_invoice_subject', |
749 | - 'name' => __( 'Subject', 'invoicing' ), |
|
750 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
749 | + 'name' => __('Subject', 'invoicing'), |
|
750 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
751 | 751 | 'type' => 'text', |
752 | - 'std' => __( '[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing' ), |
|
752 | + 'std' => __('[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing'), |
|
753 | 753 | 'size' => 'large' |
754 | 754 | ), |
755 | 755 | 'email_new_invoice_heading' => array( |
756 | 756 | 'id' => 'email_new_invoice_heading', |
757 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
758 | - 'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
757 | + 'name' => __('Email Heading', 'invoicing'), |
|
758 | + 'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
759 | 759 | 'type' => 'text', |
760 | - 'std' => __( 'New payment invoice', 'invoicing' ), |
|
760 | + 'std' => __('New payment invoice', 'invoicing'), |
|
761 | 761 | 'size' => 'large' |
762 | 762 | ), |
763 | 763 | ), |
764 | 764 | 'cancelled_invoice' => array( |
765 | 765 | 'email_cancelled_invoice_header' => array( |
766 | 766 | 'id' => 'email_cancelled_invoice_header', |
767 | - 'name' => '<h3>' . __( 'Cancelled Invoice', 'invoicing' ) . '</h3>', |
|
768 | - 'desc' => __( 'Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing' ), |
|
767 | + 'name' => '<h3>' . __('Cancelled Invoice', 'invoicing') . '</h3>', |
|
768 | + 'desc' => __('Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing'), |
|
769 | 769 | 'type' => 'header', |
770 | 770 | ), |
771 | 771 | 'email_cancelled_invoice_active' => array( |
772 | 772 | 'id' => 'email_cancelled_invoice_active', |
773 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
774 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
773 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
774 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
775 | 775 | 'type' => 'checkbox', |
776 | 776 | 'std' => 1 |
777 | 777 | ), |
778 | 778 | 'email_cancelled_invoice_subject' => array( |
779 | 779 | 'id' => 'email_cancelled_invoice_subject', |
780 | - 'name' => __( 'Subject', 'invoicing' ), |
|
781 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
780 | + 'name' => __('Subject', 'invoicing'), |
|
781 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
782 | 782 | 'type' => 'text', |
783 | - 'std' => __( '[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing' ), |
|
783 | + 'std' => __('[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing'), |
|
784 | 784 | 'size' => 'large' |
785 | 785 | ), |
786 | 786 | 'email_cancelled_invoice_heading' => array( |
787 | 787 | 'id' => 'email_cancelled_invoice_heading', |
788 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
789 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
788 | + 'name' => __('Email Heading', 'invoicing'), |
|
789 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
790 | 790 | 'type' => 'text', |
791 | - 'std' => __( 'Cancelled invoice', 'invoicing' ), |
|
791 | + 'std' => __('Cancelled invoice', 'invoicing'), |
|
792 | 792 | 'size' => 'large' |
793 | 793 | ), |
794 | 794 | ), |
795 | 795 | 'failed_invoice' => array( |
796 | 796 | 'email_failed_invoice_header' => array( |
797 | 797 | 'id' => 'email_failed_invoice_header', |
798 | - 'name' => '<h3>' . __( 'Failed Invoice', 'invoicing' ) . '</h3>', |
|
799 | - 'desc' => __( 'Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing' ), |
|
798 | + 'name' => '<h3>' . __('Failed Invoice', 'invoicing') . '</h3>', |
|
799 | + 'desc' => __('Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing'), |
|
800 | 800 | 'type' => 'header', |
801 | 801 | ), |
802 | 802 | 'email_failed_invoice_active' => array( |
803 | 803 | 'id' => 'email_failed_invoice_active', |
804 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
805 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
804 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
805 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
806 | 806 | 'type' => 'checkbox', |
807 | 807 | 'std' => 1 |
808 | 808 | ), |
809 | 809 | 'email_failed_invoice_subject' => array( |
810 | 810 | 'id' => 'email_failed_invoice_subject', |
811 | - 'name' => __( 'Subject', 'invoicing' ), |
|
812 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
811 | + 'name' => __('Subject', 'invoicing'), |
|
812 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
813 | 813 | 'type' => 'text', |
814 | - 'std' => __( '[{site_title}] Failed invoice ({invoice_number})', 'invoicing' ), |
|
814 | + 'std' => __('[{site_title}] Failed invoice ({invoice_number})', 'invoicing'), |
|
815 | 815 | 'size' => 'large' |
816 | 816 | ), |
817 | 817 | 'email_failed_invoice_heading' => array( |
818 | 818 | 'id' => 'email_failed_invoice_heading', |
819 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
820 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
819 | + 'name' => __('Email Heading', 'invoicing'), |
|
820 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
821 | 821 | 'type' => 'text', |
822 | - 'std' => __( 'Failed invoice', 'invoicing' ), |
|
822 | + 'std' => __('Failed invoice', 'invoicing'), |
|
823 | 823 | 'size' => 'large' |
824 | 824 | ) |
825 | 825 | ), |
826 | 826 | 'onhold_invoice' => array( |
827 | 827 | 'email_onhold_invoice_header' => array( |
828 | 828 | 'id' => 'email_onhold_invoice_header', |
829 | - 'name' => '<h3>' . __( 'On Hold Invoice', 'invoicing' ) . '</h3>', |
|
830 | - 'desc' => __( 'This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing' ), |
|
829 | + 'name' => '<h3>' . __('On Hold Invoice', 'invoicing') . '</h3>', |
|
830 | + 'desc' => __('This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing'), |
|
831 | 831 | 'type' => 'header', |
832 | 832 | ), |
833 | 833 | 'email_onhold_invoice_active' => array( |
834 | 834 | 'id' => 'email_onhold_invoice_active', |
835 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
836 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
835 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
836 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
837 | 837 | 'type' => 'checkbox', |
838 | 838 | 'std' => 1 |
839 | 839 | ), |
840 | 840 | 'email_onhold_invoice_subject' => array( |
841 | 841 | 'id' => 'email_onhold_invoice_subject', |
842 | - 'name' => __( 'Subject', 'invoicing' ), |
|
843 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
842 | + 'name' => __('Subject', 'invoicing'), |
|
843 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
844 | 844 | 'type' => 'text', |
845 | - 'std' => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ), |
|
845 | + 'std' => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'), |
|
846 | 846 | 'size' => 'large' |
847 | 847 | ), |
848 | 848 | 'email_onhold_invoice_heading' => array( |
849 | 849 | 'id' => 'email_onhold_invoice_heading', |
850 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
851 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
850 | + 'name' => __('Email Heading', 'invoicing'), |
|
851 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
852 | 852 | 'type' => 'text', |
853 | - 'std' => __( 'Thank you for your invoice', 'invoicing' ), |
|
853 | + 'std' => __('Thank you for your invoice', 'invoicing'), |
|
854 | 854 | 'size' => 'large' |
855 | 855 | ), |
856 | 856 | 'email_onhold_invoice_admin_bcc' => array( |
857 | 857 | 'id' => 'email_onhold_invoice_admin_bcc', |
858 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
859 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
858 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
859 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
860 | 860 | 'type' => 'checkbox', |
861 | 861 | 'std' => 1 |
862 | 862 | ), |
@@ -864,37 +864,37 @@ discard block |
||
864 | 864 | 'processing_invoice' => array( |
865 | 865 | 'email_processing_invoice_header' => array( |
866 | 866 | 'id' => 'email_processing_invoice_header', |
867 | - 'name' => '<h3>' . __( 'Processing Invoice', 'invoicing' ) . '</h3>', |
|
868 | - 'desc' => __( 'This is an invoice notification sent to users containing invoice details after payment.', 'invoicing' ), |
|
867 | + 'name' => '<h3>' . __('Processing Invoice', 'invoicing') . '</h3>', |
|
868 | + 'desc' => __('This is an invoice notification sent to users containing invoice details after payment.', 'invoicing'), |
|
869 | 869 | 'type' => 'header', |
870 | 870 | ), |
871 | 871 | 'email_processing_invoice_active' => array( |
872 | 872 | 'id' => 'email_processing_invoice_active', |
873 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
874 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
873 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
874 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
875 | 875 | 'type' => 'checkbox', |
876 | 876 | 'std' => 1 |
877 | 877 | ), |
878 | 878 | 'email_processing_invoice_subject' => array( |
879 | 879 | 'id' => 'email_processing_invoice_subject', |
880 | - 'name' => __( 'Subject', 'invoicing' ), |
|
881 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
880 | + 'name' => __('Subject', 'invoicing'), |
|
881 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
882 | 882 | 'type' => 'text', |
883 | - 'std' => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ), |
|
883 | + 'std' => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'), |
|
884 | 884 | 'size' => 'large' |
885 | 885 | ), |
886 | 886 | 'email_processing_invoice_heading' => array( |
887 | 887 | 'id' => 'email_processing_invoice_heading', |
888 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
889 | - 'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
888 | + 'name' => __('Email Heading', 'invoicing'), |
|
889 | + 'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
890 | 890 | 'type' => 'text', |
891 | - 'std' => __( 'Thank you for your invoice', 'invoicing' ), |
|
891 | + 'std' => __('Thank you for your invoice', 'invoicing'), |
|
892 | 892 | 'size' => 'large' |
893 | 893 | ), |
894 | 894 | 'email_processing_invoice_admin_bcc' => array( |
895 | 895 | 'id' => 'email_processing_invoice_admin_bcc', |
896 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
897 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
896 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
897 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
898 | 898 | 'type' => 'checkbox', |
899 | 899 | 'std' => 1 |
900 | 900 | ), |
@@ -902,37 +902,37 @@ discard block |
||
902 | 902 | 'completed_invoice' => array( |
903 | 903 | 'email_completed_invoice_header' => array( |
904 | 904 | 'id' => 'email_completed_invoice_header', |
905 | - 'name' => '<h3>' . __( 'Paid Invoice', 'invoicing' ) . '</h3>', |
|
906 | - 'desc' => __( 'Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing' ), |
|
905 | + 'name' => '<h3>' . __('Paid Invoice', 'invoicing') . '</h3>', |
|
906 | + 'desc' => __('Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing'), |
|
907 | 907 | 'type' => 'header', |
908 | 908 | ), |
909 | 909 | 'email_completed_invoice_active' => array( |
910 | 910 | 'id' => 'email_completed_invoice_active', |
911 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
912 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
911 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
912 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
913 | 913 | 'type' => 'checkbox', |
914 | 914 | 'std' => 1 |
915 | 915 | ), |
916 | 916 | 'email_completed_invoice_subject' => array( |
917 | 917 | 'id' => 'email_completed_invoice_subject', |
918 | - 'name' => __( 'Subject', 'invoicing' ), |
|
919 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
918 | + 'name' => __('Subject', 'invoicing'), |
|
919 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
920 | 920 | 'type' => 'text', |
921 | - 'std' => __( '[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing' ), |
|
921 | + 'std' => __('[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing'), |
|
922 | 922 | 'size' => 'large' |
923 | 923 | ), |
924 | 924 | 'email_completed_invoice_heading' => array( |
925 | 925 | 'id' => 'email_completed_invoice_heading', |
926 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
927 | - 'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
926 | + 'name' => __('Email Heading', 'invoicing'), |
|
927 | + 'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
928 | 928 | 'type' => 'text', |
929 | - 'std' => __( 'Your invoice has been paid', 'invoicing' ), |
|
929 | + 'std' => __('Your invoice has been paid', 'invoicing'), |
|
930 | 930 | 'size' => 'large' |
931 | 931 | ), |
932 | 932 | 'email_completed_invoice_admin_bcc' => array( |
933 | 933 | 'id' => 'email_completed_invoice_admin_bcc', |
934 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
935 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
934 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
935 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
936 | 936 | 'type' => 'checkbox', |
937 | 937 | ), |
938 | 938 | 'std' => 1 |
@@ -940,37 +940,37 @@ discard block |
||
940 | 940 | 'refunded_invoice' => array( |
941 | 941 | 'email_refunded_invoice_header' => array( |
942 | 942 | 'id' => 'email_refunded_invoice_header', |
943 | - 'name' => '<h3>' . __( 'Refunded Invoice', 'invoicing' ) . '</h3>', |
|
944 | - 'desc' => __( 'Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing' ), |
|
943 | + 'name' => '<h3>' . __('Refunded Invoice', 'invoicing') . '</h3>', |
|
944 | + 'desc' => __('Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing'), |
|
945 | 945 | 'type' => 'header', |
946 | 946 | ), |
947 | 947 | 'email_refunded_invoice_active' => array( |
948 | 948 | 'id' => 'email_refunded_invoice_active', |
949 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
950 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
949 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
950 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
951 | 951 | 'type' => 'checkbox', |
952 | 952 | 'std' => 1 |
953 | 953 | ), |
954 | 954 | 'email_refunded_invoice_subject' => array( |
955 | 955 | 'id' => 'email_refunded_invoice_subject', |
956 | - 'name' => __( 'Subject', 'invoicing' ), |
|
957 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
956 | + 'name' => __('Subject', 'invoicing'), |
|
957 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
958 | 958 | 'type' => 'text', |
959 | - 'std' => __( '[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing' ), |
|
959 | + 'std' => __('[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing'), |
|
960 | 960 | 'size' => 'large' |
961 | 961 | ), |
962 | 962 | 'email_refunded_invoice_heading' => array( |
963 | 963 | 'id' => 'email_refunded_invoice_heading', |
964 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
965 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
964 | + 'name' => __('Email Heading', 'invoicing'), |
|
965 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
966 | 966 | 'type' => 'text', |
967 | - 'std' => __( 'Your invoice has been refunded', 'invoicing' ), |
|
967 | + 'std' => __('Your invoice has been refunded', 'invoicing'), |
|
968 | 968 | 'size' => 'large' |
969 | 969 | ), |
970 | 970 | 'email_refunded_invoice_admin_bcc' => array( |
971 | 971 | 'id' => 'email_refunded_invoice_admin_bcc', |
972 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
973 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
972 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
973 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
974 | 974 | 'type' => 'checkbox', |
975 | 975 | 'std' => 1 |
976 | 976 | ), |
@@ -978,37 +978,37 @@ discard block |
||
978 | 978 | 'user_invoice' => array( |
979 | 979 | 'email_user_invoice_header' => array( |
980 | 980 | 'id' => 'email_user_invoice_header', |
981 | - 'name' => '<h3>' . __( 'Customer Invoice', 'invoicing' ) . '</h3>', |
|
982 | - 'desc' => __( 'Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing' ), |
|
981 | + 'name' => '<h3>' . __('Customer Invoice', 'invoicing') . '</h3>', |
|
982 | + 'desc' => __('Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing'), |
|
983 | 983 | 'type' => 'header', |
984 | 984 | ), |
985 | 985 | 'email_user_invoice_active' => array( |
986 | 986 | 'id' => 'email_user_invoice_active', |
987 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
988 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
987 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
988 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
989 | 989 | 'type' => 'checkbox', |
990 | 990 | 'std' => 1 |
991 | 991 | ), |
992 | 992 | 'email_user_invoice_subject' => array( |
993 | 993 | 'id' => 'email_user_invoice_subject', |
994 | - 'name' => __( 'Subject', 'invoicing' ), |
|
995 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
994 | + 'name' => __('Subject', 'invoicing'), |
|
995 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
996 | 996 | 'type' => 'text', |
997 | - 'std' => __( '[{site_title}] Your invoice from {invoice_date}', 'invoicing' ), |
|
997 | + 'std' => __('[{site_title}] Your invoice from {invoice_date}', 'invoicing'), |
|
998 | 998 | 'size' => 'large' |
999 | 999 | ), |
1000 | 1000 | 'email_user_invoice_heading' => array( |
1001 | 1001 | 'id' => 'email_user_invoice_heading', |
1002 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
1003 | - 'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
1002 | + 'name' => __('Email Heading', 'invoicing'), |
|
1003 | + 'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
1004 | 1004 | 'type' => 'text', |
1005 | - 'std' => __( 'Your invoice {invoice_number} details', 'invoicing' ), |
|
1005 | + 'std' => __('Your invoice {invoice_number} details', 'invoicing'), |
|
1006 | 1006 | 'size' => 'large' |
1007 | 1007 | ), |
1008 | 1008 | 'email_user_invoice_admin_bcc' => array( |
1009 | 1009 | 'id' => 'email_user_invoice_admin_bcc', |
1010 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
1011 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
1010 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
1011 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
1012 | 1012 | 'type' => 'checkbox', |
1013 | 1013 | 'std' => 1 |
1014 | 1014 | ), |
@@ -1016,177 +1016,177 @@ discard block |
||
1016 | 1016 | 'user_note' => array( |
1017 | 1017 | 'email_user_note_header' => array( |
1018 | 1018 | 'id' => 'email_user_note_header', |
1019 | - 'name' => '<h3>' . __( 'Customer Note', 'invoicing' ) . '</h3>', |
|
1020 | - 'desc' => __( 'Customer note emails are sent when you add a note to an invoice.', 'invoicing' ), |
|
1019 | + 'name' => '<h3>' . __('Customer Note', 'invoicing') . '</h3>', |
|
1020 | + 'desc' => __('Customer note emails are sent when you add a note to an invoice.', 'invoicing'), |
|
1021 | 1021 | 'type' => 'header', |
1022 | 1022 | ), |
1023 | 1023 | 'email_user_note_active' => array( |
1024 | 1024 | 'id' => 'email_user_note_active', |
1025 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
1026 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
1025 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
1026 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
1027 | 1027 | 'type' => 'checkbox', |
1028 | 1028 | 'std' => 1 |
1029 | 1029 | ), |
1030 | 1030 | 'email_user_note_subject' => array( |
1031 | 1031 | 'id' => 'email_user_note_subject', |
1032 | - 'name' => __( 'Subject', 'invoicing' ), |
|
1033 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
1032 | + 'name' => __('Subject', 'invoicing'), |
|
1033 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
1034 | 1034 | 'type' => 'text', |
1035 | - 'std' => __( '[{site_title}] Note added to your invoice #{invoice_number} from {invoice_date}', 'invoicing' ), |
|
1035 | + 'std' => __('[{site_title}] Note added to your invoice #{invoice_number} from {invoice_date}', 'invoicing'), |
|
1036 | 1036 | 'size' => 'large' |
1037 | 1037 | ), |
1038 | 1038 | 'email_user_note_heading' => array( |
1039 | 1039 | 'id' => 'email_user_note_heading', |
1040 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
1041 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
1040 | + 'name' => __('Email Heading', 'invoicing'), |
|
1041 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
1042 | 1042 | 'type' => 'text', |
1043 | - 'std' => __( 'A note has been added to your invoice', 'invoicing' ), |
|
1043 | + 'std' => __('A note has been added to your invoice', 'invoicing'), |
|
1044 | 1044 | 'size' => 'large' |
1045 | 1045 | ), |
1046 | 1046 | ), |
1047 | 1047 | 'overdue' => array( |
1048 | 1048 | 'email_overdue_header' => array( |
1049 | 1049 | 'id' => 'email_overdue_header', |
1050 | - 'name' => '<h3>' . __( 'Payment Reminder', 'invoicing' ) . '</h3>', |
|
1051 | - 'desc' => __( 'Payment reminder emails are sent to user automatically.', 'invoicing' ), |
|
1050 | + 'name' => '<h3>' . __('Payment Reminder', 'invoicing') . '</h3>', |
|
1051 | + 'desc' => __('Payment reminder emails are sent to user automatically.', 'invoicing'), |
|
1052 | 1052 | 'type' => 'header', |
1053 | 1053 | ), |
1054 | 1054 | 'email_overdue_active' => array( |
1055 | 1055 | 'id' => 'email_overdue_active', |
1056 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
1057 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
1056 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
1057 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
1058 | 1058 | 'type' => 'checkbox', |
1059 | 1059 | 'std' => 1 |
1060 | 1060 | ), |
1061 | 1061 | 'email_due_reminder_days' => array( |
1062 | 1062 | 'id' => 'email_due_reminder_days', |
1063 | - 'name' => __( 'When to Send', 'sliced-invoices' ), |
|
1064 | - 'desc' => __( 'Check when you would like payment reminders sent out.', 'invoicing' ), |
|
1063 | + 'name' => __('When to Send', 'sliced-invoices'), |
|
1064 | + 'desc' => __('Check when you would like payment reminders sent out.', 'invoicing'), |
|
1065 | 1065 | 'default' => '', |
1066 | 1066 | 'type' => 'multicheck', |
1067 | 1067 | 'options' => $overdue_days_options, |
1068 | 1068 | ), |
1069 | 1069 | 'email_overdue_subject' => array( |
1070 | 1070 | 'id' => 'email_overdue_subject', |
1071 | - 'name' => __( 'Subject', 'invoicing' ), |
|
1072 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
1071 | + 'name' => __('Subject', 'invoicing'), |
|
1072 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
1073 | 1073 | 'type' => 'text', |
1074 | - 'std' => __( '[{site_title}] Payment Reminder', 'invoicing' ), |
|
1074 | + 'std' => __('[{site_title}] Payment Reminder', 'invoicing'), |
|
1075 | 1075 | 'size' => 'large' |
1076 | 1076 | ), |
1077 | 1077 | 'email_overdue_heading' => array( |
1078 | 1078 | 'id' => 'email_overdue_heading', |
1079 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
1080 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
1079 | + 'name' => __('Email Heading', 'invoicing'), |
|
1080 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
1081 | 1081 | 'type' => 'text', |
1082 | - 'std' => __( 'Payment reminder for your invoice', 'invoicing' ), |
|
1082 | + 'std' => __('Payment reminder for your invoice', 'invoicing'), |
|
1083 | 1083 | 'size' => 'large' |
1084 | 1084 | ), |
1085 | 1085 | 'email_overdue_body' => array( |
1086 | 1086 | 'id' => 'email_overdue_body', |
1087 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
1088 | - 'desc' => __( 'The content of the email.', 'invoicing' ), |
|
1087 | + 'name' => __('Email Content', 'invoicing'), |
|
1088 | + 'desc' => __('The content of the email.', 'invoicing'), |
|
1089 | 1089 | 'type' => 'rich_editor', |
1090 | - 'std' => __( '<p>Hi {full_name},</p><p>This is just a friendly reminder your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To pay now for this invoice please use the following link: <a href="{invoice_pay_link}">Pay Now</a></p>', 'invoicing' ), |
|
1090 | + 'std' => __('<p>Hi {full_name},</p><p>This is just a friendly reminder your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To pay now for this invoice please use the following link: <a href="{invoice_pay_link}">Pay Now</a></p>', 'invoicing'), |
|
1091 | 1091 | 'class' => 'large', |
1092 | 1092 | 'size' => 10, |
1093 | 1093 | ), |
1094 | 1094 | ), |
1095 | 1095 | ); |
1096 | 1096 | |
1097 | - return apply_filters( 'wpinv_get_emails', $emails ); |
|
1097 | + return apply_filters('wpinv_get_emails', $emails); |
|
1098 | 1098 | } |
1099 | 1099 | |
1100 | -function wpinv_settings_emails( $settings = array() ) { |
|
1100 | +function wpinv_settings_emails($settings = array()) { |
|
1101 | 1101 | $emails = wpinv_get_emails(); |
1102 | 1102 | |
1103 | - if ( !empty( $emails ) ) { |
|
1104 | - foreach ( $emails as $key => $email ) { |
|
1103 | + if (!empty($emails)) { |
|
1104 | + foreach ($emails as $key => $email) { |
|
1105 | 1105 | $settings[$key] = $email; |
1106 | 1106 | } |
1107 | 1107 | } |
1108 | 1108 | |
1109 | - return apply_filters( 'wpinv_settings_get_emails', $settings ); |
|
1109 | + return apply_filters('wpinv_settings_get_emails', $settings); |
|
1110 | 1110 | } |
1111 | -add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 ); |
|
1111 | +add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1); |
|
1112 | 1112 | |
1113 | -function wpinv_settings_sections_emails( $settings ) { |
|
1113 | +function wpinv_settings_sections_emails($settings) { |
|
1114 | 1114 | $emails = wpinv_get_emails(); |
1115 | 1115 | |
1116 | 1116 | if (!empty($emails)) { |
1117 | - foreach ($emails as $key => $email) { |
|
1118 | - $settings[$key] = !empty( $email['email_' . $key . '_header']['name'] ) ? strip_tags( $email['email_' . $key . '_header']['name'] ) : $key; |
|
1117 | + foreach ($emails as $key => $email) { |
|
1118 | + $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : $key; |
|
1119 | 1119 | } |
1120 | 1120 | } |
1121 | 1121 | |
1122 | 1122 | return $settings; |
1123 | 1123 | } |
1124 | -add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 ); |
|
1124 | +add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1); |
|
1125 | 1125 | |
1126 | -function wpinv_email_is_enabled( $email_type ) { |
|
1126 | +function wpinv_email_is_enabled($email_type) { |
|
1127 | 1127 | $emails = wpinv_get_emails(); |
1128 | - $enabled = isset( $emails[$email_type] ) && wpinv_get_option( $email_type . '_active', 0 ) ? true : false; |
|
1128 | + $enabled = isset($emails[$email_type]) && wpinv_get_option($email_type . '_active', 0) ? true : false; |
|
1129 | 1129 | |
1130 | - return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type ); |
|
1130 | + return apply_filters('wpinv_email_is_enabled', $enabled, $email_type); |
|
1131 | 1131 | } |
1132 | 1132 | |
1133 | -function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1134 | - switch ( $email_type ) { |
|
1133 | +function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1134 | + switch ($email_type) { |
|
1135 | 1135 | case 'new_invoice': |
1136 | 1136 | case 'cancelled_invoice': |
1137 | 1137 | case 'failed_invoice': |
1138 | 1138 | $recipient = wpinv_get_admin_email(); |
1139 | 1139 | break; |
1140 | 1140 | default: |
1141 | - $invoice = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL ); |
|
1142 | - $recipient = !empty( $invoice ) ? $invoice->get_email() : ''; |
|
1141 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL); |
|
1142 | + $recipient = !empty($invoice) ? $invoice->get_email() : ''; |
|
1143 | 1143 | break; |
1144 | 1144 | } |
1145 | 1145 | |
1146 | - return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice ); |
|
1146 | + return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice); |
|
1147 | 1147 | } |
1148 | 1148 | |
1149 | -function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1150 | - $subject = wpinv_get_option( 'email_' . $email_type . '_subject' ); |
|
1149 | +function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1150 | + $subject = wpinv_get_option('email_' . $email_type . '_subject'); |
|
1151 | 1151 | |
1152 | - $subject = wpinv_email_format_text( $subject ); |
|
1152 | + $subject = wpinv_email_format_text($subject); |
|
1153 | 1153 | |
1154 | - return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice ); |
|
1154 | + return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice); |
|
1155 | 1155 | } |
1156 | 1156 | |
1157 | -function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1158 | - $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' ); |
|
1157 | +function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1158 | + $email_heading = wpinv_get_option('email_' . $email_type . '_heading'); |
|
1159 | 1159 | |
1160 | - $email_heading = wpinv_email_format_text( $email_heading ); |
|
1160 | + $email_heading = wpinv_email_format_text($email_heading); |
|
1161 | 1161 | |
1162 | - return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice ); |
|
1162 | + return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice); |
|
1163 | 1163 | } |
1164 | 1164 | |
1165 | -function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1166 | - $content = wpinv_get_option( 'email_' . $email_type . '_body' ); |
|
1165 | +function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1166 | + $content = wpinv_get_option('email_' . $email_type . '_body'); |
|
1167 | 1167 | |
1168 | - $content = wpinv_email_format_text( $content ); |
|
1168 | + $content = wpinv_email_format_text($content); |
|
1169 | 1169 | |
1170 | - return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice ); |
|
1170 | + return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice); |
|
1171 | 1171 | } |
1172 | 1172 | |
1173 | -function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1173 | +function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1174 | 1174 | $from_name = wpinv_mail_get_from_address(); |
1175 | 1175 | $from_email = wpinv_mail_get_from_address(); |
1176 | 1176 | |
1177 | - $invoice = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL ); |
|
1177 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL); |
|
1178 | 1178 | |
1179 | - $headers = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n"; |
|
1180 | - $headers .= "Reply-To: ". $from_email . "\r\n"; |
|
1179 | + $headers = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n"; |
|
1180 | + $headers .= "Reply-To: " . $from_email . "\r\n"; |
|
1181 | 1181 | $headers .= "Content-Type: " . wpinv_mail_get_content_type() . "\r\n"; |
1182 | 1182 | |
1183 | - return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice ); |
|
1183 | + return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice); |
|
1184 | 1184 | } |
1185 | 1185 | |
1186 | -function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1186 | +function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1187 | 1187 | $attachments = array(); |
1188 | 1188 | |
1189 | - return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice ); |
|
1189 | + return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice); |
|
1190 | 1190 | } |
1191 | 1191 | |
1192 | 1192 | function wpinv_email_global_vars() { |
@@ -1203,73 +1203,73 @@ discard block |
||
1203 | 1203 | $replace['sitename'] = $blogname; |
1204 | 1204 | $replace['site-title'] = $blogname; |
1205 | 1205 | |
1206 | - return apply_filters( 'wpinv_email_global_vars', array( $search, $replace ) ); |
|
1206 | + return apply_filters('wpinv_email_global_vars', array($search, $replace)); |
|
1207 | 1207 | } |
1208 | 1208 | |
1209 | -function wpinv_email_format_text( $content ) { |
|
1209 | +function wpinv_email_format_text($content) { |
|
1210 | 1210 | global $wpinv_email_search, $wpinv_email_replace; |
1211 | 1211 | |
1212 | - if ( empty( $wpinv_email_search ) ) { |
|
1212 | + if (empty($wpinv_email_search)) { |
|
1213 | 1213 | $wpinv_email_search = array(); |
1214 | 1214 | } |
1215 | 1215 | |
1216 | - if ( empty( $wpinv_email_replace ) ) { |
|
1216 | + if (empty($wpinv_email_replace)) { |
|
1217 | 1217 | $wpinv_email_replace = array(); |
1218 | 1218 | } |
1219 | 1219 | |
1220 | - $wpinv_email_search = (array)apply_filters( 'wpinv_email_format_text_search', $wpinv_email_search ); |
|
1221 | - $wpinv_email_replace = (array)apply_filters( 'wpinv_email_format_text_replace', $wpinv_email_replace ); |
|
1220 | + $wpinv_email_search = (array)apply_filters('wpinv_email_format_text_search', $wpinv_email_search); |
|
1221 | + $wpinv_email_replace = (array)apply_filters('wpinv_email_format_text_replace', $wpinv_email_replace); |
|
1222 | 1222 | |
1223 | 1223 | $global_vars = wpinv_email_global_vars(); |
1224 | 1224 | |
1225 | - $search = array_merge( $global_vars[0], $wpinv_email_search ); |
|
1226 | - $replace = array_merge( $global_vars[1], $wpinv_email_replace ); |
|
1225 | + $search = array_merge($global_vars[0], $wpinv_email_search); |
|
1226 | + $replace = array_merge($global_vars[1], $wpinv_email_replace); |
|
1227 | 1227 | |
1228 | - if ( empty( $search ) || empty( $replace ) || !is_array( $search ) || !is_array( $replace ) ) { |
|
1228 | + if (empty($search) || empty($replace) || !is_array($search) || !is_array($replace)) { |
|
1229 | 1229 | return $content; |
1230 | 1230 | } |
1231 | 1231 | |
1232 | - return str_replace( $search, $replace, $content ); |
|
1232 | + return str_replace($search, $replace, $content); |
|
1233 | 1233 | } |
1234 | 1234 | |
1235 | -function wpinv_email_style_body( $content ) { |
|
1235 | +function wpinv_email_style_body($content) { |
|
1236 | 1236 | // make sure we only inline CSS for html emails |
1237 | - if ( in_array( wpinv_mail_get_content_type(), array( 'text/html', 'multipart/alternative' ) ) && class_exists( 'DOMDocument' ) ) { |
|
1237 | + if (in_array(wpinv_mail_get_content_type(), array('text/html', 'multipart/alternative')) && class_exists('DOMDocument')) { |
|
1238 | 1238 | ob_start(); |
1239 | - wpinv_get_template( 'emails/wpinv-email-styles.php' ); |
|
1240 | - $css = apply_filters( 'wpinv_email_styles', ob_get_clean() ); |
|
1239 | + wpinv_get_template('emails/wpinv-email-styles.php'); |
|
1240 | + $css = apply_filters('wpinv_email_styles', ob_get_clean()); |
|
1241 | 1241 | |
1242 | 1242 | // apply CSS styles inline for picky email clients |
1243 | 1243 | try { |
1244 | - $emogrifier = new Emogrifier( $content, $css ); |
|
1244 | + $emogrifier = new Emogrifier($content, $css); |
|
1245 | 1245 | $content = $emogrifier->emogrify(); |
1246 | - } catch ( Exception $e ) { |
|
1247 | - wpinv_error_log( $e->getMessage(), 'emogrifier' ); |
|
1246 | + } catch (Exception $e) { |
|
1247 | + wpinv_error_log($e->getMessage(), 'emogrifier'); |
|
1248 | 1248 | } |
1249 | 1249 | } |
1250 | 1250 | return $content; |
1251 | 1251 | } |
1252 | 1252 | |
1253 | -function wpinv_email_header( $email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false ) { |
|
1254 | - wpinv_get_template( 'emails/wpinv-email-header.php', array( 'email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1253 | +function wpinv_email_header($email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false) { |
|
1254 | + wpinv_get_template('emails/wpinv-email-header.php', array('email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1255 | 1255 | } |
1256 | 1256 | |
1257 | 1257 | /** |
1258 | 1258 | * Get the email footer. |
1259 | 1259 | */ |
1260 | -function wpinv_email_footer( $invoice = array(), $email_type = '', $sent_to_admin = false ) { |
|
1261 | - wpinv_get_template( 'emails/wpinv-email-footer.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1260 | +function wpinv_email_footer($invoice = array(), $email_type = '', $sent_to_admin = false) { |
|
1261 | + wpinv_get_template('emails/wpinv-email-footer.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1262 | 1262 | } |
1263 | 1263 | |
1264 | -function wpinv_email_wrap_message( $message ) { |
|
1264 | +function wpinv_email_wrap_message($message) { |
|
1265 | 1265 | // Buffer |
1266 | 1266 | ob_start(); |
1267 | 1267 | |
1268 | - do_action( 'wpinv_email_header' ); |
|
1268 | + do_action('wpinv_email_header'); |
|
1269 | 1269 | |
1270 | - echo wpautop( wptexturize( $message ) ); |
|
1270 | + echo wpautop(wptexturize($message)); |
|
1271 | 1271 | |
1272 | - do_action( 'wpinv_email_footer' ); |
|
1272 | + do_action('wpinv_email_footer'); |
|
1273 | 1273 | |
1274 | 1274 | // Get contents |
1275 | 1275 | $message = ob_get_clean(); |
@@ -1277,86 +1277,86 @@ discard block |
||
1277 | 1277 | return $message; |
1278 | 1278 | } |
1279 | 1279 | |
1280 | -function wpinv_email_invoice_details( $invoice, $email_type = '', $sent_to_admin = false ) { |
|
1281 | - wpinv_get_template( 'emails/wpinv-email-invoice-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1280 | +function wpinv_email_invoice_details($invoice, $email_type = '', $sent_to_admin = false) { |
|
1281 | + wpinv_get_template('emails/wpinv-email-invoice-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1282 | 1282 | } |
1283 | 1283 | |
1284 | -function wpinv_email_invoice_items( $invoice, $email_type = '', $sent_to_admin = false ) { |
|
1285 | - wpinv_get_template( 'emails/wpinv-email-invoice-items.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1284 | +function wpinv_email_invoice_items($invoice, $email_type = '', $sent_to_admin = false) { |
|
1285 | + wpinv_get_template('emails/wpinv-email-invoice-items.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1286 | 1286 | } |
1287 | 1287 | |
1288 | -function wpinv_email_billing_details( $invoice, $email_type = '', $sent_to_admin = false ) { |
|
1289 | - wpinv_get_template( 'emails/wpinv-email-billing-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1288 | +function wpinv_email_billing_details($invoice, $email_type = '', $sent_to_admin = false) { |
|
1289 | + wpinv_get_template('emails/wpinv-email-billing-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1290 | 1290 | } |
1291 | 1291 | |
1292 | -function wpinv_send_customer_invoice( $data = array() ) { |
|
1293 | - $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL; |
|
1292 | +function wpinv_send_customer_invoice($data = array()) { |
|
1293 | + $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL; |
|
1294 | 1294 | |
1295 | - if ( empty( $invoice_id ) ) { |
|
1295 | + if (empty($invoice_id)) { |
|
1296 | 1296 | return; |
1297 | 1297 | } |
1298 | 1298 | |
1299 | - if ( !current_user_can( 'manage_options' ) ) { |
|
1300 | - wp_die( __( 'You do not have permission to send invoice notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
1299 | + if (!current_user_can('manage_options')) { |
|
1300 | + wp_die(__('You do not have permission to send invoice notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
1301 | 1301 | } |
1302 | 1302 | |
1303 | - $sent = wpinv_user_invoice_notification( $invoice_id ); |
|
1303 | + $sent = wpinv_user_invoice_notification($invoice_id); |
|
1304 | 1304 | |
1305 | 1305 | $status = $sent ? 'email_sent' : 'email_fail'; |
1306 | 1306 | |
1307 | - $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) ); |
|
1308 | - wp_redirect( $redirect ); |
|
1307 | + $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false)); |
|
1308 | + wp_redirect($redirect); |
|
1309 | 1309 | exit; |
1310 | 1310 | } |
1311 | -add_action( 'wpinv_send_invoice', 'wpinv_send_customer_invoice' ); |
|
1311 | +add_action('wpinv_send_invoice', 'wpinv_send_customer_invoice'); |
|
1312 | 1312 | |
1313 | -function wpinv_send_overdue_reminder( $data = array() ) { |
|
1314 | - $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL; |
|
1313 | +function wpinv_send_overdue_reminder($data = array()) { |
|
1314 | + $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL; |
|
1315 | 1315 | |
1316 | - if ( empty( $invoice_id ) ) { |
|
1316 | + if (empty($invoice_id)) { |
|
1317 | 1317 | return; |
1318 | 1318 | } |
1319 | 1319 | |
1320 | - if ( !current_user_can( 'manage_options' ) ) { |
|
1321 | - wp_die( __( 'You do not have permission to send reminder notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
1320 | + if (!current_user_can('manage_options')) { |
|
1321 | + wp_die(__('You do not have permission to send reminder notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
1322 | 1322 | } |
1323 | 1323 | |
1324 | - $sent = wpinv_send_payment_reminder_notification( $invoice_id ); |
|
1324 | + $sent = wpinv_send_payment_reminder_notification($invoice_id); |
|
1325 | 1325 | |
1326 | 1326 | $status = $sent ? 'email_sent' : 'email_fail'; |
1327 | 1327 | |
1328 | - $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) ); |
|
1329 | - wp_redirect( $redirect ); |
|
1328 | + $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false)); |
|
1329 | + wp_redirect($redirect); |
|
1330 | 1330 | exit; |
1331 | 1331 | } |
1332 | -add_action( 'wpinv_send_reminder', 'wpinv_send_overdue_reminder' ); |
|
1332 | +add_action('wpinv_send_reminder', 'wpinv_send_overdue_reminder'); |
|
1333 | 1333 | |
1334 | -function wpinv_send_customer_note_email( $data ) { |
|
1335 | - $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL; |
|
1334 | +function wpinv_send_customer_note_email($data) { |
|
1335 | + $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL; |
|
1336 | 1336 | |
1337 | - if ( empty( $invoice_id ) ) { |
|
1337 | + if (empty($invoice_id)) { |
|
1338 | 1338 | return; |
1339 | 1339 | } |
1340 | 1340 | |
1341 | - $sent = wpinv_user_note_notification( $invoice_id, $data ); |
|
1341 | + $sent = wpinv_user_note_notification($invoice_id, $data); |
|
1342 | 1342 | } |
1343 | -add_action( 'wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1 ); |
|
1343 | +add_action('wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1); |
|
1344 | 1344 | |
1345 | -function wpinv_add_notes_to_invoice_email( $invoice, $email_type, $sent_to_admin ) { |
|
1346 | - if ( !empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->ID, true ) ) { |
|
1347 | - $date_format = get_option( 'date_format' ); |
|
1348 | - $time_format = get_option( 'time_format' ); |
|
1345 | +function wpinv_add_notes_to_invoice_email($invoice, $email_type, $sent_to_admin) { |
|
1346 | + if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->ID, true)) { |
|
1347 | + $date_format = get_option('date_format'); |
|
1348 | + $time_format = get_option('time_format'); |
|
1349 | 1349 | ?> |
1350 | 1350 | <div id="wpinv-email-notes"> |
1351 | - <h3 class="wpinv-notes-t"><?php echo apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3> |
|
1351 | + <h3 class="wpinv-notes-t"><?php echo apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing')); ?></h3> |
|
1352 | 1352 | <ol class="wpinv-notes-lists"> |
1353 | 1353 | <?php |
1354 | - foreach ( $invoice_notes as $note ) { |
|
1355 | - $note_time = strtotime( $note->comment_date ); |
|
1354 | + foreach ($invoice_notes as $note) { |
|
1355 | + $note_time = strtotime($note->comment_date); |
|
1356 | 1356 | ?> |
1357 | 1357 | <li class="comment wpinv-note"> |
1358 | - <p class="wpinv-note-date meta"><?php printf( __( '%2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( $date_format, $note_time ), date_i18n( $time_format, $note_time ), $note_time ); ?></p> |
|
1359 | - <div class="wpinv-note-desc description"><?php echo wpautop( wptexturize( $note->comment_content ) ); ?></div> |
|
1358 | + <p class="wpinv-note-date meta"><?php printf(__('%2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n($date_format, $note_time), date_i18n($time_format, $note_time), $note_time); ?></p> |
|
1359 | + <div class="wpinv-note-desc description"><?php echo wpautop(wptexturize($note->comment_content)); ?></div> |
|
1360 | 1360 | </li> |
1361 | 1361 | <?php |
1362 | 1362 | } |
@@ -1365,21 +1365,21 @@ discard block |
||
1365 | 1365 | <?php |
1366 | 1366 | } |
1367 | 1367 | } |
1368 | -add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 ); |
|
1368 | +add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3); |
|
1369 | 1369 | |
1370 | 1370 | function wpinv_email_payment_reminders() { |
1371 | 1371 | global $wpi_auto_reminder; |
1372 | - if ( !wpinv_get_option( 'email_overdue_active' ) ) { |
|
1372 | + if (!wpinv_get_option('email_overdue_active')) { |
|
1373 | 1373 | return; |
1374 | 1374 | } |
1375 | 1375 | |
1376 | - if ( $reminder_days = wpinv_get_option( 'email_due_reminder_days' ) ) { |
|
1377 | - $reminder_days = is_array( $reminder_days ) ? array_values( $reminder_days ) : ''; |
|
1376 | + if ($reminder_days = wpinv_get_option('email_due_reminder_days')) { |
|
1377 | + $reminder_days = is_array($reminder_days) ? array_values($reminder_days) : ''; |
|
1378 | 1378 | |
1379 | - if ( empty( $reminder_days ) ) { |
|
1379 | + if (empty($reminder_days)) { |
|
1380 | 1380 | return; |
1381 | 1381 | } |
1382 | - $reminder_days = array_unique( array_map( 'absint', $reminder_days ) ); |
|
1382 | + $reminder_days = array_unique(array_map('absint', $reminder_days)); |
|
1383 | 1383 | |
1384 | 1384 | $args = array( |
1385 | 1385 | 'post_type' => 'wpi_invoice', |
@@ -1389,7 +1389,7 @@ discard block |
||
1389 | 1389 | 'meta_query' => array( |
1390 | 1390 | array( |
1391 | 1391 | 'key' => '_wpinv_due_date', |
1392 | - 'value' => array( '', 'none' ), |
|
1392 | + 'value' => array('', 'none'), |
|
1393 | 1393 | 'compare' => 'NOT IN', |
1394 | 1394 | ) |
1395 | 1395 | ), |
@@ -1398,64 +1398,64 @@ discard block |
||
1398 | 1398 | 'order' => 'ASC', |
1399 | 1399 | ); |
1400 | 1400 | |
1401 | - $invoices = get_posts( $args ); |
|
1401 | + $invoices = get_posts($args); |
|
1402 | 1402 | |
1403 | - if ( empty( $invoices ) ) { |
|
1403 | + if (empty($invoices)) { |
|
1404 | 1404 | return; |
1405 | 1405 | } |
1406 | 1406 | |
1407 | - $date_to_send = array(); |
|
1407 | + $date_to_send = array(); |
|
1408 | 1408 | |
1409 | - foreach ( $invoices as $id ) { |
|
1410 | - $due_date = get_post_meta( $id, '_wpinv_due_date', true ); |
|
1409 | + foreach ($invoices as $id) { |
|
1410 | + $due_date = get_post_meta($id, '_wpinv_due_date', true); |
|
1411 | 1411 | |
1412 | - foreach ( $reminder_days as $key => $days ) { |
|
1413 | - if ( $days !== '' ) { |
|
1414 | - $date_to_send[$id][] = date_i18n( 'Y-m-d', strtotime( $due_date ) + ( $days * DAY_IN_SECONDS ) ); |
|
1412 | + foreach ($reminder_days as $key => $days) { |
|
1413 | + if ($days !== '') { |
|
1414 | + $date_to_send[$id][] = date_i18n('Y-m-d', strtotime($due_date) + ($days * DAY_IN_SECONDS)); |
|
1415 | 1415 | } |
1416 | 1416 | } |
1417 | 1417 | } |
1418 | 1418 | |
1419 | - $today = date_i18n( 'Y-m-d' ); |
|
1419 | + $today = date_i18n('Y-m-d'); |
|
1420 | 1420 | $wpi_auto_reminder = true; |
1421 | 1421 | |
1422 | - foreach ( $date_to_send as $id => $values ) { |
|
1423 | - if ( in_array( $today, $values ) ) { |
|
1424 | - $sent = get_post_meta( $id, '_wpinv_reminder_sent', true ); |
|
1422 | + foreach ($date_to_send as $id => $values) { |
|
1423 | + if (in_array($today, $values)) { |
|
1424 | + $sent = get_post_meta($id, '_wpinv_reminder_sent', true); |
|
1425 | 1425 | |
1426 | - if ( isset( $sent ) && !empty( $sent ) ) { |
|
1427 | - if ( !in_array( $today, $sent ) ) { |
|
1428 | - do_action( 'wpinv_send_payment_reminder_notification', $id ); |
|
1426 | + if (isset($sent) && !empty($sent)) { |
|
1427 | + if (!in_array($today, $sent)) { |
|
1428 | + do_action('wpinv_send_payment_reminder_notification', $id); |
|
1429 | 1429 | } |
1430 | 1430 | } else { |
1431 | - do_action( 'wpinv_send_payment_reminder_notification', $id ); |
|
1431 | + do_action('wpinv_send_payment_reminder_notification', $id); |
|
1432 | 1432 | } |
1433 | 1433 | } |
1434 | 1434 | } |
1435 | 1435 | |
1436 | - $wpi_auto_reminder = false; |
|
1436 | + $wpi_auto_reminder = false; |
|
1437 | 1437 | } |
1438 | 1438 | } |
1439 | 1439 | |
1440 | -function wpinv_send_payment_reminder_notification( $invoice_id ) { |
|
1440 | +function wpinv_send_payment_reminder_notification($invoice_id) { |
|
1441 | 1441 | global $wpinv_email_search, $wpinv_email_replace; |
1442 | 1442 | |
1443 | 1443 | $email_type = 'overdue'; |
1444 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
1444 | + if (!wpinv_email_is_enabled($email_type)) { |
|
1445 | 1445 | return false; |
1446 | 1446 | } |
1447 | 1447 | |
1448 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1449 | - if ( empty( $invoice ) ) { |
|
1448 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1449 | + if (empty($invoice)) { |
|
1450 | 1450 | return false; |
1451 | 1451 | } |
1452 | 1452 | |
1453 | - if ( !$invoice->needs_payment() ) { |
|
1453 | + if (!$invoice->needs_payment()) { |
|
1454 | 1454 | return false; |
1455 | 1455 | } |
1456 | 1456 | |
1457 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
1458 | - if ( !is_email( $recipient ) ) { |
|
1457 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
1458 | + if (!is_email($recipient)) { |
|
1459 | 1459 | return false; |
1460 | 1460 | } |
1461 | 1461 | |
@@ -1471,70 +1471,70 @@ discard block |
||
1471 | 1471 | $replace = array(); |
1472 | 1472 | $replace['full_name'] = $invoice->get_user_full_name(); |
1473 | 1473 | $replace['invoice_number'] = $invoice->get_number(); |
1474 | - $replace['invoice_due_date']= $invoice->get_due_date( true ); |
|
1475 | - $replace['invoice_total'] = $invoice->get_total( true ); |
|
1476 | - $replace['invoice_link'] = $invoice->get_view_url( true ); |
|
1477 | - $replace['invoice_pay_link']= $invoice->get_checkout_payment_url( false, true ); |
|
1478 | - $replace['is_was'] = strtotime( $invoice->get_due_date() ) < strtotime( date_i18n( 'Y-m-d' ) ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ); |
|
1474 | + $replace['invoice_due_date'] = $invoice->get_due_date(true); |
|
1475 | + $replace['invoice_total'] = $invoice->get_total(true); |
|
1476 | + $replace['invoice_link'] = $invoice->get_view_url(true); |
|
1477 | + $replace['invoice_pay_link'] = $invoice->get_checkout_payment_url(false, true); |
|
1478 | + $replace['is_was'] = strtotime($invoice->get_due_date()) < strtotime(date_i18n('Y-m-d')) ? __('was', 'invoicing') : __('is', 'invoicing'); |
|
1479 | 1479 | |
1480 | 1480 | $wpinv_email_search = $search; |
1481 | 1481 | $wpinv_email_replace = $replace; |
1482 | 1482 | |
1483 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
1484 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
1485 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
1486 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
1483 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
1484 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
1485 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
1486 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
1487 | 1487 | |
1488 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
1488 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
1489 | 1489 | |
1490 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
1490 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
1491 | 1491 | 'invoice' => $invoice, |
1492 | 1492 | 'email_type' => $email_type, |
1493 | 1493 | 'email_heading' => $email_heading, |
1494 | 1494 | 'sent_to_admin' => false, |
1495 | 1495 | 'plain_text' => false, |
1496 | 1496 | 'message_body' => $message_body |
1497 | - ) ); |
|
1497 | + )); |
|
1498 | 1498 | |
1499 | - $content = wpinv_email_format_text( $content ); |
|
1499 | + $content = wpinv_email_format_text($content); |
|
1500 | 1500 | |
1501 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
1502 | - if ( $sent ) { |
|
1503 | - do_action( 'wpinv_payment_reminder_sent', $invoice_id, $invoice ); |
|
1501 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
1502 | + if ($sent) { |
|
1503 | + do_action('wpinv_payment_reminder_sent', $invoice_id, $invoice); |
|
1504 | 1504 | } |
1505 | 1505 | |
1506 | 1506 | return $sent; |
1507 | 1507 | } |
1508 | -add_action( 'wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1 ); |
|
1508 | +add_action('wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1); |
|
1509 | 1509 | |
1510 | -function wpinv_payment_reminder_sent( $invoice_id, $invoice ) { |
|
1510 | +function wpinv_payment_reminder_sent($invoice_id, $invoice) { |
|
1511 | 1511 | global $wpi_auto_reminder; |
1512 | 1512 | |
1513 | - $sent = get_post_meta( $invoice_id, '_wpinv_reminder_sent', true ); |
|
1513 | + $sent = get_post_meta($invoice_id, '_wpinv_reminder_sent', true); |
|
1514 | 1514 | |
1515 | - if ( empty( $sent ) ) { |
|
1515 | + if (empty($sent)) { |
|
1516 | 1516 | $sent = array(); |
1517 | 1517 | } |
1518 | - $sent[] = date_i18n( 'Y-m-d' ); |
|
1518 | + $sent[] = date_i18n('Y-m-d'); |
|
1519 | 1519 | |
1520 | - update_post_meta( $invoice_id, '_wpinv_reminder_sent', $sent ); |
|
1520 | + update_post_meta($invoice_id, '_wpinv_reminder_sent', $sent); |
|
1521 | 1521 | |
1522 | - if ( $wpi_auto_reminder ) { // Auto reminder note. |
|
1523 | - $note = __( 'Manual reminder sent to the user.', 'invoicing' ); |
|
1524 | - $invoice->add_note( $note, false, false, true ); |
|
1522 | + if ($wpi_auto_reminder) { // Auto reminder note. |
|
1523 | + $note = __('Manual reminder sent to the user.', 'invoicing'); |
|
1524 | + $invoice->add_note($note, false, false, true); |
|
1525 | 1525 | } else { // Menual reminder note. |
1526 | - $note = __( 'Manual reminder sent to the user.', 'invoicing' ); |
|
1527 | - $invoice->add_note( $note ); |
|
1526 | + $note = __('Manual reminder sent to the user.', 'invoicing'); |
|
1527 | + $invoice->add_note($note); |
|
1528 | 1528 | } |
1529 | 1529 | } |
1530 | -add_action( 'wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2 ); |
|
1530 | +add_action('wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2); |
|
1531 | 1531 | |
1532 | -function wpinv_email_before_note_details( $invoice, $email_type, $sent_to_admin, $customer_note ) { |
|
1532 | +function wpinv_email_before_note_details($invoice, $email_type, $sent_to_admin, $customer_note) { |
|
1533 | 1533 | if ("wpi_invoice" === $invoice->post_type && !empty($customer_note)) { |
1534 | 1534 | $before_note = ''; |
1535 | - $before_note .= __( 'Hello, a note has just been added to your invoice:', 'invoicing' ); |
|
1536 | - $before_note .= '<blockquote class="wpinv-note">'.wpautop( wptexturize( $customer_note ) ).'</blockquote>'; |
|
1537 | - $before_note .= __( 'For your reference, your invoice details are shown below.', 'invoicing' ); |
|
1535 | + $before_note .= __('Hello, a note has just been added to your invoice:', 'invoicing'); |
|
1536 | + $before_note .= '<blockquote class="wpinv-note">' . wpautop(wptexturize($customer_note)) . '</blockquote>'; |
|
1537 | + $before_note .= __('For your reference, your invoice details are shown below.', 'invoicing'); |
|
1538 | 1538 | echo $before_note; |
1539 | 1539 | } |
1540 | 1540 | } |
1541 | 1541 | \ No newline at end of file |