@@ -71,11 +71,11 @@ discard block |
||
71 | 71 | */ |
72 | 72 | function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) { |
73 | 73 | |
74 | - if ( current_user_can( 'manage_options' ) ) { |
|
75 | - return 'manage_options'; |
|
76 | - }; |
|
74 | + if ( current_user_can( 'manage_options' ) ) { |
|
75 | + return 'manage_options'; |
|
76 | + }; |
|
77 | 77 | |
78 | - return $capalibilty; |
|
78 | + return $capalibilty; |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | * @return bool Whether the current user has the given capability. |
99 | 99 | */ |
100 | 100 | function wpinv_current_user_can( $capability, $args = array() ) { |
101 | - $can = wpinv_current_user_can_manage_invoicing(); |
|
101 | + $can = wpinv_current_user_can_manage_invoicing(); |
|
102 | 102 | |
103 | - return apply_filters( 'getpaid_current_user_can', $can, $capability, $args ); |
|
103 | + return apply_filters( 'getpaid_current_user_can', $can, $capability, $args ); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -114,10 +114,10 @@ discard block |
||
114 | 114 | // Prepare user values. |
115 | 115 | $prefix = preg_replace( '/\s+/', '', $prefix ); |
116 | 116 | $prefix = empty( $prefix ) ? $email : $prefix; |
117 | - $args = array( |
|
118 | - 'user_login' => wpinv_generate_user_name( $prefix ), |
|
119 | - 'user_pass' => wp_generate_password(), |
|
120 | - 'user_email' => $email, |
|
117 | + $args = array( |
|
118 | + 'user_login' => wpinv_generate_user_name( $prefix ), |
|
119 | + 'user_pass' => wp_generate_password(), |
|
120 | + 'user_email' => $email, |
|
121 | 121 | 'role' => 'subscriber', |
122 | 122 | ); |
123 | 123 | |
@@ -134,16 +134,16 @@ discard block |
||
134 | 134 | function wpinv_generate_user_name( $prefix = '' ) { |
135 | 135 | |
136 | 136 | // If prefix is an email, retrieve the part before the email. |
137 | - $prefix = strtok( $prefix, '@' ); |
|
137 | + $prefix = strtok( $prefix, '@' ); |
|
138 | 138 | $prefix = trim( $prefix, '.' ); |
139 | 139 | |
140 | - // Sanitize the username. |
|
141 | - $prefix = sanitize_user( $prefix, true ); |
|
140 | + // Sanitize the username. |
|
141 | + $prefix = sanitize_user( $prefix, true ); |
|
142 | 142 | |
143 | - $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
144 | - if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
145 | - $prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
146 | - } |
|
143 | + $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
144 | + if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
145 | + $prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
146 | + } |
|
147 | 147 | |
148 | 148 | $username = $prefix; |
149 | 149 | $postfix = 2; |
@@ -282,43 +282,43 @@ discard block |
||
282 | 282 | |
283 | 283 | $value = $customer->get( $key ); |
284 | 284 | |
285 | - // Display the country. |
|
286 | - if ( 'country' == $key ) { |
|
287 | - |
|
288 | - aui()->select( |
|
289 | - array( |
|
290 | - 'options' => wpinv_get_country_list(), |
|
291 | - 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
|
292 | - 'id' => 'wpinv-' . sanitize_html_class( $key ), |
|
293 | - 'value' => sanitize_text_field( $value ), |
|
294 | - 'placeholder' => $label, |
|
295 | - 'label' => wp_kses_post( $label ), |
|
296 | - 'label_type' => 'vertical', |
|
297 | - 'class' => 'getpaid-address-field', |
|
285 | + // Display the country. |
|
286 | + if ( 'country' == $key ) { |
|
287 | + |
|
288 | + aui()->select( |
|
289 | + array( |
|
290 | + 'options' => wpinv_get_country_list(), |
|
291 | + 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
|
292 | + 'id' => 'wpinv-' . sanitize_html_class( $key ), |
|
293 | + 'value' => sanitize_text_field( $value ), |
|
294 | + 'placeholder' => $label, |
|
295 | + 'label' => wp_kses_post( $label ), |
|
296 | + 'label_type' => 'vertical', |
|
297 | + 'class' => 'getpaid-address-field', |
|
298 | 298 | ), |
299 | 299 | true |
300 | - ); |
|
300 | + ); |
|
301 | 301 | |
302 | - } |
|
302 | + } |
|
303 | 303 | |
304 | - // Display the state. |
|
305 | - elseif ( 'state' == $key ) { |
|
304 | + // Display the state. |
|
305 | + elseif ( 'state' == $key ) { |
|
306 | 306 | |
307 | - getpaid_get_states_select_markup( |
|
307 | + getpaid_get_states_select_markup( |
|
308 | 308 | $customer->get( 'country' ), |
309 | - $value, |
|
310 | - $label, |
|
311 | - $label, |
|
312 | - '', |
|
313 | - false, |
|
314 | - '', |
|
315 | - 'getpaid_address[' . esc_attr( $key ) . ']', |
|
309 | + $value, |
|
310 | + $label, |
|
311 | + $label, |
|
312 | + '', |
|
313 | + false, |
|
314 | + '', |
|
315 | + 'getpaid_address[' . esc_attr( $key ) . ']', |
|
316 | 316 | true |
317 | - ); |
|
317 | + ); |
|
318 | 318 | |
319 | 319 | } else { |
320 | 320 | |
321 | - aui()->input( |
|
321 | + aui()->input( |
|
322 | 322 | array( |
323 | 323 | 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
324 | 324 | 'id' => 'wpinv-' . sanitize_html_class( $key ), |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | 'class' => 'getpaid-address-field', |
331 | 331 | ), |
332 | 332 | true |
333 | - ); |
|
333 | + ); |
|
334 | 334 | |
335 | 335 | } |
336 | 336 | } |
@@ -474,7 +474,7 @@ discard block |
||
474 | 474 | function getpaid_allowed_html() { |
475 | 475 | $allowed_html = wp_kses_allowed_html( 'post' ); |
476 | 476 | |
477 | - // form fields |
|
477 | + // form fields |
|
478 | 478 | $allowed_html['form'] = array( |
479 | 479 | 'action' => true, |
480 | 480 | 'accept' => true, |
@@ -486,12 +486,12 @@ discard block |
||
486 | 486 | ); |
487 | 487 | |
488 | 488 | // - input |
489 | - $allowed_html['input'] = array( |
|
490 | - 'class' => array(), |
|
491 | - 'id' => array(), |
|
492 | - 'name' => array(), |
|
493 | - 'value' => array(), |
|
494 | - 'type' => array(), |
|
489 | + $allowed_html['input'] = array( |
|
490 | + 'class' => array(), |
|
491 | + 'id' => array(), |
|
492 | + 'name' => array(), |
|
493 | + 'value' => array(), |
|
494 | + 'type' => array(), |
|
495 | 495 | 'placeholder' => array(), |
496 | 496 | 'autocomplete' => array(), |
497 | 497 | 'autofocus' => array(), |
@@ -505,33 +505,33 @@ discard block |
||
505 | 505 | 'max' => array(), |
506 | 506 | 'step' => array(), |
507 | 507 | 'size' => array(), |
508 | - ); |
|
508 | + ); |
|
509 | 509 | |
510 | 510 | // - input |
511 | - $allowed_html['textarea'] = array( |
|
512 | - 'class' => array(), |
|
513 | - 'id' => array(), |
|
514 | - 'name' => array(), |
|
515 | - 'value' => array(), |
|
516 | - ); |
|
517 | - |
|
518 | - // select |
|
519 | - $allowed_html['select'] = array( |
|
520 | - 'class' => array(), |
|
521 | - 'id' => array(), |
|
522 | - 'name' => array(), |
|
511 | + $allowed_html['textarea'] = array( |
|
512 | + 'class' => array(), |
|
513 | + 'id' => array(), |
|
514 | + 'name' => array(), |
|
515 | + 'value' => array(), |
|
516 | + ); |
|
517 | + |
|
518 | + // select |
|
519 | + $allowed_html['select'] = array( |
|
520 | + 'class' => array(), |
|
521 | + 'id' => array(), |
|
522 | + 'name' => array(), |
|
523 | 523 | 'autocomplete' => array(), |
524 | 524 | 'multiple' => array(), |
525 | - ); |
|
525 | + ); |
|
526 | 526 | |
527 | - // select options |
|
528 | - $allowed_html['option'] = array( |
|
529 | - 'selected' => array(), |
|
527 | + // select options |
|
528 | + $allowed_html['option'] = array( |
|
529 | + 'selected' => array(), |
|
530 | 530 | 'disabled' => array(), |
531 | 531 | 'value' => array(), |
532 | - ); |
|
532 | + ); |
|
533 | 533 | |
534 | - return $allowed_html; |
|
534 | + return $allowed_html; |
|
535 | 535 | |
536 | 536 | } |
537 | 537 |
@@ -5,110 +5,110 @@ discard block |
||
5 | 5 | */ |
6 | 6 | |
7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
8 | - exit; // Exit if accessed directly |
|
8 | + exit; // Exit if accessed directly |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | if ( ! class_exists( 'GetPaid_Admin_Profile', false ) ) : |
12 | 12 | |
13 | - /** |
|
14 | - * GetPaid_Admin_Profile Class. |
|
15 | - */ |
|
16 | - class GetPaid_Admin_Profile { |
|
17 | - |
|
18 | - /** |
|
19 | - * Hook in tabs. |
|
20 | - */ |
|
21 | - public function __construct() { |
|
22 | - add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
23 | - add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
24 | - |
|
25 | - add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) ); |
|
26 | - add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) ); |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Get Address Fields for the edit user pages. |
|
31 | - * |
|
32 | - * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned |
|
33 | - */ |
|
34 | - public function get_customer_meta_fields() { |
|
35 | - |
|
36 | - $show_fields = apply_filters( |
|
37 | - 'getpaid_customer_meta_fields', |
|
38 | - array( |
|
39 | - 'billing' => array( |
|
40 | - 'title' => __( 'Billing Details (GetPaid)', 'invoicing' ), |
|
41 | - 'fields' => array( |
|
42 | - '_wpinv_first_name' => array( |
|
43 | - 'label' => __( 'First name', 'invoicing' ), |
|
44 | - 'description' => '', |
|
45 | - ), |
|
46 | - '_wpinv_last_name' => array( |
|
47 | - 'label' => __( 'Last name', 'invoicing' ), |
|
48 | - 'description' => '', |
|
49 | - ), |
|
50 | - '_wpinv_company' => array( |
|
51 | - 'label' => __( 'Company', 'invoicing' ), |
|
52 | - 'description' => '', |
|
53 | - ), |
|
54 | - '_wpinv_company_id' => array( |
|
55 | - 'label' => __( 'Company ID', 'invoicing' ), |
|
56 | - 'description' => '', |
|
57 | - ), |
|
58 | - '_wpinv_address' => array( |
|
59 | - 'label' => __( 'Address', 'invoicing' ), |
|
60 | - 'description' => '', |
|
61 | - ), |
|
62 | - '_wpinv_city' => array( |
|
63 | - 'label' => __( 'City', 'invoicing' ), |
|
64 | - 'description' => '', |
|
65 | - ), |
|
66 | - '_wpinv_zip' => array( |
|
67 | - 'label' => __( 'Postcode / ZIP', 'invoicing' ), |
|
68 | - 'description' => '', |
|
69 | - ), |
|
70 | - '_wpinv_country' => array( |
|
71 | - 'label' => __( 'Country / Region', 'invoicing' ), |
|
72 | - 'description' => '', |
|
73 | - 'class' => 'getpaid_js_field-country', |
|
74 | - 'type' => 'select', |
|
75 | - 'options' => array( '' => __( 'Select a country / region…', 'invoicing' ) ) + wpinv_get_country_list(), |
|
76 | - ), |
|
77 | - '_wpinv_state' => array( |
|
78 | - 'label' => __( 'State / County', 'invoicing' ), |
|
79 | - 'description' => __( 'State / County or state code', 'invoicing' ), |
|
80 | - 'class' => 'getpaid_js_field-state regular-text', |
|
81 | - ), |
|
82 | - '_wpinv_phone' => array( |
|
83 | - 'label' => __( 'Phone', 'invoicing' ), |
|
84 | - 'description' => '', |
|
85 | - ), |
|
86 | - '_wpinv_vat_number' => array( |
|
87 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
88 | - 'description' => '', |
|
89 | - ), |
|
90 | - ), |
|
91 | - ), |
|
92 | - ) |
|
93 | - ); |
|
94 | - return $show_fields; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Show Address Fields on edit user pages. |
|
99 | - * |
|
100 | - * @param WP_User $user |
|
101 | - */ |
|
102 | - public function add_customer_meta_fields( $user ) { |
|
103 | - |
|
104 | - if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) { |
|
105 | - return; |
|
106 | - } |
|
107 | - |
|
108 | - $show_fields = $this->get_customer_meta_fields(); |
|
109 | - |
|
110 | - foreach ( $show_fields as $fieldset_key => $fieldset ) : |
|
111 | - ?> |
|
13 | + /** |
|
14 | + * GetPaid_Admin_Profile Class. |
|
15 | + */ |
|
16 | + class GetPaid_Admin_Profile { |
|
17 | + |
|
18 | + /** |
|
19 | + * Hook in tabs. |
|
20 | + */ |
|
21 | + public function __construct() { |
|
22 | + add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
23 | + add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
24 | + |
|
25 | + add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) ); |
|
26 | + add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) ); |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Get Address Fields for the edit user pages. |
|
31 | + * |
|
32 | + * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned |
|
33 | + */ |
|
34 | + public function get_customer_meta_fields() { |
|
35 | + |
|
36 | + $show_fields = apply_filters( |
|
37 | + 'getpaid_customer_meta_fields', |
|
38 | + array( |
|
39 | + 'billing' => array( |
|
40 | + 'title' => __( 'Billing Details (GetPaid)', 'invoicing' ), |
|
41 | + 'fields' => array( |
|
42 | + '_wpinv_first_name' => array( |
|
43 | + 'label' => __( 'First name', 'invoicing' ), |
|
44 | + 'description' => '', |
|
45 | + ), |
|
46 | + '_wpinv_last_name' => array( |
|
47 | + 'label' => __( 'Last name', 'invoicing' ), |
|
48 | + 'description' => '', |
|
49 | + ), |
|
50 | + '_wpinv_company' => array( |
|
51 | + 'label' => __( 'Company', 'invoicing' ), |
|
52 | + 'description' => '', |
|
53 | + ), |
|
54 | + '_wpinv_company_id' => array( |
|
55 | + 'label' => __( 'Company ID', 'invoicing' ), |
|
56 | + 'description' => '', |
|
57 | + ), |
|
58 | + '_wpinv_address' => array( |
|
59 | + 'label' => __( 'Address', 'invoicing' ), |
|
60 | + 'description' => '', |
|
61 | + ), |
|
62 | + '_wpinv_city' => array( |
|
63 | + 'label' => __( 'City', 'invoicing' ), |
|
64 | + 'description' => '', |
|
65 | + ), |
|
66 | + '_wpinv_zip' => array( |
|
67 | + 'label' => __( 'Postcode / ZIP', 'invoicing' ), |
|
68 | + 'description' => '', |
|
69 | + ), |
|
70 | + '_wpinv_country' => array( |
|
71 | + 'label' => __( 'Country / Region', 'invoicing' ), |
|
72 | + 'description' => '', |
|
73 | + 'class' => 'getpaid_js_field-country', |
|
74 | + 'type' => 'select', |
|
75 | + 'options' => array( '' => __( 'Select a country / region…', 'invoicing' ) ) + wpinv_get_country_list(), |
|
76 | + ), |
|
77 | + '_wpinv_state' => array( |
|
78 | + 'label' => __( 'State / County', 'invoicing' ), |
|
79 | + 'description' => __( 'State / County or state code', 'invoicing' ), |
|
80 | + 'class' => 'getpaid_js_field-state regular-text', |
|
81 | + ), |
|
82 | + '_wpinv_phone' => array( |
|
83 | + 'label' => __( 'Phone', 'invoicing' ), |
|
84 | + 'description' => '', |
|
85 | + ), |
|
86 | + '_wpinv_vat_number' => array( |
|
87 | + 'label' => __( 'VAT Number', 'invoicing' ), |
|
88 | + 'description' => '', |
|
89 | + ), |
|
90 | + ), |
|
91 | + ), |
|
92 | + ) |
|
93 | + ); |
|
94 | + return $show_fields; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Show Address Fields on edit user pages. |
|
99 | + * |
|
100 | + * @param WP_User $user |
|
101 | + */ |
|
102 | + public function add_customer_meta_fields( $user ) { |
|
103 | + |
|
104 | + if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) { |
|
105 | + return; |
|
106 | + } |
|
107 | + |
|
108 | + $show_fields = $this->get_customer_meta_fields(); |
|
109 | + |
|
110 | + foreach ( $show_fields as $fieldset_key => $fieldset ) : |
|
111 | + ?> |
|
112 | 112 | <h2><?php echo esc_html( $fieldset['title'] ); ?></h2> |
113 | 113 | <table class="form-table" id="<?php echo esc_attr( 'getpaid-fieldset-' . $fieldset_key ); ?>"> |
114 | 114 | <?php foreach ( $fieldset['fields'] as $key => $field ) : ?> |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | <?php if ( ! empty( $field['type'] ) && 'select' === $field['type'] ) : ?> |
121 | 121 | <select name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" class="<?php echo esc_attr( $field['class'] ); ?> wpi_select2" style="width: 25em;"> |
122 | 122 | <?php |
123 | - $selected = esc_attr( get_user_meta( $user->ID, $key, true ) ); |
|
124 | - foreach ( $field['options'] as $option_key => $option_value ) : |
|
125 | - ?> |
|
123 | + $selected = esc_attr( get_user_meta( $user->ID, $key, true ) ); |
|
124 | + foreach ( $field['options'] as $option_key => $option_value ) : |
|
125 | + ?> |
|
126 | 126 | <option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( $selected, $option_key, true ); ?>><?php echo esc_html( $option_value ); ?></option> |
127 | 127 | <?php endforeach; ?> |
128 | 128 | </select> |
@@ -137,59 +137,59 @@ discard block |
||
137 | 137 | <?php endforeach; ?> |
138 | 138 | </table> |
139 | 139 | <?php |
140 | - endforeach; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Save Address Fields on edit user pages. |
|
145 | - * |
|
146 | - * @param int $user_id User ID of the user being saved |
|
147 | - */ |
|
148 | - public function save_customer_meta_fields( $user_id ) { |
|
149 | - if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) { |
|
150 | - return; |
|
151 | - } |
|
152 | - |
|
153 | - $save_fields = $this->get_customer_meta_fields(); |
|
154 | - |
|
155 | - $customer = getpaid_get_customer_by_user_id( get_current_user_id() ); |
|
156 | - |
|
157 | - if ( empty( $customer ) ) { |
|
158 | - $customer = new GetPaid_Customer( 0 ); |
|
159 | - $customer->clone_user( get_current_user_id() ); |
|
160 | - } |
|
161 | - |
|
162 | - foreach ( $save_fields as $fieldset ) { |
|
163 | - |
|
164 | - foreach ( $fieldset['fields'] as $key => $field ) { |
|
165 | - |
|
166 | - if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) { |
|
167 | - $customer->set( $key, ! empty( $_POST[ $key ] ) ); |
|
168 | - } elseif ( isset( $_POST[ $key ] ) ) { |
|
169 | - $customer->set( $key, wpinv_clean( $_POST[ $key ] ) ); |
|
170 | - } |
|
171 | - } |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Get user meta for a given key, with fallbacks to core user info for pre-existing fields. |
|
177 | - * |
|
178 | - * @since 3.1.0 |
|
179 | - * @param int $user_id User ID of the user being edited |
|
180 | - * @param string $key Key for user meta field |
|
181 | - * @return string |
|
182 | - */ |
|
183 | - protected function get_user_meta( $user_id, $key ) { |
|
184 | - $value = get_user_meta( $user_id, $key, true ); |
|
185 | - $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' ); |
|
186 | - if ( ! $value && in_array( $key, $existing_fields ) ) { |
|
187 | - $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true ); |
|
188 | - } |
|
189 | - |
|
190 | - return $value; |
|
191 | - } |
|
192 | - } |
|
140 | + endforeach; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Save Address Fields on edit user pages. |
|
145 | + * |
|
146 | + * @param int $user_id User ID of the user being saved |
|
147 | + */ |
|
148 | + public function save_customer_meta_fields( $user_id ) { |
|
149 | + if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) { |
|
150 | + return; |
|
151 | + } |
|
152 | + |
|
153 | + $save_fields = $this->get_customer_meta_fields(); |
|
154 | + |
|
155 | + $customer = getpaid_get_customer_by_user_id( get_current_user_id() ); |
|
156 | + |
|
157 | + if ( empty( $customer ) ) { |
|
158 | + $customer = new GetPaid_Customer( 0 ); |
|
159 | + $customer->clone_user( get_current_user_id() ); |
|
160 | + } |
|
161 | + |
|
162 | + foreach ( $save_fields as $fieldset ) { |
|
163 | + |
|
164 | + foreach ( $fieldset['fields'] as $key => $field ) { |
|
165 | + |
|
166 | + if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) { |
|
167 | + $customer->set( $key, ! empty( $_POST[ $key ] ) ); |
|
168 | + } elseif ( isset( $_POST[ $key ] ) ) { |
|
169 | + $customer->set( $key, wpinv_clean( $_POST[ $key ] ) ); |
|
170 | + } |
|
171 | + } |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Get user meta for a given key, with fallbacks to core user info for pre-existing fields. |
|
177 | + * |
|
178 | + * @since 3.1.0 |
|
179 | + * @param int $user_id User ID of the user being edited |
|
180 | + * @param string $key Key for user meta field |
|
181 | + * @return string |
|
182 | + */ |
|
183 | + protected function get_user_meta( $user_id, $key ) { |
|
184 | + $value = get_user_meta( $user_id, $key, true ); |
|
185 | + $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' ); |
|
186 | + if ( ! $value && in_array( $key, $existing_fields ) ) { |
|
187 | + $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true ); |
|
188 | + } |
|
189 | + |
|
190 | + return $value; |
|
191 | + } |
|
192 | + } |
|
193 | 193 | |
194 | 194 | endif; |
195 | 195 |
@@ -20,402 +20,402 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class GetPaid_Installer { |
22 | 22 | |
23 | - /** |
|
24 | - * Upgrades the install. |
|
25 | - * |
|
26 | - * @param string $upgrade_from The current invoicing version. |
|
27 | - */ |
|
28 | - public function upgrade_db( $upgrade_from ) { |
|
29 | - |
|
30 | - // Save the current invoicing version. |
|
31 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
32 | - |
|
33 | - // Setup the invoice Custom Post Type. |
|
34 | - GetPaid_Post_Types::register_post_types(); |
|
35 | - |
|
36 | - // Clear the permalinks |
|
37 | - flush_rewrite_rules(); |
|
38 | - |
|
39 | - // Maybe create new/missing pages. |
|
40 | - $this->create_pages(); |
|
41 | - |
|
42 | - // Maybe re(add) admin capabilities. |
|
43 | - $this->add_capabilities(); |
|
44 | - |
|
45 | - // Maybe create the default payment form. |
|
46 | - wpinv_get_default_payment_form(); |
|
47 | - |
|
48 | - // Create any missing database tables. |
|
49 | - $method = "upgrade_from_$upgrade_from"; |
|
50 | - |
|
51 | - $installed = get_option( 'gepaid_installed_on' ); |
|
52 | - |
|
53 | - if ( empty( $installed ) ) { |
|
54 | - update_option( 'gepaid_installed_on', time() ); |
|
55 | - } |
|
56 | - |
|
57 | - if ( method_exists( $this, $method ) ) { |
|
58 | - $this->$method(); |
|
59 | - } |
|
60 | - |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Do a fresh install. |
|
65 | - * |
|
66 | - */ |
|
67 | - public function upgrade_from_0() { |
|
68 | - |
|
69 | - // Save default tax rates. |
|
70 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Upgrade to 0.0.5 |
|
75 | - * |
|
76 | - */ |
|
77 | - public function upgrade_from_004() { |
|
78 | - global $wpdb; |
|
79 | - |
|
80 | - // Invoices. |
|
81 | - $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
82 | - if ( ! empty( $results ) ) { |
|
83 | - $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
84 | - |
|
85 | - // Clean post cache |
|
86 | - foreach ( $results as $row ) { |
|
87 | - clean_post_cache( $row->ID ); |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - // Item meta key changes |
|
92 | - $query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
|
93 | - $results = $wpdb->get_results( $query ); |
|
94 | - |
|
95 | - if ( ! empty( $results ) ) { |
|
96 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
97 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
98 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
99 | - |
|
100 | - foreach ( $results as $row ) { |
|
101 | - clean_post_cache( $row->post_id ); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - $this->upgrade_from_118(); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Upgrade to version 2.0.0. |
|
110 | - * |
|
111 | - */ |
|
112 | - public function upgrade_from_118() { |
|
113 | - $this->migrate_old_invoices(); |
|
114 | - $this->upgrade_from_279(); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Upgrade to version 2.0.0. |
|
119 | - * |
|
120 | - */ |
|
121 | - public function upgrade_from_279() { |
|
122 | - $this->migrate_old_customers(); |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Give administrators the capability to manage GetPaid. |
|
127 | - * |
|
128 | - */ |
|
129 | - public function add_capabilities() { |
|
130 | - $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Retreives GetPaid pages. |
|
135 | - * |
|
136 | - */ |
|
137 | - public static function get_pages() { |
|
138 | - |
|
139 | - return apply_filters( |
|
140 | - 'wpinv_create_pages', |
|
141 | - array( |
|
142 | - |
|
143 | - // Checkout page. |
|
144 | - 'checkout_page' => array( |
|
145 | - 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
146 | - 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
147 | - 'content' => ' |
|
23 | + /** |
|
24 | + * Upgrades the install. |
|
25 | + * |
|
26 | + * @param string $upgrade_from The current invoicing version. |
|
27 | + */ |
|
28 | + public function upgrade_db( $upgrade_from ) { |
|
29 | + |
|
30 | + // Save the current invoicing version. |
|
31 | + update_option( 'wpinv_version', WPINV_VERSION ); |
|
32 | + |
|
33 | + // Setup the invoice Custom Post Type. |
|
34 | + GetPaid_Post_Types::register_post_types(); |
|
35 | + |
|
36 | + // Clear the permalinks |
|
37 | + flush_rewrite_rules(); |
|
38 | + |
|
39 | + // Maybe create new/missing pages. |
|
40 | + $this->create_pages(); |
|
41 | + |
|
42 | + // Maybe re(add) admin capabilities. |
|
43 | + $this->add_capabilities(); |
|
44 | + |
|
45 | + // Maybe create the default payment form. |
|
46 | + wpinv_get_default_payment_form(); |
|
47 | + |
|
48 | + // Create any missing database tables. |
|
49 | + $method = "upgrade_from_$upgrade_from"; |
|
50 | + |
|
51 | + $installed = get_option( 'gepaid_installed_on' ); |
|
52 | + |
|
53 | + if ( empty( $installed ) ) { |
|
54 | + update_option( 'gepaid_installed_on', time() ); |
|
55 | + } |
|
56 | + |
|
57 | + if ( method_exists( $this, $method ) ) { |
|
58 | + $this->$method(); |
|
59 | + } |
|
60 | + |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Do a fresh install. |
|
65 | + * |
|
66 | + */ |
|
67 | + public function upgrade_from_0() { |
|
68 | + |
|
69 | + // Save default tax rates. |
|
70 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Upgrade to 0.0.5 |
|
75 | + * |
|
76 | + */ |
|
77 | + public function upgrade_from_004() { |
|
78 | + global $wpdb; |
|
79 | + |
|
80 | + // Invoices. |
|
81 | + $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
82 | + if ( ! empty( $results ) ) { |
|
83 | + $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
84 | + |
|
85 | + // Clean post cache |
|
86 | + foreach ( $results as $row ) { |
|
87 | + clean_post_cache( $row->ID ); |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + // Item meta key changes |
|
92 | + $query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
|
93 | + $results = $wpdb->get_results( $query ); |
|
94 | + |
|
95 | + if ( ! empty( $results ) ) { |
|
96 | + $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
97 | + $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
98 | + $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
99 | + |
|
100 | + foreach ( $results as $row ) { |
|
101 | + clean_post_cache( $row->post_id ); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + $this->upgrade_from_118(); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Upgrade to version 2.0.0. |
|
110 | + * |
|
111 | + */ |
|
112 | + public function upgrade_from_118() { |
|
113 | + $this->migrate_old_invoices(); |
|
114 | + $this->upgrade_from_279(); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Upgrade to version 2.0.0. |
|
119 | + * |
|
120 | + */ |
|
121 | + public function upgrade_from_279() { |
|
122 | + $this->migrate_old_customers(); |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Give administrators the capability to manage GetPaid. |
|
127 | + * |
|
128 | + */ |
|
129 | + public function add_capabilities() { |
|
130 | + $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Retreives GetPaid pages. |
|
135 | + * |
|
136 | + */ |
|
137 | + public static function get_pages() { |
|
138 | + |
|
139 | + return apply_filters( |
|
140 | + 'wpinv_create_pages', |
|
141 | + array( |
|
142 | + |
|
143 | + // Checkout page. |
|
144 | + 'checkout_page' => array( |
|
145 | + 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
146 | + 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
147 | + 'content' => ' |
|
148 | 148 | <!-- wp:shortcode --> |
149 | 149 | [wpinv_checkout] |
150 | 150 | <!-- /wp:shortcode --> |
151 | 151 | ', |
152 | - 'parent' => '', |
|
153 | - ), |
|
154 | - |
|
155 | - // Invoice history page. |
|
156 | - 'invoice_history_page' => array( |
|
157 | - 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
158 | - 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
159 | - 'content' => ' |
|
152 | + 'parent' => '', |
|
153 | + ), |
|
154 | + |
|
155 | + // Invoice history page. |
|
156 | + 'invoice_history_page' => array( |
|
157 | + 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
158 | + 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
159 | + 'content' => ' |
|
160 | 160 | <!-- wp:shortcode --> |
161 | 161 | [wpinv_history] |
162 | 162 | <!-- /wp:shortcode --> |
163 | 163 | ', |
164 | - 'parent' => '', |
|
165 | - ), |
|
166 | - |
|
167 | - // Success page content. |
|
168 | - 'success_page' => array( |
|
169 | - 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
170 | - 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
171 | - 'content' => ' |
|
164 | + 'parent' => '', |
|
165 | + ), |
|
166 | + |
|
167 | + // Success page content. |
|
168 | + 'success_page' => array( |
|
169 | + 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
170 | + 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
171 | + 'content' => ' |
|
172 | 172 | <!-- wp:shortcode --> |
173 | 173 | [wpinv_receipt] |
174 | 174 | <!-- /wp:shortcode --> |
175 | 175 | ', |
176 | - 'parent' => 'gp-checkout', |
|
177 | - ), |
|
178 | - |
|
179 | - // Failure page content. |
|
180 | - 'failure_page' => array( |
|
181 | - 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
182 | - 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
183 | - 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
184 | - 'parent' => 'gp-checkout', |
|
185 | - ), |
|
186 | - |
|
187 | - // Subscriptions history page. |
|
188 | - 'invoice_subscription_page' => array( |
|
189 | - 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
190 | - 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
191 | - 'content' => ' |
|
176 | + 'parent' => 'gp-checkout', |
|
177 | + ), |
|
178 | + |
|
179 | + // Failure page content. |
|
180 | + 'failure_page' => array( |
|
181 | + 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
182 | + 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
183 | + 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
184 | + 'parent' => 'gp-checkout', |
|
185 | + ), |
|
186 | + |
|
187 | + // Subscriptions history page. |
|
188 | + 'invoice_subscription_page' => array( |
|
189 | + 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
190 | + 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
191 | + 'content' => ' |
|
192 | 192 | <!-- wp:shortcode --> |
193 | 193 | [wpinv_subscriptions] |
194 | 194 | <!-- /wp:shortcode --> |
195 | 195 | ', |
196 | - 'parent' => '', |
|
197 | - ), |
|
198 | - |
|
199 | - ) |
|
200 | - ); |
|
201 | - |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Re-create GetPaid pages. |
|
206 | - * |
|
207 | - */ |
|
208 | - public function create_pages() { |
|
209 | - |
|
210 | - foreach ( self::get_pages() as $key => $page ) { |
|
211 | - wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
212 | - } |
|
213 | - |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Migrates old invoices to new invoices. |
|
218 | - * |
|
219 | - */ |
|
220 | - public function migrate_old_invoices() { |
|
221 | - global $wpdb; |
|
222 | - |
|
223 | - $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
224 | - $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
225 | - $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
226 | - $invoices = array_unique( |
|
227 | - get_posts( |
|
228 | - array( |
|
229 | - 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
230 | - 'posts_per_page' => -1, |
|
231 | - 'fields' => 'ids', |
|
232 | - 'post_status' => array_keys( get_post_stati() ), |
|
233 | - 'exclude' => (array) $migrated, |
|
234 | - ) |
|
235 | - ) |
|
236 | - ); |
|
237 | - |
|
238 | - // Abort if we do not have any invoices. |
|
239 | - if ( empty( $invoices ) ) { |
|
240 | - return; |
|
241 | - } |
|
242 | - |
|
243 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'; |
|
244 | - |
|
245 | - $invoice_rows = array(); |
|
246 | - foreach ( $invoices as $invoice ) { |
|
247 | - |
|
248 | - $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
249 | - |
|
250 | - if ( empty( $invoice->ID ) ) { |
|
251 | - return; |
|
252 | - } |
|
253 | - |
|
254 | - $fields = array( |
|
255 | - 'post_id' => $invoice->ID, |
|
256 | - 'number' => $invoice->get_number(), |
|
257 | - 'key' => $invoice->get_key(), |
|
258 | - 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
259 | - 'mode' => $invoice->mode, |
|
260 | - 'user_ip' => $invoice->get_ip(), |
|
261 | - 'first_name' => $invoice->get_first_name(), |
|
262 | - 'last_name' => $invoice->get_last_name(), |
|
263 | - 'address' => $invoice->get_address(), |
|
264 | - 'city' => $invoice->city, |
|
265 | - 'state' => $invoice->state, |
|
266 | - 'country' => $invoice->country, |
|
267 | - 'zip' => $invoice->zip, |
|
268 | - 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
269 | - 'gateway' => $invoice->get_gateway(), |
|
270 | - 'transaction_id' => $invoice->get_transaction_id(), |
|
271 | - 'currency' => $invoice->get_currency(), |
|
272 | - 'subtotal' => $invoice->get_subtotal(), |
|
273 | - 'tax' => $invoice->get_tax(), |
|
274 | - 'fees_total' => $invoice->get_fees_total(), |
|
275 | - 'total' => $invoice->get_total(), |
|
276 | - 'discount' => $invoice->get_discount(), |
|
277 | - 'discount_code' => $invoice->get_discount_code(), |
|
278 | - 'disable_taxes' => $invoice->disable_taxes, |
|
279 | - 'due_date' => $invoice->get_due_date(), |
|
280 | - 'completed_date' => $invoice->get_completed_date(), |
|
281 | - 'company' => $invoice->company, |
|
282 | - 'vat_number' => $invoice->vat_number, |
|
283 | - 'vat_rate' => $invoice->vat_rate, |
|
284 | - 'custom_meta' => $invoice->payment_meta, |
|
285 | - ); |
|
286 | - |
|
287 | - foreach ( $fields as $key => $val ) { |
|
288 | - if ( is_null( $val ) ) { |
|
289 | - $val = ''; |
|
290 | - } |
|
291 | - $val = maybe_serialize( $val ); |
|
292 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
293 | - } |
|
294 | - |
|
295 | - $fields = implode( ', ', $fields ); |
|
296 | - $invoice_rows[] = "($fields)"; |
|
297 | - |
|
298 | - $item_rows = array(); |
|
299 | - $item_columns = array(); |
|
300 | - foreach ( $invoice->get_cart_details() as $details ) { |
|
301 | - $fields = array( |
|
302 | - 'post_id' => $invoice->ID, |
|
303 | - 'item_id' => $details['id'], |
|
304 | - 'item_name' => $details['name'], |
|
305 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
306 | - 'vat_rate' => $details['vat_rate'], |
|
307 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
308 | - 'tax' => $details['tax'], |
|
309 | - 'item_price' => $details['item_price'], |
|
310 | - 'custom_price' => $details['custom_price'], |
|
311 | - 'quantity' => $details['quantity'], |
|
312 | - 'discount' => $details['discount'], |
|
313 | - 'subtotal' => $details['subtotal'], |
|
314 | - 'price' => $details['price'], |
|
315 | - 'meta' => $details['meta'], |
|
316 | - 'fees' => $details['fees'], |
|
317 | - ); |
|
318 | - |
|
319 | - $item_columns = array_keys( $fields ); |
|
320 | - |
|
321 | - foreach ( $fields as $key => $val ) { |
|
322 | - if ( is_null( $val ) ) { |
|
323 | - $val = ''; |
|
324 | - } |
|
325 | - $val = maybe_serialize( $val ); |
|
326 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
327 | - } |
|
328 | - |
|
329 | - $fields = implode( ', ', $fields ); |
|
330 | - $item_rows[] = "($fields)"; |
|
331 | - } |
|
332 | - |
|
333 | - $item_rows = implode( ', ', $item_rows ); |
|
334 | - $item_columns = implode( ', ', $item_columns ); |
|
335 | - $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
336 | - } |
|
337 | - |
|
338 | - if ( empty( $invoice_rows ) ) { |
|
339 | - return; |
|
340 | - } |
|
341 | - |
|
342 | - $invoice_rows = implode( ', ', $invoice_rows ); |
|
343 | - $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
344 | - |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * Migrates old customers to new table. |
|
349 | - * |
|
350 | - */ |
|
351 | - public function migrate_old_customers() { |
|
352 | - global $wpdb; |
|
353 | - |
|
354 | - // Fetch post_id from $wpdb->prefix . 'getpaid_invoices' where customer_id = 0 or null. |
|
355 | - $invoice_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->prefix}getpaid_invoices WHERE customer_id = 0 OR customer_id IS NULL" ); |
|
356 | - |
|
357 | - foreach ( $invoice_ids as $invoice_id ) { |
|
358 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
359 | - |
|
360 | - if ( empty( $invoice ) ) { |
|
361 | - continue; |
|
362 | - } |
|
363 | - |
|
364 | - // Fetch customer from the user ID. |
|
365 | - $user_id = $invoice->get_user_id(); |
|
366 | - |
|
367 | - if ( empty( $user_id ) ) { |
|
368 | - continue; |
|
369 | - } |
|
370 | - |
|
371 | - $customer = getpaid_get_customer_by_user_id( $user_id ); |
|
372 | - |
|
373 | - // Create if not exists. |
|
374 | - if ( empty( $customer ) ) { |
|
375 | - $customer = new GetPaid_Customer( 0 ); |
|
376 | - $customer->clone_user( $user_id ); |
|
377 | - $customer->save(); |
|
378 | - } |
|
379 | - |
|
380 | - $invoice->set_customer_id( $customer->get_id() ); |
|
381 | - $invoice->save(); |
|
382 | - } |
|
383 | - |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * Migrates old invoices to new invoices. |
|
388 | - * |
|
389 | - */ |
|
390 | - public static function rename_gateways_label() { |
|
391 | - global $wpdb; |
|
392 | - |
|
393 | - foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
394 | - |
|
395 | - $wpdb->update( |
|
396 | - $wpdb->prefix . 'getpaid_invoices', |
|
397 | - array( 'gateway' => $gateway ), |
|
398 | - array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
399 | - '%s', |
|
400 | - '%s' |
|
401 | - ); |
|
402 | - |
|
403 | - } |
|
404 | - } |
|
405 | - |
|
406 | - /** |
|
407 | - * Returns the DB schema. |
|
408 | - * |
|
409 | - */ |
|
410 | - public static function get_db_schema() { |
|
411 | - global $wpdb; |
|
412 | - |
|
413 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
414 | - |
|
415 | - $charset_collate = $wpdb->get_charset_collate(); |
|
196 | + 'parent' => '', |
|
197 | + ), |
|
198 | + |
|
199 | + ) |
|
200 | + ); |
|
201 | + |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Re-create GetPaid pages. |
|
206 | + * |
|
207 | + */ |
|
208 | + public function create_pages() { |
|
209 | + |
|
210 | + foreach ( self::get_pages() as $key => $page ) { |
|
211 | + wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
212 | + } |
|
213 | + |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Migrates old invoices to new invoices. |
|
218 | + * |
|
219 | + */ |
|
220 | + public function migrate_old_invoices() { |
|
221 | + global $wpdb; |
|
222 | + |
|
223 | + $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
224 | + $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
225 | + $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
226 | + $invoices = array_unique( |
|
227 | + get_posts( |
|
228 | + array( |
|
229 | + 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
230 | + 'posts_per_page' => -1, |
|
231 | + 'fields' => 'ids', |
|
232 | + 'post_status' => array_keys( get_post_stati() ), |
|
233 | + 'exclude' => (array) $migrated, |
|
234 | + ) |
|
235 | + ) |
|
236 | + ); |
|
237 | + |
|
238 | + // Abort if we do not have any invoices. |
|
239 | + if ( empty( $invoices ) ) { |
|
240 | + return; |
|
241 | + } |
|
242 | + |
|
243 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'; |
|
244 | + |
|
245 | + $invoice_rows = array(); |
|
246 | + foreach ( $invoices as $invoice ) { |
|
247 | + |
|
248 | + $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
249 | + |
|
250 | + if ( empty( $invoice->ID ) ) { |
|
251 | + return; |
|
252 | + } |
|
253 | + |
|
254 | + $fields = array( |
|
255 | + 'post_id' => $invoice->ID, |
|
256 | + 'number' => $invoice->get_number(), |
|
257 | + 'key' => $invoice->get_key(), |
|
258 | + 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
259 | + 'mode' => $invoice->mode, |
|
260 | + 'user_ip' => $invoice->get_ip(), |
|
261 | + 'first_name' => $invoice->get_first_name(), |
|
262 | + 'last_name' => $invoice->get_last_name(), |
|
263 | + 'address' => $invoice->get_address(), |
|
264 | + 'city' => $invoice->city, |
|
265 | + 'state' => $invoice->state, |
|
266 | + 'country' => $invoice->country, |
|
267 | + 'zip' => $invoice->zip, |
|
268 | + 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
269 | + 'gateway' => $invoice->get_gateway(), |
|
270 | + 'transaction_id' => $invoice->get_transaction_id(), |
|
271 | + 'currency' => $invoice->get_currency(), |
|
272 | + 'subtotal' => $invoice->get_subtotal(), |
|
273 | + 'tax' => $invoice->get_tax(), |
|
274 | + 'fees_total' => $invoice->get_fees_total(), |
|
275 | + 'total' => $invoice->get_total(), |
|
276 | + 'discount' => $invoice->get_discount(), |
|
277 | + 'discount_code' => $invoice->get_discount_code(), |
|
278 | + 'disable_taxes' => $invoice->disable_taxes, |
|
279 | + 'due_date' => $invoice->get_due_date(), |
|
280 | + 'completed_date' => $invoice->get_completed_date(), |
|
281 | + 'company' => $invoice->company, |
|
282 | + 'vat_number' => $invoice->vat_number, |
|
283 | + 'vat_rate' => $invoice->vat_rate, |
|
284 | + 'custom_meta' => $invoice->payment_meta, |
|
285 | + ); |
|
286 | + |
|
287 | + foreach ( $fields as $key => $val ) { |
|
288 | + if ( is_null( $val ) ) { |
|
289 | + $val = ''; |
|
290 | + } |
|
291 | + $val = maybe_serialize( $val ); |
|
292 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
293 | + } |
|
294 | + |
|
295 | + $fields = implode( ', ', $fields ); |
|
296 | + $invoice_rows[] = "($fields)"; |
|
297 | + |
|
298 | + $item_rows = array(); |
|
299 | + $item_columns = array(); |
|
300 | + foreach ( $invoice->get_cart_details() as $details ) { |
|
301 | + $fields = array( |
|
302 | + 'post_id' => $invoice->ID, |
|
303 | + 'item_id' => $details['id'], |
|
304 | + 'item_name' => $details['name'], |
|
305 | + 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
306 | + 'vat_rate' => $details['vat_rate'], |
|
307 | + 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
308 | + 'tax' => $details['tax'], |
|
309 | + 'item_price' => $details['item_price'], |
|
310 | + 'custom_price' => $details['custom_price'], |
|
311 | + 'quantity' => $details['quantity'], |
|
312 | + 'discount' => $details['discount'], |
|
313 | + 'subtotal' => $details['subtotal'], |
|
314 | + 'price' => $details['price'], |
|
315 | + 'meta' => $details['meta'], |
|
316 | + 'fees' => $details['fees'], |
|
317 | + ); |
|
318 | + |
|
319 | + $item_columns = array_keys( $fields ); |
|
320 | + |
|
321 | + foreach ( $fields as $key => $val ) { |
|
322 | + if ( is_null( $val ) ) { |
|
323 | + $val = ''; |
|
324 | + } |
|
325 | + $val = maybe_serialize( $val ); |
|
326 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
327 | + } |
|
328 | + |
|
329 | + $fields = implode( ', ', $fields ); |
|
330 | + $item_rows[] = "($fields)"; |
|
331 | + } |
|
332 | + |
|
333 | + $item_rows = implode( ', ', $item_rows ); |
|
334 | + $item_columns = implode( ', ', $item_columns ); |
|
335 | + $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
336 | + } |
|
337 | + |
|
338 | + if ( empty( $invoice_rows ) ) { |
|
339 | + return; |
|
340 | + } |
|
341 | + |
|
342 | + $invoice_rows = implode( ', ', $invoice_rows ); |
|
343 | + $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
344 | + |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * Migrates old customers to new table. |
|
349 | + * |
|
350 | + */ |
|
351 | + public function migrate_old_customers() { |
|
352 | + global $wpdb; |
|
353 | + |
|
354 | + // Fetch post_id from $wpdb->prefix . 'getpaid_invoices' where customer_id = 0 or null. |
|
355 | + $invoice_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->prefix}getpaid_invoices WHERE customer_id = 0 OR customer_id IS NULL" ); |
|
356 | + |
|
357 | + foreach ( $invoice_ids as $invoice_id ) { |
|
358 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
359 | + |
|
360 | + if ( empty( $invoice ) ) { |
|
361 | + continue; |
|
362 | + } |
|
363 | + |
|
364 | + // Fetch customer from the user ID. |
|
365 | + $user_id = $invoice->get_user_id(); |
|
366 | + |
|
367 | + if ( empty( $user_id ) ) { |
|
368 | + continue; |
|
369 | + } |
|
370 | + |
|
371 | + $customer = getpaid_get_customer_by_user_id( $user_id ); |
|
372 | + |
|
373 | + // Create if not exists. |
|
374 | + if ( empty( $customer ) ) { |
|
375 | + $customer = new GetPaid_Customer( 0 ); |
|
376 | + $customer->clone_user( $user_id ); |
|
377 | + $customer->save(); |
|
378 | + } |
|
379 | + |
|
380 | + $invoice->set_customer_id( $customer->get_id() ); |
|
381 | + $invoice->save(); |
|
382 | + } |
|
383 | + |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * Migrates old invoices to new invoices. |
|
388 | + * |
|
389 | + */ |
|
390 | + public static function rename_gateways_label() { |
|
391 | + global $wpdb; |
|
392 | + |
|
393 | + foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
394 | + |
|
395 | + $wpdb->update( |
|
396 | + $wpdb->prefix . 'getpaid_invoices', |
|
397 | + array( 'gateway' => $gateway ), |
|
398 | + array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
399 | + '%s', |
|
400 | + '%s' |
|
401 | + ); |
|
402 | + |
|
403 | + } |
|
404 | + } |
|
405 | + |
|
406 | + /** |
|
407 | + * Returns the DB schema. |
|
408 | + * |
|
409 | + */ |
|
410 | + public static function get_db_schema() { |
|
411 | + global $wpdb; |
|
412 | + |
|
413 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
414 | + |
|
415 | + $charset_collate = $wpdb->get_charset_collate(); |
|
416 | 416 | |
417 | - // Subscriptions. |
|
418 | - $schema = "CREATE TABLE {$wpdb->prefix}wpinv_subscriptions ( |
|
417 | + // Subscriptions. |
|
418 | + $schema = "CREATE TABLE {$wpdb->prefix}wpinv_subscriptions ( |
|
419 | 419 | id bigint(20) unsigned NOT NULL auto_increment, |
420 | 420 | customer_id bigint(20) NOT NULL, |
421 | 421 | frequency int(11) NOT NULL DEFAULT '1', |
@@ -438,8 +438,8 @@ discard block |
||
438 | 438 | KEY customer_and_status (customer_id, status) |
439 | 439 | ) $charset_collate;"; |
440 | 440 | |
441 | - // Invoices. |
|
442 | - $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_invoices ( |
|
441 | + // Invoices. |
|
442 | + $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_invoices ( |
|
443 | 443 | post_id BIGINT(20) NOT NULL, |
444 | 444 | customer_id BIGINT(20) NOT NULL DEFAULT 0, |
445 | 445 | `number` VARCHAR(100), |
@@ -476,8 +476,8 @@ discard block |
||
476 | 476 | KEY `key` (`key`) |
477 | 477 | ) $charset_collate;"; |
478 | 478 | |
479 | - // Invoice items. |
|
480 | - $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_invoice_items ( |
|
479 | + // Invoice items. |
|
480 | + $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_invoice_items ( |
|
481 | 481 | ID BIGINT(20) NOT NULL AUTO_INCREMENT, |
482 | 482 | post_id BIGINT(20) NOT NULL, |
483 | 483 | item_id BIGINT(20) NOT NULL, |
@@ -499,8 +499,8 @@ discard block |
||
499 | 499 | KEY post_id (post_id) |
500 | 500 | ) $charset_collate;"; |
501 | 501 | |
502 | - // Customers. |
|
503 | - $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_customers ( |
|
502 | + // Customers. |
|
503 | + $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_customers ( |
|
504 | 504 | id BIGINT(20) NOT NULL AUTO_INCREMENT, |
505 | 505 | user_id BIGINT(20) NOT NULL, |
506 | 506 | email VARCHAR(100) NOT NULL, |
@@ -510,38 +510,38 @@ discard block |
||
510 | 510 | purchase_count BIGINT(20) NOT NULL DEFAULT 0, |
511 | 511 | "; |
512 | 512 | |
513 | - // Add address fields. |
|
514 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
513 | + // Add address fields. |
|
514 | + foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
515 | 515 | |
516 | - // Skip id, user_id and email. |
|
517 | - if ( in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) { |
|
518 | - continue; |
|
519 | - } |
|
516 | + // Skip id, user_id and email. |
|
517 | + if ( in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) { |
|
518 | + continue; |
|
519 | + } |
|
520 | 520 | |
521 | - $field = sanitize_key( $field ); |
|
522 | - $length = 100; |
|
523 | - $default = ''; |
|
521 | + $field = sanitize_key( $field ); |
|
522 | + $length = 100; |
|
523 | + $default = ''; |
|
524 | 524 | |
525 | - // Country. |
|
526 | - if ( 'country' === $field ) { |
|
527 | - $length = 2; |
|
528 | - $default = wpinv_get_default_country(); |
|
529 | - } |
|
525 | + // Country. |
|
526 | + if ( 'country' === $field ) { |
|
527 | + $length = 2; |
|
528 | + $default = wpinv_get_default_country(); |
|
529 | + } |
|
530 | 530 | |
531 | - // State. |
|
532 | - if ( 'state' === $field ) { |
|
533 | - $default = wpinv_get_default_state(); |
|
534 | - } |
|
531 | + // State. |
|
532 | + if ( 'state' === $field ) { |
|
533 | + $default = wpinv_get_default_state(); |
|
534 | + } |
|
535 | 535 | |
536 | - // Phone, zip. |
|
537 | - if ( in_array( $field, array( 'phone', 'zip' ), true ) ) { |
|
538 | - $length = 20; |
|
539 | - } |
|
536 | + // Phone, zip. |
|
537 | + if ( in_array( $field, array( 'phone', 'zip' ), true ) ) { |
|
538 | + $length = 20; |
|
539 | + } |
|
540 | 540 | |
541 | - $schema .= "`$field` VARCHAR($length) NOT NULL DEFAULT '$default',"; |
|
542 | - } |
|
541 | + $schema .= "`$field` VARCHAR($length) NOT NULL DEFAULT '$default',"; |
|
542 | + } |
|
543 | 543 | |
544 | - $schema .= " |
|
544 | + $schema .= " |
|
545 | 545 | date_created DATETIME NOT NULL, |
546 | 546 | date_modified DATETIME NOT NULL, |
547 | 547 | uuid VARCHAR(100) NOT NULL, |
@@ -550,8 +550,8 @@ discard block |
||
550 | 550 | KEY email (email) |
551 | 551 | ) $charset_collate;"; |
552 | 552 | |
553 | - // Customer meta. |
|
554 | - $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_customer_meta ( |
|
553 | + // Customer meta. |
|
554 | + $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_customer_meta ( |
|
555 | 555 | meta_id BIGINT(20) NOT NULL AUTO_INCREMENT, |
556 | 556 | customer_id BIGINT(20) NOT NULL, |
557 | 557 | meta_key VARCHAR(255) NOT NULL, |
@@ -561,41 +561,41 @@ discard block |
||
561 | 561 | KEY meta_key (meta_key(191)) |
562 | 562 | ) $charset_collate;"; |
563 | 563 | |
564 | - return $schema; |
|
565 | - } |
|
564 | + return $schema; |
|
565 | + } |
|
566 | 566 | |
567 | - /** |
|
568 | - * Checks if the db schema is up to date. |
|
569 | - * |
|
570 | - * @return bool |
|
571 | - */ |
|
572 | - public static function is_db_schema_up_to_date() { |
|
573 | - return md5( self::get_db_schema() ) === get_option( 'getpaid_db_schema' ); |
|
574 | - } |
|
567 | + /** |
|
568 | + * Checks if the db schema is up to date. |
|
569 | + * |
|
570 | + * @return bool |
|
571 | + */ |
|
572 | + public static function is_db_schema_up_to_date() { |
|
573 | + return md5( self::get_db_schema() ) === get_option( 'getpaid_db_schema' ); |
|
574 | + } |
|
575 | 575 | |
576 | - /** |
|
577 | - * Set up the database tables which the plugin needs to function. |
|
578 | - */ |
|
579 | - public static function create_db_tables() { |
|
580 | - global $wpdb; |
|
576 | + /** |
|
577 | + * Set up the database tables which the plugin needs to function. |
|
578 | + */ |
|
579 | + public static function create_db_tables() { |
|
580 | + global $wpdb; |
|
581 | 581 | |
582 | - $wpdb->hide_errors(); |
|
582 | + $wpdb->hide_errors(); |
|
583 | 583 | |
584 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
584 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
585 | 585 | |
586 | - $schema = self::get_db_schema(); |
|
586 | + $schema = self::get_db_schema(); |
|
587 | 587 | |
588 | - dbDelta( $schema ); |
|
588 | + dbDelta( $schema ); |
|
589 | 589 | |
590 | - update_option( 'getpaid_db_schema', md5( self::get_db_schema() ) ); |
|
591 | - } |
|
590 | + update_option( 'getpaid_db_schema', md5( self::get_db_schema() ) ); |
|
591 | + } |
|
592 | 592 | |
593 | - /** |
|
594 | - * Creates tables if schema is not up to date. |
|
595 | - */ |
|
596 | - public static function maybe_create_db_tables() { |
|
597 | - if ( ! self::is_db_schema_up_to_date() ) { |
|
598 | - self::create_db_tables(); |
|
599 | - } |
|
600 | - } |
|
593 | + /** |
|
594 | + * Creates tables if schema is not up to date. |
|
595 | + */ |
|
596 | + public static function maybe_create_db_tables() { |
|
597 | + if ( ! self::is_db_schema_up_to_date() ) { |
|
598 | + self::create_db_tables(); |
|
599 | + } |
|
600 | + } |
|
601 | 601 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | // Load WP_List_Table if not loaded |
13 | 13 | if ( ! class_exists( 'WP_List_Table' ) ) { |
14 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
14 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | /** |
@@ -23,323 +23,323 @@ discard block |
||
23 | 23 | */ |
24 | 24 | class WPInv_Customers_Table extends WP_List_Table { |
25 | 25 | |
26 | - /** |
|
27 | - * @var int Number of items per page |
|
28 | - * @since 1.0.19 |
|
29 | - */ |
|
30 | - public $per_page = 10; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var int Number of items |
|
34 | - * @since 1.0.19 |
|
35 | - */ |
|
36 | - public $total = 0; |
|
37 | - |
|
38 | - /** |
|
39 | - * Get things started |
|
40 | - * |
|
41 | - * @since 1.0.19 |
|
42 | - * @see WP_List_Table::__construct() |
|
43 | - */ |
|
44 | - public function __construct() { |
|
45 | - |
|
46 | - // Set parent defaults |
|
47 | - parent::__construct( |
|
26 | + /** |
|
27 | + * @var int Number of items per page |
|
28 | + * @since 1.0.19 |
|
29 | + */ |
|
30 | + public $per_page = 10; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var int Number of items |
|
34 | + * @since 1.0.19 |
|
35 | + */ |
|
36 | + public $total = 0; |
|
37 | + |
|
38 | + /** |
|
39 | + * Get things started |
|
40 | + * |
|
41 | + * @since 1.0.19 |
|
42 | + * @see WP_List_Table::__construct() |
|
43 | + */ |
|
44 | + public function __construct() { |
|
45 | + |
|
46 | + // Set parent defaults |
|
47 | + parent::__construct( |
|
48 | 48 | array( |
49 | - 'singular' => 'id', |
|
50 | - 'plural' => 'ids', |
|
51 | - 'ajax' => false, |
|
49 | + 'singular' => 'id', |
|
50 | + 'plural' => 'ids', |
|
51 | + 'ajax' => false, |
|
52 | 52 | ) |
53 | 53 | ); |
54 | 54 | |
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Gets the name of the primary column. |
|
59 | - * |
|
60 | - * @since 1.0.19 |
|
61 | - * @access protected |
|
62 | - * |
|
63 | - * @return string Name of the primary column. |
|
64 | - */ |
|
65 | - protected function get_primary_column_name() { |
|
66 | - return 'name'; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * This function renders most of the columns in the list table. |
|
71 | - * |
|
72 | - * @since 1.0.19 |
|
73 | - * |
|
74 | - * @param WP_User $item |
|
75 | - * @param string $column_name The name of the column |
|
76 | - * |
|
77 | - * @return string Column Name |
|
78 | - */ |
|
79 | - public function column_default( $item, $column_name ) { |
|
80 | - $value = esc_html( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) ); |
|
81 | - return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item ); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Displays the country column. |
|
86 | - * |
|
87 | - * @since 1.0.19 |
|
88 | - * |
|
89 | - * @param WP_User $user |
|
90 | - * |
|
91 | - * @return string Column Name |
|
92 | - */ |
|
93 | - public function column_country( $user ) { |
|
94 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
95 | - if ( $country ) { |
|
96 | - $country = wpinv_country_name( $country ); |
|
97 | - } |
|
98 | - return esc_html( $country ); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Displays the state column. |
|
103 | - * |
|
104 | - * @since 1.0.19 |
|
105 | - * |
|
106 | - * @param WP_User $user |
|
107 | - * |
|
108 | - * @return string Column Name |
|
109 | - */ |
|
110 | - public function column_state( $user ) { |
|
111 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
112 | - $state = $user->_wpinv_state; |
|
113 | - if ( $state ) { |
|
114 | - $state = wpinv_state_name( $state, $country ); |
|
115 | - } |
|
116 | - |
|
117 | - return esc_html( $state ); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Displays the signup column. |
|
122 | - * |
|
123 | - * @since 1.0.19 |
|
124 | - * |
|
125 | - * @param WP_User $user |
|
126 | - * |
|
127 | - * @return string Column Name |
|
128 | - */ |
|
129 | - public function column_signup( $user ) { |
|
130 | - return getpaid_format_date_value( $user->user_registered ); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Displays the total spent column. |
|
135 | - * |
|
136 | - * @since 1.0.19 |
|
137 | - * |
|
138 | - * @param WP_User $user |
|
139 | - * |
|
140 | - * @return string Column Name |
|
141 | - */ |
|
142 | - public function column_total( $user ) { |
|
143 | - return wpinv_price( $this->column_total_raw( $user ) ); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Displays the total spent column. |
|
148 | - * |
|
149 | - * @since 1.0.19 |
|
150 | - * |
|
151 | - * @param WP_User $user |
|
152 | - * |
|
153 | - * @return float |
|
154 | - */ |
|
155 | - public function column_total_raw( $user ) { |
|
156 | - return getpaid_get_user_total_spend( $user->ID ); |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Displays the total spent column. |
|
161 | - * |
|
162 | - * @since 1.0.19 |
|
163 | - * |
|
164 | - * @param WP_User $user |
|
165 | - * |
|
166 | - * @return string Column Name |
|
167 | - */ |
|
168 | - public function column_invoices( $user ) { |
|
169 | - $value = getpaid_count_user_invoices( $user->ID ); |
|
170 | - $url = add_query_arg( array( 'post_type' => 'wpi_invoice', 'author' => $user->ID ), admin_url( 'edit.php' ) ); |
|
171 | - return empty( $value ) ? '0' : '<a href="' . esc_url( $url ) . '">' . absint( $value ) . '</a>'; |
|
172 | - |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Generates content for a single row of the table |
|
177 | - * @since 1.0.19 |
|
178 | - * |
|
179 | - * @param int $item The user id. |
|
180 | - */ |
|
181 | - public function single_row( $item ) { |
|
182 | - $item = get_user_by( 'id', $item ); |
|
183 | - |
|
184 | - if ( empty( $item ) ) { |
|
185 | - return; |
|
186 | - } |
|
187 | - |
|
188 | - echo '<tr>'; |
|
189 | - $this->single_row_columns( $item ); |
|
190 | - echo '</tr>'; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Displays the customers name |
|
195 | - * |
|
196 | - * @param WP_User $customer customer. |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - public function column_name( $customer ) { |
|
200 | - |
|
201 | - // Customer view URL. |
|
202 | - $view_url = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) ); |
|
203 | - $row_actions = $this->row_actions( |
|
204 | - array( |
|
205 | - 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
206 | - ) |
|
207 | - ); |
|
208 | - |
|
209 | - // Get user's address. |
|
210 | - $address = wpinv_get_user_address( $customer->ID ); |
|
211 | - |
|
212 | - // Customer email address. |
|
213 | - $email = sanitize_email( $customer->user_email ); |
|
214 | - |
|
215 | - // Customer's avatar. |
|
216 | - $avatar = esc_url( get_avatar_url( $email ) ); |
|
217 | - $avatar = "<img src='$avatar' height='32' width='32'/>"; |
|
218 | - |
|
219 | - // Customer's name. |
|
220 | - $name = esc_html( "{$address['first_name']} {$address['last_name']}" ); |
|
221 | - |
|
222 | - if ( empty( trim( $name ) ) ) { |
|
223 | - $name = esc_html( $address['display_name'] ); |
|
224 | - } |
|
225 | - |
|
226 | - if ( ! empty( $name ) ) { |
|
227 | - $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
|
228 | - } |
|
229 | - |
|
230 | - $email = "<div class='row-title'><a href='$view_url'>$email</a></div>"; |
|
231 | - |
|
232 | - return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>"; |
|
233 | - |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Retrieve the table columns |
|
238 | - * |
|
239 | - * @since 1.0.19 |
|
240 | - * @return array $columns Array of all the list table columns |
|
241 | - */ |
|
242 | - public function get_columns() { |
|
243 | - |
|
244 | - $columns = array( |
|
245 | - 'name' => __( 'Name', 'invoicing' ), |
|
246 | - 'country' => __( 'Country', 'invoicing' ), |
|
247 | - 'state' => __( 'State', 'invoicing' ), |
|
248 | - 'city' => __( 'City', 'invoicing' ), |
|
249 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
250 | - 'address' => __( 'Address', 'invoicing' ), |
|
251 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
252 | - 'company' => __( 'Company', 'invoicing' ), |
|
253 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
254 | - 'total' => __( 'Total Spend', 'invoicing' ), |
|
255 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
256 | - ); |
|
257 | - return apply_filters( 'wpinv_customers_table_columns', $columns ); |
|
258 | - |
|
259 | - } |
|
260 | - |
|
261 | - /** |
|
262 | - * Retrieve the current page number |
|
263 | - * |
|
264 | - * @since 1.0.19 |
|
265 | - * @return int Current page number |
|
266 | - */ |
|
267 | - public function get_paged() { |
|
268 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * Returns bulk actions. |
|
273 | - * |
|
274 | - * @since 1.0.19 |
|
275 | - * @return void |
|
276 | - */ |
|
277 | - public function bulk_actions( $which = '' ) { |
|
278 | - return array(); |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * Prepares the display query |
|
283 | - */ |
|
284 | - public function prepare_query() { |
|
285 | - global $wpdb; |
|
286 | - |
|
287 | - $post_types = ''; |
|
288 | - |
|
289 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
290 | - $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
291 | - } |
|
292 | - |
|
293 | - $post_types = rtrim( $post_types, ' OR' ); |
|
294 | - |
|
295 | - // Maybe search. |
|
296 | - if ( ! empty( $_POST['s'] ) ) { |
|
297 | - $users = get_users( |
|
298 | - array( |
|
299 | - 'search' => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*', |
|
300 | - 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
301 | - 'fields' => 'ID', |
|
302 | - ) |
|
303 | - ); |
|
304 | - |
|
305 | - $users = implode( ', ', $users ); |
|
306 | - $post_types = "($post_types) AND ( post_author IN ( $users ) )"; |
|
307 | - } |
|
308 | - |
|
309 | - // Users with invoices. |
|
310 | - $customers = $wpdb->get_col( |
|
311 | - $wpdb->prepare( |
|
312 | - "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d", |
|
313 | - $this->get_paged() * 10 - 10, |
|
314 | - $this->per_page |
|
315 | - ) |
|
316 | - ); |
|
317 | - |
|
318 | - $this->items = $customers; |
|
319 | - $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" ); |
|
320 | - |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * Setup the final data for the table |
|
325 | - * |
|
326 | - * @since 1.0.19 |
|
327 | - * @return void |
|
328 | - */ |
|
329 | - public function prepare_items() { |
|
330 | - $columns = $this->get_columns(); |
|
331 | - $hidden = array(); // No hidden columns |
|
332 | - $sortable = $this->get_sortable_columns(); |
|
333 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
334 | - $this->prepare_query(); |
|
335 | - |
|
336 | - $this->set_pagination_args( |
|
337 | - array( |
|
338 | - 'total_items' => $this->total, |
|
339 | - 'per_page' => $this->per_page, |
|
340 | - 'total_pages' => ceil( $this->total / $this->per_page ), |
|
341 | - ) |
|
342 | - ); |
|
343 | - |
|
344 | - } |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Gets the name of the primary column. |
|
59 | + * |
|
60 | + * @since 1.0.19 |
|
61 | + * @access protected |
|
62 | + * |
|
63 | + * @return string Name of the primary column. |
|
64 | + */ |
|
65 | + protected function get_primary_column_name() { |
|
66 | + return 'name'; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * This function renders most of the columns in the list table. |
|
71 | + * |
|
72 | + * @since 1.0.19 |
|
73 | + * |
|
74 | + * @param WP_User $item |
|
75 | + * @param string $column_name The name of the column |
|
76 | + * |
|
77 | + * @return string Column Name |
|
78 | + */ |
|
79 | + public function column_default( $item, $column_name ) { |
|
80 | + $value = esc_html( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) ); |
|
81 | + return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item ); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Displays the country column. |
|
86 | + * |
|
87 | + * @since 1.0.19 |
|
88 | + * |
|
89 | + * @param WP_User $user |
|
90 | + * |
|
91 | + * @return string Column Name |
|
92 | + */ |
|
93 | + public function column_country( $user ) { |
|
94 | + $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
95 | + if ( $country ) { |
|
96 | + $country = wpinv_country_name( $country ); |
|
97 | + } |
|
98 | + return esc_html( $country ); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Displays the state column. |
|
103 | + * |
|
104 | + * @since 1.0.19 |
|
105 | + * |
|
106 | + * @param WP_User $user |
|
107 | + * |
|
108 | + * @return string Column Name |
|
109 | + */ |
|
110 | + public function column_state( $user ) { |
|
111 | + $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
112 | + $state = $user->_wpinv_state; |
|
113 | + if ( $state ) { |
|
114 | + $state = wpinv_state_name( $state, $country ); |
|
115 | + } |
|
116 | + |
|
117 | + return esc_html( $state ); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Displays the signup column. |
|
122 | + * |
|
123 | + * @since 1.0.19 |
|
124 | + * |
|
125 | + * @param WP_User $user |
|
126 | + * |
|
127 | + * @return string Column Name |
|
128 | + */ |
|
129 | + public function column_signup( $user ) { |
|
130 | + return getpaid_format_date_value( $user->user_registered ); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Displays the total spent column. |
|
135 | + * |
|
136 | + * @since 1.0.19 |
|
137 | + * |
|
138 | + * @param WP_User $user |
|
139 | + * |
|
140 | + * @return string Column Name |
|
141 | + */ |
|
142 | + public function column_total( $user ) { |
|
143 | + return wpinv_price( $this->column_total_raw( $user ) ); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Displays the total spent column. |
|
148 | + * |
|
149 | + * @since 1.0.19 |
|
150 | + * |
|
151 | + * @param WP_User $user |
|
152 | + * |
|
153 | + * @return float |
|
154 | + */ |
|
155 | + public function column_total_raw( $user ) { |
|
156 | + return getpaid_get_user_total_spend( $user->ID ); |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Displays the total spent column. |
|
161 | + * |
|
162 | + * @since 1.0.19 |
|
163 | + * |
|
164 | + * @param WP_User $user |
|
165 | + * |
|
166 | + * @return string Column Name |
|
167 | + */ |
|
168 | + public function column_invoices( $user ) { |
|
169 | + $value = getpaid_count_user_invoices( $user->ID ); |
|
170 | + $url = add_query_arg( array( 'post_type' => 'wpi_invoice', 'author' => $user->ID ), admin_url( 'edit.php' ) ); |
|
171 | + return empty( $value ) ? '0' : '<a href="' . esc_url( $url ) . '">' . absint( $value ) . '</a>'; |
|
172 | + |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Generates content for a single row of the table |
|
177 | + * @since 1.0.19 |
|
178 | + * |
|
179 | + * @param int $item The user id. |
|
180 | + */ |
|
181 | + public function single_row( $item ) { |
|
182 | + $item = get_user_by( 'id', $item ); |
|
183 | + |
|
184 | + if ( empty( $item ) ) { |
|
185 | + return; |
|
186 | + } |
|
187 | + |
|
188 | + echo '<tr>'; |
|
189 | + $this->single_row_columns( $item ); |
|
190 | + echo '</tr>'; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Displays the customers name |
|
195 | + * |
|
196 | + * @param WP_User $customer customer. |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + public function column_name( $customer ) { |
|
200 | + |
|
201 | + // Customer view URL. |
|
202 | + $view_url = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) ); |
|
203 | + $row_actions = $this->row_actions( |
|
204 | + array( |
|
205 | + 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
206 | + ) |
|
207 | + ); |
|
208 | + |
|
209 | + // Get user's address. |
|
210 | + $address = wpinv_get_user_address( $customer->ID ); |
|
211 | + |
|
212 | + // Customer email address. |
|
213 | + $email = sanitize_email( $customer->user_email ); |
|
214 | + |
|
215 | + // Customer's avatar. |
|
216 | + $avatar = esc_url( get_avatar_url( $email ) ); |
|
217 | + $avatar = "<img src='$avatar' height='32' width='32'/>"; |
|
218 | + |
|
219 | + // Customer's name. |
|
220 | + $name = esc_html( "{$address['first_name']} {$address['last_name']}" ); |
|
221 | + |
|
222 | + if ( empty( trim( $name ) ) ) { |
|
223 | + $name = esc_html( $address['display_name'] ); |
|
224 | + } |
|
225 | + |
|
226 | + if ( ! empty( $name ) ) { |
|
227 | + $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
|
228 | + } |
|
229 | + |
|
230 | + $email = "<div class='row-title'><a href='$view_url'>$email</a></div>"; |
|
231 | + |
|
232 | + return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>"; |
|
233 | + |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Retrieve the table columns |
|
238 | + * |
|
239 | + * @since 1.0.19 |
|
240 | + * @return array $columns Array of all the list table columns |
|
241 | + */ |
|
242 | + public function get_columns() { |
|
243 | + |
|
244 | + $columns = array( |
|
245 | + 'name' => __( 'Name', 'invoicing' ), |
|
246 | + 'country' => __( 'Country', 'invoicing' ), |
|
247 | + 'state' => __( 'State', 'invoicing' ), |
|
248 | + 'city' => __( 'City', 'invoicing' ), |
|
249 | + 'zip' => __( 'ZIP', 'invoicing' ), |
|
250 | + 'address' => __( 'Address', 'invoicing' ), |
|
251 | + 'phone' => __( 'Phone', 'invoicing' ), |
|
252 | + 'company' => __( 'Company', 'invoicing' ), |
|
253 | + 'invoices' => __( 'Invoices', 'invoicing' ), |
|
254 | + 'total' => __( 'Total Spend', 'invoicing' ), |
|
255 | + 'signup' => __( 'Date created', 'invoicing' ), |
|
256 | + ); |
|
257 | + return apply_filters( 'wpinv_customers_table_columns', $columns ); |
|
258 | + |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * Retrieve the current page number |
|
263 | + * |
|
264 | + * @since 1.0.19 |
|
265 | + * @return int Current page number |
|
266 | + */ |
|
267 | + public function get_paged() { |
|
268 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * Returns bulk actions. |
|
273 | + * |
|
274 | + * @since 1.0.19 |
|
275 | + * @return void |
|
276 | + */ |
|
277 | + public function bulk_actions( $which = '' ) { |
|
278 | + return array(); |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * Prepares the display query |
|
283 | + */ |
|
284 | + public function prepare_query() { |
|
285 | + global $wpdb; |
|
286 | + |
|
287 | + $post_types = ''; |
|
288 | + |
|
289 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
290 | + $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
291 | + } |
|
292 | + |
|
293 | + $post_types = rtrim( $post_types, ' OR' ); |
|
294 | + |
|
295 | + // Maybe search. |
|
296 | + if ( ! empty( $_POST['s'] ) ) { |
|
297 | + $users = get_users( |
|
298 | + array( |
|
299 | + 'search' => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*', |
|
300 | + 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
301 | + 'fields' => 'ID', |
|
302 | + ) |
|
303 | + ); |
|
304 | + |
|
305 | + $users = implode( ', ', $users ); |
|
306 | + $post_types = "($post_types) AND ( post_author IN ( $users ) )"; |
|
307 | + } |
|
308 | + |
|
309 | + // Users with invoices. |
|
310 | + $customers = $wpdb->get_col( |
|
311 | + $wpdb->prepare( |
|
312 | + "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d", |
|
313 | + $this->get_paged() * 10 - 10, |
|
314 | + $this->per_page |
|
315 | + ) |
|
316 | + ); |
|
317 | + |
|
318 | + $this->items = $customers; |
|
319 | + $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" ); |
|
320 | + |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * Setup the final data for the table |
|
325 | + * |
|
326 | + * @since 1.0.19 |
|
327 | + * @return void |
|
328 | + */ |
|
329 | + public function prepare_items() { |
|
330 | + $columns = $this->get_columns(); |
|
331 | + $hidden = array(); // No hidden columns |
|
332 | + $sortable = $this->get_sortable_columns(); |
|
333 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
334 | + $this->prepare_query(); |
|
335 | + |
|
336 | + $this->set_pagination_args( |
|
337 | + array( |
|
338 | + 'total_items' => $this->total, |
|
339 | + 'per_page' => $this->per_page, |
|
340 | + 'total_pages' => ceil( $this->total / $this->per_page ), |
|
341 | + ) |
|
342 | + ); |
|
343 | + |
|
344 | + } |
|
345 | 345 | } |
@@ -15,67 +15,67 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Customer extends GetPaid_Data { |
17 | 17 | |
18 | - /** |
|
19 | - * Which data store to load. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
18 | + /** |
|
19 | + * Which data store to load. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | 23 | protected $data_store_name = 'customer'; |
24 | 24 | |
25 | 25 | /** |
26 | - * This is the name of this object type. |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected $object_type = 'customer'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Get the customer if ID is passed, otherwise the customer is new and empty. |
|
34 | - * |
|
35 | - * @param int|string|GetPaid_Customer $customer customer id, object, or email. |
|
36 | - */ |
|
37 | - public function __construct( $customer = 0 ) { |
|
26 | + * This is the name of this object type. |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected $object_type = 'customer'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Get the customer if ID is passed, otherwise the customer is new and empty. |
|
34 | + * |
|
35 | + * @param int|string|GetPaid_Customer $customer customer id, object, or email. |
|
36 | + */ |
|
37 | + public function __construct( $customer = 0 ) { |
|
38 | 38 | |
39 | 39 | // Setup default customer data. |
40 | 40 | $this->setup_default_data(); |
41 | 41 | |
42 | - if ( is_numeric( $customer ) ) { |
|
43 | - $this->set_id( $customer ); |
|
44 | - } elseif ( $customer instanceof self ) { |
|
45 | - $this->set_id( $customer->get_id() ); |
|
46 | - } elseif ( is_string( $customer ) && $customer_id = self::get_customer_id_by( $customer, 'email' ) ) { |
|
47 | - $this->set_id( $customer_id ); |
|
48 | - } |
|
42 | + if ( is_numeric( $customer ) ) { |
|
43 | + $this->set_id( $customer ); |
|
44 | + } elseif ( $customer instanceof self ) { |
|
45 | + $this->set_id( $customer->get_id() ); |
|
46 | + } elseif ( is_string( $customer ) && $customer_id = self::get_customer_id_by( $customer, 'email' ) ) { |
|
47 | + $this->set_id( $customer_id ); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | // Load the datastore. |
51 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
51 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
52 | 52 | |
53 | - if ( $this->get_id() > 0 ) { |
|
54 | - $this->data_store->read( $this ); |
|
53 | + if ( $this->get_id() > 0 ) { |
|
54 | + $this->data_store->read( $this ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | $this->set_object_read( true ); |
58 | - } |
|
58 | + } |
|
59 | 59 | |
60 | 60 | /** |
61 | - * Sets up default customer data. |
|
62 | - */ |
|
63 | - private function setup_default_data() { |
|
61 | + * Sets up default customer data. |
|
62 | + */ |
|
63 | + private function setup_default_data() { |
|
64 | 64 | |
65 | 65 | $this->data = array( |
66 | - 'user_id' => 0, |
|
67 | - 'email' => '', |
|
68 | - 'email_cc' => '', |
|
69 | - 'status' => 'active', |
|
70 | - 'purchase_value' => 0, |
|
71 | - 'purchase_count' => 0, |
|
72 | - 'date_created' => current_time( 'mysql' ), |
|
73 | - 'date_modified' => current_time( 'mysql' ), |
|
74 | - 'uuid' => wp_generate_uuid4(), |
|
75 | - ); |
|
66 | + 'user_id' => 0, |
|
67 | + 'email' => '', |
|
68 | + 'email_cc' => '', |
|
69 | + 'status' => 'active', |
|
70 | + 'purchase_value' => 0, |
|
71 | + 'purchase_count' => 0, |
|
72 | + 'date_created' => current_time( 'mysql' ), |
|
73 | + 'date_modified' => current_time( 'mysql' ), |
|
74 | + 'uuid' => wp_generate_uuid4(), |
|
75 | + ); |
|
76 | 76 | |
77 | 77 | // Add address fields. |
78 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
78 | + foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
79 | 79 | |
80 | 80 | if ( isset( $this->data[ $field ] ) ) { |
81 | 81 | continue; |
@@ -93,22 +93,22 @@ discard block |
||
93 | 93 | continue; |
94 | 94 | } |
95 | 95 | |
96 | - $this->data[ $field ] = ''; |
|
97 | - } |
|
96 | + $this->data[ $field ] = ''; |
|
97 | + } |
|
98 | 98 | |
99 | 99 | $this->default_data = $this->data; |
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Given a customer email or user id, it returns a customer id. |
|
104 | - * |
|
105 | - * @static |
|
106 | - * @param string $value |
|
107 | - * @since 1.0.15 |
|
108 | - * @return int |
|
109 | - */ |
|
110 | - public static function get_customer_id_by( $value, $by = 'email' ) { |
|
111 | - global $wpdb; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Given a customer email or user id, it returns a customer id. |
|
104 | + * |
|
105 | + * @static |
|
106 | + * @param string $value |
|
107 | + * @since 1.0.15 |
|
108 | + * @return int |
|
109 | + */ |
|
110 | + public static function get_customer_id_by( $value, $by = 'email' ) { |
|
111 | + global $wpdb; |
|
112 | 112 | |
113 | 113 | // Prepare value. |
114 | 114 | if ( 'email' === $by ) { |
@@ -123,12 +123,12 @@ discard block |
||
123 | 123 | return 0; |
124 | 124 | } |
125 | 125 | |
126 | - // Maybe retrieve from the cache. |
|
126 | + // Maybe retrieve from the cache. |
|
127 | 127 | $cache_key = 'getpaid_customer_ids_by_' . $by; |
128 | - $customer_id = wp_cache_get( $value, $cache_key ); |
|
129 | - if ( false !== $customer_id ) { |
|
130 | - return $customer_id; |
|
131 | - } |
|
128 | + $customer_id = wp_cache_get( $value, $cache_key ); |
|
129 | + if ( false !== $customer_id ) { |
|
130 | + return $customer_id; |
|
131 | + } |
|
132 | 132 | |
133 | 133 | if ( 'email' === $by ) { |
134 | 134 | $customer_id = (int) $wpdb->get_var( |
@@ -140,23 +140,23 @@ discard block |
||
140 | 140 | ); |
141 | 141 | } |
142 | 142 | |
143 | - // Update the cache with our data |
|
144 | - wp_cache_set( $value, $customer_id, $cache_key ); |
|
143 | + // Update the cache with our data |
|
144 | + wp_cache_set( $value, $customer_id, $cache_key ); |
|
145 | 145 | |
146 | - return $customer_id; |
|
146 | + return $customer_id; |
|
147 | 147 | |
148 | - } |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
150 | + /** |
|
151 | 151 | * Clears the customer's cache. |
152 | 152 | */ |
153 | 153 | public function clear_cache() { |
154 | 154 | wp_cache_delete( $this->get( 'email' ), 'getpaid_customer_ids_by_email' ); |
155 | 155 | wp_cache_delete( $this->get( 'user_id' ), 'getpaid_customer_ids_by_user_id' ); |
156 | - wp_cache_delete( $this->get_id(), 'getpaid_customers' ); |
|
157 | - } |
|
156 | + wp_cache_delete( $this->get_id(), 'getpaid_customers' ); |
|
157 | + } |
|
158 | 158 | |
159 | - /* |
|
159 | + /* |
|
160 | 160 | |-------------------------------------------------------------------------- |
161 | 161 | | CRUD methods |
162 | 162 | |-------------------------------------------------------------------------- |
@@ -187,11 +187,11 @@ discard block |
||
187 | 187 | return call_user_func( array( $this, 'get_' . $key ), $context ); |
188 | 188 | } |
189 | 189 | |
190 | - return $this->get_prop( $key, $context ); |
|
190 | + return $this->get_prop( $key, $context ); |
|
191 | 191 | |
192 | 192 | } |
193 | 193 | |
194 | - /* |
|
194 | + /* |
|
195 | 195 | |-------------------------------------------------------------------------- |
196 | 196 | | Setters |
197 | 197 | |-------------------------------------------------------------------------- |
@@ -214,114 +214,114 @@ discard block |
||
214 | 214 | return call_user_func( array( $this, 'set_' . $key ), $value ); |
215 | 215 | } |
216 | 216 | |
217 | - return $this->set_prop( $key, $value ); |
|
217 | + return $this->set_prop( $key, $value ); |
|
218 | 218 | |
219 | 219 | } |
220 | 220 | |
221 | - /** |
|
222 | - * Sets customer status. |
|
223 | - * |
|
224 | - * @since 1.0.0 |
|
225 | - * @param string $status New status. |
|
226 | - */ |
|
227 | - public function set_status( $status ) { |
|
228 | - |
|
229 | - if ( in_array( $status, array( 'active', 'inactive', 'blocked' ), true ) ) { |
|
230 | - return $this->set_prop( 'status', $status ); |
|
231 | - } |
|
232 | - |
|
233 | - $this->set_prop( 'status', 'inactive' ); |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Sets the purchase value. |
|
238 | - * |
|
239 | - * @since 1.0.0 |
|
240 | - * @param float $purchase_value. |
|
241 | - */ |
|
242 | - public function set_purchase_value( $purchase_value ) { |
|
243 | - $this->set_prop( 'purchase_value', (float) $purchase_value ); |
|
244 | - } |
|
221 | + /** |
|
222 | + * Sets customer status. |
|
223 | + * |
|
224 | + * @since 1.0.0 |
|
225 | + * @param string $status New status. |
|
226 | + */ |
|
227 | + public function set_status( $status ) { |
|
228 | + |
|
229 | + if ( in_array( $status, array( 'active', 'inactive', 'blocked' ), true ) ) { |
|
230 | + return $this->set_prop( 'status', $status ); |
|
231 | + } |
|
232 | + |
|
233 | + $this->set_prop( 'status', 'inactive' ); |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Sets the purchase value. |
|
238 | + * |
|
239 | + * @since 1.0.0 |
|
240 | + * @param float $purchase_value. |
|
241 | + */ |
|
242 | + public function set_purchase_value( $purchase_value ) { |
|
243 | + $this->set_prop( 'purchase_value', (float) $purchase_value ); |
|
244 | + } |
|
245 | 245 | |
246 | 246 | /** |
247 | - * Sets the purchase count. |
|
248 | - * |
|
249 | - * @since 1.0.0 |
|
250 | - * @param int $purchase_count. |
|
251 | - */ |
|
252 | - public function set_purchase_count( $purchase_count ) { |
|
253 | - $this->set_prop( 'purchase_count', absint( $purchase_count ) ); |
|
254 | - } |
|
247 | + * Sets the purchase count. |
|
248 | + * |
|
249 | + * @since 1.0.0 |
|
250 | + * @param int $purchase_count. |
|
251 | + */ |
|
252 | + public function set_purchase_count( $purchase_count ) { |
|
253 | + $this->set_prop( 'purchase_count', absint( $purchase_count ) ); |
|
254 | + } |
|
255 | 255 | |
256 | 256 | /** |
257 | - * Sets the user id. |
|
258 | - * |
|
259 | - * @since 1.0.0 |
|
260 | - * @param int $user_id. |
|
261 | - */ |
|
262 | - public function set_user_id( $user_id ) { |
|
263 | - $this->set_prop( 'user_id', absint( $user_id ) ); |
|
264 | - } |
|
257 | + * Sets the user id. |
|
258 | + * |
|
259 | + * @since 1.0.0 |
|
260 | + * @param int $user_id. |
|
261 | + */ |
|
262 | + public function set_user_id( $user_id ) { |
|
263 | + $this->set_prop( 'user_id', absint( $user_id ) ); |
|
264 | + } |
|
265 | 265 | |
266 | 266 | /** |
267 | - * Sets the email. |
|
268 | - * |
|
269 | - * @since 1.0.0 |
|
270 | - * @param string $email. |
|
271 | - */ |
|
272 | - public function set_email( $email ) { |
|
267 | + * Sets the email. |
|
268 | + * |
|
269 | + * @since 1.0.0 |
|
270 | + * @param string $email. |
|
271 | + */ |
|
272 | + public function set_email( $email ) { |
|
273 | 273 | $email = is_string( $email ) ? sanitize_email( $email ) : ''; |
274 | - $this->set_prop( 'email', $email ); |
|
275 | - } |
|
274 | + $this->set_prop( 'email', $email ); |
|
275 | + } |
|
276 | 276 | |
277 | 277 | /** |
278 | - * Sets the email cc. |
|
279 | - * |
|
280 | - * @since 1.0.0 |
|
281 | - * @param string $email_cc. |
|
282 | - */ |
|
283 | - public function set_email_cc( $email_cc ) { |
|
278 | + * Sets the email cc. |
|
279 | + * |
|
280 | + * @since 1.0.0 |
|
281 | + * @param string $email_cc. |
|
282 | + */ |
|
283 | + public function set_email_cc( $email_cc ) { |
|
284 | 284 | $email_cc = implode( ', ', wp_parse_list( $email_cc ) ); |
285 | - $this->set_prop( 'email_cc', $email_cc ); |
|
286 | - } |
|
285 | + $this->set_prop( 'email_cc', $email_cc ); |
|
286 | + } |
|
287 | 287 | |
288 | 288 | /** |
289 | - * Sets the created date. |
|
290 | - * |
|
291 | - * @since 1.0.0 |
|
292 | - * @param string $date_created date created. |
|
293 | - */ |
|
294 | - public function set_date_created( $date_created ) { |
|
289 | + * Sets the created date. |
|
290 | + * |
|
291 | + * @since 1.0.0 |
|
292 | + * @param string $date_created date created. |
|
293 | + */ |
|
294 | + public function set_date_created( $date_created ) { |
|
295 | 295 | |
296 | - $date = strtotime( $date_created ); |
|
296 | + $date = strtotime( $date_created ); |
|
297 | 297 | |
298 | 298 | if ( $date && $date_created !== '0000-00-00 00:00:00' && $date_created !== '0000-00-00 00:00' ) { |
299 | 299 | $this->set_prop( 'date_created', gmdate( 'Y-m-d H:i:s', $date ) ); |
300 | 300 | return; |
301 | - } |
|
301 | + } |
|
302 | 302 | |
303 | - $this->set_prop( 'date_created', null ); |
|
304 | - } |
|
303 | + $this->set_prop( 'date_created', null ); |
|
304 | + } |
|
305 | 305 | |
306 | 306 | /** |
307 | - * Sets the created date. |
|
308 | - * |
|
309 | - * @since 1.0.0 |
|
310 | - * @param string $date_modified date created. |
|
311 | - */ |
|
312 | - public function set_date_modified( $date_modified ) { |
|
307 | + * Sets the created date. |
|
308 | + * |
|
309 | + * @since 1.0.0 |
|
310 | + * @param string $date_modified date created. |
|
311 | + */ |
|
312 | + public function set_date_modified( $date_modified ) { |
|
313 | 313 | |
314 | - $date = strtotime( $date_modified ); |
|
314 | + $date = strtotime( $date_modified ); |
|
315 | 315 | |
316 | 316 | if ( $date && $date_modified !== '0000-00-00 00:00:00' && $date_modified !== '0000-00-00 00:00' ) { |
317 | 317 | $this->set_prop( 'date_modified', gmdate( 'Y-m-d H:i:s', $date ) ); |
318 | 318 | return; |
319 | - } |
|
319 | + } |
|
320 | 320 | |
321 | - $this->set_prop( 'date_modified', null ); |
|
322 | - } |
|
321 | + $this->set_prop( 'date_modified', null ); |
|
322 | + } |
|
323 | 323 | |
324 | - /* |
|
324 | + /* |
|
325 | 325 | |-------------------------------------------------------------------------- |
326 | 326 | | Additional methods |
327 | 327 | |-------------------------------------------------------------------------- |
@@ -330,12 +330,12 @@ discard block |
||
330 | 330 | | |
331 | 331 | */ |
332 | 332 | |
333 | - /** |
|
334 | - * Saves the customer. |
|
335 | - * |
|
336 | - * @since 1.0.0 |
|
337 | - */ |
|
338 | - public function save() { |
|
333 | + /** |
|
334 | + * Saves the customer. |
|
335 | + * |
|
336 | + * @since 1.0.0 |
|
337 | + */ |
|
338 | + public function save() { |
|
339 | 339 | |
340 | 340 | $maybe_set = array( |
341 | 341 | 'uuid' => wp_generate_uuid4(), |
@@ -352,23 +352,23 @@ discard block |
||
352 | 352 | |
353 | 353 | $this->set( 'date_modified', current_time( 'mysql' ) ); |
354 | 354 | |
355 | - return parent::save(); |
|
356 | - } |
|
355 | + return parent::save(); |
|
356 | + } |
|
357 | 357 | |
358 | 358 | /** |
359 | - * Helper method to clone a customer from a user ID. |
|
360 | - * |
|
361 | - * @since 1.0.0 |
|
362 | - * @param int $user_id. |
|
363 | - */ |
|
364 | - public function clone_user( $user_id ) { |
|
359 | + * Helper method to clone a customer from a user ID. |
|
360 | + * |
|
361 | + * @since 1.0.0 |
|
362 | + * @param int $user_id. |
|
363 | + */ |
|
364 | + public function clone_user( $user_id ) { |
|
365 | 365 | $user = get_userdata( $user_id ); |
366 | 366 | |
367 | 367 | if ( empty( $user ) ) { |
368 | 368 | return; |
369 | 369 | } |
370 | 370 | |
371 | - $this->set_user_id( $user->ID ); |
|
371 | + $this->set_user_id( $user->ID ); |
|
372 | 372 | $this->set_email( $user->user_email ); |
373 | 373 | $this->set_purchase_value( getpaid_get_user_total_spend( $user->ID ) ); |
374 | 374 | $this->set_purchase_count( getpaid_count_user_invoices( $user->ID ) ); |
@@ -397,18 +397,18 @@ discard block |
||
397 | 397 | continue; |
398 | 398 | } |
399 | 399 | } |
400 | - } |
|
401 | - } |
|
400 | + } |
|
401 | + } |
|
402 | 402 | |
403 | 403 | /** |
404 | - * Helper method to migrate an existing user ID to the new customers table. |
|
405 | - * |
|
406 | - * @since 1.0.0 |
|
407 | - * @param int $user_id. |
|
408 | - */ |
|
409 | - public function migrate_from_user( $user_id ) { |
|
404 | + * Helper method to migrate an existing user ID to the new customers table. |
|
405 | + * |
|
406 | + * @since 1.0.0 |
|
407 | + * @param int $user_id. |
|
408 | + */ |
|
409 | + public function migrate_from_user( $user_id ) { |
|
410 | 410 | $this->clone_user( $user_id ); |
411 | 411 | do_action( 'getpaid_customer_migrated_from_user', $this, $user_id ); |
412 | 412 | $this->save(); |
413 | - } |
|
413 | + } |
|
414 | 414 | } |
@@ -14,31 +14,31 @@ discard block |
||
14 | 14 | class WPInv_Invoice extends GetPaid_Data { |
15 | 15 | |
16 | 16 | /** |
17 | - * Which data store to load. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
17 | + * Which data store to load. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | 21 | protected $data_store_name = 'invoice'; |
22 | 22 | |
23 | 23 | /** |
24 | - * This is the name of this object type. |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
24 | + * This is the name of this object type. |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | 28 | protected $object_type = 'invoice'; |
29 | 29 | |
30 | 30 | /** |
31 | - * Item Data array. This is the core item data exposed in APIs. |
|
32 | - * |
|
33 | - * @since 1.0.19 |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - protected $data = array( |
|
37 | - 'parent_id' => 0, |
|
38 | - 'customer_id' => 0, |
|
39 | - 'status' => 'wpi-pending', |
|
40 | - 'version' => '', |
|
41 | - 'date_created' => null, |
|
31 | + * Item Data array. This is the core item data exposed in APIs. |
|
32 | + * |
|
33 | + * @since 1.0.19 |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + protected $data = array( |
|
37 | + 'parent_id' => 0, |
|
38 | + 'customer_id' => 0, |
|
39 | + 'status' => 'wpi-pending', |
|
40 | + 'version' => '', |
|
41 | + 'date_created' => null, |
|
42 | 42 | 'date_modified' => null, |
43 | 43 | 'due_date' => null, |
44 | 44 | 'completed_date' => null, |
@@ -61,17 +61,17 @@ discard block |
||
61 | 61 | 'state' => null, |
62 | 62 | 'zip' => null, |
63 | 63 | 'company' => null, |
64 | - 'company_id' => null, |
|
64 | + 'company_id' => null, |
|
65 | 65 | 'vat_number' => null, |
66 | 66 | 'vat_rate' => null, |
67 | 67 | 'address' => null, |
68 | 68 | 'address_confirmed' => false, |
69 | 69 | 'shipping' => null, |
70 | - 'subtotal' => 0, |
|
70 | + 'subtotal' => 0, |
|
71 | 71 | 'total_discount' => 0, |
72 | 72 | 'total_tax' => 0, |
73 | - 'total_fees' => 0, |
|
74 | - 'total' => 0, |
|
73 | + 'total_fees' => 0, |
|
74 | + 'total' => 0, |
|
75 | 75 | 'fees' => array(), |
76 | 76 | 'discounts' => array(), |
77 | 77 | 'taxes' => array(), |
@@ -83,22 +83,22 @@ discard block |
||
83 | 83 | 'transaction_id' => '', |
84 | 84 | 'currency' => '', |
85 | 85 | 'disable_taxes' => false, |
86 | - 'subscription_id' => null, |
|
87 | - 'remote_subscription_id' => null, |
|
88 | - 'is_viewed' => false, |
|
89 | - 'email_cc' => '', |
|
90 | - 'template' => 'quantity', // hours, amount only |
|
91 | - 'created_via' => null, |
|
86 | + 'subscription_id' => null, |
|
87 | + 'remote_subscription_id' => null, |
|
88 | + 'is_viewed' => false, |
|
89 | + 'email_cc' => '', |
|
90 | + 'template' => 'quantity', // hours, amount only |
|
91 | + 'created_via' => null, |
|
92 | 92 | ); |
93 | 93 | |
94 | 94 | /** |
95 | - * Stores meta in cache for future reads. |
|
96 | - * |
|
97 | - * A group must be set to to enable caching. |
|
98 | - * |
|
99 | - * @var string |
|
100 | - */ |
|
101 | - protected $cache_group = 'getpaid_invoices'; |
|
95 | + * Stores meta in cache for future reads. |
|
96 | + * |
|
97 | + * A group must be set to to enable caching. |
|
98 | + * |
|
99 | + * @var string |
|
100 | + */ |
|
101 | + protected $cache_group = 'getpaid_invoices'; |
|
102 | 102 | |
103 | 103 | /** |
104 | 104 | * Stores a reference to the original WP_Post object |
@@ -112,110 +112,110 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @var int |
114 | 114 | */ |
115 | - protected $recurring_item = null; |
|
115 | + protected $recurring_item = null; |
|
116 | 116 | |
117 | - /** |
|
117 | + /** |
|
118 | 118 | * Stores an array of item totals. |
119 | - * |
|
120 | - * e.g $totals['discount'] = array( |
|
121 | - * 'initial' => 10, |
|
122 | - * 'recurring' => 10, |
|
123 | - * ) |
|
119 | + * |
|
120 | + * e.g $totals['discount'] = array( |
|
121 | + * 'initial' => 10, |
|
122 | + * 'recurring' => 10, |
|
123 | + * ) |
|
124 | 124 | * |
125 | 125 | * @var array |
126 | 126 | */ |
127 | - protected $totals = array(); |
|
127 | + protected $totals = array(); |
|
128 | 128 | |
129 | - /** |
|
129 | + /** |
|
130 | 130 | * Tax rate. |
131 | - * |
|
131 | + * |
|
132 | 132 | * @var float |
133 | 133 | */ |
134 | - protected $tax_rate = 0; |
|
134 | + protected $tax_rate = 0; |
|
135 | 135 | |
136 | - /** |
|
137 | - * Stores the status transition information. |
|
138 | - * |
|
139 | - * @since 1.0.19 |
|
140 | - * @var bool|array |
|
141 | - */ |
|
142 | - protected $status_transition = false; |
|
136 | + /** |
|
137 | + * Stores the status transition information. |
|
138 | + * |
|
139 | + * @since 1.0.19 |
|
140 | + * @var bool|array |
|
141 | + */ |
|
142 | + protected $status_transition = false; |
|
143 | 143 | |
144 | 144 | /** |
145 | - * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
146 | - * |
|
147 | - * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read. |
|
148 | - */ |
|
145 | + * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
146 | + * |
|
147 | + * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read. |
|
148 | + */ |
|
149 | 149 | public function __construct( $invoice = 0 ) { |
150 | 150 | |
151 | 151 | parent::__construct( $invoice ); |
152 | 152 | |
153 | - if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( (int) $invoice ) ) ) { |
|
154 | - $this->set_id( (int) $invoice ); |
|
155 | - } elseif ( $invoice instanceof self ) { |
|
156 | - $this->set_id( $invoice->get_id() ); |
|
157 | - } elseif ( ! empty( $invoice->ID ) ) { |
|
158 | - $this->set_id( $invoice->ID ); |
|
159 | - } elseif ( is_array( $invoice ) ) { |
|
160 | - $this->set_props( $invoice ); |
|
161 | - |
|
162 | - if ( isset( $invoice['ID'] ) ) { |
|
163 | - $this->set_id( $invoice['ID'] ); |
|
164 | - } |
|
153 | + if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( (int) $invoice ) ) ) { |
|
154 | + $this->set_id( (int) $invoice ); |
|
155 | + } elseif ( $invoice instanceof self ) { |
|
156 | + $this->set_id( $invoice->get_id() ); |
|
157 | + } elseif ( ! empty( $invoice->ID ) ) { |
|
158 | + $this->set_id( $invoice->ID ); |
|
159 | + } elseif ( is_array( $invoice ) ) { |
|
160 | + $this->set_props( $invoice ); |
|
161 | + |
|
162 | + if ( isset( $invoice['ID'] ) ) { |
|
163 | + $this->set_id( $invoice['ID'] ); |
|
164 | + } |
|
165 | 165 | } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) { |
166 | - $this->set_id( $invoice_id ); |
|
167 | - } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
168 | - $this->set_id( $invoice_id ); |
|
169 | - } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
170 | - $this->set_id( $invoice_id ); |
|
171 | - } else { |
|
172 | - $this->set_object_read( true ); |
|
173 | - } |
|
166 | + $this->set_id( $invoice_id ); |
|
167 | + } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
168 | + $this->set_id( $invoice_id ); |
|
169 | + } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
170 | + $this->set_id( $invoice_id ); |
|
171 | + } else { |
|
172 | + $this->set_object_read( true ); |
|
173 | + } |
|
174 | 174 | |
175 | 175 | // Load the datastore. |
176 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
176 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
177 | 177 | |
178 | - if ( $this->get_id() > 0 ) { |
|
178 | + if ( $this->get_id() > 0 ) { |
|
179 | 179 | $this->post = get_post( $this->get_id() ); |
180 | 180 | $this->ID = $this->get_id(); |
181 | - $this->data_store->read( $this ); |
|
181 | + $this->data_store->read( $this ); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
187 | - * Given an invoice key/number, it returns its id. |
|
188 | - * |
|
189 | - * |
|
190 | - * @static |
|
191 | - * @param string $value The invoice key or number |
|
192 | - * @param string $field Either key, transaction_id or number. |
|
193 | - * @since 1.0.15 |
|
194 | - * @return int |
|
195 | - */ |
|
196 | - public static function get_invoice_id_by_field( $value, $field = 'key' ) { |
|
187 | + * Given an invoice key/number, it returns its id. |
|
188 | + * |
|
189 | + * |
|
190 | + * @static |
|
191 | + * @param string $value The invoice key or number |
|
192 | + * @param string $field Either key, transaction_id or number. |
|
193 | + * @since 1.0.15 |
|
194 | + * @return int |
|
195 | + */ |
|
196 | + public static function get_invoice_id_by_field( $value, $field = 'key' ) { |
|
197 | 197 | global $wpdb; |
198 | 198 | |
199 | - // Trim the value. |
|
200 | - $value = trim( $value ); |
|
199 | + // Trim the value. |
|
200 | + $value = trim( $value ); |
|
201 | 201 | |
202 | - if ( empty( $value ) ) { |
|
203 | - return 0; |
|
204 | - } |
|
202 | + if ( empty( $value ) ) { |
|
203 | + return 0; |
|
204 | + } |
|
205 | 205 | |
206 | 206 | // Valid fields. |
207 | 207 | $fields = array( 'key', 'number', 'transaction_id' ); |
208 | 208 | |
209 | - // Ensure a field has been passed. |
|
210 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
211 | - return 0; |
|
212 | - } |
|
209 | + // Ensure a field has been passed. |
|
210 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
211 | + return 0; |
|
212 | + } |
|
213 | 213 | |
214 | - // Maybe retrieve from the cache. |
|
215 | - $invoice_id = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
216 | - if ( false !== $invoice_id ) { |
|
217 | - return $invoice_id; |
|
218 | - } |
|
214 | + // Maybe retrieve from the cache. |
|
215 | + $invoice_id = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
216 | + if ( false !== $invoice_id ) { |
|
217 | + return $invoice_id; |
|
218 | + } |
|
219 | 219 | |
220 | 220 | // Fetch from the db. |
221 | 221 | $table = $wpdb->prefix . 'getpaid_invoices'; |
@@ -223,10 +223,10 @@ discard block |
||
223 | 223 | $wpdb->prepare( "SELECT `post_id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
224 | 224 | ); |
225 | 225 | |
226 | - // Update the cache with our data |
|
227 | - wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
226 | + // Update the cache with our data |
|
227 | + wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
228 | 228 | |
229 | - return $invoice_id; |
|
229 | + return $invoice_id; |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -252,83 +252,83 @@ discard block |
||
252 | 252 | */ |
253 | 253 | |
254 | 254 | /** |
255 | - * Get parent invoice ID. |
|
256 | - * |
|
257 | - * @since 1.0.19 |
|
258 | - * @param string $context View or edit context. |
|
259 | - * @return int |
|
260 | - */ |
|
261 | - public function get_parent_id( $context = 'view' ) { |
|
262 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
255 | + * Get parent invoice ID. |
|
256 | + * |
|
257 | + * @since 1.0.19 |
|
258 | + * @param string $context View or edit context. |
|
259 | + * @return int |
|
260 | + */ |
|
261 | + public function get_parent_id( $context = 'view' ) { |
|
262 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
266 | - * Get parent invoice. |
|
267 | - * |
|
268 | - * @since 1.0.19 |
|
269 | - * @return WPInv_Invoice |
|
270 | - */ |
|
266 | + * Get parent invoice. |
|
267 | + * |
|
268 | + * @since 1.0.19 |
|
269 | + * @return WPInv_Invoice |
|
270 | + */ |
|
271 | 271 | public function get_parent_payment() { |
272 | 272 | return new WPInv_Invoice( $this->get_parent_id() ); |
273 | 273 | } |
274 | 274 | |
275 | 275 | /** |
276 | - * Alias for self::get_parent_payment(). |
|
277 | - * |
|
278 | - * @since 1.0.19 |
|
279 | - * @return WPInv_Invoice |
|
280 | - */ |
|
276 | + * Alias for self::get_parent_payment(). |
|
277 | + * |
|
278 | + * @since 1.0.19 |
|
279 | + * @return WPInv_Invoice |
|
280 | + */ |
|
281 | 281 | public function get_parent() { |
282 | 282 | return $this->get_parent_payment(); |
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
286 | - * Get invoice status. |
|
287 | - * |
|
288 | - * @since 1.0.19 |
|
289 | - * @param string $context View or edit context. |
|
290 | - * @return string |
|
291 | - */ |
|
292 | - public function get_status( $context = 'view' ) { |
|
293 | - return $this->get_prop( 'status', $context ); |
|
294 | - } |
|
286 | + * Get invoice status. |
|
287 | + * |
|
288 | + * @since 1.0.19 |
|
289 | + * @param string $context View or edit context. |
|
290 | + * @return string |
|
291 | + */ |
|
292 | + public function get_status( $context = 'view' ) { |
|
293 | + return $this->get_prop( 'status', $context ); |
|
294 | + } |
|
295 | 295 | |
296 | - /** |
|
297 | - * Retrieves an array of possible invoice statuses. |
|
298 | - * |
|
299 | - * @since 1.0.19 |
|
300 | - * @return array |
|
301 | - */ |
|
302 | - public function get_all_statuses() { |
|
303 | - return wpinv_get_invoice_statuses( true, true, $this ); |
|
296 | + /** |
|
297 | + * Retrieves an array of possible invoice statuses. |
|
298 | + * |
|
299 | + * @since 1.0.19 |
|
300 | + * @return array |
|
301 | + */ |
|
302 | + public function get_all_statuses() { |
|
303 | + return wpinv_get_invoice_statuses( true, true, $this ); |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | /** |
307 | - * Get invoice status nice name. |
|
308 | - * |
|
309 | - * @since 1.0.19 |
|
310 | - * @return string |
|
311 | - */ |
|
307 | + * Get invoice status nice name. |
|
308 | + * |
|
309 | + * @since 1.0.19 |
|
310 | + * @return string |
|
311 | + */ |
|
312 | 312 | public function get_status_nicename() { |
313 | - $statuses = $this->get_all_statuses(); |
|
313 | + $statuses = $this->get_all_statuses(); |
|
314 | 314 | |
315 | 315 | $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status(); |
316 | 316 | |
317 | 317 | return apply_filters( 'wpinv_get_invoice_status_nicename', $status, $this ); |
318 | 318 | } |
319 | 319 | |
320 | - /** |
|
321 | - * Retrieves the invoice status class |
|
322 | - * |
|
323 | - * @since 1.0.19 |
|
324 | - * @return string |
|
325 | - */ |
|
326 | - public function get_status_class() { |
|
327 | - $statuses = getpaid_get_invoice_status_classes(); |
|
328 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark'; |
|
329 | - } |
|
320 | + /** |
|
321 | + * Retrieves the invoice status class |
|
322 | + * |
|
323 | + * @since 1.0.19 |
|
324 | + * @return string |
|
325 | + */ |
|
326 | + public function get_status_class() { |
|
327 | + $statuses = getpaid_get_invoice_status_classes(); |
|
328 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark'; |
|
329 | + } |
|
330 | 330 | |
331 | - /** |
|
331 | + /** |
|
332 | 332 | * Retrieves the invoice status label html |
333 | 333 | * |
334 | 334 | * @since 1.0.0 |
@@ -336,263 +336,263 @@ discard block |
||
336 | 336 | */ |
337 | 337 | public function get_status_label_html() { |
338 | 338 | |
339 | - $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
340 | - $status = sanitize_html_class( $this->get_status() ); |
|
341 | - $class = esc_attr( $this->get_status_class() ); |
|
342 | - |
|
343 | - return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Get plugin version when the invoice was created. |
|
348 | - * |
|
349 | - * @since 1.0.19 |
|
350 | - * @param string $context View or edit context. |
|
351 | - * @return string |
|
352 | - */ |
|
353 | - public function get_version( $context = 'view' ) { |
|
354 | - return $this->get_prop( 'version', $context ); |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * @deprecated |
|
359 | - */ |
|
360 | - public function get_invoice_date( $format = true ) { |
|
361 | - $date = getpaid_format_date( $this->get_date_completed() ); |
|
362 | - $date = empty( $date ) ? $this->get_date_created() : $this->get_date_completed(); |
|
363 | - $formatted = getpaid_format_date( $date ); |
|
364 | - |
|
365 | - if ( $format ) { |
|
366 | - return $formatted; |
|
367 | - } |
|
368 | - |
|
369 | - return empty( $formatted ) ? '' : $date; |
|
370 | - |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * Get date when the invoice was created. |
|
375 | - * |
|
376 | - * @since 1.0.19 |
|
377 | - * @param string $context View or edit context. |
|
378 | - * @return string |
|
379 | - */ |
|
380 | - public function get_date_created( $context = 'view' ) { |
|
381 | - return $this->get_prop( 'date_created', $context ); |
|
382 | - } |
|
383 | - |
|
384 | - /** |
|
385 | - * Alias for self::get_date_created(). |
|
386 | - * |
|
387 | - * @since 1.0.19 |
|
388 | - * @param string $context View or edit context. |
|
389 | - * @return string |
|
390 | - */ |
|
391 | - public function get_created_date( $context = 'view' ) { |
|
392 | - return $this->get_date_created( $context ); |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Get GMT date when the invoice was created. |
|
397 | - * |
|
398 | - * @since 1.0.19 |
|
399 | - * @param string $context View or edit context. |
|
400 | - * @return string |
|
401 | - */ |
|
402 | - public function get_date_created_gmt( $context = 'view' ) { |
|
339 | + $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
340 | + $status = sanitize_html_class( $this->get_status() ); |
|
341 | + $class = esc_attr( $this->get_status_class() ); |
|
342 | + |
|
343 | + return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Get plugin version when the invoice was created. |
|
348 | + * |
|
349 | + * @since 1.0.19 |
|
350 | + * @param string $context View or edit context. |
|
351 | + * @return string |
|
352 | + */ |
|
353 | + public function get_version( $context = 'view' ) { |
|
354 | + return $this->get_prop( 'version', $context ); |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * @deprecated |
|
359 | + */ |
|
360 | + public function get_invoice_date( $format = true ) { |
|
361 | + $date = getpaid_format_date( $this->get_date_completed() ); |
|
362 | + $date = empty( $date ) ? $this->get_date_created() : $this->get_date_completed(); |
|
363 | + $formatted = getpaid_format_date( $date ); |
|
364 | + |
|
365 | + if ( $format ) { |
|
366 | + return $formatted; |
|
367 | + } |
|
368 | + |
|
369 | + return empty( $formatted ) ? '' : $date; |
|
370 | + |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * Get date when the invoice was created. |
|
375 | + * |
|
376 | + * @since 1.0.19 |
|
377 | + * @param string $context View or edit context. |
|
378 | + * @return string |
|
379 | + */ |
|
380 | + public function get_date_created( $context = 'view' ) { |
|
381 | + return $this->get_prop( 'date_created', $context ); |
|
382 | + } |
|
383 | + |
|
384 | + /** |
|
385 | + * Alias for self::get_date_created(). |
|
386 | + * |
|
387 | + * @since 1.0.19 |
|
388 | + * @param string $context View or edit context. |
|
389 | + * @return string |
|
390 | + */ |
|
391 | + public function get_created_date( $context = 'view' ) { |
|
392 | + return $this->get_date_created( $context ); |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Get GMT date when the invoice was created. |
|
397 | + * |
|
398 | + * @since 1.0.19 |
|
399 | + * @param string $context View or edit context. |
|
400 | + * @return string |
|
401 | + */ |
|
402 | + public function get_date_created_gmt( $context = 'view' ) { |
|
403 | 403 | $date = $this->get_date_created( $context ); |
404 | 404 | |
405 | 405 | if ( $date ) { |
406 | 406 | $date = get_gmt_from_date( $date ); |
407 | 407 | } |
408 | - return $date; |
|
408 | + return $date; |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | /** |
412 | - * Get date when the invoice was last modified. |
|
413 | - * |
|
414 | - * @since 1.0.19 |
|
415 | - * @param string $context View or edit context. |
|
416 | - * @return string |
|
417 | - */ |
|
418 | - public function get_date_modified( $context = 'view' ) { |
|
419 | - return $this->get_prop( 'date_modified', $context ); |
|
420 | - } |
|
412 | + * Get date when the invoice was last modified. |
|
413 | + * |
|
414 | + * @since 1.0.19 |
|
415 | + * @param string $context View or edit context. |
|
416 | + * @return string |
|
417 | + */ |
|
418 | + public function get_date_modified( $context = 'view' ) { |
|
419 | + return $this->get_prop( 'date_modified', $context ); |
|
420 | + } |
|
421 | 421 | |
422 | - /** |
|
423 | - * Alias for self::get_date_modified(). |
|
424 | - * |
|
425 | - * @since 1.0.19 |
|
426 | - * @param string $context View or edit context. |
|
427 | - * @return string |
|
428 | - */ |
|
429 | - public function get_modified_date( $context = 'view' ) { |
|
430 | - return $this->get_date_modified( $context ); |
|
422 | + /** |
|
423 | + * Alias for self::get_date_modified(). |
|
424 | + * |
|
425 | + * @since 1.0.19 |
|
426 | + * @param string $context View or edit context. |
|
427 | + * @return string |
|
428 | + */ |
|
429 | + public function get_modified_date( $context = 'view' ) { |
|
430 | + return $this->get_date_modified( $context ); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | /** |
434 | - * Get GMT date when the invoice was last modified. |
|
435 | - * |
|
436 | - * @since 1.0.19 |
|
437 | - * @param string $context View or edit context. |
|
438 | - * @return string |
|
439 | - */ |
|
440 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
434 | + * Get GMT date when the invoice was last modified. |
|
435 | + * |
|
436 | + * @since 1.0.19 |
|
437 | + * @param string $context View or edit context. |
|
438 | + * @return string |
|
439 | + */ |
|
440 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
441 | 441 | $date = $this->get_date_modified( $context ); |
442 | 442 | |
443 | 443 | if ( $date ) { |
444 | 444 | $date = get_gmt_from_date( $date ); |
445 | 445 | } |
446 | - return $date; |
|
446 | + return $date; |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
450 | - * Get the invoice due date. |
|
451 | - * |
|
452 | - * @since 1.0.19 |
|
453 | - * @param string $context View or edit context. |
|
454 | - * @return string |
|
455 | - */ |
|
456 | - public function get_due_date( $context = 'view' ) { |
|
457 | - return $this->get_prop( 'due_date', $context ); |
|
450 | + * Get the invoice due date. |
|
451 | + * |
|
452 | + * @since 1.0.19 |
|
453 | + * @param string $context View or edit context. |
|
454 | + * @return string |
|
455 | + */ |
|
456 | + public function get_due_date( $context = 'view' ) { |
|
457 | + return $this->get_prop( 'due_date', $context ); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | /** |
461 | - * Alias for self::get_due_date(). |
|
462 | - * |
|
463 | - * @since 1.0.19 |
|
464 | - * @param string $context View or edit context. |
|
465 | - * @return string |
|
466 | - */ |
|
467 | - public function get_date_due( $context = 'view' ) { |
|
468 | - return $this->get_due_date( $context ); |
|
461 | + * Alias for self::get_due_date(). |
|
462 | + * |
|
463 | + * @since 1.0.19 |
|
464 | + * @param string $context View or edit context. |
|
465 | + * @return string |
|
466 | + */ |
|
467 | + public function get_date_due( $context = 'view' ) { |
|
468 | + return $this->get_due_date( $context ); |
|
469 | 469 | } |
470 | 470 | |
471 | 471 | /** |
472 | - * Get the invoice GMT due date. |
|
473 | - * |
|
474 | - * @since 1.0.19 |
|
475 | - * @param string $context View or edit context. |
|
476 | - * @return string |
|
477 | - */ |
|
478 | - public function get_due_date_gmt( $context = 'view' ) { |
|
472 | + * Get the invoice GMT due date. |
|
473 | + * |
|
474 | + * @since 1.0.19 |
|
475 | + * @param string $context View or edit context. |
|
476 | + * @return string |
|
477 | + */ |
|
478 | + public function get_due_date_gmt( $context = 'view' ) { |
|
479 | 479 | $date = $this->get_due_date( $context ); |
480 | 480 | |
481 | 481 | if ( $date ) { |
482 | 482 | $date = get_gmt_from_date( $date ); |
483 | 483 | } |
484 | - return $date; |
|
484 | + return $date; |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
488 | - * Alias for self::get_due_date_gmt(). |
|
489 | - * |
|
490 | - * @since 1.0.19 |
|
491 | - * @param string $context View or edit context. |
|
492 | - * @return string |
|
493 | - */ |
|
494 | - public function get_gmt_date_due( $context = 'view' ) { |
|
495 | - return $this->get_due_date_gmt( $context ); |
|
488 | + * Alias for self::get_due_date_gmt(). |
|
489 | + * |
|
490 | + * @since 1.0.19 |
|
491 | + * @param string $context View or edit context. |
|
492 | + * @return string |
|
493 | + */ |
|
494 | + public function get_gmt_date_due( $context = 'view' ) { |
|
495 | + return $this->get_due_date_gmt( $context ); |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | /** |
499 | - * Get date when the invoice was completed. |
|
500 | - * |
|
501 | - * @since 1.0.19 |
|
502 | - * @param string $context View or edit context. |
|
503 | - * @return string |
|
504 | - */ |
|
505 | - public function get_completed_date( $context = 'view' ) { |
|
506 | - return $this->get_prop( 'completed_date', $context ); |
|
499 | + * Get date when the invoice was completed. |
|
500 | + * |
|
501 | + * @since 1.0.19 |
|
502 | + * @param string $context View or edit context. |
|
503 | + * @return string |
|
504 | + */ |
|
505 | + public function get_completed_date( $context = 'view' ) { |
|
506 | + return $this->get_prop( 'completed_date', $context ); |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | /** |
510 | - * Alias for self::get_completed_date(). |
|
511 | - * |
|
512 | - * @since 1.0.19 |
|
513 | - * @param string $context View or edit context. |
|
514 | - * @return string |
|
515 | - */ |
|
516 | - public function get_date_completed( $context = 'view' ) { |
|
517 | - return $this->get_completed_date( $context ); |
|
510 | + * Alias for self::get_completed_date(). |
|
511 | + * |
|
512 | + * @since 1.0.19 |
|
513 | + * @param string $context View or edit context. |
|
514 | + * @return string |
|
515 | + */ |
|
516 | + public function get_date_completed( $context = 'view' ) { |
|
517 | + return $this->get_completed_date( $context ); |
|
518 | 518 | } |
519 | 519 | |
520 | 520 | /** |
521 | - * Get GMT date when the invoice was was completed. |
|
522 | - * |
|
523 | - * @since 1.0.19 |
|
524 | - * @param string $context View or edit context. |
|
525 | - * @return string |
|
526 | - */ |
|
527 | - public function get_completed_date_gmt( $context = 'view' ) { |
|
521 | + * Get GMT date when the invoice was was completed. |
|
522 | + * |
|
523 | + * @since 1.0.19 |
|
524 | + * @param string $context View or edit context. |
|
525 | + * @return string |
|
526 | + */ |
|
527 | + public function get_completed_date_gmt( $context = 'view' ) { |
|
528 | 528 | $date = $this->get_completed_date( $context ); |
529 | 529 | |
530 | 530 | if ( $date ) { |
531 | 531 | $date = get_gmt_from_date( $date ); |
532 | 532 | } |
533 | - return $date; |
|
533 | + return $date; |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | /** |
537 | - * Alias for self::get_completed_date_gmt(). |
|
538 | - * |
|
539 | - * @since 1.0.19 |
|
540 | - * @param string $context View or edit context. |
|
541 | - * @return string |
|
542 | - */ |
|
543 | - public function get_gmt_completed_date( $context = 'view' ) { |
|
544 | - return $this->get_completed_date_gmt( $context ); |
|
537 | + * Alias for self::get_completed_date_gmt(). |
|
538 | + * |
|
539 | + * @since 1.0.19 |
|
540 | + * @param string $context View or edit context. |
|
541 | + * @return string |
|
542 | + */ |
|
543 | + public function get_gmt_completed_date( $context = 'view' ) { |
|
544 | + return $this->get_completed_date_gmt( $context ); |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | /** |
548 | - * Get the invoice number. |
|
549 | - * |
|
550 | - * @since 1.0.19 |
|
551 | - * @param string $context View or edit context. |
|
552 | - * @return string |
|
553 | - */ |
|
554 | - public function get_number( $context = 'view' ) { |
|
555 | - $number = $this->get_prop( 'number', $context ); |
|
548 | + * Get the invoice number. |
|
549 | + * |
|
550 | + * @since 1.0.19 |
|
551 | + * @param string $context View or edit context. |
|
552 | + * @return string |
|
553 | + */ |
|
554 | + public function get_number( $context = 'view' ) { |
|
555 | + $number = $this->get_prop( 'number', $context ); |
|
556 | 556 | |
557 | - if ( empty( $number ) ) { |
|
558 | - $number = $this->generate_number(); |
|
559 | - $this->set_number( $this->generate_number() ); |
|
560 | - } |
|
557 | + if ( empty( $number ) ) { |
|
558 | + $number = $this->generate_number(); |
|
559 | + $this->set_number( $this->generate_number() ); |
|
560 | + } |
|
561 | 561 | |
562 | - return $number; |
|
562 | + return $number; |
|
563 | 563 | } |
564 | 564 | |
565 | - /** |
|
566 | - * Set the invoice number. |
|
567 | - * |
|
568 | - * @since 1.0.19 |
|
569 | - */ |
|
570 | - public function maybe_set_number() { |
|
565 | + /** |
|
566 | + * Set the invoice number. |
|
567 | + * |
|
568 | + * @since 1.0.19 |
|
569 | + */ |
|
570 | + public function maybe_set_number() { |
|
571 | 571 | $number = $this->get_number(); |
572 | 572 | |
573 | 573 | if ( empty( $number ) || $this->get_id() == $number ) { |
574 | - $this->set_number( $this->generate_number() ); |
|
574 | + $this->set_number( $this->generate_number() ); |
|
575 | 575 | } |
576 | 576 | |
577 | - } |
|
577 | + } |
|
578 | 578 | |
579 | 579 | /** |
580 | - * Get the invoice key. |
|
581 | - * |
|
582 | - * @since 1.0.19 |
|
583 | - * @param string $context View or edit context. |
|
584 | - * @return string |
|
585 | - */ |
|
586 | - public function get_key( $context = 'view' ) { |
|
580 | + * Get the invoice key. |
|
581 | + * |
|
582 | + * @since 1.0.19 |
|
583 | + * @param string $context View or edit context. |
|
584 | + * @return string |
|
585 | + */ |
|
586 | + public function get_key( $context = 'view' ) { |
|
587 | 587 | return $this->get_prop( 'key', $context ); |
588 | - } |
|
589 | - |
|
590 | - /** |
|
591 | - * Set the invoice key. |
|
592 | - * |
|
593 | - * @since 1.0.19 |
|
594 | - */ |
|
595 | - public function maybe_set_key() { |
|
588 | + } |
|
589 | + |
|
590 | + /** |
|
591 | + * Set the invoice key. |
|
592 | + * |
|
593 | + * @since 1.0.19 |
|
594 | + */ |
|
595 | + public function maybe_set_key() { |
|
596 | 596 | $key = $this->get_key(); |
597 | 597 | |
598 | 598 | if ( empty( $key ) ) { |
@@ -603,140 +603,140 @@ discard block |
||
603 | 603 | } |
604 | 604 | |
605 | 605 | /** |
606 | - * Get the invoice type. |
|
607 | - * |
|
608 | - * @since 1.0.19 |
|
609 | - * @param string $context View or edit context. |
|
610 | - * @return string |
|
611 | - */ |
|
612 | - public function get_type( $context = 'view' ) { |
|
606 | + * Get the invoice type. |
|
607 | + * |
|
608 | + * @since 1.0.19 |
|
609 | + * @param string $context View or edit context. |
|
610 | + * @return string |
|
611 | + */ |
|
612 | + public function get_type( $context = 'view' ) { |
|
613 | 613 | return $this->get_prop( 'type', $context ); |
614 | - } |
|
615 | - |
|
616 | - /** |
|
617 | - * Returns the post type name. |
|
618 | - * |
|
619 | - * @since 1.0.19 |
|
620 | - * @return string |
|
621 | - */ |
|
622 | - public function get_invoice_quote_type() { |
|
614 | + } |
|
615 | + |
|
616 | + /** |
|
617 | + * Returns the post type name. |
|
618 | + * |
|
619 | + * @since 1.0.19 |
|
620 | + * @return string |
|
621 | + */ |
|
622 | + public function get_invoice_quote_type() { |
|
623 | 623 | return getpaid_get_post_type_label( $this->get_post_type(), false ); |
624 | 624 | } |
625 | 625 | |
626 | 626 | /** |
627 | - * Get the invoice post type label. |
|
628 | - * |
|
629 | - * @since 1.0.19 |
|
630 | - * @param string $context View or edit context. |
|
631 | - * @return string |
|
632 | - */ |
|
633 | - public function get_label( $context = 'view' ) { |
|
627 | + * Get the invoice post type label. |
|
628 | + * |
|
629 | + * @since 1.0.19 |
|
630 | + * @param string $context View or edit context. |
|
631 | + * @return string |
|
632 | + */ |
|
633 | + public function get_label( $context = 'view' ) { |
|
634 | 634 | return getpaid_get_post_type_label( $this->get_post_type( $context ), false ); |
635 | - } |
|
636 | - |
|
637 | - /** |
|
638 | - * Get the invoice post type. |
|
639 | - * |
|
640 | - * @since 1.0.19 |
|
641 | - * @param string $context View or edit context. |
|
642 | - * @return string |
|
643 | - */ |
|
644 | - public function get_post_type( $context = 'view' ) { |
|
635 | + } |
|
636 | + |
|
637 | + /** |
|
638 | + * Get the invoice post type. |
|
639 | + * |
|
640 | + * @since 1.0.19 |
|
641 | + * @param string $context View or edit context. |
|
642 | + * @return string |
|
643 | + */ |
|
644 | + public function get_post_type( $context = 'view' ) { |
|
645 | 645 | return $this->get_prop( 'post_type', $context ); |
646 | 646 | } |
647 | 647 | |
648 | 648 | /** |
649 | - * Get the invoice mode. |
|
650 | - * |
|
651 | - * @since 1.0.19 |
|
652 | - * @param string $context View or edit context. |
|
653 | - * @return string |
|
654 | - */ |
|
655 | - public function get_mode( $context = 'view' ) { |
|
649 | + * Get the invoice mode. |
|
650 | + * |
|
651 | + * @since 1.0.19 |
|
652 | + * @param string $context View or edit context. |
|
653 | + * @return string |
|
654 | + */ |
|
655 | + public function get_mode( $context = 'view' ) { |
|
656 | 656 | return $this->get_prop( 'mode', $context ); |
657 | 657 | } |
658 | 658 | |
659 | 659 | /** |
660 | - * Get the invoice path. |
|
661 | - * |
|
662 | - * @since 1.0.19 |
|
663 | - * @param string $context View or edit context. |
|
664 | - * @return string |
|
665 | - */ |
|
666 | - public function get_path( $context = 'view' ) { |
|
660 | + * Get the invoice path. |
|
661 | + * |
|
662 | + * @since 1.0.19 |
|
663 | + * @param string $context View or edit context. |
|
664 | + * @return string |
|
665 | + */ |
|
666 | + public function get_path( $context = 'view' ) { |
|
667 | 667 | $path = $this->get_prop( 'path', $context ); |
668 | - $prefix = $this->get_type(); |
|
668 | + $prefix = $this->get_type(); |
|
669 | 669 | |
670 | - if ( 0 !== strpos( $path, $prefix ) ) { |
|
671 | - $path = sanitize_title( $prefix . '-' . $this->get_id() ); |
|
672 | - $this->set_path( $path ); |
|
673 | - } |
|
670 | + if ( 0 !== strpos( $path, $prefix ) ) { |
|
671 | + $path = sanitize_title( $prefix . '-' . $this->get_id() ); |
|
672 | + $this->set_path( $path ); |
|
673 | + } |
|
674 | 674 | |
675 | - return $path; |
|
675 | + return $path; |
|
676 | 676 | } |
677 | 677 | |
678 | 678 | /** |
679 | - * Get the invoice name/title. |
|
680 | - * |
|
681 | - * @since 1.0.19 |
|
682 | - * @param string $context View or edit context. |
|
683 | - * @return string |
|
684 | - */ |
|
685 | - public function get_name( $context = 'view' ) { |
|
679 | + * Get the invoice name/title. |
|
680 | + * |
|
681 | + * @since 1.0.19 |
|
682 | + * @param string $context View or edit context. |
|
683 | + * @return string |
|
684 | + */ |
|
685 | + public function get_name( $context = 'view' ) { |
|
686 | 686 | return $this->get_prop( 'title', $context ); |
687 | 687 | } |
688 | 688 | |
689 | 689 | /** |
690 | - * Alias of self::get_name(). |
|
691 | - * |
|
692 | - * @since 1.0.19 |
|
693 | - * @param string $context View or edit context. |
|
694 | - * @return string |
|
695 | - */ |
|
696 | - public function get_title( $context = 'view' ) { |
|
697 | - return $this->get_name( $context ); |
|
690 | + * Alias of self::get_name(). |
|
691 | + * |
|
692 | + * @since 1.0.19 |
|
693 | + * @param string $context View or edit context. |
|
694 | + * @return string |
|
695 | + */ |
|
696 | + public function get_title( $context = 'view' ) { |
|
697 | + return $this->get_name( $context ); |
|
698 | 698 | } |
699 | 699 | |
700 | 700 | /** |
701 | - * Get the invoice description. |
|
702 | - * |
|
703 | - * @since 1.0.19 |
|
704 | - * @param string $context View or edit context. |
|
705 | - * @return string |
|
706 | - */ |
|
707 | - public function get_description( $context = 'view' ) { |
|
708 | - return $this->get_prop( 'description', $context ); |
|
701 | + * Get the invoice description. |
|
702 | + * |
|
703 | + * @since 1.0.19 |
|
704 | + * @param string $context View or edit context. |
|
705 | + * @return string |
|
706 | + */ |
|
707 | + public function get_description( $context = 'view' ) { |
|
708 | + return $this->get_prop( 'description', $context ); |
|
709 | 709 | } |
710 | 710 | |
711 | 711 | /** |
712 | - * Alias of self::get_description(). |
|
713 | - * |
|
714 | - * @since 1.0.19 |
|
715 | - * @param string $context View or edit context. |
|
716 | - * @return string |
|
717 | - */ |
|
718 | - public function get_excerpt( $context = 'view' ) { |
|
719 | - return $this->get_description( $context ); |
|
712 | + * Alias of self::get_description(). |
|
713 | + * |
|
714 | + * @since 1.0.19 |
|
715 | + * @param string $context View or edit context. |
|
716 | + * @return string |
|
717 | + */ |
|
718 | + public function get_excerpt( $context = 'view' ) { |
|
719 | + return $this->get_description( $context ); |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | /** |
723 | - * Alias of self::get_description(). |
|
724 | - * |
|
725 | - * @since 1.0.19 |
|
726 | - * @param string $context View or edit context. |
|
727 | - * @return string |
|
728 | - */ |
|
729 | - public function get_summary( $context = 'view' ) { |
|
730 | - return $this->get_description( $context ); |
|
723 | + * Alias of self::get_description(). |
|
724 | + * |
|
725 | + * @since 1.0.19 |
|
726 | + * @param string $context View or edit context. |
|
727 | + * @return string |
|
728 | + */ |
|
729 | + public function get_summary( $context = 'view' ) { |
|
730 | + return $this->get_description( $context ); |
|
731 | 731 | } |
732 | 732 | |
733 | 733 | /** |
734 | - * Returns the user info. |
|
735 | - * |
|
736 | - * @since 1.0.19 |
|
734 | + * Returns the user info. |
|
735 | + * |
|
736 | + * @since 1.0.19 |
|
737 | 737 | * @param string $context View or edit context. |
738 | - * @return array |
|
739 | - */ |
|
738 | + * @return array |
|
739 | + */ |
|
740 | 740 | public function get_user_info( $context = 'view' ) { |
741 | 741 | |
742 | 742 | $user_info = array( |
@@ -751,683 +751,683 @@ discard block |
||
751 | 751 | 'state' => $this->get_state( $context ), |
752 | 752 | 'zip' => $this->get_zip( $context ), |
753 | 753 | 'company' => $this->get_company( $context ), |
754 | - 'company_id' => $this->get_company_id( $context ), |
|
754 | + 'company_id' => $this->get_company_id( $context ), |
|
755 | 755 | 'vat_number' => $this->get_vat_number( $context ), |
756 | 756 | 'discount' => $this->get_discount_code( $context ), |
757 | - ); |
|
757 | + ); |
|
758 | 758 | |
759 | - return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
759 | + return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
760 | 760 | |
761 | 761 | } |
762 | 762 | |
763 | 763 | /** |
764 | - * Get the user id. |
|
765 | - * |
|
766 | - * @since 1.0.19 |
|
767 | - * @param string $context View or edit context. |
|
768 | - * @return int |
|
769 | - */ |
|
770 | - public function get_author( $context = 'view' ) { |
|
771 | - return (int) $this->get_prop( 'author', $context ); |
|
764 | + * Get the user id. |
|
765 | + * |
|
766 | + * @since 1.0.19 |
|
767 | + * @param string $context View or edit context. |
|
768 | + * @return int |
|
769 | + */ |
|
770 | + public function get_author( $context = 'view' ) { |
|
771 | + return (int) $this->get_prop( 'author', $context ); |
|
772 | 772 | } |
773 | 773 | |
774 | 774 | /** |
775 | - * Alias of self::get_author(). |
|
776 | - * |
|
777 | - * @since 1.0.19 |
|
778 | - * @param string $context View or edit context. |
|
779 | - * @return int |
|
780 | - */ |
|
781 | - public function get_user_id( $context = 'view' ) { |
|
782 | - return $this->get_author( $context ); |
|
775 | + * Alias of self::get_author(). |
|
776 | + * |
|
777 | + * @since 1.0.19 |
|
778 | + * @param string $context View or edit context. |
|
779 | + * @return int |
|
780 | + */ |
|
781 | + public function get_user_id( $context = 'view' ) { |
|
782 | + return $this->get_author( $context ); |
|
783 | 783 | } |
784 | 784 | |
785 | - /** |
|
786 | - * Get customer ID. |
|
787 | - * |
|
788 | - * @since 1.0.19 |
|
789 | - * @param string $context View or edit context. |
|
790 | - * @return int |
|
791 | - */ |
|
792 | - public function get_customer_id( $context = 'view' ) { |
|
793 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
785 | + /** |
|
786 | + * Get customer ID. |
|
787 | + * |
|
788 | + * @since 1.0.19 |
|
789 | + * @param string $context View or edit context. |
|
790 | + * @return int |
|
791 | + */ |
|
792 | + public function get_customer_id( $context = 'view' ) { |
|
793 | + return (int) $this->get_prop( 'customer_id', $context ); |
|
794 | 794 | } |
795 | 795 | |
796 | 796 | /** |
797 | - * Get the customer's ip. |
|
798 | - * |
|
799 | - * @since 1.0.19 |
|
800 | - * @param string $context View or edit context. |
|
801 | - * @return string |
|
802 | - */ |
|
803 | - public function get_ip( $context = 'view' ) { |
|
804 | - return $this->get_prop( 'user_ip', $context ); |
|
797 | + * Get the customer's ip. |
|
798 | + * |
|
799 | + * @since 1.0.19 |
|
800 | + * @param string $context View or edit context. |
|
801 | + * @return string |
|
802 | + */ |
|
803 | + public function get_ip( $context = 'view' ) { |
|
804 | + return $this->get_prop( 'user_ip', $context ); |
|
805 | 805 | } |
806 | 806 | |
807 | 807 | /** |
808 | - * Alias of self::get_ip(). |
|
809 | - * |
|
810 | - * @since 1.0.19 |
|
811 | - * @param string $context View or edit context. |
|
812 | - * @return string |
|
813 | - */ |
|
814 | - public function get_user_ip( $context = 'view' ) { |
|
815 | - return $this->get_ip( $context ); |
|
808 | + * Alias of self::get_ip(). |
|
809 | + * |
|
810 | + * @since 1.0.19 |
|
811 | + * @param string $context View or edit context. |
|
812 | + * @return string |
|
813 | + */ |
|
814 | + public function get_user_ip( $context = 'view' ) { |
|
815 | + return $this->get_ip( $context ); |
|
816 | 816 | } |
817 | 817 | |
818 | - /** |
|
819 | - * Alias of self::get_ip(). |
|
820 | - * |
|
821 | - * @since 1.0.19 |
|
822 | - * @param string $context View or edit context. |
|
823 | - * @return string |
|
824 | - */ |
|
825 | - public function get_customer_ip( $context = 'view' ) { |
|
826 | - return $this->get_ip( $context ); |
|
818 | + /** |
|
819 | + * Alias of self::get_ip(). |
|
820 | + * |
|
821 | + * @since 1.0.19 |
|
822 | + * @param string $context View or edit context. |
|
823 | + * @return string |
|
824 | + */ |
|
825 | + public function get_customer_ip( $context = 'view' ) { |
|
826 | + return $this->get_ip( $context ); |
|
827 | 827 | } |
828 | 828 | |
829 | 829 | /** |
830 | - * Get the customer's first name. |
|
831 | - * |
|
832 | - * @since 1.0.19 |
|
833 | - * @param string $context View or edit context. |
|
834 | - * @return string |
|
835 | - */ |
|
836 | - public function get_first_name( $context = 'view' ) { |
|
837 | - return $this->get_prop( 'first_name', $context ); |
|
830 | + * Get the customer's first name. |
|
831 | + * |
|
832 | + * @since 1.0.19 |
|
833 | + * @param string $context View or edit context. |
|
834 | + * @return string |
|
835 | + */ |
|
836 | + public function get_first_name( $context = 'view' ) { |
|
837 | + return $this->get_prop( 'first_name', $context ); |
|
838 | 838 | } |
839 | 839 | |
840 | 840 | /** |
841 | - * Alias of self::get_first_name(). |
|
842 | - * |
|
843 | - * @since 1.0.19 |
|
844 | - * @param string $context View or edit context. |
|
845 | - * @return string |
|
846 | - */ |
|
847 | - public function get_user_first_name( $context = 'view' ) { |
|
848 | - return $this->get_first_name( $context ); |
|
841 | + * Alias of self::get_first_name(). |
|
842 | + * |
|
843 | + * @since 1.0.19 |
|
844 | + * @param string $context View or edit context. |
|
845 | + * @return string |
|
846 | + */ |
|
847 | + public function get_user_first_name( $context = 'view' ) { |
|
848 | + return $this->get_first_name( $context ); |
|
849 | 849 | } |
850 | 850 | |
851 | - /** |
|
852 | - * Alias of self::get_first_name(). |
|
853 | - * |
|
854 | - * @since 1.0.19 |
|
855 | - * @param string $context View or edit context. |
|
856 | - * @return string |
|
857 | - */ |
|
858 | - public function get_customer_first_name( $context = 'view' ) { |
|
859 | - return $this->get_first_name( $context ); |
|
851 | + /** |
|
852 | + * Alias of self::get_first_name(). |
|
853 | + * |
|
854 | + * @since 1.0.19 |
|
855 | + * @param string $context View or edit context. |
|
856 | + * @return string |
|
857 | + */ |
|
858 | + public function get_customer_first_name( $context = 'view' ) { |
|
859 | + return $this->get_first_name( $context ); |
|
860 | 860 | } |
861 | 861 | |
862 | 862 | /** |
863 | - * Get the customer's last name. |
|
864 | - * |
|
865 | - * @since 1.0.19 |
|
866 | - * @param string $context View or edit context. |
|
867 | - * @return string |
|
868 | - */ |
|
869 | - public function get_last_name( $context = 'view' ) { |
|
870 | - return $this->get_prop( 'last_name', $context ); |
|
863 | + * Get the customer's last name. |
|
864 | + * |
|
865 | + * @since 1.0.19 |
|
866 | + * @param string $context View or edit context. |
|
867 | + * @return string |
|
868 | + */ |
|
869 | + public function get_last_name( $context = 'view' ) { |
|
870 | + return $this->get_prop( 'last_name', $context ); |
|
871 | 871 | } |
872 | 872 | |
873 | 873 | /** |
874 | - * Alias of self::get_last_name(). |
|
875 | - * |
|
876 | - * @since 1.0.19 |
|
877 | - * @param string $context View or edit context. |
|
878 | - * @return string |
|
879 | - */ |
|
880 | - public function get_user_last_name( $context = 'view' ) { |
|
881 | - return $this->get_last_name( $context ); |
|
874 | + * Alias of self::get_last_name(). |
|
875 | + * |
|
876 | + * @since 1.0.19 |
|
877 | + * @param string $context View or edit context. |
|
878 | + * @return string |
|
879 | + */ |
|
880 | + public function get_user_last_name( $context = 'view' ) { |
|
881 | + return $this->get_last_name( $context ); |
|
882 | 882 | } |
883 | 883 | |
884 | 884 | /** |
885 | - * Alias of self::get_last_name(). |
|
886 | - * |
|
887 | - * @since 1.0.19 |
|
888 | - * @param string $context View or edit context. |
|
889 | - * @return string |
|
890 | - */ |
|
891 | - public function get_customer_last_name( $context = 'view' ) { |
|
892 | - return $this->get_last_name( $context ); |
|
885 | + * Alias of self::get_last_name(). |
|
886 | + * |
|
887 | + * @since 1.0.19 |
|
888 | + * @param string $context View or edit context. |
|
889 | + * @return string |
|
890 | + */ |
|
891 | + public function get_customer_last_name( $context = 'view' ) { |
|
892 | + return $this->get_last_name( $context ); |
|
893 | 893 | } |
894 | 894 | |
895 | 895 | /** |
896 | - * Get the customer's full name. |
|
897 | - * |
|
898 | - * @since 1.0.19 |
|
899 | - * @param string $context View or edit context. |
|
900 | - * @return string |
|
901 | - */ |
|
902 | - public function get_full_name( $context = 'view' ) { |
|
903 | - $name = trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
896 | + * Get the customer's full name. |
|
897 | + * |
|
898 | + * @since 1.0.19 |
|
899 | + * @param string $context View or edit context. |
|
900 | + * @return string |
|
901 | + */ |
|
902 | + public function get_full_name( $context = 'view' ) { |
|
903 | + $name = trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
904 | 904 | |
905 | - if ( ! $name ) { |
|
906 | - $user = get_userdata( $this->get_author( $context ) ); |
|
905 | + if ( ! $name ) { |
|
906 | + $user = get_userdata( $this->get_author( $context ) ); |
|
907 | 907 | |
908 | - if ( $user ) { |
|
909 | - $name = $user->display_name; |
|
910 | - } |
|
911 | - } |
|
908 | + if ( $user ) { |
|
909 | + $name = $user->display_name; |
|
910 | + } |
|
911 | + } |
|
912 | 912 | |
913 | - if ( ! $name ) { |
|
914 | - $name = $this->get_email( $context ); |
|
915 | - } |
|
913 | + if ( ! $name ) { |
|
914 | + $name = $this->get_email( $context ); |
|
915 | + } |
|
916 | 916 | |
917 | - return apply_filters( 'wpinv_invoice_user_full_name', $name, $this ); |
|
917 | + return apply_filters( 'wpinv_invoice_user_full_name', $name, $this ); |
|
918 | 918 | } |
919 | 919 | |
920 | 920 | /** |
921 | - * Alias of self::get_full_name(). |
|
922 | - * |
|
923 | - * @since 1.0.19 |
|
924 | - * @param string $context View or edit context. |
|
925 | - * @return string |
|
926 | - */ |
|
927 | - public function get_user_full_name( $context = 'view' ) { |
|
928 | - return $this->get_full_name( $context ); |
|
921 | + * Alias of self::get_full_name(). |
|
922 | + * |
|
923 | + * @since 1.0.19 |
|
924 | + * @param string $context View or edit context. |
|
925 | + * @return string |
|
926 | + */ |
|
927 | + public function get_user_full_name( $context = 'view' ) { |
|
928 | + return $this->get_full_name( $context ); |
|
929 | 929 | } |
930 | 930 | |
931 | 931 | /** |
932 | - * Alias of self::get_full_name(). |
|
933 | - * |
|
934 | - * @since 1.0.19 |
|
935 | - * @param string $context View or edit context. |
|
936 | - * @return string |
|
937 | - */ |
|
938 | - public function get_customer_full_name( $context = 'view' ) { |
|
939 | - return $this->get_full_name( $context ); |
|
932 | + * Alias of self::get_full_name(). |
|
933 | + * |
|
934 | + * @since 1.0.19 |
|
935 | + * @param string $context View or edit context. |
|
936 | + * @return string |
|
937 | + */ |
|
938 | + public function get_customer_full_name( $context = 'view' ) { |
|
939 | + return $this->get_full_name( $context ); |
|
940 | 940 | } |
941 | 941 | |
942 | 942 | /** |
943 | - * Get the customer's phone number. |
|
944 | - * |
|
945 | - * @since 1.0.19 |
|
946 | - * @param string $context View or edit context. |
|
947 | - * @return string |
|
948 | - */ |
|
949 | - public function get_phone( $context = 'view' ) { |
|
950 | - return $this->get_prop( 'phone', $context ); |
|
943 | + * Get the customer's phone number. |
|
944 | + * |
|
945 | + * @since 1.0.19 |
|
946 | + * @param string $context View or edit context. |
|
947 | + * @return string |
|
948 | + */ |
|
949 | + public function get_phone( $context = 'view' ) { |
|
950 | + return $this->get_prop( 'phone', $context ); |
|
951 | 951 | } |
952 | 952 | |
953 | 953 | /** |
954 | - * Alias of self::get_phone(). |
|
955 | - * |
|
956 | - * @since 1.0.19 |
|
957 | - * @param string $context View or edit context. |
|
958 | - * @return string |
|
959 | - */ |
|
960 | - public function get_phone_number( $context = 'view' ) { |
|
961 | - return $this->get_phone( $context ); |
|
954 | + * Alias of self::get_phone(). |
|
955 | + * |
|
956 | + * @since 1.0.19 |
|
957 | + * @param string $context View or edit context. |
|
958 | + * @return string |
|
959 | + */ |
|
960 | + public function get_phone_number( $context = 'view' ) { |
|
961 | + return $this->get_phone( $context ); |
|
962 | 962 | } |
963 | 963 | |
964 | 964 | /** |
965 | - * Alias of self::get_phone(). |
|
966 | - * |
|
967 | - * @since 1.0.19 |
|
968 | - * @param string $context View or edit context. |
|
969 | - * @return string |
|
970 | - */ |
|
971 | - public function get_user_phone( $context = 'view' ) { |
|
972 | - return $this->get_phone( $context ); |
|
965 | + * Alias of self::get_phone(). |
|
966 | + * |
|
967 | + * @since 1.0.19 |
|
968 | + * @param string $context View or edit context. |
|
969 | + * @return string |
|
970 | + */ |
|
971 | + public function get_user_phone( $context = 'view' ) { |
|
972 | + return $this->get_phone( $context ); |
|
973 | 973 | } |
974 | 974 | |
975 | 975 | /** |
976 | - * Alias of self::get_phone(). |
|
977 | - * |
|
978 | - * @since 1.0.19 |
|
979 | - * @param string $context View or edit context. |
|
980 | - * @return string |
|
981 | - */ |
|
982 | - public function get_customer_phone( $context = 'view' ) { |
|
983 | - return $this->get_phone( $context ); |
|
976 | + * Alias of self::get_phone(). |
|
977 | + * |
|
978 | + * @since 1.0.19 |
|
979 | + * @param string $context View or edit context. |
|
980 | + * @return string |
|
981 | + */ |
|
982 | + public function get_customer_phone( $context = 'view' ) { |
|
983 | + return $this->get_phone( $context ); |
|
984 | 984 | } |
985 | 985 | |
986 | 986 | /** |
987 | - * Get the customer's email address. |
|
988 | - * |
|
989 | - * @since 1.0.19 |
|
990 | - * @param string $context View or edit context. |
|
991 | - * @return string |
|
992 | - */ |
|
993 | - public function get_email( $context = 'view' ) { |
|
994 | - return $this->get_prop( 'email', $context ); |
|
987 | + * Get the customer's email address. |
|
988 | + * |
|
989 | + * @since 1.0.19 |
|
990 | + * @param string $context View or edit context. |
|
991 | + * @return string |
|
992 | + */ |
|
993 | + public function get_email( $context = 'view' ) { |
|
994 | + return $this->get_prop( 'email', $context ); |
|
995 | 995 | } |
996 | 996 | |
997 | 997 | /** |
998 | - * Alias of self::get_email(). |
|
999 | - * |
|
1000 | - * @since 1.0.19 |
|
1001 | - * @param string $context View or edit context. |
|
1002 | - * @return string |
|
1003 | - */ |
|
1004 | - public function get_email_address( $context = 'view' ) { |
|
1005 | - return $this->get_email( $context ); |
|
998 | + * Alias of self::get_email(). |
|
999 | + * |
|
1000 | + * @since 1.0.19 |
|
1001 | + * @param string $context View or edit context. |
|
1002 | + * @return string |
|
1003 | + */ |
|
1004 | + public function get_email_address( $context = 'view' ) { |
|
1005 | + return $this->get_email( $context ); |
|
1006 | 1006 | } |
1007 | 1007 | |
1008 | 1008 | /** |
1009 | - * Alias of self::get_email(). |
|
1010 | - * |
|
1011 | - * @since 1.0.19 |
|
1012 | - * @param string $context View or edit context. |
|
1013 | - * @return string |
|
1014 | - */ |
|
1015 | - public function get_user_email( $context = 'view' ) { |
|
1016 | - return $this->get_email( $context ); |
|
1009 | + * Alias of self::get_email(). |
|
1010 | + * |
|
1011 | + * @since 1.0.19 |
|
1012 | + * @param string $context View or edit context. |
|
1013 | + * @return string |
|
1014 | + */ |
|
1015 | + public function get_user_email( $context = 'view' ) { |
|
1016 | + return $this->get_email( $context ); |
|
1017 | 1017 | } |
1018 | 1018 | |
1019 | 1019 | /** |
1020 | - * Alias of self::get_email(). |
|
1021 | - * |
|
1022 | - * @since 1.0.19 |
|
1023 | - * @param string $context View or edit context. |
|
1024 | - * @return string |
|
1025 | - */ |
|
1026 | - public function get_customer_email( $context = 'view' ) { |
|
1027 | - return $this->get_email( $context ); |
|
1020 | + * Alias of self::get_email(). |
|
1021 | + * |
|
1022 | + * @since 1.0.19 |
|
1023 | + * @param string $context View or edit context. |
|
1024 | + * @return string |
|
1025 | + */ |
|
1026 | + public function get_customer_email( $context = 'view' ) { |
|
1027 | + return $this->get_email( $context ); |
|
1028 | 1028 | } |
1029 | 1029 | |
1030 | 1030 | /** |
1031 | - * Get the customer's country. |
|
1032 | - * |
|
1033 | - * @since 1.0.19 |
|
1034 | - * @param string $context View or edit context. |
|
1035 | - * @return string |
|
1036 | - */ |
|
1037 | - public function get_country( $context = 'view' ) { |
|
1038 | - $country = $this->get_prop( 'country', $context ); |
|
1039 | - return empty( $country ) ? wpinv_get_default_country() : $country; |
|
1031 | + * Get the customer's country. |
|
1032 | + * |
|
1033 | + * @since 1.0.19 |
|
1034 | + * @param string $context View or edit context. |
|
1035 | + * @return string |
|
1036 | + */ |
|
1037 | + public function get_country( $context = 'view' ) { |
|
1038 | + $country = $this->get_prop( 'country', $context ); |
|
1039 | + return empty( $country ) ? wpinv_get_default_country() : $country; |
|
1040 | 1040 | } |
1041 | 1041 | |
1042 | 1042 | /** |
1043 | - * Alias of self::get_country(). |
|
1044 | - * |
|
1045 | - * @since 1.0.19 |
|
1046 | - * @param string $context View or edit context. |
|
1047 | - * @return string |
|
1048 | - */ |
|
1049 | - public function get_user_country( $context = 'view' ) { |
|
1050 | - return $this->get_country( $context ); |
|
1043 | + * Alias of self::get_country(). |
|
1044 | + * |
|
1045 | + * @since 1.0.19 |
|
1046 | + * @param string $context View or edit context. |
|
1047 | + * @return string |
|
1048 | + */ |
|
1049 | + public function get_user_country( $context = 'view' ) { |
|
1050 | + return $this->get_country( $context ); |
|
1051 | 1051 | } |
1052 | 1052 | |
1053 | 1053 | /** |
1054 | - * Alias of self::get_country(). |
|
1055 | - * |
|
1056 | - * @since 1.0.19 |
|
1057 | - * @param string $context View or edit context. |
|
1058 | - * @return string |
|
1059 | - */ |
|
1060 | - public function get_customer_country( $context = 'view' ) { |
|
1061 | - return $this->get_country( $context ); |
|
1054 | + * Alias of self::get_country(). |
|
1055 | + * |
|
1056 | + * @since 1.0.19 |
|
1057 | + * @param string $context View or edit context. |
|
1058 | + * @return string |
|
1059 | + */ |
|
1060 | + public function get_customer_country( $context = 'view' ) { |
|
1061 | + return $this->get_country( $context ); |
|
1062 | 1062 | } |
1063 | 1063 | |
1064 | 1064 | /** |
1065 | - * Get the customer's state. |
|
1066 | - * |
|
1067 | - * @since 1.0.19 |
|
1068 | - * @param string $context View or edit context. |
|
1069 | - * @return string |
|
1070 | - */ |
|
1071 | - public function get_state( $context = 'view' ) { |
|
1072 | - $state = $this->get_prop( 'state', $context ); |
|
1073 | - return empty( $state ) ? wpinv_get_default_state() : $state; |
|
1065 | + * Get the customer's state. |
|
1066 | + * |
|
1067 | + * @since 1.0.19 |
|
1068 | + * @param string $context View or edit context. |
|
1069 | + * @return string |
|
1070 | + */ |
|
1071 | + public function get_state( $context = 'view' ) { |
|
1072 | + $state = $this->get_prop( 'state', $context ); |
|
1073 | + return empty( $state ) ? wpinv_get_default_state() : $state; |
|
1074 | 1074 | } |
1075 | 1075 | |
1076 | 1076 | /** |
1077 | - * Alias of self::get_state(). |
|
1078 | - * |
|
1079 | - * @since 1.0.19 |
|
1080 | - * @param string $context View or edit context. |
|
1081 | - * @return string |
|
1082 | - */ |
|
1083 | - public function get_user_state( $context = 'view' ) { |
|
1084 | - return $this->get_state( $context ); |
|
1077 | + * Alias of self::get_state(). |
|
1078 | + * |
|
1079 | + * @since 1.0.19 |
|
1080 | + * @param string $context View or edit context. |
|
1081 | + * @return string |
|
1082 | + */ |
|
1083 | + public function get_user_state( $context = 'view' ) { |
|
1084 | + return $this->get_state( $context ); |
|
1085 | 1085 | } |
1086 | 1086 | |
1087 | 1087 | /** |
1088 | - * Alias of self::get_state(). |
|
1089 | - * |
|
1090 | - * @since 1.0.19 |
|
1091 | - * @param string $context View or edit context. |
|
1092 | - * @return string |
|
1093 | - */ |
|
1094 | - public function get_customer_state( $context = 'view' ) { |
|
1095 | - return $this->get_state( $context ); |
|
1088 | + * Alias of self::get_state(). |
|
1089 | + * |
|
1090 | + * @since 1.0.19 |
|
1091 | + * @param string $context View or edit context. |
|
1092 | + * @return string |
|
1093 | + */ |
|
1094 | + public function get_customer_state( $context = 'view' ) { |
|
1095 | + return $this->get_state( $context ); |
|
1096 | 1096 | } |
1097 | 1097 | |
1098 | 1098 | /** |
1099 | - * Get the customer's city. |
|
1100 | - * |
|
1101 | - * @since 1.0.19 |
|
1102 | - * @param string $context View or edit context. |
|
1103 | - * @return string |
|
1104 | - */ |
|
1105 | - public function get_city( $context = 'view' ) { |
|
1106 | - return $this->get_prop( 'city', $context ); |
|
1099 | + * Get the customer's city. |
|
1100 | + * |
|
1101 | + * @since 1.0.19 |
|
1102 | + * @param string $context View or edit context. |
|
1103 | + * @return string |
|
1104 | + */ |
|
1105 | + public function get_city( $context = 'view' ) { |
|
1106 | + return $this->get_prop( 'city', $context ); |
|
1107 | 1107 | } |
1108 | 1108 | |
1109 | 1109 | /** |
1110 | - * Alias of self::get_city(). |
|
1111 | - * |
|
1112 | - * @since 1.0.19 |
|
1113 | - * @param string $context View or edit context. |
|
1114 | - * @return string |
|
1115 | - */ |
|
1116 | - public function get_user_city( $context = 'view' ) { |
|
1117 | - return $this->get_city( $context ); |
|
1110 | + * Alias of self::get_city(). |
|
1111 | + * |
|
1112 | + * @since 1.0.19 |
|
1113 | + * @param string $context View or edit context. |
|
1114 | + * @return string |
|
1115 | + */ |
|
1116 | + public function get_user_city( $context = 'view' ) { |
|
1117 | + return $this->get_city( $context ); |
|
1118 | 1118 | } |
1119 | 1119 | |
1120 | 1120 | /** |
1121 | - * Alias of self::get_city(). |
|
1122 | - * |
|
1123 | - * @since 1.0.19 |
|
1124 | - * @param string $context View or edit context. |
|
1125 | - * @return string |
|
1126 | - */ |
|
1127 | - public function get_customer_city( $context = 'view' ) { |
|
1128 | - return $this->get_city( $context ); |
|
1121 | + * Alias of self::get_city(). |
|
1122 | + * |
|
1123 | + * @since 1.0.19 |
|
1124 | + * @param string $context View or edit context. |
|
1125 | + * @return string |
|
1126 | + */ |
|
1127 | + public function get_customer_city( $context = 'view' ) { |
|
1128 | + return $this->get_city( $context ); |
|
1129 | 1129 | } |
1130 | 1130 | |
1131 | 1131 | /** |
1132 | - * Get the customer's zip. |
|
1133 | - * |
|
1134 | - * @since 1.0.19 |
|
1135 | - * @param string $context View or edit context. |
|
1136 | - * @return string |
|
1137 | - */ |
|
1138 | - public function get_zip( $context = 'view' ) { |
|
1139 | - return $this->get_prop( 'zip', $context ); |
|
1132 | + * Get the customer's zip. |
|
1133 | + * |
|
1134 | + * @since 1.0.19 |
|
1135 | + * @param string $context View or edit context. |
|
1136 | + * @return string |
|
1137 | + */ |
|
1138 | + public function get_zip( $context = 'view' ) { |
|
1139 | + return $this->get_prop( 'zip', $context ); |
|
1140 | 1140 | } |
1141 | 1141 | |
1142 | 1142 | /** |
1143 | - * Alias of self::get_zip(). |
|
1144 | - * |
|
1145 | - * @since 1.0.19 |
|
1146 | - * @param string $context View or edit context. |
|
1147 | - * @return string |
|
1148 | - */ |
|
1149 | - public function get_user_zip( $context = 'view' ) { |
|
1150 | - return $this->get_zip( $context ); |
|
1143 | + * Alias of self::get_zip(). |
|
1144 | + * |
|
1145 | + * @since 1.0.19 |
|
1146 | + * @param string $context View or edit context. |
|
1147 | + * @return string |
|
1148 | + */ |
|
1149 | + public function get_user_zip( $context = 'view' ) { |
|
1150 | + return $this->get_zip( $context ); |
|
1151 | 1151 | } |
1152 | 1152 | |
1153 | 1153 | /** |
1154 | - * Alias of self::get_zip(). |
|
1155 | - * |
|
1156 | - * @since 1.0.19 |
|
1157 | - * @param string $context View or edit context. |
|
1158 | - * @return string |
|
1159 | - */ |
|
1160 | - public function get_customer_zip( $context = 'view' ) { |
|
1161 | - return $this->get_zip( $context ); |
|
1154 | + * Alias of self::get_zip(). |
|
1155 | + * |
|
1156 | + * @since 1.0.19 |
|
1157 | + * @param string $context View or edit context. |
|
1158 | + * @return string |
|
1159 | + */ |
|
1160 | + public function get_customer_zip( $context = 'view' ) { |
|
1161 | + return $this->get_zip( $context ); |
|
1162 | 1162 | } |
1163 | 1163 | |
1164 | 1164 | /** |
1165 | - * Get the customer's company. |
|
1166 | - * |
|
1167 | - * @since 1.0.19 |
|
1168 | - * @param string $context View or edit context. |
|
1169 | - * @return string |
|
1170 | - */ |
|
1171 | - public function get_company( $context = 'view' ) { |
|
1172 | - return $this->get_prop( 'company', $context ); |
|
1165 | + * Get the customer's company. |
|
1166 | + * |
|
1167 | + * @since 1.0.19 |
|
1168 | + * @param string $context View or edit context. |
|
1169 | + * @return string |
|
1170 | + */ |
|
1171 | + public function get_company( $context = 'view' ) { |
|
1172 | + return $this->get_prop( 'company', $context ); |
|
1173 | 1173 | } |
1174 | 1174 | |
1175 | 1175 | /** |
1176 | - * Alias of self::get_company(). |
|
1177 | - * |
|
1178 | - * @since 1.0.19 |
|
1179 | - * @param string $context View or edit context. |
|
1180 | - * @return string |
|
1181 | - */ |
|
1182 | - public function get_user_company( $context = 'view' ) { |
|
1183 | - return $this->get_company( $context ); |
|
1176 | + * Alias of self::get_company(). |
|
1177 | + * |
|
1178 | + * @since 1.0.19 |
|
1179 | + * @param string $context View or edit context. |
|
1180 | + * @return string |
|
1181 | + */ |
|
1182 | + public function get_user_company( $context = 'view' ) { |
|
1183 | + return $this->get_company( $context ); |
|
1184 | + } |
|
1185 | + |
|
1186 | + /** |
|
1187 | + * Alias of self::get_company(). |
|
1188 | + * |
|
1189 | + * @since 1.0.19 |
|
1190 | + * @param string $context View or edit context. |
|
1191 | + * @return string |
|
1192 | + */ |
|
1193 | + public function get_customer_company( $context = 'view' ) { |
|
1194 | + return $this->get_company( $context ); |
|
1184 | 1195 | } |
1185 | 1196 | |
1186 | 1197 | /** |
1187 | - * Alias of self::get_company(). |
|
1188 | - * |
|
1189 | - * @since 1.0.19 |
|
1190 | - * @param string $context View or edit context. |
|
1191 | - * @return string |
|
1192 | - */ |
|
1193 | - public function get_customer_company( $context = 'view' ) { |
|
1194 | - return $this->get_company( $context ); |
|
1198 | + * Get the customer's company id. |
|
1199 | + * |
|
1200 | + * @since 1.0.19 |
|
1201 | + * @param string $context View or edit context. |
|
1202 | + * @return string |
|
1203 | + */ |
|
1204 | + public function get_company_id( $context = 'view' ) { |
|
1205 | + return $this->get_prop( 'company_id', $context ); |
|
1206 | + } |
|
1207 | + |
|
1208 | + /** |
|
1209 | + * Get the customer's vat number. |
|
1210 | + * |
|
1211 | + * @since 1.0.19 |
|
1212 | + * @param string $context View or edit context. |
|
1213 | + * @return string |
|
1214 | + */ |
|
1215 | + public function get_vat_number( $context = 'view' ) { |
|
1216 | + return $this->get_prop( 'vat_number', $context ); |
|
1195 | 1217 | } |
1196 | 1218 | |
1197 | - /** |
|
1198 | - * Get the customer's company id. |
|
1199 | - * |
|
1200 | - * @since 1.0.19 |
|
1201 | - * @param string $context View or edit context. |
|
1202 | - * @return string |
|
1203 | - */ |
|
1204 | - public function get_company_id( $context = 'view' ) { |
|
1205 | - return $this->get_prop( 'company_id', $context ); |
|
1219 | + /** |
|
1220 | + * Alias of self::get_vat_number(). |
|
1221 | + * |
|
1222 | + * @since 1.0.19 |
|
1223 | + * @param string $context View or edit context. |
|
1224 | + * @return string |
|
1225 | + */ |
|
1226 | + public function get_user_vat_number( $context = 'view' ) { |
|
1227 | + return $this->get_vat_number( $context ); |
|
1206 | 1228 | } |
1207 | 1229 | |
1208 | 1230 | /** |
1209 | - * Get the customer's vat number. |
|
1210 | - * |
|
1211 | - * @since 1.0.19 |
|
1212 | - * @param string $context View or edit context. |
|
1213 | - * @return string |
|
1214 | - */ |
|
1215 | - public function get_vat_number( $context = 'view' ) { |
|
1216 | - return $this->get_prop( 'vat_number', $context ); |
|
1231 | + * Alias of self::get_vat_number(). |
|
1232 | + * |
|
1233 | + * @since 1.0.19 |
|
1234 | + * @param string $context View or edit context. |
|
1235 | + * @return string |
|
1236 | + */ |
|
1237 | + public function get_customer_vat_number( $context = 'view' ) { |
|
1238 | + return $this->get_vat_number( $context ); |
|
1217 | 1239 | } |
1218 | 1240 | |
1219 | 1241 | /** |
1220 | - * Alias of self::get_vat_number(). |
|
1221 | - * |
|
1222 | - * @since 1.0.19 |
|
1223 | - * @param string $context View or edit context. |
|
1224 | - * @return string |
|
1225 | - */ |
|
1226 | - public function get_user_vat_number( $context = 'view' ) { |
|
1227 | - return $this->get_vat_number( $context ); |
|
1242 | + * Get the customer's vat rate. |
|
1243 | + * |
|
1244 | + * @since 1.0.19 |
|
1245 | + * @param string $context View or edit context. |
|
1246 | + * @return string |
|
1247 | + */ |
|
1248 | + public function get_vat_rate( $context = 'view' ) { |
|
1249 | + return $this->get_prop( 'vat_rate', $context ); |
|
1228 | 1250 | } |
1229 | 1251 | |
1230 | 1252 | /** |
1231 | - * Alias of self::get_vat_number(). |
|
1232 | - * |
|
1233 | - * @since 1.0.19 |
|
1234 | - * @param string $context View or edit context. |
|
1235 | - * @return string |
|
1236 | - */ |
|
1237 | - public function get_customer_vat_number( $context = 'view' ) { |
|
1238 | - return $this->get_vat_number( $context ); |
|
1253 | + * Alias of self::get_vat_rate(). |
|
1254 | + * |
|
1255 | + * @since 1.0.19 |
|
1256 | + * @param string $context View or edit context. |
|
1257 | + * @return string |
|
1258 | + */ |
|
1259 | + public function get_user_vat_rate( $context = 'view' ) { |
|
1260 | + return $this->get_vat_rate( $context ); |
|
1239 | 1261 | } |
1240 | 1262 | |
1241 | - /** |
|
1242 | - * Get the customer's vat rate. |
|
1243 | - * |
|
1244 | - * @since 1.0.19 |
|
1245 | - * @param string $context View or edit context. |
|
1246 | - * @return string |
|
1247 | - */ |
|
1248 | - public function get_vat_rate( $context = 'view' ) { |
|
1249 | - return $this->get_prop( 'vat_rate', $context ); |
|
1250 | - } |
|
1251 | - |
|
1252 | - /** |
|
1253 | - * Alias of self::get_vat_rate(). |
|
1254 | - * |
|
1255 | - * @since 1.0.19 |
|
1256 | - * @param string $context View or edit context. |
|
1257 | - * @return string |
|
1258 | - */ |
|
1259 | - public function get_user_vat_rate( $context = 'view' ) { |
|
1260 | - return $this->get_vat_rate( $context ); |
|
1261 | - } |
|
1262 | - |
|
1263 | - /** |
|
1264 | - * Alias of self::get_vat_rate(). |
|
1265 | - * |
|
1266 | - * @since 1.0.19 |
|
1267 | - * @param string $context View or edit context. |
|
1268 | - * @return string |
|
1269 | - */ |
|
1270 | - public function get_customer_vat_rate( $context = 'view' ) { |
|
1271 | - return $this->get_vat_rate( $context ); |
|
1272 | - } |
|
1273 | - |
|
1274 | - /** |
|
1275 | - * Get the customer's address. |
|
1276 | - * |
|
1277 | - * @since 1.0.19 |
|
1278 | - * @param string $context View or edit context. |
|
1279 | - * @return string |
|
1280 | - */ |
|
1281 | - public function get_address( $context = 'view' ) { |
|
1282 | - return $this->get_prop( 'address', $context ); |
|
1283 | - } |
|
1284 | - |
|
1285 | - /** |
|
1286 | - * Alias of self::get_address(). |
|
1287 | - * |
|
1288 | - * @since 1.0.19 |
|
1289 | - * @param string $context View or edit context. |
|
1290 | - * @return string |
|
1291 | - */ |
|
1292 | - public function get_user_address( $context = 'view' ) { |
|
1293 | - return $this->get_address( $context ); |
|
1294 | - } |
|
1295 | - |
|
1296 | - /** |
|
1297 | - * Alias of self::get_address(). |
|
1298 | - * |
|
1299 | - * @since 1.0.19 |
|
1300 | - * @param string $context View or edit context. |
|
1301 | - * @return string |
|
1302 | - */ |
|
1303 | - public function get_customer_address( $context = 'view' ) { |
|
1304 | - return $this->get_address( $context ); |
|
1305 | - } |
|
1306 | - |
|
1307 | - /** |
|
1308 | - * Get whether the customer has viewed the invoice or not. |
|
1309 | - * |
|
1310 | - * @since 1.0.19 |
|
1311 | - * @param string $context View or edit context. |
|
1312 | - * @return bool |
|
1313 | - */ |
|
1314 | - public function get_is_viewed( $context = 'view' ) { |
|
1315 | - return (bool) $this->get_prop( 'is_viewed', $context ); |
|
1316 | - } |
|
1317 | - |
|
1318 | - /** |
|
1319 | - * Get other recipients for invoice communications. |
|
1320 | - * |
|
1321 | - * @since 1.0.19 |
|
1322 | - * @param string $context View or edit context. |
|
1323 | - * @return bool |
|
1324 | - */ |
|
1325 | - public function get_email_cc( $context = 'view' ) { |
|
1326 | - return $this->get_prop( 'email_cc', $context ); |
|
1327 | - } |
|
1328 | - |
|
1329 | - /** |
|
1330 | - * Get invoice template. |
|
1331 | - * |
|
1332 | - * @since 1.0.19 |
|
1333 | - * @param string $context View or edit context. |
|
1334 | - * @return bool |
|
1335 | - */ |
|
1336 | - public function get_template( $context = 'view' ) { |
|
1337 | - return $this->get_prop( 'template', $context ); |
|
1338 | - } |
|
1339 | - |
|
1340 | - /** |
|
1341 | - * Get invoice source. |
|
1342 | - * |
|
1343 | - * @since 1.0.19 |
|
1344 | - * @param string $context View or edit context. |
|
1345 | - * @return bool |
|
1346 | - */ |
|
1347 | - public function get_created_via( $context = 'view' ) { |
|
1348 | - return $this->get_prop( 'created_via', $context ); |
|
1349 | - } |
|
1350 | - |
|
1351 | - /** |
|
1352 | - * Get whether the customer has confirmed their address. |
|
1353 | - * |
|
1354 | - * @since 1.0.19 |
|
1355 | - * @param string $context View or edit context. |
|
1356 | - * @return bool |
|
1357 | - */ |
|
1358 | - public function get_address_confirmed( $context = 'view' ) { |
|
1359 | - return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
1360 | - } |
|
1361 | - |
|
1362 | - /** |
|
1363 | - * Alias of self::get_address_confirmed(). |
|
1364 | - * |
|
1365 | - * @since 1.0.19 |
|
1366 | - * @param string $context View or edit context. |
|
1367 | - * @return bool |
|
1368 | - */ |
|
1369 | - public function get_user_address_confirmed( $context = 'view' ) { |
|
1370 | - return $this->get_address_confirmed( $context ); |
|
1371 | - } |
|
1372 | - |
|
1373 | - /** |
|
1374 | - * Alias of self::get_address(). |
|
1375 | - * |
|
1376 | - * @since 1.0.19 |
|
1377 | - * @param string $context View or edit context. |
|
1378 | - * @return bool |
|
1379 | - */ |
|
1380 | - public function get_customer_address_confirmed( $context = 'view' ) { |
|
1381 | - return $this->get_address_confirmed( $context ); |
|
1382 | - } |
|
1383 | - |
|
1384 | - /** |
|
1385 | - * Get the shipping address. |
|
1386 | - * |
|
1387 | - * @since 1.0.19 |
|
1388 | - * @return array|false |
|
1389 | - */ |
|
1390 | - public function get_shipping_address() { |
|
1391 | - |
|
1392 | - $shipping_address = get_post_meta( $this->get_id(), 'shipping_address', true ); |
|
1393 | - return is_array( $shipping_address ) ? $shipping_address : false; |
|
1394 | - } |
|
1395 | - |
|
1396 | - /** |
|
1397 | - * Check if the invoice has a shipping address. |
|
1398 | - */ |
|
1399 | - public function has_shipping_address() { |
|
1400 | - return false !== $this->get_shipping_address(); |
|
1401 | - } |
|
1402 | - |
|
1403 | - /** |
|
1404 | - * Get the shipping amount. |
|
1405 | - * |
|
1406 | - * @since 1.0.19 |
|
1407 | - * @param string $context View or edit context. |
|
1408 | - * @return float |
|
1409 | - */ |
|
1410 | - public function get_shipping( $context = 'view' ) { |
|
1411 | - |
|
1412 | - if ( $context = 'view' ) { |
|
1413 | - return floatval( $this->get_prop( 'shipping', $context ) ); |
|
1414 | - } |
|
1415 | - |
|
1416 | - return $this->get_prop( 'shipping', $context ); |
|
1417 | - } |
|
1418 | - |
|
1419 | - public function has_shipping() { |
|
1420 | - return defined( 'GETPAID_SHIPPING_CALCULATOR_VERSION' ) && null !== $this->get_prop( 'shipping', 'edit' ); |
|
1421 | - } |
|
1422 | - |
|
1423 | - /** |
|
1424 | - * Get the invoice subtotal. |
|
1425 | - * |
|
1426 | - * @since 1.0.19 |
|
1427 | - * @param string $context View or edit context. |
|
1428 | - * @return float |
|
1429 | - */ |
|
1430 | - public function get_subtotal( $context = 'view' ) { |
|
1263 | + /** |
|
1264 | + * Alias of self::get_vat_rate(). |
|
1265 | + * |
|
1266 | + * @since 1.0.19 |
|
1267 | + * @param string $context View or edit context. |
|
1268 | + * @return string |
|
1269 | + */ |
|
1270 | + public function get_customer_vat_rate( $context = 'view' ) { |
|
1271 | + return $this->get_vat_rate( $context ); |
|
1272 | + } |
|
1273 | + |
|
1274 | + /** |
|
1275 | + * Get the customer's address. |
|
1276 | + * |
|
1277 | + * @since 1.0.19 |
|
1278 | + * @param string $context View or edit context. |
|
1279 | + * @return string |
|
1280 | + */ |
|
1281 | + public function get_address( $context = 'view' ) { |
|
1282 | + return $this->get_prop( 'address', $context ); |
|
1283 | + } |
|
1284 | + |
|
1285 | + /** |
|
1286 | + * Alias of self::get_address(). |
|
1287 | + * |
|
1288 | + * @since 1.0.19 |
|
1289 | + * @param string $context View or edit context. |
|
1290 | + * @return string |
|
1291 | + */ |
|
1292 | + public function get_user_address( $context = 'view' ) { |
|
1293 | + return $this->get_address( $context ); |
|
1294 | + } |
|
1295 | + |
|
1296 | + /** |
|
1297 | + * Alias of self::get_address(). |
|
1298 | + * |
|
1299 | + * @since 1.0.19 |
|
1300 | + * @param string $context View or edit context. |
|
1301 | + * @return string |
|
1302 | + */ |
|
1303 | + public function get_customer_address( $context = 'view' ) { |
|
1304 | + return $this->get_address( $context ); |
|
1305 | + } |
|
1306 | + |
|
1307 | + /** |
|
1308 | + * Get whether the customer has viewed the invoice or not. |
|
1309 | + * |
|
1310 | + * @since 1.0.19 |
|
1311 | + * @param string $context View or edit context. |
|
1312 | + * @return bool |
|
1313 | + */ |
|
1314 | + public function get_is_viewed( $context = 'view' ) { |
|
1315 | + return (bool) $this->get_prop( 'is_viewed', $context ); |
|
1316 | + } |
|
1317 | + |
|
1318 | + /** |
|
1319 | + * Get other recipients for invoice communications. |
|
1320 | + * |
|
1321 | + * @since 1.0.19 |
|
1322 | + * @param string $context View or edit context. |
|
1323 | + * @return bool |
|
1324 | + */ |
|
1325 | + public function get_email_cc( $context = 'view' ) { |
|
1326 | + return $this->get_prop( 'email_cc', $context ); |
|
1327 | + } |
|
1328 | + |
|
1329 | + /** |
|
1330 | + * Get invoice template. |
|
1331 | + * |
|
1332 | + * @since 1.0.19 |
|
1333 | + * @param string $context View or edit context. |
|
1334 | + * @return bool |
|
1335 | + */ |
|
1336 | + public function get_template( $context = 'view' ) { |
|
1337 | + return $this->get_prop( 'template', $context ); |
|
1338 | + } |
|
1339 | + |
|
1340 | + /** |
|
1341 | + * Get invoice source. |
|
1342 | + * |
|
1343 | + * @since 1.0.19 |
|
1344 | + * @param string $context View or edit context. |
|
1345 | + * @return bool |
|
1346 | + */ |
|
1347 | + public function get_created_via( $context = 'view' ) { |
|
1348 | + return $this->get_prop( 'created_via', $context ); |
|
1349 | + } |
|
1350 | + |
|
1351 | + /** |
|
1352 | + * Get whether the customer has confirmed their address. |
|
1353 | + * |
|
1354 | + * @since 1.0.19 |
|
1355 | + * @param string $context View or edit context. |
|
1356 | + * @return bool |
|
1357 | + */ |
|
1358 | + public function get_address_confirmed( $context = 'view' ) { |
|
1359 | + return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
1360 | + } |
|
1361 | + |
|
1362 | + /** |
|
1363 | + * Alias of self::get_address_confirmed(). |
|
1364 | + * |
|
1365 | + * @since 1.0.19 |
|
1366 | + * @param string $context View or edit context. |
|
1367 | + * @return bool |
|
1368 | + */ |
|
1369 | + public function get_user_address_confirmed( $context = 'view' ) { |
|
1370 | + return $this->get_address_confirmed( $context ); |
|
1371 | + } |
|
1372 | + |
|
1373 | + /** |
|
1374 | + * Alias of self::get_address(). |
|
1375 | + * |
|
1376 | + * @since 1.0.19 |
|
1377 | + * @param string $context View or edit context. |
|
1378 | + * @return bool |
|
1379 | + */ |
|
1380 | + public function get_customer_address_confirmed( $context = 'view' ) { |
|
1381 | + return $this->get_address_confirmed( $context ); |
|
1382 | + } |
|
1383 | + |
|
1384 | + /** |
|
1385 | + * Get the shipping address. |
|
1386 | + * |
|
1387 | + * @since 1.0.19 |
|
1388 | + * @return array|false |
|
1389 | + */ |
|
1390 | + public function get_shipping_address() { |
|
1391 | + |
|
1392 | + $shipping_address = get_post_meta( $this->get_id(), 'shipping_address', true ); |
|
1393 | + return is_array( $shipping_address ) ? $shipping_address : false; |
|
1394 | + } |
|
1395 | + |
|
1396 | + /** |
|
1397 | + * Check if the invoice has a shipping address. |
|
1398 | + */ |
|
1399 | + public function has_shipping_address() { |
|
1400 | + return false !== $this->get_shipping_address(); |
|
1401 | + } |
|
1402 | + |
|
1403 | + /** |
|
1404 | + * Get the shipping amount. |
|
1405 | + * |
|
1406 | + * @since 1.0.19 |
|
1407 | + * @param string $context View or edit context. |
|
1408 | + * @return float |
|
1409 | + */ |
|
1410 | + public function get_shipping( $context = 'view' ) { |
|
1411 | + |
|
1412 | + if ( $context = 'view' ) { |
|
1413 | + return floatval( $this->get_prop( 'shipping', $context ) ); |
|
1414 | + } |
|
1415 | + |
|
1416 | + return $this->get_prop( 'shipping', $context ); |
|
1417 | + } |
|
1418 | + |
|
1419 | + public function has_shipping() { |
|
1420 | + return defined( 'GETPAID_SHIPPING_CALCULATOR_VERSION' ) && null !== $this->get_prop( 'shipping', 'edit' ); |
|
1421 | + } |
|
1422 | + |
|
1423 | + /** |
|
1424 | + * Get the invoice subtotal. |
|
1425 | + * |
|
1426 | + * @since 1.0.19 |
|
1427 | + * @param string $context View or edit context. |
|
1428 | + * @return float |
|
1429 | + */ |
|
1430 | + public function get_subtotal( $context = 'view' ) { |
|
1431 | 1431 | $subtotal = (float) $this->get_prop( 'subtotal', $context ); |
1432 | 1432 | |
1433 | 1433 | // Backwards compatibility. |
@@ -1439,198 +1439,198 @@ discard block |
||
1439 | 1439 | } |
1440 | 1440 | |
1441 | 1441 | /** |
1442 | - * Get the invoice discount total. |
|
1443 | - * |
|
1444 | - * @since 1.0.19 |
|
1445 | - * @param string $context View or edit context. |
|
1446 | - * @return float |
|
1447 | - */ |
|
1448 | - public function get_total_discount( $context = 'view' ) { |
|
1449 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_discount', $context ) ) ); |
|
1442 | + * Get the invoice discount total. |
|
1443 | + * |
|
1444 | + * @since 1.0.19 |
|
1445 | + * @param string $context View or edit context. |
|
1446 | + * @return float |
|
1447 | + */ |
|
1448 | + public function get_total_discount( $context = 'view' ) { |
|
1449 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_discount', $context ) ) ); |
|
1450 | 1450 | } |
1451 | 1451 | |
1452 | 1452 | /** |
1453 | - * Get the invoice tax total. |
|
1454 | - * |
|
1455 | - * @since 1.0.19 |
|
1456 | - * @param string $context View or edit context. |
|
1457 | - * @return float |
|
1458 | - */ |
|
1459 | - public function get_total_tax( $context = 'view' ) { |
|
1460 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_tax', $context ) ) ); |
|
1461 | - } |
|
1453 | + * Get the invoice tax total. |
|
1454 | + * |
|
1455 | + * @since 1.0.19 |
|
1456 | + * @param string $context View or edit context. |
|
1457 | + * @return float |
|
1458 | + */ |
|
1459 | + public function get_total_tax( $context = 'view' ) { |
|
1460 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_tax', $context ) ) ); |
|
1461 | + } |
|
1462 | 1462 | |
1463 | - /** |
|
1464 | - * @deprecated |
|
1465 | - */ |
|
1466 | - public function get_final_tax( $currency = false ) { |
|
1467 | - $tax = $this->get_total_tax(); |
|
1463 | + /** |
|
1464 | + * @deprecated |
|
1465 | + */ |
|
1466 | + public function get_final_tax( $currency = false ) { |
|
1467 | + $tax = $this->get_total_tax(); |
|
1468 | 1468 | |
1469 | 1469 | if ( $currency ) { |
1470 | - return wpinv_price( $tax, $this->get_currency() ); |
|
1470 | + return wpinv_price( $tax, $this->get_currency() ); |
|
1471 | 1471 | } |
1472 | 1472 | |
1473 | 1473 | return $tax; |
1474 | 1474 | } |
1475 | 1475 | |
1476 | 1476 | /** |
1477 | - * Get the invoice fees total. |
|
1478 | - * |
|
1479 | - * @since 1.0.19 |
|
1480 | - * @param string $context View or edit context. |
|
1481 | - * @return float |
|
1482 | - */ |
|
1483 | - public function get_total_fees( $context = 'view' ) { |
|
1484 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_fees', $context ) ) ); |
|
1477 | + * Get the invoice fees total. |
|
1478 | + * |
|
1479 | + * @since 1.0.19 |
|
1480 | + * @param string $context View or edit context. |
|
1481 | + * @return float |
|
1482 | + */ |
|
1483 | + public function get_total_fees( $context = 'view' ) { |
|
1484 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_fees', $context ) ) ); |
|
1485 | + } |
|
1486 | + |
|
1487 | + /** |
|
1488 | + * Alias for self::get_total_fees(). |
|
1489 | + * |
|
1490 | + * @since 1.0.19 |
|
1491 | + * @param string $context View or edit context. |
|
1492 | + * @return float |
|
1493 | + */ |
|
1494 | + public function get_fees_total( $context = 'view' ) { |
|
1495 | + return $this->get_total_fees( $context ); |
|
1485 | 1496 | } |
1486 | 1497 | |
1487 | 1498 | /** |
1488 | - * Alias for self::get_total_fees(). |
|
1489 | - * |
|
1490 | - * @since 1.0.19 |
|
1491 | - * @param string $context View or edit context. |
|
1492 | - * @return float |
|
1493 | - */ |
|
1494 | - public function get_fees_total( $context = 'view' ) { |
|
1495 | - return $this->get_total_fees( $context ); |
|
1499 | + * Get the invoice total. |
|
1500 | + * |
|
1501 | + * @since 1.0.19 |
|
1502 | + * @return float |
|
1503 | + */ |
|
1504 | + public function get_total( $context = 'view' ) { |
|
1505 | + $total = $this->get_prop( 'total', $context ); |
|
1506 | + |
|
1507 | + if ( $this->has_shipping() && $context == 'view' ) { |
|
1508 | + $total = $this->get_prop( 'total', $context ) + $this->get_shipping( $context ); |
|
1509 | + } |
|
1510 | + |
|
1511 | + return wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
1496 | 1512 | } |
1497 | 1513 | |
1498 | 1514 | /** |
1499 | - * Get the invoice total. |
|
1500 | - * |
|
1501 | - * @since 1.0.19 |
|
1515 | + * Retrieves the non-recurring total of items. |
|
1516 | + * |
|
1517 | + * @since 2.3.0 |
|
1502 | 1518 | * @return float |
1503 | - */ |
|
1504 | - public function get_total( $context = 'view' ) { |
|
1505 | - $total = $this->get_prop( 'total', $context ); |
|
1506 | - |
|
1507 | - if ( $this->has_shipping() && $context == 'view' ) { |
|
1508 | - $total = $this->get_prop( 'total', $context ) + $this->get_shipping( $context ); |
|
1509 | - } |
|
1510 | - |
|
1511 | - return wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
1512 | - } |
|
1513 | - |
|
1514 | - /** |
|
1515 | - * Retrieves the non-recurring total of items. |
|
1516 | - * |
|
1517 | - * @since 2.3.0 |
|
1518 | - * @return float |
|
1519 | - */ |
|
1520 | - public function get_non_recurring_total() { |
|
1521 | - |
|
1522 | - $subtotal = 0; |
|
1523 | - foreach ( $this->get_items() as $item ) { |
|
1524 | - if ( ! $item->is_recurring() ) { |
|
1525 | - $subtotal += $item->get_sub_total(); |
|
1526 | - } |
|
1527 | - } |
|
1528 | - |
|
1529 | - foreach ( $this->get_fees() as $fee ) { |
|
1530 | - if ( empty( $fee['recurring_fee'] ) ) { |
|
1531 | - $subtotal += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
1532 | - } |
|
1533 | - } |
|
1534 | - |
|
1535 | - $subtotal = wpinv_round_amount( wpinv_sanitize_amount( $subtotal ) ); |
|
1519 | + */ |
|
1520 | + public function get_non_recurring_total() { |
|
1521 | + |
|
1522 | + $subtotal = 0; |
|
1523 | + foreach ( $this->get_items() as $item ) { |
|
1524 | + if ( ! $item->is_recurring() ) { |
|
1525 | + $subtotal += $item->get_sub_total(); |
|
1526 | + } |
|
1527 | + } |
|
1528 | + |
|
1529 | + foreach ( $this->get_fees() as $fee ) { |
|
1530 | + if ( empty( $fee['recurring_fee'] ) ) { |
|
1531 | + $subtotal += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
1532 | + } |
|
1533 | + } |
|
1534 | + |
|
1535 | + $subtotal = wpinv_round_amount( wpinv_sanitize_amount( $subtotal ) ); |
|
1536 | 1536 | return apply_filters( 'wpinv_get_non_recurring_invoice_total', $subtotal, $this ); |
1537 | 1537 | |
1538 | 1538 | } |
1539 | 1539 | |
1540 | - /** |
|
1541 | - * Get the invoice totals. |
|
1542 | - * |
|
1543 | - * @since 1.0.19 |
|
1540 | + /** |
|
1541 | + * Get the invoice totals. |
|
1542 | + * |
|
1543 | + * @since 1.0.19 |
|
1544 | 1544 | * @return array |
1545 | - */ |
|
1546 | - public function get_totals() { |
|
1547 | - return $this->totals; |
|
1545 | + */ |
|
1546 | + public function get_totals() { |
|
1547 | + return $this->totals; |
|
1548 | 1548 | } |
1549 | 1549 | |
1550 | 1550 | /** |
1551 | - * Get the initial invoice total. |
|
1552 | - * |
|
1553 | - * @since 1.0.19 |
|
1551 | + * Get the initial invoice total. |
|
1552 | + * |
|
1553 | + * @since 1.0.19 |
|
1554 | 1554 | * @param string $context View or edit context. |
1555 | 1555 | * @return float |
1556 | - */ |
|
1556 | + */ |
|
1557 | 1557 | public function get_initial_total() { |
1558 | 1558 | |
1559 | - if ( empty( $this->totals ) ) { |
|
1560 | - $this->recalculate_total(); |
|
1561 | - } |
|
1559 | + if ( empty( $this->totals ) ) { |
|
1560 | + $this->recalculate_total(); |
|
1561 | + } |
|
1562 | 1562 | |
1563 | - $tax = $this->totals['tax']['initial']; |
|
1564 | - $fee = $this->totals['fee']['initial']; |
|
1565 | - $discount = $this->totals['discount']['initial']; |
|
1566 | - $subtotal = $this->totals['subtotal']['initial']; |
|
1567 | - $total = $tax + $fee - $discount + $subtotal; |
|
1563 | + $tax = $this->totals['tax']['initial']; |
|
1564 | + $fee = $this->totals['fee']['initial']; |
|
1565 | + $discount = $this->totals['discount']['initial']; |
|
1566 | + $subtotal = $this->totals['subtotal']['initial']; |
|
1567 | + $total = $tax + $fee - $discount + $subtotal; |
|
1568 | 1568 | |
1569 | - if ( 0 > $total ) { |
|
1570 | - $total = 0; |
|
1571 | - } |
|
1569 | + if ( 0 > $total ) { |
|
1570 | + $total = 0; |
|
1571 | + } |
|
1572 | 1572 | |
1573 | - $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
1573 | + $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
1574 | 1574 | return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this ); |
1575 | - } |
|
1575 | + } |
|
1576 | 1576 | |
1577 | - /** |
|
1578 | - * Get the recurring invoice total. |
|
1579 | - * |
|
1580 | - * @since 1.0.19 |
|
1577 | + /** |
|
1578 | + * Get the recurring invoice total. |
|
1579 | + * |
|
1580 | + * @since 1.0.19 |
|
1581 | 1581 | * @param string $context View or edit context. |
1582 | 1582 | * @return float |
1583 | - */ |
|
1583 | + */ |
|
1584 | 1584 | public function get_recurring_total() { |
1585 | 1585 | |
1586 | - if ( empty( $this->totals ) ) { |
|
1587 | - $this->recalculate_total(); |
|
1588 | - } |
|
1586 | + if ( empty( $this->totals ) ) { |
|
1587 | + $this->recalculate_total(); |
|
1588 | + } |
|
1589 | 1589 | |
1590 | - $tax = $this->totals['tax']['recurring']; |
|
1591 | - $fee = $this->totals['fee']['recurring']; |
|
1592 | - $discount = $this->totals['discount']['recurring']; |
|
1593 | - $subtotal = $this->totals['subtotal']['recurring']; |
|
1594 | - $total = $tax + $fee - $discount + $subtotal; |
|
1590 | + $tax = $this->totals['tax']['recurring']; |
|
1591 | + $fee = $this->totals['fee']['recurring']; |
|
1592 | + $discount = $this->totals['discount']['recurring']; |
|
1593 | + $subtotal = $this->totals['subtotal']['recurring']; |
|
1594 | + $total = $tax + $fee - $discount + $subtotal; |
|
1595 | 1595 | |
1596 | - if ( 0 > $total ) { |
|
1597 | - $total = 0; |
|
1598 | - } |
|
1596 | + if ( 0 > $total ) { |
|
1597 | + $total = 0; |
|
1598 | + } |
|
1599 | 1599 | |
1600 | - $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
1600 | + $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
1601 | 1601 | return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this ); |
1602 | - } |
|
1602 | + } |
|
1603 | 1603 | |
1604 | - /** |
|
1605 | - * Returns recurring payment details. |
|
1606 | - * |
|
1607 | - * @since 1.0.19 |
|
1604 | + /** |
|
1605 | + * Returns recurring payment details. |
|
1606 | + * |
|
1607 | + * @since 1.0.19 |
|
1608 | 1608 | * @param string $field Optionally provide a field to return. |
1609 | - * @param string $currency Whether to include the currency. |
|
1609 | + * @param string $currency Whether to include the currency. |
|
1610 | 1610 | * @return float|string |
1611 | - */ |
|
1611 | + */ |
|
1612 | 1612 | public function get_recurring_details( $field = '', $currency = false ) { |
1613 | 1613 | |
1614 | - // Maybe recalculate totals. |
|
1615 | - if ( empty( $this->totals ) ) { |
|
1616 | - $this->recalculate_total(); |
|
1617 | - } |
|
1614 | + // Maybe recalculate totals. |
|
1615 | + if ( empty( $this->totals ) ) { |
|
1616 | + $this->recalculate_total(); |
|
1617 | + } |
|
1618 | 1618 | |
1619 | - // Prepare recurring totals. |
|
1619 | + // Prepare recurring totals. |
|
1620 | 1620 | $data = apply_filters( |
1621 | - 'wpinv_get_invoice_recurring_details', |
|
1622 | - array( |
|
1623 | - 'cart_details' => $this->get_cart_details(), |
|
1624 | - 'subtotal' => $this->totals['subtotal']['recurring'], |
|
1625 | - 'discount' => $this->totals['discount']['recurring'], |
|
1626 | - 'tax' => $this->totals['tax']['recurring'], |
|
1627 | - 'fee' => $this->totals['fee']['recurring'], |
|
1628 | - 'total' => $this->get_recurring_total(), |
|
1629 | - ), |
|
1630 | - $this, |
|
1631 | - $field, |
|
1632 | - $currency |
|
1633 | - ); |
|
1621 | + 'wpinv_get_invoice_recurring_details', |
|
1622 | + array( |
|
1623 | + 'cart_details' => $this->get_cart_details(), |
|
1624 | + 'subtotal' => $this->totals['subtotal']['recurring'], |
|
1625 | + 'discount' => $this->totals['discount']['recurring'], |
|
1626 | + 'tax' => $this->totals['tax']['recurring'], |
|
1627 | + 'fee' => $this->totals['fee']['recurring'], |
|
1628 | + 'total' => $this->get_recurring_total(), |
|
1629 | + ), |
|
1630 | + $this, |
|
1631 | + $field, |
|
1632 | + $currency |
|
1633 | + ); |
|
1634 | 1634 | |
1635 | 1635 | if ( isset( $data[ $field ] ) ) { |
1636 | 1636 | return ( $currency ? wpinv_price( $data[ $field ], $this->get_currency() ) : $data[ $field ] ); |
@@ -1640,166 +1640,166 @@ discard block |
||
1640 | 1640 | } |
1641 | 1641 | |
1642 | 1642 | /** |
1643 | - * Get the invoice fees. |
|
1644 | - * |
|
1645 | - * @since 1.0.19 |
|
1646 | - * @param string $context View or edit context. |
|
1647 | - * @return array |
|
1648 | - */ |
|
1649 | - public function get_fees( $context = 'view' ) { |
|
1650 | - return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
1643 | + * Get the invoice fees. |
|
1644 | + * |
|
1645 | + * @since 1.0.19 |
|
1646 | + * @param string $context View or edit context. |
|
1647 | + * @return array |
|
1648 | + */ |
|
1649 | + public function get_fees( $context = 'view' ) { |
|
1650 | + return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
1651 | 1651 | } |
1652 | 1652 | |
1653 | 1653 | /** |
1654 | - * Get the invoice discounts. |
|
1655 | - * |
|
1656 | - * @since 1.0.19 |
|
1657 | - * @param string $context View or edit context. |
|
1658 | - * @return array |
|
1659 | - */ |
|
1660 | - public function get_discounts( $context = 'view' ) { |
|
1661 | - return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
1654 | + * Get the invoice discounts. |
|
1655 | + * |
|
1656 | + * @since 1.0.19 |
|
1657 | + * @param string $context View or edit context. |
|
1658 | + * @return array |
|
1659 | + */ |
|
1660 | + public function get_discounts( $context = 'view' ) { |
|
1661 | + return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
1662 | 1662 | } |
1663 | 1663 | |
1664 | 1664 | /** |
1665 | - * Get the invoice taxes. |
|
1666 | - * |
|
1667 | - * @since 1.0.19 |
|
1668 | - * @param string $context View or edit context. |
|
1669 | - * @return array |
|
1670 | - */ |
|
1671 | - public function get_taxes( $context = 'view' ) { |
|
1672 | - return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
1665 | + * Get the invoice taxes. |
|
1666 | + * |
|
1667 | + * @since 1.0.19 |
|
1668 | + * @param string $context View or edit context. |
|
1669 | + * @return array |
|
1670 | + */ |
|
1671 | + public function get_taxes( $context = 'view' ) { |
|
1672 | + return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
1673 | 1673 | } |
1674 | 1674 | |
1675 | 1675 | /** |
1676 | - * Get the invoice items. |
|
1677 | - * |
|
1678 | - * @since 1.0.19 |
|
1679 | - * @param string $context View or edit context. |
|
1680 | - * @return GetPaid_Form_Item[] |
|
1681 | - */ |
|
1682 | - public function get_items( $context = 'view' ) { |
|
1676 | + * Get the invoice items. |
|
1677 | + * |
|
1678 | + * @since 1.0.19 |
|
1679 | + * @param string $context View or edit context. |
|
1680 | + * @return GetPaid_Form_Item[] |
|
1681 | + */ |
|
1682 | + public function get_items( $context = 'view' ) { |
|
1683 | 1683 | return $this->get_prop( 'items', $context ); |
1684 | - } |
|
1684 | + } |
|
1685 | 1685 | |
1686 | - /** |
|
1687 | - * Get the invoice item ids. |
|
1688 | - * |
|
1689 | - * @since 1.0.19 |
|
1690 | - * @return string |
|
1691 | - */ |
|
1692 | - public function get_item_ids() { |
|
1693 | - return implode( ', ', wp_list_pluck( $this->get_cart_details(), 'item_id' ) ); |
|
1686 | + /** |
|
1687 | + * Get the invoice item ids. |
|
1688 | + * |
|
1689 | + * @since 1.0.19 |
|
1690 | + * @return string |
|
1691 | + */ |
|
1692 | + public function get_item_ids() { |
|
1693 | + return implode( ', ', wp_list_pluck( $this->get_cart_details(), 'item_id' ) ); |
|
1694 | 1694 | } |
1695 | 1695 | |
1696 | 1696 | /** |
1697 | - * Get the invoice's payment form. |
|
1698 | - * |
|
1699 | - * @since 1.0.19 |
|
1700 | - * @param string $context View or edit context. |
|
1701 | - * @return int |
|
1702 | - */ |
|
1703 | - public function get_payment_form( $context = 'view' ) { |
|
1704 | - return intval( $this->get_prop( 'payment_form', $context ) ); |
|
1697 | + * Get the invoice's payment form. |
|
1698 | + * |
|
1699 | + * @since 1.0.19 |
|
1700 | + * @param string $context View or edit context. |
|
1701 | + * @return int |
|
1702 | + */ |
|
1703 | + public function get_payment_form( $context = 'view' ) { |
|
1704 | + return intval( $this->get_prop( 'payment_form', $context ) ); |
|
1705 | 1705 | } |
1706 | 1706 | |
1707 | 1707 | /** |
1708 | - * Get the invoice's submission id. |
|
1709 | - * |
|
1710 | - * @since 1.0.19 |
|
1711 | - * @param string $context View or edit context. |
|
1712 | - * @return string |
|
1713 | - */ |
|
1714 | - public function get_submission_id( $context = 'view' ) { |
|
1715 | - return $this->get_prop( 'submission_id', $context ); |
|
1708 | + * Get the invoice's submission id. |
|
1709 | + * |
|
1710 | + * @since 1.0.19 |
|
1711 | + * @param string $context View or edit context. |
|
1712 | + * @return string |
|
1713 | + */ |
|
1714 | + public function get_submission_id( $context = 'view' ) { |
|
1715 | + return $this->get_prop( 'submission_id', $context ); |
|
1716 | 1716 | } |
1717 | 1717 | |
1718 | 1718 | /** |
1719 | - * Get the invoice's discount code. |
|
1720 | - * |
|
1721 | - * @since 1.0.19 |
|
1722 | - * @param string $context View or edit context. |
|
1723 | - * @return string |
|
1724 | - */ |
|
1725 | - public function get_discount_code( $context = 'view' ) { |
|
1726 | - return $this->get_prop( 'discount_code', $context ); |
|
1719 | + * Get the invoice's discount code. |
|
1720 | + * |
|
1721 | + * @since 1.0.19 |
|
1722 | + * @param string $context View or edit context. |
|
1723 | + * @return string |
|
1724 | + */ |
|
1725 | + public function get_discount_code( $context = 'view' ) { |
|
1726 | + return $this->get_prop( 'discount_code', $context ); |
|
1727 | 1727 | } |
1728 | 1728 | |
1729 | 1729 | /** |
1730 | - * Get the invoice's gateway. |
|
1731 | - * |
|
1732 | - * @since 1.0.19 |
|
1733 | - * @param string $context View or edit context. |
|
1734 | - * @return string |
|
1735 | - */ |
|
1736 | - public function get_gateway( $context = 'view' ) { |
|
1737 | - return $this->get_prop( 'gateway', $context ); |
|
1730 | + * Get the invoice's gateway. |
|
1731 | + * |
|
1732 | + * @since 1.0.19 |
|
1733 | + * @param string $context View or edit context. |
|
1734 | + * @return string |
|
1735 | + */ |
|
1736 | + public function get_gateway( $context = 'view' ) { |
|
1737 | + return $this->get_prop( 'gateway', $context ); |
|
1738 | 1738 | } |
1739 | 1739 | |
1740 | 1740 | /** |
1741 | - * Get the invoice's gateway display title. |
|
1742 | - * |
|
1743 | - * @since 1.0.19 |
|
1744 | - * @return string |
|
1745 | - */ |
|
1741 | + * Get the invoice's gateway display title. |
|
1742 | + * |
|
1743 | + * @since 1.0.19 |
|
1744 | + * @return string |
|
1745 | + */ |
|
1746 | 1746 | public function get_gateway_title() { |
1747 | 1747 | $title = wpinv_get_gateway_checkout_label( $this->get_gateway() ); |
1748 | 1748 | return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this ); |
1749 | 1749 | } |
1750 | 1750 | |
1751 | 1751 | /** |
1752 | - * Get the invoice's transaction id. |
|
1753 | - * |
|
1754 | - * @since 1.0.19 |
|
1755 | - * @param string $context View or edit context. |
|
1756 | - * @return string |
|
1757 | - */ |
|
1758 | - public function get_transaction_id( $context = 'view' ) { |
|
1759 | - return $this->get_prop( 'transaction_id', $context ); |
|
1752 | + * Get the invoice's transaction id. |
|
1753 | + * |
|
1754 | + * @since 1.0.19 |
|
1755 | + * @param string $context View or edit context. |
|
1756 | + * @return string |
|
1757 | + */ |
|
1758 | + public function get_transaction_id( $context = 'view' ) { |
|
1759 | + return $this->get_prop( 'transaction_id', $context ); |
|
1760 | 1760 | } |
1761 | 1761 | |
1762 | 1762 | /** |
1763 | - * Get the invoice's currency. |
|
1764 | - * |
|
1765 | - * @since 1.0.19 |
|
1766 | - * @param string $context View or edit context. |
|
1767 | - * @return string |
|
1768 | - */ |
|
1769 | - public function get_currency( $context = 'view' ) { |
|
1763 | + * Get the invoice's currency. |
|
1764 | + * |
|
1765 | + * @since 1.0.19 |
|
1766 | + * @param string $context View or edit context. |
|
1767 | + * @return string |
|
1768 | + */ |
|
1769 | + public function get_currency( $context = 'view' ) { |
|
1770 | 1770 | $currency = $this->get_prop( 'currency', $context ); |
1771 | 1771 | return empty( $currency ) ? wpinv_get_currency() : $currency; |
1772 | 1772 | } |
1773 | 1773 | |
1774 | 1774 | /** |
1775 | - * Checks if we are charging taxes for this invoice. |
|
1776 | - * |
|
1777 | - * @since 1.0.19 |
|
1778 | - * @param string $context View or edit context. |
|
1779 | - * @return bool |
|
1780 | - */ |
|
1781 | - public function get_disable_taxes( $context = 'view' ) { |
|
1775 | + * Checks if we are charging taxes for this invoice. |
|
1776 | + * |
|
1777 | + * @since 1.0.19 |
|
1778 | + * @param string $context View or edit context. |
|
1779 | + * @return bool |
|
1780 | + */ |
|
1781 | + public function get_disable_taxes( $context = 'view' ) { |
|
1782 | 1782 | return (bool) $this->get_prop( 'disable_taxes', $context ); |
1783 | 1783 | } |
1784 | 1784 | |
1785 | 1785 | /** |
1786 | - * Retrieves the subscription id for an invoice. |
|
1787 | - * |
|
1788 | - * @since 1.0.19 |
|
1789 | - * @param string $context View or edit context. |
|
1790 | - * @return int |
|
1791 | - */ |
|
1786 | + * Retrieves the subscription id for an invoice. |
|
1787 | + * |
|
1788 | + * @since 1.0.19 |
|
1789 | + * @param string $context View or edit context. |
|
1790 | + * @return int |
|
1791 | + */ |
|
1792 | 1792 | public function get_subscription_id( $context = 'view' ) { |
1793 | - return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context ); |
|
1794 | - } |
|
1795 | - |
|
1796 | - /** |
|
1797 | - * Retrieves the remote subscription id for an invoice. |
|
1798 | - * |
|
1799 | - * @since 1.0.19 |
|
1800 | - * @param string $context View or edit context. |
|
1801 | - * @return int |
|
1802 | - */ |
|
1793 | + return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context ); |
|
1794 | + } |
|
1795 | + |
|
1796 | + /** |
|
1797 | + * Retrieves the remote subscription id for an invoice. |
|
1798 | + * |
|
1799 | + * @since 1.0.19 |
|
1800 | + * @param string $context View or edit context. |
|
1801 | + * @return int |
|
1802 | + */ |
|
1803 | 1803 | public function get_remote_subscription_id( $context = 'view' ) { |
1804 | 1804 | $subscription_id = $this->get_prop( 'remote_subscription_id', $context ); |
1805 | 1805 | |
@@ -1812,12 +1812,12 @@ discard block |
||
1812 | 1812 | } |
1813 | 1813 | |
1814 | 1814 | /** |
1815 | - * Retrieves the payment meta for an invoice. |
|
1816 | - * |
|
1817 | - * @since 1.0.19 |
|
1818 | - * @param string $context View or edit context. |
|
1819 | - * @return array |
|
1820 | - */ |
|
1815 | + * Retrieves the payment meta for an invoice. |
|
1816 | + * |
|
1817 | + * @since 1.0.19 |
|
1818 | + * @param string $context View or edit context. |
|
1819 | + * @return array |
|
1820 | + */ |
|
1821 | 1821 | public function get_payment_meta( $context = 'view' ) { |
1822 | 1822 | |
1823 | 1823 | return array( |
@@ -1837,31 +1837,31 @@ discard block |
||
1837 | 1837 | } |
1838 | 1838 | |
1839 | 1839 | /** |
1840 | - * Retrieves the cart details for an invoice. |
|
1841 | - * |
|
1842 | - * @since 1.0.19 |
|
1843 | - * @return array |
|
1844 | - */ |
|
1840 | + * Retrieves the cart details for an invoice. |
|
1841 | + * |
|
1842 | + * @since 1.0.19 |
|
1843 | + * @return array |
|
1844 | + */ |
|
1845 | 1845 | public function get_cart_details() { |
1846 | 1846 | $items = $this->get_items(); |
1847 | 1847 | $cart_details = array(); |
1848 | 1848 | |
1849 | 1849 | foreach ( $items as $item ) { |
1850 | - $item->invoice_id = $this->get_id(); |
|
1850 | + $item->invoice_id = $this->get_id(); |
|
1851 | 1851 | $cart_details[] = $item->prepare_data_for_saving(); |
1852 | 1852 | } |
1853 | 1853 | |
1854 | 1854 | return $cart_details; |
1855 | - } |
|
1855 | + } |
|
1856 | 1856 | |
1857 | - /** |
|
1858 | - * Retrieves the recurring item. |
|
1859 | - * |
|
1860 | - * @return null|GetPaid_Form_Item|int |
|
1861 | - */ |
|
1862 | - public function get_recurring( $object = false ) { |
|
1857 | + /** |
|
1858 | + * Retrieves the recurring item. |
|
1859 | + * |
|
1860 | + * @return null|GetPaid_Form_Item|int |
|
1861 | + */ |
|
1862 | + public function get_recurring( $object = false ) { |
|
1863 | 1863 | |
1864 | - // Are we returning an object? |
|
1864 | + // Are we returning an object? |
|
1865 | 1865 | if ( $object ) { |
1866 | 1866 | return $this->get_item( $this->recurring_item ); |
1867 | 1867 | } |
@@ -1869,130 +1869,130 @@ discard block |
||
1869 | 1869 | return $this->recurring_item; |
1870 | 1870 | } |
1871 | 1871 | |
1872 | - /** |
|
1873 | - * Retrieves the subscription name. |
|
1874 | - * |
|
1875 | - * @since 1.0.19 |
|
1876 | - * @return string |
|
1877 | - */ |
|
1878 | - public function get_subscription_name() { |
|
1872 | + /** |
|
1873 | + * Retrieves the subscription name. |
|
1874 | + * |
|
1875 | + * @since 1.0.19 |
|
1876 | + * @return string |
|
1877 | + */ |
|
1878 | + public function get_subscription_name() { |
|
1879 | 1879 | |
1880 | - // Retrieve the recurring name |
|
1880 | + // Retrieve the recurring name |
|
1881 | 1881 | $item = $this->get_recurring( true ); |
1882 | 1882 | |
1883 | - // Abort if it does not exist. |
|
1883 | + // Abort if it does not exist. |
|
1884 | 1884 | if ( empty( $item ) ) { |
1885 | 1885 | return ''; |
1886 | 1886 | } |
1887 | 1887 | |
1888 | - // Return the item name. |
|
1888 | + // Return the item name. |
|
1889 | 1889 | return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this ); |
1890 | - } |
|
1891 | - |
|
1892 | - /** |
|
1893 | - * Retrieves the view url. |
|
1894 | - * |
|
1895 | - * @since 1.0.19 |
|
1896 | - * @return string |
|
1897 | - */ |
|
1898 | - public function get_view_url() { |
|
1890 | + } |
|
1891 | + |
|
1892 | + /** |
|
1893 | + * Retrieves the view url. |
|
1894 | + * |
|
1895 | + * @since 1.0.19 |
|
1896 | + * @return string |
|
1897 | + */ |
|
1898 | + public function get_view_url() { |
|
1899 | 1899 | $invoice_url = get_permalink( $this->get_id() ); |
1900 | - $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
1900 | + $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
1901 | 1901 | return apply_filters( 'wpinv_get_view_url', $invoice_url, $this ); |
1902 | - } |
|
1902 | + } |
|
1903 | 1903 | |
1904 | - /** |
|
1905 | - * Retrieves the payment url. |
|
1906 | - * |
|
1907 | - * @since 1.0.19 |
|
1908 | - * @return string |
|
1909 | - */ |
|
1910 | - public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
1904 | + /** |
|
1905 | + * Retrieves the payment url. |
|
1906 | + * |
|
1907 | + * @since 1.0.19 |
|
1908 | + * @return string |
|
1909 | + */ |
|
1910 | + public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
1911 | 1911 | |
1912 | - // Retrieve the checkout url. |
|
1912 | + // Retrieve the checkout url. |
|
1913 | 1913 | $pay_url = wpinv_get_checkout_uri(); |
1914 | 1914 | |
1915 | - // Maybe force ssl. |
|
1915 | + // Maybe force ssl. |
|
1916 | 1916 | if ( is_ssl() ) { |
1917 | 1917 | $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
1918 | 1918 | } |
1919 | 1919 | |
1920 | - // Add the invoice key. |
|
1921 | - $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
1920 | + // Add the invoice key. |
|
1921 | + $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
1922 | 1922 | |
1923 | - // (Maybe?) add a secret |
|
1923 | + // (Maybe?) add a secret |
|
1924 | 1924 | if ( $secret ) { |
1925 | 1925 | $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url ); |
1926 | 1926 | } |
1927 | 1927 | |
1928 | 1928 | return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret ); |
1929 | - } |
|
1929 | + } |
|
1930 | 1930 | |
1931 | - /** |
|
1932 | - * Retrieves the receipt url. |
|
1933 | - * |
|
1934 | - * @since 1.0.19 |
|
1935 | - * @return string |
|
1936 | - */ |
|
1937 | - public function get_receipt_url() { |
|
1931 | + /** |
|
1932 | + * Retrieves the receipt url. |
|
1933 | + * |
|
1934 | + * @since 1.0.19 |
|
1935 | + * @return string |
|
1936 | + */ |
|
1937 | + public function get_receipt_url() { |
|
1938 | 1938 | |
1939 | - // Retrieve the checkout url. |
|
1939 | + // Retrieve the checkout url. |
|
1940 | 1940 | $receipt_url = wpinv_get_success_page_uri(); |
1941 | 1941 | |
1942 | - // Maybe force ssl. |
|
1942 | + // Maybe force ssl. |
|
1943 | 1943 | if ( is_ssl() ) { |
1944 | 1944 | $receipt_url = str_replace( 'http:', 'https:', $receipt_url ); |
1945 | 1945 | } |
1946 | 1946 | |
1947 | - // Add the invoice key. |
|
1948 | - $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
1947 | + // Add the invoice key. |
|
1948 | + $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
1949 | 1949 | |
1950 | 1950 | return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this ); |
1951 | - } |
|
1952 | - |
|
1953 | - /** |
|
1954 | - * Retrieves the remote transaction url. |
|
1955 | - * |
|
1956 | - * @since 1.6.0 |
|
1957 | - * @return string |
|
1958 | - */ |
|
1959 | - public function get_transaction_url() { |
|
1960 | - return apply_filters( 'getpaid_gateway_' . $this->get_gateway() . '_transaction_url', '', $this ); |
|
1961 | - } |
|
1962 | - |
|
1963 | - /** |
|
1964 | - * Retrieves the default status. |
|
1965 | - * |
|
1966 | - * @since 1.0.19 |
|
1967 | - * @return string |
|
1968 | - */ |
|
1969 | - public function get_default_status() { |
|
1970 | - |
|
1971 | - $type = $this->get_type(); |
|
1972 | - $status = "wpi-$type-pending"; |
|
1973 | - return str_replace( '-invoice', '', $status ); |
|
1974 | - |
|
1975 | - } |
|
1976 | - |
|
1977 | - /** |
|
1978 | - * Magic method for accessing invoice properties. |
|
1979 | - * |
|
1980 | - * @since 1.0.15 |
|
1981 | - * @access public |
|
1982 | - * |
|
1983 | - * @param string $key Discount data to retrieve |
|
1984 | - * @param string $context View or edit context. |
|
1985 | - * @return mixed Value of the given invoice property (if set). |
|
1986 | - */ |
|
1987 | - public function get( $key, $context = 'view' ) { |
|
1988 | - $method = "get_$key"; |
|
1989 | - |
|
1990 | - if ( is_callable( array( $this, $method ) ) ) { |
|
1991 | - return $this->$method( $context ); |
|
1992 | - } |
|
1951 | + } |
|
1952 | + |
|
1953 | + /** |
|
1954 | + * Retrieves the remote transaction url. |
|
1955 | + * |
|
1956 | + * @since 1.6.0 |
|
1957 | + * @return string |
|
1958 | + */ |
|
1959 | + public function get_transaction_url() { |
|
1960 | + return apply_filters( 'getpaid_gateway_' . $this->get_gateway() . '_transaction_url', '', $this ); |
|
1961 | + } |
|
1962 | + |
|
1963 | + /** |
|
1964 | + * Retrieves the default status. |
|
1965 | + * |
|
1966 | + * @since 1.0.19 |
|
1967 | + * @return string |
|
1968 | + */ |
|
1969 | + public function get_default_status() { |
|
1970 | + |
|
1971 | + $type = $this->get_type(); |
|
1972 | + $status = "wpi-$type-pending"; |
|
1973 | + return str_replace( '-invoice', '', $status ); |
|
1974 | + |
|
1975 | + } |
|
1976 | + |
|
1977 | + /** |
|
1978 | + * Magic method for accessing invoice properties. |
|
1979 | + * |
|
1980 | + * @since 1.0.15 |
|
1981 | + * @access public |
|
1982 | + * |
|
1983 | + * @param string $key Discount data to retrieve |
|
1984 | + * @param string $context View or edit context. |
|
1985 | + * @return mixed Value of the given invoice property (if set). |
|
1986 | + */ |
|
1987 | + public function get( $key, $context = 'view' ) { |
|
1988 | + $method = "get_$key"; |
|
1989 | + |
|
1990 | + if ( is_callable( array( $this, $method ) ) ) { |
|
1991 | + return $this->$method( $context ); |
|
1992 | + } |
|
1993 | 1993 | |
1994 | 1994 | return $this->get_prop( $key, $context ); |
1995 | - } |
|
1995 | + } |
|
1996 | 1996 | |
1997 | 1997 | /* |
1998 | 1998 | |-------------------------------------------------------------------------- |
@@ -2005,129 +2005,129 @@ discard block |
||
2005 | 2005 | */ |
2006 | 2006 | |
2007 | 2007 | /** |
2008 | - * Magic method for setting invoice properties. |
|
2009 | - * |
|
2010 | - * @since 1.0.19 |
|
2011 | - * @access public |
|
2012 | - * |
|
2013 | - * @param string $key Discount data to retrieve |
|
2014 | - * @param mixed $value new value. |
|
2015 | - * @return mixed Value of the given invoice property (if set). |
|
2016 | - */ |
|
2017 | - public function set( $key, $value ) { |
|
2008 | + * Magic method for setting invoice properties. |
|
2009 | + * |
|
2010 | + * @since 1.0.19 |
|
2011 | + * @access public |
|
2012 | + * |
|
2013 | + * @param string $key Discount data to retrieve |
|
2014 | + * @param mixed $value new value. |
|
2015 | + * @return mixed Value of the given invoice property (if set). |
|
2016 | + */ |
|
2017 | + public function set( $key, $value ) { |
|
2018 | 2018 | |
2019 | 2019 | $setter = "set_$key"; |
2020 | 2020 | if ( is_callable( array( $this, $setter ) ) ) { |
2021 | 2021 | $this->{$setter}( $value ); |
2022 | 2022 | } |
2023 | 2023 | |
2024 | - } |
|
2025 | - |
|
2026 | - /** |
|
2027 | - * Sets item status. |
|
2028 | - * |
|
2029 | - * @since 1.0.19 |
|
2030 | - * @param string $new_status New status. |
|
2031 | - * @param string $note Optional note to add. |
|
2032 | - * @param bool $manual_update Is this a manual status change?. |
|
2033 | - * @return array details of change. |
|
2034 | - */ |
|
2035 | - public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
2036 | - $old_status = $this->get_status(); |
|
2037 | - |
|
2038 | - $statuses = $this->get_all_statuses(); |
|
2039 | - |
|
2040 | - if ( isset( $statuses['draft'] ) ) { |
|
2041 | - unset( $statuses['draft'] ); |
|
2042 | - } |
|
2043 | - |
|
2044 | - $this->set_prop( 'status', $new_status ); |
|
2045 | - |
|
2046 | - // If setting the status, ensure it's set to a valid status. |
|
2047 | - if ( true === $this->object_read ) { |
|
2048 | - |
|
2049 | - // Only allow valid new status. |
|
2050 | - if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
2051 | - $new_status = $this->get_default_status(); |
|
2052 | - } |
|
2053 | - |
|
2054 | - // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
2055 | - if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
2056 | - $old_status = $this->get_default_status(); |
|
2057 | - } |
|
2058 | - |
|
2059 | - // Paid - Renewal (i.e when duplicating a parent invoice ) |
|
2060 | - if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
2061 | - $old_status = 'wpi-pending'; |
|
2062 | - } |
|
2063 | - |
|
2064 | - if ( $old_status !== $new_status ) { |
|
2065 | - $this->status_transition = array( |
|
2066 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
2067 | - 'to' => $new_status, |
|
2068 | - 'note' => $note, |
|
2069 | - 'manual' => (bool) $manual_update, |
|
2070 | - ); |
|
2071 | - |
|
2072 | - if ( $manual_update ) { |
|
2073 | - do_action( 'getpaid_' . $this->object_type . '_edit_status', $this->get_id(), $new_status ); |
|
2074 | - } |
|
2075 | - |
|
2076 | - $this->maybe_set_date_paid(); |
|
2077 | - |
|
2078 | - } |
|
2079 | - } |
|
2080 | - |
|
2081 | - return array( |
|
2082 | - 'from' => $old_status, |
|
2083 | - 'to' => $new_status, |
|
2084 | - ); |
|
2085 | - } |
|
2086 | - |
|
2087 | - /** |
|
2088 | - * Maybe set date paid. |
|
2089 | - * |
|
2090 | - * Sets the date paid variable when transitioning to the payment complete |
|
2091 | - * order status. |
|
2092 | - * |
|
2093 | - * @since 1.0.19 |
|
2094 | - */ |
|
2095 | - public function maybe_set_date_paid() { |
|
2096 | - |
|
2097 | - if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
2098 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
2099 | - } |
|
2100 | - } |
|
2101 | - |
|
2102 | - /** |
|
2103 | - * Set parent invoice ID. |
|
2104 | - * |
|
2105 | - * @since 1.0.19 |
|
2106 | - */ |
|
2107 | - public function set_parent_id( $value ) { |
|
2108 | - if ( $value && ( $value === $this->get_id() ) ) { |
|
2109 | - return; |
|
2110 | - } |
|
2111 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
2112 | - } |
|
2113 | - |
|
2114 | - /** |
|
2115 | - * Set plugin version when the invoice was created. |
|
2116 | - * |
|
2117 | - * @since 1.0.19 |
|
2118 | - */ |
|
2119 | - public function set_version( $value ) { |
|
2120 | - $this->set_prop( 'version', $value ); |
|
2121 | - } |
|
2122 | - |
|
2123 | - /** |
|
2124 | - * Set date when the invoice was created. |
|
2125 | - * |
|
2126 | - * @since 1.0.19 |
|
2127 | - * @param string $value Value to set. |
|
2024 | + } |
|
2025 | + |
|
2026 | + /** |
|
2027 | + * Sets item status. |
|
2028 | + * |
|
2029 | + * @since 1.0.19 |
|
2030 | + * @param string $new_status New status. |
|
2031 | + * @param string $note Optional note to add. |
|
2032 | + * @param bool $manual_update Is this a manual status change?. |
|
2033 | + * @return array details of change. |
|
2034 | + */ |
|
2035 | + public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
2036 | + $old_status = $this->get_status(); |
|
2037 | + |
|
2038 | + $statuses = $this->get_all_statuses(); |
|
2039 | + |
|
2040 | + if ( isset( $statuses['draft'] ) ) { |
|
2041 | + unset( $statuses['draft'] ); |
|
2042 | + } |
|
2043 | + |
|
2044 | + $this->set_prop( 'status', $new_status ); |
|
2045 | + |
|
2046 | + // If setting the status, ensure it's set to a valid status. |
|
2047 | + if ( true === $this->object_read ) { |
|
2048 | + |
|
2049 | + // Only allow valid new status. |
|
2050 | + if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
2051 | + $new_status = $this->get_default_status(); |
|
2052 | + } |
|
2053 | + |
|
2054 | + // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
2055 | + if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
2056 | + $old_status = $this->get_default_status(); |
|
2057 | + } |
|
2058 | + |
|
2059 | + // Paid - Renewal (i.e when duplicating a parent invoice ) |
|
2060 | + if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
2061 | + $old_status = 'wpi-pending'; |
|
2062 | + } |
|
2063 | + |
|
2064 | + if ( $old_status !== $new_status ) { |
|
2065 | + $this->status_transition = array( |
|
2066 | + 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
2067 | + 'to' => $new_status, |
|
2068 | + 'note' => $note, |
|
2069 | + 'manual' => (bool) $manual_update, |
|
2070 | + ); |
|
2071 | + |
|
2072 | + if ( $manual_update ) { |
|
2073 | + do_action( 'getpaid_' . $this->object_type . '_edit_status', $this->get_id(), $new_status ); |
|
2074 | + } |
|
2075 | + |
|
2076 | + $this->maybe_set_date_paid(); |
|
2077 | + |
|
2078 | + } |
|
2079 | + } |
|
2080 | + |
|
2081 | + return array( |
|
2082 | + 'from' => $old_status, |
|
2083 | + 'to' => $new_status, |
|
2084 | + ); |
|
2085 | + } |
|
2086 | + |
|
2087 | + /** |
|
2088 | + * Maybe set date paid. |
|
2089 | + * |
|
2090 | + * Sets the date paid variable when transitioning to the payment complete |
|
2091 | + * order status. |
|
2092 | + * |
|
2093 | + * @since 1.0.19 |
|
2094 | + */ |
|
2095 | + public function maybe_set_date_paid() { |
|
2096 | + |
|
2097 | + if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
2098 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
2099 | + } |
|
2100 | + } |
|
2101 | + |
|
2102 | + /** |
|
2103 | + * Set parent invoice ID. |
|
2104 | + * |
|
2105 | + * @since 1.0.19 |
|
2106 | + */ |
|
2107 | + public function set_parent_id( $value ) { |
|
2108 | + if ( $value && ( $value === $this->get_id() ) ) { |
|
2109 | + return; |
|
2110 | + } |
|
2111 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
2112 | + } |
|
2113 | + |
|
2114 | + /** |
|
2115 | + * Set plugin version when the invoice was created. |
|
2116 | + * |
|
2117 | + * @since 1.0.19 |
|
2118 | + */ |
|
2119 | + public function set_version( $value ) { |
|
2120 | + $this->set_prop( 'version', $value ); |
|
2121 | + } |
|
2122 | + |
|
2123 | + /** |
|
2124 | + * Set date when the invoice was created. |
|
2125 | + * |
|
2126 | + * @since 1.0.19 |
|
2127 | + * @param string $value Value to set. |
|
2128 | 2128 | * @return bool Whether or not the date was set. |
2129 | - */ |
|
2130 | - public function set_date_created( $value ) { |
|
2129 | + */ |
|
2130 | + public function set_date_created( $value ) { |
|
2131 | 2131 | $date = strtotime( $value ); |
2132 | 2132 | |
2133 | 2133 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2135,19 +2135,19 @@ discard block |
||
2135 | 2135 | return true; |
2136 | 2136 | } |
2137 | 2137 | |
2138 | - $this->set_prop( 'date_created', '' ); |
|
2139 | - return false; |
|
2138 | + $this->set_prop( 'date_created', '' ); |
|
2139 | + return false; |
|
2140 | 2140 | |
2141 | 2141 | } |
2142 | 2142 | |
2143 | 2143 | /** |
2144 | - * Set date invoice due date. |
|
2145 | - * |
|
2146 | - * @since 1.0.19 |
|
2147 | - * @param string $value Value to set. |
|
2144 | + * Set date invoice due date. |
|
2145 | + * |
|
2146 | + * @since 1.0.19 |
|
2147 | + * @param string $value Value to set. |
|
2148 | 2148 | * @return bool Whether or not the date was set. |
2149 | - */ |
|
2150 | - public function set_due_date( $value ) { |
|
2149 | + */ |
|
2150 | + public function set_due_date( $value ) { |
|
2151 | 2151 | $date = strtotime( $value ); |
2152 | 2152 | |
2153 | 2153 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2155,29 +2155,29 @@ discard block |
||
2155 | 2155 | return true; |
2156 | 2156 | } |
2157 | 2157 | |
2158 | - $this->set_prop( 'due_date', '' ); |
|
2158 | + $this->set_prop( 'due_date', '' ); |
|
2159 | 2159 | return false; |
2160 | 2160 | |
2161 | 2161 | } |
2162 | 2162 | |
2163 | 2163 | /** |
2164 | - * Alias of self::set_due_date(). |
|
2165 | - * |
|
2166 | - * @since 1.0.19 |
|
2167 | - * @param string $value New name. |
|
2168 | - */ |
|
2169 | - public function set_date_due( $value ) { |
|
2170 | - $this->set_due_date( $value ); |
|
2164 | + * Alias of self::set_due_date(). |
|
2165 | + * |
|
2166 | + * @since 1.0.19 |
|
2167 | + * @param string $value New name. |
|
2168 | + */ |
|
2169 | + public function set_date_due( $value ) { |
|
2170 | + $this->set_due_date( $value ); |
|
2171 | 2171 | } |
2172 | 2172 | |
2173 | 2173 | /** |
2174 | - * Set date invoice was completed. |
|
2175 | - * |
|
2176 | - * @since 1.0.19 |
|
2177 | - * @param string $value Value to set. |
|
2174 | + * Set date invoice was completed. |
|
2175 | + * |
|
2176 | + * @since 1.0.19 |
|
2177 | + * @param string $value Value to set. |
|
2178 | 2178 | * @return bool Whether or not the date was set. |
2179 | - */ |
|
2180 | - public function set_completed_date( $value ) { |
|
2179 | + */ |
|
2180 | + public function set_completed_date( $value ) { |
|
2181 | 2181 | $date = strtotime( $value ); |
2182 | 2182 | |
2183 | 2183 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2185,29 +2185,29 @@ discard block |
||
2185 | 2185 | return true; |
2186 | 2186 | } |
2187 | 2187 | |
2188 | - $this->set_prop( 'completed_date', '' ); |
|
2188 | + $this->set_prop( 'completed_date', '' ); |
|
2189 | 2189 | return false; |
2190 | 2190 | |
2191 | 2191 | } |
2192 | 2192 | |
2193 | 2193 | /** |
2194 | - * Alias of self::set_completed_date(). |
|
2195 | - * |
|
2196 | - * @since 1.0.19 |
|
2197 | - * @param string $value New name. |
|
2198 | - */ |
|
2199 | - public function set_date_completed( $value ) { |
|
2200 | - $this->set_completed_date( $value ); |
|
2194 | + * Alias of self::set_completed_date(). |
|
2195 | + * |
|
2196 | + * @since 1.0.19 |
|
2197 | + * @param string $value New name. |
|
2198 | + */ |
|
2199 | + public function set_date_completed( $value ) { |
|
2200 | + $this->set_completed_date( $value ); |
|
2201 | 2201 | } |
2202 | 2202 | |
2203 | 2203 | /** |
2204 | - * Set date when the invoice was last modified. |
|
2205 | - * |
|
2206 | - * @since 1.0.19 |
|
2207 | - * @param string $value Value to set. |
|
2204 | + * Set date when the invoice was last modified. |
|
2205 | + * |
|
2206 | + * @since 1.0.19 |
|
2207 | + * @param string $value Value to set. |
|
2208 | 2208 | * @return bool Whether or not the date was set. |
2209 | - */ |
|
2210 | - public function set_date_modified( $value ) { |
|
2209 | + */ |
|
2210 | + public function set_date_modified( $value ) { |
|
2211 | 2211 | $date = strtotime( $value ); |
2212 | 2212 | |
2213 | 2213 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2215,813 +2215,813 @@ discard block |
||
2215 | 2215 | return true; |
2216 | 2216 | } |
2217 | 2217 | |
2218 | - $this->set_prop( 'date_modified', '' ); |
|
2218 | + $this->set_prop( 'date_modified', '' ); |
|
2219 | 2219 | return false; |
2220 | 2220 | |
2221 | 2221 | } |
2222 | 2222 | |
2223 | 2223 | /** |
2224 | - * Set the invoice number. |
|
2225 | - * |
|
2226 | - * @since 1.0.19 |
|
2227 | - * @param string $value New number. |
|
2228 | - */ |
|
2229 | - public function set_number( $value ) { |
|
2224 | + * Set the invoice number. |
|
2225 | + * |
|
2226 | + * @since 1.0.19 |
|
2227 | + * @param string $value New number. |
|
2228 | + */ |
|
2229 | + public function set_number( $value ) { |
|
2230 | 2230 | $number = sanitize_text_field( $value ); |
2231 | - $this->set_prop( 'number', $number ); |
|
2231 | + $this->set_prop( 'number', $number ); |
|
2232 | 2232 | } |
2233 | 2233 | |
2234 | 2234 | /** |
2235 | - * Set the invoice type. |
|
2236 | - * |
|
2237 | - * @since 1.0.19 |
|
2238 | - * @param string $value Type. |
|
2239 | - */ |
|
2240 | - public function set_type( $value ) { |
|
2235 | + * Set the invoice type. |
|
2236 | + * |
|
2237 | + * @since 1.0.19 |
|
2238 | + * @param string $value Type. |
|
2239 | + */ |
|
2240 | + public function set_type( $value ) { |
|
2241 | 2241 | $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) ); |
2242 | - $this->set_prop( 'type', $type ); |
|
2243 | - } |
|
2242 | + $this->set_prop( 'type', $type ); |
|
2243 | + } |
|
2244 | 2244 | |
2245 | 2245 | /** |
2246 | - * Set the invoice post type. |
|
2247 | - * |
|
2248 | - * @since 1.0.19 |
|
2249 | - * @param string $value Post type. |
|
2250 | - */ |
|
2251 | - public function set_post_type( $value ) { |
|
2246 | + * Set the invoice post type. |
|
2247 | + * |
|
2248 | + * @since 1.0.19 |
|
2249 | + * @param string $value Post type. |
|
2250 | + */ |
|
2251 | + public function set_post_type( $value ) { |
|
2252 | 2252 | if ( getpaid_is_invoice_post_type( $value ) ) { |
2253 | - $this->set_type( $value ); |
|
2253 | + $this->set_type( $value ); |
|
2254 | 2254 | $this->set_prop( 'post_type', $value ); |
2255 | 2255 | } |
2256 | 2256 | } |
2257 | 2257 | |
2258 | 2258 | /** |
2259 | - * Set the invoice key. |
|
2260 | - * |
|
2261 | - * @since 1.0.19 |
|
2262 | - * @param string $value New key. |
|
2263 | - */ |
|
2264 | - public function set_key( $value ) { |
|
2259 | + * Set the invoice key. |
|
2260 | + * |
|
2261 | + * @since 1.0.19 |
|
2262 | + * @param string $value New key. |
|
2263 | + */ |
|
2264 | + public function set_key( $value ) { |
|
2265 | 2265 | $key = sanitize_text_field( $value ); |
2266 | - $this->set_prop( 'key', $key ); |
|
2266 | + $this->set_prop( 'key', $key ); |
|
2267 | 2267 | } |
2268 | 2268 | |
2269 | 2269 | /** |
2270 | - * Set the invoice mode. |
|
2271 | - * |
|
2272 | - * @since 1.0.19 |
|
2273 | - * @param string $value mode. |
|
2274 | - */ |
|
2275 | - public function set_mode( $value ) { |
|
2270 | + * Set the invoice mode. |
|
2271 | + * |
|
2272 | + * @since 1.0.19 |
|
2273 | + * @param string $value mode. |
|
2274 | + */ |
|
2275 | + public function set_mode( $value ) { |
|
2276 | 2276 | if ( in_array( $value, array( 'live', 'test' ) ) ) { |
2277 | 2277 | $this->set_prop( 'mode', $value ); |
2278 | 2278 | } |
2279 | 2279 | } |
2280 | 2280 | |
2281 | 2281 | /** |
2282 | - * Set the invoice path. |
|
2283 | - * |
|
2284 | - * @since 1.0.19 |
|
2285 | - * @param string $value path. |
|
2286 | - */ |
|
2287 | - public function set_path( $value ) { |
|
2282 | + * Set the invoice path. |
|
2283 | + * |
|
2284 | + * @since 1.0.19 |
|
2285 | + * @param string $value path. |
|
2286 | + */ |
|
2287 | + public function set_path( $value ) { |
|
2288 | 2288 | $this->set_prop( 'path', $value ); |
2289 | 2289 | } |
2290 | 2290 | |
2291 | 2291 | /** |
2292 | - * Set the invoice name. |
|
2293 | - * |
|
2294 | - * @since 1.0.19 |
|
2295 | - * @param string $value New name. |
|
2296 | - */ |
|
2297 | - public function set_name( $value ) { |
|
2292 | + * Set the invoice name. |
|
2293 | + * |
|
2294 | + * @since 1.0.19 |
|
2295 | + * @param string $value New name. |
|
2296 | + */ |
|
2297 | + public function set_name( $value ) { |
|
2298 | 2298 | $name = sanitize_text_field( $value ); |
2299 | - $this->set_prop( 'name', $name ); |
|
2299 | + $this->set_prop( 'name', $name ); |
|
2300 | 2300 | } |
2301 | 2301 | |
2302 | 2302 | /** |
2303 | - * Alias of self::set_name(). |
|
2304 | - * |
|
2305 | - * @since 1.0.19 |
|
2306 | - * @param string $value New name. |
|
2307 | - */ |
|
2308 | - public function set_title( $value ) { |
|
2309 | - $this->set_name( $value ); |
|
2303 | + * Alias of self::set_name(). |
|
2304 | + * |
|
2305 | + * @since 1.0.19 |
|
2306 | + * @param string $value New name. |
|
2307 | + */ |
|
2308 | + public function set_title( $value ) { |
|
2309 | + $this->set_name( $value ); |
|
2310 | 2310 | } |
2311 | 2311 | |
2312 | 2312 | /** |
2313 | - * Set the invoice description. |
|
2314 | - * |
|
2315 | - * @since 1.0.19 |
|
2316 | - * @param string $value New description. |
|
2317 | - */ |
|
2318 | - public function set_description( $value ) { |
|
2313 | + * Set the invoice description. |
|
2314 | + * |
|
2315 | + * @since 1.0.19 |
|
2316 | + * @param string $value New description. |
|
2317 | + */ |
|
2318 | + public function set_description( $value ) { |
|
2319 | 2319 | $description = wp_kses_post( $value ); |
2320 | - $this->set_prop( 'description', $description ); |
|
2320 | + $this->set_prop( 'description', $description ); |
|
2321 | + } |
|
2322 | + |
|
2323 | + /** |
|
2324 | + * Alias of self::set_description(). |
|
2325 | + * |
|
2326 | + * @since 1.0.19 |
|
2327 | + * @param string $value New description. |
|
2328 | + */ |
|
2329 | + public function set_excerpt( $value ) { |
|
2330 | + $this->set_description( $value ); |
|
2331 | + } |
|
2332 | + |
|
2333 | + /** |
|
2334 | + * Alias of self::set_description(). |
|
2335 | + * |
|
2336 | + * @since 1.0.19 |
|
2337 | + * @param string $value New description. |
|
2338 | + */ |
|
2339 | + public function set_summary( $value ) { |
|
2340 | + $this->set_description( $value ); |
|
2341 | + } |
|
2342 | + |
|
2343 | + /** |
|
2344 | + * Set the receiver of the invoice. |
|
2345 | + * |
|
2346 | + * @since 1.0.19 |
|
2347 | + * @param int $value New author. |
|
2348 | + */ |
|
2349 | + public function set_author( $value ) { |
|
2350 | + $user = get_user_by( 'id', (int) $value ); |
|
2351 | + |
|
2352 | + if ( $user && $user->ID ) { |
|
2353 | + $this->set_prop( 'author', $user->ID ); |
|
2354 | + $this->set_prop( 'email', $user->user_email ); |
|
2355 | + } |
|
2356 | + |
|
2357 | + } |
|
2358 | + |
|
2359 | + /** |
|
2360 | + * Alias of self::set_author(). |
|
2361 | + * |
|
2362 | + * @since 1.0.19 |
|
2363 | + * @param int $value New user id. |
|
2364 | + */ |
|
2365 | + public function set_user_id( $value ) { |
|
2366 | + $this->set_author( $value ); |
|
2367 | + } |
|
2368 | + |
|
2369 | + /** |
|
2370 | + * Sets the customer ID. |
|
2371 | + * |
|
2372 | + * @since 1.0.19 |
|
2373 | + * @param int $value New user id. |
|
2374 | + */ |
|
2375 | + public function set_customer_id( $value ) { |
|
2376 | + $this->set_prop( 'customer_id', (int) $value ); |
|
2377 | + } |
|
2378 | + |
|
2379 | + /** |
|
2380 | + * Set the customer's ip. |
|
2381 | + * |
|
2382 | + * @since 1.0.19 |
|
2383 | + * @param string $value ip address. |
|
2384 | + */ |
|
2385 | + public function set_ip( $value ) { |
|
2386 | + $this->set_prop( 'ip', $value ); |
|
2387 | + } |
|
2388 | + |
|
2389 | + /** |
|
2390 | + * Alias of self::set_ip(). |
|
2391 | + * |
|
2392 | + * @since 1.0.19 |
|
2393 | + * @param string $value ip address. |
|
2394 | + */ |
|
2395 | + public function set_user_ip( $value ) { |
|
2396 | + $this->set_ip( $value ); |
|
2397 | + } |
|
2398 | + |
|
2399 | + /** |
|
2400 | + * Set the customer's first name. |
|
2401 | + * |
|
2402 | + * @since 1.0.19 |
|
2403 | + * @param string $value first name. |
|
2404 | + */ |
|
2405 | + public function set_first_name( $value ) { |
|
2406 | + $this->set_prop( 'first_name', $value ); |
|
2407 | + } |
|
2408 | + |
|
2409 | + /** |
|
2410 | + * Alias of self::set_first_name(). |
|
2411 | + * |
|
2412 | + * @since 1.0.19 |
|
2413 | + * @param string $value first name. |
|
2414 | + */ |
|
2415 | + public function set_user_first_name( $value ) { |
|
2416 | + $this->set_first_name( $value ); |
|
2417 | + } |
|
2418 | + |
|
2419 | + /** |
|
2420 | + * Alias of self::set_first_name(). |
|
2421 | + * |
|
2422 | + * @since 1.0.19 |
|
2423 | + * @param string $value first name. |
|
2424 | + */ |
|
2425 | + public function set_customer_first_name( $value ) { |
|
2426 | + $this->set_first_name( $value ); |
|
2427 | + } |
|
2428 | + |
|
2429 | + /** |
|
2430 | + * Set the customer's last name. |
|
2431 | + * |
|
2432 | + * @since 1.0.19 |
|
2433 | + * @param string $value last name. |
|
2434 | + */ |
|
2435 | + public function set_last_name( $value ) { |
|
2436 | + $this->set_prop( 'last_name', $value ); |
|
2437 | + } |
|
2438 | + |
|
2439 | + /** |
|
2440 | + * Alias of self::set_last_name(). |
|
2441 | + * |
|
2442 | + * @since 1.0.19 |
|
2443 | + * @param string $value last name. |
|
2444 | + */ |
|
2445 | + public function set_user_last_name( $value ) { |
|
2446 | + $this->set_last_name( $value ); |
|
2447 | + } |
|
2448 | + |
|
2449 | + /** |
|
2450 | + * Alias of self::set_last_name(). |
|
2451 | + * |
|
2452 | + * @since 1.0.19 |
|
2453 | + * @param string $value last name. |
|
2454 | + */ |
|
2455 | + public function set_customer_last_name( $value ) { |
|
2456 | + $this->set_last_name( $value ); |
|
2457 | + } |
|
2458 | + |
|
2459 | + /** |
|
2460 | + * Set the customer's phone number. |
|
2461 | + * |
|
2462 | + * @since 1.0.19 |
|
2463 | + * @param string $value phone. |
|
2464 | + */ |
|
2465 | + public function set_phone( $value ) { |
|
2466 | + $this->set_prop( 'phone', $value ); |
|
2321 | 2467 | } |
2322 | 2468 | |
2323 | 2469 | /** |
2324 | - * Alias of self::set_description(). |
|
2325 | - * |
|
2326 | - * @since 1.0.19 |
|
2327 | - * @param string $value New description. |
|
2328 | - */ |
|
2329 | - public function set_excerpt( $value ) { |
|
2330 | - $this->set_description( $value ); |
|
2470 | + * Alias of self::set_phone(). |
|
2471 | + * |
|
2472 | + * @since 1.0.19 |
|
2473 | + * @param string $value phone. |
|
2474 | + */ |
|
2475 | + public function set_user_phone( $value ) { |
|
2476 | + $this->set_phone( $value ); |
|
2331 | 2477 | } |
2332 | 2478 | |
2333 | 2479 | /** |
2334 | - * Alias of self::set_description(). |
|
2335 | - * |
|
2336 | - * @since 1.0.19 |
|
2337 | - * @param string $value New description. |
|
2338 | - */ |
|
2339 | - public function set_summary( $value ) { |
|
2340 | - $this->set_description( $value ); |
|
2480 | + * Alias of self::set_phone(). |
|
2481 | + * |
|
2482 | + * @since 1.0.19 |
|
2483 | + * @param string $value phone. |
|
2484 | + */ |
|
2485 | + public function set_customer_phone( $value ) { |
|
2486 | + $this->set_phone( $value ); |
|
2341 | 2487 | } |
2342 | 2488 | |
2343 | 2489 | /** |
2344 | - * Set the receiver of the invoice. |
|
2345 | - * |
|
2346 | - * @since 1.0.19 |
|
2347 | - * @param int $value New author. |
|
2348 | - */ |
|
2349 | - public function set_author( $value ) { |
|
2350 | - $user = get_user_by( 'id', (int) $value ); |
|
2490 | + * Alias of self::set_phone(). |
|
2491 | + * |
|
2492 | + * @since 1.0.19 |
|
2493 | + * @param string $value phone. |
|
2494 | + */ |
|
2495 | + public function set_phone_number( $value ) { |
|
2496 | + $this->set_phone( $value ); |
|
2497 | + } |
|
2351 | 2498 | |
2352 | - if ( $user && $user->ID ) { |
|
2353 | - $this->set_prop( 'author', $user->ID ); |
|
2354 | - $this->set_prop( 'email', $user->user_email ); |
|
2355 | - } |
|
2499 | + /** |
|
2500 | + * Set the customer's email address. |
|
2501 | + * |
|
2502 | + * @since 1.0.19 |
|
2503 | + * @param string $value email address. |
|
2504 | + */ |
|
2505 | + public function set_email( $value ) { |
|
2506 | + $this->set_prop( 'email', $value ); |
|
2507 | + } |
|
2356 | 2508 | |
2509 | + /** |
|
2510 | + * Alias of self::set_email(). |
|
2511 | + * |
|
2512 | + * @since 1.0.19 |
|
2513 | + * @param string $value email address. |
|
2514 | + */ |
|
2515 | + public function set_user_email( $value ) { |
|
2516 | + $this->set_email( $value ); |
|
2357 | 2517 | } |
2358 | 2518 | |
2359 | 2519 | /** |
2360 | - * Alias of self::set_author(). |
|
2361 | - * |
|
2362 | - * @since 1.0.19 |
|
2363 | - * @param int $value New user id. |
|
2364 | - */ |
|
2365 | - public function set_user_id( $value ) { |
|
2366 | - $this->set_author( $value ); |
|
2520 | + * Alias of self::set_email(). |
|
2521 | + * |
|
2522 | + * @since 1.0.19 |
|
2523 | + * @param string $value email address. |
|
2524 | + */ |
|
2525 | + public function set_email_address( $value ) { |
|
2526 | + $this->set_email( $value ); |
|
2367 | 2527 | } |
2368 | 2528 | |
2369 | 2529 | /** |
2370 | - * Sets the customer ID. |
|
2371 | - * |
|
2372 | - * @since 1.0.19 |
|
2373 | - * @param int $value New user id. |
|
2374 | - */ |
|
2375 | - public function set_customer_id( $value ) { |
|
2376 | - $this->set_prop( 'customer_id', (int) $value ); |
|
2530 | + * Alias of self::set_email(). |
|
2531 | + * |
|
2532 | + * @since 1.0.19 |
|
2533 | + * @param string $value email address. |
|
2534 | + */ |
|
2535 | + public function set_customer_email( $value ) { |
|
2536 | + $this->set_email( $value ); |
|
2377 | 2537 | } |
2378 | 2538 | |
2379 | 2539 | /** |
2380 | - * Set the customer's ip. |
|
2381 | - * |
|
2382 | - * @since 1.0.19 |
|
2383 | - * @param string $value ip address. |
|
2384 | - */ |
|
2385 | - public function set_ip( $value ) { |
|
2386 | - $this->set_prop( 'ip', $value ); |
|
2540 | + * Set the customer's country. |
|
2541 | + * |
|
2542 | + * @since 1.0.19 |
|
2543 | + * @param string $value country. |
|
2544 | + */ |
|
2545 | + public function set_country( $value ) { |
|
2546 | + $this->set_prop( 'country', $value ); |
|
2387 | 2547 | } |
2388 | 2548 | |
2389 | 2549 | /** |
2390 | - * Alias of self::set_ip(). |
|
2391 | - * |
|
2392 | - * @since 1.0.19 |
|
2393 | - * @param string $value ip address. |
|
2394 | - */ |
|
2395 | - public function set_user_ip( $value ) { |
|
2396 | - $this->set_ip( $value ); |
|
2550 | + * Alias of self::set_country(). |
|
2551 | + * |
|
2552 | + * @since 1.0.19 |
|
2553 | + * @param string $value country. |
|
2554 | + */ |
|
2555 | + public function set_user_country( $value ) { |
|
2556 | + $this->set_country( $value ); |
|
2397 | 2557 | } |
2398 | 2558 | |
2399 | 2559 | /** |
2400 | - * Set the customer's first name. |
|
2401 | - * |
|
2402 | - * @since 1.0.19 |
|
2403 | - * @param string $value first name. |
|
2404 | - */ |
|
2405 | - public function set_first_name( $value ) { |
|
2406 | - $this->set_prop( 'first_name', $value ); |
|
2560 | + * Alias of self::set_country(). |
|
2561 | + * |
|
2562 | + * @since 1.0.19 |
|
2563 | + * @param string $value country. |
|
2564 | + */ |
|
2565 | + public function set_customer_country( $value ) { |
|
2566 | + $this->set_country( $value ); |
|
2407 | 2567 | } |
2408 | 2568 | |
2409 | 2569 | /** |
2410 | - * Alias of self::set_first_name(). |
|
2411 | - * |
|
2412 | - * @since 1.0.19 |
|
2413 | - * @param string $value first name. |
|
2414 | - */ |
|
2415 | - public function set_user_first_name( $value ) { |
|
2416 | - $this->set_first_name( $value ); |
|
2570 | + * Set the customer's state. |
|
2571 | + * |
|
2572 | + * @since 1.0.19 |
|
2573 | + * @param string $value state. |
|
2574 | + */ |
|
2575 | + public function set_state( $value ) { |
|
2576 | + $this->set_prop( 'state', $value ); |
|
2417 | 2577 | } |
2418 | 2578 | |
2419 | 2579 | /** |
2420 | - * Alias of self::set_first_name(). |
|
2421 | - * |
|
2422 | - * @since 1.0.19 |
|
2423 | - * @param string $value first name. |
|
2424 | - */ |
|
2425 | - public function set_customer_first_name( $value ) { |
|
2426 | - $this->set_first_name( $value ); |
|
2580 | + * Alias of self::set_state(). |
|
2581 | + * |
|
2582 | + * @since 1.0.19 |
|
2583 | + * @param string $value state. |
|
2584 | + */ |
|
2585 | + public function set_user_state( $value ) { |
|
2586 | + $this->set_state( $value ); |
|
2427 | 2587 | } |
2428 | 2588 | |
2429 | 2589 | /** |
2430 | - * Set the customer's last name. |
|
2431 | - * |
|
2432 | - * @since 1.0.19 |
|
2433 | - * @param string $value last name. |
|
2434 | - */ |
|
2435 | - public function set_last_name( $value ) { |
|
2436 | - $this->set_prop( 'last_name', $value ); |
|
2590 | + * Alias of self::set_state(). |
|
2591 | + * |
|
2592 | + * @since 1.0.19 |
|
2593 | + * @param string $value state. |
|
2594 | + */ |
|
2595 | + public function set_customer_state( $value ) { |
|
2596 | + $this->set_state( $value ); |
|
2437 | 2597 | } |
2438 | 2598 | |
2439 | 2599 | /** |
2440 | - * Alias of self::set_last_name(). |
|
2441 | - * |
|
2442 | - * @since 1.0.19 |
|
2443 | - * @param string $value last name. |
|
2444 | - */ |
|
2445 | - public function set_user_last_name( $value ) { |
|
2446 | - $this->set_last_name( $value ); |
|
2600 | + * Set the customer's city. |
|
2601 | + * |
|
2602 | + * @since 1.0.19 |
|
2603 | + * @param string $value city. |
|
2604 | + */ |
|
2605 | + public function set_city( $value ) { |
|
2606 | + $this->set_prop( 'city', $value ); |
|
2447 | 2607 | } |
2448 | 2608 | |
2449 | 2609 | /** |
2450 | - * Alias of self::set_last_name(). |
|
2451 | - * |
|
2452 | - * @since 1.0.19 |
|
2453 | - * @param string $value last name. |
|
2454 | - */ |
|
2455 | - public function set_customer_last_name( $value ) { |
|
2456 | - $this->set_last_name( $value ); |
|
2610 | + * Alias of self::set_city(). |
|
2611 | + * |
|
2612 | + * @since 1.0.19 |
|
2613 | + * @param string $value city. |
|
2614 | + */ |
|
2615 | + public function set_user_city( $value ) { |
|
2616 | + $this->set_city( $value ); |
|
2457 | 2617 | } |
2458 | 2618 | |
2459 | 2619 | /** |
2460 | - * Set the customer's phone number. |
|
2461 | - * |
|
2462 | - * @since 1.0.19 |
|
2463 | - * @param string $value phone. |
|
2464 | - */ |
|
2465 | - public function set_phone( $value ) { |
|
2466 | - $this->set_prop( 'phone', $value ); |
|
2620 | + * Alias of self::set_city(). |
|
2621 | + * |
|
2622 | + * @since 1.0.19 |
|
2623 | + * @param string $value city. |
|
2624 | + */ |
|
2625 | + public function set_customer_city( $value ) { |
|
2626 | + $this->set_city( $value ); |
|
2467 | 2627 | } |
2468 | 2628 | |
2469 | 2629 | /** |
2470 | - * Alias of self::set_phone(). |
|
2471 | - * |
|
2472 | - * @since 1.0.19 |
|
2473 | - * @param string $value phone. |
|
2474 | - */ |
|
2475 | - public function set_user_phone( $value ) { |
|
2476 | - $this->set_phone( $value ); |
|
2630 | + * Set the customer's zip code. |
|
2631 | + * |
|
2632 | + * @since 1.0.19 |
|
2633 | + * @param string $value zip. |
|
2634 | + */ |
|
2635 | + public function set_zip( $value ) { |
|
2636 | + $this->set_prop( 'zip', $value ); |
|
2477 | 2637 | } |
2478 | 2638 | |
2479 | 2639 | /** |
2480 | - * Alias of self::set_phone(). |
|
2481 | - * |
|
2482 | - * @since 1.0.19 |
|
2483 | - * @param string $value phone. |
|
2484 | - */ |
|
2485 | - public function set_customer_phone( $value ) { |
|
2486 | - $this->set_phone( $value ); |
|
2640 | + * Alias of self::set_zip(). |
|
2641 | + * |
|
2642 | + * @since 1.0.19 |
|
2643 | + * @param string $value zip. |
|
2644 | + */ |
|
2645 | + public function set_user_zip( $value ) { |
|
2646 | + $this->set_zip( $value ); |
|
2487 | 2647 | } |
2488 | 2648 | |
2489 | 2649 | /** |
2490 | - * Alias of self::set_phone(). |
|
2491 | - * |
|
2492 | - * @since 1.0.19 |
|
2493 | - * @param string $value phone. |
|
2494 | - */ |
|
2495 | - public function set_phone_number( $value ) { |
|
2496 | - $this->set_phone( $value ); |
|
2650 | + * Alias of self::set_zip(). |
|
2651 | + * |
|
2652 | + * @since 1.0.19 |
|
2653 | + * @param string $value zip. |
|
2654 | + */ |
|
2655 | + public function set_customer_zip( $value ) { |
|
2656 | + $this->set_zip( $value ); |
|
2497 | 2657 | } |
2498 | 2658 | |
2499 | 2659 | /** |
2500 | - * Set the customer's email address. |
|
2501 | - * |
|
2502 | - * @since 1.0.19 |
|
2503 | - * @param string $value email address. |
|
2504 | - */ |
|
2505 | - public function set_email( $value ) { |
|
2506 | - $this->set_prop( 'email', $value ); |
|
2660 | + * Set the customer's company. |
|
2661 | + * |
|
2662 | + * @since 1.0.19 |
|
2663 | + * @param string $value company. |
|
2664 | + */ |
|
2665 | + public function set_company( $value ) { |
|
2666 | + $this->set_prop( 'company', $value ); |
|
2507 | 2667 | } |
2508 | 2668 | |
2509 | 2669 | /** |
2510 | - * Alias of self::set_email(). |
|
2511 | - * |
|
2512 | - * @since 1.0.19 |
|
2513 | - * @param string $value email address. |
|
2514 | - */ |
|
2515 | - public function set_user_email( $value ) { |
|
2516 | - $this->set_email( $value ); |
|
2670 | + * Alias of self::set_company(). |
|
2671 | + * |
|
2672 | + * @since 1.0.19 |
|
2673 | + * @param string $value company. |
|
2674 | + */ |
|
2675 | + public function set_user_company( $value ) { |
|
2676 | + $this->set_company( $value ); |
|
2517 | 2677 | } |
2518 | 2678 | |
2519 | 2679 | /** |
2520 | - * Alias of self::set_email(). |
|
2521 | - * |
|
2522 | - * @since 1.0.19 |
|
2523 | - * @param string $value email address. |
|
2524 | - */ |
|
2525 | - public function set_email_address( $value ) { |
|
2526 | - $this->set_email( $value ); |
|
2680 | + * Alias of self::set_company(). |
|
2681 | + * |
|
2682 | + * @since 1.0.19 |
|
2683 | + * @param string $value company. |
|
2684 | + */ |
|
2685 | + public function set_customer_company( $value ) { |
|
2686 | + $this->set_company( $value ); |
|
2527 | 2687 | } |
2528 | 2688 | |
2529 | 2689 | /** |
2530 | - * Alias of self::set_email(). |
|
2531 | - * |
|
2532 | - * @since 1.0.19 |
|
2533 | - * @param string $value email address. |
|
2534 | - */ |
|
2535 | - public function set_customer_email( $value ) { |
|
2536 | - $this->set_email( $value ); |
|
2690 | + * Set the customer's company id. |
|
2691 | + * |
|
2692 | + * @since 1.0.19 |
|
2693 | + * @param string $value company id. |
|
2694 | + */ |
|
2695 | + public function set_company_id( $value ) { |
|
2696 | + $this->set_prop( 'company_id', $value ); |
|
2537 | 2697 | } |
2538 | 2698 | |
2539 | 2699 | /** |
2540 | - * Set the customer's country. |
|
2541 | - * |
|
2542 | - * @since 1.0.19 |
|
2543 | - * @param string $value country. |
|
2544 | - */ |
|
2545 | - public function set_country( $value ) { |
|
2546 | - $this->set_prop( 'country', $value ); |
|
2700 | + * Set the customer's var number. |
|
2701 | + * |
|
2702 | + * @since 1.0.19 |
|
2703 | + * @param string $value var number. |
|
2704 | + */ |
|
2705 | + public function set_vat_number( $value ) { |
|
2706 | + $this->set_prop( 'vat_number', $value ); |
|
2547 | 2707 | } |
2548 | 2708 | |
2549 | 2709 | /** |
2550 | - * Alias of self::set_country(). |
|
2551 | - * |
|
2552 | - * @since 1.0.19 |
|
2553 | - * @param string $value country. |
|
2554 | - */ |
|
2555 | - public function set_user_country( $value ) { |
|
2556 | - $this->set_country( $value ); |
|
2710 | + * Alias of self::set_vat_number(). |
|
2711 | + * |
|
2712 | + * @since 1.0.19 |
|
2713 | + * @param string $value var number. |
|
2714 | + */ |
|
2715 | + public function set_user_vat_number( $value ) { |
|
2716 | + $this->set_vat_number( $value ); |
|
2557 | 2717 | } |
2558 | 2718 | |
2559 | 2719 | /** |
2560 | - * Alias of self::set_country(). |
|
2561 | - * |
|
2562 | - * @since 1.0.19 |
|
2563 | - * @param string $value country. |
|
2564 | - */ |
|
2565 | - public function set_customer_country( $value ) { |
|
2566 | - $this->set_country( $value ); |
|
2720 | + * Alias of self::set_vat_number(). |
|
2721 | + * |
|
2722 | + * @since 1.0.19 |
|
2723 | + * @param string $value var number. |
|
2724 | + */ |
|
2725 | + public function set_customer_vat_number( $value ) { |
|
2726 | + $this->set_vat_number( $value ); |
|
2567 | 2727 | } |
2568 | 2728 | |
2569 | 2729 | /** |
2570 | - * Set the customer's state. |
|
2571 | - * |
|
2572 | - * @since 1.0.19 |
|
2573 | - * @param string $value state. |
|
2574 | - */ |
|
2575 | - public function set_state( $value ) { |
|
2576 | - $this->set_prop( 'state', $value ); |
|
2730 | + * Set the customer's vat rate. |
|
2731 | + * |
|
2732 | + * @since 1.0.19 |
|
2733 | + * @param string $value var rate. |
|
2734 | + */ |
|
2735 | + public function set_vat_rate( $value ) { |
|
2736 | + $this->set_prop( 'vat_rate', $value ); |
|
2577 | 2737 | } |
2578 | 2738 | |
2579 | 2739 | /** |
2580 | - * Alias of self::set_state(). |
|
2581 | - * |
|
2582 | - * @since 1.0.19 |
|
2583 | - * @param string $value state. |
|
2584 | - */ |
|
2585 | - public function set_user_state( $value ) { |
|
2586 | - $this->set_state( $value ); |
|
2740 | + * Alias of self::set_vat_rate(). |
|
2741 | + * |
|
2742 | + * @since 1.0.19 |
|
2743 | + * @param string $value var number. |
|
2744 | + */ |
|
2745 | + public function set_user_vat_rate( $value ) { |
|
2746 | + $this->set_vat_rate( $value ); |
|
2587 | 2747 | } |
2588 | 2748 | |
2589 | 2749 | /** |
2590 | - * Alias of self::set_state(). |
|
2591 | - * |
|
2592 | - * @since 1.0.19 |
|
2593 | - * @param string $value state. |
|
2594 | - */ |
|
2595 | - public function set_customer_state( $value ) { |
|
2596 | - $this->set_state( $value ); |
|
2750 | + * Alias of self::set_vat_rate(). |
|
2751 | + * |
|
2752 | + * @since 1.0.19 |
|
2753 | + * @param string $value var number. |
|
2754 | + */ |
|
2755 | + public function set_customer_vat_rate( $value ) { |
|
2756 | + $this->set_vat_rate( $value ); |
|
2597 | 2757 | } |
2598 | 2758 | |
2599 | 2759 | /** |
2600 | - * Set the customer's city. |
|
2601 | - * |
|
2602 | - * @since 1.0.19 |
|
2603 | - * @param string $value city. |
|
2604 | - */ |
|
2605 | - public function set_city( $value ) { |
|
2606 | - $this->set_prop( 'city', $value ); |
|
2760 | + * Set the customer's address. |
|
2761 | + * |
|
2762 | + * @since 1.0.19 |
|
2763 | + * @param string $value address. |
|
2764 | + */ |
|
2765 | + public function set_address( $value ) { |
|
2766 | + $this->set_prop( 'address', $value ); |
|
2607 | 2767 | } |
2608 | 2768 | |
2609 | 2769 | /** |
2610 | - * Alias of self::set_city(). |
|
2611 | - * |
|
2612 | - * @since 1.0.19 |
|
2613 | - * @param string $value city. |
|
2614 | - */ |
|
2615 | - public function set_user_city( $value ) { |
|
2616 | - $this->set_city( $value ); |
|
2770 | + * Alias of self::set_address(). |
|
2771 | + * |
|
2772 | + * @since 1.0.19 |
|
2773 | + * @param string $value address. |
|
2774 | + */ |
|
2775 | + public function set_user_address( $value ) { |
|
2776 | + $this->set_address( $value ); |
|
2617 | 2777 | } |
2618 | 2778 | |
2619 | 2779 | /** |
2620 | - * Alias of self::set_city(). |
|
2621 | - * |
|
2622 | - * @since 1.0.19 |
|
2623 | - * @param string $value city. |
|
2624 | - */ |
|
2625 | - public function set_customer_city( $value ) { |
|
2626 | - $this->set_city( $value ); |
|
2780 | + * Alias of self::set_address(). |
|
2781 | + * |
|
2782 | + * @since 1.0.19 |
|
2783 | + * @param string $value address. |
|
2784 | + */ |
|
2785 | + public function set_customer_address( $value ) { |
|
2786 | + $this->set_address( $value ); |
|
2627 | 2787 | } |
2628 | 2788 | |
2629 | 2789 | /** |
2630 | - * Set the customer's zip code. |
|
2631 | - * |
|
2632 | - * @since 1.0.19 |
|
2633 | - * @param string $value zip. |
|
2634 | - */ |
|
2635 | - public function set_zip( $value ) { |
|
2636 | - $this->set_prop( 'zip', $value ); |
|
2790 | + * Set whether the customer has viewed the invoice or not. |
|
2791 | + * |
|
2792 | + * @since 1.0.19 |
|
2793 | + * @param int|bool $value confirmed. |
|
2794 | + */ |
|
2795 | + public function set_is_viewed( $value ) { |
|
2796 | + $this->set_prop( 'is_viewed', $value ); |
|
2637 | 2797 | } |
2638 | 2798 | |
2639 | 2799 | /** |
2640 | - * Alias of self::set_zip(). |
|
2641 | - * |
|
2642 | - * @since 1.0.19 |
|
2643 | - * @param string $value zip. |
|
2644 | - */ |
|
2645 | - public function set_user_zip( $value ) { |
|
2646 | - $this->set_zip( $value ); |
|
2800 | + * Set extra email recipients. |
|
2801 | + * |
|
2802 | + * @since 1.0.19 |
|
2803 | + * @param string $value email recipients. |
|
2804 | + */ |
|
2805 | + public function set_email_cc( $value ) { |
|
2806 | + $this->set_prop( 'email_cc', $value ); |
|
2647 | 2807 | } |
2648 | 2808 | |
2649 | 2809 | /** |
2650 | - * Alias of self::set_zip(). |
|
2651 | - * |
|
2652 | - * @since 1.0.19 |
|
2653 | - * @param string $value zip. |
|
2654 | - */ |
|
2655 | - public function set_customer_zip( $value ) { |
|
2656 | - $this->set_zip( $value ); |
|
2810 | + * Set the invoice template. |
|
2811 | + * |
|
2812 | + * @since 1.0.19 |
|
2813 | + * @param string $value template. |
|
2814 | + */ |
|
2815 | + public function set_template( $value ) { |
|
2816 | + if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
2817 | + $this->set_prop( 'template', $value ); |
|
2818 | + } |
|
2657 | 2819 | } |
2658 | 2820 | |
2659 | 2821 | /** |
2660 | - * Set the customer's company. |
|
2661 | - * |
|
2662 | - * @since 1.0.19 |
|
2663 | - * @param string $value company. |
|
2664 | - */ |
|
2665 | - public function set_company( $value ) { |
|
2666 | - $this->set_prop( 'company', $value ); |
|
2822 | + * Set the invoice source. |
|
2823 | + * |
|
2824 | + * @since 1.0.19 |
|
2825 | + * @param string $value source. |
|
2826 | + * @deprecated |
|
2827 | + */ |
|
2828 | + public function created_via( $value ) { |
|
2829 | + $this->set_created_via( sanitize_text_field( $value ) ); |
|
2667 | 2830 | } |
2668 | 2831 | |
2669 | 2832 | /** |
2670 | - * Alias of self::set_company(). |
|
2671 | - * |
|
2672 | - * @since 1.0.19 |
|
2673 | - * @param string $value company. |
|
2674 | - */ |
|
2675 | - public function set_user_company( $value ) { |
|
2676 | - $this->set_company( $value ); |
|
2833 | + * Set the invoice source. |
|
2834 | + * |
|
2835 | + * @since 1.0.19 |
|
2836 | + * @param string $value source. |
|
2837 | + */ |
|
2838 | + public function set_created_via( $value ) { |
|
2839 | + $this->set_prop( 'created_via', sanitize_text_field( $value ) ); |
|
2677 | 2840 | } |
2678 | 2841 | |
2679 | 2842 | /** |
2680 | - * Alias of self::set_company(). |
|
2681 | - * |
|
2682 | - * @since 1.0.19 |
|
2683 | - * @param string $value company. |
|
2684 | - */ |
|
2685 | - public function set_customer_company( $value ) { |
|
2686 | - $this->set_company( $value ); |
|
2687 | - } |
|
2688 | - |
|
2689 | - /** |
|
2690 | - * Set the customer's company id. |
|
2691 | - * |
|
2692 | - * @since 1.0.19 |
|
2693 | - * @param string $value company id. |
|
2694 | - */ |
|
2695 | - public function set_company_id( $value ) { |
|
2696 | - $this->set_prop( 'company_id', $value ); |
|
2843 | + * Set the customer's address confirmed status. |
|
2844 | + * |
|
2845 | + * @since 1.0.19 |
|
2846 | + * @param int|bool $value confirmed. |
|
2847 | + */ |
|
2848 | + public function set_address_confirmed( $value ) { |
|
2849 | + $this->set_prop( 'address_confirmed', $value ); |
|
2697 | 2850 | } |
2698 | 2851 | |
2699 | 2852 | /** |
2700 | - * Set the customer's var number. |
|
2701 | - * |
|
2702 | - * @since 1.0.19 |
|
2703 | - * @param string $value var number. |
|
2704 | - */ |
|
2705 | - public function set_vat_number( $value ) { |
|
2706 | - $this->set_prop( 'vat_number', $value ); |
|
2853 | + * Alias of self::set_address_confirmed(). |
|
2854 | + * |
|
2855 | + * @since 1.0.19 |
|
2856 | + * @param int|bool $value confirmed. |
|
2857 | + */ |
|
2858 | + public function set_user_address_confirmed( $value ) { |
|
2859 | + $this->set_address_confirmed( $value ); |
|
2707 | 2860 | } |
2708 | 2861 | |
2709 | 2862 | /** |
2710 | - * Alias of self::set_vat_number(). |
|
2711 | - * |
|
2712 | - * @since 1.0.19 |
|
2713 | - * @param string $value var number. |
|
2714 | - */ |
|
2715 | - public function set_user_vat_number( $value ) { |
|
2716 | - $this->set_vat_number( $value ); |
|
2863 | + * Alias of self::set_address_confirmed(). |
|
2864 | + * |
|
2865 | + * @since 1.0.19 |
|
2866 | + * @param int|bool $value confirmed. |
|
2867 | + */ |
|
2868 | + public function set_customer_address_confirmed( $value ) { |
|
2869 | + $this->set_address_confirmed( $value ); |
|
2717 | 2870 | } |
2718 | 2871 | |
2719 | 2872 | /** |
2720 | - * Alias of self::set_vat_number(). |
|
2721 | - * |
|
2722 | - * @since 1.0.19 |
|
2723 | - * @param string $value var number. |
|
2724 | - */ |
|
2725 | - public function set_customer_vat_number( $value ) { |
|
2726 | - $this->set_vat_number( $value ); |
|
2873 | + * Set the shipping fee |
|
2874 | + * |
|
2875 | + * @since 1.0.19 |
|
2876 | + * @param float $value shipping amount. |
|
2877 | + */ |
|
2878 | + public function set_shipping( $value ) { |
|
2879 | + |
|
2880 | + if ( ! is_numeric( $value ) ) { |
|
2881 | + return $this->set_prop( 'shipping', null ); |
|
2882 | + } |
|
2883 | + |
|
2884 | + $this->set_prop( 'shipping', max( 0, floatval( $value ) ) ); |
|
2727 | 2885 | } |
2728 | 2886 | |
2729 | 2887 | /** |
2730 | - * Set the customer's vat rate. |
|
2731 | - * |
|
2732 | - * @since 1.0.19 |
|
2733 | - * @param string $value var rate. |
|
2734 | - */ |
|
2735 | - public function set_vat_rate( $value ) { |
|
2736 | - $this->set_prop( 'vat_rate', $value ); |
|
2888 | + * Set the invoice sub total. |
|
2889 | + * |
|
2890 | + * @since 1.0.19 |
|
2891 | + * @param float $value sub total. |
|
2892 | + */ |
|
2893 | + public function set_subtotal( $value ) { |
|
2894 | + $this->set_prop( 'subtotal', max( 0, $value ) ); |
|
2737 | 2895 | } |
2738 | 2896 | |
2739 | - /** |
|
2740 | - * Alias of self::set_vat_rate(). |
|
2741 | - * |
|
2742 | - * @since 1.0.19 |
|
2743 | - * @param string $value var number. |
|
2744 | - */ |
|
2745 | - public function set_user_vat_rate( $value ) { |
|
2746 | - $this->set_vat_rate( $value ); |
|
2747 | - } |
|
2748 | - |
|
2749 | - /** |
|
2750 | - * Alias of self::set_vat_rate(). |
|
2751 | - * |
|
2752 | - * @since 1.0.19 |
|
2753 | - * @param string $value var number. |
|
2754 | - */ |
|
2755 | - public function set_customer_vat_rate( $value ) { |
|
2756 | - $this->set_vat_rate( $value ); |
|
2757 | - } |
|
2758 | - |
|
2759 | - /** |
|
2760 | - * Set the customer's address. |
|
2761 | - * |
|
2762 | - * @since 1.0.19 |
|
2763 | - * @param string $value address. |
|
2764 | - */ |
|
2765 | - public function set_address( $value ) { |
|
2766 | - $this->set_prop( 'address', $value ); |
|
2767 | - } |
|
2768 | - |
|
2769 | - /** |
|
2770 | - * Alias of self::set_address(). |
|
2771 | - * |
|
2772 | - * @since 1.0.19 |
|
2773 | - * @param string $value address. |
|
2774 | - */ |
|
2775 | - public function set_user_address( $value ) { |
|
2776 | - $this->set_address( $value ); |
|
2777 | - } |
|
2778 | - |
|
2779 | - /** |
|
2780 | - * Alias of self::set_address(). |
|
2781 | - * |
|
2782 | - * @since 1.0.19 |
|
2783 | - * @param string $value address. |
|
2784 | - */ |
|
2785 | - public function set_customer_address( $value ) { |
|
2786 | - $this->set_address( $value ); |
|
2787 | - } |
|
2788 | - |
|
2789 | - /** |
|
2790 | - * Set whether the customer has viewed the invoice or not. |
|
2791 | - * |
|
2792 | - * @since 1.0.19 |
|
2793 | - * @param int|bool $value confirmed. |
|
2794 | - */ |
|
2795 | - public function set_is_viewed( $value ) { |
|
2796 | - $this->set_prop( 'is_viewed', $value ); |
|
2797 | - } |
|
2798 | - |
|
2799 | - /** |
|
2800 | - * Set extra email recipients. |
|
2801 | - * |
|
2802 | - * @since 1.0.19 |
|
2803 | - * @param string $value email recipients. |
|
2804 | - */ |
|
2805 | - public function set_email_cc( $value ) { |
|
2806 | - $this->set_prop( 'email_cc', $value ); |
|
2807 | - } |
|
2808 | - |
|
2809 | - /** |
|
2810 | - * Set the invoice template. |
|
2811 | - * |
|
2812 | - * @since 1.0.19 |
|
2813 | - * @param string $value template. |
|
2814 | - */ |
|
2815 | - public function set_template( $value ) { |
|
2816 | - if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
2817 | - $this->set_prop( 'template', $value ); |
|
2818 | - } |
|
2819 | - } |
|
2820 | - |
|
2821 | - /** |
|
2822 | - * Set the invoice source. |
|
2823 | - * |
|
2824 | - * @since 1.0.19 |
|
2825 | - * @param string $value source. |
|
2826 | - * @deprecated |
|
2827 | - */ |
|
2828 | - public function created_via( $value ) { |
|
2829 | - $this->set_created_via( sanitize_text_field( $value ) ); |
|
2830 | - } |
|
2831 | - |
|
2832 | - /** |
|
2833 | - * Set the invoice source. |
|
2834 | - * |
|
2835 | - * @since 1.0.19 |
|
2836 | - * @param string $value source. |
|
2837 | - */ |
|
2838 | - public function set_created_via( $value ) { |
|
2839 | - $this->set_prop( 'created_via', sanitize_text_field( $value ) ); |
|
2840 | - } |
|
2841 | - |
|
2842 | - /** |
|
2843 | - * Set the customer's address confirmed status. |
|
2844 | - * |
|
2845 | - * @since 1.0.19 |
|
2846 | - * @param int|bool $value confirmed. |
|
2847 | - */ |
|
2848 | - public function set_address_confirmed( $value ) { |
|
2849 | - $this->set_prop( 'address_confirmed', $value ); |
|
2850 | - } |
|
2851 | - |
|
2852 | - /** |
|
2853 | - * Alias of self::set_address_confirmed(). |
|
2854 | - * |
|
2855 | - * @since 1.0.19 |
|
2856 | - * @param int|bool $value confirmed. |
|
2857 | - */ |
|
2858 | - public function set_user_address_confirmed( $value ) { |
|
2859 | - $this->set_address_confirmed( $value ); |
|
2860 | - } |
|
2861 | - |
|
2862 | - /** |
|
2863 | - * Alias of self::set_address_confirmed(). |
|
2864 | - * |
|
2865 | - * @since 1.0.19 |
|
2866 | - * @param int|bool $value confirmed. |
|
2867 | - */ |
|
2868 | - public function set_customer_address_confirmed( $value ) { |
|
2869 | - $this->set_address_confirmed( $value ); |
|
2870 | - } |
|
2871 | - |
|
2872 | - /** |
|
2873 | - * Set the shipping fee |
|
2874 | - * |
|
2875 | - * @since 1.0.19 |
|
2876 | - * @param float $value shipping amount. |
|
2877 | - */ |
|
2878 | - public function set_shipping( $value ) { |
|
2879 | - |
|
2880 | - if ( ! is_numeric( $value ) ) { |
|
2881 | - return $this->set_prop( 'shipping', null ); |
|
2882 | - } |
|
2883 | - |
|
2884 | - $this->set_prop( 'shipping', max( 0, floatval( $value ) ) ); |
|
2885 | - } |
|
2886 | - |
|
2887 | - /** |
|
2888 | - * Set the invoice sub total. |
|
2889 | - * |
|
2890 | - * @since 1.0.19 |
|
2891 | - * @param float $value sub total. |
|
2892 | - */ |
|
2893 | - public function set_subtotal( $value ) { |
|
2894 | - $this->set_prop( 'subtotal', max( 0, $value ) ); |
|
2895 | - } |
|
2896 | - |
|
2897 | - /** |
|
2898 | - * Set the invoice total. |
|
2899 | - * |
|
2900 | - * @since 1.0.19 |
|
2901 | - * @param float $value sub total. |
|
2902 | - */ |
|
2903 | - public function set_total( $value ) { |
|
2904 | - $this->set_prop( 'total', max( 0, $value ) ); |
|
2897 | + /** |
|
2898 | + * Set the invoice total. |
|
2899 | + * |
|
2900 | + * @since 1.0.19 |
|
2901 | + * @param float $value sub total. |
|
2902 | + */ |
|
2903 | + public function set_total( $value ) { |
|
2904 | + $this->set_prop( 'total', max( 0, $value ) ); |
|
2905 | 2905 | } |
2906 | 2906 | |
2907 | 2907 | /** |
2908 | - * Set the invoice discount amount. |
|
2909 | - * |
|
2910 | - * @since 1.0.19 |
|
2911 | - * @param float $value discount total. |
|
2912 | - */ |
|
2913 | - public function set_total_discount( $value ) { |
|
2914 | - $this->set_prop( 'total_discount', max( 0, $value ) ); |
|
2908 | + * Set the invoice discount amount. |
|
2909 | + * |
|
2910 | + * @since 1.0.19 |
|
2911 | + * @param float $value discount total. |
|
2912 | + */ |
|
2913 | + public function set_total_discount( $value ) { |
|
2914 | + $this->set_prop( 'total_discount', max( 0, $value ) ); |
|
2915 | 2915 | } |
2916 | 2916 | |
2917 | 2917 | /** |
2918 | - * Alias of self::set_total_discount(). |
|
2919 | - * |
|
2920 | - * @since 1.0.19 |
|
2921 | - * @param float $value discount total. |
|
2922 | - */ |
|
2923 | - public function set_discount( $value ) { |
|
2924 | - $this->set_total_discount( $value ); |
|
2918 | + * Alias of self::set_total_discount(). |
|
2919 | + * |
|
2920 | + * @since 1.0.19 |
|
2921 | + * @param float $value discount total. |
|
2922 | + */ |
|
2923 | + public function set_discount( $value ) { |
|
2924 | + $this->set_total_discount( $value ); |
|
2925 | 2925 | } |
2926 | 2926 | |
2927 | 2927 | /** |
2928 | - * Set the invoice tax amount. |
|
2929 | - * |
|
2930 | - * @since 1.0.19 |
|
2931 | - * @param float $value tax total. |
|
2932 | - */ |
|
2933 | - public function set_total_tax( $value ) { |
|
2934 | - $this->set_prop( 'total_tax', max( 0, $value ) ); |
|
2928 | + * Set the invoice tax amount. |
|
2929 | + * |
|
2930 | + * @since 1.0.19 |
|
2931 | + * @param float $value tax total. |
|
2932 | + */ |
|
2933 | + public function set_total_tax( $value ) { |
|
2934 | + $this->set_prop( 'total_tax', max( 0, $value ) ); |
|
2935 | 2935 | } |
2936 | 2936 | |
2937 | 2937 | /** |
2938 | - * Alias of self::set_total_tax(). |
|
2939 | - * |
|
2940 | - * @since 1.0.19 |
|
2941 | - * @param float $value tax total. |
|
2942 | - */ |
|
2943 | - public function set_tax_total( $value ) { |
|
2944 | - $this->set_total_tax( $value ); |
|
2938 | + * Alias of self::set_total_tax(). |
|
2939 | + * |
|
2940 | + * @since 1.0.19 |
|
2941 | + * @param float $value tax total. |
|
2942 | + */ |
|
2943 | + public function set_tax_total( $value ) { |
|
2944 | + $this->set_total_tax( $value ); |
|
2945 | 2945 | } |
2946 | 2946 | |
2947 | 2947 | /** |
2948 | - * Set the invoice fees amount. |
|
2949 | - * |
|
2950 | - * @since 1.0.19 |
|
2951 | - * @param float $value fees total. |
|
2952 | - */ |
|
2953 | - public function set_total_fees( $value ) { |
|
2954 | - $this->set_prop( 'total_fees', max( 0, $value ) ); |
|
2948 | + * Set the invoice fees amount. |
|
2949 | + * |
|
2950 | + * @since 1.0.19 |
|
2951 | + * @param float $value fees total. |
|
2952 | + */ |
|
2953 | + public function set_total_fees( $value ) { |
|
2954 | + $this->set_prop( 'total_fees', max( 0, $value ) ); |
|
2955 | 2955 | } |
2956 | 2956 | |
2957 | 2957 | /** |
2958 | - * Alias of self::set_total_fees(). |
|
2959 | - * |
|
2960 | - * @since 1.0.19 |
|
2961 | - * @param float $value fees total. |
|
2962 | - */ |
|
2963 | - public function set_fees_total( $value ) { |
|
2964 | - $this->set_total_fees( $value ); |
|
2958 | + * Alias of self::set_total_fees(). |
|
2959 | + * |
|
2960 | + * @since 1.0.19 |
|
2961 | + * @param float $value fees total. |
|
2962 | + */ |
|
2963 | + public function set_fees_total( $value ) { |
|
2964 | + $this->set_total_fees( $value ); |
|
2965 | 2965 | } |
2966 | 2966 | |
2967 | 2967 | /** |
2968 | - * Set the invoice fees. |
|
2969 | - * |
|
2970 | - * @since 1.0.19 |
|
2971 | - * @param array $value fees. |
|
2972 | - */ |
|
2973 | - public function set_fees( $value ) { |
|
2968 | + * Set the invoice fees. |
|
2969 | + * |
|
2970 | + * @since 1.0.19 |
|
2971 | + * @param array $value fees. |
|
2972 | + */ |
|
2973 | + public function set_fees( $value ) { |
|
2974 | 2974 | |
2975 | - if ( ! is_array( $value ) ) { |
|
2976 | - $value = array(); |
|
2977 | - } |
|
2975 | + if ( ! is_array( $value ) ) { |
|
2976 | + $value = array(); |
|
2977 | + } |
|
2978 | 2978 | |
2979 | - $this->set_prop( 'fees', $value ); |
|
2979 | + $this->set_prop( 'fees', $value ); |
|
2980 | 2980 | |
2981 | 2981 | } |
2982 | 2982 | |
2983 | 2983 | /** |
2984 | - * Set the invoice taxes. |
|
2985 | - * |
|
2986 | - * @since 1.0.19 |
|
2987 | - * @param array $value taxes. |
|
2988 | - */ |
|
2989 | - public function set_taxes( $value ) { |
|
2984 | + * Set the invoice taxes. |
|
2985 | + * |
|
2986 | + * @since 1.0.19 |
|
2987 | + * @param array $value taxes. |
|
2988 | + */ |
|
2989 | + public function set_taxes( $value ) { |
|
2990 | 2990 | |
2991 | - if ( ! is_array( $value ) ) { |
|
2992 | - $value = array(); |
|
2993 | - } |
|
2991 | + if ( ! is_array( $value ) ) { |
|
2992 | + $value = array(); |
|
2993 | + } |
|
2994 | 2994 | |
2995 | - $this->set_prop( 'taxes', $value ); |
|
2995 | + $this->set_prop( 'taxes', $value ); |
|
2996 | 2996 | |
2997 | 2997 | } |
2998 | 2998 | |
2999 | 2999 | /** |
3000 | - * Set the invoice discounts. |
|
3001 | - * |
|
3002 | - * @since 1.0.19 |
|
3003 | - * @param array $value discounts. |
|
3004 | - */ |
|
3005 | - public function set_discounts( $value ) { |
|
3000 | + * Set the invoice discounts. |
|
3001 | + * |
|
3002 | + * @since 1.0.19 |
|
3003 | + * @param array $value discounts. |
|
3004 | + */ |
|
3005 | + public function set_discounts( $value ) { |
|
3006 | 3006 | |
3007 | - if ( ! is_array( $value ) ) { |
|
3008 | - $value = array(); |
|
3009 | - } |
|
3007 | + if ( ! is_array( $value ) ) { |
|
3008 | + $value = array(); |
|
3009 | + } |
|
3010 | 3010 | |
3011 | - $this->set_prop( 'discounts', $value ); |
|
3011 | + $this->set_prop( 'discounts', $value ); |
|
3012 | 3012 | } |
3013 | 3013 | |
3014 | 3014 | /** |
3015 | - * Set the invoice items. |
|
3016 | - * |
|
3017 | - * @since 1.0.19 |
|
3018 | - * @param GetPaid_Form_Item[] $value items. |
|
3019 | - */ |
|
3020 | - public function set_items( $value ) { |
|
3015 | + * Set the invoice items. |
|
3016 | + * |
|
3017 | + * @since 1.0.19 |
|
3018 | + * @param GetPaid_Form_Item[] $value items. |
|
3019 | + */ |
|
3020 | + public function set_items( $value ) { |
|
3021 | 3021 | |
3022 | 3022 | // Remove existing items. |
3023 | 3023 | $this->set_prop( 'items', array() ); |
3024 | - $this->recurring_item = null; |
|
3024 | + $this->recurring_item = null; |
|
3025 | 3025 | |
3026 | 3026 | // Ensure that we have an array. |
3027 | 3027 | if ( ! is_array( $value ) ) { |
@@ -3035,95 +3035,95 @@ discard block |
||
3035 | 3035 | } |
3036 | 3036 | |
3037 | 3037 | /** |
3038 | - * Set the payment form. |
|
3039 | - * |
|
3040 | - * @since 1.0.19 |
|
3041 | - * @param int $value payment form. |
|
3042 | - */ |
|
3043 | - public function set_payment_form( $value ) { |
|
3044 | - $this->set_prop( 'payment_form', $value ); |
|
3038 | + * Set the payment form. |
|
3039 | + * |
|
3040 | + * @since 1.0.19 |
|
3041 | + * @param int $value payment form. |
|
3042 | + */ |
|
3043 | + public function set_payment_form( $value ) { |
|
3044 | + $this->set_prop( 'payment_form', $value ); |
|
3045 | 3045 | } |
3046 | 3046 | |
3047 | 3047 | /** |
3048 | - * Set the submission id. |
|
3049 | - * |
|
3050 | - * @since 1.0.19 |
|
3051 | - * @param string $value submission id. |
|
3052 | - */ |
|
3053 | - public function set_submission_id( $value ) { |
|
3054 | - $this->set_prop( 'submission_id', $value ); |
|
3048 | + * Set the submission id. |
|
3049 | + * |
|
3050 | + * @since 1.0.19 |
|
3051 | + * @param string $value submission id. |
|
3052 | + */ |
|
3053 | + public function set_submission_id( $value ) { |
|
3054 | + $this->set_prop( 'submission_id', $value ); |
|
3055 | 3055 | } |
3056 | 3056 | |
3057 | 3057 | /** |
3058 | - * Set the discount code. |
|
3059 | - * |
|
3060 | - * @since 1.0.19 |
|
3061 | - * @param string $value discount code. |
|
3062 | - */ |
|
3063 | - public function set_discount_code( $value ) { |
|
3064 | - $this->set_prop( 'discount_code', sanitize_text_field( $value ) ); |
|
3058 | + * Set the discount code. |
|
3059 | + * |
|
3060 | + * @since 1.0.19 |
|
3061 | + * @param string $value discount code. |
|
3062 | + */ |
|
3063 | + public function set_discount_code( $value ) { |
|
3064 | + $this->set_prop( 'discount_code', sanitize_text_field( $value ) ); |
|
3065 | 3065 | } |
3066 | 3066 | |
3067 | 3067 | /** |
3068 | - * Set the gateway. |
|
3069 | - * |
|
3070 | - * @since 1.0.19 |
|
3071 | - * @param string $value gateway. |
|
3072 | - */ |
|
3073 | - public function set_gateway( $value ) { |
|
3074 | - $this->set_prop( 'gateway', $value ); |
|
3068 | + * Set the gateway. |
|
3069 | + * |
|
3070 | + * @since 1.0.19 |
|
3071 | + * @param string $value gateway. |
|
3072 | + */ |
|
3073 | + public function set_gateway( $value ) { |
|
3074 | + $this->set_prop( 'gateway', $value ); |
|
3075 | 3075 | } |
3076 | 3076 | |
3077 | 3077 | /** |
3078 | - * Set the transaction id. |
|
3079 | - * |
|
3080 | - * @since 1.0.19 |
|
3081 | - * @param string $value transaction id. |
|
3082 | - */ |
|
3083 | - public function set_transaction_id( $value ) { |
|
3084 | - if ( ! empty( $value ) ) { |
|
3085 | - $this->set_prop( 'transaction_id', $value ); |
|
3086 | - } |
|
3078 | + * Set the transaction id. |
|
3079 | + * |
|
3080 | + * @since 1.0.19 |
|
3081 | + * @param string $value transaction id. |
|
3082 | + */ |
|
3083 | + public function set_transaction_id( $value ) { |
|
3084 | + if ( ! empty( $value ) ) { |
|
3085 | + $this->set_prop( 'transaction_id', $value ); |
|
3086 | + } |
|
3087 | 3087 | } |
3088 | 3088 | |
3089 | 3089 | /** |
3090 | - * Set the currency id. |
|
3091 | - * |
|
3092 | - * @since 1.0.19 |
|
3093 | - * @param string $value currency id. |
|
3094 | - */ |
|
3095 | - public function set_currency( $value ) { |
|
3096 | - $this->set_prop( 'currency', $value ); |
|
3090 | + * Set the currency id. |
|
3091 | + * |
|
3092 | + * @since 1.0.19 |
|
3093 | + * @param string $value currency id. |
|
3094 | + */ |
|
3095 | + public function set_currency( $value ) { |
|
3096 | + $this->set_prop( 'currency', $value ); |
|
3097 | 3097 | } |
3098 | 3098 | |
3099 | - /** |
|
3100 | - * Set whether to disable taxes. |
|
3101 | - * |
|
3102 | - * @since 1.0.19 |
|
3103 | - * @param bool $value value. |
|
3104 | - */ |
|
3105 | - public function set_disable_taxes( $value ) { |
|
3106 | - $this->set_prop( 'disable_taxes', (bool) $value ); |
|
3107 | - } |
|
3099 | + /** |
|
3100 | + * Set whether to disable taxes. |
|
3101 | + * |
|
3102 | + * @since 1.0.19 |
|
3103 | + * @param bool $value value. |
|
3104 | + */ |
|
3105 | + public function set_disable_taxes( $value ) { |
|
3106 | + $this->set_prop( 'disable_taxes', (bool) $value ); |
|
3107 | + } |
|
3108 | 3108 | |
3109 | 3109 | /** |
3110 | - * Set the subscription id. |
|
3111 | - * |
|
3112 | - * @since 1.0.19 |
|
3113 | - * @param string $value subscription id. |
|
3114 | - */ |
|
3115 | - public function set_subscription_id( $value ) { |
|
3116 | - $this->set_prop( 'subscription_id', $value ); |
|
3117 | - } |
|
3110 | + * Set the subscription id. |
|
3111 | + * |
|
3112 | + * @since 1.0.19 |
|
3113 | + * @param string $value subscription id. |
|
3114 | + */ |
|
3115 | + public function set_subscription_id( $value ) { |
|
3116 | + $this->set_prop( 'subscription_id', $value ); |
|
3117 | + } |
|
3118 | 3118 | |
3119 | - /** |
|
3120 | - * Set the remote subscription id. |
|
3121 | - * |
|
3122 | - * @since 1.0.19 |
|
3123 | - * @param string $value subscription id. |
|
3124 | - */ |
|
3125 | - public function set_remote_subscription_id( $value ) { |
|
3126 | - $this->set_prop( 'remote_subscription_id', $value ); |
|
3119 | + /** |
|
3120 | + * Set the remote subscription id. |
|
3121 | + * |
|
3122 | + * @since 1.0.19 |
|
3123 | + * @param string $value subscription id. |
|
3124 | + */ |
|
3125 | + public function set_remote_subscription_id( $value ) { |
|
3126 | + $this->set_prop( 'remote_subscription_id', $value ); |
|
3127 | 3127 | } |
3128 | 3128 | |
3129 | 3129 | /* |
@@ -3162,24 +3162,24 @@ discard block |
||
3162 | 3162 | */ |
3163 | 3163 | public function is_taxable() { |
3164 | 3164 | return ! $this->get_disable_taxes(); |
3165 | - } |
|
3165 | + } |
|
3166 | 3166 | |
3167 | - /** |
|
3168 | - * @deprecated |
|
3169 | - */ |
|
3170 | - public function has_vat() { |
|
3167 | + /** |
|
3168 | + * @deprecated |
|
3169 | + */ |
|
3170 | + public function has_vat() { |
|
3171 | 3171 | return $this->is_taxable(); |
3172 | - } |
|
3172 | + } |
|
3173 | 3173 | |
3174 | - /** |
|
3175 | - * Checks to see if the invoice requires payment. |
|
3176 | - */ |
|
3177 | - public function is_free() { |
|
3174 | + /** |
|
3175 | + * Checks to see if the invoice requires payment. |
|
3176 | + */ |
|
3177 | + public function is_free() { |
|
3178 | 3178 | $is_free = ( (float) wpinv_round_amount( $this->get_initial_total() ) == 0 ); |
3179 | 3179 | |
3180 | - if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
3181 | - $is_free = false; |
|
3182 | - } |
|
3180 | + if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
3181 | + $is_free = false; |
|
3182 | + } |
|
3183 | 3183 | |
3184 | 3184 | return apply_filters( 'wpinv_invoice_is_free', $is_free, $this ); |
3185 | 3185 | } |
@@ -3190,46 +3190,46 @@ discard block |
||
3190 | 3190 | public function is_paid() { |
3191 | 3191 | $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ); |
3192 | 3192 | return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this ); |
3193 | - } |
|
3193 | + } |
|
3194 | 3194 | |
3195 | - /** |
|
3195 | + /** |
|
3196 | 3196 | * Checks if the invoice needs payment. |
3197 | 3197 | */ |
3198 | - public function needs_payment() { |
|
3199 | - $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
3198 | + public function needs_payment() { |
|
3199 | + $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
3200 | 3200 | return apply_filters( 'wpinv_needs_payment', $needs_payment, $this ); |
3201 | 3201 | } |
3202 | 3202 | |
3203 | - /** |
|
3203 | + /** |
|
3204 | 3204 | * Checks if the invoice is refunded. |
3205 | 3205 | */ |
3206 | - public function is_refunded() { |
|
3206 | + public function is_refunded() { |
|
3207 | 3207 | $is_refunded = $this->has_status( 'wpi-refunded' ); |
3208 | 3208 | return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this ); |
3209 | - } |
|
3209 | + } |
|
3210 | 3210 | |
3211 | - /** |
|
3211 | + /** |
|
3212 | 3212 | * Checks if the invoice is held. |
3213 | 3213 | */ |
3214 | - public function is_held() { |
|
3214 | + public function is_held() { |
|
3215 | 3215 | $is_held = $this->has_status( 'wpi-onhold' ); |
3216 | 3216 | return apply_filters( 'wpinv_invoice_is_held', $is_held, $this ); |
3217 | - } |
|
3217 | + } |
|
3218 | 3218 | |
3219 | - /** |
|
3219 | + /** |
|
3220 | 3220 | * Checks if the invoice is due. |
3221 | 3221 | */ |
3222 | - public function is_due() { |
|
3223 | - $due_date = $this->get_due_date(); |
|
3224 | - return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
3225 | - } |
|
3222 | + public function is_due() { |
|
3223 | + $due_date = $this->get_due_date(); |
|
3224 | + return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
3225 | + } |
|
3226 | 3226 | |
3227 | - /** |
|
3227 | + /** |
|
3228 | 3228 | * Checks if the invoice is draft. |
3229 | 3229 | */ |
3230 | - public function is_draft() { |
|
3230 | + public function is_draft() { |
|
3231 | 3231 | return $this->has_status( 'draft, auto-draft' ); |
3232 | - } |
|
3232 | + } |
|
3233 | 3233 | |
3234 | 3234 | /** |
3235 | 3235 | * Checks if the invoice has a given status. |
@@ -3237,9 +3237,9 @@ discard block |
||
3237 | 3237 | public function has_status( $status ) { |
3238 | 3238 | $status = wpinv_parse_list( $status ); |
3239 | 3239 | return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status ); |
3240 | - } |
|
3240 | + } |
|
3241 | 3241 | |
3242 | - /** |
|
3242 | + /** |
|
3243 | 3243 | * Checks if the invoice is of a given type. |
3244 | 3244 | */ |
3245 | 3245 | public function is_type( $type ) { |
@@ -3262,25 +3262,25 @@ discard block |
||
3262 | 3262 | */ |
3263 | 3263 | public function has_free_trial() { |
3264 | 3264 | return $this->is_recurring() && 0 == $this->get_initial_total(); |
3265 | - } |
|
3265 | + } |
|
3266 | 3266 | |
3267 | - /** |
|
3267 | + /** |
|
3268 | 3268 | * @deprecated |
3269 | 3269 | */ |
3270 | 3270 | public function is_free_trial() { |
3271 | 3271 | return $this->has_free_trial(); |
3272 | 3272 | } |
3273 | 3273 | |
3274 | - /** |
|
3274 | + /** |
|
3275 | 3275 | * Check if the initial payment if 0. |
3276 | 3276 | * |
3277 | 3277 | */ |
3278 | - public function is_initial_free() { |
|
3278 | + public function is_initial_free() { |
|
3279 | 3279 | $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 ); |
3280 | 3280 | return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this ); |
3281 | 3281 | } |
3282 | 3282 | |
3283 | - /** |
|
3283 | + /** |
|
3284 | 3284 | * Check if the recurring item has a free trial. |
3285 | 3285 | * |
3286 | 3286 | */ |
@@ -3293,21 +3293,21 @@ discard block |
||
3293 | 3293 | |
3294 | 3294 | $item = $this->get_recurring( true ); |
3295 | 3295 | return $item->has_free_trial(); |
3296 | - } |
|
3296 | + } |
|
3297 | 3297 | |
3298 | - /** |
|
3298 | + /** |
|
3299 | 3299 | * Check if the free trial is a result of a discount. |
3300 | 3300 | */ |
3301 | 3301 | public function is_free_trial_from_discount() { |
3302 | - return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
3303 | - } |
|
3302 | + return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
3303 | + } |
|
3304 | 3304 | |
3305 | - /** |
|
3305 | + /** |
|
3306 | 3306 | * @deprecated |
3307 | 3307 | */ |
3308 | 3308 | public function discount_first_payment_only() { |
3309 | 3309 | |
3310 | - $discount = wpinv_get_discount_obj( $this->get_discount_code() ); |
|
3310 | + $discount = wpinv_get_discount_obj( $this->get_discount_code() ); |
|
3311 | 3311 | if ( ! $discount->exists() || ! $this->is_recurring() ) { |
3312 | 3312 | return true; |
3313 | 3313 | } |
@@ -3332,146 +3332,146 @@ discard block |
||
3332 | 3332 | */ |
3333 | 3333 | public function add_item( $item ) { |
3334 | 3334 | |
3335 | - if ( is_array( $item ) ) { |
|
3336 | - $item = $this->process_array_item( $item ); |
|
3337 | - } |
|
3335 | + if ( is_array( $item ) ) { |
|
3336 | + $item = $this->process_array_item( $item ); |
|
3337 | + } |
|
3338 | 3338 | |
3339 | - if ( is_numeric( $item ) ) { |
|
3340 | - $item = new GetPaid_Form_Item( $item ); |
|
3341 | - } |
|
3339 | + if ( is_numeric( $item ) ) { |
|
3340 | + $item = new GetPaid_Form_Item( $item ); |
|
3341 | + } |
|
3342 | 3342 | |
3343 | 3343 | // Make sure that it is available for purchase. |
3344 | - if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
3345 | - return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
3344 | + if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
3345 | + return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
3346 | 3346 | } |
3347 | 3347 | |
3348 | 3348 | // Do we have a recurring item? |
3349 | - if ( $item->is_recurring() ) { |
|
3350 | - $this->recurring_item = $item->get_id(); |
|
3349 | + if ( $item->is_recurring() ) { |
|
3350 | + $this->recurring_item = $item->get_id(); |
|
3351 | 3351 | } |
3352 | 3352 | |
3353 | 3353 | // Invoice id. |
3354 | 3354 | $item->invoice_id = (int) $this->get_id(); |
3355 | 3355 | |
3356 | - // Remove duplicates. |
|
3357 | - $this->remove_item( $item->get_id() ); |
|
3356 | + // Remove duplicates. |
|
3357 | + $this->remove_item( $item->get_id() ); |
|
3358 | 3358 | |
3359 | - if ( 0 == $item->get_quantity() ) { |
|
3360 | - return; |
|
3361 | - } |
|
3359 | + if ( 0 == $item->get_quantity() ) { |
|
3360 | + return; |
|
3361 | + } |
|
3362 | 3362 | |
3363 | - // Retrieve all items. |
|
3363 | + // Retrieve all items. |
|
3364 | 3364 | $items = $this->get_items(); |
3365 | 3365 | |
3366 | - // Add new item. |
|
3366 | + // Add new item. |
|
3367 | 3367 | $items[] = $item; |
3368 | 3368 | |
3369 | 3369 | $this->set_prop( 'items', $items ); |
3370 | 3370 | |
3371 | - return true; |
|
3372 | - } |
|
3371 | + return true; |
|
3372 | + } |
|
3373 | 3373 | |
3374 | - /** |
|
3375 | - * Converts an array to an item. |
|
3376 | - * |
|
3377 | - * @since 1.0.19 |
|
3378 | - * @return GetPaid_Form_Item |
|
3379 | - */ |
|
3380 | - protected function process_array_item( $array ) { |
|
3374 | + /** |
|
3375 | + * Converts an array to an item. |
|
3376 | + * |
|
3377 | + * @since 1.0.19 |
|
3378 | + * @return GetPaid_Form_Item |
|
3379 | + */ |
|
3380 | + protected function process_array_item( $array ) { |
|
3381 | 3381 | |
3382 | - $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
3383 | - $item = new GetPaid_Form_Item( $item_id ); |
|
3382 | + $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
3383 | + $item = new GetPaid_Form_Item( $item_id ); |
|
3384 | 3384 | |
3385 | - // Set item data. |
|
3386 | - foreach ( array( 'name', 'price', 'description' ) as $key ) { |
|
3387 | - if ( isset( $array[ "item_$key" ] ) ) { |
|
3388 | - $method = "set_$key"; |
|
3389 | - $item->$method( $array[ "item_$key" ] ); |
|
3390 | - } |
|
3391 | - } |
|
3385 | + // Set item data. |
|
3386 | + foreach ( array( 'name', 'price', 'description' ) as $key ) { |
|
3387 | + if ( isset( $array[ "item_$key" ] ) ) { |
|
3388 | + $method = "set_$key"; |
|
3389 | + $item->$method( $array[ "item_$key" ] ); |
|
3390 | + } |
|
3391 | + } |
|
3392 | 3392 | |
3393 | - if ( isset( $array['quantity'] ) ) { |
|
3394 | - $item->set_quantity( $array['quantity'] ); |
|
3395 | - } |
|
3393 | + if ( isset( $array['quantity'] ) ) { |
|
3394 | + $item->set_quantity( $array['quantity'] ); |
|
3395 | + } |
|
3396 | 3396 | |
3397 | - // Set item meta. |
|
3398 | - if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
3399 | - $item->set_item_meta( $array['meta'] ); |
|
3400 | - } |
|
3397 | + // Set item meta. |
|
3398 | + if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
3399 | + $item->set_item_meta( $array['meta'] ); |
|
3400 | + } |
|
3401 | 3401 | |
3402 | - return $item; |
|
3402 | + return $item; |
|
3403 | 3403 | |
3404 | - } |
|
3404 | + } |
|
3405 | 3405 | |
3406 | 3406 | /** |
3407 | - * Retrieves a specific item. |
|
3408 | - * |
|
3409 | - * @since 1.0.19 |
|
3410 | - * @return GetPaid_Form_Item|null |
|
3411 | - */ |
|
3412 | - public function get_item( $item_id ) { |
|
3407 | + * Retrieves a specific item. |
|
3408 | + * |
|
3409 | + * @since 1.0.19 |
|
3410 | + * @return GetPaid_Form_Item|null |
|
3411 | + */ |
|
3412 | + public function get_item( $item_id ) { |
|
3413 | 3413 | |
3414 | - foreach ( $this->get_items() as $item ) { |
|
3415 | - if ( (int) $item_id == $item->get_id() ) { |
|
3416 | - return $item; |
|
3417 | - } |
|
3418 | - } |
|
3414 | + foreach ( $this->get_items() as $item ) { |
|
3415 | + if ( (int) $item_id == $item->get_id() ) { |
|
3416 | + return $item; |
|
3417 | + } |
|
3418 | + } |
|
3419 | 3419 | |
3420 | - return null; |
|
3420 | + return null; |
|
3421 | 3421 | } |
3422 | 3422 | |
3423 | 3423 | /** |
3424 | - * Removes a specific item. |
|
3425 | - * |
|
3426 | - * @since 1.0.19 |
|
3427 | - */ |
|
3428 | - public function remove_item( $item_id ) { |
|
3429 | - $items = $this->get_items(); |
|
3430 | - $item_id = (int) $item_id; |
|
3424 | + * Removes a specific item. |
|
3425 | + * |
|
3426 | + * @since 1.0.19 |
|
3427 | + */ |
|
3428 | + public function remove_item( $item_id ) { |
|
3429 | + $items = $this->get_items(); |
|
3430 | + $item_id = (int) $item_id; |
|
3431 | 3431 | |
3432 | - foreach ( $items as $index => $item ) { |
|
3433 | - if ( (int) $item_id == $item->get_id() ) { |
|
3434 | - unset( $items[ $index ] ); |
|
3435 | - $this->set_prop( 'items', $items ); |
|
3432 | + foreach ( $items as $index => $item ) { |
|
3433 | + if ( (int) $item_id == $item->get_id() ) { |
|
3434 | + unset( $items[ $index ] ); |
|
3435 | + $this->set_prop( 'items', $items ); |
|
3436 | 3436 | |
3437 | - if ( $item_id == $this->recurring_item ) { |
|
3438 | - $this->recurring_item = null; |
|
3439 | - } |
|
3437 | + if ( $item_id == $this->recurring_item ) { |
|
3438 | + $this->recurring_item = null; |
|
3439 | + } |
|
3440 | 3440 | } |
3441 | - } |
|
3441 | + } |
|
3442 | 3442 | |
3443 | 3443 | } |
3444 | 3444 | |
3445 | 3445 | /** |
3446 | - * Adds a fee to the invoice. |
|
3447 | - * |
|
3448 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
3449 | - * @since 1.0.19 |
|
3450 | - */ |
|
3446 | + * Adds a fee to the invoice. |
|
3447 | + * |
|
3448 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
3449 | + * @since 1.0.19 |
|
3450 | + */ |
|
3451 | 3451 | public function add_fee( $fee ) { |
3452 | 3452 | |
3453 | - $fees = $this->get_fees(); |
|
3454 | - $fees[ $fee['name'] ] = $fee; |
|
3455 | - $this->set_prop( 'fees', $fees ); |
|
3453 | + $fees = $this->get_fees(); |
|
3454 | + $fees[ $fee['name'] ] = $fee; |
|
3455 | + $this->set_prop( 'fees', $fees ); |
|
3456 | 3456 | |
3457 | 3457 | } |
3458 | 3458 | |
3459 | 3459 | /** |
3460 | - * Retrieves a specific fee. |
|
3461 | - * |
|
3462 | - * @since 1.0.19 |
|
3463 | - */ |
|
3464 | - public function get_fee( $fee ) { |
|
3460 | + * Retrieves a specific fee. |
|
3461 | + * |
|
3462 | + * @since 1.0.19 |
|
3463 | + */ |
|
3464 | + public function get_fee( $fee ) { |
|
3465 | 3465 | $fees = $this->get_fees(); |
3466 | - return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
3466 | + return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
3467 | 3467 | } |
3468 | 3468 | |
3469 | 3469 | /** |
3470 | - * Removes a specific fee. |
|
3471 | - * |
|
3472 | - * @since 1.0.19 |
|
3473 | - */ |
|
3474 | - public function remove_fee( $fee ) { |
|
3470 | + * Removes a specific fee. |
|
3471 | + * |
|
3472 | + * @since 1.0.19 |
|
3473 | + */ |
|
3474 | + public function remove_fee( $fee ) { |
|
3475 | 3475 | $fees = $this->get_fees(); |
3476 | 3476 | if ( isset( $fees[ $fee ] ) ) { |
3477 | 3477 | unset( $fees[ $fee ] ); |
@@ -3479,55 +3479,55 @@ discard block |
||
3479 | 3479 | } |
3480 | 3480 | } |
3481 | 3481 | |
3482 | - /** |
|
3483 | - * Adds a discount to the invoice. |
|
3484 | - * |
|
3485 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
3486 | - * @since 1.0.19 |
|
3487 | - */ |
|
3488 | - public function add_discount( $discount ) { |
|
3482 | + /** |
|
3483 | + * Adds a discount to the invoice. |
|
3484 | + * |
|
3485 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
3486 | + * @since 1.0.19 |
|
3487 | + */ |
|
3488 | + public function add_discount( $discount ) { |
|
3489 | 3489 | |
3490 | - $discounts = $this->get_discounts(); |
|
3491 | - $discounts[ $discount['name'] ] = $discount; |
|
3492 | - $this->set_prop( 'discounts', $discounts ); |
|
3490 | + $discounts = $this->get_discounts(); |
|
3491 | + $discounts[ $discount['name'] ] = $discount; |
|
3492 | + $this->set_prop( 'discounts', $discounts ); |
|
3493 | 3493 | |
3494 | - } |
|
3494 | + } |
|
3495 | 3495 | |
3496 | 3496 | /** |
3497 | - * Retrieves a specific discount. |
|
3498 | - * |
|
3499 | - * @since 1.0.19 |
|
3500 | - * @return float |
|
3501 | - */ |
|
3502 | - public function get_discount( $discount = false ) { |
|
3497 | + * Retrieves a specific discount. |
|
3498 | + * |
|
3499 | + * @since 1.0.19 |
|
3500 | + * @return float |
|
3501 | + */ |
|
3502 | + public function get_discount( $discount = false ) { |
|
3503 | 3503 | |
3504 | - // Backwards compatibilty. |
|
3505 | - if ( empty( $discount ) ) { |
|
3506 | - return $this->get_total_discount(); |
|
3507 | - } |
|
3504 | + // Backwards compatibilty. |
|
3505 | + if ( empty( $discount ) ) { |
|
3506 | + return $this->get_total_discount(); |
|
3507 | + } |
|
3508 | 3508 | |
3509 | 3509 | $discounts = $this->get_discounts(); |
3510 | - return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
3510 | + return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
3511 | 3511 | } |
3512 | 3512 | |
3513 | 3513 | /** |
3514 | - * Removes a specific discount. |
|
3515 | - * |
|
3516 | - * @since 1.0.19 |
|
3517 | - */ |
|
3518 | - public function remove_discount( $discount ) { |
|
3514 | + * Removes a specific discount. |
|
3515 | + * |
|
3516 | + * @since 1.0.19 |
|
3517 | + */ |
|
3518 | + public function remove_discount( $discount ) { |
|
3519 | 3519 | $discounts = $this->get_discounts(); |
3520 | 3520 | if ( isset( $discounts[ $discount ] ) ) { |
3521 | 3521 | unset( $discounts[ $discount ] ); |
3522 | 3522 | $this->set_prop( 'discounts', $discounts ); |
3523 | 3523 | } |
3524 | 3524 | |
3525 | - if ( 'discount_code' == $discount ) { |
|
3526 | - foreach ( $this->get_items() as $item ) { |
|
3527 | - $item->item_discount = 0; |
|
3528 | - $item->recurring_item_discount = 0; |
|
3529 | - } |
|
3530 | - } |
|
3525 | + if ( 'discount_code' == $discount ) { |
|
3526 | + foreach ( $this->get_items() as $item ) { |
|
3527 | + $item->item_discount = 0; |
|
3528 | + $item->recurring_item_discount = 0; |
|
3529 | + } |
|
3530 | + } |
|
3531 | 3531 | |
3532 | 3532 | } |
3533 | 3533 | |
@@ -3540,34 +3540,34 @@ discard block |
||
3540 | 3540 | if ( $this->is_taxable() ) { |
3541 | 3541 | |
3542 | 3542 | $taxes = $this->get_taxes(); |
3543 | - $taxes[ $tax['name'] ] = $tax; |
|
3544 | - $this->set_prop( 'taxes', $tax ); |
|
3543 | + $taxes[ $tax['name'] ] = $tax; |
|
3544 | + $this->set_prop( 'taxes', $tax ); |
|
3545 | 3545 | |
3546 | 3546 | } |
3547 | 3547 | } |
3548 | 3548 | |
3549 | 3549 | /** |
3550 | - * Retrieves a specific tax. |
|
3551 | - * |
|
3552 | - * @since 1.0.19 |
|
3553 | - */ |
|
3554 | - public function get_tax( $tax = null ) { |
|
3550 | + * Retrieves a specific tax. |
|
3551 | + * |
|
3552 | + * @since 1.0.19 |
|
3553 | + */ |
|
3554 | + public function get_tax( $tax = null ) { |
|
3555 | 3555 | |
3556 | - // Backwards compatility. |
|
3557 | - if ( empty( $tax ) ) { |
|
3558 | - return $this->get_total_tax(); |
|
3559 | - } |
|
3556 | + // Backwards compatility. |
|
3557 | + if ( empty( $tax ) ) { |
|
3558 | + return $this->get_total_tax(); |
|
3559 | + } |
|
3560 | 3560 | |
3561 | 3561 | $taxes = $this->get_taxes(); |
3562 | - return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
3562 | + return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
3563 | 3563 | } |
3564 | 3564 | |
3565 | 3565 | /** |
3566 | - * Removes a specific tax. |
|
3567 | - * |
|
3568 | - * @since 1.0.19 |
|
3569 | - */ |
|
3570 | - public function remove_tax( $tax ) { |
|
3566 | + * Removes a specific tax. |
|
3567 | + * |
|
3568 | + * @since 1.0.19 |
|
3569 | + */ |
|
3570 | + public function remove_tax( $tax ) { |
|
3571 | 3571 | $taxes = $this->get_taxes(); |
3572 | 3572 | if ( isset( $taxes[ $tax ] ) ) { |
3573 | 3573 | unset( $taxes[ $tax ] ); |
@@ -3576,184 +3576,184 @@ discard block |
||
3576 | 3576 | } |
3577 | 3577 | |
3578 | 3578 | /** |
3579 | - * Recalculates the invoice subtotal. |
|
3580 | - * |
|
3581 | - * @since 1.0.19 |
|
3582 | - * @return float The recalculated subtotal |
|
3583 | - */ |
|
3584 | - public function recalculate_subtotal() { |
|
3579 | + * Recalculates the invoice subtotal. |
|
3580 | + * |
|
3581 | + * @since 1.0.19 |
|
3582 | + * @return float The recalculated subtotal |
|
3583 | + */ |
|
3584 | + public function recalculate_subtotal() { |
|
3585 | 3585 | $items = $this->get_items(); |
3586 | - $subtotal = 0; |
|
3587 | - $recurring = 0; |
|
3586 | + $subtotal = 0; |
|
3587 | + $recurring = 0; |
|
3588 | 3588 | |
3589 | 3589 | foreach ( $items as $item ) { |
3590 | - $subtotal += $item->get_sub_total( 'edit' ); |
|
3591 | - $recurring += $item->get_recurring_sub_total( 'edit' ); |
|
3590 | + $subtotal += $item->get_sub_total( 'edit' ); |
|
3591 | + $recurring += $item->get_recurring_sub_total( 'edit' ); |
|
3592 | 3592 | } |
3593 | 3593 | |
3594 | - if ( wpinv_prices_include_tax() ) { |
|
3595 | - $subtotal = max( 0, $subtotal - $this->totals['tax']['initial'] ); |
|
3596 | - $recurring = max( 0, $recurring - $this->totals['tax']['recurring'] ); |
|
3597 | - } |
|
3594 | + if ( wpinv_prices_include_tax() ) { |
|
3595 | + $subtotal = max( 0, $subtotal - $this->totals['tax']['initial'] ); |
|
3596 | + $recurring = max( 0, $recurring - $this->totals['tax']['recurring'] ); |
|
3597 | + } |
|
3598 | 3598 | |
3599 | - $current = $this->is_renewal() ? $recurring : $subtotal; |
|
3600 | - $this->set_subtotal( $current ); |
|
3599 | + $current = $this->is_renewal() ? $recurring : $subtotal; |
|
3600 | + $this->set_subtotal( $current ); |
|
3601 | 3601 | |
3602 | - $this->totals['subtotal'] = array( |
|
3603 | - 'initial' => $subtotal, |
|
3604 | - 'recurring' => $recurring, |
|
3605 | - ); |
|
3602 | + $this->totals['subtotal'] = array( |
|
3603 | + 'initial' => $subtotal, |
|
3604 | + 'recurring' => $recurring, |
|
3605 | + ); |
|
3606 | 3606 | |
3607 | 3607 | return $current; |
3608 | 3608 | } |
3609 | 3609 | |
3610 | 3610 | /** |
3611 | - * Recalculates the invoice discount total. |
|
3612 | - * |
|
3613 | - * @since 1.0.19 |
|
3614 | - * @return float The recalculated discount |
|
3615 | - */ |
|
3616 | - public function recalculate_total_discount() { |
|
3611 | + * Recalculates the invoice discount total. |
|
3612 | + * |
|
3613 | + * @since 1.0.19 |
|
3614 | + * @return float The recalculated discount |
|
3615 | + */ |
|
3616 | + public function recalculate_total_discount() { |
|
3617 | 3617 | $discounts = $this->get_discounts(); |
3618 | - $discount = 0; |
|
3619 | - $recurring = 0; |
|
3618 | + $discount = 0; |
|
3619 | + $recurring = 0; |
|
3620 | 3620 | |
3621 | 3621 | foreach ( $discounts as $data ) { |
3622 | - $discount += wpinv_sanitize_amount( $data['initial_discount'] ); |
|
3623 | - $recurring += wpinv_sanitize_amount( $data['recurring_discount'] ); |
|
3624 | - } |
|
3622 | + $discount += wpinv_sanitize_amount( $data['initial_discount'] ); |
|
3623 | + $recurring += wpinv_sanitize_amount( $data['recurring_discount'] ); |
|
3624 | + } |
|
3625 | 3625 | |
3626 | - $current = $this->is_renewal() ? $recurring : $discount; |
|
3626 | + $current = $this->is_renewal() ? $recurring : $discount; |
|
3627 | 3627 | |
3628 | - $this->set_total_discount( $current ); |
|
3628 | + $this->set_total_discount( $current ); |
|
3629 | 3629 | |
3630 | - $this->totals['discount'] = array( |
|
3631 | - 'initial' => $discount, |
|
3632 | - 'recurring' => $recurring, |
|
3633 | - ); |
|
3630 | + $this->totals['discount'] = array( |
|
3631 | + 'initial' => $discount, |
|
3632 | + 'recurring' => $recurring, |
|
3633 | + ); |
|
3634 | 3634 | |
3635 | - return $current; |
|
3635 | + return $current; |
|
3636 | 3636 | |
3637 | 3637 | } |
3638 | 3638 | |
3639 | 3639 | /** |
3640 | - * Recalculates the invoice tax total. |
|
3641 | - * |
|
3642 | - * @since 1.0.19 |
|
3643 | - * @return float The recalculated tax |
|
3644 | - */ |
|
3645 | - public function recalculate_total_tax() { |
|
3640 | + * Recalculates the invoice tax total. |
|
3641 | + * |
|
3642 | + * @since 1.0.19 |
|
3643 | + * @return float The recalculated tax |
|
3644 | + */ |
|
3645 | + public function recalculate_total_tax() { |
|
3646 | 3646 | |
3647 | - // Maybe disable taxes. |
|
3648 | - $vat_number = $this->get_vat_number(); |
|
3649 | - $skip_tax = GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $this->get_country() ) && ! empty( $vat_number ); |
|
3647 | + // Maybe disable taxes. |
|
3648 | + $vat_number = $this->get_vat_number(); |
|
3649 | + $skip_tax = GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $this->get_country() ) && ! empty( $vat_number ); |
|
3650 | 3650 | |
3651 | - if ( wpinv_is_base_country( $this->get_country() ) && 'vat_too' === wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
3652 | - $skip_tax = false; |
|
3653 | - } |
|
3651 | + if ( wpinv_is_base_country( $this->get_country() ) && 'vat_too' === wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
3652 | + $skip_tax = false; |
|
3653 | + } |
|
3654 | 3654 | |
3655 | - if ( ! wpinv_use_taxes() || $this->get_disable_taxes() || ! wpinv_is_country_taxable( $this->get_country() ) || $skip_tax ) { |
|
3655 | + if ( ! wpinv_use_taxes() || $this->get_disable_taxes() || ! wpinv_is_country_taxable( $this->get_country() ) || $skip_tax ) { |
|
3656 | 3656 | |
3657 | - $this->totals['tax'] = array( |
|
3658 | - 'initial' => 0, |
|
3659 | - 'recurring' => 0, |
|
3660 | - ); |
|
3657 | + $this->totals['tax'] = array( |
|
3658 | + 'initial' => 0, |
|
3659 | + 'recurring' => 0, |
|
3660 | + ); |
|
3661 | 3661 | |
3662 | - $this->tax_rate = 0; |
|
3662 | + $this->tax_rate = 0; |
|
3663 | 3663 | |
3664 | - $this->set_taxes( array() ); |
|
3665 | - $current = 0; |
|
3666 | - } else { |
|
3664 | + $this->set_taxes( array() ); |
|
3665 | + $current = 0; |
|
3666 | + } else { |
|
3667 | 3667 | |
3668 | - $item_taxes = array(); |
|
3668 | + $item_taxes = array(); |
|
3669 | 3669 | |
3670 | - foreach ( $this->get_items() as $item ) { |
|
3671 | - $rates = getpaid_get_item_tax_rates( $item, $this->get_country(), $this->get_state() ); |
|
3672 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
3673 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
3674 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
3675 | - foreach ( $taxes as $name => $amount ) { |
|
3676 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
3677 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
3670 | + foreach ( $this->get_items() as $item ) { |
|
3671 | + $rates = getpaid_get_item_tax_rates( $item, $this->get_country(), $this->get_state() ); |
|
3672 | + $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
3673 | + $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
3674 | + $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
3675 | + foreach ( $taxes as $name => $amount ) { |
|
3676 | + $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
3677 | + $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
3678 | 3678 | |
3679 | - if ( ! isset( $item_taxes[ $name ] ) ) { |
|
3680 | - $item_taxes[ $name ] = $tax; |
|
3681 | - continue; |
|
3682 | - } |
|
3679 | + if ( ! isset( $item_taxes[ $name ] ) ) { |
|
3680 | + $item_taxes[ $name ] = $tax; |
|
3681 | + continue; |
|
3682 | + } |
|
3683 | 3683 | |
3684 | - $item_taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
3685 | - $item_taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
3684 | + $item_taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
3685 | + $item_taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
3686 | 3686 | |
3687 | - } |
|
3688 | - } |
|
3687 | + } |
|
3688 | + } |
|
3689 | 3689 | |
3690 | - $item_taxes = array_replace( $this->get_taxes(), $item_taxes ); |
|
3691 | - $this->set_taxes( $item_taxes ); |
|
3690 | + $item_taxes = array_replace( $this->get_taxes(), $item_taxes ); |
|
3691 | + $this->set_taxes( $item_taxes ); |
|
3692 | 3692 | |
3693 | - $initial_tax = array_sum( wp_list_pluck( $item_taxes, 'initial_tax' ) ); |
|
3694 | - $recurring_tax = array_sum( wp_list_pluck( $item_taxes, 'recurring_tax' ) ); |
|
3693 | + $initial_tax = array_sum( wp_list_pluck( $item_taxes, 'initial_tax' ) ); |
|
3694 | + $recurring_tax = array_sum( wp_list_pluck( $item_taxes, 'recurring_tax' ) ); |
|
3695 | 3695 | |
3696 | - $current = $this->is_renewal() ? $recurring_tax : $initial_tax; |
|
3696 | + $current = $this->is_renewal() ? $recurring_tax : $initial_tax; |
|
3697 | 3697 | |
3698 | - $this->totals['tax'] = array( |
|
3699 | - 'initial' => $initial_tax, |
|
3700 | - 'recurring' => $recurring_tax, |
|
3701 | - ); |
|
3698 | + $this->totals['tax'] = array( |
|
3699 | + 'initial' => $initial_tax, |
|
3700 | + 'recurring' => $recurring_tax, |
|
3701 | + ); |
|
3702 | 3702 | |
3703 | - } |
|
3703 | + } |
|
3704 | 3704 | |
3705 | - $this->set_total_tax( $current ); |
|
3705 | + $this->set_total_tax( $current ); |
|
3706 | 3706 | |
3707 | - return $current; |
|
3707 | + return $current; |
|
3708 | 3708 | |
3709 | 3709 | } |
3710 | 3710 | |
3711 | 3711 | /** |
3712 | - * Recalculates the invoice fees total. |
|
3713 | - * |
|
3714 | - * @since 1.0.19 |
|
3715 | - * @return float The recalculated fee |
|
3716 | - */ |
|
3717 | - public function recalculate_total_fees() { |
|
3718 | - $fees = $this->get_fees(); |
|
3719 | - $fee = 0; |
|
3720 | - $recurring = 0; |
|
3712 | + * Recalculates the invoice fees total. |
|
3713 | + * |
|
3714 | + * @since 1.0.19 |
|
3715 | + * @return float The recalculated fee |
|
3716 | + */ |
|
3717 | + public function recalculate_total_fees() { |
|
3718 | + $fees = $this->get_fees(); |
|
3719 | + $fee = 0; |
|
3720 | + $recurring = 0; |
|
3721 | 3721 | |
3722 | 3722 | foreach ( $fees as $data ) { |
3723 | - $fee += wpinv_sanitize_amount( $data['initial_fee'] ); |
|
3724 | - $recurring += wpinv_sanitize_amount( $data['recurring_fee'] ); |
|
3725 | - } |
|
3723 | + $fee += wpinv_sanitize_amount( $data['initial_fee'] ); |
|
3724 | + $recurring += wpinv_sanitize_amount( $data['recurring_fee'] ); |
|
3725 | + } |
|
3726 | 3726 | |
3727 | - $current = $this->is_renewal() ? $recurring : $fee; |
|
3728 | - $this->set_total_fees( $current ); |
|
3727 | + $current = $this->is_renewal() ? $recurring : $fee; |
|
3728 | + $this->set_total_fees( $current ); |
|
3729 | 3729 | |
3730 | - $this->totals['fee'] = array( |
|
3731 | - 'initial' => $fee, |
|
3732 | - 'recurring' => $recurring, |
|
3733 | - ); |
|
3730 | + $this->totals['fee'] = array( |
|
3731 | + 'initial' => $fee, |
|
3732 | + 'recurring' => $recurring, |
|
3733 | + ); |
|
3734 | 3734 | |
3735 | 3735 | $this->set_total_fees( $fee ); |
3736 | 3736 | return $current; |
3737 | 3737 | } |
3738 | 3738 | |
3739 | 3739 | /** |
3740 | - * Recalculates the invoice total. |
|
3741 | - * |
|
3742 | - * @since 1.0.19 |
|
3740 | + * Recalculates the invoice total. |
|
3741 | + * |
|
3742 | + * @since 1.0.19 |
|
3743 | 3743 | * @return float The invoice total |
3744 | - */ |
|
3745 | - public function recalculate_total() { |
|
3744 | + */ |
|
3745 | + public function recalculate_total() { |
|
3746 | 3746 | $this->recalculate_total_fees(); |
3747 | 3747 | $this->recalculate_total_discount(); |
3748 | - $this->recalculate_total_tax(); |
|
3749 | - $this->recalculate_subtotal(); |
|
3750 | - $this->set_total( $this->get_total_tax( 'edit' ) + $this->get_total_fees( 'edit' ) + $this->get_subtotal( 'edit' ) - $this->get_total_discount( 'edit' ) ); |
|
3751 | - return $this->get_total(); |
|
3752 | - } |
|
3753 | - |
|
3754 | - /** |
|
3755 | - * @deprecated |
|
3756 | - */ |
|
3748 | + $this->recalculate_total_tax(); |
|
3749 | + $this->recalculate_subtotal(); |
|
3750 | + $this->set_total( $this->get_total_tax( 'edit' ) + $this->get_total_fees( 'edit' ) + $this->get_subtotal( 'edit' ) - $this->get_total_discount( 'edit' ) ); |
|
3751 | + return $this->get_total(); |
|
3752 | + } |
|
3753 | + |
|
3754 | + /** |
|
3755 | + * @deprecated |
|
3756 | + */ |
|
3757 | 3757 | public function recalculate_totals() { |
3758 | 3758 | $this->recalculate_total(); |
3759 | 3759 | $this->save( true ); |
@@ -3767,22 +3767,22 @@ discard block |
||
3767 | 3767 | return $this->get_data(); |
3768 | 3768 | } |
3769 | 3769 | |
3770 | - /** |
|
3770 | + /** |
|
3771 | 3771 | * Adds a system note to an invoice. |
3772 | 3772 | * |
3773 | 3773 | * @param string $note The note being added. |
3774 | - * @return int|false The new note's ID on success, false on failure. |
|
3774 | + * @return int|false The new note's ID on success, false on failure. |
|
3775 | 3775 | * |
3776 | 3776 | */ |
3777 | 3777 | public function add_system_note( $note ) { |
3778 | - return $this->add_note( $note, false, false, true ); |
|
3779 | - } |
|
3778 | + return $this->add_note( $note, false, false, true ); |
|
3779 | + } |
|
3780 | 3780 | |
3781 | 3781 | /** |
3782 | 3782 | * Adds a note to an invoice. |
3783 | 3783 | * |
3784 | 3784 | * @param string $note The note being added. |
3785 | - * @return int|false The new note's ID on success, false on failure. |
|
3785 | + * @return int|false The new note's ID on success, false on failure. |
|
3786 | 3786 | * |
3787 | 3787 | */ |
3788 | 3788 | public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
@@ -3792,21 +3792,21 @@ discard block |
||
3792 | 3792 | return false; |
3793 | 3793 | } |
3794 | 3794 | |
3795 | - $author = 'System'; |
|
3796 | - $author_email = '[email protected]'; |
|
3795 | + $author = 'System'; |
|
3796 | + $author_email = '[email protected]'; |
|
3797 | 3797 | |
3798 | - // If this is an admin comment or it has been added by the user. |
|
3799 | - if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) { |
|
3800 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
3798 | + // If this is an admin comment or it has been added by the user. |
|
3799 | + if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) { |
|
3800 | + $user = get_user_by( 'id', get_current_user_id() ); |
|
3801 | 3801 | $author = $user->display_name; |
3802 | 3802 | $author_email = $user->user_email; |
3803 | - } |
|
3803 | + } |
|
3804 | 3804 | |
3805 | - return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
3805 | + return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
3806 | 3806 | |
3807 | - } |
|
3807 | + } |
|
3808 | 3808 | |
3809 | - /** |
|
3809 | + /** |
|
3810 | 3810 | * Generates a unique key for the invoice. |
3811 | 3811 | */ |
3812 | 3812 | public function generate_key( $string = '' ) { |
@@ -3826,113 +3826,113 @@ discard block |
||
3826 | 3826 | $number = wpinv_get_next_invoice_number( $this->get_post_type() ); |
3827 | 3827 | } |
3828 | 3828 | |
3829 | - return wpinv_format_invoice_number( $number, $this->get_post_type() ); |
|
3830 | - |
|
3831 | - } |
|
3832 | - |
|
3833 | - /** |
|
3834 | - * Handle the status transition. |
|
3835 | - */ |
|
3836 | - protected function status_transition() { |
|
3837 | - $status_transition = $this->status_transition; |
|
3838 | - |
|
3839 | - // Reset status transition variable. |
|
3840 | - $this->status_transition = false; |
|
3841 | - |
|
3842 | - if ( $status_transition ) { |
|
3843 | - try { |
|
3844 | - |
|
3845 | - // Fire a hook for the status change. |
|
3846 | - do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition ); |
|
3847 | - |
|
3848 | - // @deprecated this is deprecated and will be removed in the future. |
|
3849 | - do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3850 | - |
|
3851 | - if ( ! empty( $status_transition['from'] ) ) { |
|
3852 | - |
|
3853 | - /* translators: 1: old invoice status 2: new invoice status */ |
|
3854 | - $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'], $this ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
3855 | - |
|
3856 | - // Fire another hook. |
|
3857 | - do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this ); |
|
3858 | - do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
3829 | + return wpinv_format_invoice_number( $number, $this->get_post_type() ); |
|
3859 | 3830 | |
3860 | - // @deprecated this is deprecated and will be removed in the future. |
|
3861 | - do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3862 | - |
|
3863 | - // Note the transition occurred. |
|
3864 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] ); |
|
3865 | - |
|
3866 | - // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
3867 | - if ( |
|
3868 | - in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
3869 | - && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3870 | - ) { |
|
3871 | - do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition ); |
|
3872 | - } |
|
3873 | - |
|
3874 | - // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead. |
|
3875 | - if ( |
|
3876 | - in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3877 | - && in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
3878 | - ) { |
|
3879 | - do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition ); |
|
3880 | - } |
|
3881 | - } else { |
|
3882 | - /* translators: %s: new invoice status */ |
|
3883 | - $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
3884 | - |
|
3885 | - // Note the transition occurred. |
|
3886 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
3831 | + } |
|
3887 | 3832 | |
3888 | - } |
|
3889 | - } catch ( Exception $e ) { |
|
3890 | - $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
3891 | - } |
|
3892 | - } |
|
3893 | - } |
|
3833 | + /** |
|
3834 | + * Handle the status transition. |
|
3835 | + */ |
|
3836 | + protected function status_transition() { |
|
3837 | + $status_transition = $this->status_transition; |
|
3838 | + |
|
3839 | + // Reset status transition variable. |
|
3840 | + $this->status_transition = false; |
|
3841 | + |
|
3842 | + if ( $status_transition ) { |
|
3843 | + try { |
|
3844 | + |
|
3845 | + // Fire a hook for the status change. |
|
3846 | + do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition ); |
|
3847 | + |
|
3848 | + // @deprecated this is deprecated and will be removed in the future. |
|
3849 | + do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3850 | + |
|
3851 | + if ( ! empty( $status_transition['from'] ) ) { |
|
3852 | + |
|
3853 | + /* translators: 1: old invoice status 2: new invoice status */ |
|
3854 | + $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'], $this ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
3855 | + |
|
3856 | + // Fire another hook. |
|
3857 | + do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this ); |
|
3858 | + do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
3859 | + |
|
3860 | + // @deprecated this is deprecated and will be removed in the future. |
|
3861 | + do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3862 | + |
|
3863 | + // Note the transition occurred. |
|
3864 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] ); |
|
3865 | + |
|
3866 | + // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
3867 | + if ( |
|
3868 | + in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
3869 | + && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3870 | + ) { |
|
3871 | + do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition ); |
|
3872 | + } |
|
3873 | + |
|
3874 | + // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead. |
|
3875 | + if ( |
|
3876 | + in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3877 | + && in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
3878 | + ) { |
|
3879 | + do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition ); |
|
3880 | + } |
|
3881 | + } else { |
|
3882 | + /* translators: %s: new invoice status */ |
|
3883 | + $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
3884 | + |
|
3885 | + // Note the transition occurred. |
|
3886 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
3887 | + |
|
3888 | + } |
|
3889 | + } catch ( Exception $e ) { |
|
3890 | + $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
3891 | + } |
|
3892 | + } |
|
3893 | + } |
|
3894 | 3894 | |
3895 | - /** |
|
3896 | - * Updates an invoice status. |
|
3897 | - */ |
|
3898 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
3895 | + /** |
|
3896 | + * Updates an invoice status. |
|
3897 | + */ |
|
3898 | + public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
3899 | 3899 | |
3900 | - // Fires before updating a status. |
|
3901 | - do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
3900 | + // Fires before updating a status. |
|
3901 | + do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
3902 | 3902 | |
3903 | - // Update the status. |
|
3904 | - $this->set_status( $new_status, $note, $manual ); |
|
3903 | + // Update the status. |
|
3904 | + $this->set_status( $new_status, $note, $manual ); |
|
3905 | 3905 | |
3906 | - // Save the order. |
|
3907 | - return $this->save(); |
|
3906 | + // Save the order. |
|
3907 | + return $this->save(); |
|
3908 | 3908 | |
3909 | - } |
|
3909 | + } |
|
3910 | 3910 | |
3911 | - /** |
|
3912 | - * @deprecated |
|
3913 | - */ |
|
3914 | - public function refresh_item_ids() { |
|
3911 | + /** |
|
3912 | + * @deprecated |
|
3913 | + */ |
|
3914 | + public function refresh_item_ids() { |
|
3915 | 3915 | $item_ids = implode( ',', array_unique( wp_list_pluck( $this->get_cart_details(), 'item_id' ) ) ); |
3916 | 3916 | update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids ); |
3917 | - } |
|
3917 | + } |
|
3918 | 3918 | |
3919 | - /** |
|
3920 | - * @deprecated |
|
3921 | - */ |
|
3922 | - public function update_items( $temp = false ) { |
|
3919 | + /** |
|
3920 | + * @deprecated |
|
3921 | + */ |
|
3922 | + public function update_items( $temp = false ) { |
|
3923 | 3923 | |
3924 | - $this->set_items( $this->get_items() ); |
|
3924 | + $this->set_items( $this->get_items() ); |
|
3925 | 3925 | |
3926 | - if ( ! $temp ) { |
|
3927 | - $this->save(); |
|
3928 | - } |
|
3926 | + if ( ! $temp ) { |
|
3927 | + $this->save(); |
|
3928 | + } |
|
3929 | 3929 | |
3930 | 3930 | return $this; |
3931 | - } |
|
3931 | + } |
|
3932 | 3932 | |
3933 | - /** |
|
3934 | - * @deprecated |
|
3935 | - */ |
|
3933 | + /** |
|
3934 | + * @deprecated |
|
3935 | + */ |
|
3936 | 3936 | public function validate_discount() { |
3937 | 3937 | |
3938 | 3938 | $discount_code = $this->get_discount_code(); |
@@ -3948,101 +3948,101 @@ discard block |
||
3948 | 3948 | |
3949 | 3949 | } |
3950 | 3950 | |
3951 | - /** |
|
3952 | - * Refunds an invoice. |
|
3953 | - */ |
|
3951 | + /** |
|
3952 | + * Refunds an invoice. |
|
3953 | + */ |
|
3954 | 3954 | public function refund() { |
3955 | - $this->set_status( 'wpi-refunded' ); |
|
3955 | + $this->set_status( 'wpi-refunded' ); |
|
3956 | 3956 | $this->save(); |
3957 | - } |
|
3957 | + } |
|
3958 | 3958 | |
3959 | - /** |
|
3960 | - * Marks an invoice as paid. |
|
3961 | - * |
|
3962 | - * @param string $transaction_id |
|
3963 | - */ |
|
3959 | + /** |
|
3960 | + * Marks an invoice as paid. |
|
3961 | + * |
|
3962 | + * @param string $transaction_id |
|
3963 | + */ |
|
3964 | 3964 | public function mark_paid( $transaction_id = null, $note = '' ) { |
3965 | 3965 | |
3966 | - // Set the transaction id. |
|
3967 | - if ( empty( $transaction_id ) ) { |
|
3968 | - $transaction_id = $this->generate_key( 'trans_' ); |
|
3969 | - } |
|
3966 | + // Set the transaction id. |
|
3967 | + if ( empty( $transaction_id ) ) { |
|
3968 | + $transaction_id = $this->generate_key( 'trans_' ); |
|
3969 | + } |
|
3970 | 3970 | |
3971 | - if ( ! $this->get_transaction_id() ) { |
|
3972 | - $this->set_transaction_id( $transaction_id ); |
|
3973 | - } |
|
3971 | + if ( ! $this->get_transaction_id() ) { |
|
3972 | + $this->set_transaction_id( $transaction_id ); |
|
3973 | + } |
|
3974 | 3974 | |
3975 | - if ( $this->is_paid() && 'wpi-processing' !== $this->get_status() ) { |
|
3976 | - return $this->save(); |
|
3977 | - } |
|
3975 | + if ( $this->is_paid() && 'wpi-processing' !== $this->get_status() ) { |
|
3976 | + return $this->save(); |
|
3977 | + } |
|
3978 | 3978 | |
3979 | - // Set the completed date. |
|
3980 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
3979 | + // Set the completed date. |
|
3980 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
3981 | 3981 | |
3982 | - // Set the new status. |
|
3983 | - $gateway = sanitize_text_field( $this->get_gateway_title() ); |
|
3984 | - if ( $this->is_renewal() || ! $this->is_parent() ) { |
|
3982 | + // Set the new status. |
|
3983 | + $gateway = sanitize_text_field( $this->get_gateway_title() ); |
|
3984 | + if ( $this->is_renewal() || ! $this->is_parent() ) { |
|
3985 | 3985 | |
3986 | - $_note = wp_sprintf( __( 'Renewed via %s', 'invoicing' ), $gateway ); |
|
3987 | - $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
3986 | + $_note = wp_sprintf( __( 'Renewed via %s', 'invoicing' ), $gateway ); |
|
3987 | + $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
3988 | 3988 | |
3989 | - if ( 'none' == $this->get_gateway() ) { |
|
3990 | - $_note = $note; |
|
3991 | - } |
|
3989 | + if ( 'none' == $this->get_gateway() ) { |
|
3990 | + $_note = $note; |
|
3991 | + } |
|
3992 | 3992 | |
3993 | - $this->set_status( 'wpi-renewal', $_note ); |
|
3993 | + $this->set_status( 'wpi-renewal', $_note ); |
|
3994 | 3994 | |
3995 | - } else { |
|
3995 | + } else { |
|
3996 | 3996 | |
3997 | - $_note = wp_sprintf( __( 'Paid via %s', 'invoicing' ), $gateway ); |
|
3998 | - $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
3997 | + $_note = wp_sprintf( __( 'Paid via %s', 'invoicing' ), $gateway ); |
|
3998 | + $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
3999 | 3999 | |
4000 | - if ( 'none' == $this->get_gateway() ) { |
|
4001 | - $_note = $note; |
|
4002 | - } |
|
4000 | + if ( 'none' == $this->get_gateway() ) { |
|
4001 | + $_note = $note; |
|
4002 | + } |
|
4003 | 4003 | |
4004 | - $this->set_status( 'publish', $_note ); |
|
4004 | + $this->set_status( 'publish', $_note ); |
|
4005 | 4005 | |
4006 | - } |
|
4006 | + } |
|
4007 | 4007 | |
4008 | - // Set checkout mode. |
|
4009 | - $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
4010 | - $this->set_mode( $mode ); |
|
4008 | + // Set checkout mode. |
|
4009 | + $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
4010 | + $this->set_mode( $mode ); |
|
4011 | 4011 | |
4012 | - // Save the invoice. |
|
4012 | + // Save the invoice. |
|
4013 | 4013 | $this->save(); |
4014 | - } |
|
4015 | - |
|
4016 | - /** |
|
4017 | - * Save data to the database. |
|
4018 | - * |
|
4019 | - * @since 1.0.19 |
|
4020 | - * @return int invoice ID |
|
4021 | - */ |
|
4022 | - public function save() { |
|
4023 | - $this->maybe_set_date_paid(); |
|
4024 | - $this->maybe_set_key(); |
|
4025 | - parent::save(); |
|
4026 | - $this->clear_cache(); |
|
4027 | - $this->status_transition(); |
|
4028 | - return $this->get_id(); |
|
4029 | - } |
|
4030 | - |
|
4031 | - /** |
|
4014 | + } |
|
4015 | + |
|
4016 | + /** |
|
4017 | + * Save data to the database. |
|
4018 | + * |
|
4019 | + * @since 1.0.19 |
|
4020 | + * @return int invoice ID |
|
4021 | + */ |
|
4022 | + public function save() { |
|
4023 | + $this->maybe_set_date_paid(); |
|
4024 | + $this->maybe_set_key(); |
|
4025 | + parent::save(); |
|
4026 | + $this->clear_cache(); |
|
4027 | + $this->status_transition(); |
|
4028 | + return $this->get_id(); |
|
4029 | + } |
|
4030 | + |
|
4031 | + /** |
|
4032 | 4032 | * Clears the subscription's cache. |
4033 | 4033 | */ |
4034 | 4034 | public function clear_cache() { |
4035 | - if ( $this->get_key() ) { |
|
4036 | - wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' ); |
|
4037 | - } |
|
4038 | - |
|
4039 | - if ( $this->get_number() ) { |
|
4040 | - wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' ); |
|
4041 | - } |
|
4042 | - |
|
4043 | - if ( $this->get_transaction_id() ) { |
|
4044 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' ); |
|
4045 | - } |
|
4046 | - } |
|
4035 | + if ( $this->get_key() ) { |
|
4036 | + wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' ); |
|
4037 | + } |
|
4038 | + |
|
4039 | + if ( $this->get_number() ) { |
|
4040 | + wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' ); |
|
4041 | + } |
|
4042 | + |
|
4043 | + if ( $this->get_transaction_id() ) { |
|
4044 | + wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' ); |
|
4045 | + } |
|
4046 | + } |
|
4047 | 4047 | |
4048 | 4048 | } |
@@ -11,187 +11,187 @@ |
||
11 | 11 | */ |
12 | 12 | class GetPaid_Data_Store { |
13 | 13 | |
14 | - /** |
|
15 | - * Contains an instance of the data store class that we are working with. |
|
16 | - * |
|
17 | - * @var GetPaid_Data_Store |
|
18 | - */ |
|
19 | - private $instance = null; |
|
20 | - |
|
21 | - /** |
|
22 | - * Contains an array of default supported data stores. |
|
23 | - * Format of object name => class name. |
|
24 | - * Example: 'item' => 'GetPaid_Item_Data_Store' |
|
25 | - * You can also pass something like item-<type> for item stores and |
|
26 | - * that type will be used first when available, if a store is requested like |
|
27 | - * this and doesn't exist, then the store would fall back to 'item'. |
|
28 | - * Ran through `getpaid_data_stores`. |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - private $stores = array( |
|
33 | - 'item' => 'GetPaid_Item_Data_Store', |
|
34 | - 'payment_form' => 'GetPaid_Payment_Form_Data_Store', |
|
35 | - 'discount' => 'GetPaid_Discount_Data_Store', |
|
36 | - 'invoice' => 'GetPaid_Invoice_Data_Store', |
|
37 | - 'subscription' => 'GetPaid_Subscription_Data_Store', |
|
38 | - 'customer' => 'GetPaid_Customer_Data_Store', |
|
39 | - ); |
|
40 | - |
|
41 | - /** |
|
42 | - * Contains the name of the current data store's class name. |
|
43 | - * |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - private $current_class_name = ''; |
|
47 | - |
|
48 | - /** |
|
49 | - * The object type this store works with. |
|
50 | - * |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - private $object_type = ''; |
|
54 | - |
|
55 | - /** |
|
56 | - * Tells GetPaid_Data_Store which object |
|
57 | - * store we want to work with. |
|
58 | - * |
|
59 | - * @param string $object_type Name of object. |
|
60 | - */ |
|
61 | - public function __construct( $object_type ) { |
|
62 | - $this->object_type = $object_type; |
|
63 | - $this->stores = apply_filters( 'getpaid_data_stores', $this->stores ); |
|
64 | - |
|
65 | - // If this object type can't be found, check to see if we can load one |
|
66 | - // level up (so if item-type isn't found, we try item). |
|
67 | - if ( ! array_key_exists( $object_type, $this->stores ) ) { |
|
68 | - $pieces = explode( '-', $object_type ); |
|
69 | - $object_type = $pieces[0]; |
|
70 | - } |
|
71 | - |
|
72 | - if ( array_key_exists( $object_type, $this->stores ) ) { |
|
73 | - $store = apply_filters( 'getpaid_' . $object_type . '_data_store', $this->stores[ $object_type ] ); |
|
74 | - if ( is_object( $store ) ) { |
|
75 | - $this->current_class_name = get_class( $store ); |
|
76 | - $this->instance = $store; |
|
77 | - } else { |
|
78 | - if ( ! class_exists( $store ) ) { |
|
79 | - throw new Exception( __( 'Data store class does not exist.', 'invoicing' ) ); |
|
80 | - } |
|
81 | - $this->current_class_name = $store; |
|
82 | - $this->instance = new $store(); |
|
83 | - } |
|
84 | - } else { |
|
85 | - throw new Exception( __( 'Invalid data store.', 'invoicing' ) ); |
|
86 | - } |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Only store the object type to avoid serializing the data store instance. |
|
91 | - * |
|
92 | - * @return array |
|
93 | - */ |
|
94 | - public function __sleep() { |
|
95 | - return array( 'object_type' ); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Re-run the constructor with the object type. |
|
100 | - * |
|
101 | - * @throws Exception When validation fails. |
|
102 | - */ |
|
103 | - public function __wakeup() { |
|
104 | - $this->__construct( $this->object_type ); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Loads a data store. |
|
109 | - * |
|
110 | - * @param string $object_type Name of object. |
|
111 | - * |
|
112 | - * @since 1.0.19 |
|
113 | - * @throws Exception When validation fails. |
|
114 | - * @return GetPaid_Data_Store |
|
115 | - */ |
|
116 | - public static function load( $object_type ) { |
|
117 | - return new GetPaid_Data_Store( $object_type ); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Returns the class name of the current data store. |
|
122 | - * |
|
123 | - * @since 1.0.19 |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - public function get_current_class_name() { |
|
127 | - return $this->current_class_name; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Returns the object type of the current data store. |
|
132 | - * |
|
133 | - * @since 1.0.19 |
|
134 | - * @return string |
|
135 | - */ |
|
136 | - public function get_object_type() { |
|
137 | - return $this->object_type; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Reads an object from the data store. |
|
142 | - * |
|
143 | - * @since 1.0.19 |
|
144 | - * @param GetPaid_Data $data GetPaid data instance. |
|
145 | - */ |
|
146 | - public function read( &$data ) { |
|
147 | - $this->instance->read( $data ); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Create an object in the data store. |
|
152 | - * |
|
153 | - * @since 1.0.19 |
|
154 | - * @param GetPaid_Data $data GetPaid data instance. |
|
155 | - */ |
|
156 | - public function create( &$data ) { |
|
157 | - $this->instance->create( $data ); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Update an object in the data store. |
|
162 | - * |
|
163 | - * @since 1.0.19 |
|
164 | - * @param GetPaid_Data $data GetPaid data instance. |
|
165 | - */ |
|
166 | - public function update( &$data ) { |
|
167 | - $this->instance->update( $data ); |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Delete an object from the data store. |
|
172 | - * |
|
173 | - * @since 1.0.19 |
|
174 | - * @param GetPaid_Data $data GetPaid data instance. |
|
175 | - * @param array $args Array of args to pass to the delete method. |
|
176 | - */ |
|
177 | - public function delete( &$data, $args = array() ) { |
|
178 | - $this->instance->delete( $data, $args ); |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Data stores can define additional function. This passes |
|
183 | - * through to the instance if that function exists. |
|
184 | - * |
|
185 | - * @since 1.0.19 |
|
186 | - * @param string $method Method. |
|
187 | - * @return mixed |
|
188 | - */ |
|
189 | - public function __call( $method, $parameters ) { |
|
190 | - if ( is_callable( array( $this->instance, $method ) ) ) { |
|
191 | - $object = array_shift( $parameters ); |
|
192 | - $parameters = array_merge( array( &$object ), $parameters ); |
|
193 | - return call_user_func_array( array( $this->instance, $method ), $parameters ); |
|
194 | - } |
|
195 | - } |
|
14 | + /** |
|
15 | + * Contains an instance of the data store class that we are working with. |
|
16 | + * |
|
17 | + * @var GetPaid_Data_Store |
|
18 | + */ |
|
19 | + private $instance = null; |
|
20 | + |
|
21 | + /** |
|
22 | + * Contains an array of default supported data stores. |
|
23 | + * Format of object name => class name. |
|
24 | + * Example: 'item' => 'GetPaid_Item_Data_Store' |
|
25 | + * You can also pass something like item-<type> for item stores and |
|
26 | + * that type will be used first when available, if a store is requested like |
|
27 | + * this and doesn't exist, then the store would fall back to 'item'. |
|
28 | + * Ran through `getpaid_data_stores`. |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + private $stores = array( |
|
33 | + 'item' => 'GetPaid_Item_Data_Store', |
|
34 | + 'payment_form' => 'GetPaid_Payment_Form_Data_Store', |
|
35 | + 'discount' => 'GetPaid_Discount_Data_Store', |
|
36 | + 'invoice' => 'GetPaid_Invoice_Data_Store', |
|
37 | + 'subscription' => 'GetPaid_Subscription_Data_Store', |
|
38 | + 'customer' => 'GetPaid_Customer_Data_Store', |
|
39 | + ); |
|
40 | + |
|
41 | + /** |
|
42 | + * Contains the name of the current data store's class name. |
|
43 | + * |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + private $current_class_name = ''; |
|
47 | + |
|
48 | + /** |
|
49 | + * The object type this store works with. |
|
50 | + * |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + private $object_type = ''; |
|
54 | + |
|
55 | + /** |
|
56 | + * Tells GetPaid_Data_Store which object |
|
57 | + * store we want to work with. |
|
58 | + * |
|
59 | + * @param string $object_type Name of object. |
|
60 | + */ |
|
61 | + public function __construct( $object_type ) { |
|
62 | + $this->object_type = $object_type; |
|
63 | + $this->stores = apply_filters( 'getpaid_data_stores', $this->stores ); |
|
64 | + |
|
65 | + // If this object type can't be found, check to see if we can load one |
|
66 | + // level up (so if item-type isn't found, we try item). |
|
67 | + if ( ! array_key_exists( $object_type, $this->stores ) ) { |
|
68 | + $pieces = explode( '-', $object_type ); |
|
69 | + $object_type = $pieces[0]; |
|
70 | + } |
|
71 | + |
|
72 | + if ( array_key_exists( $object_type, $this->stores ) ) { |
|
73 | + $store = apply_filters( 'getpaid_' . $object_type . '_data_store', $this->stores[ $object_type ] ); |
|
74 | + if ( is_object( $store ) ) { |
|
75 | + $this->current_class_name = get_class( $store ); |
|
76 | + $this->instance = $store; |
|
77 | + } else { |
|
78 | + if ( ! class_exists( $store ) ) { |
|
79 | + throw new Exception( __( 'Data store class does not exist.', 'invoicing' ) ); |
|
80 | + } |
|
81 | + $this->current_class_name = $store; |
|
82 | + $this->instance = new $store(); |
|
83 | + } |
|
84 | + } else { |
|
85 | + throw new Exception( __( 'Invalid data store.', 'invoicing' ) ); |
|
86 | + } |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Only store the object type to avoid serializing the data store instance. |
|
91 | + * |
|
92 | + * @return array |
|
93 | + */ |
|
94 | + public function __sleep() { |
|
95 | + return array( 'object_type' ); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Re-run the constructor with the object type. |
|
100 | + * |
|
101 | + * @throws Exception When validation fails. |
|
102 | + */ |
|
103 | + public function __wakeup() { |
|
104 | + $this->__construct( $this->object_type ); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Loads a data store. |
|
109 | + * |
|
110 | + * @param string $object_type Name of object. |
|
111 | + * |
|
112 | + * @since 1.0.19 |
|
113 | + * @throws Exception When validation fails. |
|
114 | + * @return GetPaid_Data_Store |
|
115 | + */ |
|
116 | + public static function load( $object_type ) { |
|
117 | + return new GetPaid_Data_Store( $object_type ); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Returns the class name of the current data store. |
|
122 | + * |
|
123 | + * @since 1.0.19 |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + public function get_current_class_name() { |
|
127 | + return $this->current_class_name; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Returns the object type of the current data store. |
|
132 | + * |
|
133 | + * @since 1.0.19 |
|
134 | + * @return string |
|
135 | + */ |
|
136 | + public function get_object_type() { |
|
137 | + return $this->object_type; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Reads an object from the data store. |
|
142 | + * |
|
143 | + * @since 1.0.19 |
|
144 | + * @param GetPaid_Data $data GetPaid data instance. |
|
145 | + */ |
|
146 | + public function read( &$data ) { |
|
147 | + $this->instance->read( $data ); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Create an object in the data store. |
|
152 | + * |
|
153 | + * @since 1.0.19 |
|
154 | + * @param GetPaid_Data $data GetPaid data instance. |
|
155 | + */ |
|
156 | + public function create( &$data ) { |
|
157 | + $this->instance->create( $data ); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Update an object in the data store. |
|
162 | + * |
|
163 | + * @since 1.0.19 |
|
164 | + * @param GetPaid_Data $data GetPaid data instance. |
|
165 | + */ |
|
166 | + public function update( &$data ) { |
|
167 | + $this->instance->update( $data ); |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Delete an object from the data store. |
|
172 | + * |
|
173 | + * @since 1.0.19 |
|
174 | + * @param GetPaid_Data $data GetPaid data instance. |
|
175 | + * @param array $args Array of args to pass to the delete method. |
|
176 | + */ |
|
177 | + public function delete( &$data, $args = array() ) { |
|
178 | + $this->instance->delete( $data, $args ); |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Data stores can define additional function. This passes |
|
183 | + * through to the instance if that function exists. |
|
184 | + * |
|
185 | + * @since 1.0.19 |
|
186 | + * @param string $method Method. |
|
187 | + * @return mixed |
|
188 | + */ |
|
189 | + public function __call( $method, $parameters ) { |
|
190 | + if ( is_callable( array( $this->instance, $method ) ) ) { |
|
191 | + $object = array_shift( $parameters ); |
|
192 | + $parameters = array_merge( array( &$object ), $parameters ); |
|
193 | + return call_user_func_array( array( $this->instance, $method ), $parameters ); |
|
194 | + } |
|
195 | + } |
|
196 | 196 | |
197 | 197 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
8 | - exit; |
|
8 | + exit; |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | /** |
@@ -15,196 +15,196 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Customer_Data_Store { |
17 | 17 | |
18 | - /* |
|
18 | + /* |
|
19 | 19 | |-------------------------------------------------------------------------- |
20 | 20 | | CRUD Methods |
21 | 21 | |-------------------------------------------------------------------------- |
22 | 22 | */ |
23 | 23 | |
24 | - /** |
|
25 | - * Method to create a new customer in the database. |
|
26 | - * |
|
27 | - * @param GetPaid_Customer $customer customer object. |
|
28 | - */ |
|
29 | - public function create( &$customer ) { |
|
30 | - global $wpdb; |
|
31 | - |
|
32 | - $values = array(); |
|
33 | - $formats = array(); |
|
34 | - |
|
35 | - $fields = self::get_database_fields(); |
|
36 | - unset( $fields['id'] ); |
|
37 | - |
|
38 | - foreach ( $fields as $key => $format ) { |
|
39 | - $values[ $key ] = $customer->get( $key, 'edit' ); |
|
40 | - $formats[] = $format; |
|
41 | - } |
|
42 | - |
|
43 | - $result = $wpdb->insert( $wpdb->prefix . 'getpaid_customers', $values, $formats ); |
|
44 | - |
|
45 | - if ( $result ) { |
|
46 | - $customer->set_id( $wpdb->insert_id ); |
|
47 | - $customer->apply_changes(); |
|
48 | - $customer->clear_cache(); |
|
49 | - do_action( 'getpaid_new_customer', $customer ); |
|
50 | - return true; |
|
51 | - } |
|
52 | - |
|
53 | - return false; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Method to read a customer from the database. |
|
58 | - * |
|
59 | - * @param GetPaid_Customer $customer customer object. |
|
60 | - * |
|
61 | - */ |
|
62 | - public function read( &$customer ) { |
|
63 | - global $wpdb; |
|
64 | - |
|
65 | - $customer->set_defaults(); |
|
66 | - |
|
67 | - if ( ! $customer->get_id() ) { |
|
68 | - $customer->last_error = 'Invalid customer.'; |
|
69 | - $customer->set_id( 0 ); |
|
70 | - return false; |
|
71 | - } |
|
72 | - |
|
73 | - // Maybe retrieve from the cache. |
|
74 | - $raw_customer = wp_cache_get( $customer->get_id(), 'getpaid_customers' ); |
|
75 | - |
|
76 | - // If not found, retrieve from the db. |
|
77 | - if ( false === $raw_customer ) { |
|
78 | - |
|
79 | - $raw_customer = $wpdb->get_row( |
|
80 | - $wpdb->prepare( |
|
81 | - "SELECT * FROM {$wpdb->prefix}getpaid_customers WHERE id = %d", |
|
82 | - $customer->get_id() |
|
83 | - ) |
|
84 | - ); |
|
85 | - |
|
86 | - // Update the cache with our data |
|
87 | - wp_cache_set( $customer->get_id(), $raw_customer, 'getpaid_customers' ); |
|
88 | - |
|
89 | - } |
|
90 | - |
|
91 | - if ( ! $raw_customer ) { |
|
92 | - $raw_customer->last_error = 'Invalid customer.'; |
|
93 | - return false; |
|
94 | - } |
|
95 | - |
|
96 | - // Loop through raw customer fields. |
|
97 | - foreach ( (array) $raw_customer as $key => $value ) { |
|
98 | - $customer->set( $key, $value ); |
|
99 | - } |
|
100 | - |
|
101 | - $customer->set_object_read( true ); |
|
102 | - do_action( 'getpaid_read_customer', $customer ); |
|
103 | - |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Method to update a customer in the database. |
|
108 | - * |
|
109 | - * @param GetPaid_Customer $customer Customer object. |
|
110 | - */ |
|
111 | - public function update( &$customer ) { |
|
112 | - global $wpdb; |
|
113 | - |
|
114 | - do_action( 'getpaid_before_update_customer', $customer, $customer->get_changes() ); |
|
115 | - |
|
116 | - $changes = $customer->get_changes(); |
|
117 | - $values = array(); |
|
118 | - $format = array(); |
|
119 | - |
|
120 | - foreach ( self::get_database_fields() as $key => $format ) { |
|
121 | - if ( array_key_exists( $key, $changes ) ) { |
|
122 | - $values[ $key ] = $customer->get( $key, 'edit' ); |
|
123 | - $formats[] = $format; |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - if ( empty( $values ) ) { |
|
128 | - return; |
|
129 | - } |
|
130 | - |
|
131 | - $wpdb->update( |
|
132 | - $wpdb->prefix . 'getpaid_customers', |
|
133 | - $values, |
|
134 | - array( |
|
135 | - 'id' => $customer->get_id(), |
|
136 | - ), |
|
137 | - $formats, |
|
138 | - '%d' |
|
139 | - ); |
|
140 | - |
|
141 | - // Apply the changes. |
|
142 | - $customer->apply_changes(); |
|
143 | - |
|
144 | - // Delete cache. |
|
145 | - $customer->clear_cache(); |
|
146 | - |
|
147 | - // Fire a hook. |
|
148 | - do_action( 'getpaid_update_customer', $customer ); |
|
149 | - |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Method to delete a customer from the database. |
|
154 | - * |
|
155 | - * @param GetPaid_Customer $customer |
|
156 | - */ |
|
157 | - public function delete( &$customer ) { |
|
158 | - global $wpdb; |
|
159 | - |
|
160 | - do_action( 'getpaid_before_delete_customer', $customer ); |
|
161 | - |
|
162 | - $wpdb->delete( |
|
163 | - $wpdb->prefix . 'getpaid_customers', |
|
164 | - array( |
|
165 | - 'id' => $customer->get_id(), |
|
166 | - ), |
|
167 | - '%d' |
|
168 | - ); |
|
169 | - |
|
170 | - // Delete cache. |
|
171 | - $customer->clear_cache(); |
|
172 | - |
|
173 | - // Fire a hook. |
|
174 | - do_action( 'getpaid_delete_customer', $customer ); |
|
175 | - |
|
176 | - $customer->set_id( 0 ); |
|
177 | - } |
|
178 | - |
|
179 | - /* |
|
24 | + /** |
|
25 | + * Method to create a new customer in the database. |
|
26 | + * |
|
27 | + * @param GetPaid_Customer $customer customer object. |
|
28 | + */ |
|
29 | + public function create( &$customer ) { |
|
30 | + global $wpdb; |
|
31 | + |
|
32 | + $values = array(); |
|
33 | + $formats = array(); |
|
34 | + |
|
35 | + $fields = self::get_database_fields(); |
|
36 | + unset( $fields['id'] ); |
|
37 | + |
|
38 | + foreach ( $fields as $key => $format ) { |
|
39 | + $values[ $key ] = $customer->get( $key, 'edit' ); |
|
40 | + $formats[] = $format; |
|
41 | + } |
|
42 | + |
|
43 | + $result = $wpdb->insert( $wpdb->prefix . 'getpaid_customers', $values, $formats ); |
|
44 | + |
|
45 | + if ( $result ) { |
|
46 | + $customer->set_id( $wpdb->insert_id ); |
|
47 | + $customer->apply_changes(); |
|
48 | + $customer->clear_cache(); |
|
49 | + do_action( 'getpaid_new_customer', $customer ); |
|
50 | + return true; |
|
51 | + } |
|
52 | + |
|
53 | + return false; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Method to read a customer from the database. |
|
58 | + * |
|
59 | + * @param GetPaid_Customer $customer customer object. |
|
60 | + * |
|
61 | + */ |
|
62 | + public function read( &$customer ) { |
|
63 | + global $wpdb; |
|
64 | + |
|
65 | + $customer->set_defaults(); |
|
66 | + |
|
67 | + if ( ! $customer->get_id() ) { |
|
68 | + $customer->last_error = 'Invalid customer.'; |
|
69 | + $customer->set_id( 0 ); |
|
70 | + return false; |
|
71 | + } |
|
72 | + |
|
73 | + // Maybe retrieve from the cache. |
|
74 | + $raw_customer = wp_cache_get( $customer->get_id(), 'getpaid_customers' ); |
|
75 | + |
|
76 | + // If not found, retrieve from the db. |
|
77 | + if ( false === $raw_customer ) { |
|
78 | + |
|
79 | + $raw_customer = $wpdb->get_row( |
|
80 | + $wpdb->prepare( |
|
81 | + "SELECT * FROM {$wpdb->prefix}getpaid_customers WHERE id = %d", |
|
82 | + $customer->get_id() |
|
83 | + ) |
|
84 | + ); |
|
85 | + |
|
86 | + // Update the cache with our data |
|
87 | + wp_cache_set( $customer->get_id(), $raw_customer, 'getpaid_customers' ); |
|
88 | + |
|
89 | + } |
|
90 | + |
|
91 | + if ( ! $raw_customer ) { |
|
92 | + $raw_customer->last_error = 'Invalid customer.'; |
|
93 | + return false; |
|
94 | + } |
|
95 | + |
|
96 | + // Loop through raw customer fields. |
|
97 | + foreach ( (array) $raw_customer as $key => $value ) { |
|
98 | + $customer->set( $key, $value ); |
|
99 | + } |
|
100 | + |
|
101 | + $customer->set_object_read( true ); |
|
102 | + do_action( 'getpaid_read_customer', $customer ); |
|
103 | + |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Method to update a customer in the database. |
|
108 | + * |
|
109 | + * @param GetPaid_Customer $customer Customer object. |
|
110 | + */ |
|
111 | + public function update( &$customer ) { |
|
112 | + global $wpdb; |
|
113 | + |
|
114 | + do_action( 'getpaid_before_update_customer', $customer, $customer->get_changes() ); |
|
115 | + |
|
116 | + $changes = $customer->get_changes(); |
|
117 | + $values = array(); |
|
118 | + $format = array(); |
|
119 | + |
|
120 | + foreach ( self::get_database_fields() as $key => $format ) { |
|
121 | + if ( array_key_exists( $key, $changes ) ) { |
|
122 | + $values[ $key ] = $customer->get( $key, 'edit' ); |
|
123 | + $formats[] = $format; |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + if ( empty( $values ) ) { |
|
128 | + return; |
|
129 | + } |
|
130 | + |
|
131 | + $wpdb->update( |
|
132 | + $wpdb->prefix . 'getpaid_customers', |
|
133 | + $values, |
|
134 | + array( |
|
135 | + 'id' => $customer->get_id(), |
|
136 | + ), |
|
137 | + $formats, |
|
138 | + '%d' |
|
139 | + ); |
|
140 | + |
|
141 | + // Apply the changes. |
|
142 | + $customer->apply_changes(); |
|
143 | + |
|
144 | + // Delete cache. |
|
145 | + $customer->clear_cache(); |
|
146 | + |
|
147 | + // Fire a hook. |
|
148 | + do_action( 'getpaid_update_customer', $customer ); |
|
149 | + |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Method to delete a customer from the database. |
|
154 | + * |
|
155 | + * @param GetPaid_Customer $customer |
|
156 | + */ |
|
157 | + public function delete( &$customer ) { |
|
158 | + global $wpdb; |
|
159 | + |
|
160 | + do_action( 'getpaid_before_delete_customer', $customer ); |
|
161 | + |
|
162 | + $wpdb->delete( |
|
163 | + $wpdb->prefix . 'getpaid_customers', |
|
164 | + array( |
|
165 | + 'id' => $customer->get_id(), |
|
166 | + ), |
|
167 | + '%d' |
|
168 | + ); |
|
169 | + |
|
170 | + // Delete cache. |
|
171 | + $customer->clear_cache(); |
|
172 | + |
|
173 | + // Fire a hook. |
|
174 | + do_action( 'getpaid_delete_customer', $customer ); |
|
175 | + |
|
176 | + $customer->set_id( 0 ); |
|
177 | + } |
|
178 | + |
|
179 | + /* |
|
180 | 180 | |-------------------------------------------------------------------------- |
181 | 181 | | Additional Methods |
182 | 182 | |-------------------------------------------------------------------------- |
183 | 183 | */ |
184 | - public static function get_database_fields() { |
|
185 | - |
|
186 | - $fields = array( |
|
187 | - 'id' => '%d', |
|
188 | - 'user_id' => '%d', |
|
189 | - 'email' => '%s', |
|
190 | - 'email_cc' => '%s', |
|
191 | - 'status' => '%s', |
|
192 | - 'purchase_value' => '%f', |
|
193 | - 'purchase_count' => '%d', |
|
194 | - 'date_created' => '%s', |
|
195 | - 'date_modified' => '%s', |
|
196 | - 'uuid' => '%s', |
|
197 | - ); |
|
198 | - |
|
199 | - // Add address fields. |
|
200 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
201 | - |
|
202 | - // Skip id, user_id and email. |
|
203 | - if ( ! in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) { |
|
204 | - $fields[ $field ] = '%s'; |
|
205 | - } |
|
206 | - } |
|
207 | - |
|
208 | - return $fields; |
|
209 | - } |
|
184 | + public static function get_database_fields() { |
|
185 | + |
|
186 | + $fields = array( |
|
187 | + 'id' => '%d', |
|
188 | + 'user_id' => '%d', |
|
189 | + 'email' => '%s', |
|
190 | + 'email_cc' => '%s', |
|
191 | + 'status' => '%s', |
|
192 | + 'purchase_value' => '%f', |
|
193 | + 'purchase_count' => '%d', |
|
194 | + 'date_created' => '%s', |
|
195 | + 'date_modified' => '%s', |
|
196 | + 'uuid' => '%s', |
|
197 | + ); |
|
198 | + |
|
199 | + // Add address fields. |
|
200 | + foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
201 | + |
|
202 | + // Skip id, user_id and email. |
|
203 | + if ( ! in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) { |
|
204 | + $fields[ $field ] = '%s'; |
|
205 | + } |
|
206 | + } |
|
207 | + |
|
208 | + return $fields; |
|
209 | + } |
|
210 | 210 | } |
@@ -14,652 +14,652 @@ |
||
14 | 14 | */ |
15 | 15 | class WPInv_Plugin { |
16 | 16 | |
17 | - /** |
|
18 | - * GetPaid version. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $version; |
|
23 | - |
|
24 | - /** |
|
25 | - * Data container. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $data = array(); |
|
30 | - |
|
31 | - /** |
|
32 | - * Form elements instance. |
|
33 | - * |
|
34 | - * @var WPInv_Payment_Form_Elements |
|
35 | - */ |
|
36 | - public $form_elements; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var array An array of payment gateways. |
|
40 | - */ |
|
41 | - public $gateways; |
|
42 | - |
|
43 | - /** |
|
44 | - * Class constructor. |
|
45 | - */ |
|
46 | - public function __construct() { |
|
47 | - $this->define_constants(); |
|
48 | - $this->includes(); |
|
49 | - $this->init_hooks(); |
|
50 | - $this->set_properties(); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Sets a custom data property. |
|
55 | - * |
|
56 | - * @param string $prop The prop to set. |
|
57 | - * @param mixed $value The value to retrieve. |
|
58 | - */ |
|
59 | - public function set( $prop, $value ) { |
|
60 | - $this->data[ $prop ] = $value; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Gets a custom data property. |
|
65 | - * |
|
66 | - * @param string $prop The prop to set. |
|
67 | - * @return mixed The value. |
|
68 | - */ |
|
69 | - public function get( $prop ) { |
|
70 | - |
|
71 | - if ( isset( $this->data[ $prop ] ) ) { |
|
72 | - return $this->data[ $prop ]; |
|
73 | - } |
|
74 | - |
|
75 | - return null; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Define class properties. |
|
80 | - */ |
|
81 | - public function set_properties() { |
|
82 | - |
|
83 | - // Sessions. |
|
84 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
86 | - $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
87 | - |
|
88 | - // Init other objects. |
|
89 | - $this->set( 'notes', new WPInv_Notes() ); |
|
90 | - $this->set( 'api', new WPInv_API() ); |
|
91 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
92 | - $this->set( 'template', new GetPaid_Template() ); |
|
93 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
94 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
95 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
96 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
97 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
98 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
99 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
100 | - |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Define plugin constants. |
|
105 | - */ |
|
106 | - public function define_constants() { |
|
107 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
108 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
109 | - $this->version = WPINV_VERSION; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Hook into actions and filters. |
|
114 | - * |
|
115 | - * @since 1.0.19 |
|
116 | - */ |
|
117 | - protected function init_hooks() { |
|
118 | - /* Internationalize the text strings used. */ |
|
119 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
120 | - |
|
121 | - // Init the plugin after WordPress inits. |
|
122 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
123 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
124 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
125 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
126 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
127 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
128 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
129 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
130 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
131 | - add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
132 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
133 | - |
|
134 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
17 | + /** |
|
18 | + * GetPaid version. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $version; |
|
23 | + |
|
24 | + /** |
|
25 | + * Data container. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $data = array(); |
|
30 | + |
|
31 | + /** |
|
32 | + * Form elements instance. |
|
33 | + * |
|
34 | + * @var WPInv_Payment_Form_Elements |
|
35 | + */ |
|
36 | + public $form_elements; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var array An array of payment gateways. |
|
40 | + */ |
|
41 | + public $gateways; |
|
42 | + |
|
43 | + /** |
|
44 | + * Class constructor. |
|
45 | + */ |
|
46 | + public function __construct() { |
|
47 | + $this->define_constants(); |
|
48 | + $this->includes(); |
|
49 | + $this->init_hooks(); |
|
50 | + $this->set_properties(); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Sets a custom data property. |
|
55 | + * |
|
56 | + * @param string $prop The prop to set. |
|
57 | + * @param mixed $value The value to retrieve. |
|
58 | + */ |
|
59 | + public function set( $prop, $value ) { |
|
60 | + $this->data[ $prop ] = $value; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Gets a custom data property. |
|
65 | + * |
|
66 | + * @param string $prop The prop to set. |
|
67 | + * @return mixed The value. |
|
68 | + */ |
|
69 | + public function get( $prop ) { |
|
70 | + |
|
71 | + if ( isset( $this->data[ $prop ] ) ) { |
|
72 | + return $this->data[ $prop ]; |
|
73 | + } |
|
74 | + |
|
75 | + return null; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Define class properties. |
|
80 | + */ |
|
81 | + public function set_properties() { |
|
82 | + |
|
83 | + // Sessions. |
|
84 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
86 | + $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
87 | + |
|
88 | + // Init other objects. |
|
89 | + $this->set( 'notes', new WPInv_Notes() ); |
|
90 | + $this->set( 'api', new WPInv_API() ); |
|
91 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
92 | + $this->set( 'template', new GetPaid_Template() ); |
|
93 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
94 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
95 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
96 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
97 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
98 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
99 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
100 | + |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Define plugin constants. |
|
105 | + */ |
|
106 | + public function define_constants() { |
|
107 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
108 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
109 | + $this->version = WPINV_VERSION; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Hook into actions and filters. |
|
114 | + * |
|
115 | + * @since 1.0.19 |
|
116 | + */ |
|
117 | + protected function init_hooks() { |
|
118 | + /* Internationalize the text strings used. */ |
|
119 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
120 | + |
|
121 | + // Init the plugin after WordPress inits. |
|
122 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
123 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
124 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
125 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
126 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
127 | + add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
128 | + add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
129 | + add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
130 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
131 | + add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
132 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
133 | + |
|
134 | + add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
135 | 135 | add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
136 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
137 | - |
|
138 | - // Fires after registering actions. |
|
139 | - do_action( 'wpinv_actions', $this ); |
|
140 | - do_action( 'getpaid_actions', $this ); |
|
141 | - |
|
142 | - } |
|
143 | - |
|
144 | - public function plugins_loaded() { |
|
145 | - /* Internationalize the text strings used. */ |
|
146 | - $this->load_textdomain(); |
|
147 | - |
|
148 | - do_action( 'wpinv_loaded' ); |
|
149 | - |
|
150 | - // Fix oxygen page builder conflict |
|
151 | - if ( function_exists( 'ct_css_output' ) ) { |
|
152 | - wpinv_oxygen_fix_conflict(); |
|
153 | - } |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Load Localisation files. |
|
158 | - * |
|
159 | - * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
160 | - * |
|
161 | - * Locales found in: |
|
162 | - * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
163 | - * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
164 | - * |
|
165 | - * @since 1.0.0 |
|
166 | - */ |
|
167 | - public function load_textdomain() { |
|
168 | - |
|
169 | - load_plugin_textdomain( |
|
170 | - 'invoicing', |
|
171 | - false, |
|
172 | - plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' |
|
173 | - ); |
|
174 | - |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Include required core files used in admin and on the frontend. |
|
179 | - */ |
|
180 | - public function includes() { |
|
181 | - |
|
182 | - // Start with the settings. |
|
183 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
184 | - |
|
185 | - // Packages/libraries. |
|
186 | - require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
187 | - require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
188 | - |
|
189 | - // Load functions. |
|
190 | - require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
191 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
192 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
193 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
194 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
195 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
196 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
197 | - require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
198 | - require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
199 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
200 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
201 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
202 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
203 | - require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
204 | - require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
205 | - |
|
206 | - // Register autoloader. |
|
207 | - try { |
|
208 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
209 | - } catch ( Exception $e ) { |
|
210 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
211 | - } |
|
212 | - |
|
213 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
214 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
215 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
216 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
217 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
218 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
219 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
220 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
221 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
222 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
223 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
224 | - require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
225 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
226 | - require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
227 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
228 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
229 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
230 | - require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
231 | - require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
232 | - require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
233 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
234 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
235 | - |
|
236 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
237 | - GetPaid_Post_Types_Admin::init(); |
|
238 | - |
|
239 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
240 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
241 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
242 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
243 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
244 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
245 | - // load the user class only on the users.php page |
|
246 | - global $pagenow; |
|
247 | - if ( $pagenow == 'users.php' ) { |
|
248 | - new WPInv_Admin_Users(); |
|
249 | - } |
|
250 | - } |
|
251 | - |
|
252 | - // Register cli commands |
|
253 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
254 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
255 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
256 | - } |
|
257 | - |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Class autoloader |
|
262 | - * |
|
263 | - * @param string $class_name The name of the class to load. |
|
264 | - * @access public |
|
265 | - * @since 1.0.19 |
|
266 | - * @return void |
|
267 | - */ |
|
268 | - public function autoload( $class_name ) { |
|
269 | - |
|
270 | - // Normalize the class name... |
|
271 | - $class_name = strtolower( $class_name ); |
|
272 | - |
|
273 | - // ... and make sure it is our class. |
|
274 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
275 | - return; |
|
276 | - } |
|
277 | - |
|
278 | - // Next, prepare the file name from the class. |
|
279 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
280 | - |
|
281 | - // Base path of the classes. |
|
282 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
283 | - |
|
284 | - // And an array of possible locations in order of importance. |
|
285 | - $locations = array( |
|
286 | - "$plugin_path/includes", |
|
287 | - "$plugin_path/includes/data-stores", |
|
288 | - "$plugin_path/includes/gateways", |
|
289 | - "$plugin_path/includes/payments", |
|
290 | - "$plugin_path/includes/geolocation", |
|
291 | - "$plugin_path/includes/reports", |
|
292 | - "$plugin_path/includes/api", |
|
293 | - "$plugin_path/includes/admin", |
|
294 | - "$plugin_path/includes/admin/meta-boxes", |
|
295 | - ); |
|
296 | - |
|
297 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
298 | - |
|
299 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
300 | - include trailingslashit( $location ) . $file_name; |
|
301 | - break; |
|
302 | - } |
|
136 | + add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
137 | + |
|
138 | + // Fires after registering actions. |
|
139 | + do_action( 'wpinv_actions', $this ); |
|
140 | + do_action( 'getpaid_actions', $this ); |
|
141 | + |
|
142 | + } |
|
143 | + |
|
144 | + public function plugins_loaded() { |
|
145 | + /* Internationalize the text strings used. */ |
|
146 | + $this->load_textdomain(); |
|
147 | + |
|
148 | + do_action( 'wpinv_loaded' ); |
|
149 | + |
|
150 | + // Fix oxygen page builder conflict |
|
151 | + if ( function_exists( 'ct_css_output' ) ) { |
|
152 | + wpinv_oxygen_fix_conflict(); |
|
153 | + } |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Load Localisation files. |
|
158 | + * |
|
159 | + * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
160 | + * |
|
161 | + * Locales found in: |
|
162 | + * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
163 | + * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
164 | + * |
|
165 | + * @since 1.0.0 |
|
166 | + */ |
|
167 | + public function load_textdomain() { |
|
168 | + |
|
169 | + load_plugin_textdomain( |
|
170 | + 'invoicing', |
|
171 | + false, |
|
172 | + plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' |
|
173 | + ); |
|
174 | + |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * Include required core files used in admin and on the frontend. |
|
179 | + */ |
|
180 | + public function includes() { |
|
181 | + |
|
182 | + // Start with the settings. |
|
183 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
184 | + |
|
185 | + // Packages/libraries. |
|
186 | + require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
187 | + require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
188 | + |
|
189 | + // Load functions. |
|
190 | + require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
191 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
192 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
193 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
194 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
195 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
196 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
197 | + require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
198 | + require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
199 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
200 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
201 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
202 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
203 | + require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
204 | + require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
205 | + |
|
206 | + // Register autoloader. |
|
207 | + try { |
|
208 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
209 | + } catch ( Exception $e ) { |
|
210 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
211 | + } |
|
212 | + |
|
213 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
214 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
215 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
216 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
217 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
218 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
219 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
220 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
221 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
222 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
223 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
224 | + require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
225 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
226 | + require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
227 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
228 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
229 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
230 | + require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
231 | + require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
232 | + require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
233 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
234 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
235 | + |
|
236 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
237 | + GetPaid_Post_Types_Admin::init(); |
|
238 | + |
|
239 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
240 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
241 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
242 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
243 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
244 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
245 | + // load the user class only on the users.php page |
|
246 | + global $pagenow; |
|
247 | + if ( $pagenow == 'users.php' ) { |
|
248 | + new WPInv_Admin_Users(); |
|
249 | + } |
|
250 | + } |
|
251 | + |
|
252 | + // Register cli commands |
|
253 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
254 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
255 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
256 | + } |
|
257 | + |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Class autoloader |
|
262 | + * |
|
263 | + * @param string $class_name The name of the class to load. |
|
264 | + * @access public |
|
265 | + * @since 1.0.19 |
|
266 | + * @return void |
|
267 | + */ |
|
268 | + public function autoload( $class_name ) { |
|
269 | + |
|
270 | + // Normalize the class name... |
|
271 | + $class_name = strtolower( $class_name ); |
|
272 | + |
|
273 | + // ... and make sure it is our class. |
|
274 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
275 | + return; |
|
276 | + } |
|
277 | + |
|
278 | + // Next, prepare the file name from the class. |
|
279 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
280 | + |
|
281 | + // Base path of the classes. |
|
282 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
283 | + |
|
284 | + // And an array of possible locations in order of importance. |
|
285 | + $locations = array( |
|
286 | + "$plugin_path/includes", |
|
287 | + "$plugin_path/includes/data-stores", |
|
288 | + "$plugin_path/includes/gateways", |
|
289 | + "$plugin_path/includes/payments", |
|
290 | + "$plugin_path/includes/geolocation", |
|
291 | + "$plugin_path/includes/reports", |
|
292 | + "$plugin_path/includes/api", |
|
293 | + "$plugin_path/includes/admin", |
|
294 | + "$plugin_path/includes/admin/meta-boxes", |
|
295 | + ); |
|
296 | + |
|
297 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
298 | + |
|
299 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
300 | + include trailingslashit( $location ) . $file_name; |
|
301 | + break; |
|
302 | + } |
|
303 | 303 | } |
304 | 304 | |
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Inits hooks etc. |
|
309 | - */ |
|
310 | - public function init() { |
|
311 | - |
|
312 | - // Fires before getpaid inits. |
|
313 | - do_action( 'before_getpaid_init', $this ); |
|
314 | - |
|
315 | - // Maybe upgrade. |
|
316 | - $this->maybe_upgrade_database(); |
|
317 | - |
|
318 | - // Load default gateways. |
|
319 | - $gateways = apply_filters( |
|
320 | - 'getpaid_default_gateways', |
|
321 | - array( |
|
322 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
323 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
324 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
325 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
326 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
327 | - ) |
|
328 | - ); |
|
329 | - |
|
330 | - foreach ( $gateways as $id => $class ) { |
|
331 | - $this->gateways[ $id ] = new $class(); |
|
332 | - } |
|
333 | - |
|
334 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
335 | - GetPaid_Installer::rename_gateways_label(); |
|
336 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
337 | - } |
|
338 | - |
|
339 | - // Fires after getpaid inits. |
|
340 | - do_action( 'getpaid_init', $this ); |
|
341 | - |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Checks if this is an IPN request and processes it. |
|
346 | - */ |
|
347 | - public function maybe_process_ipn() { |
|
348 | - |
|
349 | - // Ensure that this is an IPN request. |
|
350 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
351 | - return; |
|
352 | - } |
|
353 | - |
|
354 | - $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
355 | - |
|
356 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
357 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
358 | - exit; |
|
359 | - |
|
360 | - } |
|
361 | - |
|
362 | - public function enqueue_scripts() { |
|
363 | - |
|
364 | - // Fires before adding scripts. |
|
365 | - do_action( 'getpaid_enqueue_scripts' ); |
|
366 | - |
|
367 | - $localize = array(); |
|
368 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
369 | - $localize['thousands'] = wpinv_thousands_separator(); |
|
370 | - $localize['decimals'] = wpinv_decimal_separator(); |
|
371 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
372 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
373 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
374 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
375 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
376 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
377 | - $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
|
378 | - |
|
379 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
380 | - |
|
381 | - // reCaptcha. |
|
382 | - if ( getpaid_is_recaptcha_enabled() ) { |
|
383 | - $url = apply_filters( |
|
384 | - 'getpaid_recaptcha_api_url', |
|
385 | - add_query_arg( |
|
386 | - array( |
|
387 | - 'render' => 'v2' === getpaid_get_recaptcha_version() ? 'explicit' : getpaid_get_recaptcha_site_key(), |
|
388 | - ), |
|
389 | - 'https://www.google.com/recaptcha/api.js' |
|
390 | - ) |
|
391 | - ); |
|
392 | - wp_enqueue_script( 'recaptcha', $url, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
393 | - } |
|
394 | - |
|
395 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
396 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
397 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
398 | - } |
|
399 | - |
|
400 | - public function wpinv_actions() { |
|
401 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
402 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
403 | - } |
|
404 | - |
|
405 | - if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
406 | - include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
407 | - } |
|
408 | - } |
|
409 | - |
|
410 | - /** |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Inits hooks etc. |
|
309 | + */ |
|
310 | + public function init() { |
|
311 | + |
|
312 | + // Fires before getpaid inits. |
|
313 | + do_action( 'before_getpaid_init', $this ); |
|
314 | + |
|
315 | + // Maybe upgrade. |
|
316 | + $this->maybe_upgrade_database(); |
|
317 | + |
|
318 | + // Load default gateways. |
|
319 | + $gateways = apply_filters( |
|
320 | + 'getpaid_default_gateways', |
|
321 | + array( |
|
322 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
323 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
324 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
325 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
326 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
327 | + ) |
|
328 | + ); |
|
329 | + |
|
330 | + foreach ( $gateways as $id => $class ) { |
|
331 | + $this->gateways[ $id ] = new $class(); |
|
332 | + } |
|
333 | + |
|
334 | + if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
335 | + GetPaid_Installer::rename_gateways_label(); |
|
336 | + update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
337 | + } |
|
338 | + |
|
339 | + // Fires after getpaid inits. |
|
340 | + do_action( 'getpaid_init', $this ); |
|
341 | + |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Checks if this is an IPN request and processes it. |
|
346 | + */ |
|
347 | + public function maybe_process_ipn() { |
|
348 | + |
|
349 | + // Ensure that this is an IPN request. |
|
350 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
351 | + return; |
|
352 | + } |
|
353 | + |
|
354 | + $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
355 | + |
|
356 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
357 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
358 | + exit; |
|
359 | + |
|
360 | + } |
|
361 | + |
|
362 | + public function enqueue_scripts() { |
|
363 | + |
|
364 | + // Fires before adding scripts. |
|
365 | + do_action( 'getpaid_enqueue_scripts' ); |
|
366 | + |
|
367 | + $localize = array(); |
|
368 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
369 | + $localize['thousands'] = wpinv_thousands_separator(); |
|
370 | + $localize['decimals'] = wpinv_decimal_separator(); |
|
371 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
372 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
373 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
374 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
375 | + $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
376 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
377 | + $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
|
378 | + |
|
379 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
380 | + |
|
381 | + // reCaptcha. |
|
382 | + if ( getpaid_is_recaptcha_enabled() ) { |
|
383 | + $url = apply_filters( |
|
384 | + 'getpaid_recaptcha_api_url', |
|
385 | + add_query_arg( |
|
386 | + array( |
|
387 | + 'render' => 'v2' === getpaid_get_recaptcha_version() ? 'explicit' : getpaid_get_recaptcha_site_key(), |
|
388 | + ), |
|
389 | + 'https://www.google.com/recaptcha/api.js' |
|
390 | + ) |
|
391 | + ); |
|
392 | + wp_enqueue_script( 'recaptcha', $url, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
393 | + } |
|
394 | + |
|
395 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
396 | + wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
397 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
398 | + } |
|
399 | + |
|
400 | + public function wpinv_actions() { |
|
401 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
402 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
403 | + } |
|
404 | + |
|
405 | + if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
406 | + include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
407 | + } |
|
408 | + } |
|
409 | + |
|
410 | + /** |
|
411 | 411 | * Fires an action after verifying that a user can fire them. |
412 | - * |
|
413 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
414 | - * current user owns the invoice/subscription. |
|
412 | + * |
|
413 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
414 | + * current user owns the invoice/subscription. |
|
415 | 415 | */ |
416 | 416 | public function maybe_do_authenticated_action() { |
417 | 417 | |
418 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
418 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
419 | 419 | |
420 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
421 | - $data = wp_unslash( $_REQUEST ); |
|
422 | - if ( is_user_logged_in() ) { |
|
423 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
424 | - } |
|
420 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
421 | + $data = wp_unslash( $_REQUEST ); |
|
422 | + if ( is_user_logged_in() ) { |
|
423 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
424 | + } |
|
425 | 425 | |
426 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
426 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
427 | 427 | |
428 | - } |
|
428 | + } |
|
429 | 429 | |
430 | 430 | } |
431 | 431 | |
432 | - public function pre_get_posts( $wp_query ) { |
|
433 | - |
|
434 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
435 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
436 | - } |
|
437 | - |
|
438 | - return $wp_query; |
|
439 | - } |
|
440 | - |
|
441 | - /** |
|
442 | - * Register widgets |
|
443 | - * |
|
444 | - */ |
|
445 | - public function register_widgets() { |
|
446 | - global $pagenow; |
|
447 | - |
|
448 | - // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
449 | - // So we disable our widgets when editing a page with UX Builder. |
|
450 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
451 | - return; |
|
452 | - } |
|
453 | - |
|
454 | - $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
455 | - |
|
456 | - if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
457 | - // don't initiate in these conditions. |
|
458 | - } else { |
|
459 | - |
|
460 | - // Only load allowed widgets. |
|
461 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
462 | - $widgets = apply_filters( |
|
463 | - 'getpaid_widget_classes', |
|
464 | - array( |
|
465 | - 'WPInv_Checkout_Widget', |
|
466 | - 'WPInv_History_Widget', |
|
467 | - 'WPInv_Receipt_Widget', |
|
468 | - 'WPInv_Subscriptions_Widget', |
|
469 | - 'WPInv_Buy_Item_Widget', |
|
470 | - 'WPInv_Messages_Widget', |
|
471 | - 'WPInv_GetPaid_Widget', |
|
472 | - 'WPInv_Invoice_Widget', |
|
473 | - ) |
|
474 | - ); |
|
475 | - |
|
476 | - // For each widget... |
|
477 | - foreach ( $widgets as $widget ) { |
|
478 | - |
|
479 | - // Abort early if it is excluded for this page. |
|
480 | - if ( in_array( $widget, $exclude ) ) { |
|
481 | - continue; |
|
482 | - } |
|
483 | - |
|
484 | - // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
485 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
486 | - register_widget( $widget ); |
|
487 | - } else { |
|
488 | - new $widget(); |
|
489 | - } |
|
432 | + public function pre_get_posts( $wp_query ) { |
|
433 | + |
|
434 | + if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
435 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
436 | + } |
|
437 | + |
|
438 | + return $wp_query; |
|
439 | + } |
|
440 | + |
|
441 | + /** |
|
442 | + * Register widgets |
|
443 | + * |
|
444 | + */ |
|
445 | + public function register_widgets() { |
|
446 | + global $pagenow; |
|
447 | + |
|
448 | + // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
449 | + // So we disable our widgets when editing a page with UX Builder. |
|
450 | + if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
451 | + return; |
|
452 | + } |
|
453 | + |
|
454 | + $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
455 | + |
|
456 | + if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
457 | + // don't initiate in these conditions. |
|
458 | + } else { |
|
459 | + |
|
460 | + // Only load allowed widgets. |
|
461 | + $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
462 | + $widgets = apply_filters( |
|
463 | + 'getpaid_widget_classes', |
|
464 | + array( |
|
465 | + 'WPInv_Checkout_Widget', |
|
466 | + 'WPInv_History_Widget', |
|
467 | + 'WPInv_Receipt_Widget', |
|
468 | + 'WPInv_Subscriptions_Widget', |
|
469 | + 'WPInv_Buy_Item_Widget', |
|
470 | + 'WPInv_Messages_Widget', |
|
471 | + 'WPInv_GetPaid_Widget', |
|
472 | + 'WPInv_Invoice_Widget', |
|
473 | + ) |
|
474 | + ); |
|
475 | + |
|
476 | + // For each widget... |
|
477 | + foreach ( $widgets as $widget ) { |
|
478 | + |
|
479 | + // Abort early if it is excluded for this page. |
|
480 | + if ( in_array( $widget, $exclude ) ) { |
|
481 | + continue; |
|
482 | + } |
|
483 | + |
|
484 | + // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
485 | + if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
486 | + register_widget( $widget ); |
|
487 | + } else { |
|
488 | + new $widget(); |
|
489 | + } |
|
490 | 490 | } |
491 | 491 | } |
492 | 492 | |
493 | - } |
|
493 | + } |
|
494 | + |
|
495 | + /** |
|
496 | + * Upgrades the database. |
|
497 | + * |
|
498 | + * @since 2.0.2 |
|
499 | + */ |
|
500 | + public function maybe_upgrade_database() { |
|
501 | + |
|
502 | + // Ensure the database tables are up to date. |
|
503 | + GetPaid_Installer::maybe_create_db_tables(); |
|
504 | + |
|
505 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
506 | + |
|
507 | + if ( $wpi_version == WPINV_VERSION ) { |
|
508 | + return; |
|
509 | + } |
|
510 | + |
|
511 | + $installer = new GetPaid_Installer(); |
|
512 | + |
|
513 | + if ( empty( $wpi_version ) ) { |
|
514 | + return $installer->upgrade_db( 0 ); |
|
515 | + } |
|
516 | + |
|
517 | + $upgrades = array( |
|
518 | + '0.0.5' => '004', |
|
519 | + '1.0.3' => '102', |
|
520 | + '2.0.0' => '118', |
|
521 | + '2.8.0' => '279', |
|
522 | + ); |
|
523 | + |
|
524 | + foreach ( $upgrades as $key => $method ) { |
|
525 | + |
|
526 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
527 | + return $installer->upgrade_db( $method ); |
|
528 | + } |
|
529 | + } |
|
530 | + |
|
531 | + } |
|
532 | + |
|
533 | + /** |
|
534 | + * Flushes the permalinks if needed. |
|
535 | + * |
|
536 | + * @since 2.0.8 |
|
537 | + */ |
|
538 | + public function maybe_flush_permalinks() { |
|
539 | + |
|
540 | + $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
541 | + |
|
542 | + if ( ! empty( $flush ) ) { |
|
543 | + flush_rewrite_rules(); |
|
544 | + delete_option( 'wpinv_flush_permalinks' ); |
|
545 | + } |
|
546 | + |
|
547 | + } |
|
548 | + |
|
549 | + /** |
|
550 | + * Remove our pages from yoast sitemaps. |
|
551 | + * |
|
552 | + * @since 1.0.19 |
|
553 | + * @param int[] $excluded_posts_ids |
|
554 | + */ |
|
555 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
556 | + |
|
557 | + // Ensure that we have an array. |
|
558 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
559 | + $excluded_posts_ids = array(); |
|
560 | + } |
|
561 | + |
|
562 | + // Prepare our pages. |
|
563 | + $our_pages = array(); |
|
564 | + |
|
565 | + // Checkout page. |
|
566 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
567 | + |
|
568 | + // Success page. |
|
569 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
570 | + |
|
571 | + // Failure page. |
|
572 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
494 | 573 | |
495 | - /** |
|
496 | - * Upgrades the database. |
|
497 | - * |
|
498 | - * @since 2.0.2 |
|
499 | - */ |
|
500 | - public function maybe_upgrade_database() { |
|
574 | + // History page. |
|
575 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
501 | 576 | |
502 | - // Ensure the database tables are up to date. |
|
503 | - GetPaid_Installer::maybe_create_db_tables(); |
|
577 | + // Subscriptions page. |
|
578 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
504 | 579 | |
505 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
580 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
506 | 581 | |
507 | - if ( $wpi_version == WPINV_VERSION ) { |
|
508 | - return; |
|
509 | - } |
|
582 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
583 | + return array_unique( $excluded_posts_ids ); |
|
510 | 584 | |
511 | - $installer = new GetPaid_Installer(); |
|
585 | + } |
|
586 | + |
|
587 | + /** |
|
588 | + * Remove our pages from yoast sitemaps. |
|
589 | + * |
|
590 | + * @since 1.0.19 |
|
591 | + * @param string[] $post_types |
|
592 | + */ |
|
593 | + public function exclude_invoicing_post_types( $post_types ) { |
|
594 | + |
|
595 | + // Ensure that we have an array. |
|
596 | + if ( ! is_array( $post_types ) ) { |
|
597 | + $post_types = array(); |
|
598 | + } |
|
599 | + |
|
600 | + // Remove our post types. |
|
601 | + return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
602 | + } |
|
603 | + |
|
604 | + /** |
|
605 | + * Displays additional footer code. |
|
606 | + * |
|
607 | + * @since 2.0.0 |
|
608 | + */ |
|
609 | + public function wp_footer() { |
|
610 | + wpinv_get_template( 'frontend-footer.php' ); |
|
611 | + } |
|
512 | 612 | |
513 | - if ( empty( $wpi_version ) ) { |
|
514 | - return $installer->upgrade_db( 0 ); |
|
515 | - } |
|
613 | + /** |
|
614 | + * Displays additional header code. |
|
615 | + * |
|
616 | + * @since 2.0.0 |
|
617 | + */ |
|
618 | + public function wp_head() { |
|
619 | + wpinv_get_template( 'frontend-head.php' ); |
|
620 | + } |
|
516 | 621 | |
517 | - $upgrades = array( |
|
518 | - '0.0.5' => '004', |
|
519 | - '1.0.3' => '102', |
|
520 | - '2.0.0' => '118', |
|
521 | - '2.8.0' => '279', |
|
522 | - ); |
|
523 | - |
|
524 | - foreach ( $upgrades as $key => $method ) { |
|
525 | - |
|
526 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
527 | - return $installer->upgrade_db( $method ); |
|
528 | - } |
|
529 | - } |
|
530 | - |
|
531 | - } |
|
532 | - |
|
533 | - /** |
|
534 | - * Flushes the permalinks if needed. |
|
535 | - * |
|
536 | - * @since 2.0.8 |
|
537 | - */ |
|
538 | - public function maybe_flush_permalinks() { |
|
539 | - |
|
540 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
541 | - |
|
542 | - if ( ! empty( $flush ) ) { |
|
543 | - flush_rewrite_rules(); |
|
544 | - delete_option( 'wpinv_flush_permalinks' ); |
|
545 | - } |
|
546 | - |
|
547 | - } |
|
548 | - |
|
549 | - /** |
|
550 | - * Remove our pages from yoast sitemaps. |
|
551 | - * |
|
552 | - * @since 1.0.19 |
|
553 | - * @param int[] $excluded_posts_ids |
|
554 | - */ |
|
555 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
556 | - |
|
557 | - // Ensure that we have an array. |
|
558 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
559 | - $excluded_posts_ids = array(); |
|
560 | - } |
|
561 | - |
|
562 | - // Prepare our pages. |
|
563 | - $our_pages = array(); |
|
564 | - |
|
565 | - // Checkout page. |
|
566 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
567 | - |
|
568 | - // Success page. |
|
569 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
570 | - |
|
571 | - // Failure page. |
|
572 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
573 | - |
|
574 | - // History page. |
|
575 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
576 | - |
|
577 | - // Subscriptions page. |
|
578 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
579 | - |
|
580 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
581 | - |
|
582 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
583 | - return array_unique( $excluded_posts_ids ); |
|
584 | - |
|
585 | - } |
|
586 | - |
|
587 | - /** |
|
588 | - * Remove our pages from yoast sitemaps. |
|
589 | - * |
|
590 | - * @since 1.0.19 |
|
591 | - * @param string[] $post_types |
|
592 | - */ |
|
593 | - public function exclude_invoicing_post_types( $post_types ) { |
|
594 | - |
|
595 | - // Ensure that we have an array. |
|
596 | - if ( ! is_array( $post_types ) ) { |
|
597 | - $post_types = array(); |
|
598 | - } |
|
599 | - |
|
600 | - // Remove our post types. |
|
601 | - return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
602 | - } |
|
603 | - |
|
604 | - /** |
|
605 | - * Displays additional footer code. |
|
606 | - * |
|
607 | - * @since 2.0.0 |
|
608 | - */ |
|
609 | - public function wp_footer() { |
|
610 | - wpinv_get_template( 'frontend-footer.php' ); |
|
611 | - } |
|
612 | - |
|
613 | - /** |
|
614 | - * Displays additional header code. |
|
615 | - * |
|
616 | - * @since 2.0.0 |
|
617 | - */ |
|
618 | - public function wp_head() { |
|
619 | - wpinv_get_template( 'frontend-head.php' ); |
|
620 | - } |
|
621 | - |
|
622 | - /** |
|
623 | - * Custom query vars. |
|
624 | - * |
|
625 | - */ |
|
626 | - public function custom_query_vars( $vars ) { |
|
622 | + /** |
|
623 | + * Custom query vars. |
|
624 | + * |
|
625 | + */ |
|
626 | + public function custom_query_vars( $vars ) { |
|
627 | 627 | $vars[] = 'getpaid-ipn'; |
628 | 628 | return $vars; |
629 | - } |
|
629 | + } |
|
630 | 630 | |
631 | - /** |
|
632 | - * Add rewrite tags and rules. |
|
633 | - * |
|
634 | - */ |
|
635 | - public function add_rewrite_rule() { |
|
631 | + /** |
|
632 | + * Add rewrite tags and rules. |
|
633 | + * |
|
634 | + */ |
|
635 | + public function add_rewrite_rule() { |
|
636 | 636 | $tag = 'getpaid-ipn'; |
637 | 637 | add_rewrite_tag( "%$tag%", '([^&]+)' ); |
638 | 638 | add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
639 | - } |
|
639 | + } |
|
640 | 640 | |
641 | - /** |
|
642 | - * Processes non-query string ipns. |
|
643 | - * |
|
644 | - */ |
|
645 | - public function maybe_process_new_ipn( $query ) { |
|
641 | + /** |
|
642 | + * Processes non-query string ipns. |
|
643 | + * |
|
644 | + */ |
|
645 | + public function maybe_process_new_ipn( $query ) { |
|
646 | 646 | |
647 | 647 | if ( is_admin() || ! $query->is_main_query() ) { |
648 | 648 | return; |
649 | 649 | } |
650 | 650 | |
651 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
651 | + $gateway = get_query_var( 'getpaid-ipn' ); |
|
652 | 652 | |
653 | 653 | if ( ! empty( $gateway ) ) { |
654 | 654 | |
655 | - $gateway = sanitize_text_field( $gateway ); |
|
656 | - nocache_headers(); |
|
657 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
658 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
659 | - exit; |
|
655 | + $gateway = sanitize_text_field( $gateway ); |
|
656 | + nocache_headers(); |
|
657 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
658 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
659 | + exit; |
|
660 | 660 | |
661 | 661 | } |
662 | 662 | |
663 | - } |
|
663 | + } |
|
664 | 664 | |
665 | 665 | } |