@@ -4,99 +4,99 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Displays an invoice. |
11 | 11 | * |
12 | 12 | * @param WPInv_Invoice $invoice. |
13 | 13 | */ |
14 | -function getpaid_invoice( $invoice ) { |
|
15 | - if ( ! empty( $invoice ) ) { |
|
16 | - wpinv_get_template( 'invoice/invoice.php', compact( 'invoice' ) ); |
|
14 | +function getpaid_invoice($invoice) { |
|
15 | + if (!empty($invoice)) { |
|
16 | + wpinv_get_template('invoice/invoice.php', compact('invoice')); |
|
17 | 17 | } |
18 | 18 | } |
19 | -add_action( 'getpaid_invoice', 'getpaid_invoice', 10 ); |
|
19 | +add_action('getpaid_invoice', 'getpaid_invoice', 10); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Displays the invoice footer. |
23 | 23 | */ |
24 | -function getpaid_invoice_footer( $invoice ) { |
|
25 | - if ( ! empty( $invoice ) ) { |
|
26 | - wpinv_get_template( 'invoice/footer.php', compact( 'invoice' ) ); |
|
24 | +function getpaid_invoice_footer($invoice) { |
|
25 | + if (!empty($invoice)) { |
|
26 | + wpinv_get_template('invoice/footer.php', compact('invoice')); |
|
27 | 27 | } |
28 | 28 | } |
29 | -add_action( 'getpaid_invoice_footer', 'getpaid_invoice_footer', 10 ); |
|
29 | +add_action('getpaid_invoice_footer', 'getpaid_invoice_footer', 10); |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Displays the invoice top bar. |
33 | 33 | */ |
34 | -function getpaid_invoice_header( $invoice ) { |
|
35 | - if ( ! empty( $invoice ) ) { |
|
36 | - wpinv_get_template( 'invoice/header.php', compact( 'invoice' ) ); |
|
34 | +function getpaid_invoice_header($invoice) { |
|
35 | + if (!empty($invoice)) { |
|
36 | + wpinv_get_template('invoice/header.php', compact('invoice')); |
|
37 | 37 | } |
38 | 38 | } |
39 | -add_action( 'getpaid_invoice_header', 'getpaid_invoice_header', 10 ); |
|
39 | +add_action('getpaid_invoice_header', 'getpaid_invoice_header', 10); |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Displays actions on the left side of the header. |
43 | 43 | */ |
44 | -function getpaid_invoice_header_left_actions( $invoice ) { |
|
45 | - if ( ! empty( $invoice ) ) { |
|
46 | - wpinv_get_template( 'invoice/header-left-actions.php', compact( 'invoice' ) ); |
|
44 | +function getpaid_invoice_header_left_actions($invoice) { |
|
45 | + if (!empty($invoice)) { |
|
46 | + wpinv_get_template('invoice/header-left-actions.php', compact('invoice')); |
|
47 | 47 | } |
48 | 48 | } |
49 | -add_action( 'getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10 ); |
|
49 | +add_action('getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10); |
|
50 | 50 | |
51 | 51 | /** |
52 | 52 | * Displays actions on the right side of the invoice top bar. |
53 | 53 | */ |
54 | -function getpaid_invoice_header_right_actions( $invoice ) { |
|
55 | - if ( ! empty( $invoice ) ) { |
|
56 | - wpinv_get_template( 'invoice/header-right-actions.php', compact( 'invoice' ) ); |
|
54 | +function getpaid_invoice_header_right_actions($invoice) { |
|
55 | + if (!empty($invoice)) { |
|
56 | + wpinv_get_template('invoice/header-right-actions.php', compact('invoice')); |
|
57 | 57 | } |
58 | 58 | } |
59 | -add_action( 'getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10 ); |
|
59 | +add_action('getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10); |
|
60 | 60 | |
61 | 61 | /** |
62 | 62 | * Displays the invoice title, logo etc. |
63 | 63 | */ |
64 | -function getpaid_invoice_details_top( $invoice ) { |
|
65 | - if ( ! empty( $invoice ) ) { |
|
66 | - wpinv_get_template( 'invoice/details-top.php', compact( 'invoice' ) ); |
|
64 | +function getpaid_invoice_details_top($invoice) { |
|
65 | + if (!empty($invoice)) { |
|
66 | + wpinv_get_template('invoice/details-top.php', compact('invoice')); |
|
67 | 67 | } |
68 | 68 | } |
69 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_top', 10 ); |
|
69 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_top', 10); |
|
70 | 70 | |
71 | 71 | /** |
72 | 72 | * Displays the company logo. |
73 | 73 | */ |
74 | -function getpaid_invoice_logo( $invoice ) { |
|
75 | - if ( ! empty( $invoice ) ) { |
|
76 | - wpinv_get_template( 'invoice/invoice-logo.php', compact( 'invoice' ) ); |
|
74 | +function getpaid_invoice_logo($invoice) { |
|
75 | + if (!empty($invoice)) { |
|
76 | + wpinv_get_template('invoice/invoice-logo.php', compact('invoice')); |
|
77 | 77 | } |
78 | 78 | } |
79 | -add_action( 'getpaid_invoice_details_top_left', 'getpaid_invoice_logo' ); |
|
79 | +add_action('getpaid_invoice_details_top_left', 'getpaid_invoice_logo'); |
|
80 | 80 | |
81 | 81 | /** |
82 | 82 | * Displays the type of invoice. |
83 | 83 | */ |
84 | -function getpaid_invoice_type( $invoice ) { |
|
85 | - if ( ! empty( $invoice ) ) { |
|
86 | - wpinv_get_template( 'invoice/invoice-type.php', compact( 'invoice' ) ); |
|
84 | +function getpaid_invoice_type($invoice) { |
|
85 | + if (!empty($invoice)) { |
|
86 | + wpinv_get_template('invoice/invoice-type.php', compact('invoice')); |
|
87 | 87 | } |
88 | 88 | } |
89 | -add_action( 'getpaid_invoice_details_top_right', 'getpaid_invoice_type' ); |
|
89 | +add_action('getpaid_invoice_details_top_right', 'getpaid_invoice_type'); |
|
90 | 90 | |
91 | 91 | /** |
92 | 92 | * Displays the invoice details. |
93 | 93 | */ |
94 | -function getpaid_invoice_details_main( $invoice ) { |
|
95 | - if ( ! empty( $invoice ) ) { |
|
96 | - wpinv_get_template( 'invoice/details.php', compact( 'invoice' ) ); |
|
94 | +function getpaid_invoice_details_main($invoice) { |
|
95 | + if (!empty($invoice)) { |
|
96 | + wpinv_get_template('invoice/details.php', compact('invoice')); |
|
97 | 97 | } |
98 | 98 | } |
99 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_main', 50 ); |
|
99 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_main', 50); |
|
100 | 100 | |
101 | 101 | /** |
102 | 102 | * Returns a path to the templates directory. |
@@ -125,8 +125,8 @@ discard block |
||
125 | 125 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
126 | 126 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
127 | 127 | */ |
128 | -function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
129 | - getpaid_template()->display_template( $template_name, $args, $template_path, $default_path ); |
|
128 | +function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
129 | + getpaid_template()->display_template($template_name, $args, $template_path, $default_path); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
140 | 140 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
141 | 141 | */ |
142 | -function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
143 | - return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
142 | +function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
143 | + return getpaid_template()->get_template($template_name, $args, $template_path, $default_path); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @return string |
150 | 150 | */ |
151 | 151 | function wpinv_template_path() { |
152 | - return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() ); |
|
152 | + return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name()); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | function wpinv_get_theme_template_dir_name() { |
161 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
161 | + return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing')); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -170,58 +170,58 @@ discard block |
||
170 | 170 | * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'. |
171 | 171 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
172 | 172 | */ |
173 | -function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
174 | - return getpaid_template()->locate_template( $template_name, $template_path, $default_path ); |
|
173 | +function wpinv_locate_template($template_name, $template_path = '', $default_path = '') { |
|
174 | + return getpaid_template()->locate_template($template_name, $template_path, $default_path); |
|
175 | 175 | } |
176 | 176 | |
177 | -function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
|
178 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
177 | +function wpinv_get_template_part($slug, $name = null, $load = true) { |
|
178 | + do_action('get_template_part_' . $slug, $slug, $name); |
|
179 | 179 | |
180 | 180 | // Setup possible parts |
181 | 181 | $templates = array(); |
182 | - if ( isset( $name ) ) { |
|
182 | + if (isset($name)) { |
|
183 | 183 | $templates[] = $slug . '-' . $name . '.php'; |
184 | 184 | } |
185 | 185 | $templates[] = $slug . '.php'; |
186 | 186 | |
187 | 187 | // Allow template parts to be filtered |
188 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
188 | + $templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name); |
|
189 | 189 | |
190 | 190 | // Return the part that is found |
191 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
191 | + return wpinv_locate_tmpl($templates, $load, false); |
|
192 | 192 | } |
193 | 193 | |
194 | -function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
|
194 | +function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) { |
|
195 | 195 | // No file found yet |
196 | 196 | $located = false; |
197 | 197 | |
198 | 198 | // Try to find a template file |
199 | - foreach ( (array)$template_names as $template_name ) { |
|
199 | + foreach ((array) $template_names as $template_name) { |
|
200 | 200 | |
201 | 201 | // Continue if template is empty |
202 | - if ( empty( $template_name ) ) { |
|
202 | + if (empty($template_name)) { |
|
203 | 203 | continue; |
204 | 204 | } |
205 | 205 | |
206 | 206 | // Trim off any slashes from the template name |
207 | - $template_name = ltrim( $template_name, '/' ); |
|
207 | + $template_name = ltrim($template_name, '/'); |
|
208 | 208 | |
209 | 209 | // try locating this template file by looping through the template paths |
210 | - foreach ( wpinv_get_theme_template_paths() as $template_path ) { |
|
210 | + foreach (wpinv_get_theme_template_paths() as $template_path) { |
|
211 | 211 | |
212 | - if ( file_exists( $template_path . $template_name ) ) { |
|
212 | + if (file_exists($template_path . $template_name)) { |
|
213 | 213 | $located = $template_path . $template_name; |
214 | 214 | break; |
215 | 215 | } |
216 | 216 | } |
217 | 217 | |
218 | - if ( ! empty( $located ) ) { |
|
218 | + if (!empty($located)) { |
|
219 | 219 | break; |
220 | 220 | } |
221 | 221 | } |
222 | 222 | |
223 | - if ( ( true == $load ) && ! empty( $located ) ) { |
|
224 | - load_template( $located, $require_once ); |
|
223 | + if ((true == $load) && !empty($located)) { |
|
224 | + load_template($located, $require_once); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | return $located; |
@@ -231,73 +231,73 @@ discard block |
||
231 | 231 | $template_dir = wpinv_get_theme_template_dir_name(); |
232 | 232 | |
233 | 233 | $file_paths = array( |
234 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
235 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
234 | + 1 => trailingslashit(get_stylesheet_directory()) . $template_dir, |
|
235 | + 10 => trailingslashit(get_template_directory()) . $template_dir, |
|
236 | 236 | 100 => wpinv_get_templates_dir(), |
237 | 237 | ); |
238 | 238 | |
239 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
239 | + $file_paths = apply_filters('wpinv_template_paths', $file_paths); |
|
240 | 240 | |
241 | 241 | // sort the file paths based on priority |
242 | - ksort( $file_paths, SORT_NUMERIC ); |
|
242 | + ksort($file_paths, SORT_NUMERIC); |
|
243 | 243 | |
244 | - return array_map( 'trailingslashit', $file_paths ); |
|
244 | + return array_map('trailingslashit', $file_paths); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | function wpinv_checkout_meta_tags() { |
248 | 248 | |
249 | 249 | $pages = array(); |
250 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
251 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
252 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
253 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
250 | + $pages[] = wpinv_get_option('success_page'); |
|
251 | + $pages[] = wpinv_get_option('failure_page'); |
|
252 | + $pages[] = wpinv_get_option('invoice_history_page'); |
|
253 | + $pages[] = wpinv_get_option('invoice_subscription_page'); |
|
254 | 254 | |
255 | - if ( ! wpinv_is_checkout() && ! is_page( $pages ) ) { |
|
255 | + if (!wpinv_is_checkout() && !is_page($pages)) { |
|
256 | 256 | return; |
257 | 257 | } |
258 | 258 | |
259 | 259 | echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
260 | 260 | } |
261 | -add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
|
261 | +add_action('wp_head', 'wpinv_checkout_meta_tags'); |
|
262 | 262 | |
263 | -function wpinv_add_body_classes( $class ) { |
|
264 | - $classes = (array)$class; |
|
263 | +function wpinv_add_body_classes($class) { |
|
264 | + $classes = (array) $class; |
|
265 | 265 | |
266 | - if ( wpinv_is_checkout() ) { |
|
266 | + if (wpinv_is_checkout()) { |
|
267 | 267 | $classes[] = 'wpinv-checkout'; |
268 | 268 | $classes[] = 'wpinv-page'; |
269 | 269 | } |
270 | 270 | |
271 | - if ( wpinv_is_success_page() ) { |
|
271 | + if (wpinv_is_success_page()) { |
|
272 | 272 | $classes[] = 'wpinv-success'; |
273 | 273 | $classes[] = 'wpinv-page'; |
274 | 274 | } |
275 | 275 | |
276 | - if ( wpinv_is_failed_transaction_page() ) { |
|
276 | + if (wpinv_is_failed_transaction_page()) { |
|
277 | 277 | $classes[] = 'wpinv-failed-transaction'; |
278 | 278 | $classes[] = 'wpinv-page'; |
279 | 279 | } |
280 | 280 | |
281 | - if ( wpinv_is_invoice_history_page() ) { |
|
281 | + if (wpinv_is_invoice_history_page()) { |
|
282 | 282 | $classes[] = 'wpinv-history'; |
283 | 283 | $classes[] = 'wpinv-page'; |
284 | 284 | } |
285 | 285 | |
286 | - if ( wpinv_is_subscriptions_history_page() ) { |
|
286 | + if (wpinv_is_subscriptions_history_page()) { |
|
287 | 287 | $classes[] = 'wpinv-subscription'; |
288 | 288 | $classes[] = 'wpinv-page'; |
289 | 289 | } |
290 | 290 | |
291 | - if ( wpinv_is_test_mode() ) { |
|
291 | + if (wpinv_is_test_mode()) { |
|
292 | 292 | $classes[] = 'wpinv-test-mode'; |
293 | 293 | $classes[] = 'wpinv-page'; |
294 | 294 | } |
295 | 295 | |
296 | - return array_unique( $classes ); |
|
296 | + return array_unique($classes); |
|
297 | 297 | } |
298 | -add_filter( 'body_class', 'wpinv_add_body_classes' ); |
|
298 | +add_filter('body_class', 'wpinv_add_body_classes'); |
|
299 | 299 | |
300 | -function wpinv_html_select( $args = array() ) { |
|
300 | +function wpinv_html_select($args = array()) { |
|
301 | 301 | $defaults = array( |
302 | 302 | 'options' => array(), |
303 | 303 | 'name' => null, |
@@ -306,8 +306,8 @@ discard block |
||
306 | 306 | 'selected' => 0, |
307 | 307 | 'placeholder' => null, |
308 | 308 | 'multiple' => false, |
309 | - 'show_option_all' => _x( 'All', 'all dropdown items', 'invoicing' ), |
|
310 | - 'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ), |
|
309 | + 'show_option_all' => _x('All', 'all dropdown items', 'invoicing'), |
|
310 | + 'show_option_none' => _x('None', 'no dropdown items', 'invoicing'), |
|
311 | 311 | 'data' => array(), |
312 | 312 | 'onchange' => null, |
313 | 313 | 'required' => false, |
@@ -315,79 +315,79 @@ discard block |
||
315 | 315 | 'readonly' => false, |
316 | 316 | ); |
317 | 317 | |
318 | - $args = wp_parse_args( $args, $defaults ); |
|
318 | + $args = wp_parse_args($args, $defaults); |
|
319 | 319 | |
320 | 320 | $attrs = array( |
321 | 321 | 'name' => $args['name'], |
322 | 322 | 'id' => $args['id'], |
323 | - 'class' => 'wpinv-select ' . implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ), |
|
324 | - 'multiple' => ! empty( $args['multiple'] ), |
|
325 | - 'readonly' => ! empty( $args['readonly'] ), |
|
326 | - 'disabled' => ! empty( $args['disabled'] ), |
|
327 | - 'required' => ! empty( $args['required'] ), |
|
328 | - 'onchange' => ! empty( $args['onchange'] ), |
|
323 | + 'class' => 'wpinv-select ' . implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))), |
|
324 | + 'multiple' => !empty($args['multiple']), |
|
325 | + 'readonly' => !empty($args['readonly']), |
|
326 | + 'disabled' => !empty($args['disabled']), |
|
327 | + 'required' => !empty($args['required']), |
|
328 | + 'onchange' => !empty($args['onchange']), |
|
329 | 329 | ); |
330 | 330 | |
331 | - if ( $args['placeholder'] ) { |
|
331 | + if ($args['placeholder']) { |
|
332 | 332 | $attrs['data-placeholder'] = $args['placeholder']; |
333 | 333 | } |
334 | 334 | |
335 | - if ( $args['onchange'] ) { |
|
335 | + if ($args['onchange']) { |
|
336 | 336 | $attrs['onchange'] = $args['onchange']; |
337 | 337 | } |
338 | 338 | |
339 | - foreach ( $args['data'] as $key => $value ) { |
|
339 | + foreach ($args['data'] as $key => $value) { |
|
340 | 340 | $attrs["data-$key"] = $value; |
341 | 341 | } |
342 | 342 | |
343 | 343 | echo '<select '; |
344 | 344 | |
345 | - foreach ( $attrs as $attr => $value ) { |
|
345 | + foreach ($attrs as $attr => $value) { |
|
346 | 346 | |
347 | - if ( false === $value ) { |
|
347 | + if (false === $value) { |
|
348 | 348 | continue; |
349 | 349 | } |
350 | 350 | |
351 | - if ( true === $value ) { |
|
352 | - echo ' ' . esc_attr( $attr ); |
|
351 | + if (true === $value) { |
|
352 | + echo ' ' . esc_attr($attr); |
|
353 | 353 | } else { |
354 | - echo ' ' . esc_attr( $attr ) . '="' . esc_attr( $value ) . '"'; |
|
354 | + echo ' ' . esc_attr($attr) . '="' . esc_attr($value) . '"'; |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | } |
358 | 358 | |
359 | 359 | echo '>'; |
360 | 360 | |
361 | - if ( $args['show_option_all'] ) { |
|
362 | - if ( $args['multiple'] ) { |
|
363 | - $selected = in_array( 0, $args['selected'] ); |
|
361 | + if ($args['show_option_all']) { |
|
362 | + if ($args['multiple']) { |
|
363 | + $selected = in_array(0, $args['selected']); |
|
364 | 364 | } else { |
365 | - $selected = empty( $args['selected'] ); |
|
365 | + $selected = empty($args['selected']); |
|
366 | 366 | } |
367 | - echo '<option value="all"' . selected( $selected, true, false ) . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
367 | + echo '<option value="all"' . selected($selected, true, false) . '>' . esc_html($args['show_option_all']) . '</option>'; |
|
368 | 368 | } |
369 | 369 | |
370 | - if ( ! empty( $args['options'] ) ) { |
|
370 | + if (!empty($args['options'])) { |
|
371 | 371 | |
372 | - if ( $args['show_option_none'] ) { |
|
373 | - if ( $args['multiple'] ) { |
|
374 | - $selected = in_array( '', $args['selected'] ); |
|
372 | + if ($args['show_option_none']) { |
|
373 | + if ($args['multiple']) { |
|
374 | + $selected = in_array('', $args['selected']); |
|
375 | 375 | } else { |
376 | 376 | $selected = $args['selected'] === ''; |
377 | 377 | } |
378 | 378 | |
379 | - echo '<option value=""' . selected( $selected, true, false ) . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
379 | + echo '<option value=""' . selected($selected, true, false) . '>' . esc_html($args['show_option_none']) . '</option>'; |
|
380 | 380 | } |
381 | 381 | |
382 | - foreach ( $args['options'] as $key => $option ) { |
|
382 | + foreach ($args['options'] as $key => $option) { |
|
383 | 383 | |
384 | - if ( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
385 | - $selected = in_array( $key, $args['selected'] ); |
|
384 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
385 | + $selected = in_array($key, $args['selected']); |
|
386 | 386 | } else { |
387 | 387 | $selected = $args['selected'] == $key; |
388 | 388 | } |
389 | 389 | |
390 | - echo '<option value="' . esc_attr( $key ) . '"' . selected( $selected, true, false ) . '>' . esc_html( $option ) . '</option>'; |
|
390 | + echo '<option value="' . esc_attr($key) . '"' . selected($selected, true, false) . '>' . esc_html($option) . '</option>'; |
|
391 | 391 | } |
392 | 392 | } |
393 | 393 | |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | |
396 | 396 | } |
397 | 397 | |
398 | -function wpinv_item_dropdown( $args = array() ) { |
|
398 | +function wpinv_item_dropdown($args = array()) { |
|
399 | 399 | $defaults = array( |
400 | 400 | 'name' => 'wpi_item', |
401 | 401 | 'id' => 'wpi_item', |
@@ -403,14 +403,14 @@ discard block |
||
403 | 403 | 'multiple' => false, |
404 | 404 | 'selected' => 0, |
405 | 405 | 'number' => -1, |
406 | - 'placeholder' => __( 'Choose a item', 'invoicing' ), |
|
407 | - 'data' => array( 'search-type' => 'item' ), |
|
406 | + 'placeholder' => __('Choose a item', 'invoicing'), |
|
407 | + 'data' => array('search-type' => 'item'), |
|
408 | 408 | 'show_option_all' => false, |
409 | 409 | 'show_option_none' => false, |
410 | 410 | 'show_recurring' => false, |
411 | 411 | ); |
412 | 412 | |
413 | - $args = wp_parse_args( $args, $defaults ); |
|
413 | + $args = wp_parse_args($args, $defaults); |
|
414 | 414 | |
415 | 415 | $item_args = array( |
416 | 416 | 'post_type' => 'wpi_item', |
@@ -419,40 +419,40 @@ discard block |
||
419 | 419 | 'posts_per_page' => $args['number'], |
420 | 420 | ); |
421 | 421 | |
422 | - $item_args = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults ); |
|
422 | + $item_args = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults); |
|
423 | 423 | |
424 | - $items = get_posts( $item_args ); |
|
424 | + $items = get_posts($item_args); |
|
425 | 425 | $options = array(); |
426 | - if ( $items ) { |
|
427 | - foreach ( $items as $item ) { |
|
428 | - $title = esc_html( $item->post_title ); |
|
426 | + if ($items) { |
|
427 | + foreach ($items as $item) { |
|
428 | + $title = esc_html($item->post_title); |
|
429 | 429 | |
430 | - if ( ! empty( $args['show_recurring'] ) ) { |
|
431 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
430 | + if (!empty($args['show_recurring'])) { |
|
431 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
432 | 432 | } |
433 | 433 | |
434 | - $options[ absint( $item->ID ) ] = $title; |
|
434 | + $options[absint($item->ID)] = $title; |
|
435 | 435 | } |
436 | 436 | } |
437 | 437 | |
438 | 438 | // This ensures that any selected items are included in the drop down |
439 | - if ( is_array( $args['selected'] ) ) { |
|
440 | - foreach ( $args['selected'] as $item ) { |
|
441 | - if ( ! in_array( $item, $options ) ) { |
|
442 | - $title = get_the_title( $item ); |
|
443 | - if ( ! empty( $args['show_recurring'] ) ) { |
|
444 | - $title .= wpinv_get_item_suffix( $item, false ); |
|
439 | + if (is_array($args['selected'])) { |
|
440 | + foreach ($args['selected'] as $item) { |
|
441 | + if (!in_array($item, $options)) { |
|
442 | + $title = get_the_title($item); |
|
443 | + if (!empty($args['show_recurring'])) { |
|
444 | + $title .= wpinv_get_item_suffix($item, false); |
|
445 | 445 | } |
446 | - $options[ $item ] = $title; |
|
446 | + $options[$item] = $title; |
|
447 | 447 | } |
448 | 448 | } |
449 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
450 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
451 | - $title = get_the_title( $args['selected'] ); |
|
452 | - if ( ! empty( $args['show_recurring'] ) ) { |
|
453 | - $title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
449 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
450 | + if (!in_array($args['selected'], $options)) { |
|
451 | + $title = get_the_title($args['selected']); |
|
452 | + if (!empty($args['show_recurring'])) { |
|
453 | + $title .= wpinv_get_item_suffix($args['selected'], false); |
|
454 | 454 | } |
455 | - $options[ $args['selected'] ] = get_the_title( $args['selected'] ); |
|
455 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
456 | 456 | } |
457 | 457 | } |
458 | 458 | |
@@ -488,16 +488,16 @@ discard block |
||
488 | 488 | ); |
489 | 489 | |
490 | 490 | $options = array(); |
491 | - if ( $items ) { |
|
492 | - foreach ( $items as $item ) { |
|
493 | - $options[ $item->ID ] = esc_html( $item->post_title ) . wpinv_get_item_suffix( $item->ID, false ); |
|
491 | + if ($items) { |
|
492 | + foreach ($items as $item) { |
|
493 | + $options[$item->ID] = esc_html($item->post_title) . wpinv_get_item_suffix($item->ID, false); |
|
494 | 494 | } |
495 | 495 | } |
496 | 496 | |
497 | 497 | return $options; |
498 | 498 | } |
499 | 499 | |
500 | -function wpinv_html_checkbox( $args = array() ) { |
|
500 | +function wpinv_html_checkbox($args = array()) { |
|
501 | 501 | $defaults = array( |
502 | 502 | 'name' => null, |
503 | 503 | 'current' => null, |
@@ -508,17 +508,17 @@ discard block |
||
508 | 508 | ), |
509 | 509 | ); |
510 | 510 | |
511 | - $args = wp_parse_args( $args, $defaults ); |
|
511 | + $args = wp_parse_args($args, $defaults); |
|
512 | 512 | |
513 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
513 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
514 | 514 | $attr = ''; |
515 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
515 | + if (!empty($args['options']['disabled'])) { |
|
516 | 516 | $attr .= ' disabled="disabled"'; |
517 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
517 | + } elseif (!empty($args['options']['readonly'])) { |
|
518 | 518 | $attr .= ' readonly'; |
519 | 519 | } |
520 | 520 | |
521 | - $output = '<input type="checkbox"' . $attr . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . esc_attr( $class ) . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />'; |
|
521 | + $output = '<input type="checkbox"' . $attr . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . esc_attr($class) . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />'; |
|
522 | 522 | |
523 | 523 | return $output; |
524 | 524 | } |
@@ -526,34 +526,34 @@ discard block |
||
526 | 526 | /** |
527 | 527 | * Displays a hidden field. |
528 | 528 | */ |
529 | -function getpaid_hidden_field( $name, $value ) { |
|
530 | - echo "<input type='hidden' name='" . esc_attr( $name ) . "' value='" . esc_attr( $value ) . "' />"; |
|
529 | +function getpaid_hidden_field($name, $value) { |
|
530 | + echo "<input type='hidden' name='" . esc_attr($name) . "' value='" . esc_attr($value) . "' />"; |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | /** |
534 | 534 | * Displays a submit field. |
535 | 535 | */ |
536 | -function getpaid_submit_field( $value, $name = 'submit', $class = 'btn-primary' ) { |
|
537 | - echo "<input type='submit' name='" . esc_attr( $name ) . "' value='" . esc_attr( $value ) . "' class='btn " . esc_attr( $class ) . "' />"; |
|
536 | +function getpaid_submit_field($value, $name = 'submit', $class = 'btn-primary') { |
|
537 | + echo "<input type='submit' name='" . esc_attr($name) . "' value='" . esc_attr($value) . "' class='btn " . esc_attr($class) . "' />"; |
|
538 | 538 | } |
539 | 539 | |
540 | -function wpinv_html_text( $args = array() ) { |
|
540 | +function wpinv_html_text($args = array()) { |
|
541 | 541 | // Backwards compatibility |
542 | - if ( func_num_args() > 1 ) { |
|
542 | + if (func_num_args() > 1) { |
|
543 | 543 | $args = func_get_args(); |
544 | 544 | |
545 | 545 | $name = $args[0]; |
546 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
547 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
548 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
546 | + $value = isset($args[1]) ? $args[1] : ''; |
|
547 | + $label = isset($args[2]) ? $args[2] : ''; |
|
548 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | $defaults = array( |
552 | 552 | 'id' => '', |
553 | - 'name' => isset( $name ) ? $name : 'text', |
|
554 | - 'value' => isset( $value ) ? $value : null, |
|
555 | - 'label' => isset( $label ) ? $label : null, |
|
556 | - 'desc' => isset( $desc ) ? $desc : null, |
|
553 | + 'name' => isset($name) ? $name : 'text', |
|
554 | + 'value' => isset($value) ? $value : null, |
|
555 | + 'label' => isset($label) ? $label : null, |
|
556 | + 'desc' => isset($desc) ? $desc : null, |
|
557 | 557 | 'placeholder' => '', |
558 | 558 | 'class' => 'regular-text', |
559 | 559 | 'disabled' => false, |
@@ -563,41 +563,41 @@ discard block |
||
563 | 563 | 'data' => false, |
564 | 564 | ); |
565 | 565 | |
566 | - $args = wp_parse_args( $args, $defaults ); |
|
566 | + $args = wp_parse_args($args, $defaults); |
|
567 | 567 | |
568 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
568 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
569 | 569 | $options = ''; |
570 | - if ( $args['required'] ) { |
|
570 | + if ($args['required']) { |
|
571 | 571 | $options .= ' required="required"'; |
572 | 572 | } |
573 | - if ( $args['readonly'] ) { |
|
573 | + if ($args['readonly']) { |
|
574 | 574 | $options .= ' readonly'; |
575 | 575 | } |
576 | - if ( $args['readonly'] ) { |
|
576 | + if ($args['readonly']) { |
|
577 | 577 | $options .= ' readonly'; |
578 | 578 | } |
579 | 579 | |
580 | 580 | $data = ''; |
581 | - if ( ! empty( $args['data'] ) ) { |
|
582 | - foreach ( $args['data'] as $key => $value ) { |
|
583 | - $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
581 | + if (!empty($args['data'])) { |
|
582 | + foreach ($args['data'] as $key => $value) { |
|
583 | + $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" '; |
|
584 | 584 | } |
585 | 585 | } |
586 | 586 | |
587 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
588 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
589 | - if ( ! empty( $args['desc'] ) ) { |
|
590 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
587 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
588 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>'; |
|
589 | + if (!empty($args['desc'])) { |
|
590 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
591 | 591 | } |
592 | 592 | |
593 | - $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>'; |
|
593 | + $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>'; |
|
594 | 594 | |
595 | 595 | $output .= '</span>'; |
596 | 596 | |
597 | 597 | return $output; |
598 | 598 | } |
599 | 599 | |
600 | -function wpinv_html_textarea( $args = array() ) { |
|
600 | +function wpinv_html_textarea($args = array()) { |
|
601 | 601 | $defaults = array( |
602 | 602 | 'name' => 'textarea', |
603 | 603 | 'value' => null, |
@@ -608,31 +608,31 @@ discard block |
||
608 | 608 | 'placeholder' => '', |
609 | 609 | ); |
610 | 610 | |
611 | - $args = wp_parse_args( $args, $defaults ); |
|
611 | + $args = wp_parse_args($args, $defaults); |
|
612 | 612 | |
613 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
613 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
614 | 614 | $disabled = ''; |
615 | - if ( $args['disabled'] ) { |
|
615 | + if ($args['disabled']) { |
|
616 | 616 | $disabled = ' disabled="disabled"'; |
617 | 617 | } |
618 | 618 | |
619 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
620 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
621 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
619 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
620 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>'; |
|
621 | + $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>'; |
|
622 | 622 | |
623 | - if ( ! empty( $args['desc'] ) ) { |
|
624 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
623 | + if (!empty($args['desc'])) { |
|
624 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
625 | 625 | } |
626 | 626 | $output .= '</span>'; |
627 | 627 | |
628 | 628 | return $output; |
629 | 629 | } |
630 | 630 | |
631 | -function wpinv_html_ajax_user_search( $args = array() ) { |
|
631 | +function wpinv_html_ajax_user_search($args = array()) { |
|
632 | 632 | $defaults = array( |
633 | 633 | 'name' => 'user_id', |
634 | 634 | 'value' => null, |
635 | - 'placeholder' => __( 'Enter username', 'invoicing' ), |
|
635 | + 'placeholder' => __('Enter username', 'invoicing'), |
|
636 | 636 | 'label' => null, |
637 | 637 | 'desc' => null, |
638 | 638 | 'class' => '', |
@@ -641,13 +641,13 @@ discard block |
||
641 | 641 | 'data' => false, |
642 | 642 | ); |
643 | 643 | |
644 | - $args = wp_parse_args( $args, $defaults ); |
|
644 | + $args = wp_parse_args($args, $defaults); |
|
645 | 645 | |
646 | 646 | $args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
647 | 647 | |
648 | 648 | $output = '<span class="wpinv_user_search_wrap">'; |
649 | - $output .= wpinv_html_text( $args ); |
|
650 | - $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>'; |
|
649 | + $output .= wpinv_html_text($args); |
|
650 | + $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>'; |
|
651 | 651 | $output .= '</span>'; |
652 | 652 | |
653 | 653 | return $output; |
@@ -658,44 +658,44 @@ discard block |
||
658 | 658 | * |
659 | 659 | * @param string $template the template that is currently being used. |
660 | 660 | */ |
661 | -function wpinv_template( $template ) { |
|
661 | +function wpinv_template($template) { |
|
662 | 662 | global $post; |
663 | 663 | |
664 | - if ( ! is_admin() && ( is_single() || is_404() ) && ! empty( $post->ID ) && getpaid_is_invoice_post_type( get_post_type( $post->ID ) ) ) { |
|
664 | + if (!is_admin() && (is_single() || is_404()) && !empty($post->ID) && getpaid_is_invoice_post_type(get_post_type($post->ID))) { |
|
665 | 665 | |
666 | 666 | // If the user can view this invoice, display it. |
667 | - if ( wpinv_user_can_view_invoice( $post->ID ) ) { |
|
667 | + if (wpinv_user_can_view_invoice($post->ID)) { |
|
668 | 668 | |
669 | - return wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
669 | + return wpinv_get_template_part('wpinv-invoice-print', false, false); |
|
670 | 670 | |
671 | 671 | // Else display an error message. |
672 | 672 | } else { |
673 | 673 | |
674 | - return wpinv_get_template_part( 'wpinv-invalid-access', false, false ); |
|
674 | + return wpinv_get_template_part('wpinv-invalid-access', false, false); |
|
675 | 675 | |
676 | 676 | } |
677 | 677 | } |
678 | 678 | |
679 | 679 | return $template; |
680 | 680 | } |
681 | -add_filter( 'template_include', 'wpinv_template', 1000, 1 ); |
|
681 | +add_filter('template_include', 'wpinv_template', 1000, 1); |
|
682 | 682 | |
683 | 683 | function wpinv_get_business_address() { |
684 | 684 | $business_address = wpinv_store_address(); |
685 | - $business_address = ! empty( $business_address ) ? wp_kses_post( wpautop( $business_address ) ) : ''; |
|
685 | + $business_address = !empty($business_address) ? wp_kses_post(wpautop($business_address)) : ''; |
|
686 | 686 | |
687 | 687 | $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
688 | 688 | |
689 | - return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
689 | + return apply_filters('wpinv_get_business_address', $business_address); |
|
690 | 690 | } |
691 | 691 | |
692 | 692 | /** |
693 | 693 | * Displays the company address. |
694 | 694 | */ |
695 | 695 | function wpinv_display_from_address() { |
696 | - wpinv_get_template( 'invoice/company-address.php' ); |
|
696 | + wpinv_get_template('invoice/company-address.php'); |
|
697 | 697 | } |
698 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_from_address', 10 ); |
|
698 | +add_action('getpaid_invoice_details_left', 'wpinv_display_from_address', 10); |
|
699 | 699 | |
700 | 700 | /** |
701 | 701 | * Generates a watermark text for an invoice. |
@@ -703,9 +703,9 @@ discard block |
||
703 | 703 | * @param WPInv_Invoice $invoice |
704 | 704 | * @return string |
705 | 705 | */ |
706 | -function wpinv_watermark( $invoice ) { |
|
707 | - $watermark = wpinv_get_watermark( $invoice ); |
|
708 | - return apply_filters( 'wpinv_get_watermark', $watermark, $invoice ); |
|
706 | +function wpinv_watermark($invoice) { |
|
707 | + $watermark = wpinv_get_watermark($invoice); |
|
708 | + return apply_filters('wpinv_get_watermark', $watermark, $invoice); |
|
709 | 709 | } |
710 | 710 | |
711 | 711 | /** |
@@ -714,37 +714,37 @@ discard block |
||
714 | 714 | * @param WPInv_Invoice $invoice |
715 | 715 | * @return string |
716 | 716 | */ |
717 | -function wpinv_get_watermark( $invoice ) { |
|
717 | +function wpinv_get_watermark($invoice) { |
|
718 | 718 | return $invoice->get_status_nicename(); |
719 | 719 | } |
720 | 720 | |
721 | 721 | /** |
722 | 722 | * @deprecated |
723 | 723 | */ |
724 | -function wpinv_display_invoice_details( $invoice ) { |
|
725 | - return getpaid_invoice_meta( $invoice ); |
|
724 | +function wpinv_display_invoice_details($invoice) { |
|
725 | + return getpaid_invoice_meta($invoice); |
|
726 | 726 | } |
727 | 727 | |
728 | 728 | /** |
729 | 729 | * Displays invoice meta. |
730 | 730 | */ |
731 | -function getpaid_invoice_meta( $invoice ) { |
|
731 | +function getpaid_invoice_meta($invoice) { |
|
732 | 732 | |
733 | - $invoice = new WPInv_Invoice( $invoice ); |
|
733 | + $invoice = new WPInv_Invoice($invoice); |
|
734 | 734 | |
735 | 735 | // Ensure that we have an invoice. |
736 | - if ( 0 == $invoice->get_id() ) { |
|
736 | + if (0 == $invoice->get_id()) { |
|
737 | 737 | return; |
738 | 738 | } |
739 | 739 | |
740 | 740 | // Get the invoice meta. |
741 | - $meta = getpaid_get_invoice_meta( $invoice ); |
|
741 | + $meta = getpaid_get_invoice_meta($invoice); |
|
742 | 742 | |
743 | 743 | // Display the meta. |
744 | - wpinv_get_template( 'invoice/invoice-meta.php', compact( 'invoice', 'meta' ) ); |
|
744 | + wpinv_get_template('invoice/invoice-meta.php', compact('invoice', 'meta')); |
|
745 | 745 | |
746 | 746 | } |
747 | -add_action( 'getpaid_invoice_details_right', 'getpaid_invoice_meta', 10 ); |
|
747 | +add_action('getpaid_invoice_details_right', 'getpaid_invoice_meta', 10); |
|
748 | 748 | |
749 | 749 | /** |
750 | 750 | * Retrieves the address markup to use on Invoices. |
@@ -756,29 +756,29 @@ discard block |
||
756 | 756 | * @param string $separator How to separate address lines. |
757 | 757 | * @return string |
758 | 758 | */ |
759 | -function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) { |
|
759 | +function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') { |
|
760 | 760 | |
761 | 761 | // Retrieve the address markup... |
762 | - $country = empty( $billing_details['country'] ) ? '' : $billing_details['country']; |
|
763 | - $format = wpinv_get_full_address_format( $country ); |
|
762 | + $country = empty($billing_details['country']) ? '' : $billing_details['country']; |
|
763 | + $format = wpinv_get_full_address_format($country); |
|
764 | 764 | |
765 | 765 | // ... and the replacements. |
766 | - $replacements = wpinv_get_invoice_address_replacements( $billing_details ); |
|
766 | + $replacements = wpinv_get_invoice_address_replacements($billing_details); |
|
767 | 767 | |
768 | - $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
|
768 | + $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format); |
|
769 | 769 | |
770 | 770 | // Remove unavailable tags. |
771 | - $formatted_address = preg_replace( '/\{\{\w+\}\}/', '', $formatted_address ); |
|
771 | + $formatted_address = preg_replace('/\{\{\w+\}\}/', '', $formatted_address); |
|
772 | 772 | |
773 | 773 | // Clean up white space. |
774 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
775 | - $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
|
774 | + $formatted_address = preg_replace('/ +/', ' ', trim($formatted_address)); |
|
775 | + $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address); |
|
776 | 776 | |
777 | 777 | // Break newlines apart and remove empty lines/trim commas and white space. |
778 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
778 | + $formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address))); |
|
779 | 779 | |
780 | 780 | // Add html breaks. |
781 | - $formatted_address = implode( $separator, $formatted_address ); |
|
781 | + $formatted_address = implode($separator, $formatted_address); |
|
782 | 782 | |
783 | 783 | // We're done! |
784 | 784 | return $formatted_address; |
@@ -790,118 +790,118 @@ discard block |
||
790 | 790 | * |
791 | 791 | * @param WPInv_Invoice $invoice |
792 | 792 | */ |
793 | -function wpinv_display_to_address( $invoice = 0 ) { |
|
794 | - if ( ! empty( $invoice ) ) { |
|
795 | - wpinv_get_template( 'invoice/billing-address.php', compact( 'invoice' ) ); |
|
793 | +function wpinv_display_to_address($invoice = 0) { |
|
794 | + if (!empty($invoice)) { |
|
795 | + wpinv_get_template('invoice/billing-address.php', compact('invoice')); |
|
796 | 796 | } |
797 | 797 | } |
798 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_to_address', 40 ); |
|
798 | +add_action('getpaid_invoice_details_left', 'wpinv_display_to_address', 40); |
|
799 | 799 | |
800 | 800 | |
801 | 801 | /** |
802 | 802 | * Displays invoice line items. |
803 | 803 | */ |
804 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
804 | +function wpinv_display_line_items($invoice_id = 0) { |
|
805 | 805 | |
806 | 806 | // Prepare the invoice. |
807 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
807 | + $invoice = new WPInv_Invoice($invoice_id); |
|
808 | 808 | |
809 | 809 | // Abort if there is no invoice. |
810 | - if ( 0 == $invoice->get_id() ) { |
|
810 | + if (0 == $invoice->get_id()) { |
|
811 | 811 | return; |
812 | 812 | } |
813 | 813 | |
814 | 814 | // Line item columns. |
815 | - $columns = getpaid_invoice_item_columns( $invoice ); |
|
816 | - $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice ); |
|
815 | + $columns = getpaid_invoice_item_columns($invoice); |
|
816 | + $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice); |
|
817 | 817 | |
818 | - wpinv_get_template( 'invoice/line-items.php', compact( 'invoice', 'columns' ) ); |
|
818 | + wpinv_get_template('invoice/line-items.php', compact('invoice', 'columns')); |
|
819 | 819 | } |
820 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_line_items', 10 ); |
|
820 | +add_action('getpaid_invoice_line_items', 'wpinv_display_line_items', 10); |
|
821 | 821 | |
822 | 822 | /** |
823 | 823 | * Displays invoice subscriptions. |
824 | 824 | * |
825 | 825 | * @param WPInv_Invoice $invoice |
826 | 826 | */ |
827 | -function getpaid_display_invoice_subscriptions( $invoice ) { |
|
827 | +function getpaid_display_invoice_subscriptions($invoice) { |
|
828 | 828 | |
829 | 829 | // Subscriptions. |
830 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
830 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
831 | 831 | |
832 | - if ( empty( $subscriptions ) || ! $invoice->is_recurring() ) { |
|
832 | + if (empty($subscriptions) || !$invoice->is_recurring()) { |
|
833 | 833 | return; |
834 | 834 | } |
835 | 835 | |
836 | - $main_subscription = getpaid_get_invoice_subscription( $invoice ); |
|
836 | + $main_subscription = getpaid_get_invoice_subscription($invoice); |
|
837 | 837 | |
838 | 838 | // Display related subscriptions. |
839 | - if ( is_array( $subscriptions ) ) { |
|
840 | - printf( '<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__( 'Related Subscriptions', 'invoicing' ) ); |
|
841 | - getpaid_admin_subscription_related_subscriptions_metabox( $main_subscription, false ); |
|
839 | + if (is_array($subscriptions)) { |
|
840 | + printf('<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__('Related Subscriptions', 'invoicing')); |
|
841 | + getpaid_admin_subscription_related_subscriptions_metabox($main_subscription, false); |
|
842 | 842 | } |
843 | 843 | |
844 | - if ( $main_subscription->get_total_payments() > 1 ) { |
|
845 | - printf( '<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__( 'Related Invoices', 'invoicing' ) ); |
|
846 | - getpaid_admin_subscription_invoice_details_metabox( $main_subscription, false ); |
|
844 | + if ($main_subscription->get_total_payments() > 1) { |
|
845 | + printf('<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__('Related Invoices', 'invoicing')); |
|
846 | + getpaid_admin_subscription_invoice_details_metabox($main_subscription, false); |
|
847 | 847 | } |
848 | 848 | |
849 | 849 | } |
850 | -add_action( 'getpaid_invoice_line_items', 'getpaid_display_invoice_subscriptions', 55 ); |
|
851 | -add_action( 'wpinv_receipt_end', 'getpaid_display_invoice_subscriptions', 11 ); |
|
850 | +add_action('getpaid_invoice_line_items', 'getpaid_display_invoice_subscriptions', 55); |
|
851 | +add_action('wpinv_receipt_end', 'getpaid_display_invoice_subscriptions', 11); |
|
852 | 852 | |
853 | 853 | /** |
854 | 854 | * Displays invoice notices on invoices. |
855 | 855 | */ |
856 | 856 | function wpinv_display_invoice_notice() { |
857 | 857 | |
858 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
859 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
858 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
859 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
860 | 860 | |
861 | - if ( empty( $label ) && empty( $notice ) ) { |
|
861 | + if (empty($label) && empty($notice)) { |
|
862 | 862 | return; |
863 | 863 | } |
864 | 864 | |
865 | 865 | echo '<div class="mt-4 mb-4 wpinv-vat-notice">'; |
866 | 866 | |
867 | - if ( ! empty( $label ) ) { |
|
868 | - echo "<h5>" . esc_html( $label ) . "</h5>"; |
|
867 | + if (!empty($label)) { |
|
868 | + echo "<h5>" . esc_html($label) . "</h5>"; |
|
869 | 869 | } |
870 | 870 | |
871 | - if ( ! empty( $notice ) ) { |
|
872 | - echo '<small class="form-text text-muted">' . wp_kses_post( wpautop( wptexturize( $notice ) ) ) . '</small>'; |
|
871 | + if (!empty($notice)) { |
|
872 | + echo '<small class="form-text text-muted">' . wp_kses_post(wpautop(wptexturize($notice))) . '</small>'; |
|
873 | 873 | } |
874 | 874 | |
875 | 875 | echo '</div>'; |
876 | 876 | } |
877 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100 ); |
|
877 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100); |
|
878 | 878 | |
879 | 879 | /** |
880 | 880 | * @param WPInv_Invoice $invoice |
881 | 881 | */ |
882 | -function wpinv_display_invoice_notes( $invoice ) { |
|
882 | +function wpinv_display_invoice_notes($invoice) { |
|
883 | 883 | |
884 | 884 | // Retrieve the notes. |
885 | - $notes = wpinv_get_invoice_notes( $invoice->get_id(), 'customer' ); |
|
885 | + $notes = wpinv_get_invoice_notes($invoice->get_id(), 'customer'); |
|
886 | 886 | |
887 | 887 | // Abort if we have non. |
888 | - if ( empty( $notes ) ) { |
|
888 | + if (empty($notes)) { |
|
889 | 889 | return; |
890 | 890 | } |
891 | 891 | |
892 | 892 | // Echo the note. |
893 | 893 | echo '<div class="getpaid-invoice-notes-wrapper position-relative my-4">'; |
894 | - echo '<h2 class="getpaid-invoice-notes-title mb-1 p-0 h4">' . esc_html__( 'Notes', 'invoicing' ) . '</h2>'; |
|
894 | + echo '<h2 class="getpaid-invoice-notes-title mb-1 p-0 h4">' . esc_html__('Notes', 'invoicing') . '</h2>'; |
|
895 | 895 | echo '<ul class="getpaid-invoice-notes text-break overflow-auto list-unstyled p-0 m-0">'; |
896 | 896 | |
897 | - foreach ( $notes as $note ) { |
|
898 | - wpinv_get_invoice_note_line_item( $note ); |
|
897 | + foreach ($notes as $note) { |
|
898 | + wpinv_get_invoice_note_line_item($note); |
|
899 | 899 | } |
900 | 900 | |
901 | 901 | echo '</ul>'; |
902 | 902 | echo '</div>'; |
903 | 903 | } |
904 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60 ); |
|
904 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60); |
|
905 | 905 | |
906 | 906 | /** |
907 | 907 | * Loads scripts on our invoice templates. |
@@ -909,32 +909,32 @@ discard block |
||
909 | 909 | function wpinv_display_style() { |
910 | 910 | |
911 | 911 | // Make sure that all scripts have been loaded. |
912 | - if ( ! did_action( 'wp_enqueue_scripts' ) ) { |
|
913 | - do_action( 'wp_enqueue_scripts' ); |
|
912 | + if (!did_action('wp_enqueue_scripts')) { |
|
913 | + do_action('wp_enqueue_scripts'); |
|
914 | 914 | } |
915 | 915 | |
916 | 916 | // Register the invoices style. |
917 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice.css' ) ); |
|
917 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice.css')); |
|
918 | 918 | |
919 | 919 | // Load required styles |
920 | - wp_print_styles( 'wpinv-single-style' ); |
|
921 | - wp_print_styles( 'ayecode-ui' ); |
|
920 | + wp_print_styles('wpinv-single-style'); |
|
921 | + wp_print_styles('ayecode-ui'); |
|
922 | 922 | |
923 | 923 | // Maybe load custom css. |
924 | - $custom_css = wpinv_get_option( 'template_custom_css' ); |
|
924 | + $custom_css = wpinv_get_option('template_custom_css'); |
|
925 | 925 | |
926 | - if ( isset( $custom_css ) && ! empty( $custom_css ) ) { |
|
927 | - $custom_css = wp_kses( $custom_css, array( '\'', '\"' ) ); |
|
928 | - $custom_css = str_replace( '>', '>', $custom_css ); |
|
926 | + if (isset($custom_css) && !empty($custom_css)) { |
|
927 | + $custom_css = wp_kses($custom_css, array('\'', '\"')); |
|
928 | + $custom_css = str_replace('>', '>', $custom_css); |
|
929 | 929 | echo '<style type="text/css">'; |
930 | - echo wp_kses_post( $custom_css ); |
|
930 | + echo wp_kses_post($custom_css); |
|
931 | 931 | echo '</style>'; |
932 | 932 | } |
933 | 933 | |
934 | 934 | wp_site_icon(); |
935 | 935 | } |
936 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
937 | -add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' ); |
|
936 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
937 | +add_action('wpinv_invalid_invoice_head', 'wpinv_display_style'); |
|
938 | 938 | |
939 | 939 | |
940 | 940 | /** |
@@ -946,41 +946,41 @@ discard block |
||
946 | 946 | // Retrieve the current invoice. |
947 | 947 | $invoice_id = getpaid_get_current_invoice_id(); |
948 | 948 | |
949 | - if ( empty( $invoice_id ) ) { |
|
949 | + if (empty($invoice_id)) { |
|
950 | 950 | |
951 | 951 | return aui()->alert( |
952 | 952 | array( |
953 | 953 | 'type' => 'warning', |
954 | - 'content' => __( 'Invalid invoice', 'invoicing' ), |
|
954 | + 'content' => __('Invalid invoice', 'invoicing'), |
|
955 | 955 | ) |
956 | 956 | ); |
957 | 957 | |
958 | 958 | } |
959 | 959 | |
960 | 960 | // Can the user view this invoice? |
961 | - if ( ! wpinv_user_can_view_invoice( $invoice_id ) ) { |
|
961 | + if (!wpinv_user_can_view_invoice($invoice_id)) { |
|
962 | 962 | |
963 | 963 | return aui()->alert( |
964 | 964 | array( |
965 | 965 | 'type' => 'warning', |
966 | - 'content' => __( 'You are not allowed to view this invoice', 'invoicing' ), |
|
966 | + 'content' => __('You are not allowed to view this invoice', 'invoicing'), |
|
967 | 967 | ) |
968 | 968 | ); |
969 | 969 | |
970 | 970 | } |
971 | 971 | |
972 | 972 | // Ensure that it is not yet paid for. |
973 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
973 | + $invoice = new WPInv_Invoice($invoice_id); |
|
974 | 974 | |
975 | 975 | // Maybe mark it as viewed. |
976 | - getpaid_maybe_mark_invoice_as_viewed( $invoice ); |
|
976 | + getpaid_maybe_mark_invoice_as_viewed($invoice); |
|
977 | 977 | |
978 | - if ( $invoice->is_paid() ) { |
|
978 | + if ($invoice->is_paid()) { |
|
979 | 979 | |
980 | 980 | return aui()->alert( |
981 | 981 | array( |
982 | 982 | 'type' => 'success', |
983 | - 'content' => __( 'This invoice has already been paid.', 'invoicing' ), |
|
983 | + 'content' => __('This invoice has already been paid.', 'invoicing'), |
|
984 | 984 | ) |
985 | 985 | ); |
986 | 986 | |
@@ -990,15 +990,15 @@ discard block |
||
990 | 990 | $wpi_checkout_id = $invoice_id; |
991 | 991 | |
992 | 992 | // Retrieve appropriate payment form. |
993 | - $payment_form = new GetPaid_Payment_Form( $invoice->get_meta( 'force_payment_form' ) ); |
|
994 | - $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
993 | + $payment_form = new GetPaid_Payment_Form($invoice->get_meta('force_payment_form')); |
|
994 | + $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
995 | 995 | |
996 | - if ( ! $payment_form->exists() ) { |
|
996 | + if (!$payment_form->exists()) { |
|
997 | 997 | |
998 | 998 | return aui()->alert( |
999 | 999 | array( |
1000 | 1000 | 'type' => 'warning', |
1001 | - 'content' => __( 'Error loading the payment form', 'invoicing' ), |
|
1001 | + 'content' => __('Error loading the payment form', 'invoicing'), |
|
1002 | 1002 | ) |
1003 | 1003 | ); |
1004 | 1004 | |
@@ -1007,29 +1007,29 @@ discard block |
||
1007 | 1007 | // Set the invoice. |
1008 | 1008 | $payment_form->invoice = $invoice; |
1009 | 1009 | |
1010 | - if ( ! $payment_form->is_default() ) { |
|
1010 | + if (!$payment_form->is_default()) { |
|
1011 | 1011 | |
1012 | 1012 | $items = array(); |
1013 | 1013 | $item_ids = array(); |
1014 | 1014 | |
1015 | - foreach ( $invoice->get_items() as $item ) { |
|
1016 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
1015 | + foreach ($invoice->get_items() as $item) { |
|
1016 | + if (!in_array($item->get_id(), $item_ids)) { |
|
1017 | 1017 | $item_ids[] = $item->get_id(); |
1018 | 1018 | $items[] = $item; |
1019 | 1019 | } |
1020 | 1020 | } |
1021 | 1021 | |
1022 | - foreach ( $payment_form->get_items() as $item ) { |
|
1023 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
1022 | + foreach ($payment_form->get_items() as $item) { |
|
1023 | + if (!in_array($item->get_id(), $item_ids)) { |
|
1024 | 1024 | $item_ids[] = $item->get_id(); |
1025 | 1025 | $items[] = $item; |
1026 | 1026 | } |
1027 | 1027 | } |
1028 | 1028 | |
1029 | - $payment_form->set_items( $items ); |
|
1029 | + $payment_form->set_items($items); |
|
1030 | 1030 | |
1031 | 1031 | } else { |
1032 | - $payment_form->set_items( $invoice->get_items() ); |
|
1032 | + $payment_form->set_items($invoice->get_items()); |
|
1033 | 1033 | } |
1034 | 1034 | |
1035 | 1035 | // Generate the html. |
@@ -1038,7 +1038,7 @@ discard block |
||
1038 | 1038 | } |
1039 | 1039 | |
1040 | 1040 | function wpinv_empty_cart_message() { |
1041 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1041 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
1042 | 1042 | } |
1043 | 1043 | |
1044 | 1044 | /** |
@@ -1056,76 +1056,76 @@ discard block |
||
1056 | 1056 | true |
1057 | 1057 | ); |
1058 | 1058 | } |
1059 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
1059 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
1060 | 1060 | |
1061 | 1061 | /** |
1062 | 1062 | * Filters the receipt page. |
1063 | 1063 | */ |
1064 | -function wpinv_filter_success_page_content( $content ) { |
|
1064 | +function wpinv_filter_success_page_content($content) { |
|
1065 | 1065 | |
1066 | 1066 | // Maybe abort early. |
1067 | - if ( is_admin() || ! is_singular() || ! in_the_loop() || ! is_main_query() || is_preview() ) { |
|
1067 | + if (is_admin() || !is_singular() || !in_the_loop() || !is_main_query() || is_preview()) { |
|
1068 | 1068 | return $content; |
1069 | 1069 | } |
1070 | 1070 | |
1071 | 1071 | // Ensure this is our page. |
1072 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
1072 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
1073 | 1073 | |
1074 | - $gateway = sanitize_text_field( $_GET['payment-confirm'] ); |
|
1075 | - return apply_filters( "wpinv_payment_confirm_$gateway", $content ); |
|
1074 | + $gateway = sanitize_text_field($_GET['payment-confirm']); |
|
1075 | + return apply_filters("wpinv_payment_confirm_$gateway", $content); |
|
1076 | 1076 | |
1077 | 1077 | } |
1078 | 1078 | |
1079 | 1079 | return $content; |
1080 | 1080 | } |
1081 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
1081 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
1082 | 1082 | |
1083 | -function wpinv_invoice_link( $invoice_id ) { |
|
1084 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1083 | +function wpinv_invoice_link($invoice_id) { |
|
1084 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1085 | 1085 | |
1086 | - if ( empty( $invoice ) ) { |
|
1086 | + if (empty($invoice)) { |
|
1087 | 1087 | return null; |
1088 | 1088 | } |
1089 | 1089 | |
1090 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
1090 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
1091 | 1091 | |
1092 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
1092 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
1093 | 1093 | } |
1094 | 1094 | |
1095 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
1096 | - if ( empty( $note ) ) { |
|
1095 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
1096 | + if (empty($note)) { |
|
1097 | 1097 | return null; |
1098 | 1098 | } |
1099 | 1099 | |
1100 | - if ( is_int( $note ) ) { |
|
1101 | - $note = get_comment( $note ); |
|
1100 | + if (is_int($note)) { |
|
1101 | + $note = get_comment($note); |
|
1102 | 1102 | } |
1103 | 1103 | |
1104 | - if ( ! ( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
1104 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
1105 | 1105 | return null; |
1106 | 1106 | } |
1107 | 1107 | |
1108 | - $note_classes = array( 'note' ); |
|
1109 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
1108 | + $note_classes = array('note'); |
|
1109 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
1110 | 1110 | $note_classes[] = $note->comment_author === 'System' ? 'system-note' : ''; |
1111 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
1112 | - $note_classes = ! empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
1111 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
1112 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
1113 | 1113 | |
1114 | 1114 | ob_start(); |
1115 | 1115 | ?> |
1116 | - <li rel="<?php echo absint( $note->comment_ID ); ?>" class="<?php echo esc_attr( $note_classes ); ?> mb-2"> |
|
1116 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?> mb-2"> |
|
1117 | 1117 | <div class="note_content"> |
1118 | 1118 | |
1119 | - <?php echo wp_kses_post( wptexturize( $note->comment_content ) ); ?> |
|
1119 | + <?php echo wp_kses_post(wptexturize($note->comment_content)); ?> |
|
1120 | 1120 | |
1121 | - <?php if ( ! is_admin() ) : ?> |
|
1121 | + <?php if (!is_admin()) : ?> |
|
1122 | 1122 | <em class="small form-text text-muted mt-0"> |
1123 | 1123 | <?php |
1124 | 1124 | printf( |
1125 | - esc_html__( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
1126 | - esc_html( $note->comment_author ), |
|
1127 | - esc_html( getpaid_format_date_value( $note->comment_date ) ), |
|
1128 | - esc_html( date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ) |
|
1125 | + esc_html__('%1$s - %2$s at %3$s', 'invoicing'), |
|
1126 | + esc_html($note->comment_author), |
|
1127 | + esc_html(getpaid_format_date_value($note->comment_date)), |
|
1128 | + esc_html(date_i18n(get_option('time_format'), strtotime($note->comment_date))) |
|
1129 | 1129 | ); |
1130 | 1130 | ?> |
1131 | 1131 | </em> |
@@ -1133,21 +1133,21 @@ discard block |
||
1133 | 1133 | |
1134 | 1134 | </div> |
1135 | 1135 | |
1136 | - <?php if ( is_admin() ) : ?> |
|
1136 | + <?php if (is_admin()) : ?> |
|
1137 | 1137 | |
1138 | 1138 | <p class="meta px-4 py-2"> |
1139 | - <abbr class="exact-date" title="<?php echo esc_attr( $note->comment_date ); ?>"> |
|
1139 | + <abbr class="exact-date" title="<?php echo esc_attr($note->comment_date); ?>"> |
|
1140 | 1140 | <?php |
1141 | 1141 | printf( |
1142 | - esc_html__( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
1143 | - esc_html( $note->comment_author ), |
|
1144 | - esc_html( getpaid_format_date_value( $note->comment_date ) ), |
|
1145 | - esc_html( date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ) |
|
1142 | + esc_html__('%1$s - %2$s at %3$s', 'invoicing'), |
|
1143 | + esc_html($note->comment_author), |
|
1144 | + esc_html(getpaid_format_date_value($note->comment_date)), |
|
1145 | + esc_html(date_i18n(get_option('time_format'), strtotime($note->comment_date))) |
|
1146 | 1146 | ); |
1147 | 1147 | ?> |
1148 | 1148 | </abbr> |
1149 | - <?php if ( $note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing() ) { ?> |
|
1150 | - <a href="#" class="delete_note"><?php esc_html_e( 'Delete note', 'invoicing' ); ?></a> |
|
1149 | + <?php if ($note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing()) { ?> |
|
1150 | + <a href="#" class="delete_note"><?php esc_html_e('Delete note', 'invoicing'); ?></a> |
|
1151 | 1151 | <?php } ?> |
1152 | 1152 | </p> |
1153 | 1153 | |
@@ -1156,10 +1156,10 @@ discard block |
||
1156 | 1156 | </li> |
1157 | 1157 | <?php |
1158 | 1158 | $note_content = ob_get_clean(); |
1159 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
1159 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
1160 | 1160 | |
1161 | - if ( $echo ) { |
|
1162 | - echo wp_kses_post( $note_content ); |
|
1161 | + if ($echo) { |
|
1162 | + echo wp_kses_post($note_content); |
|
1163 | 1163 | } else { |
1164 | 1164 | return $note_content; |
1165 | 1165 | } |
@@ -1172,43 +1172,43 @@ discard block |
||
1172 | 1172 | * @return string |
1173 | 1173 | */ |
1174 | 1174 | function wpinv_get_policy_text() { |
1175 | - $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 ); |
|
1175 | + $privacy_page_id = get_option('wp_page_for_privacy_policy', 0); |
|
1176 | 1176 | |
1177 | - $text = wpinv_get_option( 'invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' ) ); |
|
1177 | + $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]')); |
|
1178 | 1178 | |
1179 | - if ( ! $privacy_page_id ) { |
|
1180 | - $privacy_page_id = wpinv_get_option( 'privacy_page', 0 ); |
|
1179 | + if (!$privacy_page_id) { |
|
1180 | + $privacy_page_id = wpinv_get_option('privacy_page', 0); |
|
1181 | 1181 | } |
1182 | 1182 | |
1183 | - $privacy_link = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' ); |
|
1183 | + $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing'); |
|
1184 | 1184 | |
1185 | 1185 | $find_replace = array( |
1186 | 1186 | '[wpinv_privacy_policy]' => $privacy_link, |
1187 | 1187 | ); |
1188 | 1188 | |
1189 | - $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text ); |
|
1189 | + $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text); |
|
1190 | 1190 | |
1191 | - return wp_kses_post( wpautop( $privacy_text ) ); |
|
1191 | + return wp_kses_post(wpautop($privacy_text)); |
|
1192 | 1192 | } |
1193 | 1193 | |
1194 | 1194 | function wpinv_oxygen_fix_conflict() { |
1195 | 1195 | global $ct_ignore_post_types; |
1196 | 1196 | |
1197 | - if ( ! is_array( $ct_ignore_post_types ) ) { |
|
1197 | + if (!is_array($ct_ignore_post_types)) { |
|
1198 | 1198 | $ct_ignore_post_types = array(); |
1199 | 1199 | } |
1200 | 1200 | |
1201 | - $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item', 'wpi_payment_form' ); |
|
1201 | + $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item', 'wpi_payment_form'); |
|
1202 | 1202 | |
1203 | - foreach ( $post_types as $post_type ) { |
|
1203 | + foreach ($post_types as $post_type) { |
|
1204 | 1204 | $ct_ignore_post_types[] = $post_type; |
1205 | 1205 | |
1206 | 1206 | // Ignore post type |
1207 | - add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 ); |
|
1207 | + add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999); |
|
1208 | 1208 | } |
1209 | 1209 | |
1210 | - remove_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
1211 | - add_filter( 'template_include', 'wpinv_template', 999, 1 ); |
|
1210 | + remove_filter('template_include', 'wpinv_template', 10, 1); |
|
1211 | + add_filter('template_include', 'wpinv_template', 999, 1); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | /** |
@@ -1216,10 +1216,10 @@ discard block |
||
1216 | 1216 | * |
1217 | 1217 | * @param GetPaid_Payment_Form $form |
1218 | 1218 | */ |
1219 | -function getpaid_display_payment_form( $form ) { |
|
1219 | +function getpaid_display_payment_form($form) { |
|
1220 | 1220 | |
1221 | - if ( is_numeric( $form ) ) { |
|
1222 | - $form = new GetPaid_Payment_Form( $form ); |
|
1221 | + if (is_numeric($form)) { |
|
1222 | + $form = new GetPaid_Payment_Form($form); |
|
1223 | 1223 | } |
1224 | 1224 | |
1225 | 1225 | $form->display(); |
@@ -1229,61 +1229,61 @@ discard block |
||
1229 | 1229 | /** |
1230 | 1230 | * Helper function to display a item payment form on the frontend. |
1231 | 1231 | */ |
1232 | -function getpaid_display_item_payment_form( $items ) { |
|
1232 | +function getpaid_display_item_payment_form($items) { |
|
1233 | 1233 | |
1234 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1235 | - $form->set_items( $items ); |
|
1234 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1235 | + $form->set_items($items); |
|
1236 | 1236 | |
1237 | - if ( 0 == count( $form->get_items() ) ) { |
|
1237 | + if (0 == count($form->get_items())) { |
|
1238 | 1238 | aui()->alert( |
1239 | 1239 | array( |
1240 | 1240 | 'type' => 'warning', |
1241 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
1241 | + 'content' => __('No published items found', 'invoicing'), |
|
1242 | 1242 | ), |
1243 | 1243 | true |
1244 | 1244 | ); |
1245 | 1245 | return; |
1246 | 1246 | } |
1247 | 1247 | |
1248 | - $extra_items = esc_attr( getpaid_convert_items_to_string( $items ) ); |
|
1249 | - $extra_items_key = md5( NONCE_KEY . AUTH_KEY . $extra_items ); |
|
1248 | + $extra_items = esc_attr(getpaid_convert_items_to_string($items)); |
|
1249 | + $extra_items_key = md5(NONCE_KEY . AUTH_KEY . $extra_items); |
|
1250 | 1250 | $extra_items = "<input type='hidden' name='getpaid-form-items' value='$extra_items' />"; |
1251 | 1251 | $extra_items .= "<input type='hidden' name='getpaid-form-items-key' value='$extra_items_key' />"; |
1252 | 1252 | |
1253 | - $form->display( $extra_items ); |
|
1253 | + $form->display($extra_items); |
|
1254 | 1254 | } |
1255 | 1255 | |
1256 | 1256 | /** |
1257 | 1257 | * Helper function to display an invoice payment form on the frontend. |
1258 | 1258 | */ |
1259 | -function getpaid_display_invoice_payment_form( $invoice_id ) { |
|
1259 | +function getpaid_display_invoice_payment_form($invoice_id) { |
|
1260 | 1260 | |
1261 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1261 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1262 | 1262 | |
1263 | - if ( empty( $invoice ) ) { |
|
1263 | + if (empty($invoice)) { |
|
1264 | 1264 | aui()->alert( |
1265 | 1265 | array( |
1266 | 1266 | 'type' => 'warning', |
1267 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1267 | + 'content' => __('Invoice not found', 'invoicing'), |
|
1268 | 1268 | ), |
1269 | 1269 | true |
1270 | 1270 | ); |
1271 | 1271 | return; |
1272 | 1272 | } |
1273 | 1273 | |
1274 | - if ( $invoice->is_paid() ) { |
|
1274 | + if ($invoice->is_paid()) { |
|
1275 | 1275 | aui()->alert( |
1276 | 1276 | array( |
1277 | 1277 | 'type' => 'warning', |
1278 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1278 | + 'content' => __('Invoice has already been paid', 'invoicing'), |
|
1279 | 1279 | ), |
1280 | 1280 | true |
1281 | 1281 | ); |
1282 | 1282 | return; |
1283 | 1283 | } |
1284 | 1284 | |
1285 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1286 | - $form->set_items( $invoice->get_items() ); |
|
1285 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1286 | + $form->set_items($invoice->get_items()); |
|
1287 | 1287 | |
1288 | 1288 | $form->display(); |
1289 | 1289 | } |
@@ -1291,23 +1291,23 @@ discard block |
||
1291 | 1291 | /** |
1292 | 1292 | * Helper function to convert item string to array. |
1293 | 1293 | */ |
1294 | -function getpaid_convert_items_to_array( $items ) { |
|
1295 | - $items = array_filter( array_map( 'trim', explode( ',', $items ) ) ); |
|
1294 | +function getpaid_convert_items_to_array($items) { |
|
1295 | + $items = array_filter(array_map('trim', explode(',', $items))); |
|
1296 | 1296 | $prepared = array(); |
1297 | 1297 | |
1298 | - foreach ( $items as $item ) { |
|
1299 | - $data = array_map( 'trim', explode( '|', $item ) ); |
|
1298 | + foreach ($items as $item) { |
|
1299 | + $data = array_map('trim', explode('|', $item)); |
|
1300 | 1300 | |
1301 | - if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) { |
|
1301 | + if (empty($data[0]) || !is_numeric($data[0])) { |
|
1302 | 1302 | continue; |
1303 | 1303 | } |
1304 | 1304 | |
1305 | 1305 | $quantity = 1; |
1306 | - if ( isset( $data[1] ) && is_numeric( $data[1] ) ) { |
|
1306 | + if (isset($data[1]) && is_numeric($data[1])) { |
|
1307 | 1307 | $quantity = (float) $data[1]; |
1308 | 1308 | } |
1309 | 1309 | |
1310 | - $prepared[ $data[0] ] = $quantity; |
|
1310 | + $prepared[$data[0]] = $quantity; |
|
1311 | 1311 | |
1312 | 1312 | } |
1313 | 1313 | |
@@ -1317,13 +1317,13 @@ discard block |
||
1317 | 1317 | /** |
1318 | 1318 | * Helper function to convert item array to string. |
1319 | 1319 | */ |
1320 | -function getpaid_convert_items_to_string( $items ) { |
|
1320 | +function getpaid_convert_items_to_string($items) { |
|
1321 | 1321 | $prepared = array(); |
1322 | 1322 | |
1323 | - foreach ( $items as $item => $quantity ) { |
|
1323 | + foreach ($items as $item => $quantity) { |
|
1324 | 1324 | $prepared[] = "$item|$quantity"; |
1325 | 1325 | } |
1326 | - return implode( ',', $prepared ); |
|
1326 | + return implode(',', $prepared); |
|
1327 | 1327 | } |
1328 | 1328 | |
1329 | 1329 | /** |
@@ -1331,21 +1331,21 @@ discard block |
||
1331 | 1331 | * |
1332 | 1332 | * Provide a label and one of $form, $items or $invoice. |
1333 | 1333 | */ |
1334 | -function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) { |
|
1335 | - $label = sanitize_text_field( $label ); |
|
1334 | +function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) { |
|
1335 | + $label = sanitize_text_field($label); |
|
1336 | 1336 | |
1337 | - if ( ! empty( $form ) ) { |
|
1338 | - $form = esc_attr( $form ); |
|
1337 | + if (!empty($form)) { |
|
1338 | + $form = esc_attr($form); |
|
1339 | 1339 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>"; |
1340 | 1340 | } |
1341 | 1341 | |
1342 | - if ( ! empty( $items ) ) { |
|
1343 | - $items = esc_attr( $items ); |
|
1342 | + if (!empty($items)) { |
|
1343 | + $items = esc_attr($items); |
|
1344 | 1344 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>"; |
1345 | 1345 | } |
1346 | 1346 | |
1347 | - if ( ! empty( $invoice ) ) { |
|
1348 | - $invoice = esc_attr( $invoice ); |
|
1347 | + if (!empty($invoice)) { |
|
1348 | + $invoice = esc_attr($invoice); |
|
1349 | 1349 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-invoice='$invoice'>$label</button>"; |
1350 | 1350 | } |
1351 | 1351 | |
@@ -1356,17 +1356,17 @@ discard block |
||
1356 | 1356 | * |
1357 | 1357 | * @param WPInv_Invoice $invoice |
1358 | 1358 | */ |
1359 | -function getpaid_the_invoice_description( $invoice ) { |
|
1359 | +function getpaid_the_invoice_description($invoice) { |
|
1360 | 1360 | $description = $invoice->get_description(); |
1361 | 1361 | |
1362 | - if ( empty( $description ) ) { |
|
1362 | + if (empty($description)) { |
|
1363 | 1363 | return; |
1364 | 1364 | } |
1365 | 1365 | |
1366 | - echo "<small class='getpaid-invoice-description text-dark p-2 form-text' style='margin-bottom: 20px; border-left: 2px solid #2196F3;'><em>" . wp_kses_post( wpautop( $description ) ) . "</em></small>"; |
|
1366 | + echo "<small class='getpaid-invoice-description text-dark p-2 form-text' style='margin-bottom: 20px; border-left: 2px solid #2196F3;'><em>" . wp_kses_post(wpautop($description)) . "</em></small>"; |
|
1367 | 1367 | } |
1368 | -add_action( 'getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100 ); |
|
1369 | -add_action( 'wpinv_email_billing_details', 'getpaid_the_invoice_description', 100 ); |
|
1368 | +add_action('getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100); |
|
1369 | +add_action('wpinv_email_billing_details', 'getpaid_the_invoice_description', 100); |
|
1370 | 1370 | |
1371 | 1371 | /** |
1372 | 1372 | * Render element on a form. |
@@ -1374,79 +1374,79 @@ discard block |
||
1374 | 1374 | * @param array $element |
1375 | 1375 | * @param GetPaid_Payment_Form $form |
1376 | 1376 | */ |
1377 | -function getpaid_payment_form_element( $element, $form ) { |
|
1377 | +function getpaid_payment_form_element($element, $form) { |
|
1378 | 1378 | |
1379 | 1379 | // Set up the args. |
1380 | - $element_type = trim( $element['type'] ); |
|
1380 | + $element_type = trim($element['type']); |
|
1381 | 1381 | $element['form'] = $form; |
1382 | - extract( $element ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract |
|
1382 | + extract($element); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract |
|
1383 | 1383 | |
1384 | 1384 | // Try to locate the appropriate template. |
1385 | - $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" ); |
|
1385 | + $located = wpinv_locate_template("payment-forms/elements/$element_type.php"); |
|
1386 | 1386 | |
1387 | 1387 | // Abort if this is not our element. |
1388 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1388 | + if (empty($located) || !file_exists($located)) { |
|
1389 | 1389 | return; |
1390 | 1390 | } |
1391 | 1391 | |
1392 | 1392 | // Generate the class and id of the element. |
1393 | - $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) ); |
|
1394 | - $id = isset( $id ) ? $id : uniqid( 'gp' ); |
|
1393 | + $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type)); |
|
1394 | + $id = isset($id) ? $id : uniqid('gp'); |
|
1395 | 1395 | |
1396 | - $element_id = ! empty( $element['label'] ) ? sanitize_title( $element['label'] ) : $id; |
|
1397 | - $query_value = isset( $_GET[ $element_id ] ) ? wpinv_clean( urldecode_deep( $_GET[ $element_id ] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
1396 | + $element_id = !empty($element['label']) ? sanitize_title($element['label']) : $id; |
|
1397 | + $query_value = isset($_GET[$element_id]) ? wpinv_clean(urldecode_deep($_GET[$element_id])) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
1398 | 1398 | |
1399 | 1399 | $element_id = 'getpaid-' . $element_id; |
1400 | - if ( ! empty( $GLOBALS['rendered_getpaid_forms'][ $form->get_id() ] ) ) { |
|
1401 | - $element_id = $element_id . '-' . $GLOBALS['rendered_getpaid_forms'][ $form->get_id() ]; |
|
1400 | + if (!empty($GLOBALS['rendered_getpaid_forms'][$form->get_id()])) { |
|
1401 | + $element_id = $element_id . '-' . $GLOBALS['rendered_getpaid_forms'][$form->get_id()]; |
|
1402 | 1402 | } |
1403 | 1403 | |
1404 | 1404 | // Echo the opening wrapper. |
1405 | - echo "<div class='getpaid-payment-form-element " . esc_attr( $wrapper_class ) . "'>"; |
|
1405 | + echo "<div class='getpaid-payment-form-element " . esc_attr($wrapper_class) . "'>"; |
|
1406 | 1406 | |
1407 | 1407 | // Fires before displaying a given element type's content. |
1408 | - do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form ); |
|
1408 | + do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form); |
|
1409 | 1409 | |
1410 | 1410 | // Include the template for the element. |
1411 | 1411 | include $located; |
1412 | 1412 | |
1413 | 1413 | // Fires after displaying a given element type's content. |
1414 | - do_action( "getpaid_payment_form_{$element_type}_element", $element, $form ); |
|
1414 | + do_action("getpaid_payment_form_{$element_type}_element", $element, $form); |
|
1415 | 1415 | |
1416 | 1416 | // Echo the closing wrapper. |
1417 | 1417 | echo '</div>'; |
1418 | 1418 | } |
1419 | -add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 ); |
|
1419 | +add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2); |
|
1420 | 1420 | |
1421 | 1421 | /** |
1422 | 1422 | * Render an element's edit page. |
1423 | 1423 | * |
1424 | 1424 | * @param WP_Post $post |
1425 | 1425 | */ |
1426 | -function getpaid_payment_form_edit_element_template( $post ) { |
|
1426 | +function getpaid_payment_form_edit_element_template($post) { |
|
1427 | 1427 | |
1428 | 1428 | // Retrieve all elements. |
1429 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
1429 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
1430 | 1430 | |
1431 | - foreach ( $all_elements as $element ) { |
|
1431 | + foreach ($all_elements as $element) { |
|
1432 | 1432 | |
1433 | 1433 | // Try to locate the appropriate template. |
1434 | - $element = esc_attr( sanitize_key( $element ) ); |
|
1435 | - $located = wpinv_locate_template( "payment-forms-admin/edit/$element.php" ); |
|
1434 | + $element = esc_attr(sanitize_key($element)); |
|
1435 | + $located = wpinv_locate_template("payment-forms-admin/edit/$element.php"); |
|
1436 | 1436 | |
1437 | 1437 | // Continue if this is not our element. |
1438 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1438 | + if (empty($located) || !file_exists($located)) { |
|
1439 | 1439 | continue; |
1440 | 1440 | } |
1441 | 1441 | |
1442 | 1442 | // Include the template for the element. |
1443 | - echo "<div v-if=\"active_form_element.type=='" . esc_attr( $element ) . "'\">"; |
|
1443 | + echo "<div v-if=\"active_form_element.type=='" . esc_attr($element) . "'\">"; |
|
1444 | 1444 | include $located; |
1445 | 1445 | echo '</div>'; |
1446 | 1446 | } |
1447 | 1447 | |
1448 | 1448 | } |
1449 | -add_action( 'getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template' ); |
|
1449 | +add_action('getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template'); |
|
1450 | 1450 | |
1451 | 1451 | /** |
1452 | 1452 | * Render an element's preview. |
@@ -1455,27 +1455,27 @@ discard block |
||
1455 | 1455 | function getpaid_payment_form_render_element_preview_template() { |
1456 | 1456 | |
1457 | 1457 | // Retrieve all elements. |
1458 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
1458 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
1459 | 1459 | |
1460 | - foreach ( $all_elements as $element ) { |
|
1460 | + foreach ($all_elements as $element) { |
|
1461 | 1461 | |
1462 | 1462 | // Try to locate the appropriate template. |
1463 | - $element = sanitize_key( $element ); |
|
1464 | - $located = wpinv_locate_template( "payment-forms-admin/previews/$element.php" ); |
|
1463 | + $element = sanitize_key($element); |
|
1464 | + $located = wpinv_locate_template("payment-forms-admin/previews/$element.php"); |
|
1465 | 1465 | |
1466 | 1466 | // Continue if this is not our element. |
1467 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1467 | + if (empty($located) || !file_exists($located)) { |
|
1468 | 1468 | continue; |
1469 | 1469 | } |
1470 | 1470 | |
1471 | 1471 | // Include the template for the element. |
1472 | - echo "<div v-if=\"form_element.type=='" . esc_html( $element ) . "'\">"; |
|
1472 | + echo "<div v-if=\"form_element.type=='" . esc_html($element) . "'\">"; |
|
1473 | 1473 | include $located; |
1474 | 1474 | echo '</div>'; |
1475 | 1475 | } |
1476 | 1476 | |
1477 | 1477 | } |
1478 | -add_action( 'wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template' ); |
|
1478 | +add_action('wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template'); |
|
1479 | 1479 | |
1480 | 1480 | /** |
1481 | 1481 | * Shows a list of gateways that support recurring payments. |
@@ -1483,17 +1483,17 @@ discard block |
||
1483 | 1483 | function wpinv_get_recurring_gateways_text() { |
1484 | 1484 | $gateways = array(); |
1485 | 1485 | |
1486 | - foreach ( wpinv_get_payment_gateways() as $key => $gateway ) { |
|
1487 | - if ( wpinv_gateway_support_subscription( $key ) ) { |
|
1488 | - $gateways[] = sanitize_text_field( $gateway['admin_label'] ); |
|
1486 | + foreach (wpinv_get_payment_gateways() as $key => $gateway) { |
|
1487 | + if (wpinv_gateway_support_subscription($key)) { |
|
1488 | + $gateways[] = sanitize_text_field($gateway['admin_label']); |
|
1489 | 1489 | } |
1490 | 1490 | } |
1491 | 1491 | |
1492 | - if ( empty( $gateways ) ) { |
|
1493 | - return "<span class='form-text text-danger'>" . __( 'No active gateways support subscription payments.', 'invoicing' ) . '</span>'; |
|
1492 | + if (empty($gateways)) { |
|
1493 | + return "<span class='form-text text-danger'>" . __('No active gateways support subscription payments.', 'invoicing') . '</span>'; |
|
1494 | 1494 | } |
1495 | 1495 | |
1496 | - return "<span class='form-text text-muted'>" . wp_sprintf( __( 'Subscription payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ) . '</span>'; |
|
1496 | + return "<span class='form-text text-muted'>" . wp_sprintf(__('Subscription payments only supported by: %s', 'invoicing'), implode(', ', $gateways)) . '</span>'; |
|
1497 | 1497 | |
1498 | 1498 | } |
1499 | 1499 | |
@@ -1503,7 +1503,7 @@ discard block |
||
1503 | 1503 | * @return GetPaid_Template |
1504 | 1504 | */ |
1505 | 1505 | function getpaid_template() { |
1506 | - return getpaid()->get( 'template' ); |
|
1506 | + return getpaid()->get('template'); |
|
1507 | 1507 | } |
1508 | 1508 | |
1509 | 1509 | /** |
@@ -1512,8 +1512,8 @@ discard block |
||
1512 | 1512 | * @param array args |
1513 | 1513 | * @return string |
1514 | 1514 | */ |
1515 | -function getpaid_paginate_links( $args ) { |
|
1516 | - return str_replace( 'page-link dots', 'page-link text-dark', aui()->pagination( $args ) ); |
|
1515 | +function getpaid_paginate_links($args) { |
|
1516 | + return str_replace('page-link dots', 'page-link text-dark', aui()->pagination($args)); |
|
1517 | 1517 | } |
1518 | 1518 | |
1519 | 1519 | /** |
@@ -1523,22 +1523,22 @@ discard block |
||
1523 | 1523 | * @param string state |
1524 | 1524 | * @return string |
1525 | 1525 | */ |
1526 | -function getpaid_get_states_select_markup( $country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state', $echo = false ) { |
|
1526 | +function getpaid_get_states_select_markup($country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state', $echo = false) { |
|
1527 | 1527 | |
1528 | - $states = wpinv_get_country_states( $country ); |
|
1529 | - $uniqid = uniqid( '_' ); |
|
1528 | + $states = wpinv_get_country_states($country); |
|
1529 | + $uniqid = uniqid('_'); |
|
1530 | 1530 | |
1531 | - if ( ! empty( $states ) ) { |
|
1531 | + if (!empty($states)) { |
|
1532 | 1532 | |
1533 | 1533 | return aui()->select( |
1534 | 1534 | array( |
1535 | 1535 | 'options' => $states, |
1536 | - 'name' => esc_attr( $field_name ), |
|
1537 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
1538 | - 'value' => sanitize_text_field( $state ), |
|
1536 | + 'name' => esc_attr($field_name), |
|
1537 | + 'id' => sanitize_html_class($field_name) . $uniqid, |
|
1538 | + 'value' => sanitize_text_field($state), |
|
1539 | 1539 | 'placeholder' => $placeholder, |
1540 | 1540 | 'required' => $required, |
1541 | - 'label' => wp_kses_post( $label ), |
|
1541 | + 'label' => wp_kses_post($label), |
|
1542 | 1542 | 'label_type' => 'vertical', |
1543 | 1543 | 'help_text' => $help_text, |
1544 | 1544 | 'class' => 'getpaid-address-field wpinv_state', |
@@ -1555,14 +1555,14 @@ discard block |
||
1555 | 1555 | |
1556 | 1556 | return aui()->input( |
1557 | 1557 | array( |
1558 | - 'name' => esc_attr( $field_name ), |
|
1559 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
1558 | + 'name' => esc_attr($field_name), |
|
1559 | + 'id' => sanitize_html_class($field_name) . $uniqid, |
|
1560 | 1560 | 'placeholder' => $placeholder, |
1561 | 1561 | 'required' => $required, |
1562 | - 'label' => wp_kses_post( $label ), |
|
1562 | + 'label' => wp_kses_post($label), |
|
1563 | 1563 | 'label_type' => 'vertical', |
1564 | 1564 | 'help_text' => $help_text, |
1565 | - 'value' => sanitize_text_field( $state ), |
|
1565 | + 'value' => sanitize_text_field($state), |
|
1566 | 1566 | 'class' => 'getpaid-address-field wpinv_state', |
1567 | 1567 | 'wrap_class' => "$wrapper_class getpaid-address-field-wrapper__state", |
1568 | 1568 | 'label_class' => 'getpaid-address-field-label getpaid-address-field-label__state', |
@@ -1581,16 +1581,16 @@ discard block |
||
1581 | 1581 | * @param array $element |
1582 | 1582 | * @return string |
1583 | 1583 | */ |
1584 | -function getpaid_get_form_element_grid_class( $element ) { |
|
1584 | +function getpaid_get_form_element_grid_class($element) { |
|
1585 | 1585 | |
1586 | 1586 | $class = 'col-12'; |
1587 | - $width = empty( $element['grid_width'] ) ? 'full' : $element['grid_width']; |
|
1587 | + $width = empty($element['grid_width']) ? 'full' : $element['grid_width']; |
|
1588 | 1588 | |
1589 | - if ( $width == 'half' ) { |
|
1589 | + if ($width == 'half') { |
|
1590 | 1590 | $class .= ' col-md-6'; |
1591 | 1591 | } |
1592 | 1592 | |
1593 | - if ( $width == 'third' ) { |
|
1593 | + if ($width == 'third') { |
|
1594 | 1594 | $class .= ' col-md-4'; |
1595 | 1595 | } |
1596 | 1596 | |
@@ -1605,15 +1605,15 @@ discard block |
||
1605 | 1605 | * |
1606 | 1606 | * @return string |
1607 | 1607 | */ |
1608 | -function getpaid_embed_url( $payment_form = false, $items = false ) { |
|
1608 | +function getpaid_embed_url($payment_form = false, $items = false) { |
|
1609 | 1609 | |
1610 | 1610 | return add_query_arg( |
1611 | 1611 | array( |
1612 | 1612 | 'getpaid_embed' => 1, |
1613 | - 'form' => $payment_form ? absint( $payment_form ) : false, |
|
1614 | - 'item' => $items ? urlencode( $items ) : false, |
|
1613 | + 'form' => $payment_form ? absint($payment_form) : false, |
|
1614 | + 'item' => $items ? urlencode($items) : false, |
|
1615 | 1615 | ), |
1616 | - home_url( 'index.php' ) |
|
1616 | + home_url('index.php') |
|
1617 | 1617 | ); |
1618 | 1618 | |
1619 | 1619 | } |
@@ -1623,13 +1623,13 @@ discard block |
||
1623 | 1623 | * |
1624 | 1624 | * @return string |
1625 | 1625 | */ |
1626 | -function getpaid_filter_embed_template( $template ) { |
|
1626 | +function getpaid_filter_embed_template($template) { |
|
1627 | 1627 | |
1628 | - if ( isset( $_GET['getpaid_embed'] ) ) { |
|
1629 | - wpinv_get_template( 'payment-forms/embed.php' ); |
|
1628 | + if (isset($_GET['getpaid_embed'])) { |
|
1629 | + wpinv_get_template('payment-forms/embed.php'); |
|
1630 | 1630 | exit; |
1631 | 1631 | } |
1632 | 1632 | |
1633 | 1633 | return $template; |
1634 | 1634 | } |
1635 | -add_filter( 'template_include', 'getpaid_filter_embed_template' ); |
|
1635 | +add_filter('template_include', 'getpaid_filter_embed_template'); |
@@ -12,184 +12,184 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Checkout { |
14 | 14 | |
15 | - /** |
|
16 | - * @var GetPaid_Payment_Form_Submission |
|
17 | - */ |
|
18 | - protected $payment_form_submission; |
|
19 | - |
|
20 | - /** |
|
21 | - * Class constructor. |
|
22 | - * |
|
23 | - * @param GetPaid_Payment_Form_Submission $submission |
|
24 | - */ |
|
25 | - public function __construct( $submission ) { |
|
26 | - $this->payment_form_submission = $submission; |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Processes the checkout. |
|
31 | - * |
|
32 | - */ |
|
33 | - public function process_checkout() { |
|
34 | - |
|
35 | - // Validate the submission. |
|
36 | - $this->validate_submission(); |
|
37 | - |
|
38 | - // Prepare the invoice. |
|
39 | - $items = $this->get_submission_items(); |
|
40 | - $invoice = $this->get_submission_invoice(); |
|
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | - $prepared = $this->prepare_submission_data_for_saving(); |
|
43 | - |
|
44 | - $this->prepare_billing_info( $invoice ); |
|
45 | - |
|
46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
47 | - |
|
48 | - // Save the invoice. |
|
49 | - $invoice->set_is_viewed( true ); |
|
50 | - $invoice->recalculate_total(); |
|
15 | + /** |
|
16 | + * @var GetPaid_Payment_Form_Submission |
|
17 | + */ |
|
18 | + protected $payment_form_submission; |
|
19 | + |
|
20 | + /** |
|
21 | + * Class constructor. |
|
22 | + * |
|
23 | + * @param GetPaid_Payment_Form_Submission $submission |
|
24 | + */ |
|
25 | + public function __construct( $submission ) { |
|
26 | + $this->payment_form_submission = $submission; |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Processes the checkout. |
|
31 | + * |
|
32 | + */ |
|
33 | + public function process_checkout() { |
|
34 | + |
|
35 | + // Validate the submission. |
|
36 | + $this->validate_submission(); |
|
37 | + |
|
38 | + // Prepare the invoice. |
|
39 | + $items = $this->get_submission_items(); |
|
40 | + $invoice = $this->get_submission_invoice(); |
|
41 | + $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | + $prepared = $this->prepare_submission_data_for_saving(); |
|
43 | + |
|
44 | + $this->prepare_billing_info( $invoice ); |
|
45 | + |
|
46 | + $shipping = $this->prepare_shipping_info( $invoice ); |
|
47 | + |
|
48 | + // Save the invoice. |
|
49 | + $invoice->set_is_viewed( true ); |
|
50 | + $invoice->recalculate_total(); |
|
51 | 51 | $invoice->save(); |
52 | 52 | |
53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
53 | + do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
54 | 54 | |
55 | - // Send to the gateway. |
|
56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
57 | - } |
|
55 | + // Send to the gateway. |
|
56 | + $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Validates the submission. |
|
61 | - * |
|
62 | - */ |
|
63 | - protected function validate_submission() { |
|
59 | + /** |
|
60 | + * Validates the submission. |
|
61 | + * |
|
62 | + */ |
|
63 | + protected function validate_submission() { |
|
64 | 64 | |
65 | - $submission = $this->payment_form_submission; |
|
66 | - $data = $submission->get_data(); |
|
65 | + $submission = $this->payment_form_submission; |
|
66 | + $data = $submission->get_data(); |
|
67 | 67 | |
68 | - // Do we have an error? |
|
68 | + // Do we have an error? |
|
69 | 69 | if ( ! empty( $submission->last_error ) ) { |
70 | - wp_send_json_error( $submission->last_error ); |
|
70 | + wp_send_json_error( $submission->last_error ); |
|
71 | 71 | } |
72 | 72 | |
73 | - // We need a billing email. |
|
73 | + // We need a billing email. |
|
74 | 74 | if ( ! $submission->has_billing_email() ) { |
75 | 75 | wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
76 | - } |
|
76 | + } |
|
77 | 77 | |
78 | - // Non-recurring gateways should not be allowed to process recurring invoices. |
|
79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
81 | - } |
|
78 | + // Non-recurring gateways should not be allowed to process recurring invoices. |
|
79 | + if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | + wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
81 | + } |
|
82 | 82 | |
83 | - // Ensure the gateway is active. |
|
84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | - wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
86 | - } |
|
83 | + // Ensure the gateway is active. |
|
84 | + if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | + wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
86 | + } |
|
87 | 87 | |
88 | - // Clear any existing errors. |
|
89 | - wpinv_clear_errors(); |
|
88 | + // Clear any existing errors. |
|
89 | + wpinv_clear_errors(); |
|
90 | 90 | |
91 | - // Allow themes and plugins to hook to errors |
|
92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
91 | + // Allow themes and plugins to hook to errors |
|
92 | + do_action( 'getpaid_checkout_error_checks', $submission ); |
|
93 | 93 | |
94 | - // Do we have any errors? |
|
94 | + // Do we have any errors? |
|
95 | 95 | if ( wpinv_get_errors() ) { |
96 | 96 | wp_send_json_error( getpaid_get_errors_html() ); |
97 | - } |
|
97 | + } |
|
98 | 98 | |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Retrieves submission items. |
|
103 | - * |
|
104 | - * @return GetPaid_Form_Item[] |
|
105 | - */ |
|
106 | - protected function get_submission_items() { |
|
101 | + /** |
|
102 | + * Retrieves submission items. |
|
103 | + * |
|
104 | + * @return GetPaid_Form_Item[] |
|
105 | + */ |
|
106 | + protected function get_submission_items() { |
|
107 | 107 | |
108 | - $items = $this->payment_form_submission->get_items(); |
|
108 | + $items = $this->payment_form_submission->get_items(); |
|
109 | 109 | |
110 | 110 | // Ensure that we have items. |
111 | 111 | if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
112 | 112 | wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
113 | - } |
|
114 | - |
|
115 | - return $items; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Retrieves submission invoice. |
|
120 | - * |
|
121 | - * @return WPInv_Invoice |
|
122 | - */ |
|
123 | - protected function get_submission_invoice() { |
|
124 | - $submission = $this->payment_form_submission; |
|
125 | - |
|
126 | - if ( ! $submission->has_invoice() ) { |
|
127 | - $invoice = new WPInv_Invoice(); |
|
128 | - $invoice->set_created_via( 'payment_form' ); |
|
129 | - return $invoice; |
|
130 | 113 | } |
131 | 114 | |
132 | - $invoice = $submission->get_invoice(); |
|
115 | + return $items; |
|
116 | + } |
|
133 | 117 | |
134 | - // Make sure that it is neither paid or refunded. |
|
135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | - } |
|
118 | + /** |
|
119 | + * Retrieves submission invoice. |
|
120 | + * |
|
121 | + * @return WPInv_Invoice |
|
122 | + */ |
|
123 | + protected function get_submission_invoice() { |
|
124 | + $submission = $this->payment_form_submission; |
|
138 | 125 | |
139 | - return $invoice; |
|
140 | - } |
|
126 | + if ( ! $submission->has_invoice() ) { |
|
127 | + $invoice = new WPInv_Invoice(); |
|
128 | + $invoice->set_created_via( 'payment_form' ); |
|
129 | + return $invoice; |
|
130 | + } |
|
141 | 131 | |
142 | - /** |
|
143 | - * Processes the submission invoice. |
|
144 | - * |
|
145 | - * @param WPInv_Invoice $invoice |
|
146 | - * @param GetPaid_Form_Item[] $items |
|
147 | - * @return WPInv_Invoice |
|
148 | - */ |
|
149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
132 | + $invoice = $submission->get_invoice(); |
|
150 | 133 | |
151 | - $submission = $this->payment_form_submission; |
|
134 | + // Make sure that it is neither paid or refunded. |
|
135 | + if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | + wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | + } |
|
152 | 138 | |
153 | - // Set-up the invoice details. |
|
154 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
139 | + return $invoice; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Processes the submission invoice. |
|
144 | + * |
|
145 | + * @param WPInv_Invoice $invoice |
|
146 | + * @param GetPaid_Form_Item[] $items |
|
147 | + * @return WPInv_Invoice |
|
148 | + */ |
|
149 | + protected function process_submission_invoice( $invoice, $items ) { |
|
150 | + |
|
151 | + $submission = $this->payment_form_submission; |
|
152 | + |
|
153 | + // Set-up the invoice details. |
|
154 | + $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | + $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | + $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
157 | 157 | $invoice->set_items( $items ); |
158 | 158 | $invoice->set_fees( $submission->get_fees() ); |
159 | 159 | $invoice->set_taxes( $submission->get_taxes() ); |
160 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
161 | - $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
162 | - $invoice->set_currency( $submission->get_currency() ); |
|
160 | + $invoice->set_discounts( $submission->get_discounts() ); |
|
161 | + $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
162 | + $invoice->set_currency( $submission->get_currency() ); |
|
163 | 163 | |
164 | - if ( $submission->has_shipping() ) { |
|
165 | - $invoice->set_shipping( $submission->get_shipping() ); |
|
166 | - } |
|
164 | + if ( $submission->has_shipping() ) { |
|
165 | + $invoice->set_shipping( $submission->get_shipping() ); |
|
166 | + } |
|
167 | 167 | |
168 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
169 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
168 | + $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
169 | + $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
170 | 170 | |
171 | - if ( $submission->has_discount_code() ) { |
|
171 | + if ( $submission->has_discount_code() ) { |
|
172 | 172 | $invoice->set_discount_code( $submission->get_discount_code() ); |
173 | - } |
|
174 | - |
|
175 | - getpaid_maybe_add_default_address( $invoice ); |
|
176 | - return $invoice; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Retrieves the submission's customer. |
|
181 | - * |
|
182 | - * @return int The customer id. |
|
183 | - */ |
|
184 | - protected function get_submission_customer() { |
|
185 | - $submission = $this->payment_form_submission; |
|
186 | - |
|
187 | - // If this is an existing invoice... |
|
188 | - if ( $submission->has_invoice() ) { |
|
189 | - return $submission->get_invoice()->get_user_id(); |
|
190 | - } |
|
191 | - |
|
192 | - // (Maybe) create the user. |
|
173 | + } |
|
174 | + |
|
175 | + getpaid_maybe_add_default_address( $invoice ); |
|
176 | + return $invoice; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Retrieves the submission's customer. |
|
181 | + * |
|
182 | + * @return int The customer id. |
|
183 | + */ |
|
184 | + protected function get_submission_customer() { |
|
185 | + $submission = $this->payment_form_submission; |
|
186 | + |
|
187 | + // If this is an existing invoice... |
|
188 | + if ( $submission->has_invoice() ) { |
|
189 | + return $submission->get_invoice()->get_user_id(); |
|
190 | + } |
|
191 | + |
|
192 | + // (Maybe) create the user. |
|
193 | 193 | $user = get_current_user_id(); |
194 | 194 | |
195 | 195 | if ( empty( $user ) ) { |
@@ -197,16 +197,16 @@ discard block |
||
197 | 197 | } |
198 | 198 | |
199 | 199 | if ( empty( $user ) ) { |
200 | - $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
201 | - $name = implode( '', array_filter( $name ) ); |
|
200 | + $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
201 | + $name = implode( '', array_filter( $name ) ); |
|
202 | 202 | $user = wpinv_create_user( $submission->get_billing_email(), $name ); |
203 | 203 | |
204 | - // (Maybe) send new user notification. |
|
205 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
206 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
207 | - wp_send_new_user_notifications( $user, 'user' ); |
|
208 | - } |
|
209 | - } |
|
204 | + // (Maybe) send new user notification. |
|
205 | + $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
206 | + if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
207 | + wp_send_new_user_notifications( $user, 'user' ); |
|
208 | + } |
|
209 | + } |
|
210 | 210 | |
211 | 211 | if ( is_wp_error( $user ) ) { |
212 | 212 | wp_send_json_error( $user->get_error_message() ); |
@@ -214,49 +214,49 @@ discard block |
||
214 | 214 | |
215 | 215 | if ( is_numeric( $user ) ) { |
216 | 216 | return $user; |
217 | - } |
|
217 | + } |
|
218 | 218 | |
219 | - return $user->ID; |
|
219 | + return $user->ID; |
|
220 | 220 | |
221 | - } |
|
221 | + } |
|
222 | 222 | |
223 | - /** |
|
223 | + /** |
|
224 | 224 | * Prepares submission data for saving to the database. |
225 | 225 | * |
226 | - * @return array |
|
226 | + * @return array |
|
227 | 227 | */ |
228 | 228 | public function prepare_submission_data_for_saving() { |
229 | 229 | |
230 | - $submission = $this->payment_form_submission; |
|
230 | + $submission = $this->payment_form_submission; |
|
231 | 231 | |
232 | - // Prepared submission details. |
|
232 | + // Prepared submission details. |
|
233 | 233 | $prepared = array( |
234 | - 'all' => array(), |
|
235 | - 'meta' => array(), |
|
236 | - ); |
|
234 | + 'all' => array(), |
|
235 | + 'meta' => array(), |
|
236 | + ); |
|
237 | 237 | |
238 | 238 | // Raw submission details. |
239 | - $data = $submission->get_data(); |
|
239 | + $data = $submission->get_data(); |
|
240 | 240 | |
241 | - // Loop through the submitted details. |
|
241 | + // Loop through the submitted details. |
|
242 | 242 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
243 | 243 | |
244 | - // Skip premade fields. |
|
244 | + // Skip premade fields. |
|
245 | 245 | if ( ! empty( $field['premade'] ) ) { |
246 | 246 | continue; |
247 | 247 | } |
248 | 248 | |
249 | - // Ensure address is provided. |
|
250 | - if ( $field['type'] == 'address' ) { |
|
249 | + // Ensure address is provided. |
|
250 | + if ( $field['type'] == 'address' ) { |
|
251 | 251 | $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
252 | 252 | |
253 | - foreach ( $field['fields'] as $address_field ) { |
|
253 | + foreach ( $field['fields'] as $address_field ) { |
|
254 | 254 | |
255 | - if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { |
|
256 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
257 | - } |
|
258 | - } |
|
259 | - } |
|
255 | + if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { |
|
256 | + wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
257 | + } |
|
258 | + } |
|
259 | + } |
|
260 | 260 | |
261 | 261 | // If it is required and not set, abort. |
262 | 262 | if ( ! $submission->is_required_field_set( $field ) ) { |
@@ -266,31 +266,31 @@ discard block |
||
266 | 266 | // Handle misc fields. |
267 | 267 | if ( isset( $data[ $field['id'] ] ) ) { |
268 | 268 | |
269 | - // Uploads. |
|
270 | - if ( $field['type'] == 'file_upload' ) { |
|
271 | - $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
269 | + // Uploads. |
|
270 | + if ( $field['type'] == 'file_upload' ) { |
|
271 | + $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
272 | 272 | |
273 | - if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
274 | - wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
275 | - } |
|
273 | + if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
274 | + wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
275 | + } |
|
276 | 276 | |
277 | - $value = array(); |
|
277 | + $value = array(); |
|
278 | 278 | |
279 | - foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
280 | - $value[] = sprintf( |
|
281 | - '<a href="%s" target="_blank">%s</a>', |
|
282 | - esc_url_raw( $url ), |
|
283 | - esc_html( $name ) |
|
284 | - ); |
|
285 | - } |
|
279 | + foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
280 | + $value[] = sprintf( |
|
281 | + '<a href="%s" target="_blank">%s</a>', |
|
282 | + esc_url_raw( $url ), |
|
283 | + esc_html( $name ) |
|
284 | + ); |
|
285 | + } |
|
286 | 286 | |
287 | - $value = implode( ' | ', $value ); |
|
287 | + $value = implode( ' | ', $value ); |
|
288 | 288 | |
289 | - } elseif ( $field['type'] == 'checkbox' ) { |
|
290 | - $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
291 | - } else { |
|
292 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
293 | - } |
|
289 | + } elseif ( $field['type'] == 'checkbox' ) { |
|
290 | + $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
291 | + } else { |
|
292 | + $value = wp_kses_post( $data[ $field['id'] ] ); |
|
293 | + } |
|
294 | 294 | |
295 | 295 | $label = $field['id']; |
296 | 296 | |
@@ -298,188 +298,188 @@ discard block |
||
298 | 298 | $label = $field['label']; |
299 | 299 | } |
300 | 300 | |
301 | - if ( ! empty( $field['add_meta'] ) ) { |
|
302 | - $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
303 | - } |
|
304 | - $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
301 | + if ( ! empty( $field['add_meta'] ) ) { |
|
302 | + $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
303 | + } |
|
304 | + $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
305 | 305 | |
306 | 306 | } |
307 | 307 | } |
308 | 308 | |
309 | - return $prepared; |
|
309 | + return $prepared; |
|
310 | 310 | |
311 | - } |
|
311 | + } |
|
312 | 312 | |
313 | - /** |
|
313 | + /** |
|
314 | 314 | * Retrieves address details. |
315 | 315 | * |
316 | - * @return array |
|
317 | - * @param WPInv_Invoice $invoice |
|
318 | - * @param string $type |
|
316 | + * @return array |
|
317 | + * @param WPInv_Invoice $invoice |
|
318 | + * @param string $type |
|
319 | 319 | */ |
320 | 320 | public function prepare_address_details( $invoice, $type = 'billing' ) { |
321 | 321 | |
322 | - $data = $this->payment_form_submission->get_data(); |
|
323 | - $type = sanitize_key( $type ); |
|
324 | - $address = array(); |
|
325 | - $prepared = array(); |
|
322 | + $data = $this->payment_form_submission->get_data(); |
|
323 | + $type = sanitize_key( $type ); |
|
324 | + $address = array(); |
|
325 | + $prepared = array(); |
|
326 | 326 | |
327 | - if ( ! empty( $data[ $type ] ) ) { |
|
328 | - $address = $data[ $type ]; |
|
329 | - } |
|
327 | + if ( ! empty( $data[ $type ] ) ) { |
|
328 | + $address = $data[ $type ]; |
|
329 | + } |
|
330 | 330 | |
331 | - // Clean address details. |
|
332 | - foreach ( $address as $key => $value ) { |
|
333 | - $key = sanitize_key( $key ); |
|
334 | - $key = str_replace( 'wpinv_', '', $key ); |
|
335 | - $value = wpinv_clean( $value ); |
|
336 | - $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
337 | - } |
|
331 | + // Clean address details. |
|
332 | + foreach ( $address as $key => $value ) { |
|
333 | + $key = sanitize_key( $key ); |
|
334 | + $key = str_replace( 'wpinv_', '', $key ); |
|
335 | + $value = wpinv_clean( $value ); |
|
336 | + $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
337 | + } |
|
338 | 338 | |
339 | - // Filter address details. |
|
340 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
339 | + // Filter address details. |
|
340 | + $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
341 | 341 | |
342 | - // Remove non-whitelisted values. |
|
343 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
342 | + // Remove non-whitelisted values. |
|
343 | + return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
344 | 344 | |
345 | - } |
|
345 | + } |
|
346 | 346 | |
347 | - /** |
|
347 | + /** |
|
348 | 348 | * Prepares the billing details. |
349 | 349 | * |
350 | - * @return array |
|
351 | - * @param WPInv_Invoice $invoice |
|
350 | + * @return array |
|
351 | + * @param WPInv_Invoice $invoice |
|
352 | 352 | */ |
353 | 353 | protected function prepare_billing_info( &$invoice ) { |
354 | 354 | |
355 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
355 | + $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
356 | 356 | |
357 | - // Update the invoice with the billing details. |
|
358 | - $invoice->set_props( $billing_address ); |
|
357 | + // Update the invoice with the billing details. |
|
358 | + $invoice->set_props( $billing_address ); |
|
359 | 359 | |
360 | - } |
|
360 | + } |
|
361 | 361 | |
362 | - /** |
|
362 | + /** |
|
363 | 363 | * Prepares the shipping details. |
364 | 364 | * |
365 | - * @return array |
|
366 | - * @param WPInv_Invoice $invoice |
|
365 | + * @return array |
|
366 | + * @param WPInv_Invoice $invoice |
|
367 | 367 | */ |
368 | 368 | protected function prepare_shipping_info( $invoice ) { |
369 | 369 | |
370 | - $data = $this->payment_form_submission->get_data(); |
|
370 | + $data = $this->payment_form_submission->get_data(); |
|
371 | 371 | |
372 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
373 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
374 | - } |
|
372 | + if ( empty( $data['same-shipping-address'] ) ) { |
|
373 | + return $this->prepare_address_details( $invoice, 'shipping' ); |
|
374 | + } |
|
375 | 375 | |
376 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
376 | + return $this->prepare_address_details( $invoice, 'billing' ); |
|
377 | 377 | |
378 | - } |
|
378 | + } |
|
379 | 379 | |
380 | - /** |
|
381 | - * Confirms the submission is valid and send users to the gateway. |
|
382 | - * |
|
383 | - * @param WPInv_Invoice $invoice |
|
384 | - * @param array $prepared_payment_form_data |
|
385 | - * @param array $shipping |
|
386 | - */ |
|
387 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
380 | + /** |
|
381 | + * Confirms the submission is valid and send users to the gateway. |
|
382 | + * |
|
383 | + * @param WPInv_Invoice $invoice |
|
384 | + * @param array $prepared_payment_form_data |
|
385 | + * @param array $shipping |
|
386 | + */ |
|
387 | + protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
388 | 388 | |
389 | - // Ensure the invoice exists. |
|
389 | + // Ensure the invoice exists. |
|
390 | 390 | if ( ! $invoice->exists() ) { |
391 | 391 | wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
392 | 392 | } |
393 | 393 | |
394 | - // Save payment form data. |
|
395 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
394 | + // Save payment form data. |
|
395 | + $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
396 | 396 | delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
397 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
398 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
397 | + delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
398 | + if ( ! empty( $prepared_payment_form_data ) ) { |
|
399 | 399 | |
400 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
401 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
402 | - } |
|
400 | + if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
401 | + update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
402 | + } |
|
403 | 403 | |
404 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
405 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
406 | - } |
|
404 | + if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
405 | + update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
406 | + } |
|
407 | 407 | } |
408 | 408 | |
409 | - // Save payment form data. |
|
410 | - $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
409 | + // Save payment form data. |
|
410 | + $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
411 | 411 | if ( ! empty( $shipping ) ) { |
412 | 412 | update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
413 | - } |
|
413 | + } |
|
414 | 414 | |
415 | - // Backwards compatibility. |
|
415 | + // Backwards compatibility. |
|
416 | 416 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
417 | 417 | |
418 | - $this->process_payment( $invoice ); |
|
418 | + $this->process_payment( $invoice ); |
|
419 | 419 | |
420 | 420 | // If we are here, there was an error. |
421 | - wpinv_send_back_to_checkout( $invoice ); |
|
421 | + wpinv_send_back_to_checkout( $invoice ); |
|
422 | 422 | |
423 | - } |
|
423 | + } |
|
424 | 424 | |
425 | - /** |
|
426 | - * Processes the actual payment. |
|
427 | - * |
|
428 | - * @param WPInv_Invoice $invoice |
|
429 | - */ |
|
430 | - protected function process_payment( $invoice ) { |
|
425 | + /** |
|
426 | + * Processes the actual payment. |
|
427 | + * |
|
428 | + * @param WPInv_Invoice $invoice |
|
429 | + */ |
|
430 | + protected function process_payment( $invoice ) { |
|
431 | 431 | |
432 | - // Clear any checkout errors. |
|
433 | - wpinv_clear_errors(); |
|
432 | + // Clear any checkout errors. |
|
433 | + wpinv_clear_errors(); |
|
434 | 434 | |
435 | - // No need to send free invoices to the gateway. |
|
436 | - if ( $invoice->is_free() ) { |
|
437 | - $this->process_free_payment( $invoice ); |
|
438 | - } |
|
435 | + // No need to send free invoices to the gateway. |
|
436 | + if ( $invoice->is_free() ) { |
|
437 | + $this->process_free_payment( $invoice ); |
|
438 | + } |
|
439 | 439 | |
440 | - $submission = $this->payment_form_submission; |
|
440 | + $submission = $this->payment_form_submission; |
|
441 | 441 | |
442 | - // Fires before sending to the gateway. |
|
443 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
442 | + // Fires before sending to the gateway. |
|
443 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
444 | 444 | |
445 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
446 | - $submission_data = $submission->get_data(); |
|
447 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
448 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
445 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
446 | + $submission_data = $submission->get_data(); |
|
447 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
448 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
449 | 449 | |
450 | - // Validate the currency. |
|
451 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
452 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
453 | - } |
|
450 | + // Validate the currency. |
|
451 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
452 | + wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
453 | + } |
|
454 | 454 | |
455 | - // Check to see if we have any errors. |
|
456 | - if ( wpinv_get_errors() ) { |
|
457 | - wpinv_send_back_to_checkout( $invoice ); |
|
458 | - } |
|
455 | + // Check to see if we have any errors. |
|
456 | + if ( wpinv_get_errors() ) { |
|
457 | + wpinv_send_back_to_checkout( $invoice ); |
|
458 | + } |
|
459 | 459 | |
460 | - // Send info to the gateway for payment processing |
|
461 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
460 | + // Send info to the gateway for payment processing |
|
461 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
462 | 462 | |
463 | - // Backwards compatibility. |
|
464 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
463 | + // Backwards compatibility. |
|
464 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
465 | 465 | |
466 | - } |
|
466 | + } |
|
467 | 467 | |
468 | - /** |
|
469 | - * Marks the invoice as paid in case the checkout is free. |
|
470 | - * |
|
471 | - * @param WPInv_Invoice $invoice |
|
472 | - */ |
|
473 | - protected function process_free_payment( $invoice ) { |
|
468 | + /** |
|
469 | + * Marks the invoice as paid in case the checkout is free. |
|
470 | + * |
|
471 | + * @param WPInv_Invoice $invoice |
|
472 | + */ |
|
473 | + protected function process_free_payment( $invoice ) { |
|
474 | 474 | |
475 | - $invoice->set_gateway( 'none' ); |
|
476 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
477 | - $invoice->mark_paid(); |
|
478 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
475 | + $invoice->set_gateway( 'none' ); |
|
476 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
477 | + $invoice->mark_paid(); |
|
478 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
479 | 479 | |
480 | - } |
|
480 | + } |
|
481 | 481 | |
482 | - /** |
|
482 | + /** |
|
483 | 483 | * Sends a redrect response to payment details. |
484 | 484 | * |
485 | 485 | */ |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Main Checkout Class. |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @param GetPaid_Payment_Form_Submission $submission |
24 | 24 | */ |
25 | - public function __construct( $submission ) { |
|
25 | + public function __construct($submission) { |
|
26 | 26 | $this->payment_form_submission = $submission; |
27 | 27 | } |
28 | 28 | |
@@ -38,22 +38,22 @@ discard block |
||
38 | 38 | // Prepare the invoice. |
39 | 39 | $items = $this->get_submission_items(); |
40 | 40 | $invoice = $this->get_submission_invoice(); |
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
41 | + $invoice = $this->process_submission_invoice($invoice, $items); |
|
42 | 42 | $prepared = $this->prepare_submission_data_for_saving(); |
43 | 43 | |
44 | - $this->prepare_billing_info( $invoice ); |
|
44 | + $this->prepare_billing_info($invoice); |
|
45 | 45 | |
46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
46 | + $shipping = $this->prepare_shipping_info($invoice); |
|
47 | 47 | |
48 | 48 | // Save the invoice. |
49 | - $invoice->set_is_viewed( true ); |
|
49 | + $invoice->set_is_viewed(true); |
|
50 | 50 | $invoice->recalculate_total(); |
51 | 51 | $invoice->save(); |
52 | 52 | |
53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
53 | + do_action('getpaid_checkout_invoice_updated', $invoice); |
|
54 | 54 | |
55 | 55 | // Send to the gateway. |
56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
56 | + $this->post_process_submission($invoice, $prepared, $shipping); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -66,34 +66,34 @@ discard block |
||
66 | 66 | $data = $submission->get_data(); |
67 | 67 | |
68 | 68 | // Do we have an error? |
69 | - if ( ! empty( $submission->last_error ) ) { |
|
70 | - wp_send_json_error( $submission->last_error ); |
|
69 | + if (!empty($submission->last_error)) { |
|
70 | + wp_send_json_error($submission->last_error); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // We need a billing email. |
74 | - if ( ! $submission->has_billing_email() ) { |
|
75 | - wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
|
74 | + if (!$submission->has_billing_email()) { |
|
75 | + wp_send_json_error(__('Provide a valid billing email.', 'invoicing')); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // Non-recurring gateways should not be allowed to process recurring invoices. |
79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
79 | + if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) { |
|
80 | + wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing')); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | // Ensure the gateway is active. |
84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | - wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
84 | + if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) { |
|
85 | + wp_send_json_error(__('The selected payment gateway is not active', 'invoicing')); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | // Clear any existing errors. |
89 | 89 | wpinv_clear_errors(); |
90 | 90 | |
91 | 91 | // Allow themes and plugins to hook to errors |
92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
92 | + do_action('getpaid_checkout_error_checks', $submission); |
|
93 | 93 | |
94 | 94 | // Do we have any errors? |
95 | - if ( wpinv_get_errors() ) { |
|
96 | - wp_send_json_error( getpaid_get_errors_html() ); |
|
95 | + if (wpinv_get_errors()) { |
|
96 | + wp_send_json_error(getpaid_get_errors_html()); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | } |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | $items = $this->payment_form_submission->get_items(); |
109 | 109 | |
110 | 110 | // Ensure that we have items. |
111 | - if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
|
112 | - wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
|
111 | + if (empty($items) && !$this->payment_form_submission->has_fees()) { |
|
112 | + wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing')); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | return $items; |
@@ -123,17 +123,17 @@ discard block |
||
123 | 123 | protected function get_submission_invoice() { |
124 | 124 | $submission = $this->payment_form_submission; |
125 | 125 | |
126 | - if ( ! $submission->has_invoice() ) { |
|
126 | + if (!$submission->has_invoice()) { |
|
127 | 127 | $invoice = new WPInv_Invoice(); |
128 | - $invoice->set_created_via( 'payment_form' ); |
|
128 | + $invoice->set_created_via('payment_form'); |
|
129 | 129 | return $invoice; |
130 | 130 | } |
131 | 131 | |
132 | 132 | $invoice = $submission->get_invoice(); |
133 | 133 | |
134 | 134 | // Make sure that it is neither paid or refunded. |
135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
135 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
136 | + wp_send_json_error(__('This invoice has already been paid for.', 'invoicing')); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | return $invoice; |
@@ -146,33 +146,33 @@ discard block |
||
146 | 146 | * @param GetPaid_Form_Item[] $items |
147 | 147 | * @return WPInv_Invoice |
148 | 148 | */ |
149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
149 | + protected function process_submission_invoice($invoice, $items) { |
|
150 | 150 | |
151 | 151 | $submission = $this->payment_form_submission; |
152 | 152 | |
153 | 153 | // Set-up the invoice details. |
154 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
157 | - $invoice->set_items( $items ); |
|
158 | - $invoice->set_fees( $submission->get_fees() ); |
|
159 | - $invoice->set_taxes( $submission->get_taxes() ); |
|
160 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
161 | - $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
162 | - $invoice->set_currency( $submission->get_currency() ); |
|
163 | - |
|
164 | - if ( $submission->has_shipping() ) { |
|
165 | - $invoice->set_shipping( $submission->get_shipping() ); |
|
154 | + $invoice->set_email(sanitize_email($submission->get_billing_email())); |
|
155 | + $invoice->set_user_id($this->get_submission_customer()); |
|
156 | + $invoice->set_payment_form(absint($submission->get_payment_form()->get_id())); |
|
157 | + $invoice->set_items($items); |
|
158 | + $invoice->set_fees($submission->get_fees()); |
|
159 | + $invoice->set_taxes($submission->get_taxes()); |
|
160 | + $invoice->set_discounts($submission->get_discounts()); |
|
161 | + $invoice->set_gateway($submission->get_field('wpi-gateway')); |
|
162 | + $invoice->set_currency($submission->get_currency()); |
|
163 | + |
|
164 | + if ($submission->has_shipping()) { |
|
165 | + $invoice->set_shipping($submission->get_shipping()); |
|
166 | 166 | } |
167 | 167 | |
168 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
169 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
168 | + $address_confirmed = $submission->get_field('confirm-address'); |
|
169 | + $invoice->set_address_confirmed(!empty($address_confirmed)); |
|
170 | 170 | |
171 | - if ( $submission->has_discount_code() ) { |
|
172 | - $invoice->set_discount_code( $submission->get_discount_code() ); |
|
171 | + if ($submission->has_discount_code()) { |
|
172 | + $invoice->set_discount_code($submission->get_discount_code()); |
|
173 | 173 | } |
174 | 174 | |
175 | - getpaid_maybe_add_default_address( $invoice ); |
|
175 | + getpaid_maybe_add_default_address($invoice); |
|
176 | 176 | return $invoice; |
177 | 177 | } |
178 | 178 | |
@@ -185,34 +185,34 @@ discard block |
||
185 | 185 | $submission = $this->payment_form_submission; |
186 | 186 | |
187 | 187 | // If this is an existing invoice... |
188 | - if ( $submission->has_invoice() ) { |
|
188 | + if ($submission->has_invoice()) { |
|
189 | 189 | return $submission->get_invoice()->get_user_id(); |
190 | 190 | } |
191 | 191 | |
192 | 192 | // (Maybe) create the user. |
193 | 193 | $user = get_current_user_id(); |
194 | 194 | |
195 | - if ( empty( $user ) ) { |
|
196 | - $user = get_user_by( 'email', $submission->get_billing_email() ); |
|
195 | + if (empty($user)) { |
|
196 | + $user = get_user_by('email', $submission->get_billing_email()); |
|
197 | 197 | } |
198 | 198 | |
199 | - if ( empty( $user ) ) { |
|
200 | - $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
201 | - $name = implode( '', array_filter( $name ) ); |
|
202 | - $user = wpinv_create_user( $submission->get_billing_email(), $name ); |
|
199 | + if (empty($user)) { |
|
200 | + $name = array($submission->get_field('wpinv_first_name', 'billing'), $submission->get_field('wpinv_last_name', 'billing')); |
|
201 | + $name = implode('', array_filter($name)); |
|
202 | + $user = wpinv_create_user($submission->get_billing_email(), $name); |
|
203 | 203 | |
204 | 204 | // (Maybe) send new user notification. |
205 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
206 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
207 | - wp_send_new_user_notifications( $user, 'user' ); |
|
205 | + $should_send_notification = wpinv_get_option('disable_new_user_emails'); |
|
206 | + if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification), $user)) { |
|
207 | + wp_send_new_user_notifications($user, 'user'); |
|
208 | 208 | } |
209 | 209 | } |
210 | 210 | |
211 | - if ( is_wp_error( $user ) ) { |
|
212 | - wp_send_json_error( $user->get_error_message() ); |
|
211 | + if (is_wp_error($user)) { |
|
212 | + wp_send_json_error($user->get_error_message()); |
|
213 | 213 | } |
214 | 214 | |
215 | - if ( is_numeric( $user ) ) { |
|
215 | + if (is_numeric($user)) { |
|
216 | 216 | return $user; |
217 | 217 | } |
218 | 218 | |
@@ -236,72 +236,72 @@ discard block |
||
236 | 236 | ); |
237 | 237 | |
238 | 238 | // Raw submission details. |
239 | - $data = $submission->get_data(); |
|
239 | + $data = $submission->get_data(); |
|
240 | 240 | |
241 | 241 | // Loop through the submitted details. |
242 | - foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
|
242 | + foreach ($submission->get_payment_form()->get_elements() as $field) { |
|
243 | 243 | |
244 | 244 | // Skip premade fields. |
245 | - if ( ! empty( $field['premade'] ) ) { |
|
245 | + if (!empty($field['premade'])) { |
|
246 | 246 | continue; |
247 | 247 | } |
248 | 248 | |
249 | 249 | // Ensure address is provided. |
250 | - if ( $field['type'] == 'address' ) { |
|
251 | - $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
|
250 | + if ($field['type'] == 'address') { |
|
251 | + $address_type = isset($field['address_type']) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
|
252 | 252 | |
253 | - foreach ( $field['fields'] as $address_field ) { |
|
253 | + foreach ($field['fields'] as $address_field) { |
|
254 | 254 | |
255 | - if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { |
|
256 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
255 | + if (!empty($address_field['visible']) && !empty($address_field['required']) && '' === trim($_POST[$address_type][$address_field['name']])) { |
|
256 | + wp_send_json_error(__('Please fill all required fields.', 'invoicing')); |
|
257 | 257 | } |
258 | 258 | } |
259 | 259 | } |
260 | 260 | |
261 | 261 | // If it is required and not set, abort. |
262 | - if ( ! $submission->is_required_field_set( $field ) ) { |
|
263 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
262 | + if (!$submission->is_required_field_set($field)) { |
|
263 | + wp_send_json_error(__('Please fill all required fields.', 'invoicing')); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | // Handle misc fields. |
267 | - if ( isset( $data[ $field['id'] ] ) ) { |
|
267 | + if (isset($data[$field['id']])) { |
|
268 | 268 | |
269 | 269 | // Uploads. |
270 | - if ( $field['type'] == 'file_upload' ) { |
|
271 | - $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
270 | + if ($field['type'] == 'file_upload') { |
|
271 | + $max_file_num = empty($field['max_file_num']) ? 1 : absint($field['max_file_num']); |
|
272 | 272 | |
273 | - if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
274 | - wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
273 | + if (count($data[$field['id']]) > $max_file_num) { |
|
274 | + wp_send_json_error(__('Maximum number of allowed files exceeded.', 'invoicing')); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | $value = array(); |
278 | 278 | |
279 | - foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
279 | + foreach ($data[$field['id']] as $url => $name) { |
|
280 | 280 | $value[] = sprintf( |
281 | 281 | '<a href="%s" target="_blank">%s</a>', |
282 | - esc_url_raw( $url ), |
|
283 | - esc_html( $name ) |
|
282 | + esc_url_raw($url), |
|
283 | + esc_html($name) |
|
284 | 284 | ); |
285 | 285 | } |
286 | 286 | |
287 | - $value = implode( ' | ', $value ); |
|
287 | + $value = implode(' | ', $value); |
|
288 | 288 | |
289 | - } elseif ( $field['type'] == 'checkbox' ) { |
|
290 | - $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
289 | + } elseif ($field['type'] == 'checkbox') { |
|
290 | + $value = isset($data[$field['id']]) ? __('Yes', 'invoicing') : __('No', 'invoicing'); |
|
291 | 291 | } else { |
292 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
292 | + $value = wp_kses_post($data[$field['id']]); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | $label = $field['id']; |
296 | 296 | |
297 | - if ( isset( $field['label'] ) ) { |
|
297 | + if (isset($field['label'])) { |
|
298 | 298 | $label = $field['label']; |
299 | 299 | } |
300 | 300 | |
301 | - if ( ! empty( $field['add_meta'] ) ) { |
|
302 | - $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
301 | + if (!empty($field['add_meta'])) { |
|
302 | + $prepared['meta'][wpinv_clean($label)] = wp_kses_post_deep($value); |
|
303 | 303 | } |
304 | - $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
304 | + $prepared['all'][wpinv_clean($label)] = wp_kses_post_deep($value); |
|
305 | 305 | |
306 | 306 | } |
307 | 307 | } |
@@ -317,30 +317,30 @@ discard block |
||
317 | 317 | * @param WPInv_Invoice $invoice |
318 | 318 | * @param string $type |
319 | 319 | */ |
320 | - public function prepare_address_details( $invoice, $type = 'billing' ) { |
|
320 | + public function prepare_address_details($invoice, $type = 'billing') { |
|
321 | 321 | |
322 | 322 | $data = $this->payment_form_submission->get_data(); |
323 | - $type = sanitize_key( $type ); |
|
323 | + $type = sanitize_key($type); |
|
324 | 324 | $address = array(); |
325 | 325 | $prepared = array(); |
326 | 326 | |
327 | - if ( ! empty( $data[ $type ] ) ) { |
|
328 | - $address = $data[ $type ]; |
|
327 | + if (!empty($data[$type])) { |
|
328 | + $address = $data[$type]; |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | // Clean address details. |
332 | - foreach ( $address as $key => $value ) { |
|
333 | - $key = sanitize_key( $key ); |
|
334 | - $key = str_replace( 'wpinv_', '', $key ); |
|
335 | - $value = wpinv_clean( $value ); |
|
336 | - $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
332 | + foreach ($address as $key => $value) { |
|
333 | + $key = sanitize_key($key); |
|
334 | + $key = str_replace('wpinv_', '', $key); |
|
335 | + $value = wpinv_clean($value); |
|
336 | + $prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | // Filter address details. |
340 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
340 | + $prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice); |
|
341 | 341 | |
342 | 342 | // Remove non-whitelisted values. |
343 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
343 | + return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY); |
|
344 | 344 | |
345 | 345 | } |
346 | 346 | |
@@ -350,12 +350,12 @@ discard block |
||
350 | 350 | * @return array |
351 | 351 | * @param WPInv_Invoice $invoice |
352 | 352 | */ |
353 | - protected function prepare_billing_info( &$invoice ) { |
|
353 | + protected function prepare_billing_info(&$invoice) { |
|
354 | 354 | |
355 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
355 | + $billing_address = $this->prepare_address_details($invoice, 'billing'); |
|
356 | 356 | |
357 | 357 | // Update the invoice with the billing details. |
358 | - $invoice->set_props( $billing_address ); |
|
358 | + $invoice->set_props($billing_address); |
|
359 | 359 | |
360 | 360 | } |
361 | 361 | |
@@ -365,15 +365,15 @@ discard block |
||
365 | 365 | * @return array |
366 | 366 | * @param WPInv_Invoice $invoice |
367 | 367 | */ |
368 | - protected function prepare_shipping_info( $invoice ) { |
|
368 | + protected function prepare_shipping_info($invoice) { |
|
369 | 369 | |
370 | 370 | $data = $this->payment_form_submission->get_data(); |
371 | 371 | |
372 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
373 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
372 | + if (empty($data['same-shipping-address'])) { |
|
373 | + return $this->prepare_address_details($invoice, 'shipping'); |
|
374 | 374 | } |
375 | 375 | |
376 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
376 | + return $this->prepare_address_details($invoice, 'billing'); |
|
377 | 377 | |
378 | 378 | } |
379 | 379 | |
@@ -384,41 +384,41 @@ discard block |
||
384 | 384 | * @param array $prepared_payment_form_data |
385 | 385 | * @param array $shipping |
386 | 386 | */ |
387 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
387 | + protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) { |
|
388 | 388 | |
389 | 389 | // Ensure the invoice exists. |
390 | - if ( ! $invoice->exists() ) { |
|
391 | - wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
|
390 | + if (!$invoice->exists()) { |
|
391 | + wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing')); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | // Save payment form data. |
395 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
396 | - delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
|
397 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
398 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
395 | + $prepared_payment_form_data = apply_filters('getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice); |
|
396 | + delete_post_meta($invoice->get_id(), 'payment_form_data'); |
|
397 | + delete_post_meta($invoice->get_id(), 'additional_meta_data'); |
|
398 | + if (!empty($prepared_payment_form_data)) { |
|
399 | 399 | |
400 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
401 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
400 | + if (!empty($prepared_payment_form_data['all'])) { |
|
401 | + update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all']); |
|
402 | 402 | } |
403 | 403 | |
404 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
405 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
404 | + if (!empty($prepared_payment_form_data['meta'])) { |
|
405 | + update_post_meta($invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta']); |
|
406 | 406 | } |
407 | 407 | } |
408 | 408 | |
409 | 409 | // Save payment form data. |
410 | - $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
411 | - if ( ! empty( $shipping ) ) { |
|
412 | - update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
|
410 | + $shipping = apply_filters('getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission); |
|
411 | + if (!empty($shipping)) { |
|
412 | + update_post_meta($invoice->get_id(), 'shipping_address', $shipping); |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | // Backwards compatibility. |
416 | - add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
|
416 | + add_filter('wp_redirect', array($this, 'send_redirect_response')); |
|
417 | 417 | |
418 | - $this->process_payment( $invoice ); |
|
418 | + $this->process_payment($invoice); |
|
419 | 419 | |
420 | 420 | // If we are here, there was an error. |
421 | - wpinv_send_back_to_checkout( $invoice ); |
|
421 | + wpinv_send_back_to_checkout($invoice); |
|
422 | 422 | |
423 | 423 | } |
424 | 424 | |
@@ -427,41 +427,41 @@ discard block |
||
427 | 427 | * |
428 | 428 | * @param WPInv_Invoice $invoice |
429 | 429 | */ |
430 | - protected function process_payment( $invoice ) { |
|
430 | + protected function process_payment($invoice) { |
|
431 | 431 | |
432 | 432 | // Clear any checkout errors. |
433 | 433 | wpinv_clear_errors(); |
434 | 434 | |
435 | 435 | // No need to send free invoices to the gateway. |
436 | - if ( $invoice->is_free() ) { |
|
437 | - $this->process_free_payment( $invoice ); |
|
436 | + if ($invoice->is_free()) { |
|
437 | + $this->process_free_payment($invoice); |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | $submission = $this->payment_form_submission; |
441 | 441 | |
442 | 442 | // Fires before sending to the gateway. |
443 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
443 | + do_action('getpaid_checkout_before_gateway', $invoice, $submission); |
|
444 | 444 | |
445 | 445 | // Allow the sumission data to be modified before it is sent to the gateway. |
446 | 446 | $submission_data = $submission->get_data(); |
447 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
448 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
447 | + $submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice); |
|
448 | + $submission_data = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice); |
|
449 | 449 | |
450 | 450 | // Validate the currency. |
451 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
452 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
451 | + if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) { |
|
452 | + wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support this currency', 'invoicing')); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | // Check to see if we have any errors. |
456 | - if ( wpinv_get_errors() ) { |
|
457 | - wpinv_send_back_to_checkout( $invoice ); |
|
456 | + if (wpinv_get_errors()) { |
|
457 | + wpinv_send_back_to_checkout($invoice); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | // Send info to the gateway for payment processing |
461 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
461 | + do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission); |
|
462 | 462 | |
463 | 463 | // Backwards compatibility. |
464 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
464 | + wpinv_send_to_gateway($submission_gateway, $invoice); |
|
465 | 465 | |
466 | 466 | } |
467 | 467 | |
@@ -470,12 +470,12 @@ discard block |
||
470 | 470 | * |
471 | 471 | * @param WPInv_Invoice $invoice |
472 | 472 | */ |
473 | - protected function process_free_payment( $invoice ) { |
|
473 | + protected function process_free_payment($invoice) { |
|
474 | 474 | |
475 | - $invoice->set_gateway( 'none' ); |
|
476 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
475 | + $invoice->set_gateway('none'); |
|
476 | + $invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true); |
|
477 | 477 | $invoice->mark_paid(); |
478 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
478 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
479 | 479 | |
480 | 480 | } |
481 | 481 | |
@@ -483,9 +483,9 @@ discard block |
||
483 | 483 | * Sends a redrect response to payment details. |
484 | 484 | * |
485 | 485 | */ |
486 | - public function send_redirect_response( $url ) { |
|
487 | - $url = urlencode( $url ); |
|
488 | - wp_send_json_success( $url ); |
|
486 | + public function send_redirect_response($url) { |
|
487 | + $url = urlencode($url); |
|
488 | + wp_send_json_success($url); |
|
489 | 489 | } |
490 | 490 | |
491 | 491 | } |