@@ -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'], true ); |
|
372 | + if ($args['show_option_none']) { |
|
373 | + if ($args['multiple']) { |
|
374 | + $selected = in_array('', $args['selected'], true); |
|
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'], true ); |
|
384 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
385 | + $selected = in_array($key, $args['selected'], true); |
|
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', |
@@ -428,40 +428,40 @@ discard block |
||
428 | 428 | ), |
429 | 429 | ); |
430 | 430 | |
431 | - $item_args = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults ); |
|
431 | + $item_args = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults); |
|
432 | 432 | |
433 | - $items = get_posts( $item_args ); |
|
433 | + $items = get_posts($item_args); |
|
434 | 434 | $options = array(); |
435 | - if ( $items ) { |
|
436 | - foreach ( $items as $item ) { |
|
437 | - $title = esc_html( $item->post_title ); |
|
435 | + if ($items) { |
|
436 | + foreach ($items as $item) { |
|
437 | + $title = esc_html($item->post_title); |
|
438 | 438 | |
439 | - if ( ! empty( $args['show_recurring'] ) ) { |
|
440 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
439 | + if (!empty($args['show_recurring'])) { |
|
440 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
441 | 441 | } |
442 | 442 | |
443 | - $options[ absint( $item->ID ) ] = $title; |
|
443 | + $options[absint($item->ID)] = $title; |
|
444 | 444 | } |
445 | 445 | } |
446 | 446 | |
447 | 447 | // This ensures that any selected items are included in the drop down |
448 | - if ( is_array( $args['selected'] ) ) { |
|
449 | - foreach ( $args['selected'] as $item ) { |
|
450 | - if ( ! in_array( $item, $options ) ) { |
|
451 | - $title = get_the_title( $item ); |
|
452 | - if ( ! empty( $args['show_recurring'] ) ) { |
|
453 | - $title .= wpinv_get_item_suffix( $item, false ); |
|
448 | + if (is_array($args['selected'])) { |
|
449 | + foreach ($args['selected'] as $item) { |
|
450 | + if (!in_array($item, $options)) { |
|
451 | + $title = get_the_title($item); |
|
452 | + if (!empty($args['show_recurring'])) { |
|
453 | + $title .= wpinv_get_item_suffix($item, false); |
|
454 | 454 | } |
455 | - $options[ $item ] = $title; |
|
455 | + $options[$item] = $title; |
|
456 | 456 | } |
457 | 457 | } |
458 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
459 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
460 | - $title = get_the_title( $args['selected'] ); |
|
461 | - if ( ! empty( $args['show_recurring'] ) ) { |
|
462 | - $title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
458 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
459 | + if (!in_array($args['selected'], $options)) { |
|
460 | + $title = get_the_title($args['selected']); |
|
461 | + if (!empty($args['show_recurring'])) { |
|
462 | + $title .= wpinv_get_item_suffix($args['selected'], false); |
|
463 | 463 | } |
464 | - $options[ $args['selected'] ] = get_the_title( $args['selected'] ); |
|
464 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
465 | 465 | } |
466 | 466 | } |
467 | 467 | |
@@ -497,16 +497,16 @@ discard block |
||
497 | 497 | ); |
498 | 498 | |
499 | 499 | $options = array(); |
500 | - if ( $items ) { |
|
501 | - foreach ( $items as $item ) { |
|
502 | - $options[ $item->ID ] = esc_html( $item->post_title ) . wpinv_get_item_suffix( $item->ID, false ); |
|
500 | + if ($items) { |
|
501 | + foreach ($items as $item) { |
|
502 | + $options[$item->ID] = esc_html($item->post_title) . wpinv_get_item_suffix($item->ID, false); |
|
503 | 503 | } |
504 | 504 | } |
505 | 505 | |
506 | 506 | return $options; |
507 | 507 | } |
508 | 508 | |
509 | -function wpinv_html_checkbox( $args = array() ) { |
|
509 | +function wpinv_html_checkbox($args = array()) { |
|
510 | 510 | $defaults = array( |
511 | 511 | 'name' => null, |
512 | 512 | 'current' => null, |
@@ -517,17 +517,17 @@ discard block |
||
517 | 517 | ), |
518 | 518 | ); |
519 | 519 | |
520 | - $args = wp_parse_args( $args, $defaults ); |
|
520 | + $args = wp_parse_args($args, $defaults); |
|
521 | 521 | |
522 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
522 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
523 | 523 | $attr = ''; |
524 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
524 | + if (!empty($args['options']['disabled'])) { |
|
525 | 525 | $attr .= ' disabled="disabled"'; |
526 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
526 | + } elseif (!empty($args['options']['readonly'])) { |
|
527 | 527 | $attr .= ' readonly'; |
528 | 528 | } |
529 | 529 | |
530 | - $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 ) . ' />'; |
|
530 | + $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) . ' />'; |
|
531 | 531 | |
532 | 532 | return $output; |
533 | 533 | } |
@@ -535,34 +535,34 @@ discard block |
||
535 | 535 | /** |
536 | 536 | * Displays a hidden field. |
537 | 537 | */ |
538 | -function getpaid_hidden_field( $name, $value ) { |
|
539 | - echo "<input type='hidden' name='" . esc_attr( $name ) . "' value='" . esc_attr( $value ) . "' />"; |
|
538 | +function getpaid_hidden_field($name, $value) { |
|
539 | + echo "<input type='hidden' name='" . esc_attr($name) . "' value='" . esc_attr($value) . "' />"; |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | /** |
543 | 543 | * Displays a submit field. |
544 | 544 | */ |
545 | -function getpaid_submit_field( $value, $name = 'submit', $class = 'btn-primary' ) { |
|
546 | - echo "<input type='submit' name='" . esc_attr( $name ) . "' value='" . esc_attr( $value ) . "' class='btn " . esc_attr( $class ) . "' />"; |
|
545 | +function getpaid_submit_field($value, $name = 'submit', $class = 'btn-primary') { |
|
546 | + echo "<input type='submit' name='" . esc_attr($name) . "' value='" . esc_attr($value) . "' class='btn " . esc_attr($class) . "' />"; |
|
547 | 547 | } |
548 | 548 | |
549 | -function wpinv_html_text( $args = array() ) { |
|
549 | +function wpinv_html_text($args = array()) { |
|
550 | 550 | // Backwards compatibility |
551 | - if ( func_num_args() > 1 ) { |
|
551 | + if (func_num_args() > 1) { |
|
552 | 552 | $args = func_get_args(); |
553 | 553 | |
554 | 554 | $name = $args[0]; |
555 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
556 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
557 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
555 | + $value = isset($args[1]) ? $args[1] : ''; |
|
556 | + $label = isset($args[2]) ? $args[2] : ''; |
|
557 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
558 | 558 | } |
559 | 559 | |
560 | 560 | $defaults = array( |
561 | 561 | 'id' => '', |
562 | - 'name' => isset( $name ) ? $name : 'text', |
|
563 | - 'value' => isset( $value ) ? $value : null, |
|
564 | - 'label' => isset( $label ) ? $label : null, |
|
565 | - 'desc' => isset( $desc ) ? $desc : null, |
|
562 | + 'name' => isset($name) ? $name : 'text', |
|
563 | + 'value' => isset($value) ? $value : null, |
|
564 | + 'label' => isset($label) ? $label : null, |
|
565 | + 'desc' => isset($desc) ? $desc : null, |
|
566 | 566 | 'placeholder' => '', |
567 | 567 | 'class' => 'regular-text', |
568 | 568 | 'disabled' => false, |
@@ -572,41 +572,41 @@ discard block |
||
572 | 572 | 'data' => false, |
573 | 573 | ); |
574 | 574 | |
575 | - $args = wp_parse_args( $args, $defaults ); |
|
575 | + $args = wp_parse_args($args, $defaults); |
|
576 | 576 | |
577 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
577 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
578 | 578 | $options = ''; |
579 | - if ( $args['required'] ) { |
|
579 | + if ($args['required']) { |
|
580 | 580 | $options .= ' required="required"'; |
581 | 581 | } |
582 | - if ( $args['readonly'] ) { |
|
582 | + if ($args['readonly']) { |
|
583 | 583 | $options .= ' readonly'; |
584 | 584 | } |
585 | - if ( $args['readonly'] ) { |
|
585 | + if ($args['readonly']) { |
|
586 | 586 | $options .= ' readonly'; |
587 | 587 | } |
588 | 588 | |
589 | 589 | $data = ''; |
590 | - if ( ! empty( $args['data'] ) ) { |
|
591 | - foreach ( $args['data'] as $key => $value ) { |
|
592 | - $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
590 | + if (!empty($args['data'])) { |
|
591 | + foreach ($args['data'] as $key => $value) { |
|
592 | + $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" '; |
|
593 | 593 | } |
594 | 594 | } |
595 | 595 | |
596 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
597 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
598 | - if ( ! empty( $args['desc'] ) ) { |
|
599 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
596 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
597 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>'; |
|
598 | + if (!empty($args['desc'])) { |
|
599 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
600 | 600 | } |
601 | 601 | |
602 | - $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 ) . '/>'; |
|
602 | + $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) . '/>'; |
|
603 | 603 | |
604 | 604 | $output .= '</span>'; |
605 | 605 | |
606 | 606 | return $output; |
607 | 607 | } |
608 | 608 | |
609 | -function wpinv_html_textarea( $args = array() ) { |
|
609 | +function wpinv_html_textarea($args = array()) { |
|
610 | 610 | $defaults = array( |
611 | 611 | 'name' => 'textarea', |
612 | 612 | 'value' => null, |
@@ -617,31 +617,31 @@ discard block |
||
617 | 617 | 'placeholder' => '', |
618 | 618 | ); |
619 | 619 | |
620 | - $args = wp_parse_args( $args, $defaults ); |
|
620 | + $args = wp_parse_args($args, $defaults); |
|
621 | 621 | |
622 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
622 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
623 | 623 | $disabled = ''; |
624 | - if ( $args['disabled'] ) { |
|
624 | + if ($args['disabled']) { |
|
625 | 625 | $disabled = ' disabled="disabled"'; |
626 | 626 | } |
627 | 627 | |
628 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
629 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
630 | - $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>'; |
|
628 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
629 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>'; |
|
630 | + $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>'; |
|
631 | 631 | |
632 | - if ( ! empty( $args['desc'] ) ) { |
|
633 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
632 | + if (!empty($args['desc'])) { |
|
633 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
634 | 634 | } |
635 | 635 | $output .= '</span>'; |
636 | 636 | |
637 | 637 | return $output; |
638 | 638 | } |
639 | 639 | |
640 | -function wpinv_html_ajax_user_search( $args = array() ) { |
|
640 | +function wpinv_html_ajax_user_search($args = array()) { |
|
641 | 641 | $defaults = array( |
642 | 642 | 'name' => 'user_id', |
643 | 643 | 'value' => null, |
644 | - 'placeholder' => __( 'Enter username', 'invoicing' ), |
|
644 | + 'placeholder' => __('Enter username', 'invoicing'), |
|
645 | 645 | 'label' => null, |
646 | 646 | 'desc' => null, |
647 | 647 | 'class' => '', |
@@ -650,13 +650,13 @@ discard block |
||
650 | 650 | 'data' => false, |
651 | 651 | ); |
652 | 652 | |
653 | - $args = wp_parse_args( $args, $defaults ); |
|
653 | + $args = wp_parse_args($args, $defaults); |
|
654 | 654 | |
655 | 655 | $args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
656 | 656 | |
657 | 657 | $output = '<span class="wpinv_user_search_wrap">'; |
658 | - $output .= wpinv_html_text( $args ); |
|
659 | - $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>'; |
|
658 | + $output .= wpinv_html_text($args); |
|
659 | + $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>'; |
|
660 | 660 | $output .= '</span>'; |
661 | 661 | |
662 | 662 | return $output; |
@@ -667,44 +667,44 @@ discard block |
||
667 | 667 | * |
668 | 668 | * @param string $template the template that is currently being used. |
669 | 669 | */ |
670 | -function wpinv_template( $template ) { |
|
670 | +function wpinv_template($template) { |
|
671 | 671 | global $post; |
672 | 672 | |
673 | - if ( ! is_admin() && ( is_single() || is_404() ) && ! empty( $post->ID ) && getpaid_is_invoice_post_type( get_post_type( $post->ID ) ) ) { |
|
673 | + if (!is_admin() && (is_single() || is_404()) && !empty($post->ID) && getpaid_is_invoice_post_type(get_post_type($post->ID))) { |
|
674 | 674 | |
675 | 675 | // If the user can view this invoice, display it. |
676 | - if ( wpinv_user_can_view_invoice( $post->ID ) ) { |
|
676 | + if (wpinv_user_can_view_invoice($post->ID)) { |
|
677 | 677 | |
678 | - return wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
678 | + return wpinv_get_template_part('wpinv-invoice-print', false, false); |
|
679 | 679 | |
680 | 680 | // Else display an error message. |
681 | 681 | } else { |
682 | 682 | |
683 | - return wpinv_get_template_part( 'wpinv-invalid-access', false, false ); |
|
683 | + return wpinv_get_template_part('wpinv-invalid-access', false, false); |
|
684 | 684 | |
685 | 685 | } |
686 | 686 | } |
687 | 687 | |
688 | 688 | return $template; |
689 | 689 | } |
690 | -add_filter( 'template_include', 'wpinv_template', 1000, 1 ); |
|
690 | +add_filter('template_include', 'wpinv_template', 1000, 1); |
|
691 | 691 | |
692 | 692 | function wpinv_get_business_address() { |
693 | 693 | $business_address = wpinv_store_address(); |
694 | - $business_address = ! empty( $business_address ) ? wp_kses_post( wpautop( $business_address ) ) : ''; |
|
694 | + $business_address = !empty($business_address) ? wp_kses_post(wpautop($business_address)) : ''; |
|
695 | 695 | |
696 | 696 | $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
697 | 697 | |
698 | - return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
698 | + return apply_filters('wpinv_get_business_address', $business_address); |
|
699 | 699 | } |
700 | 700 | |
701 | 701 | /** |
702 | 702 | * Displays the company address. |
703 | 703 | */ |
704 | 704 | function wpinv_display_from_address() { |
705 | - wpinv_get_template( 'invoice/company-address.php' ); |
|
705 | + wpinv_get_template('invoice/company-address.php'); |
|
706 | 706 | } |
707 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_from_address', 10 ); |
|
707 | +add_action('getpaid_invoice_details_left', 'wpinv_display_from_address', 10); |
|
708 | 708 | |
709 | 709 | /** |
710 | 710 | * Generates a watermark text for an invoice. |
@@ -712,9 +712,9 @@ discard block |
||
712 | 712 | * @param WPInv_Invoice $invoice |
713 | 713 | * @return string |
714 | 714 | */ |
715 | -function wpinv_watermark( $invoice ) { |
|
716 | - $watermark = wpinv_get_watermark( $invoice ); |
|
717 | - return apply_filters( 'wpinv_get_watermark', $watermark, $invoice ); |
|
715 | +function wpinv_watermark($invoice) { |
|
716 | + $watermark = wpinv_get_watermark($invoice); |
|
717 | + return apply_filters('wpinv_get_watermark', $watermark, $invoice); |
|
718 | 718 | } |
719 | 719 | |
720 | 720 | /** |
@@ -723,37 +723,37 @@ discard block |
||
723 | 723 | * @param WPInv_Invoice $invoice |
724 | 724 | * @return string |
725 | 725 | */ |
726 | -function wpinv_get_watermark( $invoice ) { |
|
726 | +function wpinv_get_watermark($invoice) { |
|
727 | 727 | return $invoice->get_status_nicename(); |
728 | 728 | } |
729 | 729 | |
730 | 730 | /** |
731 | 731 | * @deprecated |
732 | 732 | */ |
733 | -function wpinv_display_invoice_details( $invoice ) { |
|
734 | - return getpaid_invoice_meta( $invoice ); |
|
733 | +function wpinv_display_invoice_details($invoice) { |
|
734 | + return getpaid_invoice_meta($invoice); |
|
735 | 735 | } |
736 | 736 | |
737 | 737 | /** |
738 | 738 | * Displays invoice meta. |
739 | 739 | */ |
740 | -function getpaid_invoice_meta( $invoice ) { |
|
740 | +function getpaid_invoice_meta($invoice) { |
|
741 | 741 | |
742 | - $invoice = new WPInv_Invoice( $invoice ); |
|
742 | + $invoice = new WPInv_Invoice($invoice); |
|
743 | 743 | |
744 | 744 | // Ensure that we have an invoice. |
745 | - if ( 0 == $invoice->get_id() ) { |
|
745 | + if (0 == $invoice->get_id()) { |
|
746 | 746 | return; |
747 | 747 | } |
748 | 748 | |
749 | 749 | // Get the invoice meta. |
750 | - $meta = getpaid_get_invoice_meta( $invoice ); |
|
750 | + $meta = getpaid_get_invoice_meta($invoice); |
|
751 | 751 | |
752 | 752 | // Display the meta. |
753 | - wpinv_get_template( 'invoice/invoice-meta.php', compact( 'invoice', 'meta' ) ); |
|
753 | + wpinv_get_template('invoice/invoice-meta.php', compact('invoice', 'meta')); |
|
754 | 754 | |
755 | 755 | } |
756 | -add_action( 'getpaid_invoice_details_right', 'getpaid_invoice_meta', 10 ); |
|
756 | +add_action('getpaid_invoice_details_right', 'getpaid_invoice_meta', 10); |
|
757 | 757 | |
758 | 758 | /** |
759 | 759 | * Retrieves the address markup to use on Invoices. |
@@ -765,29 +765,29 @@ discard block |
||
765 | 765 | * @param string $separator How to separate address lines. |
766 | 766 | * @return string |
767 | 767 | */ |
768 | -function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) { |
|
768 | +function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') { |
|
769 | 769 | |
770 | 770 | // Retrieve the address markup... |
771 | - $country = empty( $billing_details['country'] ) ? '' : $billing_details['country']; |
|
772 | - $format = wpinv_get_full_address_format( $country ); |
|
771 | + $country = empty($billing_details['country']) ? '' : $billing_details['country']; |
|
772 | + $format = wpinv_get_full_address_format($country); |
|
773 | 773 | |
774 | 774 | // ... and the replacements. |
775 | - $replacements = wpinv_get_invoice_address_replacements( $billing_details ); |
|
775 | + $replacements = wpinv_get_invoice_address_replacements($billing_details); |
|
776 | 776 | |
777 | - $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
|
777 | + $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format); |
|
778 | 778 | |
779 | 779 | // Remove unavailable tags. |
780 | - $formatted_address = preg_replace( '/\{\{\w+\}\}/', '', $formatted_address ); |
|
780 | + $formatted_address = preg_replace('/\{\{\w+\}\}/', '', $formatted_address); |
|
781 | 781 | |
782 | 782 | // Clean up white space. |
783 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
784 | - $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
|
783 | + $formatted_address = preg_replace('/ +/', ' ', trim($formatted_address)); |
|
784 | + $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address); |
|
785 | 785 | |
786 | 786 | // Break newlines apart and remove empty lines/trim commas and white space. |
787 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
787 | + $formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address))); |
|
788 | 788 | |
789 | 789 | // Add html breaks. |
790 | - $formatted_address = implode( $separator, $formatted_address ); |
|
790 | + $formatted_address = implode($separator, $formatted_address); |
|
791 | 791 | |
792 | 792 | // We're done! |
793 | 793 | return $formatted_address; |
@@ -799,118 +799,118 @@ discard block |
||
799 | 799 | * |
800 | 800 | * @param WPInv_Invoice $invoice |
801 | 801 | */ |
802 | -function wpinv_display_to_address( $invoice = 0 ) { |
|
803 | - if ( ! empty( $invoice ) ) { |
|
804 | - wpinv_get_template( 'invoice/billing-address.php', compact( 'invoice' ) ); |
|
802 | +function wpinv_display_to_address($invoice = 0) { |
|
803 | + if (!empty($invoice)) { |
|
804 | + wpinv_get_template('invoice/billing-address.php', compact('invoice')); |
|
805 | 805 | } |
806 | 806 | } |
807 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_to_address', 40 ); |
|
807 | +add_action('getpaid_invoice_details_left', 'wpinv_display_to_address', 40); |
|
808 | 808 | |
809 | 809 | |
810 | 810 | /** |
811 | 811 | * Displays invoice line items. |
812 | 812 | */ |
813 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
813 | +function wpinv_display_line_items($invoice_id = 0) { |
|
814 | 814 | |
815 | 815 | // Prepare the invoice. |
816 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
816 | + $invoice = new WPInv_Invoice($invoice_id); |
|
817 | 817 | |
818 | 818 | // Abort if there is no invoice. |
819 | - if ( 0 == $invoice->get_id() ) { |
|
819 | + if (0 == $invoice->get_id()) { |
|
820 | 820 | return; |
821 | 821 | } |
822 | 822 | |
823 | 823 | // Line item columns. |
824 | - $columns = getpaid_invoice_item_columns( $invoice ); |
|
825 | - $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice ); |
|
824 | + $columns = getpaid_invoice_item_columns($invoice); |
|
825 | + $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice); |
|
826 | 826 | |
827 | - wpinv_get_template( 'invoice/line-items.php', compact( 'invoice', 'columns' ) ); |
|
827 | + wpinv_get_template('invoice/line-items.php', compact('invoice', 'columns')); |
|
828 | 828 | } |
829 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_line_items', 10 ); |
|
829 | +add_action('getpaid_invoice_line_items', 'wpinv_display_line_items', 10); |
|
830 | 830 | |
831 | 831 | /** |
832 | 832 | * Displays invoice subscriptions. |
833 | 833 | * |
834 | 834 | * @param WPInv_Invoice $invoice |
835 | 835 | */ |
836 | -function getpaid_display_invoice_subscriptions( $invoice ) { |
|
836 | +function getpaid_display_invoice_subscriptions($invoice) { |
|
837 | 837 | |
838 | 838 | // Subscriptions. |
839 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
839 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
840 | 840 | |
841 | - if ( empty( $subscriptions ) || ! $invoice->is_recurring() ) { |
|
841 | + if (empty($subscriptions) || !$invoice->is_recurring()) { |
|
842 | 842 | return; |
843 | 843 | } |
844 | 844 | |
845 | - $main_subscription = getpaid_get_invoice_subscription( $invoice ); |
|
845 | + $main_subscription = getpaid_get_invoice_subscription($invoice); |
|
846 | 846 | |
847 | 847 | // Display related subscriptions. |
848 | - if ( is_array( $subscriptions ) ) { |
|
849 | - printf( '<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__( 'Related Subscriptions', 'invoicing' ) ); |
|
850 | - getpaid_admin_subscription_related_subscriptions_metabox( $main_subscription, false ); |
|
848 | + if (is_array($subscriptions)) { |
|
849 | + printf('<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__('Related Subscriptions', 'invoicing')); |
|
850 | + getpaid_admin_subscription_related_subscriptions_metabox($main_subscription, false); |
|
851 | 851 | } |
852 | 852 | |
853 | - if ( $main_subscription->get_total_payments() > 1 ) { |
|
854 | - printf( '<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__( 'Related Invoices', 'invoicing' ) ); |
|
855 | - getpaid_admin_subscription_invoice_details_metabox( $main_subscription, false ); |
|
853 | + if ($main_subscription->get_total_payments() > 1) { |
|
854 | + printf('<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__('Related Invoices', 'invoicing')); |
|
855 | + getpaid_admin_subscription_invoice_details_metabox($main_subscription, false); |
|
856 | 856 | } |
857 | 857 | |
858 | 858 | } |
859 | -add_action( 'getpaid_invoice_line_items', 'getpaid_display_invoice_subscriptions', 55 ); |
|
860 | -add_action( 'wpinv_receipt_end', 'getpaid_display_invoice_subscriptions', 11 ); |
|
859 | +add_action('getpaid_invoice_line_items', 'getpaid_display_invoice_subscriptions', 55); |
|
860 | +add_action('wpinv_receipt_end', 'getpaid_display_invoice_subscriptions', 11); |
|
861 | 861 | |
862 | 862 | /** |
863 | 863 | * Displays invoice notices on invoices. |
864 | 864 | */ |
865 | 865 | function wpinv_display_invoice_notice() { |
866 | 866 | |
867 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
868 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
867 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
868 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
869 | 869 | |
870 | - if ( empty( $label ) && empty( $notice ) ) { |
|
870 | + if (empty($label) && empty($notice)) { |
|
871 | 871 | return; |
872 | 872 | } |
873 | 873 | |
874 | 874 | echo '<div class="mt-4 mb-4 wpinv-vat-notice">'; |
875 | 875 | |
876 | - if ( ! empty( $label ) ) { |
|
877 | - echo "<h5>" . esc_html( $label ) . "</h5>"; |
|
876 | + if (!empty($label)) { |
|
877 | + echo "<h5>" . esc_html($label) . "</h5>"; |
|
878 | 878 | } |
879 | 879 | |
880 | - if ( ! empty( $notice ) ) { |
|
881 | - echo '<small class="form-text text-muted">' . wp_kses_post( wpautop( wptexturize( $notice ) ) ) . '</small>'; |
|
880 | + if (!empty($notice)) { |
|
881 | + echo '<small class="form-text text-muted">' . wp_kses_post(wpautop(wptexturize($notice))) . '</small>'; |
|
882 | 882 | } |
883 | 883 | |
884 | 884 | echo '</div>'; |
885 | 885 | } |
886 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100 ); |
|
886 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100); |
|
887 | 887 | |
888 | 888 | /** |
889 | 889 | * @param WPInv_Invoice $invoice |
890 | 890 | */ |
891 | -function wpinv_display_invoice_notes( $invoice ) { |
|
891 | +function wpinv_display_invoice_notes($invoice) { |
|
892 | 892 | |
893 | 893 | // Retrieve the notes. |
894 | - $notes = wpinv_get_invoice_notes( $invoice->get_id(), 'customer' ); |
|
894 | + $notes = wpinv_get_invoice_notes($invoice->get_id(), 'customer'); |
|
895 | 895 | |
896 | 896 | // Abort if we have non. |
897 | - if ( empty( $notes ) ) { |
|
897 | + if (empty($notes)) { |
|
898 | 898 | return; |
899 | 899 | } |
900 | 900 | |
901 | 901 | // Echo the note. |
902 | 902 | echo '<div class="getpaid-invoice-notes-wrapper position-relative my-4">'; |
903 | - echo '<h2 class="getpaid-invoice-notes-title mb-1 p-0 h4">' . esc_html__( 'Notes', 'invoicing' ) . '</h2>'; |
|
903 | + echo '<h2 class="getpaid-invoice-notes-title mb-1 p-0 h4">' . esc_html__('Notes', 'invoicing') . '</h2>'; |
|
904 | 904 | echo '<ul class="getpaid-invoice-notes text-break overflow-auto list-unstyled p-0 m-0">'; |
905 | 905 | |
906 | - foreach ( $notes as $note ) { |
|
907 | - wpinv_get_invoice_note_line_item( $note ); |
|
906 | + foreach ($notes as $note) { |
|
907 | + wpinv_get_invoice_note_line_item($note); |
|
908 | 908 | } |
909 | 909 | |
910 | 910 | echo '</ul>'; |
911 | 911 | echo '</div>'; |
912 | 912 | } |
913 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60 ); |
|
913 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60); |
|
914 | 914 | |
915 | 915 | /** |
916 | 916 | * Loads scripts on our invoice templates. |
@@ -918,32 +918,32 @@ discard block |
||
918 | 918 | function wpinv_display_style() { |
919 | 919 | |
920 | 920 | // Make sure that all scripts have been loaded. |
921 | - if ( ! did_action( 'wp_enqueue_scripts' ) ) { |
|
922 | - do_action( 'wp_enqueue_scripts' ); |
|
921 | + if (!did_action('wp_enqueue_scripts')) { |
|
922 | + do_action('wp_enqueue_scripts'); |
|
923 | 923 | } |
924 | 924 | |
925 | 925 | // Register the invoices style. |
926 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice.css' ) ); |
|
926 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice.css')); |
|
927 | 927 | |
928 | 928 | // Load required styles |
929 | - wp_print_styles( 'wpinv-single-style' ); |
|
930 | - wp_print_styles( 'ayecode-ui' ); |
|
929 | + wp_print_styles('wpinv-single-style'); |
|
930 | + wp_print_styles('ayecode-ui'); |
|
931 | 931 | |
932 | 932 | // Maybe load custom css. |
933 | - $custom_css = wpinv_get_option( 'template_custom_css' ); |
|
933 | + $custom_css = wpinv_get_option('template_custom_css'); |
|
934 | 934 | |
935 | - if ( isset( $custom_css ) && ! empty( $custom_css ) ) { |
|
936 | - $custom_css = wp_kses( $custom_css, array( '\'', '\"' ) ); |
|
937 | - $custom_css = str_replace( '>', '>', $custom_css ); |
|
935 | + if (isset($custom_css) && !empty($custom_css)) { |
|
936 | + $custom_css = wp_kses($custom_css, array('\'', '\"')); |
|
937 | + $custom_css = str_replace('>', '>', $custom_css); |
|
938 | 938 | echo '<style type="text/css">'; |
939 | - echo wp_kses_post( $custom_css ); |
|
939 | + echo wp_kses_post($custom_css); |
|
940 | 940 | echo '</style>'; |
941 | 941 | } |
942 | 942 | |
943 | 943 | wp_site_icon(); |
944 | 944 | } |
945 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
946 | -add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' ); |
|
945 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
946 | +add_action('wpinv_invalid_invoice_head', 'wpinv_display_style'); |
|
947 | 947 | |
948 | 948 | |
949 | 949 | /** |
@@ -955,41 +955,41 @@ discard block |
||
955 | 955 | // Retrieve the current invoice. |
956 | 956 | $invoice_id = getpaid_get_current_invoice_id(); |
957 | 957 | |
958 | - if ( empty( $invoice_id ) ) { |
|
958 | + if (empty($invoice_id)) { |
|
959 | 959 | |
960 | 960 | return aui()->alert( |
961 | 961 | array( |
962 | 962 | 'type' => 'warning', |
963 | - 'content' => __( 'Invalid invoice', 'invoicing' ), |
|
963 | + 'content' => __('Invalid invoice', 'invoicing'), |
|
964 | 964 | ) |
965 | 965 | ); |
966 | 966 | |
967 | 967 | } |
968 | 968 | |
969 | 969 | // Can the user view this invoice? |
970 | - if ( ! wpinv_user_can_view_invoice( $invoice_id ) ) { |
|
970 | + if (!wpinv_user_can_view_invoice($invoice_id)) { |
|
971 | 971 | |
972 | 972 | return aui()->alert( |
973 | 973 | array( |
974 | 974 | 'type' => 'warning', |
975 | - 'content' => __( 'You are not allowed to view this invoice', 'invoicing' ), |
|
975 | + 'content' => __('You are not allowed to view this invoice', 'invoicing'), |
|
976 | 976 | ) |
977 | 977 | ); |
978 | 978 | |
979 | 979 | } |
980 | 980 | |
981 | 981 | // Ensure that it is not yet paid for. |
982 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
982 | + $invoice = new WPInv_Invoice($invoice_id); |
|
983 | 983 | |
984 | 984 | // Maybe mark it as viewed. |
985 | - getpaid_maybe_mark_invoice_as_viewed( $invoice ); |
|
985 | + getpaid_maybe_mark_invoice_as_viewed($invoice); |
|
986 | 986 | |
987 | - if ( $invoice->is_paid() ) { |
|
987 | + if ($invoice->is_paid()) { |
|
988 | 988 | |
989 | 989 | return aui()->alert( |
990 | 990 | array( |
991 | 991 | 'type' => 'success', |
992 | - 'content' => __( 'This invoice has already been paid.', 'invoicing' ), |
|
992 | + 'content' => __('This invoice has already been paid.', 'invoicing'), |
|
993 | 993 | ) |
994 | 994 | ); |
995 | 995 | |
@@ -999,15 +999,15 @@ discard block |
||
999 | 999 | $wpi_checkout_id = $invoice_id; |
1000 | 1000 | |
1001 | 1001 | // Retrieve appropriate payment form. |
1002 | - $payment_form = new GetPaid_Payment_Form( $invoice->get_meta( 'force_payment_form' ) ); |
|
1003 | - $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1002 | + $payment_form = new GetPaid_Payment_Form($invoice->get_meta('force_payment_form')); |
|
1003 | + $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1004 | 1004 | |
1005 | - if ( ! $payment_form->exists() ) { |
|
1005 | + if (!$payment_form->exists()) { |
|
1006 | 1006 | |
1007 | 1007 | return aui()->alert( |
1008 | 1008 | array( |
1009 | 1009 | 'type' => 'warning', |
1010 | - 'content' => __( 'Error loading the payment form', 'invoicing' ), |
|
1010 | + 'content' => __('Error loading the payment form', 'invoicing'), |
|
1011 | 1011 | ) |
1012 | 1012 | ); |
1013 | 1013 | |
@@ -1016,29 +1016,29 @@ discard block |
||
1016 | 1016 | // Set the invoice. |
1017 | 1017 | $payment_form->invoice = $invoice; |
1018 | 1018 | |
1019 | - if ( ! $payment_form->is_default() ) { |
|
1019 | + if (!$payment_form->is_default()) { |
|
1020 | 1020 | |
1021 | 1021 | $items = array(); |
1022 | 1022 | $item_ids = array(); |
1023 | 1023 | |
1024 | - foreach ( $invoice->get_items() as $item ) { |
|
1025 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
1024 | + foreach ($invoice->get_items() as $item) { |
|
1025 | + if (!in_array($item->get_id(), $item_ids)) { |
|
1026 | 1026 | $item_ids[] = $item->get_id(); |
1027 | 1027 | $items[] = $item; |
1028 | 1028 | } |
1029 | 1029 | } |
1030 | 1030 | |
1031 | - foreach ( $payment_form->get_items() as $item ) { |
|
1032 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
1031 | + foreach ($payment_form->get_items() as $item) { |
|
1032 | + if (!in_array($item->get_id(), $item_ids)) { |
|
1033 | 1033 | $item_ids[] = $item->get_id(); |
1034 | 1034 | $items[] = $item; |
1035 | 1035 | } |
1036 | 1036 | } |
1037 | 1037 | |
1038 | - $payment_form->set_items( $items ); |
|
1038 | + $payment_form->set_items($items); |
|
1039 | 1039 | |
1040 | 1040 | } else { |
1041 | - $payment_form->set_items( $invoice->get_items() ); |
|
1041 | + $payment_form->set_items($invoice->get_items()); |
|
1042 | 1042 | } |
1043 | 1043 | |
1044 | 1044 | // Generate the html. |
@@ -1047,7 +1047,7 @@ discard block |
||
1047 | 1047 | } |
1048 | 1048 | |
1049 | 1049 | function wpinv_empty_cart_message() { |
1050 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1050 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
1051 | 1051 | } |
1052 | 1052 | |
1053 | 1053 | /** |
@@ -1065,76 +1065,76 @@ discard block |
||
1065 | 1065 | true |
1066 | 1066 | ); |
1067 | 1067 | } |
1068 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
1068 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
1069 | 1069 | |
1070 | 1070 | /** |
1071 | 1071 | * Filters the receipt page. |
1072 | 1072 | */ |
1073 | -function wpinv_filter_success_page_content( $content ) { |
|
1073 | +function wpinv_filter_success_page_content($content) { |
|
1074 | 1074 | |
1075 | 1075 | // Maybe abort early. |
1076 | - if ( is_admin() || ! is_singular() || ! in_the_loop() || ! is_main_query() || is_preview() ) { |
|
1076 | + if (is_admin() || !is_singular() || !in_the_loop() || !is_main_query() || is_preview()) { |
|
1077 | 1077 | return $content; |
1078 | 1078 | } |
1079 | 1079 | |
1080 | 1080 | // Ensure this is our page. |
1081 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
1081 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
1082 | 1082 | |
1083 | - $gateway = sanitize_text_field( $_GET['payment-confirm'] ); |
|
1084 | - return apply_filters( "wpinv_payment_confirm_$gateway", $content ); |
|
1083 | + $gateway = sanitize_text_field($_GET['payment-confirm']); |
|
1084 | + return apply_filters("wpinv_payment_confirm_$gateway", $content); |
|
1085 | 1085 | |
1086 | 1086 | } |
1087 | 1087 | |
1088 | 1088 | return $content; |
1089 | 1089 | } |
1090 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
1090 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
1091 | 1091 | |
1092 | -function wpinv_invoice_link( $invoice_id ) { |
|
1093 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1092 | +function wpinv_invoice_link($invoice_id) { |
|
1093 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1094 | 1094 | |
1095 | - if ( empty( $invoice ) ) { |
|
1095 | + if (empty($invoice)) { |
|
1096 | 1096 | return null; |
1097 | 1097 | } |
1098 | 1098 | |
1099 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
1099 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
1100 | 1100 | |
1101 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
1101 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
1102 | 1102 | } |
1103 | 1103 | |
1104 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
1105 | - if ( empty( $note ) ) { |
|
1104 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
1105 | + if (empty($note)) { |
|
1106 | 1106 | return null; |
1107 | 1107 | } |
1108 | 1108 | |
1109 | - if ( is_int( $note ) ) { |
|
1110 | - $note = get_comment( $note ); |
|
1109 | + if (is_int($note)) { |
|
1110 | + $note = get_comment($note); |
|
1111 | 1111 | } |
1112 | 1112 | |
1113 | - if ( ! ( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
1113 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
1114 | 1114 | return null; |
1115 | 1115 | } |
1116 | 1116 | |
1117 | - $note_classes = array( 'note' ); |
|
1118 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
1117 | + $note_classes = array('note'); |
|
1118 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
1119 | 1119 | $note_classes[] = $note->comment_author === 'System' ? 'system-note' : ''; |
1120 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
1121 | - $note_classes = ! empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
1120 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
1121 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
1122 | 1122 | |
1123 | 1123 | ob_start(); |
1124 | 1124 | ?> |
1125 | - <li rel="<?php echo absint( $note->comment_ID ); ?>" class="<?php echo esc_attr( $note_classes ); ?> mb-2"> |
|
1125 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?> mb-2"> |
|
1126 | 1126 | <div class="note_content"> |
1127 | 1127 | |
1128 | - <?php echo wp_kses_post( wptexturize( $note->comment_content ) ); ?> |
|
1128 | + <?php echo wp_kses_post(wptexturize($note->comment_content)); ?> |
|
1129 | 1129 | |
1130 | - <?php if ( ! is_admin() ) : ?> |
|
1130 | + <?php if (!is_admin()) : ?> |
|
1131 | 1131 | <em class="small form-text text-muted mt-0"> |
1132 | 1132 | <?php |
1133 | 1133 | printf( |
1134 | - esc_html__( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
1135 | - esc_html( $note->comment_author ), |
|
1136 | - esc_html( getpaid_format_date_value( $note->comment_date ) ), |
|
1137 | - esc_html( date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ) |
|
1134 | + esc_html__('%1$s - %2$s at %3$s', 'invoicing'), |
|
1135 | + esc_html($note->comment_author), |
|
1136 | + esc_html(getpaid_format_date_value($note->comment_date)), |
|
1137 | + esc_html(date_i18n(get_option('time_format'), strtotime($note->comment_date))) |
|
1138 | 1138 | ); |
1139 | 1139 | ?> |
1140 | 1140 | </em> |
@@ -1142,21 +1142,21 @@ discard block |
||
1142 | 1142 | |
1143 | 1143 | </div> |
1144 | 1144 | |
1145 | - <?php if ( is_admin() ) : ?> |
|
1145 | + <?php if (is_admin()) : ?> |
|
1146 | 1146 | |
1147 | 1147 | <p class="meta px-4 py-2"> |
1148 | - <abbr class="exact-date" title="<?php echo esc_attr( $note->comment_date ); ?>"> |
|
1148 | + <abbr class="exact-date" title="<?php echo esc_attr($note->comment_date); ?>"> |
|
1149 | 1149 | <?php |
1150 | 1150 | printf( |
1151 | - esc_html__( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
1152 | - esc_html( $note->comment_author ), |
|
1153 | - esc_html( getpaid_format_date_value( $note->comment_date ) ), |
|
1154 | - esc_html( date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ) |
|
1151 | + esc_html__('%1$s - %2$s at %3$s', 'invoicing'), |
|
1152 | + esc_html($note->comment_author), |
|
1153 | + esc_html(getpaid_format_date_value($note->comment_date)), |
|
1154 | + esc_html(date_i18n(get_option('time_format'), strtotime($note->comment_date))) |
|
1155 | 1155 | ); |
1156 | 1156 | ?> |
1157 | 1157 | </abbr> |
1158 | - <?php if ( $note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing() ) { ?> |
|
1159 | - <a href="#" class="delete_note" data-id="<?php echo esc_attr( $note->comment_ID ); ?>"><?php esc_html_e( 'Delete note', 'invoicing' ); ?></a> |
|
1158 | + <?php if ($note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing()) { ?> |
|
1159 | + <a href="#" class="delete_note" data-id="<?php echo esc_attr($note->comment_ID); ?>"><?php esc_html_e('Delete note', 'invoicing'); ?></a> |
|
1160 | 1160 | <?php } ?> |
1161 | 1161 | </p> |
1162 | 1162 | |
@@ -1165,10 +1165,10 @@ discard block |
||
1165 | 1165 | </li> |
1166 | 1166 | <?php |
1167 | 1167 | $note_content = ob_get_clean(); |
1168 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
1168 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
1169 | 1169 | |
1170 | - if ( $echo ) { |
|
1171 | - echo wp_kses_post( $note_content ); |
|
1170 | + if ($echo) { |
|
1171 | + echo wp_kses_post($note_content); |
|
1172 | 1172 | } else { |
1173 | 1173 | return $note_content; |
1174 | 1174 | } |
@@ -1181,43 +1181,43 @@ discard block |
||
1181 | 1181 | * @return string |
1182 | 1182 | */ |
1183 | 1183 | function wpinv_get_policy_text() { |
1184 | - $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 ); |
|
1184 | + $privacy_page_id = get_option('wp_page_for_privacy_policy', 0); |
|
1185 | 1185 | |
1186 | - $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]' ) ); |
|
1186 | + $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]')); |
|
1187 | 1187 | |
1188 | - if ( ! $privacy_page_id ) { |
|
1189 | - $privacy_page_id = wpinv_get_option( 'privacy_page', 0 ); |
|
1188 | + if (!$privacy_page_id) { |
|
1189 | + $privacy_page_id = wpinv_get_option('privacy_page', 0); |
|
1190 | 1190 | } |
1191 | 1191 | |
1192 | - $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' ); |
|
1192 | + $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'); |
|
1193 | 1193 | |
1194 | 1194 | $find_replace = array( |
1195 | 1195 | '[wpinv_privacy_policy]' => $privacy_link, |
1196 | 1196 | ); |
1197 | 1197 | |
1198 | - $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text ); |
|
1198 | + $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text); |
|
1199 | 1199 | |
1200 | - return wp_kses_post( wpautop( $privacy_text ) ); |
|
1200 | + return wp_kses_post(wpautop($privacy_text)); |
|
1201 | 1201 | } |
1202 | 1202 | |
1203 | 1203 | function wpinv_oxygen_fix_conflict() { |
1204 | 1204 | global $ct_ignore_post_types; |
1205 | 1205 | |
1206 | - if ( ! is_array( $ct_ignore_post_types ) ) { |
|
1206 | + if (!is_array($ct_ignore_post_types)) { |
|
1207 | 1207 | $ct_ignore_post_types = array(); |
1208 | 1208 | } |
1209 | 1209 | |
1210 | - $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item', 'wpi_payment_form' ); |
|
1210 | + $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item', 'wpi_payment_form'); |
|
1211 | 1211 | |
1212 | - foreach ( $post_types as $post_type ) { |
|
1212 | + foreach ($post_types as $post_type) { |
|
1213 | 1213 | $ct_ignore_post_types[] = $post_type; |
1214 | 1214 | |
1215 | 1215 | // Ignore post type |
1216 | - add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 ); |
|
1216 | + add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999); |
|
1217 | 1217 | } |
1218 | 1218 | |
1219 | - remove_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
1220 | - add_filter( 'template_include', 'wpinv_template', 999, 1 ); |
|
1219 | + remove_filter('template_include', 'wpinv_template', 10, 1); |
|
1220 | + add_filter('template_include', 'wpinv_template', 999, 1); |
|
1221 | 1221 | } |
1222 | 1222 | |
1223 | 1223 | /** |
@@ -1225,10 +1225,10 @@ discard block |
||
1225 | 1225 | * |
1226 | 1226 | * @param GetPaid_Payment_Form $form |
1227 | 1227 | */ |
1228 | -function getpaid_display_payment_form( $form ) { |
|
1228 | +function getpaid_display_payment_form($form) { |
|
1229 | 1229 | |
1230 | - if ( is_numeric( $form ) ) { |
|
1231 | - $form = new GetPaid_Payment_Form( $form ); |
|
1230 | + if (is_numeric($form)) { |
|
1231 | + $form = new GetPaid_Payment_Form($form); |
|
1232 | 1232 | } |
1233 | 1233 | |
1234 | 1234 | $form->display(); |
@@ -1238,61 +1238,61 @@ discard block |
||
1238 | 1238 | /** |
1239 | 1239 | * Helper function to display a item payment form on the frontend. |
1240 | 1240 | */ |
1241 | -function getpaid_display_item_payment_form( $items ) { |
|
1241 | +function getpaid_display_item_payment_form($items) { |
|
1242 | 1242 | |
1243 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1244 | - $form->set_items( $items ); |
|
1243 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1244 | + $form->set_items($items); |
|
1245 | 1245 | |
1246 | - if ( 0 == count( $form->get_items() ) ) { |
|
1246 | + if (0 == count($form->get_items())) { |
|
1247 | 1247 | aui()->alert( |
1248 | 1248 | array( |
1249 | 1249 | 'type' => 'warning', |
1250 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
1250 | + 'content' => __('No published items found', 'invoicing'), |
|
1251 | 1251 | ), |
1252 | 1252 | true |
1253 | 1253 | ); |
1254 | 1254 | return; |
1255 | 1255 | } |
1256 | 1256 | |
1257 | - $extra_items = esc_attr( getpaid_convert_items_to_string( $items ) ); |
|
1258 | - $extra_items_key = md5( NONCE_KEY . AUTH_KEY . $extra_items ); |
|
1257 | + $extra_items = esc_attr(getpaid_convert_items_to_string($items)); |
|
1258 | + $extra_items_key = md5(NONCE_KEY . AUTH_KEY . $extra_items); |
|
1259 | 1259 | $extra_items = "<input type='hidden' name='getpaid-form-items' value='$extra_items' />"; |
1260 | 1260 | $extra_items .= "<input type='hidden' name='getpaid-form-items-key' value='$extra_items_key' />"; |
1261 | 1261 | |
1262 | - $form->display( $extra_items ); |
|
1262 | + $form->display($extra_items); |
|
1263 | 1263 | } |
1264 | 1264 | |
1265 | 1265 | /** |
1266 | 1266 | * Helper function to display an invoice payment form on the frontend. |
1267 | 1267 | */ |
1268 | -function getpaid_display_invoice_payment_form( $invoice_id ) { |
|
1268 | +function getpaid_display_invoice_payment_form($invoice_id) { |
|
1269 | 1269 | |
1270 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1270 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1271 | 1271 | |
1272 | - if ( empty( $invoice ) ) { |
|
1272 | + if (empty($invoice)) { |
|
1273 | 1273 | aui()->alert( |
1274 | 1274 | array( |
1275 | 1275 | 'type' => 'warning', |
1276 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1276 | + 'content' => __('Invoice not found', 'invoicing'), |
|
1277 | 1277 | ), |
1278 | 1278 | true |
1279 | 1279 | ); |
1280 | 1280 | return; |
1281 | 1281 | } |
1282 | 1282 | |
1283 | - if ( $invoice->is_paid() ) { |
|
1283 | + if ($invoice->is_paid()) { |
|
1284 | 1284 | aui()->alert( |
1285 | 1285 | array( |
1286 | 1286 | 'type' => 'warning', |
1287 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1287 | + 'content' => __('Invoice has already been paid', 'invoicing'), |
|
1288 | 1288 | ), |
1289 | 1289 | true |
1290 | 1290 | ); |
1291 | 1291 | return; |
1292 | 1292 | } |
1293 | 1293 | |
1294 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1295 | - $form->set_items( $invoice->get_items() ); |
|
1294 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1295 | + $form->set_items($invoice->get_items()); |
|
1296 | 1296 | |
1297 | 1297 | $form->display(); |
1298 | 1298 | } |
@@ -1300,25 +1300,25 @@ discard block |
||
1300 | 1300 | /** |
1301 | 1301 | * Helper function to convert item string to array. |
1302 | 1302 | */ |
1303 | -function getpaid_convert_items_to_array( $items ) { |
|
1304 | - $items = array_filter( array_map( 'trim', explode( ',', $items ) ) ); |
|
1303 | +function getpaid_convert_items_to_array($items) { |
|
1304 | + $items = array_filter(array_map('trim', explode(',', $items))); |
|
1305 | 1305 | $prepared = array(); |
1306 | 1306 | |
1307 | - foreach ( $items as $item ) { |
|
1308 | - $data = array_map( 'trim', explode( '|', $item ) ); |
|
1307 | + foreach ($items as $item) { |
|
1308 | + $data = array_map('trim', explode('|', $item)); |
|
1309 | 1309 | |
1310 | - if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) { |
|
1310 | + if (empty($data[0]) || !is_numeric($data[0])) { |
|
1311 | 1311 | continue; |
1312 | 1312 | } |
1313 | 1313 | |
1314 | 1314 | $quantity = 1; |
1315 | - if ( isset( $data[1] ) && is_numeric( $data[1] ) ) { |
|
1315 | + if (isset($data[1]) && is_numeric($data[1])) { |
|
1316 | 1316 | $quantity = (float) $data[1]; |
1317 | 1317 | } |
1318 | 1318 | |
1319 | 1319 | // WPML support. |
1320 | - $item_id = apply_filters( 'wpml_object_id', $data[0], 'wpi_item', true ); |
|
1321 | - $prepared[ $item_id ] = $quantity; |
|
1320 | + $item_id = apply_filters('wpml_object_id', $data[0], 'wpi_item', true); |
|
1321 | + $prepared[$item_id] = $quantity; |
|
1322 | 1322 | |
1323 | 1323 | } |
1324 | 1324 | |
@@ -1328,13 +1328,13 @@ discard block |
||
1328 | 1328 | /** |
1329 | 1329 | * Helper function to convert item array to string. |
1330 | 1330 | */ |
1331 | -function getpaid_convert_items_to_string( $items ) { |
|
1331 | +function getpaid_convert_items_to_string($items) { |
|
1332 | 1332 | $prepared = array(); |
1333 | 1333 | |
1334 | - foreach ( $items as $item => $quantity ) { |
|
1334 | + foreach ($items as $item => $quantity) { |
|
1335 | 1335 | $prepared[] = "$item|$quantity"; |
1336 | 1336 | } |
1337 | - return implode( ',', $prepared ); |
|
1337 | + return implode(',', $prepared); |
|
1338 | 1338 | } |
1339 | 1339 | |
1340 | 1340 | /** |
@@ -1342,21 +1342,21 @@ discard block |
||
1342 | 1342 | * |
1343 | 1343 | * Provide a label and one of $form, $items or $invoice. |
1344 | 1344 | */ |
1345 | -function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) { |
|
1346 | - $label = sanitize_text_field( $label ); |
|
1345 | +function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) { |
|
1346 | + $label = sanitize_text_field($label); |
|
1347 | 1347 | |
1348 | - if ( ! empty( $form ) ) { |
|
1349 | - $form = esc_attr( $form ); |
|
1348 | + if (!empty($form)) { |
|
1349 | + $form = esc_attr($form); |
|
1350 | 1350 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>"; |
1351 | 1351 | } |
1352 | 1352 | |
1353 | - if ( ! empty( $items ) ) { |
|
1354 | - $items = esc_attr( $items ); |
|
1353 | + if (!empty($items)) { |
|
1354 | + $items = esc_attr($items); |
|
1355 | 1355 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>"; |
1356 | 1356 | } |
1357 | 1357 | |
1358 | - if ( ! empty( $invoice ) ) { |
|
1359 | - $invoice = esc_attr( $invoice ); |
|
1358 | + if (!empty($invoice)) { |
|
1359 | + $invoice = esc_attr($invoice); |
|
1360 | 1360 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-invoice='$invoice'>$label</button>"; |
1361 | 1361 | } |
1362 | 1362 | |
@@ -1367,17 +1367,17 @@ discard block |
||
1367 | 1367 | * |
1368 | 1368 | * @param WPInv_Invoice $invoice |
1369 | 1369 | */ |
1370 | -function getpaid_the_invoice_description( $invoice ) { |
|
1370 | +function getpaid_the_invoice_description($invoice) { |
|
1371 | 1371 | $description = $invoice->get_description(); |
1372 | 1372 | |
1373 | - if ( empty( $description ) ) { |
|
1373 | + if (empty($description)) { |
|
1374 | 1374 | return; |
1375 | 1375 | } |
1376 | 1376 | |
1377 | - 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>"; |
|
1377 | + 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>"; |
|
1378 | 1378 | } |
1379 | -add_action( 'getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100 ); |
|
1380 | -add_action( 'wpinv_email_billing_details', 'getpaid_the_invoice_description', 100 ); |
|
1379 | +add_action('getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100); |
|
1380 | +add_action('wpinv_email_billing_details', 'getpaid_the_invoice_description', 100); |
|
1381 | 1381 | |
1382 | 1382 | /** |
1383 | 1383 | * Render element on a form. |
@@ -1385,79 +1385,79 @@ discard block |
||
1385 | 1385 | * @param array $element |
1386 | 1386 | * @param GetPaid_Payment_Form $form |
1387 | 1387 | */ |
1388 | -function getpaid_payment_form_element( $element, $form ) { |
|
1388 | +function getpaid_payment_form_element($element, $form) { |
|
1389 | 1389 | |
1390 | 1390 | // Set up the args. |
1391 | - $element_type = trim( $element['type'] ); |
|
1391 | + $element_type = trim($element['type']); |
|
1392 | 1392 | $element['form'] = $form; |
1393 | - extract( $element ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract |
|
1393 | + extract($element); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract |
|
1394 | 1394 | |
1395 | 1395 | // Try to locate the appropriate template. |
1396 | - $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" ); |
|
1396 | + $located = wpinv_locate_template("payment-forms/elements/$element_type.php"); |
|
1397 | 1397 | |
1398 | 1398 | // Abort if this is not our element. |
1399 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1399 | + if (empty($located) || !file_exists($located)) { |
|
1400 | 1400 | return; |
1401 | 1401 | } |
1402 | 1402 | |
1403 | 1403 | // Generate the class and id of the element. |
1404 | - $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) ); |
|
1405 | - $id = isset( $id ) ? $id : uniqid( 'gp' ); |
|
1404 | + $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type)); |
|
1405 | + $id = isset($id) ? $id : uniqid('gp'); |
|
1406 | 1406 | |
1407 | - $element_id = ! empty( $element['label'] ) ? sanitize_title( $element['label'] ) : $id; |
|
1408 | - $query_value = isset( $_GET[ $element_id ] ) ? wpinv_clean( urldecode_deep( $_GET[ $element_id ] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
1407 | + $element_id = !empty($element['label']) ? sanitize_title($element['label']) : $id; |
|
1408 | + $query_value = isset($_GET[$element_id]) ? wpinv_clean(urldecode_deep($_GET[$element_id])) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
1409 | 1409 | |
1410 | 1410 | $element_id = 'getpaid-' . $element_id; |
1411 | - if ( ! empty( $GLOBALS['rendered_getpaid_forms'][ $form->get_id() ] ) ) { |
|
1412 | - $element_id = $element_id . '-' . $GLOBALS['rendered_getpaid_forms'][ $form->get_id() ]; |
|
1411 | + if (!empty($GLOBALS['rendered_getpaid_forms'][$form->get_id()])) { |
|
1412 | + $element_id = $element_id . '-' . $GLOBALS['rendered_getpaid_forms'][$form->get_id()]; |
|
1413 | 1413 | } |
1414 | 1414 | |
1415 | 1415 | // Echo the opening wrapper. |
1416 | - echo "<div class='getpaid-payment-form-element " . esc_attr( $wrapper_class ) . "'>"; |
|
1416 | + echo "<div class='getpaid-payment-form-element " . esc_attr($wrapper_class) . "'>"; |
|
1417 | 1417 | |
1418 | 1418 | // Fires before displaying a given element type's content. |
1419 | - do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form ); |
|
1419 | + do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form); |
|
1420 | 1420 | |
1421 | 1421 | // Include the template for the element. |
1422 | 1422 | include $located; |
1423 | 1423 | |
1424 | 1424 | // Fires after displaying a given element type's content. |
1425 | - do_action( "getpaid_payment_form_{$element_type}_element", $element, $form ); |
|
1425 | + do_action("getpaid_payment_form_{$element_type}_element", $element, $form); |
|
1426 | 1426 | |
1427 | 1427 | // Echo the closing wrapper. |
1428 | 1428 | echo '</div>'; |
1429 | 1429 | } |
1430 | -add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 ); |
|
1430 | +add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2); |
|
1431 | 1431 | |
1432 | 1432 | /** |
1433 | 1433 | * Render an element's edit page. |
1434 | 1434 | * |
1435 | 1435 | * @param WP_Post $post |
1436 | 1436 | */ |
1437 | -function getpaid_payment_form_edit_element_template( $post ) { |
|
1437 | +function getpaid_payment_form_edit_element_template($post) { |
|
1438 | 1438 | |
1439 | 1439 | // Retrieve all elements. |
1440 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
1440 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
1441 | 1441 | |
1442 | - foreach ( $all_elements as $element ) { |
|
1442 | + foreach ($all_elements as $element) { |
|
1443 | 1443 | |
1444 | 1444 | // Try to locate the appropriate template. |
1445 | - $element = esc_attr( sanitize_key( $element ) ); |
|
1446 | - $located = wpinv_locate_template( "payment-forms-admin/edit/$element.php" ); |
|
1445 | + $element = esc_attr(sanitize_key($element)); |
|
1446 | + $located = wpinv_locate_template("payment-forms-admin/edit/$element.php"); |
|
1447 | 1447 | |
1448 | 1448 | // Continue if this is not our element. |
1449 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1449 | + if (empty($located) || !file_exists($located)) { |
|
1450 | 1450 | continue; |
1451 | 1451 | } |
1452 | 1452 | |
1453 | 1453 | // Include the template for the element. |
1454 | - echo "<div v-if=\"active_form_element.type=='" . esc_attr( $element ) . "'\">"; |
|
1454 | + echo "<div v-if=\"active_form_element.type=='" . esc_attr($element) . "'\">"; |
|
1455 | 1455 | include $located; |
1456 | 1456 | echo '</div>'; |
1457 | 1457 | } |
1458 | 1458 | |
1459 | 1459 | } |
1460 | -add_action( 'getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template' ); |
|
1460 | +add_action('getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template'); |
|
1461 | 1461 | |
1462 | 1462 | /** |
1463 | 1463 | * Render an element's preview. |
@@ -1466,27 +1466,27 @@ discard block |
||
1466 | 1466 | function getpaid_payment_form_render_element_preview_template() { |
1467 | 1467 | |
1468 | 1468 | // Retrieve all elements. |
1469 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
1469 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
1470 | 1470 | |
1471 | - foreach ( $all_elements as $element ) { |
|
1471 | + foreach ($all_elements as $element) { |
|
1472 | 1472 | |
1473 | 1473 | // Try to locate the appropriate template. |
1474 | - $element = sanitize_key( $element ); |
|
1475 | - $located = wpinv_locate_template( "payment-forms-admin/previews/$element.php" ); |
|
1474 | + $element = sanitize_key($element); |
|
1475 | + $located = wpinv_locate_template("payment-forms-admin/previews/$element.php"); |
|
1476 | 1476 | |
1477 | 1477 | // Continue if this is not our element. |
1478 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1478 | + if (empty($located) || !file_exists($located)) { |
|
1479 | 1479 | continue; |
1480 | 1480 | } |
1481 | 1481 | |
1482 | 1482 | // Include the template for the element. |
1483 | - echo "<div v-if=\"form_element.type=='" . esc_html( $element ) . "'\">"; |
|
1483 | + echo "<div v-if=\"form_element.type=='" . esc_html($element) . "'\">"; |
|
1484 | 1484 | include $located; |
1485 | 1485 | echo '</div>'; |
1486 | 1486 | } |
1487 | 1487 | |
1488 | 1488 | } |
1489 | -add_action( 'wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template' ); |
|
1489 | +add_action('wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template'); |
|
1490 | 1490 | |
1491 | 1491 | /** |
1492 | 1492 | * Shows a list of gateways that support recurring payments. |
@@ -1494,17 +1494,17 @@ discard block |
||
1494 | 1494 | function wpinv_get_recurring_gateways_text() { |
1495 | 1495 | $gateways = array(); |
1496 | 1496 | |
1497 | - foreach ( wpinv_get_payment_gateways() as $key => $gateway ) { |
|
1498 | - if ( wpinv_gateway_support_subscription( $key ) ) { |
|
1499 | - $gateways[] = sanitize_text_field( $gateway['admin_label'] ); |
|
1497 | + foreach (wpinv_get_payment_gateways() as $key => $gateway) { |
|
1498 | + if (wpinv_gateway_support_subscription($key)) { |
|
1499 | + $gateways[] = sanitize_text_field($gateway['admin_label']); |
|
1500 | 1500 | } |
1501 | 1501 | } |
1502 | 1502 | |
1503 | - if ( empty( $gateways ) ) { |
|
1504 | - return "<span class='form-text text-danger'>" . __( 'No active gateways support subscription payments.', 'invoicing' ) . '</span>'; |
|
1503 | + if (empty($gateways)) { |
|
1504 | + return "<span class='form-text text-danger'>" . __('No active gateways support subscription payments.', 'invoicing') . '</span>'; |
|
1505 | 1505 | } |
1506 | 1506 | |
1507 | - return "<span class='form-text text-muted'>" . wp_sprintf( __( 'Subscription payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ) . '</span>'; |
|
1507 | + return "<span class='form-text text-muted'>" . wp_sprintf(__('Subscription payments only supported by: %s', 'invoicing'), implode(', ', $gateways)) . '</span>'; |
|
1508 | 1508 | |
1509 | 1509 | } |
1510 | 1510 | |
@@ -1514,7 +1514,7 @@ discard block |
||
1514 | 1514 | * @return GetPaid_Template |
1515 | 1515 | */ |
1516 | 1516 | function getpaid_template() { |
1517 | - return getpaid()->get( 'template' ); |
|
1517 | + return getpaid()->get('template'); |
|
1518 | 1518 | } |
1519 | 1519 | |
1520 | 1520 | /** |
@@ -1523,8 +1523,8 @@ discard block |
||
1523 | 1523 | * @param array args |
1524 | 1524 | * @return string |
1525 | 1525 | */ |
1526 | -function getpaid_paginate_links( $args ) { |
|
1527 | - return str_replace( 'page-link dots', 'page-link text-dark', aui()->pagination( $args ) ); |
|
1526 | +function getpaid_paginate_links($args) { |
|
1527 | + return str_replace('page-link dots', 'page-link text-dark', aui()->pagination($args)); |
|
1528 | 1528 | } |
1529 | 1529 | |
1530 | 1530 | /** |
@@ -1534,22 +1534,22 @@ discard block |
||
1534 | 1534 | * @param string state |
1535 | 1535 | * @return string |
1536 | 1536 | */ |
1537 | -function getpaid_get_states_select_markup( $country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state', $echo = false ) { |
|
1537 | +function getpaid_get_states_select_markup($country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state', $echo = false) { |
|
1538 | 1538 | |
1539 | - $states = wpinv_get_country_states( $country ); |
|
1540 | - $uniqid = uniqid( '_' ); |
|
1539 | + $states = wpinv_get_country_states($country); |
|
1540 | + $uniqid = uniqid('_'); |
|
1541 | 1541 | |
1542 | - if ( ! empty( $states ) ) { |
|
1542 | + if (!empty($states)) { |
|
1543 | 1543 | |
1544 | 1544 | return aui()->select( |
1545 | 1545 | array( |
1546 | 1546 | 'options' => $states, |
1547 | - 'name' => esc_attr( $field_name ), |
|
1548 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
1549 | - 'value' => sanitize_text_field( $state ), |
|
1547 | + 'name' => esc_attr($field_name), |
|
1548 | + 'id' => sanitize_html_class($field_name) . $uniqid, |
|
1549 | + 'value' => sanitize_text_field($state), |
|
1550 | 1550 | 'placeholder' => $placeholder, |
1551 | 1551 | 'required' => $required, |
1552 | - 'label' => wp_kses_post( $label ), |
|
1552 | + 'label' => wp_kses_post($label), |
|
1553 | 1553 | 'label_type' => 'vertical', |
1554 | 1554 | 'help_text' => $help_text, |
1555 | 1555 | 'class' => 'getpaid-address-field wpinv_state', |
@@ -1566,14 +1566,14 @@ discard block |
||
1566 | 1566 | |
1567 | 1567 | return aui()->input( |
1568 | 1568 | array( |
1569 | - 'name' => esc_attr( $field_name ), |
|
1570 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
1569 | + 'name' => esc_attr($field_name), |
|
1570 | + 'id' => sanitize_html_class($field_name) . $uniqid, |
|
1571 | 1571 | 'placeholder' => $placeholder, |
1572 | 1572 | 'required' => $required, |
1573 | - 'label' => wp_kses_post( $label ), |
|
1573 | + 'label' => wp_kses_post($label), |
|
1574 | 1574 | 'label_type' => 'vertical', |
1575 | 1575 | 'help_text' => $help_text, |
1576 | - 'value' => sanitize_text_field( $state ), |
|
1576 | + 'value' => sanitize_text_field($state), |
|
1577 | 1577 | 'class' => 'getpaid-address-field wpinv_state', |
1578 | 1578 | 'wrap_class' => "$wrapper_class getpaid-address-field-wrapper__state", |
1579 | 1579 | 'label_class' => 'getpaid-address-field-label getpaid-address-field-label__state', |
@@ -1592,16 +1592,16 @@ discard block |
||
1592 | 1592 | * @param array $element |
1593 | 1593 | * @return string |
1594 | 1594 | */ |
1595 | -function getpaid_get_form_element_grid_class( $element ) { |
|
1595 | +function getpaid_get_form_element_grid_class($element) { |
|
1596 | 1596 | |
1597 | 1597 | $class = 'col-12'; |
1598 | - $width = empty( $element['grid_width'] ) ? 'full' : $element['grid_width']; |
|
1598 | + $width = empty($element['grid_width']) ? 'full' : $element['grid_width']; |
|
1599 | 1599 | |
1600 | - if ( $width == 'half' ) { |
|
1600 | + if ($width == 'half') { |
|
1601 | 1601 | $class .= ' col-md-6'; |
1602 | 1602 | } |
1603 | 1603 | |
1604 | - if ( $width == 'third' ) { |
|
1604 | + if ($width == 'third') { |
|
1605 | 1605 | $class .= ' col-md-4'; |
1606 | 1606 | } |
1607 | 1607 | |
@@ -1616,15 +1616,15 @@ discard block |
||
1616 | 1616 | * |
1617 | 1617 | * @return string |
1618 | 1618 | */ |
1619 | -function getpaid_embed_url( $payment_form = false, $items = false ) { |
|
1619 | +function getpaid_embed_url($payment_form = false, $items = false) { |
|
1620 | 1620 | |
1621 | 1621 | return add_query_arg( |
1622 | 1622 | array( |
1623 | 1623 | 'getpaid_embed' => 1, |
1624 | - 'form' => $payment_form ? absint( $payment_form ) : false, |
|
1625 | - 'item' => $items ? urlencode( $items ) : false, |
|
1624 | + 'form' => $payment_form ? absint($payment_form) : false, |
|
1625 | + 'item' => $items ? urlencode($items) : false, |
|
1626 | 1626 | ), |
1627 | - home_url( 'index.php' ) |
|
1627 | + home_url('index.php') |
|
1628 | 1628 | ); |
1629 | 1629 | |
1630 | 1630 | } |
@@ -1634,13 +1634,13 @@ discard block |
||
1634 | 1634 | * |
1635 | 1635 | * @return string |
1636 | 1636 | */ |
1637 | -function getpaid_filter_embed_template( $template ) { |
|
1637 | +function getpaid_filter_embed_template($template) { |
|
1638 | 1638 | |
1639 | - if ( isset( $_GET['getpaid_embed'] ) ) { |
|
1640 | - wpinv_get_template( 'payment-forms/embed.php' ); |
|
1639 | + if (isset($_GET['getpaid_embed'])) { |
|
1640 | + wpinv_get_template('payment-forms/embed.php'); |
|
1641 | 1641 | exit; |
1642 | 1642 | } |
1643 | 1643 | |
1644 | 1644 | return $template; |
1645 | 1645 | } |
1646 | -add_filter( 'template_include', 'getpaid_filter_embed_template' ); |
|
1646 | +add_filter('template_include', 'getpaid_filter_embed_template'); |
@@ -13,741 +13,741 @@ discard block |
||
13 | 13 | class GetPaid_Post_Types_Admin { |
14 | 14 | |
15 | 15 | /** |
16 | - * Hook in methods. |
|
17 | - */ |
|
18 | - public static function init() { |
|
19 | - |
|
20 | - // Init metaboxes. |
|
21 | - GetPaid_Metaboxes::init(); |
|
22 | - |
|
23 | - // Filter the post updated messages. |
|
24 | - add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
25 | - |
|
26 | - // Filter post actions. |
|
27 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
28 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 ); |
|
29 | - |
|
30 | - // Invoice table columns. |
|
31 | - add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
32 | - add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
33 | - add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) ); |
|
34 | - add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 ); |
|
35 | - |
|
36 | - // Items table columns. |
|
37 | - add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
38 | - add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
39 | - add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
40 | - add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
41 | - add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
42 | - add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
43 | - |
|
44 | - // Payment forms columns. |
|
45 | - add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
46 | - add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
47 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
48 | - |
|
49 | - // Discount table columns. |
|
50 | - add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
51 | - add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
52 | - |
|
53 | - // Deleting posts. |
|
54 | - add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
55 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
56 | - |
|
57 | - add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 ); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Post updated messages. |
|
62 | - */ |
|
63 | - public static function post_updated_messages( $messages ) { |
|
64 | - global $post; |
|
65 | - |
|
66 | - $messages['wpi_discount'] = array( |
|
67 | - 0 => '', |
|
68 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
69 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
70 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
71 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
72 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
73 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
74 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
75 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
76 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
77 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
78 | - ); |
|
79 | - |
|
80 | - $messages['wpi_payment_form'] = array( |
|
81 | - 0 => '', |
|
82 | - 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
83 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
84 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
85 | - 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
86 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
87 | - 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
88 | - 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
89 | - 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
90 | - 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
91 | - 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
92 | - ); |
|
93 | - |
|
94 | - return $messages; |
|
95 | - |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Post row actions. |
|
100 | - */ |
|
101 | - public static function post_row_actions( $actions, $post ) { |
|
102 | - |
|
103 | - $post = get_post( $post ); |
|
104 | - |
|
105 | - // We do not want to edit the default payment form. |
|
106 | - if ( 'wpi_payment_form' == $post->post_type ) { |
|
107 | - |
|
108 | - if ( wpinv_get_default_payment_form() === $post->ID ) { |
|
109 | - unset( $actions['trash'] ); |
|
110 | - unset( $actions['inline hide-if-no-js'] ); |
|
111 | - } |
|
112 | - |
|
113 | - $actions['duplicate'] = sprintf( |
|
114 | - '<a href="%1$s">%2$s</a>', |
|
115 | - esc_url( |
|
116 | - wp_nonce_url( |
|
117 | - add_query_arg( |
|
118 | - array( |
|
119 | - 'getpaid-admin-action' => 'duplicate_form', |
|
120 | - 'form_id' => $post->ID, |
|
121 | - ) |
|
122 | - ), |
|
123 | - 'getpaid-nonce', |
|
124 | - 'getpaid-nonce' |
|
125 | - ) |
|
126 | - ), |
|
127 | - esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
128 | - ); |
|
129 | - |
|
130 | - $actions['reset'] = sprintf( |
|
131 | - '<a href="%1$s" style="color: #800">%2$s</a>', |
|
132 | - esc_url( |
|
133 | - wp_nonce_url( |
|
134 | - add_query_arg( |
|
135 | - array( |
|
136 | - 'getpaid-admin-action' => 'reset_form_stats', |
|
137 | - 'form_id' => $post->ID, |
|
138 | - ) |
|
139 | - ), |
|
140 | - 'getpaid-nonce', |
|
141 | - 'getpaid-nonce' |
|
142 | - ) |
|
143 | - ), |
|
144 | - esc_html( __( 'Reset Stats', 'invoicing' ) ) |
|
145 | - ); |
|
146 | - } |
|
147 | - |
|
148 | - // Link to item payment form. |
|
149 | - if ( 'wpi_item' == $post->post_type ) { |
|
150 | - |
|
151 | - if ( in_array( get_post_meta( $post->ID, '_wpinv_type', true ), array( '', 'fee', 'custom' ), true ) ) { |
|
152 | - |
|
153 | - $actions['buy'] = sprintf( |
|
154 | - '<a href="%1$s">%2$s</a>', |
|
155 | - esc_url( getpaid_embed_url( false, $post->ID . '|0' ) ), |
|
156 | - esc_html( __( 'Buy', 'invoicing' ) ) |
|
157 | - ); |
|
158 | - |
|
159 | - } |
|
16 | + * Hook in methods. |
|
17 | + */ |
|
18 | + public static function init() { |
|
19 | + |
|
20 | + // Init metaboxes. |
|
21 | + GetPaid_Metaboxes::init(); |
|
22 | + |
|
23 | + // Filter the post updated messages. |
|
24 | + add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
25 | + |
|
26 | + // Filter post actions. |
|
27 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
28 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 ); |
|
29 | + |
|
30 | + // Invoice table columns. |
|
31 | + add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
32 | + add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
33 | + add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) ); |
|
34 | + add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 ); |
|
35 | + |
|
36 | + // Items table columns. |
|
37 | + add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
38 | + add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
39 | + add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
40 | + add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
41 | + add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
42 | + add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
43 | + |
|
44 | + // Payment forms columns. |
|
45 | + add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
46 | + add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
47 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
48 | + |
|
49 | + // Discount table columns. |
|
50 | + add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
51 | + add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
52 | + |
|
53 | + // Deleting posts. |
|
54 | + add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
55 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
56 | + |
|
57 | + add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 ); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Post updated messages. |
|
62 | + */ |
|
63 | + public static function post_updated_messages( $messages ) { |
|
64 | + global $post; |
|
65 | + |
|
66 | + $messages['wpi_discount'] = array( |
|
67 | + 0 => '', |
|
68 | + 1 => __( 'Discount updated.', 'invoicing' ), |
|
69 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
70 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
71 | + 4 => __( 'Discount updated.', 'invoicing' ), |
|
72 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
73 | + 6 => __( 'Discount updated.', 'invoicing' ), |
|
74 | + 7 => __( 'Discount saved.', 'invoicing' ), |
|
75 | + 8 => __( 'Discount submitted.', 'invoicing' ), |
|
76 | + 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
77 | + 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
78 | + ); |
|
79 | + |
|
80 | + $messages['wpi_payment_form'] = array( |
|
81 | + 0 => '', |
|
82 | + 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
83 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
84 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
85 | + 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
86 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
87 | + 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
88 | + 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
89 | + 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
90 | + 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
91 | + 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
92 | + ); |
|
93 | + |
|
94 | + return $messages; |
|
95 | + |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Post row actions. |
|
100 | + */ |
|
101 | + public static function post_row_actions( $actions, $post ) { |
|
102 | + |
|
103 | + $post = get_post( $post ); |
|
104 | + |
|
105 | + // We do not want to edit the default payment form. |
|
106 | + if ( 'wpi_payment_form' == $post->post_type ) { |
|
107 | + |
|
108 | + if ( wpinv_get_default_payment_form() === $post->ID ) { |
|
109 | + unset( $actions['trash'] ); |
|
110 | + unset( $actions['inline hide-if-no-js'] ); |
|
111 | + } |
|
112 | + |
|
113 | + $actions['duplicate'] = sprintf( |
|
114 | + '<a href="%1$s">%2$s</a>', |
|
115 | + esc_url( |
|
116 | + wp_nonce_url( |
|
117 | + add_query_arg( |
|
118 | + array( |
|
119 | + 'getpaid-admin-action' => 'duplicate_form', |
|
120 | + 'form_id' => $post->ID, |
|
121 | + ) |
|
122 | + ), |
|
123 | + 'getpaid-nonce', |
|
124 | + 'getpaid-nonce' |
|
125 | + ) |
|
126 | + ), |
|
127 | + esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
128 | + ); |
|
129 | + |
|
130 | + $actions['reset'] = sprintf( |
|
131 | + '<a href="%1$s" style="color: #800">%2$s</a>', |
|
132 | + esc_url( |
|
133 | + wp_nonce_url( |
|
134 | + add_query_arg( |
|
135 | + array( |
|
136 | + 'getpaid-admin-action' => 'reset_form_stats', |
|
137 | + 'form_id' => $post->ID, |
|
138 | + ) |
|
139 | + ), |
|
140 | + 'getpaid-nonce', |
|
141 | + 'getpaid-nonce' |
|
142 | + ) |
|
143 | + ), |
|
144 | + esc_html( __( 'Reset Stats', 'invoicing' ) ) |
|
145 | + ); |
|
146 | + } |
|
147 | + |
|
148 | + // Link to item payment form. |
|
149 | + if ( 'wpi_item' == $post->post_type ) { |
|
150 | + |
|
151 | + if ( in_array( get_post_meta( $post->ID, '_wpinv_type', true ), array( '', 'fee', 'custom' ), true ) ) { |
|
152 | + |
|
153 | + $actions['buy'] = sprintf( |
|
154 | + '<a href="%1$s">%2$s</a>', |
|
155 | + esc_url( getpaid_embed_url( false, $post->ID . '|0' ) ), |
|
156 | + esc_html( __( 'Buy', 'invoicing' ) ) |
|
157 | + ); |
|
158 | + |
|
159 | + } |
|
160 | 160 | } |
161 | 161 | |
162 | - return $actions; |
|
163 | - } |
|
162 | + return $actions; |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
165 | + /** |
|
166 | 166 | * Remove bulk edit option from admin side quote listing |
167 | 167 | * |
168 | 168 | * @since 1.0.0 |
169 | 169 | * @param array $actions post actions |
170 | - * @param WP_Post $post |
|
170 | + * @param WP_Post $post |
|
171 | 171 | * @return array $actions actions without edit option |
172 | 172 | */ |
173 | 173 | public static function filter_invoice_row_actions( $actions, $post ) { |
174 | 174 | |
175 | 175 | if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
176 | 176 | |
177 | - $actions = array(); |
|
178 | - $invoice = new WPInv_Invoice( $post ); |
|
179 | - |
|
180 | - $actions['edit'] = sprintf( |
|
181 | - '<a href="%1$s">%2$s</a>', |
|
182 | - esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
183 | - esc_html( __( 'Edit', 'invoicing' ) ) |
|
184 | - ); |
|
185 | - |
|
186 | - if ( ! $invoice->is_draft() ) { |
|
187 | - |
|
188 | - $actions['view'] = sprintf( |
|
189 | - '<a href="%1$s">%2$s</a>', |
|
190 | - esc_url( $invoice->get_view_url() ), |
|
191 | - sprintf( |
|
192 | - // translators: %s is the invoice type |
|
193 | - esc_html__( 'View %s', 'invoicing' ), |
|
194 | - getpaid_get_post_type_label( $invoice->get_post_type(), false ) |
|
195 | - ) |
|
196 | - ); |
|
197 | - |
|
198 | - $actions['send'] = sprintf( |
|
199 | - '<a href="%1$s">%2$s</a>', |
|
200 | - esc_url( |
|
201 | - wp_nonce_url( |
|
202 | - add_query_arg( |
|
203 | - array( |
|
204 | - 'getpaid-admin-action' => 'send_invoice', |
|
205 | - 'invoice_id' => $invoice->get_id(), |
|
206 | - ) |
|
207 | - ), |
|
208 | - 'getpaid-nonce', |
|
209 | - 'getpaid-nonce' |
|
210 | - ) |
|
211 | - ), |
|
212 | - esc_html( __( 'Send to Customer', 'invoicing' ) ) |
|
213 | - ); |
|
214 | - |
|
215 | - } |
|
216 | - |
|
217 | - $actions['duplicate'] = sprintf( |
|
218 | - '<a href="%1$s">%2$s</a>', |
|
219 | - esc_url( |
|
220 | - wp_nonce_url( |
|
221 | - add_query_arg( |
|
222 | - array( |
|
223 | - 'getpaid-admin-action' => 'duplicate_invoice', |
|
224 | - 'invoice_id' => $post->ID, |
|
225 | - ) |
|
226 | - ), |
|
227 | - 'getpaid-nonce', |
|
228 | - 'getpaid-nonce' |
|
229 | - ) |
|
230 | - ), |
|
231 | - esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
232 | - ); |
|
177 | + $actions = array(); |
|
178 | + $invoice = new WPInv_Invoice( $post ); |
|
179 | + |
|
180 | + $actions['edit'] = sprintf( |
|
181 | + '<a href="%1$s">%2$s</a>', |
|
182 | + esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
183 | + esc_html( __( 'Edit', 'invoicing' ) ) |
|
184 | + ); |
|
185 | + |
|
186 | + if ( ! $invoice->is_draft() ) { |
|
187 | + |
|
188 | + $actions['view'] = sprintf( |
|
189 | + '<a href="%1$s">%2$s</a>', |
|
190 | + esc_url( $invoice->get_view_url() ), |
|
191 | + sprintf( |
|
192 | + // translators: %s is the invoice type |
|
193 | + esc_html__( 'View %s', 'invoicing' ), |
|
194 | + getpaid_get_post_type_label( $invoice->get_post_type(), false ) |
|
195 | + ) |
|
196 | + ); |
|
197 | + |
|
198 | + $actions['send'] = sprintf( |
|
199 | + '<a href="%1$s">%2$s</a>', |
|
200 | + esc_url( |
|
201 | + wp_nonce_url( |
|
202 | + add_query_arg( |
|
203 | + array( |
|
204 | + 'getpaid-admin-action' => 'send_invoice', |
|
205 | + 'invoice_id' => $invoice->get_id(), |
|
206 | + ) |
|
207 | + ), |
|
208 | + 'getpaid-nonce', |
|
209 | + 'getpaid-nonce' |
|
210 | + ) |
|
211 | + ), |
|
212 | + esc_html( __( 'Send to Customer', 'invoicing' ) ) |
|
213 | + ); |
|
214 | + |
|
215 | + } |
|
216 | + |
|
217 | + $actions['duplicate'] = sprintf( |
|
218 | + '<a href="%1$s">%2$s</a>', |
|
219 | + esc_url( |
|
220 | + wp_nonce_url( |
|
221 | + add_query_arg( |
|
222 | + array( |
|
223 | + 'getpaid-admin-action' => 'duplicate_invoice', |
|
224 | + 'invoice_id' => $post->ID, |
|
225 | + ) |
|
226 | + ), |
|
227 | + 'getpaid-nonce', |
|
228 | + 'getpaid-nonce' |
|
229 | + ) |
|
230 | + ), |
|
231 | + esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
232 | + ); |
|
233 | 233 | |
234 | 234 | } |
235 | 235 | |
236 | 236 | return $actions; |
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * Returns an array of invoice table columns. |
|
241 | - */ |
|
242 | - public static function invoice_columns( $columns ) { |
|
243 | - |
|
244 | - $columns = array( |
|
245 | - 'cb' => $columns['cb'], |
|
246 | - 'number' => __( 'Invoice', 'invoicing' ), |
|
247 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
248 | - 'invoice_date' => __( 'Created', 'invoicing' ), |
|
249 | - 'payment_date' => __( 'Completed', 'invoicing' ), |
|
250 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
251 | - 'recurring' => __( 'Recurring', 'invoicing' ), |
|
252 | - 'status' => __( 'Status', 'invoicing' ), |
|
253 | - ); |
|
254 | - |
|
255 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Displays invoice table columns. |
|
260 | - */ |
|
261 | - public static function display_invoice_columns( $column_name, $post_id ) { |
|
262 | - |
|
263 | - $invoice = new WPInv_Invoice( $post_id ); |
|
264 | - |
|
265 | - switch ( $column_name ) { |
|
266 | - |
|
267 | - case 'invoice_date': |
|
268 | - $date_time = esc_attr( $invoice->get_created_date() ); |
|
269 | - $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
270 | - echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
271 | - break; |
|
272 | - |
|
273 | - case 'payment_date': |
|
274 | - if ( $invoice->is_paid() ) { |
|
275 | - $date_time = esc_attr( $invoice->get_completed_date() ); |
|
276 | - $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
277 | - echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
278 | - } else { |
|
279 | - echo '—'; |
|
280 | - } |
|
281 | - |
|
282 | - break; |
|
283 | - |
|
284 | - case 'amount': |
|
285 | - $amount = $invoice->get_total(); |
|
286 | - $formated_amount = wp_kses_post( wpinv_price( $amount, $invoice->get_currency() ) ); |
|
287 | - |
|
288 | - if ( $invoice->is_refunded() ) { |
|
289 | - $refunded_amount = wpinv_price( 0, $invoice->get_currency() ); |
|
290 | - echo wp_kses_post( "<del>$formated_amount</del> <ins>$refunded_amount</ins>" ); |
|
291 | - } else { |
|
292 | - |
|
293 | - $discount = $invoice->get_total_discount(); |
|
294 | - |
|
295 | - if ( ! empty( $discount ) ) { |
|
296 | - $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() ); |
|
297 | - echo wp_kses_post( "<del>$new_amount</del> <ins>$formated_amount</ins>" ); |
|
298 | - } else { |
|
299 | - echo wp_kses_post( $formated_amount ); |
|
300 | - } |
|
301 | - } |
|
302 | - |
|
303 | - break; |
|
304 | - |
|
305 | - case 'status': |
|
306 | - $status = esc_html( $invoice->get_status() ); |
|
307 | - $status_label = esc_html( $invoice->get_status_nicename() ); |
|
308 | - |
|
309 | - // If it is paid, show the gateway title. |
|
310 | - if ( $invoice->is_paid() ) { |
|
311 | - $gateway = esc_html( $invoice->get_gateway_title() ); |
|
312 | - $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), esc_html( $gateway ) ); |
|
313 | - |
|
314 | - echo wp_kses_post( "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>" ); |
|
315 | - } else { |
|
316 | - echo wp_kses_post( "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>" ); |
|
317 | - } |
|
318 | - |
|
319 | - // If it is not paid, display the overdue and view status. |
|
320 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
321 | - |
|
322 | - // Invoice view status. |
|
323 | - if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
324 | - echo ' <i class="fa fa-eye wpi-help-tip" title="' . esc_attr__( 'Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
325 | - } else { |
|
326 | - echo ' <i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__( 'Not Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
327 | - } |
|
328 | - |
|
329 | - // Display the overview status. |
|
330 | - if ( wpinv_get_option( 'overdue_active' ) ) { |
|
331 | - $due_date = $invoice->get_due_date(); |
|
332 | - $fomatted = getpaid_format_date( $due_date ); |
|
333 | - |
|
334 | - if ( ! empty( $fomatted ) ) { |
|
335 | - $date = wp_sprintf( |
|
336 | - // translators: %s is the due date. |
|
337 | - __( 'Due %s', 'invoicing' ), |
|
338 | - $fomatted |
|
339 | - ); |
|
340 | - echo wp_kses_post( "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>" ); |
|
341 | - } |
|
342 | - } |
|
343 | - } |
|
344 | - |
|
345 | - break; |
|
346 | - |
|
347 | - case 'recurring': |
|
348 | - if ( $invoice->is_recurring() ) { |
|
349 | - echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
350 | - } else { |
|
351 | - echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
352 | - } |
|
353 | - break; |
|
354 | - |
|
355 | - case 'number': |
|
356 | - $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
357 | - $invoice_number = esc_html( $invoice->get_number() ); |
|
358 | - $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
359 | - |
|
360 | - echo wp_kses_post( "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>" ); |
|
361 | - |
|
362 | - do_action( 'getpaid_admin_table_invoice_number_column', $invoice ); |
|
363 | - break; |
|
364 | - |
|
365 | - case 'customer': |
|
366 | - $customer_name = $invoice->get_user_full_name(); |
|
367 | - |
|
368 | - if ( empty( $customer_name ) ) { |
|
369 | - $customer_name = $invoice->get_email(); |
|
370 | - } |
|
371 | - |
|
372 | - if ( ! empty( $customer_name ) ) { |
|
373 | - $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
374 | - $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
375 | - echo wp_kses_post( "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>" ); |
|
376 | - } else { |
|
377 | - echo '<div>—</div>'; |
|
378 | - } |
|
379 | - |
|
380 | - break; |
|
381 | - |
|
382 | - } |
|
383 | - |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * Displays invoice bulk actions. |
|
388 | - */ |
|
389 | - public static function invoice_bulk_actions( $actions ) { |
|
390 | - $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' ); |
|
391 | - return $actions; |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * Processes invoice bulk actions. |
|
396 | - */ |
|
397 | - public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) { |
|
398 | - |
|
399 | - if ( 'resend-invoice' === $action ) { |
|
400 | - foreach ( $post_ids as $post_id ) { |
|
401 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true ); |
|
402 | - } |
|
403 | - } |
|
404 | - |
|
405 | - return $redirect_url; |
|
406 | - |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * Returns an array of payment forms table columns. |
|
411 | - */ |
|
412 | - public static function payment_form_columns( $columns ) { |
|
413 | - |
|
414 | - $columns = array( |
|
415 | - 'cb' => $columns['cb'], |
|
416 | - 'title' => __( 'Name', 'invoicing' ), |
|
417 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
418 | - 'earnings' => __( 'Revenue', 'invoicing' ), |
|
419 | - 'refunds' => __( 'Refunded', 'invoicing' ), |
|
420 | - 'items' => __( 'Items', 'invoicing' ), |
|
421 | - 'date' => __( 'Date', 'invoicing' ), |
|
422 | - ); |
|
423 | - |
|
424 | - return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
425 | - |
|
426 | - } |
|
427 | - |
|
428 | - /** |
|
429 | - * Displays payment form table columns. |
|
430 | - */ |
|
431 | - public static function display_payment_form_columns( $column_name, $post_id ) { |
|
432 | - |
|
433 | - // Retrieve the payment form. |
|
434 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
435 | - |
|
436 | - switch ( $column_name ) { |
|
437 | - |
|
438 | - case 'earnings': |
|
439 | - echo wp_kses_post( wpinv_price( $form->get_earned() ) ); |
|
440 | - break; |
|
441 | - |
|
442 | - case 'refunds': |
|
443 | - echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
444 | - break; |
|
445 | - |
|
446 | - case 'refunds': |
|
447 | - echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
448 | - break; |
|
449 | - |
|
450 | - case 'shortcode': |
|
451 | - if ( $form->is_default() ) { |
|
452 | - echo '—'; |
|
453 | - } else { |
|
454 | - echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
455 | - } |
|
456 | - |
|
457 | - break; |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * Returns an array of invoice table columns. |
|
241 | + */ |
|
242 | + public static function invoice_columns( $columns ) { |
|
243 | + |
|
244 | + $columns = array( |
|
245 | + 'cb' => $columns['cb'], |
|
246 | + 'number' => __( 'Invoice', 'invoicing' ), |
|
247 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
248 | + 'invoice_date' => __( 'Created', 'invoicing' ), |
|
249 | + 'payment_date' => __( 'Completed', 'invoicing' ), |
|
250 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
251 | + 'recurring' => __( 'Recurring', 'invoicing' ), |
|
252 | + 'status' => __( 'Status', 'invoicing' ), |
|
253 | + ); |
|
254 | + |
|
255 | + return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Displays invoice table columns. |
|
260 | + */ |
|
261 | + public static function display_invoice_columns( $column_name, $post_id ) { |
|
262 | + |
|
263 | + $invoice = new WPInv_Invoice( $post_id ); |
|
264 | + |
|
265 | + switch ( $column_name ) { |
|
266 | + |
|
267 | + case 'invoice_date': |
|
268 | + $date_time = esc_attr( $invoice->get_created_date() ); |
|
269 | + $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
270 | + echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
271 | + break; |
|
272 | + |
|
273 | + case 'payment_date': |
|
274 | + if ( $invoice->is_paid() ) { |
|
275 | + $date_time = esc_attr( $invoice->get_completed_date() ); |
|
276 | + $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
277 | + echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
278 | + } else { |
|
279 | + echo '—'; |
|
280 | + } |
|
281 | + |
|
282 | + break; |
|
283 | + |
|
284 | + case 'amount': |
|
285 | + $amount = $invoice->get_total(); |
|
286 | + $formated_amount = wp_kses_post( wpinv_price( $amount, $invoice->get_currency() ) ); |
|
287 | + |
|
288 | + if ( $invoice->is_refunded() ) { |
|
289 | + $refunded_amount = wpinv_price( 0, $invoice->get_currency() ); |
|
290 | + echo wp_kses_post( "<del>$formated_amount</del> <ins>$refunded_amount</ins>" ); |
|
291 | + } else { |
|
292 | + |
|
293 | + $discount = $invoice->get_total_discount(); |
|
294 | + |
|
295 | + if ( ! empty( $discount ) ) { |
|
296 | + $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() ); |
|
297 | + echo wp_kses_post( "<del>$new_amount</del> <ins>$formated_amount</ins>" ); |
|
298 | + } else { |
|
299 | + echo wp_kses_post( $formated_amount ); |
|
300 | + } |
|
301 | + } |
|
302 | + |
|
303 | + break; |
|
304 | + |
|
305 | + case 'status': |
|
306 | + $status = esc_html( $invoice->get_status() ); |
|
307 | + $status_label = esc_html( $invoice->get_status_nicename() ); |
|
308 | + |
|
309 | + // If it is paid, show the gateway title. |
|
310 | + if ( $invoice->is_paid() ) { |
|
311 | + $gateway = esc_html( $invoice->get_gateway_title() ); |
|
312 | + $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), esc_html( $gateway ) ); |
|
313 | + |
|
314 | + echo wp_kses_post( "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>" ); |
|
315 | + } else { |
|
316 | + echo wp_kses_post( "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>" ); |
|
317 | + } |
|
318 | + |
|
319 | + // If it is not paid, display the overdue and view status. |
|
320 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
321 | + |
|
322 | + // Invoice view status. |
|
323 | + if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
324 | + echo ' <i class="fa fa-eye wpi-help-tip" title="' . esc_attr__( 'Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
325 | + } else { |
|
326 | + echo ' <i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__( 'Not Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
327 | + } |
|
328 | + |
|
329 | + // Display the overview status. |
|
330 | + if ( wpinv_get_option( 'overdue_active' ) ) { |
|
331 | + $due_date = $invoice->get_due_date(); |
|
332 | + $fomatted = getpaid_format_date( $due_date ); |
|
333 | + |
|
334 | + if ( ! empty( $fomatted ) ) { |
|
335 | + $date = wp_sprintf( |
|
336 | + // translators: %s is the due date. |
|
337 | + __( 'Due %s', 'invoicing' ), |
|
338 | + $fomatted |
|
339 | + ); |
|
340 | + echo wp_kses_post( "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>" ); |
|
341 | + } |
|
342 | + } |
|
343 | + } |
|
344 | + |
|
345 | + break; |
|
346 | + |
|
347 | + case 'recurring': |
|
348 | + if ( $invoice->is_recurring() ) { |
|
349 | + echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
350 | + } else { |
|
351 | + echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
352 | + } |
|
353 | + break; |
|
354 | + |
|
355 | + case 'number': |
|
356 | + $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
357 | + $invoice_number = esc_html( $invoice->get_number() ); |
|
358 | + $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
359 | + |
|
360 | + echo wp_kses_post( "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>" ); |
|
361 | + |
|
362 | + do_action( 'getpaid_admin_table_invoice_number_column', $invoice ); |
|
363 | + break; |
|
364 | + |
|
365 | + case 'customer': |
|
366 | + $customer_name = $invoice->get_user_full_name(); |
|
367 | + |
|
368 | + if ( empty( $customer_name ) ) { |
|
369 | + $customer_name = $invoice->get_email(); |
|
370 | + } |
|
371 | + |
|
372 | + if ( ! empty( $customer_name ) ) { |
|
373 | + $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
374 | + $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
375 | + echo wp_kses_post( "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>" ); |
|
376 | + } else { |
|
377 | + echo '<div>—</div>'; |
|
378 | + } |
|
379 | + |
|
380 | + break; |
|
458 | 381 | |
459 | - case 'items': |
|
460 | - $items = $form->get_items(); |
|
461 | - |
|
462 | - if ( $form->is_default() || empty( $items ) ) { |
|
463 | - echo '—'; |
|
464 | - return; |
|
465 | - } |
|
466 | - |
|
467 | - $_items = array(); |
|
468 | - |
|
469 | - foreach ( $items as $item ) { |
|
470 | - $url = $item->get_edit_url(); |
|
471 | - |
|
472 | - if ( empty( $url ) ) { |
|
473 | - $_items[] = esc_html( $item->get_name() ); |
|
474 | - } else { |
|
475 | - $_items[] = sprintf( |
|
476 | - '<a href="%s">%s</a>', |
|
477 | - esc_url( $url ), |
|
478 | - esc_html( $item->get_name() ) |
|
479 | - ); |
|
480 | - } |
|
382 | + } |
|
383 | + |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * Displays invoice bulk actions. |
|
388 | + */ |
|
389 | + public static function invoice_bulk_actions( $actions ) { |
|
390 | + $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' ); |
|
391 | + return $actions; |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * Processes invoice bulk actions. |
|
396 | + */ |
|
397 | + public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) { |
|
398 | + |
|
399 | + if ( 'resend-invoice' === $action ) { |
|
400 | + foreach ( $post_ids as $post_id ) { |
|
401 | + getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true ); |
|
402 | + } |
|
403 | + } |
|
404 | + |
|
405 | + return $redirect_url; |
|
406 | + |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * Returns an array of payment forms table columns. |
|
411 | + */ |
|
412 | + public static function payment_form_columns( $columns ) { |
|
413 | + |
|
414 | + $columns = array( |
|
415 | + 'cb' => $columns['cb'], |
|
416 | + 'title' => __( 'Name', 'invoicing' ), |
|
417 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
418 | + 'earnings' => __( 'Revenue', 'invoicing' ), |
|
419 | + 'refunds' => __( 'Refunded', 'invoicing' ), |
|
420 | + 'items' => __( 'Items', 'invoicing' ), |
|
421 | + 'date' => __( 'Date', 'invoicing' ), |
|
422 | + ); |
|
423 | + |
|
424 | + return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
425 | + |
|
426 | + } |
|
427 | + |
|
428 | + /** |
|
429 | + * Displays payment form table columns. |
|
430 | + */ |
|
431 | + public static function display_payment_form_columns( $column_name, $post_id ) { |
|
432 | + |
|
433 | + // Retrieve the payment form. |
|
434 | + $form = new GetPaid_Payment_Form( $post_id ); |
|
435 | + |
|
436 | + switch ( $column_name ) { |
|
437 | + |
|
438 | + case 'earnings': |
|
439 | + echo wp_kses_post( wpinv_price( $form->get_earned() ) ); |
|
440 | + break; |
|
441 | + |
|
442 | + case 'refunds': |
|
443 | + echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
444 | + break; |
|
445 | + |
|
446 | + case 'refunds': |
|
447 | + echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
448 | + break; |
|
449 | + |
|
450 | + case 'shortcode': |
|
451 | + if ( $form->is_default() ) { |
|
452 | + echo '—'; |
|
453 | + } else { |
|
454 | + echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
455 | + } |
|
456 | + |
|
457 | + break; |
|
458 | + |
|
459 | + case 'items': |
|
460 | + $items = $form->get_items(); |
|
461 | + |
|
462 | + if ( $form->is_default() || empty( $items ) ) { |
|
463 | + echo '—'; |
|
464 | + return; |
|
465 | + } |
|
466 | + |
|
467 | + $_items = array(); |
|
468 | + |
|
469 | + foreach ( $items as $item ) { |
|
470 | + $url = $item->get_edit_url(); |
|
471 | + |
|
472 | + if ( empty( $url ) ) { |
|
473 | + $_items[] = esc_html( $item->get_name() ); |
|
474 | + } else { |
|
475 | + $_items[] = sprintf( |
|
476 | + '<a href="%s">%s</a>', |
|
477 | + esc_url( $url ), |
|
478 | + esc_html( $item->get_name() ) |
|
479 | + ); |
|
480 | + } |
|
481 | 481 | } |
482 | 482 | |
483 | - echo wp_kses_post( implode( '<br>', $_items ) ); |
|
483 | + echo wp_kses_post( implode( '<br>', $_items ) ); |
|
484 | + |
|
485 | + break; |
|
486 | + |
|
487 | + } |
|
488 | + |
|
489 | + } |
|
490 | + |
|
491 | + /** |
|
492 | + * Filters post states. |
|
493 | + */ |
|
494 | + public static function filter_payment_form_state( $post_states, $post ) { |
|
495 | + |
|
496 | + if ( 'wpi_payment_form' === $post->post_type && wpinv_get_default_payment_form() === $post->ID ) { |
|
497 | + $post_states['default_form'] = __( 'Default Payment Form', 'invoicing' ); |
|
498 | + } |
|
499 | + |
|
500 | + return $post_states; |
|
501 | + |
|
502 | + } |
|
503 | + |
|
504 | + /** |
|
505 | + * Returns an array of coupon table columns. |
|
506 | + */ |
|
507 | + public static function discount_columns( $columns ) { |
|
508 | + |
|
509 | + $columns = array( |
|
510 | + 'cb' => $columns['cb'], |
|
511 | + 'title' => __( 'Name', 'invoicing' ), |
|
512 | + 'code' => __( 'Code', 'invoicing' ), |
|
513 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
514 | + 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
515 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
516 | + 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
517 | + ); |
|
518 | + |
|
519 | + return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
520 | + } |
|
484 | 521 | |
485 | - break; |
|
522 | + /** |
|
523 | + * Filters post states. |
|
524 | + */ |
|
525 | + public static function filter_discount_state( $post_states, $post ) { |
|
486 | 526 | |
487 | - } |
|
527 | + if ( 'wpi_discount' === $post->post_type ) { |
|
488 | 528 | |
489 | - } |
|
529 | + $discount = new WPInv_Discount( $post ); |
|
490 | 530 | |
491 | - /** |
|
492 | - * Filters post states. |
|
493 | - */ |
|
494 | - public static function filter_payment_form_state( $post_states, $post ) { |
|
531 | + $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
495 | 532 | |
496 | - if ( 'wpi_payment_form' === $post->post_type && wpinv_get_default_payment_form() === $post->ID ) { |
|
497 | - $post_states['default_form'] = __( 'Default Payment Form', 'invoicing' ); |
|
498 | - } |
|
533 | + if ( 'publish' !== $status ) { |
|
534 | + return array( |
|
535 | + 'discount_status' => wpinv_discount_status( $status ), |
|
536 | + ); |
|
537 | + } |
|
538 | + |
|
539 | + return array(); |
|
540 | + |
|
541 | + } |
|
542 | + |
|
543 | + return $post_states; |
|
499 | 544 | |
500 | - return $post_states; |
|
545 | + } |
|
501 | 546 | |
502 | - } |
|
547 | + /** |
|
548 | + * Returns an array of items table columns. |
|
549 | + */ |
|
550 | + public static function item_columns( $columns ) { |
|
551 | + |
|
552 | + $columns = array( |
|
553 | + 'cb' => $columns['cb'], |
|
554 | + 'title' => __( 'Name', 'invoicing' ), |
|
555 | + 'price' => __( 'Price', 'invoicing' ), |
|
556 | + 'vat_rule' => __( 'Tax Rule', 'invoicing' ), |
|
557 | + 'vat_class' => __( 'Tax Class', 'invoicing' ), |
|
558 | + 'type' => __( 'Type', 'invoicing' ), |
|
559 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
560 | + ); |
|
561 | + |
|
562 | + if ( ! wpinv_use_taxes() ) { |
|
563 | + unset( $columns['vat_rule'] ); |
|
564 | + unset( $columns['vat_class'] ); |
|
565 | + } |
|
503 | 566 | |
504 | - /** |
|
505 | - * Returns an array of coupon table columns. |
|
506 | - */ |
|
507 | - public static function discount_columns( $columns ) { |
|
567 | + return apply_filters( 'wpi_item_table_columns', $columns ); |
|
568 | + } |
|
508 | 569 | |
509 | - $columns = array( |
|
510 | - 'cb' => $columns['cb'], |
|
511 | - 'title' => __( 'Name', 'invoicing' ), |
|
512 | - 'code' => __( 'Code', 'invoicing' ), |
|
513 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
514 | - 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
515 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
516 | - 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
517 | - ); |
|
570 | + /** |
|
571 | + * Returns an array of sortable items table columns. |
|
572 | + */ |
|
573 | + public static function sortable_item_columns( $columns ) { |
|
574 | + |
|
575 | + return array_merge( |
|
576 | + $columns, |
|
577 | + array( |
|
578 | + 'price' => 'price', |
|
579 | + 'vat_rule' => 'vat_rule', |
|
580 | + 'vat_class' => 'vat_class', |
|
581 | + 'type' => 'type', |
|
582 | + ) |
|
583 | + ); |
|
518 | 584 | |
519 | - return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
520 | - } |
|
585 | + } |
|
521 | 586 | |
522 | - /** |
|
523 | - * Filters post states. |
|
524 | - */ |
|
525 | - public static function filter_discount_state( $post_states, $post ) { |
|
587 | + /** |
|
588 | + * Displays items table columns. |
|
589 | + */ |
|
590 | + public static function display_item_columns( $column_name, $post_id ) { |
|
526 | 591 | |
527 | - if ( 'wpi_discount' === $post->post_type ) { |
|
592 | + $item = new WPInv_Item( $post_id ); |
|
528 | 593 | |
529 | - $discount = new WPInv_Discount( $post ); |
|
594 | + switch ( $column_name ) { |
|
530 | 595 | |
531 | - $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
596 | + case 'price': |
|
597 | + if ( ! $item->is_recurring() ) { |
|
598 | + echo wp_kses_post( $item->get_the_price() ); |
|
599 | + break; |
|
600 | + } |
|
532 | 601 | |
533 | - if ( 'publish' !== $status ) { |
|
534 | - return array( |
|
535 | - 'discount_status' => wpinv_discount_status( $status ), |
|
536 | - ); |
|
537 | - } |
|
602 | + $price = wp_sprintf( |
|
603 | + __( '%1$s / %2$s', 'invoicing' ), |
|
604 | + $item->get_the_price(), |
|
605 | + getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
606 | + ); |
|
538 | 607 | |
539 | - return array(); |
|
608 | + if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
609 | + echo wp_kses_post( $price ); |
|
610 | + break; |
|
611 | + } |
|
540 | 612 | |
541 | - } |
|
613 | + echo wp_kses_post( $item->get_the_initial_price() ); |
|
542 | 614 | |
543 | - return $post_states; |
|
615 | + echo '<span class="meta">' . wp_sprintf( esc_html__( 'then %s', 'invoicing' ), wp_kses_post( $price ) ) . '</span>'; |
|
616 | + break; |
|
544 | 617 | |
545 | - } |
|
618 | + case 'vat_rule': |
|
619 | + echo wp_kses_post( getpaid_get_tax_rule_label( $item->get_vat_rule() ) ); |
|
620 | + break; |
|
546 | 621 | |
547 | - /** |
|
548 | - * Returns an array of items table columns. |
|
549 | - */ |
|
550 | - public static function item_columns( $columns ) { |
|
622 | + case 'vat_class': |
|
623 | + echo wp_kses_post( getpaid_get_tax_class_label( $item->get_vat_class() ) ); |
|
624 | + break; |
|
551 | 625 | |
552 | - $columns = array( |
|
553 | - 'cb' => $columns['cb'], |
|
554 | - 'title' => __( 'Name', 'invoicing' ), |
|
555 | - 'price' => __( 'Price', 'invoicing' ), |
|
556 | - 'vat_rule' => __( 'Tax Rule', 'invoicing' ), |
|
557 | - 'vat_class' => __( 'Tax Class', 'invoicing' ), |
|
558 | - 'type' => __( 'Type', 'invoicing' ), |
|
559 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
560 | - ); |
|
626 | + case 'shortcode': |
|
627 | + if ( $item->is_type( array( '', 'fee', 'custom' ) ) ) { |
|
628 | + echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
629 | + } else { |
|
630 | + echo '—'; |
|
631 | + } |
|
561 | 632 | |
562 | - if ( ! wpinv_use_taxes() ) { |
|
563 | - unset( $columns['vat_rule'] ); |
|
564 | - unset( $columns['vat_class'] ); |
|
565 | - } |
|
633 | + break; |
|
566 | 634 | |
567 | - return apply_filters( 'wpi_item_table_columns', $columns ); |
|
568 | - } |
|
635 | + case 'type': |
|
636 | + echo wp_kses_post( wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>' ); |
|
637 | + break; |
|
569 | 638 | |
570 | - /** |
|
571 | - * Returns an array of sortable items table columns. |
|
572 | - */ |
|
573 | - public static function sortable_item_columns( $columns ) { |
|
574 | - |
|
575 | - return array_merge( |
|
576 | - $columns, |
|
577 | - array( |
|
578 | - 'price' => 'price', |
|
579 | - 'vat_rule' => 'vat_rule', |
|
580 | - 'vat_class' => 'vat_class', |
|
581 | - 'type' => 'type', |
|
582 | - ) |
|
583 | - ); |
|
584 | - |
|
585 | - } |
|
586 | - |
|
587 | - /** |
|
588 | - * Displays items table columns. |
|
589 | - */ |
|
590 | - public static function display_item_columns( $column_name, $post_id ) { |
|
591 | - |
|
592 | - $item = new WPInv_Item( $post_id ); |
|
593 | - |
|
594 | - switch ( $column_name ) { |
|
595 | - |
|
596 | - case 'price': |
|
597 | - if ( ! $item->is_recurring() ) { |
|
598 | - echo wp_kses_post( $item->get_the_price() ); |
|
599 | - break; |
|
600 | - } |
|
601 | - |
|
602 | - $price = wp_sprintf( |
|
603 | - __( '%1$s / %2$s', 'invoicing' ), |
|
604 | - $item->get_the_price(), |
|
605 | - getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
606 | - ); |
|
607 | - |
|
608 | - if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
609 | - echo wp_kses_post( $price ); |
|
610 | - break; |
|
611 | - } |
|
612 | - |
|
613 | - echo wp_kses_post( $item->get_the_initial_price() ); |
|
614 | - |
|
615 | - echo '<span class="meta">' . wp_sprintf( esc_html__( 'then %s', 'invoicing' ), wp_kses_post( $price ) ) . '</span>'; |
|
616 | - break; |
|
617 | - |
|
618 | - case 'vat_rule': |
|
619 | - echo wp_kses_post( getpaid_get_tax_rule_label( $item->get_vat_rule() ) ); |
|
620 | - break; |
|
621 | - |
|
622 | - case 'vat_class': |
|
623 | - echo wp_kses_post( getpaid_get_tax_class_label( $item->get_vat_class() ) ); |
|
624 | - break; |
|
625 | - |
|
626 | - case 'shortcode': |
|
627 | - if ( $item->is_type( array( '', 'fee', 'custom' ) ) ) { |
|
628 | - echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
629 | - } else { |
|
630 | - echo '—'; |
|
631 | - } |
|
632 | - |
|
633 | - break; |
|
634 | - |
|
635 | - case 'type': |
|
636 | - echo wp_kses_post( wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>' ); |
|
637 | - break; |
|
638 | - |
|
639 | - } |
|
640 | - |
|
641 | - } |
|
642 | - |
|
643 | - /** |
|
644 | - * Lets users filter items using taxes. |
|
645 | - */ |
|
646 | - public static function add_item_filters( $post_type ) { |
|
647 | - |
|
648 | - // Abort if we're not dealing with items. |
|
649 | - if ( 'wpi_item' !== $post_type ) { |
|
650 | - return; |
|
651 | - } |
|
652 | - |
|
653 | - // Filter by vat rules. |
|
654 | - if ( wpinv_use_taxes() ) { |
|
655 | - |
|
656 | - // Sanitize selected vat rule. |
|
657 | - $vat_rule = ''; |
|
658 | - $vat_rules = getpaid_get_tax_rules(); |
|
659 | - if ( isset( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
660 | - $vat_rule = sanitize_text_field( $_GET['vat_rule'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
661 | - } |
|
662 | - |
|
663 | - // Filter by VAT rule. |
|
664 | - wpinv_html_select( |
|
665 | - array( |
|
666 | - 'options' => array_merge( |
|
667 | - array( |
|
668 | - '' => __( 'All Tax Rules', 'invoicing' ), |
|
669 | - ), |
|
670 | - $vat_rules |
|
671 | - ), |
|
672 | - 'name' => 'vat_rule', |
|
673 | - 'id' => 'vat_rule', |
|
674 | - 'selected' => in_array( $vat_rule, array_keys( $vat_rules ), true ) ? $vat_rule : '', |
|
675 | - 'show_option_all' => false, |
|
676 | - 'show_option_none' => false, |
|
677 | - ) |
|
678 | - ); |
|
679 | - |
|
680 | - // Filter by VAT class. |
|
681 | - |
|
682 | - // Sanitize selected vat rule. |
|
683 | - $vat_class = ''; |
|
684 | - $vat_classes = getpaid_get_tax_classes(); |
|
685 | - if ( isset( $_GET['vat_class'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
686 | - $vat_class = sanitize_text_field( $_GET['vat_class'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
687 | - } |
|
688 | - |
|
689 | - wpinv_html_select( |
|
690 | - array( |
|
691 | - 'options' => array_merge( |
|
692 | - array( |
|
693 | - '' => __( 'All Tax Classes', 'invoicing' ), |
|
694 | - ), |
|
695 | - $vat_classes |
|
696 | - ), |
|
697 | - 'name' => 'vat_class', |
|
698 | - 'id' => 'vat_class', |
|
699 | - 'selected' => in_array( $vat_class, array_keys( $vat_classes ), true ) ? $vat_class : '', |
|
700 | - 'show_option_all' => false, |
|
701 | - 'show_option_none' => false, |
|
702 | - ) |
|
703 | - ); |
|
704 | - |
|
705 | - } |
|
706 | - |
|
707 | - // Filter by item type. |
|
708 | - $type = ''; |
|
709 | - if ( isset( $_GET['type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
710 | - $type = sanitize_text_field( $_GET['type'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
711 | - } |
|
712 | - |
|
713 | - wpinv_html_select( |
|
714 | - array( |
|
715 | - 'options' => array_merge( |
|
716 | - array( |
|
717 | - '' => __( 'All item types', 'invoicing' ), |
|
718 | - ), |
|
719 | - wpinv_get_item_types() |
|
720 | - ), |
|
721 | - 'name' => 'type', |
|
722 | - 'id' => 'type', |
|
723 | - 'selected' => in_array( $type, wpinv_item_types(), true ) ? $type : '', |
|
724 | - 'show_option_all' => false, |
|
725 | - 'show_option_none' => false, |
|
726 | - ) |
|
727 | - ); |
|
728 | - |
|
729 | - } |
|
730 | - |
|
731 | - /** |
|
732 | - * Filters the item query. |
|
733 | - */ |
|
734 | - public static function filter_item_query( $query ) { |
|
735 | - |
|
736 | - // modify the query only if it admin and main query. |
|
737 | - if ( ! ( is_admin() && $query->is_main_query() ) ) { |
|
738 | - return $query; |
|
739 | - } |
|
740 | - |
|
741 | - // we want to modify the query for our items. |
|
742 | - if ( empty( $query->query['post_type'] ) || 'wpi_item' !== $query->query['post_type'] ) { |
|
743 | - return $query; |
|
744 | - } |
|
745 | - |
|
746 | - if ( empty( $query->query_vars['meta_query'] ) ) { |
|
747 | - $query->query_vars['meta_query'] = array(); |
|
748 | - } |
|
749 | - |
|
750 | - // Filter vat rule type |
|
639 | + } |
|
640 | + |
|
641 | + } |
|
642 | + |
|
643 | + /** |
|
644 | + * Lets users filter items using taxes. |
|
645 | + */ |
|
646 | + public static function add_item_filters( $post_type ) { |
|
647 | + |
|
648 | + // Abort if we're not dealing with items. |
|
649 | + if ( 'wpi_item' !== $post_type ) { |
|
650 | + return; |
|
651 | + } |
|
652 | + |
|
653 | + // Filter by vat rules. |
|
654 | + if ( wpinv_use_taxes() ) { |
|
655 | + |
|
656 | + // Sanitize selected vat rule. |
|
657 | + $vat_rule = ''; |
|
658 | + $vat_rules = getpaid_get_tax_rules(); |
|
659 | + if ( isset( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
660 | + $vat_rule = sanitize_text_field( $_GET['vat_rule'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
661 | + } |
|
662 | + |
|
663 | + // Filter by VAT rule. |
|
664 | + wpinv_html_select( |
|
665 | + array( |
|
666 | + 'options' => array_merge( |
|
667 | + array( |
|
668 | + '' => __( 'All Tax Rules', 'invoicing' ), |
|
669 | + ), |
|
670 | + $vat_rules |
|
671 | + ), |
|
672 | + 'name' => 'vat_rule', |
|
673 | + 'id' => 'vat_rule', |
|
674 | + 'selected' => in_array( $vat_rule, array_keys( $vat_rules ), true ) ? $vat_rule : '', |
|
675 | + 'show_option_all' => false, |
|
676 | + 'show_option_none' => false, |
|
677 | + ) |
|
678 | + ); |
|
679 | + |
|
680 | + // Filter by VAT class. |
|
681 | + |
|
682 | + // Sanitize selected vat rule. |
|
683 | + $vat_class = ''; |
|
684 | + $vat_classes = getpaid_get_tax_classes(); |
|
685 | + if ( isset( $_GET['vat_class'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
686 | + $vat_class = sanitize_text_field( $_GET['vat_class'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
687 | + } |
|
688 | + |
|
689 | + wpinv_html_select( |
|
690 | + array( |
|
691 | + 'options' => array_merge( |
|
692 | + array( |
|
693 | + '' => __( 'All Tax Classes', 'invoicing' ), |
|
694 | + ), |
|
695 | + $vat_classes |
|
696 | + ), |
|
697 | + 'name' => 'vat_class', |
|
698 | + 'id' => 'vat_class', |
|
699 | + 'selected' => in_array( $vat_class, array_keys( $vat_classes ), true ) ? $vat_class : '', |
|
700 | + 'show_option_all' => false, |
|
701 | + 'show_option_none' => false, |
|
702 | + ) |
|
703 | + ); |
|
704 | + |
|
705 | + } |
|
706 | + |
|
707 | + // Filter by item type. |
|
708 | + $type = ''; |
|
709 | + if ( isset( $_GET['type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
710 | + $type = sanitize_text_field( $_GET['type'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
711 | + } |
|
712 | + |
|
713 | + wpinv_html_select( |
|
714 | + array( |
|
715 | + 'options' => array_merge( |
|
716 | + array( |
|
717 | + '' => __( 'All item types', 'invoicing' ), |
|
718 | + ), |
|
719 | + wpinv_get_item_types() |
|
720 | + ), |
|
721 | + 'name' => 'type', |
|
722 | + 'id' => 'type', |
|
723 | + 'selected' => in_array( $type, wpinv_item_types(), true ) ? $type : '', |
|
724 | + 'show_option_all' => false, |
|
725 | + 'show_option_none' => false, |
|
726 | + ) |
|
727 | + ); |
|
728 | + |
|
729 | + } |
|
730 | + |
|
731 | + /** |
|
732 | + * Filters the item query. |
|
733 | + */ |
|
734 | + public static function filter_item_query( $query ) { |
|
735 | + |
|
736 | + // modify the query only if it admin and main query. |
|
737 | + if ( ! ( is_admin() && $query->is_main_query() ) ) { |
|
738 | + return $query; |
|
739 | + } |
|
740 | + |
|
741 | + // we want to modify the query for our items. |
|
742 | + if ( empty( $query->query['post_type'] ) || 'wpi_item' !== $query->query['post_type'] ) { |
|
743 | + return $query; |
|
744 | + } |
|
745 | + |
|
746 | + if ( empty( $query->query_vars['meta_query'] ) ) { |
|
747 | + $query->query_vars['meta_query'] = array(); |
|
748 | + } |
|
749 | + |
|
750 | + // Filter vat rule type |
|
751 | 751 | if ( ! empty( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
752 | 752 | $query->query_vars['meta_query'][] = array( |
753 | 753 | 'key' => '_wpinv_vat_rule', |
@@ -772,101 +772,101 @@ discard block |
||
772 | 772 | 'value' => sanitize_text_field( $_GET['type'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
773 | 773 | 'compare' => '=', |
774 | 774 | ); |
775 | - } |
|
776 | - |
|
777 | - $query->query_vars['meta_query'][] = array( |
|
778 | - 'key' => '_wpinv_one_time', |
|
779 | - 'compare' => 'NOT EXISTS', |
|
780 | - ); |
|
781 | - } |
|
782 | - |
|
783 | - /** |
|
784 | - * Reorders items. |
|
785 | - */ |
|
786 | - public static function reorder_items( $vars ) { |
|
787 | - global $typenow; |
|
788 | - |
|
789 | - if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
790 | - return $vars; |
|
791 | - } |
|
792 | - |
|
793 | - // By item type. |
|
794 | - if ( 'type' === $vars['orderby'] ) { |
|
795 | - return array_merge( |
|
796 | - $vars, |
|
797 | - array( |
|
798 | - 'meta_key' => '_wpinv_type', |
|
799 | - 'orderby' => 'meta_value', |
|
800 | - ) |
|
801 | - ); |
|
802 | - } |
|
803 | - |
|
804 | - // By vat class. |
|
805 | - if ( 'vat_class' === $vars['orderby'] ) { |
|
806 | - return array_merge( |
|
807 | - $vars, |
|
808 | - array( |
|
809 | - 'meta_key' => '_wpinv_vat_class', |
|
810 | - 'orderby' => 'meta_value', |
|
811 | - ) |
|
812 | - ); |
|
813 | - } |
|
814 | - |
|
815 | - // By vat rule. |
|
816 | - if ( 'vat_rule' === $vars['orderby'] ) { |
|
817 | - return array_merge( |
|
818 | - $vars, |
|
819 | - array( |
|
820 | - 'meta_key' => '_wpinv_vat_rule', |
|
821 | - 'orderby' => 'meta_value', |
|
822 | - ) |
|
823 | - ); |
|
824 | - } |
|
825 | - |
|
826 | - // By price. |
|
827 | - if ( 'price' === $vars['orderby'] ) { |
|
828 | - return array_merge( |
|
829 | - $vars, |
|
830 | - array( |
|
831 | - 'meta_key' => '_wpinv_price', |
|
832 | - 'orderby' => 'meta_value_num', |
|
833 | - ) |
|
834 | - ); |
|
835 | - } |
|
836 | - |
|
837 | - return $vars; |
|
838 | - |
|
839 | - } |
|
840 | - |
|
841 | - /** |
|
842 | - * Fired when deleting a post. |
|
843 | - */ |
|
844 | - public static function delete_post( $post_id ) { |
|
845 | - |
|
846 | - switch ( get_post_type( $post_id ) ) { |
|
847 | - |
|
848 | - case 'wpi_item': |
|
849 | - do_action( 'getpaid_before_delete_item', new WPInv_Item( $post_id ) ); |
|
850 | - break; |
|
851 | - |
|
852 | - case 'wpi_payment_form': |
|
853 | - do_action( 'getpaid_before_delete_payment_form', new GetPaid_Payment_Form( $post_id ) ); |
|
854 | - break; |
|
855 | - |
|
856 | - case 'wpi_discount': |
|
857 | - do_action( 'getpaid_before_delete_discount', new WPInv_Discount( $post_id ) ); |
|
858 | - break; |
|
859 | - |
|
860 | - case 'wpi_invoice': |
|
861 | - $invoice = new WPInv_Invoice( $post_id ); |
|
862 | - do_action( 'getpaid_before_delete_invoice', $invoice ); |
|
863 | - $invoice->get_data_store()->delete_items( $invoice ); |
|
864 | - $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
865 | - break; |
|
866 | - } |
|
867 | - } |
|
868 | - |
|
869 | - /** |
|
775 | + } |
|
776 | + |
|
777 | + $query->query_vars['meta_query'][] = array( |
|
778 | + 'key' => '_wpinv_one_time', |
|
779 | + 'compare' => 'NOT EXISTS', |
|
780 | + ); |
|
781 | + } |
|
782 | + |
|
783 | + /** |
|
784 | + * Reorders items. |
|
785 | + */ |
|
786 | + public static function reorder_items( $vars ) { |
|
787 | + global $typenow; |
|
788 | + |
|
789 | + if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
790 | + return $vars; |
|
791 | + } |
|
792 | + |
|
793 | + // By item type. |
|
794 | + if ( 'type' === $vars['orderby'] ) { |
|
795 | + return array_merge( |
|
796 | + $vars, |
|
797 | + array( |
|
798 | + 'meta_key' => '_wpinv_type', |
|
799 | + 'orderby' => 'meta_value', |
|
800 | + ) |
|
801 | + ); |
|
802 | + } |
|
803 | + |
|
804 | + // By vat class. |
|
805 | + if ( 'vat_class' === $vars['orderby'] ) { |
|
806 | + return array_merge( |
|
807 | + $vars, |
|
808 | + array( |
|
809 | + 'meta_key' => '_wpinv_vat_class', |
|
810 | + 'orderby' => 'meta_value', |
|
811 | + ) |
|
812 | + ); |
|
813 | + } |
|
814 | + |
|
815 | + // By vat rule. |
|
816 | + if ( 'vat_rule' === $vars['orderby'] ) { |
|
817 | + return array_merge( |
|
818 | + $vars, |
|
819 | + array( |
|
820 | + 'meta_key' => '_wpinv_vat_rule', |
|
821 | + 'orderby' => 'meta_value', |
|
822 | + ) |
|
823 | + ); |
|
824 | + } |
|
825 | + |
|
826 | + // By price. |
|
827 | + if ( 'price' === $vars['orderby'] ) { |
|
828 | + return array_merge( |
|
829 | + $vars, |
|
830 | + array( |
|
831 | + 'meta_key' => '_wpinv_price', |
|
832 | + 'orderby' => 'meta_value_num', |
|
833 | + ) |
|
834 | + ); |
|
835 | + } |
|
836 | + |
|
837 | + return $vars; |
|
838 | + |
|
839 | + } |
|
840 | + |
|
841 | + /** |
|
842 | + * Fired when deleting a post. |
|
843 | + */ |
|
844 | + public static function delete_post( $post_id ) { |
|
845 | + |
|
846 | + switch ( get_post_type( $post_id ) ) { |
|
847 | + |
|
848 | + case 'wpi_item': |
|
849 | + do_action( 'getpaid_before_delete_item', new WPInv_Item( $post_id ) ); |
|
850 | + break; |
|
851 | + |
|
852 | + case 'wpi_payment_form': |
|
853 | + do_action( 'getpaid_before_delete_payment_form', new GetPaid_Payment_Form( $post_id ) ); |
|
854 | + break; |
|
855 | + |
|
856 | + case 'wpi_discount': |
|
857 | + do_action( 'getpaid_before_delete_discount', new WPInv_Discount( $post_id ) ); |
|
858 | + break; |
|
859 | + |
|
860 | + case 'wpi_invoice': |
|
861 | + $invoice = new WPInv_Invoice( $post_id ); |
|
862 | + do_action( 'getpaid_before_delete_invoice', $invoice ); |
|
863 | + $invoice->get_data_store()->delete_items( $invoice ); |
|
864 | + $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
865 | + break; |
|
866 | + } |
|
867 | + } |
|
868 | + |
|
869 | + /** |
|
870 | 870 | * Add a post display state for special GetPaid pages in the page list table. |
871 | 871 | * |
872 | 872 | * @param array $post_states An array of post display states. |
@@ -880,21 +880,21 @@ discard block |
||
880 | 880 | $post_states['getpaid_success_page'] = __( 'GetPaid Receipt Page', 'invoicing' ); |
881 | 881 | } |
882 | 882 | |
883 | - foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) { |
|
883 | + foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) { |
|
884 | 884 | |
885 | - if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) { |
|
886 | - $post_states[ "getpaid_{$post_type}_history_page" ] = sprintf( |
|
887 | - __( 'GetPaid %s History Page', 'invoicing' ), |
|
888 | - $label |
|
889 | - ); |
|
890 | - } |
|
885 | + if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) { |
|
886 | + $post_states[ "getpaid_{$post_type}_history_page" ] = sprintf( |
|
887 | + __( 'GetPaid %s History Page', 'invoicing' ), |
|
888 | + $label |
|
889 | + ); |
|
890 | + } |
|
891 | 891 | } |
892 | 892 | |
893 | - if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) { |
|
893 | + if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) { |
|
894 | 894 | $post_states['getpaid_invoice_subscription_page'] = __( 'GetPaid Subscription Page', 'invoicing' ); |
895 | 895 | } |
896 | 896 | |
897 | - if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) { |
|
897 | + if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) { |
|
898 | 898 | $post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' ); |
899 | 899 | } |
900 | 900 |
@@ -57,21 +57,21 @@ discard block |
||
57 | 57 | $args = wp_parse_args( |
58 | 58 | $args, |
59 | 59 | array( |
60 | - 'status' => array( 'publish' ), |
|
61 | - 'limit' => get_option( 'posts_per_page' ), |
|
62 | - 'page' => 1, |
|
63 | - 'exclude' => array(), |
|
64 | - 'orderby' => 'date', |
|
65 | - 'order' => 'DESC', |
|
66 | - 'type' => wpinv_item_types(), |
|
67 | - 'meta_query' => array( |
|
60 | + 'status' => array( 'publish' ), |
|
61 | + 'limit' => get_option( 'posts_per_page' ), |
|
62 | + 'page' => 1, |
|
63 | + 'exclude' => array(), |
|
64 | + 'orderby' => 'date', |
|
65 | + 'order' => 'DESC', |
|
66 | + 'type' => wpinv_item_types(), |
|
67 | + 'meta_query' => array( |
|
68 | 68 | array( |
69 | 69 | 'key' => '_wpinv_one_time', |
70 | 70 | 'compare' => 'NOT EXISTS', |
71 | 71 | ), |
72 | 72 | ), |
73 | - 'return' => 'objects', |
|
74 | - 'paginate' => false, |
|
73 | + 'return' => 'objects', |
|
74 | + 'paginate' => false, |
|
75 | 75 | ) |
76 | 76 | ); |
77 | 77 | |
@@ -211,9 +211,9 @@ discard block |
||
211 | 211 | |
212 | 212 | function wpinv_get_item_types() { |
213 | 213 | $item_types = array( |
214 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
215 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
216 | - ); |
|
214 | + 'custom' => __( 'Standard', 'invoicing' ), |
|
215 | + 'fee' => __( 'Fee', 'invoicing' ), |
|
216 | + ); |
|
217 | 217 | return apply_filters( 'wpinv_get_item_types', $item_types ); |
218 | 218 | } |
219 | 219 | |
@@ -255,16 +255,16 @@ discard block |
||
255 | 255 | $args = array(); |
256 | 256 | if ( $post_ids ) { |
257 | 257 | $args = array( |
258 | - 'fields' => 'ids', |
|
259 | - ); |
|
258 | + 'fields' => 'ids', |
|
259 | + ); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | $args = array_merge( |
263 | 263 | $args, |
264 | 264 | array( |
265 | 265 | 'post_type' => 'wpi_item', |
266 | - 'orderby' => 'rand', |
|
267 | - 'post_count' => $num, |
|
266 | + 'orderby' => 'rand', |
|
267 | + 'post_count' => $num, |
|
268 | 268 | 'meta_query' => array( |
269 | 269 | array( |
270 | 270 | 'key' => '_wpinv_one_time', |
@@ -439,10 +439,10 @@ discard block |
||
439 | 439 | $bill_times_less = $bill_times - 1; |
440 | 440 | |
441 | 441 | if ( ! empty( $bill_times ) ) { |
442 | - $bill_times = $item->get_recurring_interval() * $bill_times; |
|
442 | + $bill_times = $item->get_recurring_interval() * $bill_times; |
|
443 | 443 | $bill_times_less = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times - $item->get_recurring_interval() ); |
444 | - $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
445 | - } |
|
444 | + $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
445 | + } |
|
446 | 446 | |
447 | 447 | if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) { |
448 | 448 | $initial_price = wpinv_price( $item->get_sub_total(), $currency ); |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Retrieves an item by it's ID. |
@@ -14,9 +14,9 @@ discard block |
||
14 | 14 | * @param int the item ID to retrieve. |
15 | 15 | * @return WPInv_Item|false |
16 | 16 | */ |
17 | -function wpinv_get_item_by_id( $id ) { |
|
18 | - $item = wpinv_get_item( $id ); |
|
19 | - return empty( $item ) || $id != $item->get_id() ? false : $item; |
|
17 | +function wpinv_get_item_by_id($id) { |
|
18 | + $item = wpinv_get_item($id); |
|
19 | + return empty($item) || $id != $item->get_id() ? false : $item; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -24,14 +24,14 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @return WPInv_Item|false |
26 | 26 | */ |
27 | -function wpinv_get_item_by( $field = '', $value = '', $type = '' ) { |
|
27 | +function wpinv_get_item_by($field = '', $value = '', $type = '') { |
|
28 | 28 | |
29 | - if ( 'id' === strtolower( $field ) ) { |
|
30 | - return wpinv_get_item_by_id( $value ); |
|
29 | + if ('id' === strtolower($field)) { |
|
30 | + return wpinv_get_item_by_id($value); |
|
31 | 31 | } |
32 | 32 | |
33 | - $id = WPInv_Item::get_item_id_by_field( $value, strtolower( $field ), $type ); |
|
34 | - return empty( $id ) ? false : wpinv_get_item( $id ); |
|
33 | + $id = WPInv_Item::get_item_id_by_field($value, strtolower($field), $type); |
|
34 | + return empty($id) ? false : wpinv_get_item($id); |
|
35 | 35 | |
36 | 36 | } |
37 | 37 | |
@@ -41,24 +41,24 @@ discard block |
||
41 | 41 | * @param int|WPInv_Item the item to retrieve. |
42 | 42 | * @return WPInv_Item|false |
43 | 43 | */ |
44 | -function wpinv_get_item( $item = 0 ) { |
|
44 | +function wpinv_get_item($item = 0) { |
|
45 | 45 | |
46 | - if ( empty( $item ) ) { |
|
46 | + if (empty($item)) { |
|
47 | 47 | return false; |
48 | 48 | } |
49 | 49 | |
50 | - $item = new WPInv_Item( $item ); |
|
50 | + $item = new WPInv_Item($item); |
|
51 | 51 | return $item->exists() ? $item : false; |
52 | 52 | |
53 | 53 | } |
54 | 54 | |
55 | -function wpinv_get_all_items( $args = array() ) { |
|
55 | +function wpinv_get_all_items($args = array()) { |
|
56 | 56 | |
57 | 57 | $args = wp_parse_args( |
58 | 58 | $args, |
59 | 59 | array( |
60 | - 'status' => array( 'publish' ), |
|
61 | - 'limit' => get_option( 'posts_per_page' ), |
|
60 | + 'status' => array('publish'), |
|
61 | + 'limit' => get_option('posts_per_page'), |
|
62 | 62 | 'page' => 1, |
63 | 63 | 'exclude' => array(), |
64 | 64 | 'orderby' => 'date', |
@@ -83,44 +83,44 @@ discard block |
||
83 | 83 | 'fields' => 'ids', |
84 | 84 | 'orderby' => $args['orderby'], |
85 | 85 | 'order' => $args['order'], |
86 | - 'paged' => absint( $args['page'] ), |
|
86 | + 'paged' => absint($args['page']), |
|
87 | 87 | ); |
88 | 88 | |
89 | - if ( ! empty( $args['exclude'] ) ) { |
|
90 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
89 | + if (!empty($args['exclude'])) { |
|
90 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
91 | 91 | } |
92 | 92 | |
93 | - if ( ! $args['paginate'] ) { |
|
93 | + if (!$args['paginate']) { |
|
94 | 94 | $wp_query_args['no_found_rows'] = true; |
95 | 95 | } |
96 | 96 | |
97 | - if ( ! empty( $args['search'] ) ) { |
|
97 | + if (!empty($args['search'])) { |
|
98 | 98 | $wp_query_args['s'] = $args['search']; |
99 | 99 | } |
100 | 100 | |
101 | - if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) { |
|
102 | - $types = wpinv_parse_list( $args['type'] ); |
|
101 | + if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) { |
|
102 | + $types = wpinv_parse_list($args['type']); |
|
103 | 103 | $wp_query_args['meta_query'][] = array( |
104 | 104 | 'key' => '_wpinv_type', |
105 | - 'value' => implode( ',', $types ), |
|
105 | + 'value' => implode(',', $types), |
|
106 | 106 | 'compare' => 'IN', |
107 | 107 | ); |
108 | 108 | } |
109 | 109 | |
110 | - $wp_query_args = apply_filters( 'wpinv_get_items_args', $wp_query_args, $args ); |
|
110 | + $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args); |
|
111 | 111 | |
112 | 112 | // Get results. |
113 | - $items = new WP_Query( $wp_query_args ); |
|
113 | + $items = new WP_Query($wp_query_args); |
|
114 | 114 | |
115 | - if ( 'objects' === $args['return'] ) { |
|
116 | - $return = array_map( 'wpinv_get_item_by_id', $items->posts ); |
|
117 | - } elseif ( 'self' === $args['return'] ) { |
|
115 | + if ('objects' === $args['return']) { |
|
116 | + $return = array_map('wpinv_get_item_by_id', $items->posts); |
|
117 | + } elseif ('self' === $args['return']) { |
|
118 | 118 | return $items; |
119 | 119 | } else { |
120 | 120 | $return = $items->posts; |
121 | 121 | } |
122 | 122 | |
123 | - if ( $args['paginate'] ) { |
|
123 | + if ($args['paginate']) { |
|
124 | 124 | return (object) array( |
125 | 125 | 'items' => $return, |
126 | 126 | 'total' => $items->found_posts, |
@@ -132,12 +132,12 @@ discard block |
||
132 | 132 | |
133 | 133 | } |
134 | 134 | |
135 | -function wpinv_is_free_item( $item_id = 0 ) { |
|
136 | - if ( empty( $item_id ) ) { |
|
135 | +function wpinv_is_free_item($item_id = 0) { |
|
136 | + if (empty($item_id)) { |
|
137 | 137 | return false; |
138 | 138 | } |
139 | 139 | |
140 | - $item = new WPInv_Item( $item_id ); |
|
140 | + $item = new WPInv_Item($item_id); |
|
141 | 141 | |
142 | 142 | return $item->is_free(); |
143 | 143 | } |
@@ -147,21 +147,21 @@ discard block |
||
147 | 147 | * |
148 | 148 | * @param WP_Post|WPInv_Item|Int $item The item to check for. |
149 | 149 | */ |
150 | -function wpinv_item_is_editable( $item = 0 ) { |
|
150 | +function wpinv_item_is_editable($item = 0) { |
|
151 | 151 | |
152 | 152 | // Fetch the item. |
153 | - $item = new WPInv_Item( $item ); |
|
153 | + $item = new WPInv_Item($item); |
|
154 | 154 | |
155 | 155 | // Check if it is editable. |
156 | 156 | return $item->is_editable(); |
157 | 157 | } |
158 | 158 | |
159 | -function wpinv_get_item_price( $item_id = 0 ) { |
|
160 | - if ( empty( $item_id ) ) { |
|
159 | +function wpinv_get_item_price($item_id = 0) { |
|
160 | + if (empty($item_id)) { |
|
161 | 161 | return false; |
162 | 162 | } |
163 | 163 | |
164 | - $item = new WPInv_Item( $item_id ); |
|
164 | + $item = new WPInv_Item($item_id); |
|
165 | 165 | |
166 | 166 | return $item->get_price(); |
167 | 167 | } |
@@ -171,89 +171,89 @@ discard block |
||
171 | 171 | * |
172 | 172 | * @param WPInv_Item|int $item |
173 | 173 | */ |
174 | -function wpinv_is_recurring_item( $item = 0 ) { |
|
175 | - $item = new WPInv_Item( $item ); |
|
174 | +function wpinv_is_recurring_item($item = 0) { |
|
175 | + $item = new WPInv_Item($item); |
|
176 | 176 | return $item->is_recurring(); |
177 | 177 | } |
178 | 178 | |
179 | -function wpinv_item_price( $item_id = 0 ) { |
|
180 | - if ( empty( $item_id ) ) { |
|
179 | +function wpinv_item_price($item_id = 0) { |
|
180 | + if (empty($item_id)) { |
|
181 | 181 | return false; |
182 | 182 | } |
183 | 183 | |
184 | - $price = wpinv_get_item_price( $item_id ); |
|
185 | - $price = wpinv_price( $price ); |
|
184 | + $price = wpinv_get_item_price($item_id); |
|
185 | + $price = wpinv_price($price); |
|
186 | 186 | |
187 | - return apply_filters( 'wpinv_item_price', $price, $item_id ); |
|
187 | + return apply_filters('wpinv_item_price', $price, $item_id); |
|
188 | 188 | } |
189 | 189 | |
190 | -function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) { |
|
191 | - if ( is_null( $amount_override ) ) { |
|
192 | - $original_price = get_post_meta( $item_id, '_wpinv_price', true ); |
|
190 | +function wpinv_get_item_final_price($item_id = 0, $amount_override = null) { |
|
191 | + if (is_null($amount_override)) { |
|
192 | + $original_price = get_post_meta($item_id, '_wpinv_price', true); |
|
193 | 193 | } else { |
194 | 194 | $original_price = $amount_override; |
195 | 195 | } |
196 | 196 | |
197 | 197 | $price = $original_price; |
198 | 198 | |
199 | - return apply_filters( 'wpinv_get_item_final_price', $price, $item_id ); |
|
199 | + return apply_filters('wpinv_get_item_final_price', $price, $item_id); |
|
200 | 200 | } |
201 | 201 | |
202 | -function wpinv_item_custom_singular_name( $item_id ) { |
|
203 | - if ( empty( $item_id ) ) { |
|
202 | +function wpinv_item_custom_singular_name($item_id) { |
|
203 | + if (empty($item_id)) { |
|
204 | 204 | return false; |
205 | 205 | } |
206 | 206 | |
207 | - $item = new WPInv_Item( $item_id ); |
|
207 | + $item = new WPInv_Item($item_id); |
|
208 | 208 | |
209 | 209 | return $item->get_custom_singular_name(); |
210 | 210 | } |
211 | 211 | |
212 | 212 | function wpinv_get_item_types() { |
213 | 213 | $item_types = array( |
214 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
215 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
214 | + 'custom' => __('Standard', 'invoicing'), |
|
215 | + 'fee' => __('Fee', 'invoicing'), |
|
216 | 216 | ); |
217 | - return apply_filters( 'wpinv_get_item_types', $item_types ); |
|
217 | + return apply_filters('wpinv_get_item_types', $item_types); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | function wpinv_item_types() { |
221 | 221 | $item_types = wpinv_get_item_types(); |
222 | 222 | |
223 | - return ( ! empty( $item_types ) ? array_keys( $item_types ) : array() ); |
|
223 | + return (!empty($item_types) ? array_keys($item_types) : array()); |
|
224 | 224 | } |
225 | 225 | |
226 | -function wpinv_get_item_type( $item_id ) { |
|
227 | - if ( empty( $item_id ) ) { |
|
226 | +function wpinv_get_item_type($item_id) { |
|
227 | + if (empty($item_id)) { |
|
228 | 228 | return false; |
229 | 229 | } |
230 | 230 | |
231 | - $item = new WPInv_Item( $item_id ); |
|
231 | + $item = new WPInv_Item($item_id); |
|
232 | 232 | |
233 | 233 | return $item->get_type(); |
234 | 234 | } |
235 | 235 | |
236 | -function wpinv_item_type( $item_id ) { |
|
236 | +function wpinv_item_type($item_id) { |
|
237 | 237 | $item_types = wpinv_get_item_types(); |
238 | 238 | |
239 | - $item_type = wpinv_get_item_type( $item_id ); |
|
239 | + $item_type = wpinv_get_item_type($item_id); |
|
240 | 240 | |
241 | - if ( empty( $item_type ) ) { |
|
241 | + if (empty($item_type)) { |
|
242 | 242 | $item_type = '-'; |
243 | 243 | } |
244 | 244 | |
245 | - $item_type = isset( $item_types[ $item_type ] ) ? $item_types[ $item_type ] : __( $item_type, 'invoicing' ); |
|
245 | + $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing'); |
|
246 | 246 | |
247 | - return apply_filters( 'wpinv_item_type', $item_type, $item_id ); |
|
247 | + return apply_filters('wpinv_item_type', $item_type, $item_id); |
|
248 | 248 | } |
249 | 249 | |
250 | -function wpinv_get_random_item( $post_ids = true ) { |
|
251 | - wpinv_get_random_items( 1, $post_ids ); |
|
250 | +function wpinv_get_random_item($post_ids = true) { |
|
251 | + wpinv_get_random_items(1, $post_ids); |
|
252 | 252 | } |
253 | 253 | |
254 | -function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
|
254 | +function wpinv_get_random_items($num = 3, $post_ids = true) { |
|
255 | 255 | $args = array(); |
256 | - if ( $post_ids ) { |
|
256 | + if ($post_ids) { |
|
257 | 257 | $args = array( |
258 | 258 | 'fields' => 'ids', |
259 | 259 | ); |
@@ -274,9 +274,9 @@ discard block |
||
274 | 274 | ) |
275 | 275 | ); |
276 | 276 | |
277 | - $args = apply_filters( 'wpinv_get_random_items', $args ); |
|
277 | + $args = apply_filters('wpinv_get_random_items', $args); |
|
278 | 278 | |
279 | - return get_posts( $args ); |
|
279 | + return get_posts($args); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | /** |
@@ -285,13 +285,13 @@ discard block |
||
285 | 285 | * @param WPInv_Item|int $item |
286 | 286 | * @param bool $html |
287 | 287 | */ |
288 | -function wpinv_get_item_suffix( $item, $html = true ) { |
|
288 | +function wpinv_get_item_suffix($item, $html = true) { |
|
289 | 289 | |
290 | - $item = new WPInv_Item( $item ); |
|
291 | - $suffix = $item->is_recurring() ? ' ' . __( '(r)', 'invoicing' ) : ''; |
|
292 | - $suffix = $html ? $suffix : wp_strip_all_tags( $suffix ); |
|
290 | + $item = new WPInv_Item($item); |
|
291 | + $suffix = $item->is_recurring() ? ' ' . __('(r)', 'invoicing') : ''; |
|
292 | + $suffix = $html ? $suffix : wp_strip_all_tags($suffix); |
|
293 | 293 | |
294 | - return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html ); |
|
294 | + return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -300,9 +300,9 @@ discard block |
||
300 | 300 | * @param WPInv_Item|int $item |
301 | 301 | * @param bool $force_delete |
302 | 302 | */ |
303 | -function wpinv_remove_item( $item = 0, $force_delete = false ) { |
|
304 | - $item = new WPInv_Item( $item ); |
|
305 | - $item->delete( $force_delete ); |
|
303 | +function wpinv_remove_item($item = 0, $force_delete = false) { |
|
304 | + $item = new WPInv_Item($item); |
|
305 | + $item->delete($force_delete); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
@@ -341,44 +341,44 @@ discard block |
||
341 | 341 | * @param bool $wp_error whether or not to return a WP_Error on failure. |
342 | 342 | * @return bool|WP_Error|WPInv_Item |
343 | 343 | */ |
344 | -function wpinv_create_item( $args = array(), $wp_error = false ) { |
|
344 | +function wpinv_create_item($args = array(), $wp_error = false) { |
|
345 | 345 | |
346 | 346 | // Prepare the item. |
347 | - if ( ! empty( $args['custom_id'] ) && empty( $args['ID'] ) ) { |
|
348 | - $type = empty( $args['type'] ) ? 'custom' : $args['type']; |
|
349 | - $item = wpinv_get_item_by( 'custom_id', $args['custom_id'], $type ); |
|
347 | + if (!empty($args['custom_id']) && empty($args['ID'])) { |
|
348 | + $type = empty($args['type']) ? 'custom' : $args['type']; |
|
349 | + $item = wpinv_get_item_by('custom_id', $args['custom_id'], $type); |
|
350 | 350 | |
351 | - if ( ! empty( $item ) ) { |
|
351 | + if (!empty($item)) { |
|
352 | 352 | $args['ID'] = $item->get_id(); |
353 | 353 | } |
354 | 354 | } |
355 | 355 | |
356 | 356 | // Do we have an item? |
357 | - if ( ! empty( $args['ID'] ) ) { |
|
358 | - $item = new WPInv_Item( $args['ID'] ); |
|
357 | + if (!empty($args['ID'])) { |
|
358 | + $item = new WPInv_Item($args['ID']); |
|
359 | 359 | } else { |
360 | 360 | $item = new WPInv_Item(); |
361 | 361 | } |
362 | 362 | |
363 | 363 | // Do we have an error? |
364 | - if ( ! empty( $item->last_error ) ) { |
|
365 | - return $wp_error ? new WP_Error( 'invalid_item', $item->last_error ) : false; |
|
364 | + if (!empty($item->last_error)) { |
|
365 | + return $wp_error ? new WP_Error('invalid_item', $item->last_error) : false; |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | // Update item props. |
369 | - $item->set_props( $args ); |
|
369 | + $item->set_props($args); |
|
370 | 370 | |
371 | 371 | // Save the item. |
372 | 372 | $item->save(); |
373 | 373 | |
374 | 374 | // Do we have an error? |
375 | - if ( ! empty( $item->last_error ) ) { |
|
376 | - return $wp_error ? new WP_Error( 'not_saved', $item->last_error ) : false; |
|
375 | + if (!empty($item->last_error)) { |
|
376 | + return $wp_error ? new WP_Error('not_saved', $item->last_error) : false; |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | // Was the item saved? |
380 | - if ( ! $item->get_id() ) { |
|
381 | - return $wp_error ? new WP_Error( 'not_saved', __( 'An error occured while saving the item', 'invoicing' ) ) : false; |
|
380 | + if (!$item->get_id()) { |
|
381 | + return $wp_error ? new WP_Error('not_saved', __('An error occured while saving the item', 'invoicing')) : false; |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | return $item; |
@@ -390,14 +390,14 @@ discard block |
||
390 | 390 | * |
391 | 391 | * @see wpinv_create_item() |
392 | 392 | */ |
393 | -function wpinv_update_item( $args = array(), $wp_error = false ) { |
|
394 | - return wpinv_create_item( $args, $wp_error ); |
|
393 | +function wpinv_update_item($args = array(), $wp_error = false) { |
|
394 | + return wpinv_create_item($args, $wp_error); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | /** |
398 | 398 | * Sanitizes a recurring period |
399 | 399 | */ |
400 | -function getpaid_sanitize_recurring_period( $period, $full = false ) { |
|
400 | +function getpaid_sanitize_recurring_period($period, $full = false) { |
|
401 | 401 | |
402 | 402 | $periods = array( |
403 | 403 | 'D' => 'day', |
@@ -406,16 +406,16 @@ discard block |
||
406 | 406 | 'Y' => 'year', |
407 | 407 | ); |
408 | 408 | |
409 | - if ( ! isset( $periods[ $period ] ) ) { |
|
409 | + if (!isset($periods[$period])) { |
|
410 | 410 | $period = 'D'; |
411 | 411 | } |
412 | 412 | |
413 | - return $full ? $periods[ $period ] : $period; |
|
413 | + return $full ? $periods[$period] : $period; |
|
414 | 414 | |
415 | 415 | } |
416 | 416 | |
417 | -function wpinv_item_max_buyable_quantity( $item_id ) { |
|
418 | - return apply_filters( 'wpinv_item_max_buyable_quantity', 5, $item_id ); |
|
417 | +function wpinv_item_max_buyable_quantity($item_id) { |
|
418 | + return apply_filters('wpinv_item_max_buyable_quantity', 5, $item_id); |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | /** |
@@ -423,47 +423,47 @@ discard block |
||
423 | 423 | * |
424 | 424 | * @param WPInv_Item|GetPaid_Form_Item $item |
425 | 425 | */ |
426 | -function getpaid_item_recurring_price_help_text( $item, $currency = '', $_initial_price = false, $_recurring_price = false ) { |
|
426 | +function getpaid_item_recurring_price_help_text($item, $currency = '', $_initial_price = false, $_recurring_price = false) { |
|
427 | 427 | |
428 | 428 | // Abort if it is not recurring. |
429 | - if ( ! $item->is_recurring() ) { |
|
429 | + if (!$item->is_recurring()) { |
|
430 | 430 | return ''; |
431 | 431 | } |
432 | 432 | |
433 | - $initial_price = false === $_initial_price ? wpinv_price( $item->get_initial_price(), $currency ) : $_initial_price; |
|
434 | - $recurring_price = false === $_recurring_price ? wpinv_price( $item->get_recurring_price(), $currency ) : $_recurring_price; |
|
435 | - $period = getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ); |
|
433 | + $initial_price = false === $_initial_price ? wpinv_price($item->get_initial_price(), $currency) : $_initial_price; |
|
434 | + $recurring_price = false === $_recurring_price ? wpinv_price($item->get_recurring_price(), $currency) : $_recurring_price; |
|
435 | + $period = getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), ''); |
|
436 | 436 | $initial_class = 'getpaid-item-initial-price'; |
437 | 437 | $recurring_class = 'getpaid-item-recurring-price'; |
438 | 438 | $bill_times = $item->get_recurring_limit(); |
439 | 439 | $bill_times_less = $bill_times - 1; |
440 | 440 | |
441 | - if ( ! empty( $bill_times ) ) { |
|
441 | + if (!empty($bill_times)) { |
|
442 | 442 | $bill_times = $item->get_recurring_interval() * $bill_times; |
443 | - $bill_times_less = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times - $item->get_recurring_interval() ); |
|
444 | - $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
443 | + $bill_times_less = getpaid_get_subscription_period_label($item->get_recurring_period(), $bill_times - $item->get_recurring_interval()); |
|
444 | + $bill_times = getpaid_get_subscription_period_label($item->get_recurring_period(), $bill_times); |
|
445 | 445 | } |
446 | 446 | |
447 | - if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) { |
|
448 | - $initial_price = wpinv_price( $item->get_sub_total(), $currency ); |
|
449 | - $recurring_price = wpinv_price( $item->get_recurring_sub_total(), $currency ); |
|
447 | + if ($item instanceof GetPaid_Form_Item && false === $_initial_price) { |
|
448 | + $initial_price = wpinv_price($item->get_sub_total(), $currency); |
|
449 | + $recurring_price = wpinv_price($item->get_recurring_sub_total(), $currency); |
|
450 | 450 | } |
451 | 451 | |
452 | - if ( wpinv_price( 0, $currency ) == $initial_price && wpinv_price( 0, $currency ) == $recurring_price ) { |
|
453 | - return __( 'Free forever', 'invoicing' ); |
|
452 | + if (wpinv_price(0, $currency) == $initial_price && wpinv_price(0, $currency) == $recurring_price) { |
|
453 | + return __('Free forever', 'invoicing'); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | // For free trial items. |
457 | - if ( $item->has_free_trial() ) { |
|
458 | - $trial_period = getpaid_get_subscription_period_label( $item->get_trial_period(), $item->get_trial_interval() ); |
|
457 | + if ($item->has_free_trial()) { |
|
458 | + $trial_period = getpaid_get_subscription_period_label($item->get_trial_period(), $item->get_trial_interval()); |
|
459 | 459 | |
460 | - if ( wpinv_price( 0, $currency ) == $initial_price ) { |
|
460 | + if (wpinv_price(0, $currency) == $initial_price) { |
|
461 | 461 | |
462 | - if ( empty( $bill_times ) ) { |
|
462 | + if (empty($bill_times)) { |
|
463 | 463 | |
464 | 464 | return sprintf( |
465 | 465 | // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period |
466 | - _x( 'Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing' ), |
|
466 | + _x('Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing'), |
|
467 | 467 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
468 | 468 | "<span class='$recurring_class'>$recurring_price</span>", |
469 | 469 | "<span class='getpaid-item-recurring-period'>$period</span>" |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | |
474 | 474 | return sprintf( |
475 | 475 | // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period, $4: is the bill times |
476 | - _x( 'Free for %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year for 4 years)', 'invoicing' ), |
|
476 | + _x('Free for %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year for 4 years)', 'invoicing'), |
|
477 | 477 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
478 | 478 | "<span class='$recurring_class'>$recurring_price</span>", |
479 | 479 | "<span class='getpaid-item-recurring-period'>$period</span>", |
@@ -482,11 +482,11 @@ discard block |
||
482 | 482 | |
483 | 483 | } |
484 | 484 | |
485 | - if ( empty( $bill_times ) ) { |
|
485 | + if (empty($bill_times)) { |
|
486 | 486 | |
487 | 487 | return sprintf( |
488 | 488 | // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period |
489 | - _x( '%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing' ), |
|
489 | + _x('%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing'), |
|
490 | 490 | "<span class='$initial_class'>$initial_price</span>", |
491 | 491 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
492 | 492 | "<span class='$recurring_class'>$recurring_price</span>", |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | |
498 | 498 | return sprintf( |
499 | 499 | // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period, $4: is the susbcription bill times |
500 | - _x( '%1$s for %2$s then %3$s / %4$s for %5$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year for 5 years)', 'invoicing' ), |
|
500 | + _x('%1$s for %2$s then %3$s / %4$s for %5$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year for 5 years)', 'invoicing'), |
|
501 | 501 | "<span class='$initial_class'>$initial_price</span>", |
502 | 502 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
503 | 503 | "<span class='$recurring_class'>$recurring_price</span>", |
@@ -507,13 +507,13 @@ discard block |
||
507 | 507 | |
508 | 508 | } |
509 | 509 | |
510 | - if ( $initial_price == $recurring_price ) { |
|
510 | + if ($initial_price == $recurring_price) { |
|
511 | 511 | |
512 | - if ( empty( $bill_times ) ) { |
|
512 | + if (empty($bill_times)) { |
|
513 | 513 | |
514 | 514 | return sprintf( |
515 | 515 | // translators: $1: is the recurring price, $2: is the susbcription period |
516 | - _x( '%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
516 | + _x('%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing'), |
|
517 | 517 | "<span class='$recurring_class'>$recurring_price</span>", |
518 | 518 | "<span class='getpaid-item-recurring-period'>$period</span>" |
519 | 519 | ); |
@@ -522,7 +522,7 @@ discard block |
||
522 | 522 | |
523 | 523 | return sprintf( |
524 | 524 | // translators: $1: is the recurring price, $2: is the susbcription period, $3: is the susbcription bill times |
525 | - _x( '%1$s / %2$s for %3$s', 'Item subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
|
525 | + _x('%1$s / %2$s for %3$s', 'Item subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing'), |
|
526 | 526 | "<span class='$recurring_class'>$recurring_price</span>", |
527 | 527 | "<span class='getpaid-item-recurring-period'>$period</span>", |
528 | 528 | "<span class='getpaid-item-recurring-bill-times'>$bill_times</span>" |
@@ -530,13 +530,13 @@ discard block |
||
530 | 530 | |
531 | 531 | } |
532 | 532 | |
533 | - if ( $initial_price == wpinv_price( 0, $currency ) ) { |
|
533 | + if ($initial_price == wpinv_price(0, $currency)) { |
|
534 | 534 | |
535 | - if ( empty( $bill_times ) ) { |
|
535 | + if (empty($bill_times)) { |
|
536 | 536 | |
537 | 537 | return sprintf( |
538 | 538 | // translators: $1: is the recurring period, $2: is the recurring price |
539 | - _x( 'Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing' ), |
|
539 | + _x('Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing'), |
|
540 | 540 | "<span class='getpaid-item-recurring-period'>$period</span>", |
541 | 541 | "<span class='$recurring_class'>$recurring_price</span>" |
542 | 542 | ); |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | |
546 | 546 | return sprintf( |
547 | 547 | // translators: $1: is the recurring period, $2: is the recurring price, $3: is the bill times |
548 | - _x( 'Free for %1$s then %2$s / %1$s for %3$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months for 12 months)', 'invoicing' ), |
|
548 | + _x('Free for %1$s then %2$s / %1$s for %3$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months for 12 months)', 'invoicing'), |
|
549 | 549 | "<span class='getpaid-item-recurring-period'>$period</span>", |
550 | 550 | "<span class='$recurring_class'>$recurring_price</span>", |
551 | 551 | "<span class='getpaid-item-recurring-bill-times'>$bill_times_less</span>" |
@@ -553,11 +553,11 @@ discard block |
||
553 | 553 | |
554 | 554 | } |
555 | 555 | |
556 | - if ( empty( $bill_times ) ) { |
|
556 | + if (empty($bill_times)) { |
|
557 | 557 | |
558 | 558 | return sprintf( |
559 | 559 | // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period |
560 | - _x( 'Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing' ), |
|
560 | + _x('Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing'), |
|
561 | 561 | "<span class='$initial_class'>$initial_price</span>", |
562 | 562 | "<span class='$recurring_class'>$recurring_price</span>", |
563 | 563 | "<span class='getpaid-item-recurring-period'>$period</span>" |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | |
568 | 568 | return sprintf( |
569 | 569 | // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period, $4: is the susbcription bill times |
570 | - _x( 'Initial payment of %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year for 4 years)', 'invoicing' ), |
|
570 | + _x('Initial payment of %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year for 4 years)', 'invoicing'), |
|
571 | 571 | "<span class='$initial_class'>$initial_price</span>", |
572 | 572 | "<span class='$recurring_class'>$recurring_price</span>", |
573 | 573 | "<span class='getpaid-item-recurring-period'>$period</span>", |