@@ -12,75 +12,75 @@ discard block |
||
12 | 12 | * @var GetPaid_Payment_Form $form |
13 | 13 | */ |
14 | 14 | |
15 | -defined( 'ABSPATH' ) || exit; |
|
15 | +defined('ABSPATH') || exit; |
|
16 | 16 | |
17 | -$field_type = sanitize_key( $field_type ); |
|
17 | +$field_type = sanitize_key($field_type); |
|
18 | 18 | |
19 | -echo "<div class='row " . esc_attr( $field_type ) . "'>"; |
|
19 | +echo "<div class='row " . esc_attr($field_type) . "'>"; |
|
20 | 20 | |
21 | 21 | // Prepare current user. |
22 | -if ( ! empty( $form->invoice ) ) { |
|
22 | +if (!empty($form->invoice)) { |
|
23 | 23 | $user_id = $form->invoice->get_user_id(); |
24 | 24 | } |
25 | 25 | |
26 | -if ( empty( $user_id ) && is_user_logged_in() ) { |
|
26 | +if (empty($user_id) && is_user_logged_in()) { |
|
27 | 27 | $user_id = get_current_user_id(); |
28 | 28 | } |
29 | 29 | |
30 | -if ( ! empty( $user_id ) ) { |
|
31 | - $user = wp_get_current_user(); |
|
30 | +if (!empty($user_id)) { |
|
31 | + $user = wp_get_current_user(); |
|
32 | 32 | } |
33 | 33 | |
34 | -foreach ( $fields as $address_field ) { |
|
34 | +foreach ($fields as $address_field) { |
|
35 | 35 | |
36 | 36 | // Skip if it is hidden. |
37 | - if ( empty( $address_field['visible'] ) ) { |
|
37 | + if (empty($address_field['visible'])) { |
|
38 | 38 | continue; |
39 | 39 | } |
40 | 40 | |
41 | - do_action( 'getpaid_payment_form_address_field_before_' . $address_field['name'], $field_type, $address_field ); |
|
41 | + do_action('getpaid_payment_form_address_field_before_' . $address_field['name'], $field_type, $address_field); |
|
42 | 42 | |
43 | 43 | // Prepare variables. |
44 | 44 | $field_name = $address_field['name']; |
45 | 45 | $field_name = "{$field_type}[$field_name]"; |
46 | - $wrap_class = getpaid_get_form_element_grid_class( $address_field ); |
|
47 | - $wrap_class = esc_attr( "$wrap_class getpaid-address-field-wrapper" ); |
|
48 | - $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] ); |
|
49 | - $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] ); |
|
50 | - $value = ! empty( $user_id ) ? get_user_meta( $user_id, '_' . $address_field['name'], true ) : ''; |
|
51 | - $label = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] ); |
|
52 | - |
|
53 | - $method_name = 'get_' . str_replace( 'wpinv_', '', $address_field['name'] ); |
|
54 | - if ( ! empty( $form->invoice ) && is_callable( array( $form->invoice, $method_name ) ) ) { |
|
55 | - $value = call_user_func( array( $form->invoice, $method_name ) ); |
|
46 | + $wrap_class = getpaid_get_form_element_grid_class($address_field); |
|
47 | + $wrap_class = esc_attr("$wrap_class getpaid-address-field-wrapper"); |
|
48 | + $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']); |
|
49 | + $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']); |
|
50 | + $value = !empty($user_id) ? get_user_meta($user_id, '_' . $address_field['name'], true) : ''; |
|
51 | + $label = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']); |
|
52 | + |
|
53 | + $method_name = 'get_' . str_replace('wpinv_', '', $address_field['name']); |
|
54 | + if (!empty($form->invoice) && is_callable(array($form->invoice, $method_name))) { |
|
55 | + $value = call_user_func(array($form->invoice, $method_name)); |
|
56 | 56 | } |
57 | 57 | |
58 | - if ( empty( $value ) && 'wpinv_first_name' === $address_field['name'] && ! empty( $user ) ) { |
|
58 | + if (empty($value) && 'wpinv_first_name' === $address_field['name'] && !empty($user)) { |
|
59 | 59 | $value = $user->first_name; |
60 | 60 | } |
61 | 61 | |
62 | - if ( empty( $value ) && 'wpinv_last_name' === $address_field['name'] && ! empty( $user ) ) { |
|
62 | + if (empty($value) && 'wpinv_last_name' === $address_field['name'] && !empty($user)) { |
|
63 | 63 | $value = $user->last_name; |
64 | 64 | } |
65 | 65 | |
66 | - if ( ! empty( $address_field['required'] ) ) { |
|
66 | + if (!empty($address_field['required'])) { |
|
67 | 67 | $label .= "<span class='text-danger'> *</span>"; |
68 | 68 | } |
69 | 69 | |
70 | 70 | // Display the country. |
71 | - if ( 'wpinv_country' === $address_field['name'] ) { |
|
71 | + if ('wpinv_country' === $address_field['name']) { |
|
72 | 72 | |
73 | - echo "<div class='form-group mb-3 " . esc_attr( $wrap_class ) . " getpaid-address-field-wrapper__country'"; |
|
73 | + echo "<div class='form-group mb-3 " . esc_attr($wrap_class) . " getpaid-address-field-wrapper__country'"; |
|
74 | 74 | |
75 | 75 | aui()->select( |
76 | 76 | array( |
77 | 77 | 'options' => wpinv_get_country_list(), |
78 | - 'name' => esc_attr( $field_name ), |
|
79 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
80 | - 'value' => esc_attr( $country ), |
|
78 | + 'name' => esc_attr($field_name), |
|
79 | + 'id' => sanitize_html_class($field_name) . $uniqid, |
|
80 | + 'value' => esc_attr($country), |
|
81 | 81 | 'placeholder' => $placeholder, |
82 | - 'required' => ! empty( $address_field['required'] ), |
|
83 | - 'label' => wp_kses_post( $label ), |
|
82 | + 'required' => !empty($address_field['required']), |
|
83 | + 'label' => wp_kses_post($label), |
|
84 | 84 | 'label_type' => 'vertical', |
85 | 85 | 'help_text' => $description, |
86 | 86 | 'class' => 'getpaid-address-field wpinv_country', |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | true |
95 | 95 | ); |
96 | 96 | |
97 | - if ( wpinv_should_validate_vat_number() ) { |
|
97 | + if (wpinv_should_validate_vat_number()) { |
|
98 | 98 | |
99 | 99 | aui()->input( |
100 | 100 | array( |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | 'id' => "shipping-toggle$uniqid", |
104 | 104 | 'wrap_class' => 'getpaid-address-field-wrapper__address-confirm mt-1 d-none', |
105 | 105 | 'required' => false, |
106 | - 'label' => __( 'I certify that I live in the country selected above', 'invoicing' ) . "<span class='text-danger'> *</span>", |
|
106 | + 'label' => __('I certify that I live in the country selected above', 'invoicing') . "<span class='text-danger'> *</span>", |
|
107 | 107 | 'value' => 1, |
108 | 108 | 'checked' => true, |
109 | 109 | 'class' => 'w-auto', |
@@ -118,9 +118,9 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | // Display the state. |
121 | - elseif ( 'wpinv_state' == $address_field['name'] ) { |
|
121 | + elseif ('wpinv_state' == $address_field['name']) { |
|
122 | 122 | |
123 | - if ( empty( $value ) ) { |
|
123 | + if (empty($value)) { |
|
124 | 124 | $value = wpinv_get_default_state(); |
125 | 125 | } |
126 | 126 | |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | $placeholder, |
131 | 131 | $label, |
132 | 132 | $description, |
133 | - ! empty( $address_field['required'] ), |
|
133 | + !empty($address_field['required']), |
|
134 | 134 | $wrap_class, |
135 | 135 | $field_name, |
136 | 136 | true |
@@ -138,8 +138,8 @@ discard block |
||
138 | 138 | |
139 | 139 | } else { |
140 | 140 | |
141 | - $key = str_replace( 'wpinv_', '', $address_field['name'] ); |
|
142 | - $key = esc_attr( str_replace( '_', '-', $key ) ); |
|
141 | + $key = str_replace('wpinv_', '', $address_field['name']); |
|
142 | + $key = esc_attr(str_replace('_', '-', $key)); |
|
143 | 143 | $autocomplete = ''; |
144 | 144 | $replacements = array( |
145 | 145 | 'zip' => 'postal-code', |
@@ -152,37 +152,37 @@ discard block |
||
152 | 152 | ); |
153 | 153 | |
154 | 154 | |
155 | - if ( isset( $replacements[ $key ] ) ) { |
|
155 | + if (isset($replacements[$key])) { |
|
156 | 156 | $autocomplete = array( |
157 | - 'autocomplete' => "$field_type {$replacements[ $key ]}", |
|
157 | + 'autocomplete' => "$field_type {$replacements[$key]}", |
|
158 | 158 | ); |
159 | 159 | } |
160 | 160 | |
161 | 161 | $append = ''; |
162 | 162 | |
163 | - if ( 'billing' === $field_type && wpinv_should_validate_vat_number() && 'vat-number' === $key ) { |
|
164 | - $valid = esc_attr__( 'Valid', 'invoicing' ); |
|
165 | - $invalid = esc_attr__( 'Invalid', 'invoicing' ); |
|
166 | - $validate = esc_attr__( 'Validate', 'invoicing' ); |
|
163 | + if ('billing' === $field_type && wpinv_should_validate_vat_number() && 'vat-number' === $key) { |
|
164 | + $valid = esc_attr__('Valid', 'invoicing'); |
|
165 | + $invalid = esc_attr__('Invalid', 'invoicing'); |
|
166 | + $validate = esc_attr__('Validate', 'invoicing'); |
|
167 | 167 | $append = "<span class='btn btn-primary getpaid-vat-number-validate' data-valid='$valid' data-invalid='$invalid' data-validate='$validate'>$validate</span>"; |
168 | 168 | } |
169 | 169 | |
170 | - if ( 'billing' === $field_type ) { |
|
171 | - $description .= '<div class="getpaid-error-' . esc_attr( $field_name ) . ' getpaid-custom-payment-form-errors alert alert-danger d-none"></div>'; |
|
170 | + if ('billing' === $field_type) { |
|
171 | + $description .= '<div class="getpaid-error-' . esc_attr($field_name) . ' getpaid-custom-payment-form-errors alert alert-danger d-none"></div>'; |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | aui()->input( |
175 | 175 | array( |
176 | - 'name' => esc_attr( $field_name ), |
|
177 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
178 | - 'required' => ! empty( $address_field['required'] ), |
|
176 | + 'name' => esc_attr($field_name), |
|
177 | + 'id' => sanitize_html_class($field_name) . $uniqid, |
|
178 | + 'required' => !empty($address_field['required']), |
|
179 | 179 | 'placeholder' => $placeholder, |
180 | - 'label' => wp_kses_post( $label ), |
|
180 | + 'label' => wp_kses_post($label), |
|
181 | 181 | 'label_type' => 'vertical', |
182 | 182 | 'help_text' => $description, |
183 | 183 | 'type' => 'text', |
184 | - 'value' => apply_filters( 'getpaid_payment_form_value_' . $address_field['name'], esc_attr( $value ) ), |
|
185 | - 'class' => 'getpaid-address-field ' . esc_attr( $address_field['name'] ), |
|
184 | + 'value' => apply_filters('getpaid_payment_form_value_' . $address_field['name'], esc_attr($value)), |
|
185 | + 'class' => 'getpaid-address-field ' . esc_attr($address_field['name']), |
|
186 | 186 | 'wrap_class' => "$wrap_class getpaid-address-field-wrapper__$key", |
187 | 187 | 'label_class' => 'getpaid-address-field-label getpaid-address-field-label__' . $key, |
188 | 188 | 'extra_attributes' => $autocomplete, |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | |
194 | 194 | } |
195 | 195 | |
196 | - do_action( 'getpaid_payment_form_address_field_after_' . $address_field['name'], $field_type, $address_field ); |
|
196 | + do_action('getpaid_payment_form_address_field_after_' . $address_field['name'], $field_type, $address_field); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | echo '</div>'; |
@@ -7,37 +7,37 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | $value = $query_value; |
13 | 13 | $class = ''; |
14 | 14 | |
15 | -if ( ! empty( $form->invoice ) ) { |
|
16 | - $value = sanitize_email( $form->invoice->get_email() ); |
|
17 | -} elseif ( is_user_logged_in() ) { |
|
15 | +if (!empty($form->invoice)) { |
|
16 | + $value = sanitize_email($form->invoice->get_email()); |
|
17 | +} elseif (is_user_logged_in()) { |
|
18 | 18 | $user = wp_get_current_user(); |
19 | - $value = sanitize_email( $user->user_email ); |
|
19 | + $value = sanitize_email($user->user_email); |
|
20 | 20 | } |
21 | 21 | |
22 | -if ( ! empty( $value ) && ! empty( $hide_billing_email ) ) { |
|
22 | +if (!empty($value) && !empty($hide_billing_email)) { |
|
23 | 23 | $class = 'd-none'; |
24 | 24 | } |
25 | 25 | |
26 | -do_action( 'getpaid_before_payment_form_billing_email', $form ); |
|
26 | +do_action('getpaid_before_payment_form_billing_email', $form); |
|
27 | 27 | |
28 | -echo "<span class='" . esc_attr( $class ) . "'>"; |
|
28 | +echo "<span class='" . esc_attr($class) . "'>"; |
|
29 | 29 | |
30 | 30 | aui()->input( |
31 | 31 | array( |
32 | 32 | 'name' => 'billing_email', |
33 | - 'id' => esc_attr( $element_id ), |
|
34 | - 'placeholder' => empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
35 | - 'required' => ! empty( $required ), |
|
36 | - 'label' => empty( $label ) ? '' : wp_kses_post( $label ) . '<span class="text-danger"> *</span>', |
|
33 | + 'id' => esc_attr($element_id), |
|
34 | + 'placeholder' => empty($placeholder) ? '' : esc_attr($placeholder), |
|
35 | + 'required' => !empty($required), |
|
36 | + 'label' => empty($label) ? '' : wp_kses_post($label) . '<span class="text-danger"> *</span>', |
|
37 | 37 | 'label_type' => 'vertical', |
38 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
38 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
39 | 39 | 'type' => 'email', |
40 | - 'value' => apply_filters ( 'getpaid_payment_form_billing_email_value', $value ), |
|
40 | + 'value' => apply_filters('getpaid_payment_form_billing_email_value', $value), |
|
41 | 41 | 'class' => 'wpinv_billing_email getpaid-refresh-on-change', |
42 | 42 | 'extra_attributes' => array( |
43 | 43 | 'autocomplete' => 'billing email', |
@@ -48,4 +48,4 @@ discard block |
||
48 | 48 | |
49 | 49 | echo '</span>'; |
50 | 50 | |
51 | -do_action( 'getpaid_after_payment_form_billing_email', $form ); |
|
51 | +do_action('getpaid_after_payment_form_billing_email', $form); |
@@ -160,50 +160,50 @@ |
||
160 | 160 | */ |
161 | 161 | function getpaid_calculate_invoice_discount( $invoice, $discount ) { |
162 | 162 | |
163 | - $initial_discount = 0; |
|
164 | - $recurring_discount = 0; |
|
163 | + $initial_discount = 0; |
|
164 | + $recurring_discount = 0; |
|
165 | 165 | |
166 | - foreach ( $invoice->get_items() as $item ) { |
|
166 | + foreach ( $invoice->get_items() as $item ) { |
|
167 | 167 | |
168 | - // Abort if it is not valid for this item. |
|
169 | - if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
170 | - continue; |
|
171 | - } |
|
168 | + // Abort if it is not valid for this item. |
|
169 | + if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
170 | + continue; |
|
171 | + } |
|
172 | 172 | |
173 | - // Calculate the initial amount... |
|
174 | - $item_discount = $discount->get_discounted_amount( $item->get_sub_total() ); |
|
175 | - $recurring_item_discount = 0; |
|
173 | + // Calculate the initial amount... |
|
174 | + $item_discount = $discount->get_discounted_amount( $item->get_sub_total() ); |
|
175 | + $recurring_item_discount = 0; |
|
176 | 176 | |
177 | - // ... and maybe the recurring amount. |
|
178 | - if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
179 | - $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
180 | - } |
|
177 | + // ... and maybe the recurring amount. |
|
178 | + if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
179 | + $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
180 | + } |
|
181 | 181 | |
182 | - // Discount should not exceed discounted amount. |
|
183 | - if ( ! $discount->is_type( 'percent' ) ) { |
|
182 | + // Discount should not exceed discounted amount. |
|
183 | + if ( ! $discount->is_type( 'percent' ) ) { |
|
184 | 184 | |
185 | - if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { |
|
186 | - $item_discount = $discount->get_amount() - $initial_discount; |
|
187 | - } |
|
185 | + if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { |
|
186 | + $item_discount = $discount->get_amount() - $initial_discount; |
|
187 | + } |
|
188 | 188 | |
189 | - if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { |
|
190 | - $recurring_item_discount = $discount->get_amount() - $recurring_discount; |
|
191 | - } |
|
189 | + if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { |
|
190 | + $recurring_item_discount = $discount->get_amount() - $recurring_discount; |
|
191 | + } |
|
192 | 192 | } |
193 | 193 | |
194 | - $initial_discount += $item_discount; |
|
195 | - $recurring_discount += $recurring_item_discount; |
|
196 | - $item->item_discount = $item_discount; |
|
197 | - $item->recurring_item_discount = $recurring_item_discount; |
|
194 | + $initial_discount += $item_discount; |
|
195 | + $recurring_discount += $recurring_item_discount; |
|
196 | + $item->item_discount = $item_discount; |
|
197 | + $item->recurring_item_discount = $recurring_item_discount; |
|
198 | 198 | |
199 | - } |
|
199 | + } |
|
200 | 200 | |
201 | - return array( |
|
202 | - 'name' => 'discount_code', |
|
203 | - 'discount_code' => $discount->get_code(), |
|
204 | - 'initial_discount' => $initial_discount, |
|
205 | - 'recurring_discount' => $recurring_discount, |
|
206 | - ); |
|
201 | + return array( |
|
202 | + 'name' => 'discount_code', |
|
203 | + 'discount_code' => $discount->get_code(), |
|
204 | + 'initial_discount' => $initial_discount, |
|
205 | + 'recurring_discount' => $recurring_discount, |
|
206 | + ); |
|
207 | 207 | |
208 | 208 | } |
209 | 209 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Returns an array of discount type. |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | return apply_filters( |
18 | 18 | 'wpinv_discount_types', |
19 | 19 | array( |
20 | - 'percent' => __( 'Percentage', 'invoicing' ), |
|
21 | - 'flat' => __( 'Flat Amount', 'invoicing' ), |
|
20 | + 'percent' => __('Percentage', 'invoicing'), |
|
21 | + 'flat' => __('Flat Amount', 'invoicing'), |
|
22 | 22 | ) |
23 | 23 | ); |
24 | 24 | } |
@@ -28,46 +28,46 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return string |
30 | 30 | */ |
31 | -function wpinv_get_discount_type_name( $type = '' ) { |
|
31 | +function wpinv_get_discount_type_name($type = '') { |
|
32 | 32 | $types = wpinv_get_discount_types(); |
33 | - return isset( $types[ $type ] ) ? $types[ $type ] : $type; |
|
33 | + return isset($types[$type]) ? $types[$type] : $type; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Deletes a discount via the admin page. |
38 | 38 | * |
39 | 39 | */ |
40 | -function wpinv_delete_discount( $data ) { |
|
40 | +function wpinv_delete_discount($data) { |
|
41 | 41 | |
42 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
43 | - $discount->delete( true ); |
|
42 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
43 | + $discount->delete(true); |
|
44 | 44 | |
45 | 45 | } |
46 | -add_action( 'getpaid_authenticated_admin_action_delete_discount', 'wpinv_delete_discount' ); |
|
46 | +add_action('getpaid_authenticated_admin_action_delete_discount', 'wpinv_delete_discount'); |
|
47 | 47 | |
48 | 48 | /** |
49 | 49 | * Deactivates a discount via the admin page. |
50 | 50 | */ |
51 | -function wpinv_activate_discount( $data ) { |
|
51 | +function wpinv_activate_discount($data) { |
|
52 | 52 | |
53 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
54 | - $discount->set_status( 'publish' ); |
|
53 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
54 | + $discount->set_status('publish'); |
|
55 | 55 | $discount->save(); |
56 | 56 | |
57 | 57 | } |
58 | -add_action( 'getpaid_authenticated_admin_action_activate_discount', 'wpinv_activate_discount' ); |
|
58 | +add_action('getpaid_authenticated_admin_action_activate_discount', 'wpinv_activate_discount'); |
|
59 | 59 | |
60 | 60 | /** |
61 | 61 | * Activates a discount via the admin page. |
62 | 62 | */ |
63 | -function wpinv_deactivate_discount( $data ) { |
|
63 | +function wpinv_deactivate_discount($data) { |
|
64 | 64 | |
65 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
66 | - $discount->set_status( 'pending' ); |
|
65 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
66 | + $discount->set_status('pending'); |
|
67 | 67 | $discount->save(); |
68 | 68 | |
69 | 69 | } |
70 | -add_action( 'getpaid_authenticated_admin_action_deactivate_discount', 'wpinv_deactivate_discount' ); |
|
70 | +add_action('getpaid_authenticated_admin_action_deactivate_discount', 'wpinv_deactivate_discount'); |
|
71 | 71 | |
72 | 72 | /** |
73 | 73 | * Fetches a discount object. |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | * @since 1.0.15 |
77 | 77 | * @return WPInv_Discount |
78 | 78 | */ |
79 | -function wpinv_get_discount( $discount ) { |
|
80 | - return new WPInv_Discount( $discount ); |
|
79 | +function wpinv_get_discount($discount) { |
|
80 | + return new WPInv_Discount($discount); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | * @since 1.0.15 |
88 | 88 | * @return WPInv_Discount |
89 | 89 | */ |
90 | -function wpinv_get_discount_obj( $discount = 0 ) { |
|
91 | - return new WPInv_Discount( $discount ); |
|
90 | +function wpinv_get_discount_obj($discount = 0) { |
|
91 | + return new WPInv_Discount($discount); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -98,10 +98,10 @@ discard block |
||
98 | 98 | * @param string|int $value The field value |
99 | 99 | * @return bool|WPInv_Discount |
100 | 100 | */ |
101 | -function wpinv_get_discount_by( $deprecated = null, $value = '' ) { |
|
102 | - $discount = new WPInv_Discount( $value ); |
|
101 | +function wpinv_get_discount_by($deprecated = null, $value = '') { |
|
102 | + $discount = new WPInv_Discount($value); |
|
103 | 103 | |
104 | - if ( $discount->get_id() != 0 ) { |
|
104 | + if ($discount->get_id() != 0) { |
|
105 | 105 | return $discount; |
106 | 106 | } |
107 | 107 | |
@@ -116,9 +116,9 @@ discard block |
||
116 | 116 | function wpinv_get_discount_statuses() { |
117 | 117 | |
118 | 118 | return array( |
119 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
120 | - 'publish' => __( 'Active', 'invoicing' ), |
|
121 | - 'inactive' => __( 'Inactive', 'invoicing' ), |
|
119 | + 'expired' => __('Expired', 'invoicing'), |
|
120 | + 'publish' => __('Active', 'invoicing'), |
|
121 | + 'inactive' => __('Inactive', 'invoicing'), |
|
122 | 122 | ); |
123 | 123 | |
124 | 124 | } |
@@ -126,9 +126,9 @@ discard block |
||
126 | 126 | /** |
127 | 127 | * Retrieves an invoice status label. |
128 | 128 | */ |
129 | -function wpinv_discount_status( $status ) { |
|
129 | +function wpinv_discount_status($status) { |
|
130 | 130 | $statuses = wpinv_get_discount_statuses(); |
131 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : __( 'Inactive', 'invoicing' ); |
|
131 | + return isset($statuses[$status]) ? $statuses[$status] : __('Inactive', 'invoicing'); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | * @param int|array|string|WPInv_Discount $code discount data, object, ID or code. |
139 | 139 | * @return bool |
140 | 140 | */ |
141 | -function wpinv_discount_is_recurring( $discount = 0, $code = 0 ) { |
|
141 | +function wpinv_discount_is_recurring($discount = 0, $code = 0) { |
|
142 | 142 | |
143 | - if ( ! empty( $discount ) ) { |
|
144 | - $discount = wpinv_get_discount_obj( $discount ); |
|
143 | + if (!empty($discount)) { |
|
144 | + $discount = wpinv_get_discount_obj($discount); |
|
145 | 145 | } else { |
146 | - $discount = wpinv_get_discount_obj( $code ); |
|
146 | + $discount = wpinv_get_discount_obj($code); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | return $discount->get_is_recurring(); |
@@ -158,35 +158,35 @@ discard block |
||
158 | 158 | * @param WPInv_Discount $discount |
159 | 159 | * @return array |
160 | 160 | */ |
161 | -function getpaid_calculate_invoice_discount( $invoice, $discount ) { |
|
161 | +function getpaid_calculate_invoice_discount($invoice, $discount) { |
|
162 | 162 | |
163 | 163 | $initial_discount = 0; |
164 | 164 | $recurring_discount = 0; |
165 | 165 | |
166 | - foreach ( $invoice->get_items() as $item ) { |
|
166 | + foreach ($invoice->get_items() as $item) { |
|
167 | 167 | |
168 | 168 | // Abort if it is not valid for this item. |
169 | - if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
169 | + if (!$discount->is_valid_for_items(array($item->get_id()))) { |
|
170 | 170 | continue; |
171 | 171 | } |
172 | 172 | |
173 | 173 | // Calculate the initial amount... |
174 | - $item_discount = $discount->get_discounted_amount( $item->get_sub_total() ); |
|
174 | + $item_discount = $discount->get_discounted_amount($item->get_sub_total()); |
|
175 | 175 | $recurring_item_discount = 0; |
176 | 176 | |
177 | 177 | // ... and maybe the recurring amount. |
178 | - if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
179 | - $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
178 | + if ($item->is_recurring() && $discount->is_recurring()) { |
|
179 | + $recurring_item_discount = $discount->get_discounted_amount($item->get_recurring_sub_total()); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | // Discount should not exceed discounted amount. |
183 | - if ( ! $discount->is_type( 'percent' ) ) { |
|
183 | + if (!$discount->is_type('percent')) { |
|
184 | 184 | |
185 | - if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { |
|
185 | + if (($initial_discount + $item_discount) > $discount->get_amount()) { |
|
186 | 186 | $item_discount = $discount->get_amount() - $initial_discount; |
187 | 187 | } |
188 | 188 | |
189 | - if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { |
|
189 | + if (($recurring_discount + $recurring_item_discount) > $discount->get_amount()) { |
|
190 | 190 | $recurring_item_discount = $discount->get_amount() - $recurring_discount; |
191 | 191 | } |
192 | 192 | } |
@@ -218,10 +218,10 @@ discard block |
||
218 | 218 | array( |
219 | 219 | 'post_type' => 'wpi_discount', |
220 | 220 | 'numberposts' => 1, |
221 | - 'fields' => array( 'ids' ), |
|
221 | + 'fields' => array('ids'), |
|
222 | 222 | ) |
223 | 223 | ); |
224 | 224 | |
225 | - return ! empty( $discounts ); |
|
225 | + return !empty($discounts); |
|
226 | 226 | |
227 | 227 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,55 +10,55 @@ discard block |
||
10 | 10 | class GetPaid_Payment_Form extends GetPaid_Data { |
11 | 11 | |
12 | 12 | /** |
13 | - * Which data store to load. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
13 | + * Which data store to load. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | 17 | protected $data_store_name = 'payment_form'; |
18 | 18 | |
19 | 19 | /** |
20 | - * This is the name of this object type. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $object_type = 'payment_form'; |
|
20 | + * This is the name of this object type. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $object_type = 'payment_form'; |
|
25 | 25 | |
26 | 26 | /** |
27 | - * Form Data array. This is the core form data exposed in APIs. |
|
28 | - * |
|
29 | - * @since 1.0.19 |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $data = array( |
|
33 | - 'status' => 'draft', |
|
34 | - 'version' => '', |
|
35 | - 'date_created' => null, |
|
27 | + * Form Data array. This is the core form data exposed in APIs. |
|
28 | + * |
|
29 | + * @since 1.0.19 |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $data = array( |
|
33 | + 'status' => 'draft', |
|
34 | + 'version' => '', |
|
35 | + 'date_created' => null, |
|
36 | 36 | 'date_modified' => null, |
37 | 37 | 'name' => '', |
38 | 38 | 'author' => 1, |
39 | 39 | 'elements' => null, |
40 | - 'items' => null, |
|
41 | - 'earned' => 0, |
|
42 | - 'refunded' => 0, |
|
43 | - 'cancelled' => 0, |
|
44 | - 'failed' => 0, |
|
45 | - ); |
|
46 | - |
|
47 | - /** |
|
48 | - * Stores meta in cache for future reads. |
|
49 | - * |
|
50 | - * A group must be set to to enable caching. |
|
51 | - * |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - protected $cache_group = 'getpaid_forms'; |
|
55 | - |
|
56 | - /** |
|
57 | - * Stores a reference to the invoice if the form is for an invoice.. |
|
58 | - * |
|
59 | - * @var WPInv_Invoice |
|
60 | - */ |
|
61 | - public $invoice = 0; |
|
40 | + 'items' => null, |
|
41 | + 'earned' => 0, |
|
42 | + 'refunded' => 0, |
|
43 | + 'cancelled' => 0, |
|
44 | + 'failed' => 0, |
|
45 | + ); |
|
46 | + |
|
47 | + /** |
|
48 | + * Stores meta in cache for future reads. |
|
49 | + * |
|
50 | + * A group must be set to to enable caching. |
|
51 | + * |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + protected $cache_group = 'getpaid_forms'; |
|
55 | + |
|
56 | + /** |
|
57 | + * Stores a reference to the invoice if the form is for an invoice.. |
|
58 | + * |
|
59 | + * @var WPInv_Invoice |
|
60 | + */ |
|
61 | + public $invoice = 0; |
|
62 | 62 | |
63 | 63 | /** |
64 | 64 | * Stores a reference to the original WP_Post object |
@@ -68,35 +68,35 @@ discard block |
||
68 | 68 | protected $post = null; |
69 | 69 | |
70 | 70 | /** |
71 | - * Get the form if ID is passed, otherwise the form is new and empty. |
|
72 | - * |
|
73 | - * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
74 | - */ |
|
75 | - public function __construct( $form = 0 ) { |
|
76 | - parent::__construct( $form ); |
|
71 | + * Get the form if ID is passed, otherwise the form is new and empty. |
|
72 | + * |
|
73 | + * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
74 | + */ |
|
75 | + public function __construct( $form = 0 ) { |
|
76 | + parent::__construct( $form ); |
|
77 | 77 | |
78 | - if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | - $this->set_id( $form ); |
|
80 | - } elseif ( $form instanceof self ) { |
|
78 | + if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | + $this->set_id( $form ); |
|
80 | + } elseif ( $form instanceof self ) { |
|
81 | 81 | |
82 | - $this->set_id( $form->get_id() ); |
|
83 | - $this->invoice = $form->invoice; |
|
82 | + $this->set_id( $form->get_id() ); |
|
83 | + $this->invoice = $form->invoice; |
|
84 | 84 | |
85 | - } elseif ( ! empty( $form->ID ) ) { |
|
86 | - $this->set_id( $form->ID ); |
|
87 | - } else { |
|
88 | - $this->set_object_read( true ); |
|
89 | - } |
|
85 | + } elseif ( ! empty( $form->ID ) ) { |
|
86 | + $this->set_id( $form->ID ); |
|
87 | + } else { |
|
88 | + $this->set_object_read( true ); |
|
89 | + } |
|
90 | 90 | |
91 | 91 | // Load the datastore. |
92 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
92 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
93 | 93 | |
94 | - if ( $this->get_id() > 0 ) { |
|
94 | + if ( $this->get_id() > 0 ) { |
|
95 | 95 | $this->post = get_post( $this->get_id() ); |
96 | - $this->data_store->read( $this ); |
|
96 | + $this->data_store->read( $this ); |
|
97 | 97 | } |
98 | 98 | |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | 101 | /* |
102 | 102 | |-------------------------------------------------------------------------- |
@@ -114,356 +114,356 @@ discard block |
||
114 | 114 | */ |
115 | 115 | |
116 | 116 | /** |
117 | - * Get plugin version when the form was created. |
|
118 | - * |
|
119 | - * @since 1.0.19 |
|
120 | - * @param string $context View or edit context. |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function get_version( $context = 'view' ) { |
|
124 | - return $this->get_prop( 'version', $context ); |
|
117 | + * Get plugin version when the form was created. |
|
118 | + * |
|
119 | + * @since 1.0.19 |
|
120 | + * @param string $context View or edit context. |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function get_version( $context = 'view' ) { |
|
124 | + return $this->get_prop( 'version', $context ); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | - * Get date when the form was created. |
|
129 | - * |
|
130 | - * @since 1.0.19 |
|
131 | - * @param string $context View or edit context. |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - public function get_date_created( $context = 'view' ) { |
|
135 | - return $this->get_prop( 'date_created', $context ); |
|
128 | + * Get date when the form was created. |
|
129 | + * |
|
130 | + * @since 1.0.19 |
|
131 | + * @param string $context View or edit context. |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + public function get_date_created( $context = 'view' ) { |
|
135 | + return $this->get_prop( 'date_created', $context ); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | - * Get GMT date when the form was created. |
|
140 | - * |
|
141 | - * @since 1.0.19 |
|
142 | - * @param string $context View or edit context. |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - public function get_date_created_gmt( $context = 'view' ) { |
|
139 | + * Get GMT date when the form was created. |
|
140 | + * |
|
141 | + * @since 1.0.19 |
|
142 | + * @param string $context View or edit context. |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + public function get_date_created_gmt( $context = 'view' ) { |
|
146 | 146 | $date = $this->get_date_created( $context ); |
147 | 147 | |
148 | 148 | if ( $date ) { |
149 | 149 | $date = get_gmt_from_date( $date ); |
150 | 150 | } |
151 | - return $date; |
|
151 | + return $date; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
155 | - * Get date when the form was last modified. |
|
156 | - * |
|
157 | - * @since 1.0.19 |
|
158 | - * @param string $context View or edit context. |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - public function get_date_modified( $context = 'view' ) { |
|
162 | - return $this->get_prop( 'date_modified', $context ); |
|
155 | + * Get date when the form was last modified. |
|
156 | + * |
|
157 | + * @since 1.0.19 |
|
158 | + * @param string $context View or edit context. |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + public function get_date_modified( $context = 'view' ) { |
|
162 | + return $this->get_prop( 'date_modified', $context ); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
166 | - * Get GMT date when the form was last modified. |
|
167 | - * |
|
168 | - * @since 1.0.19 |
|
169 | - * @param string $context View or edit context. |
|
170 | - * @return string |
|
171 | - */ |
|
172 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
166 | + * Get GMT date when the form was last modified. |
|
167 | + * |
|
168 | + * @since 1.0.19 |
|
169 | + * @param string $context View or edit context. |
|
170 | + * @return string |
|
171 | + */ |
|
172 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
173 | 173 | $date = $this->get_date_modified( $context ); |
174 | 174 | |
175 | 175 | if ( $date ) { |
176 | 176 | $date = get_gmt_from_date( $date ); |
177 | 177 | } |
178 | - return $date; |
|
178 | + return $date; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
182 | - * Get the form name. |
|
183 | - * |
|
184 | - * @since 1.0.19 |
|
185 | - * @param string $context View or edit context. |
|
186 | - * @return string |
|
187 | - */ |
|
188 | - public function get_name( $context = 'view' ) { |
|
189 | - return $this->get_prop( 'name', $context ); |
|
182 | + * Get the form name. |
|
183 | + * |
|
184 | + * @since 1.0.19 |
|
185 | + * @param string $context View or edit context. |
|
186 | + * @return string |
|
187 | + */ |
|
188 | + public function get_name( $context = 'view' ) { |
|
189 | + return $this->get_prop( 'name', $context ); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
193 | - * Alias of self::get_name(). |
|
194 | - * |
|
195 | - * @since 1.0.19 |
|
196 | - * @param string $context View or edit context. |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - public function get_title( $context = 'view' ) { |
|
200 | - return $this->get_name( $context ); |
|
201 | - } |
|
193 | + * Alias of self::get_name(). |
|
194 | + * |
|
195 | + * @since 1.0.19 |
|
196 | + * @param string $context View or edit context. |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + public function get_title( $context = 'view' ) { |
|
200 | + return $this->get_name( $context ); |
|
201 | + } |
|
202 | 202 | |
203 | 203 | /** |
204 | - * Get the owner of the form. |
|
205 | - * |
|
206 | - * @since 1.0.19 |
|
207 | - * @param string $context View or edit context. |
|
208 | - * @return int |
|
209 | - */ |
|
210 | - public function get_author( $context = 'view' ) { |
|
211 | - return (int) $this->get_prop( 'author', $context ); |
|
204 | + * Get the owner of the form. |
|
205 | + * |
|
206 | + * @since 1.0.19 |
|
207 | + * @param string $context View or edit context. |
|
208 | + * @return int |
|
209 | + */ |
|
210 | + public function get_author( $context = 'view' ) { |
|
211 | + return (int) $this->get_prop( 'author', $context ); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
215 | - * Get the elements that make up the form. |
|
216 | - * |
|
217 | - * @since 1.0.19 |
|
218 | - * @param string $context View or edit context. |
|
219 | - * @return array |
|
220 | - */ |
|
221 | - public function get_elements( $context = 'view' ) { |
|
222 | - $elements = $this->get_prop( 'elements', $context ); |
|
215 | + * Get the elements that make up the form. |
|
216 | + * |
|
217 | + * @since 1.0.19 |
|
218 | + * @param string $context View or edit context. |
|
219 | + * @return array |
|
220 | + */ |
|
221 | + public function get_elements( $context = 'view' ) { |
|
222 | + $elements = $this->get_prop( 'elements', $context ); |
|
223 | 223 | |
224 | - if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
224 | + if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
225 | 225 | return wpinv_get_data( 'sample-payment-form' ); |
226 | - } |
|
226 | + } |
|
227 | 227 | |
228 | - // Ensure that all required elements exist. |
|
229 | - $_elements = array(); |
|
230 | - foreach ( $elements as $element ) { |
|
228 | + // Ensure that all required elements exist. |
|
229 | + $_elements = array(); |
|
230 | + foreach ( $elements as $element ) { |
|
231 | 231 | |
232 | - if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
232 | + if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
233 | 233 | |
234 | - $_elements[] = array( |
|
235 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
236 | - 'id' => 'gtscicd', |
|
237 | - 'name' => 'gtscicd', |
|
238 | - 'type' => 'gateway_select', |
|
239 | - 'premade' => true, |
|
234 | + $_elements[] = array( |
|
235 | + 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
236 | + 'id' => 'gtscicd', |
|
237 | + 'name' => 'gtscicd', |
|
238 | + 'type' => 'gateway_select', |
|
239 | + 'premade' => true, |
|
240 | 240 | |
241 | - ); |
|
241 | + ); |
|
242 | 242 | |
243 | - } |
|
243 | + } |
|
244 | 244 | |
245 | - $_elements[] = $element; |
|
245 | + $_elements[] = $element; |
|
246 | 246 | |
247 | - } |
|
247 | + } |
|
248 | 248 | |
249 | 249 | return $_elements; |
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * Get the items sold via the form. |
|
254 | - * |
|
255 | - * @since 1.0.19 |
|
256 | - * @param string $context View or edit context. |
|
257 | - * @param string $return objects or arrays. |
|
258 | - * @return GetPaid_Form_Item[] |
|
259 | - */ |
|
260 | - public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | - $items = $this->get_prop( 'items', $context ); |
|
262 | - |
|
263 | - if ( empty( $items ) || ! is_array( $items ) ) { |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Get the items sold via the form. |
|
254 | + * |
|
255 | + * @since 1.0.19 |
|
256 | + * @param string $context View or edit context. |
|
257 | + * @param string $return objects or arrays. |
|
258 | + * @return GetPaid_Form_Item[] |
|
259 | + */ |
|
260 | + public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | + $items = $this->get_prop( 'items', $context ); |
|
262 | + |
|
263 | + if ( empty( $items ) || ! is_array( $items ) ) { |
|
264 | 264 | $items = wpinv_get_data( 'sample-payment-form-items' ); |
265 | - } |
|
265 | + } |
|
266 | + |
|
267 | + // Convert the items. |
|
268 | + $prepared = array(); |
|
269 | + |
|
270 | + foreach ( $items as $key => $value ) { |
|
271 | + |
|
272 | + // Form items. |
|
273 | + if ( $value instanceof GetPaid_Form_Item ) { |
|
274 | + |
|
275 | + if ( $value->can_purchase() ) { |
|
276 | + $prepared[] = $value; |
|
277 | + } |
|
266 | 278 | |
267 | - // Convert the items. |
|
268 | - $prepared = array(); |
|
279 | + continue; |
|
269 | 280 | |
270 | - foreach ( $items as $key => $value ) { |
|
281 | + } |
|
271 | 282 | |
272 | - // Form items. |
|
273 | - if ( $value instanceof GetPaid_Form_Item ) { |
|
283 | + // $item_id => $quantity (buy buttons) |
|
284 | + if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | + $item = new GetPaid_Form_Item( $key ); |
|
274 | 286 | |
275 | - if ( $value->can_purchase() ) { |
|
276 | - $prepared[] = $value; |
|
277 | - } |
|
287 | + if ( $item->can_purchase() ) { |
|
278 | 288 | |
279 | - continue; |
|
289 | + $value = (float) $value; |
|
290 | + $item->set_quantity( $value ); |
|
291 | + if ( 0 == $value ) { |
|
292 | + $item->set_quantity( 1 ); |
|
293 | + $item->set_allow_quantities( true ); |
|
294 | + } |
|
280 | 295 | |
281 | - } |
|
296 | + $prepared[] = $item; |
|
297 | + } |
|
282 | 298 | |
283 | - // $item_id => $quantity (buy buttons) |
|
284 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | - $item = new GetPaid_Form_Item( $key ); |
|
299 | + continue; |
|
300 | + } |
|
286 | 301 | |
287 | - if ( $item->can_purchase() ) { |
|
302 | + // Items saved via payment forms editor. |
|
303 | + if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
288 | 304 | |
289 | - $value = (float) $value; |
|
290 | - $item->set_quantity( $value ); |
|
291 | - if ( 0 == $value ) { |
|
292 | - $item->set_quantity( 1 ); |
|
293 | - $item->set_allow_quantities( true ); |
|
294 | - } |
|
305 | + $item = new GetPaid_Form_Item( $value['id'] ); |
|
295 | 306 | |
296 | - $prepared[] = $item; |
|
297 | - } |
|
307 | + if ( ! $item->can_purchase() ) { |
|
308 | + continue; |
|
309 | + } |
|
298 | 310 | |
299 | - continue; |
|
300 | - } |
|
311 | + // Sub-total (Cart items). |
|
312 | + if ( isset( $value['subtotal'] ) ) { |
|
313 | + $item->set_price( $value['subtotal'] ); |
|
314 | + } |
|
301 | 315 | |
302 | - // Items saved via payment forms editor. |
|
303 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
316 | + if ( isset( $value['quantity'] ) ) { |
|
317 | + $item->set_quantity( $value['quantity'] ); |
|
318 | + } |
|
304 | 319 | |
305 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
320 | + if ( isset( $value['allow_quantities'] ) ) { |
|
321 | + $item->set_allow_quantities( $value['allow_quantities'] ); |
|
322 | + } |
|
306 | 323 | |
307 | - if ( ! $item->can_purchase() ) { |
|
308 | - continue; |
|
309 | - } |
|
324 | + if ( isset( $value['required'] ) ) { |
|
325 | + $item->set_is_required( $value['required'] ); |
|
326 | + } |
|
310 | 327 | |
311 | - // Sub-total (Cart items). |
|
312 | - if ( isset( $value['subtotal'] ) ) { |
|
313 | - $item->set_price( $value['subtotal'] ); |
|
314 | - } |
|
328 | + if ( isset( $value['description'] ) ) { |
|
329 | + $item->set_custom_description( $value['description'] ); |
|
330 | + } |
|
315 | 331 | |
316 | - if ( isset( $value['quantity'] ) ) { |
|
317 | - $item->set_quantity( $value['quantity'] ); |
|
318 | - } |
|
332 | + $prepared[] = $item; |
|
333 | + continue; |
|
319 | 334 | |
320 | - if ( isset( $value['allow_quantities'] ) ) { |
|
321 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
322 | - } |
|
335 | + } |
|
323 | 336 | |
324 | - if ( isset( $value['required'] ) ) { |
|
325 | - $item->set_is_required( $value['required'] ); |
|
326 | - } |
|
337 | + // $item_id => array( 'price' => 10 ) (item variations) |
|
338 | + if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | + $item = new GetPaid_Form_Item( $key ); |
|
327 | 340 | |
328 | - if ( isset( $value['description'] ) ) { |
|
329 | - $item->set_custom_description( $value['description'] ); |
|
330 | - } |
|
341 | + if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | + $item->set_price( $value['price'] ); |
|
343 | + } |
|
331 | 344 | |
332 | - $prepared[] = $item; |
|
333 | - continue; |
|
345 | + if ( $item->can_purchase() ) { |
|
346 | + $prepared[] = $item; |
|
347 | + } |
|
334 | 348 | |
335 | - } |
|
336 | - |
|
337 | - // $item_id => array( 'price' => 10 ) (item variations) |
|
338 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | - $item = new GetPaid_Form_Item( $key ); |
|
340 | - |
|
341 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | - $item->set_price( $value['price'] ); |
|
343 | - } |
|
344 | - |
|
345 | - if ( $item->can_purchase() ) { |
|
346 | - $prepared[] = $item; |
|
347 | - } |
|
348 | - |
|
349 | - continue; |
|
350 | - } |
|
351 | - } |
|
352 | - |
|
353 | - if ( 'objects' == $return && 'view' == $context ) { |
|
354 | - return $prepared; |
|
355 | - } |
|
356 | - |
|
357 | - $items = array(); |
|
358 | - foreach ( $prepared as $item ) { |
|
359 | - $items[] = $item->prepare_data_for_use(); |
|
360 | - } |
|
361 | - |
|
362 | - return $items; |
|
363 | - } |
|
364 | - |
|
365 | - /** |
|
366 | - * Get a single item belonging to the form. |
|
367 | - * |
|
368 | - * @since 1.0.19 |
|
369 | - * @param int $item_id The item id to return. |
|
370 | - * @return GetPaid_Form_Item|bool |
|
371 | - */ |
|
372 | - public function get_item( $item_id ) { |
|
373 | - |
|
374 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
375 | - return false; |
|
376 | - } |
|
377 | - |
|
378 | - foreach ( $this->get_items() as $item ) { |
|
379 | - if ( $item->get_id() == (int) $item_id ) { |
|
380 | - return $item; |
|
381 | - } |
|
382 | - } |
|
383 | - |
|
384 | - return false; |
|
385 | - |
|
386 | - } |
|
387 | - |
|
388 | - /** |
|
389 | - * Gets a single element. |
|
390 | - * |
|
391 | - * @since 1.0.19 |
|
392 | - * @param string $element_type The element type to return. |
|
393 | - * @return array|bool |
|
394 | - */ |
|
395 | - public function get_element_type( $element_type ) { |
|
396 | - |
|
397 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
398 | - return false; |
|
399 | - } |
|
400 | - |
|
401 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
402 | - |
|
403 | - if ( $element['type'] === $element_type ) { |
|
404 | - return $element; |
|
405 | - } |
|
406 | - } |
|
407 | - |
|
408 | - return false; |
|
409 | - |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * Get the total amount earned via this form. |
|
414 | - * |
|
415 | - * @since 1.0.19 |
|
416 | - * @param string $context View or edit context. |
|
417 | - * @return float |
|
418 | - */ |
|
419 | - public function get_earned( $context = 'view' ) { |
|
420 | - return $this->get_prop( 'earned', $context ); |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * Get the total amount refunded via this form. |
|
425 | - * |
|
426 | - * @since 1.0.19 |
|
427 | - * @param string $context View or edit context. |
|
428 | - * @return float |
|
429 | - */ |
|
430 | - public function get_refunded( $context = 'view' ) { |
|
431 | - return $this->get_prop( 'refunded', $context ); |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * Get the total amount cancelled via this form. |
|
436 | - * |
|
437 | - * @since 1.0.19 |
|
438 | - * @param string $context View or edit context. |
|
439 | - * @return float |
|
440 | - */ |
|
441 | - public function get_cancelled( $context = 'view' ) { |
|
442 | - return $this->get_prop( 'cancelled', $context ); |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * Get the total amount failed via this form. |
|
447 | - * |
|
448 | - * @since 1.0.19 |
|
449 | - * @param string $context View or edit context. |
|
450 | - * @return float |
|
451 | - */ |
|
452 | - public function get_failed( $context = 'view' ) { |
|
453 | - return $this->get_prop( 'failed', $context ); |
|
454 | - } |
|
455 | - |
|
456 | - /** |
|
457 | - * Get the currency. |
|
458 | - * |
|
459 | - * @since 1.0.19 |
|
460 | - * @param string $context View or edit context. |
|
461 | - * @return string |
|
462 | - */ |
|
463 | - public function get_currency() { |
|
464 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
465 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
466 | - } |
|
349 | + continue; |
|
350 | + } |
|
351 | + } |
|
352 | + |
|
353 | + if ( 'objects' == $return && 'view' == $context ) { |
|
354 | + return $prepared; |
|
355 | + } |
|
356 | + |
|
357 | + $items = array(); |
|
358 | + foreach ( $prepared as $item ) { |
|
359 | + $items[] = $item->prepare_data_for_use(); |
|
360 | + } |
|
361 | + |
|
362 | + return $items; |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * Get a single item belonging to the form. |
|
367 | + * |
|
368 | + * @since 1.0.19 |
|
369 | + * @param int $item_id The item id to return. |
|
370 | + * @return GetPaid_Form_Item|bool |
|
371 | + */ |
|
372 | + public function get_item( $item_id ) { |
|
373 | + |
|
374 | + if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
375 | + return false; |
|
376 | + } |
|
377 | + |
|
378 | + foreach ( $this->get_items() as $item ) { |
|
379 | + if ( $item->get_id() == (int) $item_id ) { |
|
380 | + return $item; |
|
381 | + } |
|
382 | + } |
|
383 | + |
|
384 | + return false; |
|
385 | + |
|
386 | + } |
|
387 | + |
|
388 | + /** |
|
389 | + * Gets a single element. |
|
390 | + * |
|
391 | + * @since 1.0.19 |
|
392 | + * @param string $element_type The element type to return. |
|
393 | + * @return array|bool |
|
394 | + */ |
|
395 | + public function get_element_type( $element_type ) { |
|
396 | + |
|
397 | + if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
398 | + return false; |
|
399 | + } |
|
400 | + |
|
401 | + foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
402 | + |
|
403 | + if ( $element['type'] === $element_type ) { |
|
404 | + return $element; |
|
405 | + } |
|
406 | + } |
|
407 | + |
|
408 | + return false; |
|
409 | + |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * Get the total amount earned via this form. |
|
414 | + * |
|
415 | + * @since 1.0.19 |
|
416 | + * @param string $context View or edit context. |
|
417 | + * @return float |
|
418 | + */ |
|
419 | + public function get_earned( $context = 'view' ) { |
|
420 | + return $this->get_prop( 'earned', $context ); |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * Get the total amount refunded via this form. |
|
425 | + * |
|
426 | + * @since 1.0.19 |
|
427 | + * @param string $context View or edit context. |
|
428 | + * @return float |
|
429 | + */ |
|
430 | + public function get_refunded( $context = 'view' ) { |
|
431 | + return $this->get_prop( 'refunded', $context ); |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * Get the total amount cancelled via this form. |
|
436 | + * |
|
437 | + * @since 1.0.19 |
|
438 | + * @param string $context View or edit context. |
|
439 | + * @return float |
|
440 | + */ |
|
441 | + public function get_cancelled( $context = 'view' ) { |
|
442 | + return $this->get_prop( 'cancelled', $context ); |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * Get the total amount failed via this form. |
|
447 | + * |
|
448 | + * @since 1.0.19 |
|
449 | + * @param string $context View or edit context. |
|
450 | + * @return float |
|
451 | + */ |
|
452 | + public function get_failed( $context = 'view' ) { |
|
453 | + return $this->get_prop( 'failed', $context ); |
|
454 | + } |
|
455 | + |
|
456 | + /** |
|
457 | + * Get the currency. |
|
458 | + * |
|
459 | + * @since 1.0.19 |
|
460 | + * @param string $context View or edit context. |
|
461 | + * @return string |
|
462 | + */ |
|
463 | + public function get_currency() { |
|
464 | + $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
465 | + return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
466 | + } |
|
467 | 467 | |
468 | 468 | /* |
469 | 469 | |-------------------------------------------------------------------------- |
@@ -476,22 +476,22 @@ discard block |
||
476 | 476 | */ |
477 | 477 | |
478 | 478 | /** |
479 | - * Set plugin version when the item was created. |
|
480 | - * |
|
481 | - * @since 1.0.19 |
|
482 | - */ |
|
483 | - public function set_version( $value ) { |
|
484 | - $this->set_prop( 'version', $value ); |
|
479 | + * Set plugin version when the item was created. |
|
480 | + * |
|
481 | + * @since 1.0.19 |
|
482 | + */ |
|
483 | + public function set_version( $value ) { |
|
484 | + $this->set_prop( 'version', $value ); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
488 | - * Set date when the item was created. |
|
489 | - * |
|
490 | - * @since 1.0.19 |
|
491 | - * @param string $value Value to set. |
|
488 | + * Set date when the item was created. |
|
489 | + * |
|
490 | + * @since 1.0.19 |
|
491 | + * @param string $value Value to set. |
|
492 | 492 | * @return bool Whether or not the date was set. |
493 | - */ |
|
494 | - public function set_date_created( $value ) { |
|
493 | + */ |
|
494 | + public function set_date_created( $value ) { |
|
495 | 495 | $date = strtotime( $value ); |
496 | 496 | |
497 | 497 | if ( $date ) { |
@@ -504,13 +504,13 @@ discard block |
||
504 | 504 | } |
505 | 505 | |
506 | 506 | /** |
507 | - * Set date when the item was last modified. |
|
508 | - * |
|
509 | - * @since 1.0.19 |
|
510 | - * @param string $value Value to set. |
|
507 | + * Set date when the item was last modified. |
|
508 | + * |
|
509 | + * @since 1.0.19 |
|
510 | + * @param string $value Value to set. |
|
511 | 511 | * @return bool Whether or not the date was set. |
512 | - */ |
|
513 | - public function set_date_modified( $value ) { |
|
512 | + */ |
|
513 | + public function set_date_modified( $value ) { |
|
514 | 514 | $date = strtotime( $value ); |
515 | 515 | |
516 | 516 | if ( $date ) { |
@@ -523,164 +523,164 @@ discard block |
||
523 | 523 | } |
524 | 524 | |
525 | 525 | /** |
526 | - * Set the item name. |
|
527 | - * |
|
528 | - * @since 1.0.19 |
|
529 | - * @param string $value New name. |
|
530 | - */ |
|
531 | - public function set_name( $value ) { |
|
532 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
533 | - } |
|
534 | - |
|
535 | - /** |
|
536 | - * Alias of self::set_name(). |
|
537 | - * |
|
538 | - * @since 1.0.19 |
|
539 | - * @param string $value New name. |
|
540 | - */ |
|
541 | - public function set_title( $value ) { |
|
542 | - $this->set_name( $value ); |
|
543 | - } |
|
544 | - |
|
545 | - /** |
|
546 | - * Set the owner of the item. |
|
547 | - * |
|
548 | - * @since 1.0.19 |
|
549 | - * @param int $value New author. |
|
550 | - */ |
|
551 | - public function set_author( $value ) { |
|
552 | - $this->set_prop( 'author', (int) $value ); |
|
553 | - } |
|
554 | - |
|
555 | - /** |
|
556 | - * Set the form elements. |
|
557 | - * |
|
558 | - * @since 1.0.19 |
|
559 | - * @sinve 2.3.4 Array values sanitized. |
|
560 | - * @param array $value Form elements. |
|
561 | - */ |
|
562 | - public function set_elements( $value ) { |
|
563 | - if ( is_array( $value ) ) { |
|
564 | - $this->set_prop( 'elements', wp_kses_post_deep( $value ) ); |
|
565 | - } |
|
566 | - } |
|
567 | - |
|
568 | - /** |
|
569 | - * Sanitize array values. |
|
570 | - * |
|
571 | - * @param $value |
|
572 | - * |
|
573 | - * @return mixed |
|
574 | - */ |
|
575 | - public function sanitize_array_values( $value ) { |
|
576 | - |
|
577 | - // sanitize |
|
578 | - if ( ! empty( $value ) ) { |
|
579 | - |
|
580 | - foreach ( $value as $key => $val_arr ) { |
|
581 | - |
|
582 | - if ( is_array( $val_arr ) ) { |
|
583 | - // check if we have sub array items. |
|
584 | - $sub_arr = array(); |
|
585 | - foreach ( $val_arr as $key2 => $val2 ) { |
|
586 | - if ( is_array( $val2 ) ) { |
|
587 | - $sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 ); |
|
588 | - unset( $val_arr[ $key ][ $key2 ] ); |
|
589 | - } |
|
590 | - } |
|
591 | - |
|
592 | - // we allow some html in description so we sanitize it separately. |
|
593 | - $help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : ''; |
|
594 | - |
|
595 | - // sanitize array elements |
|
596 | - $value[ $key ] = array_map( 'sanitize_text_field', $val_arr ); |
|
597 | - |
|
598 | - // add back the description if set |
|
599 | - if ( isset( $val_arr['description'] ) ) { |
|
526 | + * Set the item name. |
|
527 | + * |
|
528 | + * @since 1.0.19 |
|
529 | + * @param string $value New name. |
|
530 | + */ |
|
531 | + public function set_name( $value ) { |
|
532 | + $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
533 | + } |
|
534 | + |
|
535 | + /** |
|
536 | + * Alias of self::set_name(). |
|
537 | + * |
|
538 | + * @since 1.0.19 |
|
539 | + * @param string $value New name. |
|
540 | + */ |
|
541 | + public function set_title( $value ) { |
|
542 | + $this->set_name( $value ); |
|
543 | + } |
|
544 | + |
|
545 | + /** |
|
546 | + * Set the owner of the item. |
|
547 | + * |
|
548 | + * @since 1.0.19 |
|
549 | + * @param int $value New author. |
|
550 | + */ |
|
551 | + public function set_author( $value ) { |
|
552 | + $this->set_prop( 'author', (int) $value ); |
|
553 | + } |
|
554 | + |
|
555 | + /** |
|
556 | + * Set the form elements. |
|
557 | + * |
|
558 | + * @since 1.0.19 |
|
559 | + * @sinve 2.3.4 Array values sanitized. |
|
560 | + * @param array $value Form elements. |
|
561 | + */ |
|
562 | + public function set_elements( $value ) { |
|
563 | + if ( is_array( $value ) ) { |
|
564 | + $this->set_prop( 'elements', wp_kses_post_deep( $value ) ); |
|
565 | + } |
|
566 | + } |
|
567 | + |
|
568 | + /** |
|
569 | + * Sanitize array values. |
|
570 | + * |
|
571 | + * @param $value |
|
572 | + * |
|
573 | + * @return mixed |
|
574 | + */ |
|
575 | + public function sanitize_array_values( $value ) { |
|
576 | + |
|
577 | + // sanitize |
|
578 | + if ( ! empty( $value ) ) { |
|
579 | + |
|
580 | + foreach ( $value as $key => $val_arr ) { |
|
581 | + |
|
582 | + if ( is_array( $val_arr ) ) { |
|
583 | + // check if we have sub array items. |
|
584 | + $sub_arr = array(); |
|
585 | + foreach ( $val_arr as $key2 => $val2 ) { |
|
586 | + if ( is_array( $val2 ) ) { |
|
587 | + $sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 ); |
|
588 | + unset( $val_arr[ $key ][ $key2 ] ); |
|
589 | + } |
|
590 | + } |
|
591 | + |
|
592 | + // we allow some html in description so we sanitize it separately. |
|
593 | + $help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : ''; |
|
594 | + |
|
595 | + // sanitize array elements |
|
596 | + $value[ $key ] = array_map( 'sanitize_text_field', $val_arr ); |
|
597 | + |
|
598 | + // add back the description if set |
|
599 | + if ( isset( $val_arr['description'] ) ) { |
|
600 | 600 | $value[ $key ]['description'] = $help_text;} |
601 | 601 | |
602 | - // add back sub array items after its been sanitized. |
|
603 | - if ( ! empty( $sub_arr ) ) { |
|
604 | - $value[ $key ] = array_merge( $value[ $key ], $sub_arr ); |
|
605 | - } |
|
606 | - } |
|
602 | + // add back sub array items after its been sanitized. |
|
603 | + if ( ! empty( $sub_arr ) ) { |
|
604 | + $value[ $key ] = array_merge( $value[ $key ], $sub_arr ); |
|
605 | + } |
|
606 | + } |
|
607 | 607 | } |
608 | 608 | } |
609 | 609 | |
610 | - return $value; |
|
611 | - } |
|
612 | - |
|
613 | - /** |
|
614 | - * Set the form items. |
|
615 | - * |
|
616 | - * @since 1.0.19 |
|
617 | - * @param array $value Form elements. |
|
618 | - */ |
|
619 | - public function set_items( $value ) { |
|
620 | - if ( is_array( $value ) ) { |
|
621 | - $this->set_prop( 'items', $value ); |
|
622 | - } |
|
623 | - } |
|
624 | - |
|
625 | - /** |
|
626 | - * Set the total amount earned via this form. |
|
627 | - * |
|
628 | - * @since 1.0.19 |
|
629 | - * @param float $value Amount earned. |
|
630 | - */ |
|
631 | - public function set_earned( $value ) { |
|
632 | - $value = max( (float) $value, 0 ); |
|
633 | - $this->set_prop( 'earned', $value ); |
|
634 | - } |
|
635 | - |
|
636 | - /** |
|
637 | - * Set the total amount refunded via this form. |
|
638 | - * |
|
639 | - * @since 1.0.19 |
|
640 | - * @param float $value Amount refunded. |
|
641 | - */ |
|
642 | - public function set_refunded( $value ) { |
|
643 | - $value = max( (float) $value, 0 ); |
|
644 | - $this->set_prop( 'refunded', $value ); |
|
645 | - } |
|
646 | - |
|
647 | - /** |
|
648 | - * Set the total amount cancelled via this form. |
|
649 | - * |
|
650 | - * @since 1.0.19 |
|
651 | - * @param float $value Amount cancelled. |
|
652 | - */ |
|
653 | - public function set_cancelled( $value ) { |
|
654 | - $value = max( (float) $value, 0 ); |
|
655 | - $this->set_prop( 'cancelled', $value ); |
|
656 | - } |
|
657 | - |
|
658 | - /** |
|
659 | - * Set the total amount failed via this form. |
|
660 | - * |
|
661 | - * @since 1.0.19 |
|
662 | - * @param float $value Amount cancelled. |
|
663 | - */ |
|
664 | - public function set_failed( $value ) { |
|
665 | - $value = max( (float) $value, 0 ); |
|
666 | - $this->set_prop( 'failed', $value ); |
|
667 | - } |
|
610 | + return $value; |
|
611 | + } |
|
612 | + |
|
613 | + /** |
|
614 | + * Set the form items. |
|
615 | + * |
|
616 | + * @since 1.0.19 |
|
617 | + * @param array $value Form elements. |
|
618 | + */ |
|
619 | + public function set_items( $value ) { |
|
620 | + if ( is_array( $value ) ) { |
|
621 | + $this->set_prop( 'items', $value ); |
|
622 | + } |
|
623 | + } |
|
624 | + |
|
625 | + /** |
|
626 | + * Set the total amount earned via this form. |
|
627 | + * |
|
628 | + * @since 1.0.19 |
|
629 | + * @param float $value Amount earned. |
|
630 | + */ |
|
631 | + public function set_earned( $value ) { |
|
632 | + $value = max( (float) $value, 0 ); |
|
633 | + $this->set_prop( 'earned', $value ); |
|
634 | + } |
|
635 | + |
|
636 | + /** |
|
637 | + * Set the total amount refunded via this form. |
|
638 | + * |
|
639 | + * @since 1.0.19 |
|
640 | + * @param float $value Amount refunded. |
|
641 | + */ |
|
642 | + public function set_refunded( $value ) { |
|
643 | + $value = max( (float) $value, 0 ); |
|
644 | + $this->set_prop( 'refunded', $value ); |
|
645 | + } |
|
646 | + |
|
647 | + /** |
|
648 | + * Set the total amount cancelled via this form. |
|
649 | + * |
|
650 | + * @since 1.0.19 |
|
651 | + * @param float $value Amount cancelled. |
|
652 | + */ |
|
653 | + public function set_cancelled( $value ) { |
|
654 | + $value = max( (float) $value, 0 ); |
|
655 | + $this->set_prop( 'cancelled', $value ); |
|
656 | + } |
|
657 | + |
|
658 | + /** |
|
659 | + * Set the total amount failed via this form. |
|
660 | + * |
|
661 | + * @since 1.0.19 |
|
662 | + * @param float $value Amount cancelled. |
|
663 | + */ |
|
664 | + public function set_failed( $value ) { |
|
665 | + $value = max( (float) $value, 0 ); |
|
666 | + $this->set_prop( 'failed', $value ); |
|
667 | + } |
|
668 | 668 | |
669 | 669 | /** |
670 | 670 | * Create an item. For backwards compatibilty. |
671 | 671 | * |
672 | 672 | * @deprecated |
673 | - * @return int item id |
|
673 | + * @return int item id |
|
674 | 674 | */ |
675 | 675 | public function create( $data = array() ) { |
676 | 676 | |
677 | - // Set the properties. |
|
678 | - if ( is_array( $data ) ) { |
|
679 | - $this->set_props( $data ); |
|
680 | - } |
|
677 | + // Set the properties. |
|
678 | + if ( is_array( $data ) ) { |
|
679 | + $this->set_props( $data ); |
|
680 | + } |
|
681 | 681 | |
682 | - // Save the item. |
|
683 | - return $this->save(); |
|
682 | + // Save the item. |
|
683 | + return $this->save(); |
|
684 | 684 | |
685 | 685 | } |
686 | 686 | |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | * Updates an item. For backwards compatibilty. |
689 | 689 | * |
690 | 690 | * @deprecated |
691 | - * @return int item id |
|
691 | + * @return int item id |
|
692 | 692 | */ |
693 | 693 | public function update( $data = array() ) { |
694 | 694 | return $this->create( $data ); |
@@ -704,22 +704,22 @@ discard block |
||
704 | 704 | */ |
705 | 705 | |
706 | 706 | /** |
707 | - * Checks whether this is the default payment form. |
|
708 | - * |
|
709 | - * @since 1.0.19 |
|
710 | - * @return bool |
|
711 | - */ |
|
707 | + * Checks whether this is the default payment form. |
|
708 | + * |
|
709 | + * @since 1.0.19 |
|
710 | + * @return bool |
|
711 | + */ |
|
712 | 712 | public function is_default() { |
713 | 713 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
714 | 714 | return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
715 | - } |
|
715 | + } |
|
716 | 716 | |
717 | 717 | /** |
718 | - * Checks whether the form is active. |
|
719 | - * |
|
720 | - * @since 1.0.19 |
|
721 | - * @return bool |
|
722 | - */ |
|
718 | + * Checks whether the form is active. |
|
719 | + * |
|
720 | + * @since 1.0.19 |
|
721 | + * @return bool |
|
722 | + */ |
|
723 | 723 | public function is_active() { |
724 | 724 | $is_active = 0 !== (int) $this->get_id(); |
725 | 725 | |
@@ -728,81 +728,81 @@ discard block |
||
728 | 728 | } |
729 | 729 | |
730 | 730 | return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
731 | - } |
|
732 | - |
|
733 | - /** |
|
734 | - * Checks whether the form has a given item. |
|
735 | - * |
|
736 | - * @since 1.0.19 |
|
737 | - * @return bool |
|
738 | - */ |
|
731 | + } |
|
732 | + |
|
733 | + /** |
|
734 | + * Checks whether the form has a given item. |
|
735 | + * |
|
736 | + * @since 1.0.19 |
|
737 | + * @return bool |
|
738 | + */ |
|
739 | 739 | public function has_item( $item_id ) { |
740 | 740 | return false !== $this->get_item( $item_id ); |
741 | - } |
|
742 | - |
|
743 | - /** |
|
744 | - * Checks whether the form has a given element. |
|
745 | - * |
|
746 | - * @since 1.0.19 |
|
747 | - * @return bool |
|
748 | - */ |
|
741 | + } |
|
742 | + |
|
743 | + /** |
|
744 | + * Checks whether the form has a given element. |
|
745 | + * |
|
746 | + * @since 1.0.19 |
|
747 | + * @return bool |
|
748 | + */ |
|
749 | 749 | public function has_element_type( $element_type ) { |
750 | 750 | return false !== $this->get_element_type( $element_type ); |
751 | - } |
|
752 | - |
|
753 | - /** |
|
754 | - * Checks whether this form is recurring or not. |
|
755 | - * |
|
756 | - * @since 1.0.19 |
|
757 | - * @return bool |
|
758 | - */ |
|
751 | + } |
|
752 | + |
|
753 | + /** |
|
754 | + * Checks whether this form is recurring or not. |
|
755 | + * |
|
756 | + * @since 1.0.19 |
|
757 | + * @return bool |
|
758 | + */ |
|
759 | 759 | public function is_recurring() { |
760 | 760 | |
761 | - if ( ! empty( $this->invoice ) ) { |
|
762 | - return $this->invoice->is_recurring(); |
|
763 | - } |
|
761 | + if ( ! empty( $this->invoice ) ) { |
|
762 | + return $this->invoice->is_recurring(); |
|
763 | + } |
|
764 | 764 | |
765 | - foreach ( $this->get_items() as $item ) { |
|
765 | + foreach ( $this->get_items() as $item ) { |
|
766 | 766 | |
767 | - if ( $item->is_recurring() ) { |
|
768 | - return true; |
|
769 | - } |
|
767 | + if ( $item->is_recurring() ) { |
|
768 | + return true; |
|
769 | + } |
|
770 | 770 | } |
771 | 771 | |
772 | 772 | return false; |
773 | - } |
|
773 | + } |
|
774 | 774 | |
775 | - /** |
|
776 | - * Retrieves the form's html. |
|
777 | - * |
|
778 | - * @since 1.0.19 |
|
779 | - */ |
|
775 | + /** |
|
776 | + * Retrieves the form's html. |
|
777 | + * |
|
778 | + * @since 1.0.19 |
|
779 | + */ |
|
780 | 780 | public function get_html( $extra_markup = '' ) { |
781 | 781 | |
782 | - // Return the HTML. |
|
783 | - return wpinv_get_template_html( |
|
784 | - 'payment-forms/form.php', |
|
785 | - array( |
|
786 | - 'form' => $this, |
|
787 | - 'extra_markup' => $extra_markup, |
|
788 | - ) |
|
789 | - ); |
|
790 | - |
|
791 | - } |
|
792 | - |
|
793 | - /** |
|
794 | - * Displays the payment form. |
|
795 | - * |
|
796 | - * @since 1.0.19 |
|
797 | - */ |
|
782 | + // Return the HTML. |
|
783 | + return wpinv_get_template_html( |
|
784 | + 'payment-forms/form.php', |
|
785 | + array( |
|
786 | + 'form' => $this, |
|
787 | + 'extra_markup' => $extra_markup, |
|
788 | + ) |
|
789 | + ); |
|
790 | + |
|
791 | + } |
|
792 | + |
|
793 | + /** |
|
794 | + * Displays the payment form. |
|
795 | + * |
|
796 | + * @since 1.0.19 |
|
797 | + */ |
|
798 | 798 | public function display( $extra_markup = '' ) { |
799 | - wpinv_get_template( |
|
800 | - 'payment-forms/form.php', |
|
801 | - array( |
|
802 | - 'form' => $this, |
|
803 | - 'extra_markup' => $extra_markup, |
|
804 | - ) |
|
805 | - ); |
|
799 | + wpinv_get_template( |
|
800 | + 'payment-forms/form.php', |
|
801 | + array( |
|
802 | + 'form' => $this, |
|
803 | + 'extra_markup' => $extra_markup, |
|
804 | + ) |
|
805 | + ); |
|
806 | 806 | } |
807 | 807 | |
808 | 808 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -72,28 +72,28 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
74 | 74 | */ |
75 | - public function __construct( $form = 0 ) { |
|
76 | - parent::__construct( $form ); |
|
75 | + public function __construct($form = 0) { |
|
76 | + parent::__construct($form); |
|
77 | 77 | |
78 | - if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | - $this->set_id( $form ); |
|
80 | - } elseif ( $form instanceof self ) { |
|
78 | + if (is_numeric($form) && $form > 0) { |
|
79 | + $this->set_id($form); |
|
80 | + } elseif ($form instanceof self) { |
|
81 | 81 | |
82 | - $this->set_id( $form->get_id() ); |
|
82 | + $this->set_id($form->get_id()); |
|
83 | 83 | $this->invoice = $form->invoice; |
84 | 84 | |
85 | - } elseif ( ! empty( $form->ID ) ) { |
|
86 | - $this->set_id( $form->ID ); |
|
85 | + } elseif (!empty($form->ID)) { |
|
86 | + $this->set_id($form->ID); |
|
87 | 87 | } else { |
88 | - $this->set_object_read( true ); |
|
88 | + $this->set_object_read(true); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | // Load the datastore. |
92 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
92 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
93 | 93 | |
94 | - if ( $this->get_id() > 0 ) { |
|
95 | - $this->post = get_post( $this->get_id() ); |
|
96 | - $this->data_store->read( $this ); |
|
94 | + if ($this->get_id() > 0) { |
|
95 | + $this->post = get_post($this->get_id()); |
|
96 | + $this->data_store->read($this); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | } |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | * @param string $context View or edit context. |
121 | 121 | * @return string |
122 | 122 | */ |
123 | - public function get_version( $context = 'view' ) { |
|
124 | - return $this->get_prop( 'version', $context ); |
|
123 | + public function get_version($context = 'view') { |
|
124 | + return $this->get_prop('version', $context); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | * @param string $context View or edit context. |
132 | 132 | * @return string |
133 | 133 | */ |
134 | - public function get_date_created( $context = 'view' ) { |
|
135 | - return $this->get_prop( 'date_created', $context ); |
|
134 | + public function get_date_created($context = 'view') { |
|
135 | + return $this->get_prop('date_created', $context); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | * @param string $context View or edit context. |
143 | 143 | * @return string |
144 | 144 | */ |
145 | - public function get_date_created_gmt( $context = 'view' ) { |
|
146 | - $date = $this->get_date_created( $context ); |
|
145 | + public function get_date_created_gmt($context = 'view') { |
|
146 | + $date = $this->get_date_created($context); |
|
147 | 147 | |
148 | - if ( $date ) { |
|
149 | - $date = get_gmt_from_date( $date ); |
|
148 | + if ($date) { |
|
149 | + $date = get_gmt_from_date($date); |
|
150 | 150 | } |
151 | 151 | return $date; |
152 | 152 | } |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * @param string $context View or edit context. |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - public function get_date_modified( $context = 'view' ) { |
|
162 | - return $this->get_prop( 'date_modified', $context ); |
|
161 | + public function get_date_modified($context = 'view') { |
|
162 | + return $this->get_prop('date_modified', $context); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -169,11 +169,11 @@ discard block |
||
169 | 169 | * @param string $context View or edit context. |
170 | 170 | * @return string |
171 | 171 | */ |
172 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
173 | - $date = $this->get_date_modified( $context ); |
|
172 | + public function get_date_modified_gmt($context = 'view') { |
|
173 | + $date = $this->get_date_modified($context); |
|
174 | 174 | |
175 | - if ( $date ) { |
|
176 | - $date = get_gmt_from_date( $date ); |
|
175 | + if ($date) { |
|
176 | + $date = get_gmt_from_date($date); |
|
177 | 177 | } |
178 | 178 | return $date; |
179 | 179 | } |
@@ -185,8 +185,8 @@ discard block |
||
185 | 185 | * @param string $context View or edit context. |
186 | 186 | * @return string |
187 | 187 | */ |
188 | - public function get_name( $context = 'view' ) { |
|
189 | - return $this->get_prop( 'name', $context ); |
|
188 | + public function get_name($context = 'view') { |
|
189 | + return $this->get_prop('name', $context); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -196,8 +196,8 @@ discard block |
||
196 | 196 | * @param string $context View or edit context. |
197 | 197 | * @return string |
198 | 198 | */ |
199 | - public function get_title( $context = 'view' ) { |
|
200 | - return $this->get_name( $context ); |
|
199 | + public function get_title($context = 'view') { |
|
200 | + return $this->get_name($context); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -207,8 +207,8 @@ discard block |
||
207 | 207 | * @param string $context View or edit context. |
208 | 208 | * @return int |
209 | 209 | */ |
210 | - public function get_author( $context = 'view' ) { |
|
211 | - return (int) $this->get_prop( 'author', $context ); |
|
210 | + public function get_author($context = 'view') { |
|
211 | + return (int) $this->get_prop('author', $context); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -218,21 +218,21 @@ discard block |
||
218 | 218 | * @param string $context View or edit context. |
219 | 219 | * @return array |
220 | 220 | */ |
221 | - public function get_elements( $context = 'view' ) { |
|
222 | - $elements = $this->get_prop( 'elements', $context ); |
|
221 | + public function get_elements($context = 'view') { |
|
222 | + $elements = $this->get_prop('elements', $context); |
|
223 | 223 | |
224 | - if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
225 | - return wpinv_get_data( 'sample-payment-form' ); |
|
224 | + if (empty($elements) || !is_array($elements)) { |
|
225 | + return wpinv_get_data('sample-payment-form'); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | // Ensure that all required elements exist. |
229 | 229 | $_elements = array(); |
230 | - foreach ( $elements as $element ) { |
|
230 | + foreach ($elements as $element) { |
|
231 | 231 | |
232 | - if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
232 | + if ($element['type'] == 'pay_button' && !$this->has_element_type('gateway_select')) { |
|
233 | 233 | |
234 | 234 | $_elements[] = array( |
235 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
235 | + 'text' => __('Select Payment Method', 'invoicing'), |
|
236 | 236 | 'id' => 'gtscicd', |
237 | 237 | 'name' => 'gtscicd', |
238 | 238 | 'type' => 'gateway_select', |
@@ -257,22 +257,22 @@ discard block |
||
257 | 257 | * @param string $return objects or arrays. |
258 | 258 | * @return GetPaid_Form_Item[] |
259 | 259 | */ |
260 | - public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | - $items = $this->get_prop( 'items', $context ); |
|
260 | + public function get_items($context = 'view', $return = 'objects') { |
|
261 | + $items = $this->get_prop('items', $context); |
|
262 | 262 | |
263 | - if ( empty( $items ) || ! is_array( $items ) ) { |
|
264 | - $items = wpinv_get_data( 'sample-payment-form-items' ); |
|
263 | + if (empty($items) || !is_array($items)) { |
|
264 | + $items = wpinv_get_data('sample-payment-form-items'); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | // Convert the items. |
268 | 268 | $prepared = array(); |
269 | 269 | |
270 | - foreach ( $items as $key => $value ) { |
|
270 | + foreach ($items as $key => $value) { |
|
271 | 271 | |
272 | 272 | // Form items. |
273 | - if ( $value instanceof GetPaid_Form_Item ) { |
|
273 | + if ($value instanceof GetPaid_Form_Item) { |
|
274 | 274 | |
275 | - if ( $value->can_purchase() ) { |
|
275 | + if ($value->can_purchase()) { |
|
276 | 276 | $prepared[] = $value; |
277 | 277 | } |
278 | 278 | |
@@ -281,16 +281,16 @@ discard block |
||
281 | 281 | } |
282 | 282 | |
283 | 283 | // $item_id => $quantity (buy buttons) |
284 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | - $item = new GetPaid_Form_Item( $key ); |
|
284 | + if (is_numeric($key) && is_numeric($value)) { |
|
285 | + $item = new GetPaid_Form_Item($key); |
|
286 | 286 | |
287 | - if ( $item->can_purchase() ) { |
|
287 | + if ($item->can_purchase()) { |
|
288 | 288 | |
289 | 289 | $value = (float) $value; |
290 | - $item->set_quantity( $value ); |
|
291 | - if ( 0 == $value ) { |
|
292 | - $item->set_quantity( 1 ); |
|
293 | - $item->set_allow_quantities( true ); |
|
290 | + $item->set_quantity($value); |
|
291 | + if (0 == $value) { |
|
292 | + $item->set_quantity(1); |
|
293 | + $item->set_allow_quantities(true); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | $prepared[] = $item; |
@@ -300,33 +300,33 @@ discard block |
||
300 | 300 | } |
301 | 301 | |
302 | 302 | // Items saved via payment forms editor. |
303 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
303 | + if (is_array($value) && isset($value['id'])) { |
|
304 | 304 | |
305 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
305 | + $item = new GetPaid_Form_Item($value['id']); |
|
306 | 306 | |
307 | - if ( ! $item->can_purchase() ) { |
|
307 | + if (!$item->can_purchase()) { |
|
308 | 308 | continue; |
309 | 309 | } |
310 | 310 | |
311 | 311 | // Sub-total (Cart items). |
312 | - if ( isset( $value['subtotal'] ) ) { |
|
313 | - $item->set_price( $value['subtotal'] ); |
|
312 | + if (isset($value['subtotal'])) { |
|
313 | + $item->set_price($value['subtotal']); |
|
314 | 314 | } |
315 | 315 | |
316 | - if ( isset( $value['quantity'] ) ) { |
|
317 | - $item->set_quantity( $value['quantity'] ); |
|
316 | + if (isset($value['quantity'])) { |
|
317 | + $item->set_quantity($value['quantity']); |
|
318 | 318 | } |
319 | 319 | |
320 | - if ( isset( $value['allow_quantities'] ) ) { |
|
321 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
320 | + if (isset($value['allow_quantities'])) { |
|
321 | + $item->set_allow_quantities($value['allow_quantities']); |
|
322 | 322 | } |
323 | 323 | |
324 | - if ( isset( $value['required'] ) ) { |
|
325 | - $item->set_is_required( $value['required'] ); |
|
324 | + if (isset($value['required'])) { |
|
325 | + $item->set_is_required($value['required']); |
|
326 | 326 | } |
327 | 327 | |
328 | - if ( isset( $value['description'] ) ) { |
|
329 | - $item->set_custom_description( $value['description'] ); |
|
328 | + if (isset($value['description'])) { |
|
329 | + $item->set_custom_description($value['description']); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | $prepared[] = $item; |
@@ -335,14 +335,14 @@ discard block |
||
335 | 335 | } |
336 | 336 | |
337 | 337 | // $item_id => array( 'price' => 10 ) (item variations) |
338 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | - $item = new GetPaid_Form_Item( $key ); |
|
338 | + if (is_numeric($key) && is_array($value)) { |
|
339 | + $item = new GetPaid_Form_Item($key); |
|
340 | 340 | |
341 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | - $item->set_price( $value['price'] ); |
|
341 | + if (isset($value['price']) && $item->user_can_set_their_price()) { |
|
342 | + $item->set_price($value['price']); |
|
343 | 343 | } |
344 | 344 | |
345 | - if ( $item->can_purchase() ) { |
|
345 | + if ($item->can_purchase()) { |
|
346 | 346 | $prepared[] = $item; |
347 | 347 | } |
348 | 348 | |
@@ -350,12 +350,12 @@ discard block |
||
350 | 350 | } |
351 | 351 | } |
352 | 352 | |
353 | - if ( 'objects' == $return && 'view' == $context ) { |
|
353 | + if ('objects' == $return && 'view' == $context) { |
|
354 | 354 | return $prepared; |
355 | 355 | } |
356 | 356 | |
357 | 357 | $items = array(); |
358 | - foreach ( $prepared as $item ) { |
|
358 | + foreach ($prepared as $item) { |
|
359 | 359 | $items[] = $item->prepare_data_for_use(); |
360 | 360 | } |
361 | 361 | |
@@ -369,14 +369,14 @@ discard block |
||
369 | 369 | * @param int $item_id The item id to return. |
370 | 370 | * @return GetPaid_Form_Item|bool |
371 | 371 | */ |
372 | - public function get_item( $item_id ) { |
|
372 | + public function get_item($item_id) { |
|
373 | 373 | |
374 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
374 | + if (empty($item_id) || !is_numeric($item_id)) { |
|
375 | 375 | return false; |
376 | 376 | } |
377 | 377 | |
378 | - foreach ( $this->get_items() as $item ) { |
|
379 | - if ( $item->get_id() == (int) $item_id ) { |
|
378 | + foreach ($this->get_items() as $item) { |
|
379 | + if ($item->get_id() == (int) $item_id) { |
|
380 | 380 | return $item; |
381 | 381 | } |
382 | 382 | } |
@@ -392,15 +392,15 @@ discard block |
||
392 | 392 | * @param string $element_type The element type to return. |
393 | 393 | * @return array|bool |
394 | 394 | */ |
395 | - public function get_element_type( $element_type ) { |
|
395 | + public function get_element_type($element_type) { |
|
396 | 396 | |
397 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
397 | + if (empty($element_type) || !is_scalar($element_type)) { |
|
398 | 398 | return false; |
399 | 399 | } |
400 | 400 | |
401 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
401 | + foreach ($this->get_prop('elements') as $element) { |
|
402 | 402 | |
403 | - if ( $element['type'] === $element_type ) { |
|
403 | + if ($element['type'] === $element_type) { |
|
404 | 404 | return $element; |
405 | 405 | } |
406 | 406 | } |
@@ -416,8 +416,8 @@ discard block |
||
416 | 416 | * @param string $context View or edit context. |
417 | 417 | * @return float |
418 | 418 | */ |
419 | - public function get_earned( $context = 'view' ) { |
|
420 | - return $this->get_prop( 'earned', $context ); |
|
419 | + public function get_earned($context = 'view') { |
|
420 | + return $this->get_prop('earned', $context); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | /** |
@@ -427,8 +427,8 @@ discard block |
||
427 | 427 | * @param string $context View or edit context. |
428 | 428 | * @return float |
429 | 429 | */ |
430 | - public function get_refunded( $context = 'view' ) { |
|
431 | - return $this->get_prop( 'refunded', $context ); |
|
430 | + public function get_refunded($context = 'view') { |
|
431 | + return $this->get_prop('refunded', $context); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | /** |
@@ -438,8 +438,8 @@ discard block |
||
438 | 438 | * @param string $context View or edit context. |
439 | 439 | * @return float |
440 | 440 | */ |
441 | - public function get_cancelled( $context = 'view' ) { |
|
442 | - return $this->get_prop( 'cancelled', $context ); |
|
441 | + public function get_cancelled($context = 'view') { |
|
442 | + return $this->get_prop('cancelled', $context); |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | /** |
@@ -449,8 +449,8 @@ discard block |
||
449 | 449 | * @param string $context View or edit context. |
450 | 450 | * @return float |
451 | 451 | */ |
452 | - public function get_failed( $context = 'view' ) { |
|
453 | - return $this->get_prop( 'failed', $context ); |
|
452 | + public function get_failed($context = 'view') { |
|
453 | + return $this->get_prop('failed', $context); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | /** |
@@ -461,8 +461,8 @@ discard block |
||
461 | 461 | * @return string |
462 | 462 | */ |
463 | 463 | public function get_currency() { |
464 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
465 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
464 | + $currency = empty($this->invoice) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
465 | + return apply_filters('getpaid-payment-form-currency', $currency, $this); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | /* |
@@ -480,8 +480,8 @@ discard block |
||
480 | 480 | * |
481 | 481 | * @since 1.0.19 |
482 | 482 | */ |
483 | - public function set_version( $value ) { |
|
484 | - $this->set_prop( 'version', $value ); |
|
483 | + public function set_version($value) { |
|
484 | + $this->set_prop('version', $value); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
@@ -491,11 +491,11 @@ discard block |
||
491 | 491 | * @param string $value Value to set. |
492 | 492 | * @return bool Whether or not the date was set. |
493 | 493 | */ |
494 | - public function set_date_created( $value ) { |
|
495 | - $date = strtotime( $value ); |
|
494 | + public function set_date_created($value) { |
|
495 | + $date = strtotime($value); |
|
496 | 496 | |
497 | - if ( $date ) { |
|
498 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
497 | + if ($date) { |
|
498 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
499 | 499 | return true; |
500 | 500 | } |
501 | 501 | |
@@ -510,11 +510,11 @@ discard block |
||
510 | 510 | * @param string $value Value to set. |
511 | 511 | * @return bool Whether or not the date was set. |
512 | 512 | */ |
513 | - public function set_date_modified( $value ) { |
|
514 | - $date = strtotime( $value ); |
|
513 | + public function set_date_modified($value) { |
|
514 | + $date = strtotime($value); |
|
515 | 515 | |
516 | - if ( $date ) { |
|
517 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
516 | + if ($date) { |
|
517 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
518 | 518 | return true; |
519 | 519 | } |
520 | 520 | |
@@ -528,8 +528,8 @@ discard block |
||
528 | 528 | * @since 1.0.19 |
529 | 529 | * @param string $value New name. |
530 | 530 | */ |
531 | - public function set_name( $value ) { |
|
532 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
531 | + public function set_name($value) { |
|
532 | + $this->set_prop('name', sanitize_text_field($value)); |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | /** |
@@ -538,8 +538,8 @@ discard block |
||
538 | 538 | * @since 1.0.19 |
539 | 539 | * @param string $value New name. |
540 | 540 | */ |
541 | - public function set_title( $value ) { |
|
542 | - $this->set_name( $value ); |
|
541 | + public function set_title($value) { |
|
542 | + $this->set_name($value); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | /** |
@@ -548,8 +548,8 @@ discard block |
||
548 | 548 | * @since 1.0.19 |
549 | 549 | * @param int $value New author. |
550 | 550 | */ |
551 | - public function set_author( $value ) { |
|
552 | - $this->set_prop( 'author', (int) $value ); |
|
551 | + public function set_author($value) { |
|
552 | + $this->set_prop('author', (int) $value); |
|
553 | 553 | } |
554 | 554 | |
555 | 555 | /** |
@@ -559,9 +559,9 @@ discard block |
||
559 | 559 | * @sinve 2.3.4 Array values sanitized. |
560 | 560 | * @param array $value Form elements. |
561 | 561 | */ |
562 | - public function set_elements( $value ) { |
|
563 | - if ( is_array( $value ) ) { |
|
564 | - $this->set_prop( 'elements', wp_kses_post_deep( $value ) ); |
|
562 | + public function set_elements($value) { |
|
563 | + if (is_array($value)) { |
|
564 | + $this->set_prop('elements', wp_kses_post_deep($value)); |
|
565 | 565 | } |
566 | 566 | } |
567 | 567 | |
@@ -572,36 +572,36 @@ discard block |
||
572 | 572 | * |
573 | 573 | * @return mixed |
574 | 574 | */ |
575 | - public function sanitize_array_values( $value ) { |
|
575 | + public function sanitize_array_values($value) { |
|
576 | 576 | |
577 | 577 | // sanitize |
578 | - if ( ! empty( $value ) ) { |
|
578 | + if (!empty($value)) { |
|
579 | 579 | |
580 | - foreach ( $value as $key => $val_arr ) { |
|
580 | + foreach ($value as $key => $val_arr) { |
|
581 | 581 | |
582 | - if ( is_array( $val_arr ) ) { |
|
582 | + if (is_array($val_arr)) { |
|
583 | 583 | // check if we have sub array items. |
584 | 584 | $sub_arr = array(); |
585 | - foreach ( $val_arr as $key2 => $val2 ) { |
|
586 | - if ( is_array( $val2 ) ) { |
|
587 | - $sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 ); |
|
588 | - unset( $val_arr[ $key ][ $key2 ] ); |
|
585 | + foreach ($val_arr as $key2 => $val2) { |
|
586 | + if (is_array($val2)) { |
|
587 | + $sub_arr[$key2] = $this->sanitize_array_values($val2); |
|
588 | + unset($val_arr[$key][$key2]); |
|
589 | 589 | } |
590 | 590 | } |
591 | 591 | |
592 | 592 | // we allow some html in description so we sanitize it separately. |
593 | - $help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : ''; |
|
593 | + $help_text = !empty($val_arr['description']) ? wp_kses_post($val_arr['description']) : ''; |
|
594 | 594 | |
595 | 595 | // sanitize array elements |
596 | - $value[ $key ] = array_map( 'sanitize_text_field', $val_arr ); |
|
596 | + $value[$key] = array_map('sanitize_text_field', $val_arr); |
|
597 | 597 | |
598 | 598 | // add back the description if set |
599 | - if ( isset( $val_arr['description'] ) ) { |
|
600 | -$value[ $key ]['description'] = $help_text;} |
|
599 | + if (isset($val_arr['description'])) { |
|
600 | +$value[$key]['description'] = $help_text; } |
|
601 | 601 | |
602 | 602 | // add back sub array items after its been sanitized. |
603 | - if ( ! empty( $sub_arr ) ) { |
|
604 | - $value[ $key ] = array_merge( $value[ $key ], $sub_arr ); |
|
603 | + if (!empty($sub_arr)) { |
|
604 | + $value[$key] = array_merge($value[$key], $sub_arr); |
|
605 | 605 | } |
606 | 606 | } |
607 | 607 | } |
@@ -616,9 +616,9 @@ discard block |
||
616 | 616 | * @since 1.0.19 |
617 | 617 | * @param array $value Form elements. |
618 | 618 | */ |
619 | - public function set_items( $value ) { |
|
620 | - if ( is_array( $value ) ) { |
|
621 | - $this->set_prop( 'items', $value ); |
|
619 | + public function set_items($value) { |
|
620 | + if (is_array($value)) { |
|
621 | + $this->set_prop('items', $value); |
|
622 | 622 | } |
623 | 623 | } |
624 | 624 | |
@@ -628,9 +628,9 @@ discard block |
||
628 | 628 | * @since 1.0.19 |
629 | 629 | * @param float $value Amount earned. |
630 | 630 | */ |
631 | - public function set_earned( $value ) { |
|
632 | - $value = max( (float) $value, 0 ); |
|
633 | - $this->set_prop( 'earned', $value ); |
|
631 | + public function set_earned($value) { |
|
632 | + $value = max((float) $value, 0); |
|
633 | + $this->set_prop('earned', $value); |
|
634 | 634 | } |
635 | 635 | |
636 | 636 | /** |
@@ -639,9 +639,9 @@ discard block |
||
639 | 639 | * @since 1.0.19 |
640 | 640 | * @param float $value Amount refunded. |
641 | 641 | */ |
642 | - public function set_refunded( $value ) { |
|
643 | - $value = max( (float) $value, 0 ); |
|
644 | - $this->set_prop( 'refunded', $value ); |
|
642 | + public function set_refunded($value) { |
|
643 | + $value = max((float) $value, 0); |
|
644 | + $this->set_prop('refunded', $value); |
|
645 | 645 | } |
646 | 646 | |
647 | 647 | /** |
@@ -650,9 +650,9 @@ discard block |
||
650 | 650 | * @since 1.0.19 |
651 | 651 | * @param float $value Amount cancelled. |
652 | 652 | */ |
653 | - public function set_cancelled( $value ) { |
|
654 | - $value = max( (float) $value, 0 ); |
|
655 | - $this->set_prop( 'cancelled', $value ); |
|
653 | + public function set_cancelled($value) { |
|
654 | + $value = max((float) $value, 0); |
|
655 | + $this->set_prop('cancelled', $value); |
|
656 | 656 | } |
657 | 657 | |
658 | 658 | /** |
@@ -661,9 +661,9 @@ discard block |
||
661 | 661 | * @since 1.0.19 |
662 | 662 | * @param float $value Amount cancelled. |
663 | 663 | */ |
664 | - public function set_failed( $value ) { |
|
665 | - $value = max( (float) $value, 0 ); |
|
666 | - $this->set_prop( 'failed', $value ); |
|
664 | + public function set_failed($value) { |
|
665 | + $value = max((float) $value, 0); |
|
666 | + $this->set_prop('failed', $value); |
|
667 | 667 | } |
668 | 668 | |
669 | 669 | /** |
@@ -672,11 +672,11 @@ discard block |
||
672 | 672 | * @deprecated |
673 | 673 | * @return int item id |
674 | 674 | */ |
675 | - public function create( $data = array() ) { |
|
675 | + public function create($data = array()) { |
|
676 | 676 | |
677 | 677 | // Set the properties. |
678 | - if ( is_array( $data ) ) { |
|
679 | - $this->set_props( $data ); |
|
678 | + if (is_array($data)) { |
|
679 | + $this->set_props($data); |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | // Save the item. |
@@ -690,8 +690,8 @@ discard block |
||
690 | 690 | * @deprecated |
691 | 691 | * @return int item id |
692 | 692 | */ |
693 | - public function update( $data = array() ) { |
|
694 | - return $this->create( $data ); |
|
693 | + public function update($data = array()) { |
|
694 | + return $this->create($data); |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | /* |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | */ |
712 | 712 | public function is_default() { |
713 | 713 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
714 | - return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
|
714 | + return (bool) apply_filters('wpinv_is_default_payment_form', $is_default, $this->get_id(), $this); |
|
715 | 715 | } |
716 | 716 | |
717 | 717 | /** |
@@ -723,11 +723,11 @@ discard block |
||
723 | 723 | public function is_active() { |
724 | 724 | $is_active = 0 !== (int) $this->get_id(); |
725 | 725 | |
726 | - if ( $is_active && ! current_user_can( 'edit_post', $this->get_id() ) && $this->get_status() != 'publish' ) { |
|
726 | + if ($is_active && !current_user_can('edit_post', $this->get_id()) && $this->get_status() != 'publish') { |
|
727 | 727 | $is_active = false; |
728 | 728 | } |
729 | 729 | |
730 | - return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
|
730 | + return (bool) apply_filters('wpinv_is_payment_form_active', $is_active, $this); |
|
731 | 731 | } |
732 | 732 | |
733 | 733 | /** |
@@ -736,8 +736,8 @@ discard block |
||
736 | 736 | * @since 1.0.19 |
737 | 737 | * @return bool |
738 | 738 | */ |
739 | - public function has_item( $item_id ) { |
|
740 | - return false !== $this->get_item( $item_id ); |
|
739 | + public function has_item($item_id) { |
|
740 | + return false !== $this->get_item($item_id); |
|
741 | 741 | } |
742 | 742 | |
743 | 743 | /** |
@@ -746,8 +746,8 @@ discard block |
||
746 | 746 | * @since 1.0.19 |
747 | 747 | * @return bool |
748 | 748 | */ |
749 | - public function has_element_type( $element_type ) { |
|
750 | - return false !== $this->get_element_type( $element_type ); |
|
749 | + public function has_element_type($element_type) { |
|
750 | + return false !== $this->get_element_type($element_type); |
|
751 | 751 | } |
752 | 752 | |
753 | 753 | /** |
@@ -758,13 +758,13 @@ discard block |
||
758 | 758 | */ |
759 | 759 | public function is_recurring() { |
760 | 760 | |
761 | - if ( ! empty( $this->invoice ) ) { |
|
761 | + if (!empty($this->invoice)) { |
|
762 | 762 | return $this->invoice->is_recurring(); |
763 | 763 | } |
764 | 764 | |
765 | - foreach ( $this->get_items() as $item ) { |
|
765 | + foreach ($this->get_items() as $item) { |
|
766 | 766 | |
767 | - if ( $item->is_recurring() ) { |
|
767 | + if ($item->is_recurring()) { |
|
768 | 768 | return true; |
769 | 769 | } |
770 | 770 | } |
@@ -777,7 +777,7 @@ discard block |
||
777 | 777 | * |
778 | 778 | * @since 1.0.19 |
779 | 779 | */ |
780 | - public function get_html( $extra_markup = '' ) { |
|
780 | + public function get_html($extra_markup = '') { |
|
781 | 781 | |
782 | 782 | // Return the HTML. |
783 | 783 | return wpinv_get_template_html( |
@@ -795,7 +795,7 @@ discard block |
||
795 | 795 | * |
796 | 796 | * @since 1.0.19 |
797 | 797 | */ |
798 | - public function display( $extra_markup = '' ) { |
|
798 | + public function display($extra_markup = '') { |
|
799 | 799 | wpinv_get_template( |
800 | 800 | 'payment-forms/form.php', |
801 | 801 | array( |
@@ -13,9 +13,9 @@ discard block |
||
13 | 13 | |
14 | 14 | |
15 | 15 | function wpinv_get_default_country() { |
16 | - $country = wpinv_get_option( 'default_country', 'UK' ); |
|
16 | + $country = wpinv_get_option( 'default_country', 'UK' ); |
|
17 | 17 | |
18 | - return apply_filters( 'wpinv_default_country', $country ); |
|
18 | + return apply_filters( 'wpinv_default_country', $country ); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | function wpinv_sanitize_country( $country ) { |
38 | 38 | |
39 | - // Enure the country is specified |
|
39 | + // Enure the country is specified |
|
40 | 40 | if ( empty( $country ) ) { |
41 | 41 | $country = wpinv_get_default_country(); |
42 | 42 | } |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | function wpinv_get_default_state() { |
69 | - $state = wpinv_get_option( 'default_state', '' ); |
|
69 | + $state = wpinv_get_option( 'default_state', '' ); |
|
70 | 70 | |
71 | - return apply_filters( 'wpinv_default_state', $state ); |
|
71 | + return apply_filters( 'wpinv_default_state', $state ); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | function wpinv_state_name( $state_code = '', $country_code = '' ) { |
@@ -299,11 +299,11 @@ discard block |
||
299 | 299 | |
300 | 300 | $country = wpinv_sanitize_country( $country ); |
301 | 301 | |
302 | - foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
303 | - if ( false !== array_search( $country, $countries, true ) ) { |
|
304 | - return $continent_code; |
|
305 | - } |
|
306 | - } |
|
302 | + foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
303 | + if ( false !== array_search( $country, $countries, true ) ) { |
|
304 | + return $continent_code; |
|
305 | + } |
|
306 | + } |
|
307 | 307 | |
308 | 308 | return ''; |
309 | 309 | |
@@ -595,31 +595,31 @@ discard block |
||
595 | 595 | } |
596 | 596 | |
597 | 597 | function wpinv_get_states_field() { |
598 | - if ( empty( $_POST['country'] ) ) { |
|
599 | - $_POST['country'] = wpinv_get_default_country(); |
|
600 | - } |
|
601 | - $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
598 | + if ( empty( $_POST['country'] ) ) { |
|
599 | + $_POST['country'] = wpinv_get_default_country(); |
|
600 | + } |
|
601 | + $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
602 | 602 | |
603 | - if ( ! empty( $states ) ) { |
|
604 | - $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
603 | + if ( ! empty( $states ) ) { |
|
604 | + $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
605 | 605 | |
606 | 606 | $class = isset( $_POST['class'] ) ? esc_attr( sanitize_text_field( $_POST['class'] ) ) : ''; |
607 | 607 | $class .= " $sanitized_field_name getpaid_js_field-state custom-select wpinv-select wpi_select2"; |
608 | 608 | |
609 | 609 | $args = array( |
610 | - 'name' => $sanitized_field_name, |
|
611 | - 'id' => $sanitized_field_name, |
|
612 | - 'class' => implode( ' ', array_unique( explode( ' ', $class ) ) ), |
|
613 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
614 | - 'show_option_all' => false, |
|
615 | - 'show_option_none' => false, |
|
616 | - ); |
|
617 | - |
|
618 | - wpinv_html_select( $args ); |
|
619 | - |
|
620 | - } else { |
|
621 | - echo 'nostates'; |
|
622 | - } |
|
610 | + 'name' => $sanitized_field_name, |
|
611 | + 'id' => $sanitized_field_name, |
|
612 | + 'class' => implode( ' ', array_unique( explode( ' ', $class ) ) ), |
|
613 | + 'options' => array_merge( array( '' => '' ), $states ), |
|
614 | + 'show_option_all' => false, |
|
615 | + 'show_option_none' => false, |
|
616 | + ); |
|
617 | + |
|
618 | + wpinv_html_select( $args ); |
|
619 | + |
|
620 | + } else { |
|
621 | + echo 'nostates'; |
|
622 | + } |
|
623 | 623 | |
624 | 624 | } |
625 | 625 | |
@@ -638,47 +638,47 @@ discard block |
||
638 | 638 | */ |
639 | 639 | function wpinv_get_address_formats() { |
640 | 640 | |
641 | - return apply_filters( |
|
641 | + return apply_filters( |
|
642 | 642 | 'wpinv_localisation_address_formats', |
643 | - array( |
|
644 | - 'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}", |
|
645 | - 'AU' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}", |
|
646 | - 'AT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
647 | - 'BE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
648 | - 'CA' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}} {{zip}}\n{{country}}", |
|
649 | - 'CH' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
650 | - 'CL' => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}", |
|
651 | - 'CN' => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}", |
|
652 | - 'CZ' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
653 | - 'DE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
654 | - 'EE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
655 | - 'FI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
656 | - 'DK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
657 | - 'FR' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}", |
|
658 | - 'HK' => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}", |
|
659 | - 'HU' => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}", |
|
660 | - 'IN' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}", |
|
661 | - 'IS' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
662 | - 'IT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}", |
|
663 | - 'JP' => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}", |
|
664 | - 'TW' => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}", |
|
665 | - 'LI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
666 | - 'NL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
667 | - 'NZ' => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}", |
|
668 | - 'NO' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
669 | - 'PL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
670 | - 'PT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
671 | - 'SK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
672 | - 'RS' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
673 | - 'SI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
674 | - 'ES' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}", |
|
675 | - 'SE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
676 | - 'TR' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}", |
|
677 | - 'UG' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}", |
|
678 | - 'US' => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}", |
|
679 | - 'VN' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}", |
|
680 | - ) |
|
681 | - ); |
|
643 | + array( |
|
644 | + 'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}", |
|
645 | + 'AU' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}", |
|
646 | + 'AT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
647 | + 'BE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
648 | + 'CA' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}} {{zip}}\n{{country}}", |
|
649 | + 'CH' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
650 | + 'CL' => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}", |
|
651 | + 'CN' => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}", |
|
652 | + 'CZ' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
653 | + 'DE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
654 | + 'EE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
655 | + 'FI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
656 | + 'DK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
657 | + 'FR' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}", |
|
658 | + 'HK' => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}", |
|
659 | + 'HU' => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}", |
|
660 | + 'IN' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}", |
|
661 | + 'IS' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
662 | + 'IT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}", |
|
663 | + 'JP' => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}", |
|
664 | + 'TW' => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}", |
|
665 | + 'LI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
666 | + 'NL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
667 | + 'NZ' => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}", |
|
668 | + 'NO' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
669 | + 'PL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
670 | + 'PT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
671 | + 'SK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
672 | + 'RS' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
673 | + 'SI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
674 | + 'ES' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}", |
|
675 | + 'SE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
676 | + 'TR' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}", |
|
677 | + 'UG' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}", |
|
678 | + 'US' => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}", |
|
679 | + 'VN' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}", |
|
680 | + ) |
|
681 | + ); |
|
682 | 682 | } |
683 | 683 | |
684 | 684 | /** |
@@ -695,21 +695,21 @@ discard block |
||
695 | 695 | } |
696 | 696 | |
697 | 697 | // Get all formats. |
698 | - $formats = wpinv_get_address_formats(); |
|
698 | + $formats = wpinv_get_address_formats(); |
|
699 | 699 | |
700 | - // Get format for the specified country. |
|
701 | - $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
700 | + // Get format for the specified country. |
|
701 | + $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
702 | 702 | |
703 | 703 | /** |
704 | - * Filters the address format to use on Invoices. |
|
704 | + * Filters the address format to use on Invoices. |
|
705 | 705 | * |
706 | 706 | * New lines will be replaced by a `br` element. Double new lines will be replaced by a paragraph. HTML tags are allowed. |
707 | - * |
|
708 | - * @since 1.0.13 |
|
709 | - * |
|
710 | - * @param string $format The address format to use. |
|
707 | + * |
|
708 | + * @since 1.0.13 |
|
709 | + * |
|
710 | + * @param string $format The address format to use. |
|
711 | 711 | * @param string $country The country who's address format is being retrieved. |
712 | - */ |
|
712 | + */ |
|
713 | 713 | return apply_filters( 'wpinv_get_full_address_format', $format, $country ); |
714 | 714 | } |
715 | 715 | |
@@ -730,8 +730,8 @@ discard block |
||
730 | 730 | 'country' => '', |
731 | 731 | 'zip' => '', |
732 | 732 | 'first_name' => '', |
733 | - 'last_name' => '', |
|
734 | - 'company' => '', |
|
733 | + 'last_name' => '', |
|
734 | + 'company' => '', |
|
735 | 735 | ); |
736 | 736 | |
737 | 737 | $args = map_deep( wp_parse_args( array_filter( $billing_details ), $default_args ), 'trim' ); |
@@ -752,14 +752,14 @@ discard block |
||
752 | 752 | $args['country_code'] = $country; |
753 | 753 | |
754 | 754 | /** |
755 | - * Filters the address format replacements to use on Invoices. |
|
755 | + * Filters the address format replacements to use on Invoices. |
|
756 | + * |
|
757 | + * |
|
758 | + * @since 1.0.13 |
|
756 | 759 | * |
757 | - * |
|
758 | - * @since 1.0.13 |
|
759 | - * |
|
760 | - * @param array $replacements The address replacements to use. |
|
760 | + * @param array $replacements The address replacements to use. |
|
761 | 761 | * @param array $billing_details The billing details to use. |
762 | - */ |
|
762 | + */ |
|
763 | 763 | $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details ); |
764 | 764 | |
765 | 765 | $return = array(); |
@@ -782,5 +782,5 @@ discard block |
||
782 | 782 | * @return string |
783 | 783 | */ |
784 | 784 | function wpinv_trim_formatted_address_line( $line ) { |
785 | - return trim( $line, ', ' ); |
|
785 | + return trim( $line, ', ' ); |
|
786 | 786 | } |
@@ -7,15 +7,15 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( ! defined( 'WPINC' ) ) { |
|
10 | +if (!defined('WPINC')) { |
|
11 | 11 | exit; |
12 | 12 | } |
13 | 13 | |
14 | 14 | |
15 | 15 | function wpinv_get_default_country() { |
16 | - $country = wpinv_get_option( 'default_country', 'UK' ); |
|
16 | + $country = wpinv_get_option('default_country', 'UK'); |
|
17 | 17 | |
18 | - return apply_filters( 'wpinv_default_country', $country ); |
|
18 | + return apply_filters('wpinv_default_country', $country); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @return string |
25 | 25 | */ |
26 | -function getpaid_get_ip_country( $ip_address = '' ) { |
|
27 | - $country = GetPaid_Geolocation::geolocate_ip( $ip_address, true ); |
|
26 | +function getpaid_get_ip_country($ip_address = '') { |
|
27 | + $country = GetPaid_Geolocation::geolocate_ip($ip_address, true); |
|
28 | 28 | return $country['country']; |
29 | 29 | } |
30 | 30 | |
@@ -34,59 +34,59 @@ discard block |
||
34 | 34 | * @param string $country The country code to sanitize |
35 | 35 | * @return array |
36 | 36 | */ |
37 | -function wpinv_sanitize_country( $country ) { |
|
37 | +function wpinv_sanitize_country($country) { |
|
38 | 38 | |
39 | 39 | // Enure the country is specified |
40 | - if ( empty( $country ) ) { |
|
40 | + if (empty($country)) { |
|
41 | 41 | $country = wpinv_get_default_country(); |
42 | 42 | } |
43 | - return trim( wpinv_utf8_strtoupper( $country ) ); |
|
43 | + return trim(wpinv_utf8_strtoupper($country)); |
|
44 | 44 | |
45 | 45 | } |
46 | 46 | |
47 | -function wpinv_is_base_country( $country ) { |
|
47 | +function wpinv_is_base_country($country) { |
|
48 | 48 | $base_country = wpinv_get_default_country(); |
49 | 49 | |
50 | - if ( $base_country === 'UK' ) { |
|
50 | + if ($base_country === 'UK') { |
|
51 | 51 | $base_country = 'GB'; |
52 | 52 | } |
53 | - if ( $country == 'UK' ) { |
|
53 | + if ($country == 'UK') { |
|
54 | 54 | $country = 'GB'; |
55 | 55 | } |
56 | 56 | |
57 | - return ( $country && $country === $base_country ) ? true : false; |
|
57 | + return ($country && $country === $base_country) ? true : false; |
|
58 | 58 | } |
59 | 59 | |
60 | -function wpinv_country_name( $country_code = '' ) { |
|
60 | +function wpinv_country_name($country_code = '') { |
|
61 | 61 | $countries = wpinv_get_country_list(); |
62 | 62 | $country_code = $country_code == 'UK' ? 'GB' : $country_code; |
63 | - $country = isset( $countries[ $country_code ] ) ? $countries[ $country_code ] : $country_code; |
|
63 | + $country = isset($countries[$country_code]) ? $countries[$country_code] : $country_code; |
|
64 | 64 | |
65 | - return apply_filters( 'wpinv_country_name', $country, $country_code ); |
|
65 | + return apply_filters('wpinv_country_name', $country, $country_code); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | function wpinv_get_default_state() { |
69 | - $state = wpinv_get_option( 'default_state', '' ); |
|
69 | + $state = wpinv_get_option('default_state', ''); |
|
70 | 70 | |
71 | - return apply_filters( 'wpinv_default_state', $state ); |
|
71 | + return apply_filters('wpinv_default_state', $state); |
|
72 | 72 | } |
73 | 73 | |
74 | -function wpinv_state_name( $state_code = '', $country_code = '' ) { |
|
74 | +function wpinv_state_name($state_code = '', $country_code = '') { |
|
75 | 75 | $state = $state_code; |
76 | 76 | |
77 | - if ( ! empty( $country_code ) ) { |
|
78 | - $states = wpinv_get_country_states( $country_code ); |
|
77 | + if (!empty($country_code)) { |
|
78 | + $states = wpinv_get_country_states($country_code); |
|
79 | 79 | |
80 | - $state = ! empty( $states ) && isset( $states[ $state_code ] ) ? $states[ $state_code ] : $state; |
|
80 | + $state = !empty($states) && isset($states[$state_code]) ? $states[$state_code] : $state; |
|
81 | 81 | } |
82 | 82 | |
83 | - return apply_filters( 'wpinv_state_name', $state, $state_code, $country_code ); |
|
83 | + return apply_filters('wpinv_state_name', $state, $state_code, $country_code); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | function wpinv_store_address() { |
87 | - $address = wpinv_get_option( 'store_address', '' ); |
|
87 | + $address = wpinv_get_option('store_address', ''); |
|
88 | 88 | |
89 | - return apply_filters( 'wpinv_store_address', $address ); |
|
89 | + return apply_filters('wpinv_store_address', $address); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -94,24 +94,24 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @param WPInv_Invoice $invoice |
96 | 96 | */ |
97 | -function getpaid_maybe_add_default_address( &$invoice ) { |
|
97 | +function getpaid_maybe_add_default_address(&$invoice) { |
|
98 | 98 | |
99 | 99 | $user_id = $invoice->get_user_id(); |
100 | 100 | |
101 | 101 | // Abort if the invoice belongs to no one. |
102 | - if ( empty( $user_id ) ) { |
|
102 | + if (empty($user_id)) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Fill in defaults whenever necessary. |
107 | - foreach ( wpinv_get_user_address( $user_id ) as $key => $value ) { |
|
107 | + foreach (wpinv_get_user_address($user_id) as $key => $value) { |
|
108 | 108 | |
109 | - if ( is_callable( $invoice, "get_$key" ) ) { |
|
110 | - $current = call_user_func( array( $invoice, "get_$key" ) ); |
|
109 | + if (is_callable($invoice, "get_$key")) { |
|
110 | + $current = call_user_func(array($invoice, "get_$key")); |
|
111 | 111 | |
112 | - if ( empty( $current ) ) { |
|
112 | + if (empty($current)) { |
|
113 | 113 | $method = "set_$key"; |
114 | - $invoice->$method( $value ); |
|
114 | + $invoice->$method($value); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | } |
@@ -123,27 +123,27 @@ discard block |
||
123 | 123 | * |
124 | 124 | * @return array |
125 | 125 | */ |
126 | -function getpaid_user_address_fields( $force_vat = false ) { |
|
126 | +function getpaid_user_address_fields($force_vat = false) { |
|
127 | 127 | |
128 | 128 | $address_fields = apply_filters( |
129 | 129 | 'getpaid_user_address_fields', |
130 | 130 | array( |
131 | - 'first_name' => __( 'First Name', 'invoicing' ), |
|
132 | - 'last_name' => __( 'Last Name', 'invoicing' ), |
|
133 | - 'address' => __( 'Address', 'invoicing' ), |
|
134 | - 'city' => __( 'City', 'invoicing' ), |
|
135 | - 'country' => __( 'Country', 'invoicing' ), |
|
136 | - 'state' => __( 'State', 'invoicing' ), |
|
137 | - 'zip' => __( 'Zip/Postal Code', 'invoicing' ), |
|
138 | - 'phone' => __( 'Phone Number', 'invoicing' ), |
|
139 | - 'company' => __( 'Company', 'invoicing' ), |
|
140 | - 'company_id' => __( 'Company ID', 'invoicing' ), |
|
141 | - 'vat_number' => __( 'VAT Number', 'invoicing' ), |
|
131 | + 'first_name' => __('First Name', 'invoicing'), |
|
132 | + 'last_name' => __('Last Name', 'invoicing'), |
|
133 | + 'address' => __('Address', 'invoicing'), |
|
134 | + 'city' => __('City', 'invoicing'), |
|
135 | + 'country' => __('Country', 'invoicing'), |
|
136 | + 'state' => __('State', 'invoicing'), |
|
137 | + 'zip' => __('Zip/Postal Code', 'invoicing'), |
|
138 | + 'phone' => __('Phone Number', 'invoicing'), |
|
139 | + 'company' => __('Company', 'invoicing'), |
|
140 | + 'company_id' => __('Company ID', 'invoicing'), |
|
141 | + 'vat_number' => __('VAT Number', 'invoicing'), |
|
142 | 142 | ) |
143 | 143 | ); |
144 | 144 | |
145 | - if ( ! wpinv_use_taxes() && isset( $address_fields['vat_number'] ) && ! wp_doing_ajax() && ! $force_vat ) { |
|
146 | - unset( $address_fields['vat_number'] ); |
|
145 | + if (!wpinv_use_taxes() && isset($address_fields['vat_number']) && !wp_doing_ajax() && !$force_vat) { |
|
146 | + unset($address_fields['vat_number']); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | return $address_fields; |
@@ -154,8 +154,8 @@ discard block |
||
154 | 154 | * |
155 | 155 | * @return bool |
156 | 156 | */ |
157 | -function getpaid_is_address_field_whitelisted( $key ) { |
|
158 | - return array_key_exists( $key, getpaid_user_address_fields() ); |
|
157 | +function getpaid_is_address_field_whitelisted($key) { |
|
158 | + return array_key_exists($key, getpaid_user_address_fields()); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -165,44 +165,44 @@ discard block |
||
165 | 165 | * |
166 | 166 | * @param WPInv_Invoice $invoice |
167 | 167 | */ |
168 | -function getpaid_save_invoice_user_address( $invoice ) { |
|
168 | +function getpaid_save_invoice_user_address($invoice) { |
|
169 | 169 | |
170 | 170 | // Retrieve the invoice. |
171 | - $invoice = wpinv_get_invoice( $invoice ); |
|
171 | + $invoice = wpinv_get_invoice($invoice); |
|
172 | 172 | |
173 | 173 | // Abort if it does not exist. |
174 | - if ( empty( $invoice ) || $invoice->is_renewal() ) { |
|
174 | + if (empty($invoice) || $invoice->is_renewal()) { |
|
175 | 175 | return; |
176 | 176 | } |
177 | 177 | |
178 | - $customer = getpaid_get_customer_by_user_id( $invoice->get_user_id() ); |
|
178 | + $customer = getpaid_get_customer_by_user_id($invoice->get_user_id()); |
|
179 | 179 | |
180 | - if ( empty( $customer ) ) { |
|
181 | - $customer = new GetPaid_Customer( 0 ); |
|
182 | - $customer->clone_user( $invoice->get_user_id() ); |
|
180 | + if (empty($customer)) { |
|
181 | + $customer = new GetPaid_Customer(0); |
|
182 | + $customer->clone_user($invoice->get_user_id()); |
|
183 | 183 | } |
184 | 184 | |
185 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
185 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
186 | 186 | |
187 | - if ( is_callable( array( $invoice, "get_$field" ) ) ) { |
|
188 | - $value = call_user_func( array( $invoice, "get_$field" ) ); |
|
187 | + if (is_callable(array($invoice, "get_$field"))) { |
|
188 | + $value = call_user_func(array($invoice, "get_$field")); |
|
189 | 189 | |
190 | 190 | // Only save if it is not empty. |
191 | - if ( ! empty( $value ) ) { |
|
192 | - $customer->set( $field, sanitize_text_field( $value ) ); |
|
191 | + if (!empty($value)) { |
|
192 | + $customer->set($field, sanitize_text_field($value)); |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | } |
196 | 196 | |
197 | 197 | $customer->save(); |
198 | 198 | |
199 | - if ( ! $invoice->get_customer_id() ) { |
|
200 | - $invoice->set_customer_id( $customer->get_id() ); |
|
199 | + if (!$invoice->get_customer_id()) { |
|
200 | + $invoice->set_customer_id($customer->get_id()); |
|
201 | 201 | $invoice->save(); |
202 | 202 | } |
203 | 203 | } |
204 | -add_action( 'getpaid_new_invoice', 'getpaid_save_invoice_user_address' ); |
|
205 | -add_action( 'getpaid_update_invoice', 'getpaid_save_invoice_user_address' ); |
|
204 | +add_action('getpaid_new_invoice', 'getpaid_save_invoice_user_address'); |
|
205 | +add_action('getpaid_update_invoice', 'getpaid_save_invoice_user_address'); |
|
206 | 206 | |
207 | 207 | /** |
208 | 208 | * Retrieves a saved user address. |
@@ -210,36 +210,36 @@ discard block |
||
210 | 210 | * @param int $user_id The user id whose address we should get. Defaults to the current user id. |
211 | 211 | * @return array |
212 | 212 | */ |
213 | -function wpinv_get_user_address( $user_id = 0 ) { |
|
213 | +function wpinv_get_user_address($user_id = 0) { |
|
214 | 214 | |
215 | 215 | // Prepare the user id. |
216 | - $user_id = empty( $user_id ) ? get_current_user_id() : $user_id; |
|
217 | - $user_info = get_userdata( $user_id ); |
|
216 | + $user_id = empty($user_id) ? get_current_user_id() : $user_id; |
|
217 | + $user_info = get_userdata($user_id); |
|
218 | 218 | |
219 | 219 | // Abort if non exists. |
220 | - if ( empty( $user_info ) ) { |
|
220 | + if (empty($user_info)) { |
|
221 | 221 | return array(); |
222 | 222 | } |
223 | 223 | |
224 | - $customer = getpaid_get_customer_by_user_id( $user_id ); |
|
224 | + $customer = getpaid_get_customer_by_user_id($user_id); |
|
225 | 225 | |
226 | - if ( empty( $customer ) ) { |
|
227 | - $customer = new GetPaid_Customer( 0 ); |
|
228 | - $customer->clone_user( $user_id ); |
|
226 | + if (empty($customer)) { |
|
227 | + $customer = new GetPaid_Customer(0); |
|
228 | + $customer->clone_user($user_id); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | // Prepare the address. |
232 | 232 | $address = array( |
233 | 233 | 'user_id' => $user_id, |
234 | - 'email' => $customer->get( 'email' ), |
|
234 | + 'email' => $customer->get('email'), |
|
235 | 235 | 'display_name' => $user_info->display_name, |
236 | 236 | ); |
237 | 237 | |
238 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
239 | - $address[ $field ] = $customer->get( $field ); |
|
238 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
239 | + $address[$field] = $customer->get($field); |
|
240 | 240 | } |
241 | 241 | |
242 | - $address = array_filter( $address ); |
|
242 | + $address = array_filter($address); |
|
243 | 243 | |
244 | 244 | $defaults = array( |
245 | 245 | 'first_name' => $user_info->first_name, |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | 'country' => wpinv_get_default_country(), |
249 | 249 | ); |
250 | 250 | |
251 | - return getpaid_array_merge_if_empty( $address, $defaults ); |
|
251 | + return getpaid_array_merge_if_empty($address, $defaults); |
|
252 | 252 | |
253 | 253 | } |
254 | 254 | |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | * @return string|null |
261 | 261 | * @deprecated |
262 | 262 | */ |
263 | -function getpaid_get_user_address_field( $user_id, $field ) { |
|
263 | +function getpaid_get_user_address_field($user_id, $field) { |
|
264 | 264 | |
265 | 265 | $prefixes = array( |
266 | 266 | '_wpinv_', |
@@ -268,15 +268,15 @@ discard block |
||
268 | 268 | '', |
269 | 269 | ); |
270 | 270 | |
271 | - foreach ( $prefixes as $prefix ) { |
|
271 | + foreach ($prefixes as $prefix) { |
|
272 | 272 | |
273 | 273 | // Meta table. |
274 | - $value = get_user_meta( $user_id, $prefix . $field, true ); |
|
274 | + $value = get_user_meta($user_id, $prefix . $field, true); |
|
275 | 275 | |
276 | 276 | // UWP table. |
277 | - $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value; |
|
277 | + $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value; |
|
278 | 278 | |
279 | - if ( ! empty( $value ) ) { |
|
279 | + if (!empty($value)) { |
|
280 | 280 | return $value; |
281 | 281 | } |
282 | 282 | } |
@@ -292,16 +292,16 @@ discard block |
||
292 | 292 | * @param string $return What to return. |
293 | 293 | * @return array |
294 | 294 | */ |
295 | -function wpinv_get_continents( $return = 'all' ) { |
|
295 | +function wpinv_get_continents($return = 'all') { |
|
296 | 296 | |
297 | - $continents = wpinv_get_data( 'continents' ); |
|
297 | + $continents = wpinv_get_data('continents'); |
|
298 | 298 | |
299 | - switch ( $return ) { |
|
299 | + switch ($return) { |
|
300 | 300 | case 'name': |
301 | - return wp_list_pluck( $continents, 'name' ); |
|
301 | + return wp_list_pluck($continents, 'name'); |
|
302 | 302 | break; |
303 | 303 | case 'countries': |
304 | - return wp_list_pluck( $continents, 'countries' ); |
|
304 | + return wp_list_pluck($continents, 'countries'); |
|
305 | 305 | break; |
306 | 306 | default: |
307 | 307 | return $continents; |
@@ -317,12 +317,12 @@ discard block |
||
317 | 317 | * @param string $country Country code. If no code is specified, defaults to the default country. |
318 | 318 | * @return string |
319 | 319 | */ |
320 | -function wpinv_get_continent_code_for_country( $country = false ) { |
|
320 | +function wpinv_get_continent_code_for_country($country = false) { |
|
321 | 321 | |
322 | - $country = wpinv_sanitize_country( $country ); |
|
322 | + $country = wpinv_sanitize_country($country); |
|
323 | 323 | |
324 | - foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
325 | - if ( false !== array_search( $country, $countries, true ) ) { |
|
324 | + foreach (wpinv_get_continents('countries') as $continent_code => $countries) { |
|
325 | + if (false !== array_search($country, $countries, true)) { |
|
326 | 326 | return $continent_code; |
327 | 327 | } |
328 | 328 | } |
@@ -338,13 +338,13 @@ discard block |
||
338 | 338 | * @param string $country Country code. If no code is specified, defaults to the default country. |
339 | 339 | * @return array |
340 | 340 | */ |
341 | -function wpinv_get_country_calling_code( $country = null ) { |
|
341 | +function wpinv_get_country_calling_code($country = null) { |
|
342 | 342 | |
343 | - $country = wpinv_sanitize_country( $country ); |
|
344 | - $codes = wpinv_get_data( 'phone-codes' ); |
|
345 | - $code = isset( $codes[ $country ] ) ? $codes[ $country ] : ''; |
|
343 | + $country = wpinv_sanitize_country($country); |
|
344 | + $codes = wpinv_get_data('phone-codes'); |
|
345 | + $code = isset($codes[$country]) ? $codes[$country] : ''; |
|
346 | 346 | |
347 | - if ( is_array( $code ) ) { |
|
347 | + if (is_array($code)) { |
|
348 | 348 | return $code[0]; |
349 | 349 | } |
350 | 350 | return $code; |
@@ -357,8 +357,8 @@ discard block |
||
357 | 357 | * @param bool $first_empty Whether or not the first item in the list should be empty |
358 | 358 | * @return array |
359 | 359 | */ |
360 | -function wpinv_get_country_list( $first_empty = false ) { |
|
361 | - return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty ); |
|
360 | +function wpinv_get_country_list($first_empty = false) { |
|
361 | + return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | /** |
@@ -368,22 +368,22 @@ discard block |
||
368 | 368 | * @param bool $first_empty Whether or not the first item in the list should be empty |
369 | 369 | * @return array |
370 | 370 | */ |
371 | -function wpinv_get_country_states( $country = null, $first_empty = false ) { |
|
371 | +function wpinv_get_country_states($country = null, $first_empty = false) { |
|
372 | 372 | |
373 | 373 | // Prepare the country. |
374 | - $country = wpinv_sanitize_country( $country ); |
|
374 | + $country = wpinv_sanitize_country($country); |
|
375 | 375 | |
376 | 376 | // Fetch all states. |
377 | - $all_states = wpinv_get_data( 'states' ); |
|
377 | + $all_states = wpinv_get_data('states'); |
|
378 | 378 | |
379 | 379 | // Fetch the specified country's states. |
380 | - $states = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array(); |
|
381 | - $states = apply_filters( "wpinv_{$country}_states", $states ); |
|
382 | - $states = apply_filters( 'wpinv_country_states', $states, $country ); |
|
380 | + $states = isset($all_states[$country]) ? $all_states[$country] : array(); |
|
381 | + $states = apply_filters("wpinv_{$country}_states", $states); |
|
382 | + $states = apply_filters('wpinv_country_states', $states, $country); |
|
383 | 383 | |
384 | - asort( $states ); |
|
384 | + asort($states); |
|
385 | 385 | |
386 | - return wpinv_maybe_add_empty_option( $states, $first_empty ); |
|
386 | + return wpinv_maybe_add_empty_option($states, $first_empty); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | /** |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | * @return array |
394 | 394 | */ |
395 | 395 | function wpinv_get_us_states_list() { |
396 | - return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) ); |
|
396 | + return apply_filters('wpinv_usa_states', wpinv_get_country_states('US')); |
|
397 | 397 | } |
398 | 398 | |
399 | 399 | /** |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | * @return array |
404 | 404 | */ |
405 | 405 | function wpinv_get_canada_states_list() { |
406 | - return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) ); |
|
406 | + return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA')); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | * @return array |
414 | 414 | */ |
415 | 415 | function wpinv_get_australia_states_list() { |
416 | - return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) ); |
|
416 | + return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU')); |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | /** |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | * @return array |
424 | 424 | */ |
425 | 425 | function wpinv_get_bangladesh_states_list() { |
426 | - return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) ); |
|
426 | + return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD')); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | /** |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | * @return array |
434 | 434 | */ |
435 | 435 | function wpinv_get_brazil_states_list() { |
436 | - return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) ); |
|
436 | + return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR')); |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | /** |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | * @return array |
444 | 444 | */ |
445 | 445 | function wpinv_get_bulgaria_states_list() { |
446 | - return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) ); |
|
446 | + return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG')); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | * @return array |
454 | 454 | */ |
455 | 455 | function wpinv_get_hong_kong_states_list() { |
456 | - return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) ); |
|
456 | + return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK')); |
|
457 | 457 | } |
458 | 458 | |
459 | 459 | /** |
@@ -463,7 +463,7 @@ discard block |
||
463 | 463 | * @return array |
464 | 464 | */ |
465 | 465 | function wpinv_get_hungary_states_list() { |
466 | - return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) ); |
|
466 | + return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU')); |
|
467 | 467 | } |
468 | 468 | |
469 | 469 | /** |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | * @return array |
474 | 474 | */ |
475 | 475 | function wpinv_get_japan_states_list() { |
476 | - return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) ); |
|
476 | + return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP')); |
|
477 | 477 | } |
478 | 478 | |
479 | 479 | /** |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | * @return array |
484 | 484 | */ |
485 | 485 | function wpinv_get_china_states_list() { |
486 | - return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) ); |
|
486 | + return apply_filters('wpinv_china_states', wpinv_get_country_states('CN')); |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | /** |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | * @return array |
494 | 494 | */ |
495 | 495 | function wpinv_get_new_zealand_states_list() { |
496 | - return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) ); |
|
496 | + return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ')); |
|
497 | 497 | } |
498 | 498 | |
499 | 499 | /** |
@@ -503,7 +503,7 @@ discard block |
||
503 | 503 | * @return array |
504 | 504 | */ |
505 | 505 | function wpinv_get_peru_states_list() { |
506 | - return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) ); |
|
506 | + return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE')); |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | /** |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | * @return array |
514 | 514 | */ |
515 | 515 | function wpinv_get_indonesia_states_list() { |
516 | - return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) ); |
|
516 | + return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID')); |
|
517 | 517 | } |
518 | 518 | |
519 | 519 | /** |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | * @return array |
524 | 524 | */ |
525 | 525 | function wpinv_get_india_states_list() { |
526 | - return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) ); |
|
526 | + return apply_filters('wpinv_india_states', wpinv_get_country_states('IN')); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | * @return array |
534 | 534 | */ |
535 | 535 | function wpinv_get_iran_states_list() { |
536 | - return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) ); |
|
536 | + return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR')); |
|
537 | 537 | } |
538 | 538 | |
539 | 539 | /** |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | * @return array |
544 | 544 | */ |
545 | 545 | function wpinv_get_italy_states_list() { |
546 | - return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) ); |
|
546 | + return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT')); |
|
547 | 547 | } |
548 | 548 | |
549 | 549 | /** |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | * @return array |
554 | 554 | */ |
555 | 555 | function wpinv_get_malaysia_states_list() { |
556 | - return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) ); |
|
556 | + return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY')); |
|
557 | 557 | } |
558 | 558 | |
559 | 559 | /** |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | * @return array |
564 | 564 | */ |
565 | 565 | function wpinv_get_mexico_states_list() { |
566 | - return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) ); |
|
566 | + return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX')); |
|
567 | 567 | } |
568 | 568 | |
569 | 569 | /** |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | * @return array |
574 | 574 | */ |
575 | 575 | function wpinv_get_nepal_states_list() { |
576 | - return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) ); |
|
576 | + return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP')); |
|
577 | 577 | } |
578 | 578 | |
579 | 579 | /** |
@@ -583,7 +583,7 @@ discard block |
||
583 | 583 | * @return array |
584 | 584 | */ |
585 | 585 | function wpinv_get_south_africa_states_list() { |
586 | - return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) ); |
|
586 | + return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA')); |
|
587 | 587 | } |
588 | 588 | |
589 | 589 | /** |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | * @return array |
594 | 594 | */ |
595 | 595 | function wpinv_get_thailand_states_list() { |
596 | - return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) ); |
|
596 | + return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH')); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | /** |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | * @return array |
604 | 604 | */ |
605 | 605 | function wpinv_get_turkey_states_list() { |
606 | - return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) ); |
|
606 | + return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR')); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | /** |
@@ -613,31 +613,31 @@ discard block |
||
613 | 613 | * @return array |
614 | 614 | */ |
615 | 615 | function wpinv_get_spain_states_list() { |
616 | - return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) ); |
|
616 | + return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES')); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | function wpinv_get_states_field() { |
620 | - if ( empty( $_POST['country'] ) ) { |
|
620 | + if (empty($_POST['country'])) { |
|
621 | 621 | $_POST['country'] = wpinv_get_default_country(); |
622 | 622 | } |
623 | - $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
623 | + $states = wpinv_get_country_states(sanitize_text_field($_POST['country'])); |
|
624 | 624 | |
625 | - if ( ! empty( $states ) ) { |
|
626 | - $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
625 | + if (!empty($states)) { |
|
626 | + $sanitized_field_name = sanitize_text_field($_POST['field_name']); |
|
627 | 627 | |
628 | - $class = isset( $_POST['class'] ) ? esc_attr( sanitize_text_field( $_POST['class'] ) ) : ''; |
|
628 | + $class = isset($_POST['class']) ? esc_attr(sanitize_text_field($_POST['class'])) : ''; |
|
629 | 629 | $class .= " $sanitized_field_name getpaid_js_field-state custom-select wpinv-select wpi_select2"; |
630 | 630 | |
631 | - $args = array( |
|
631 | + $args = array( |
|
632 | 632 | 'name' => $sanitized_field_name, |
633 | 633 | 'id' => $sanitized_field_name, |
634 | - 'class' => implode( ' ', array_unique( explode( ' ', $class ) ) ), |
|
635 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
634 | + 'class' => implode(' ', array_unique(explode(' ', $class))), |
|
635 | + 'options' => array_merge(array('' => ''), $states), |
|
636 | 636 | 'show_option_all' => false, |
637 | 637 | 'show_option_none' => false, |
638 | 638 | ); |
639 | 639 | |
640 | - wpinv_html_select( $args ); |
|
640 | + wpinv_html_select($args); |
|
641 | 641 | |
642 | 642 | } else { |
643 | 643 | echo 'nostates'; |
@@ -645,10 +645,10 @@ discard block |
||
645 | 645 | |
646 | 646 | } |
647 | 647 | |
648 | -function wpinv_default_billing_country( $country = '', $user_id = 0 ) { |
|
649 | - $country = ! empty( $country ) ? $country : wpinv_get_default_country(); |
|
648 | +function wpinv_default_billing_country($country = '', $user_id = 0) { |
|
649 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
650 | 650 | |
651 | - return apply_filters( 'wpinv_default_billing_country', $country, $user_id ); |
|
651 | + return apply_filters('wpinv_default_billing_country', $country, $user_id); |
|
652 | 652 | } |
653 | 653 | |
654 | 654 | /** |
@@ -710,9 +710,9 @@ discard block |
||
710 | 710 | * @see `wpinv_get_invoice_address_replacements` |
711 | 711 | * @return string |
712 | 712 | */ |
713 | -function wpinv_get_full_address_format( $country = false ) { |
|
713 | +function wpinv_get_full_address_format($country = false) { |
|
714 | 714 | |
715 | - if ( empty( $country ) ) { |
|
715 | + if (empty($country)) { |
|
716 | 716 | $country = wpinv_get_default_country(); |
717 | 717 | } |
718 | 718 | |
@@ -720,7 +720,7 @@ discard block |
||
720 | 720 | $formats = wpinv_get_address_formats(); |
721 | 721 | |
722 | 722 | // Get format for the specified country. |
723 | - $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
723 | + $format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default']; |
|
724 | 724 | |
725 | 725 | /** |
726 | 726 | * Filters the address format to use on Invoices. |
@@ -732,7 +732,7 @@ discard block |
||
732 | 732 | * @param string $format The address format to use. |
733 | 733 | * @param string $country The country who's address format is being retrieved. |
734 | 734 | */ |
735 | - return apply_filters( 'wpinv_get_full_address_format', $format, $country ); |
|
735 | + return apply_filters('wpinv_get_full_address_format', $format, $country); |
|
736 | 736 | } |
737 | 737 | |
738 | 738 | /** |
@@ -743,7 +743,7 @@ discard block |
||
743 | 743 | * @param array $billing_details customer's billing details |
744 | 744 | * @return array |
745 | 745 | */ |
746 | -function wpinv_get_invoice_address_replacements( $billing_details ) { |
|
746 | +function wpinv_get_invoice_address_replacements($billing_details) { |
|
747 | 747 | |
748 | 748 | $default_args = array( |
749 | 749 | 'address' => '', |
@@ -756,15 +756,15 @@ discard block |
||
756 | 756 | 'company' => '', |
757 | 757 | ); |
758 | 758 | |
759 | - $args = map_deep( wp_parse_args( array_filter( $billing_details ), $default_args ), 'trim' ); |
|
759 | + $args = map_deep(wp_parse_args(array_filter($billing_details), $default_args), 'trim'); |
|
760 | 760 | $state = $args['state']; |
761 | 761 | $country = $args['country']; |
762 | 762 | |
763 | 763 | // Handle full country name. |
764 | - $full_country = empty( $country ) ? $country : wpinv_country_name( $country ); |
|
764 | + $full_country = empty($country) ? $country : wpinv_country_name($country); |
|
765 | 765 | |
766 | 766 | // Handle full state name. |
767 | - $full_state = ( $country && $state ) ? wpinv_state_name( $state, $country ) : $state; |
|
767 | + $full_state = ($country && $state) ? wpinv_state_name($state, $country) : $state; |
|
768 | 768 | |
769 | 769 | $args['postcode'] = $args['zip']; |
770 | 770 | $args['name'] = $args['first_name'] . ' ' . $args['last_name']; |
@@ -782,14 +782,14 @@ discard block |
||
782 | 782 | * @param array $replacements The address replacements to use. |
783 | 783 | * @param array $billing_details The billing details to use. |
784 | 784 | */ |
785 | - $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details ); |
|
785 | + $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details); |
|
786 | 786 | |
787 | 787 | $return = array(); |
788 | 788 | |
789 | - foreach ( $replacements as $key => $value ) { |
|
790 | - $value = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : ''; |
|
791 | - $return[ '{{' . $key . '}}' ] = $value; |
|
792 | - $return[ '{{' . $key . '_upper}}' ] = wpinv_utf8_strtoupper( $value ); |
|
789 | + foreach ($replacements as $key => $value) { |
|
790 | + $value = is_scalar($value) ? trim(sanitize_text_field($value)) : ''; |
|
791 | + $return['{{' . $key . '}}'] = $value; |
|
792 | + $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value); |
|
793 | 793 | } |
794 | 794 | |
795 | 795 | return $return; |
@@ -803,6 +803,6 @@ discard block |
||
803 | 803 | * @since 1.0.14 |
804 | 804 | * @return string |
805 | 805 | */ |
806 | -function wpinv_trim_formatted_address_line( $line ) { |
|
807 | - return trim( $line, ', ' ); |
|
806 | +function wpinv_trim_formatted_address_line($line) { |
|
807 | + return trim($line, ', '); |
|
808 | 808 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
7 | - exit; |
|
7 | + exit; |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
@@ -14,228 +14,228 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class GetPaid_Item_Data_Store extends GetPaid_Data_Store_WP { |
16 | 16 | |
17 | - /** |
|
18 | - * Data stored in meta keys, but not considered "meta" for an item. |
|
19 | - * |
|
20 | - * @since 1.0.19 |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $internal_meta_keys = array( |
|
24 | - '_wpinv_price', |
|
25 | - '_wpinv_vat_rule', |
|
26 | - '_wpinv_vat_class', |
|
27 | - '_wpinv_type', |
|
28 | - '_wpinv_custom_id', |
|
29 | - '_wpinv_custom_name', |
|
30 | - '_wpinv_custom_singular_name', |
|
31 | - '_wpinv_editable', |
|
32 | - '_wpinv_dynamic_pricing', |
|
33 | - '_minimum_price', |
|
34 | - '_wpinv_is_recurring', |
|
35 | - '_wpinv_recurring_period', |
|
36 | - '_wpinv_recurring_interval', |
|
37 | - '_wpinv_recurring_limit', |
|
38 | - '_wpinv_free_trial', |
|
39 | - '_wpinv_trial_period', |
|
40 | - '_wpinv_trial_interval', |
|
41 | - ); |
|
42 | - |
|
43 | - /** |
|
44 | - * A map of meta keys to data props. |
|
45 | - * |
|
46 | - * @since 1.0.19 |
|
47 | - * |
|
48 | - * @var array |
|
49 | - */ |
|
50 | - protected $meta_key_to_props = array( |
|
51 | - '_wpinv_price' => 'price', |
|
52 | - '_wpinv_vat_rule' => 'vat_rule', |
|
53 | - '_wpinv_vat_class' => 'vat_class', |
|
54 | - '_wpinv_type' => 'type', |
|
55 | - '_wpinv_custom_id' => 'custom_id', |
|
56 | - '_wpinv_custom_name' => 'custom_name', |
|
57 | - '_wpinv_custom_singular_name' => 'custom_singular_name', |
|
58 | - '_wpinv_editable' => 'is_editable', |
|
59 | - '_wpinv_dynamic_pricing' => 'is_dynamic_pricing', |
|
60 | - '_minimum_price' => 'minimum_price', |
|
61 | - '_wpinv_custom_name' => 'custom_name', |
|
62 | - '_wpinv_is_recurring' => 'is_recurring', |
|
63 | - '_wpinv_recurring_period' => 'recurring_period', |
|
64 | - '_wpinv_recurring_interval' => 'recurring_interval', |
|
65 | - '_wpinv_recurring_limit' => 'recurring_limit', |
|
66 | - '_wpinv_free_trial' => 'is_free_trial', |
|
67 | - '_wpinv_trial_period' => 'trial_period', |
|
68 | - '_wpinv_trial_interval' => 'trial_interval', |
|
69 | - '_wpinv_version' => 'version', |
|
70 | - ); |
|
71 | - |
|
72 | - /* |
|
17 | + /** |
|
18 | + * Data stored in meta keys, but not considered "meta" for an item. |
|
19 | + * |
|
20 | + * @since 1.0.19 |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $internal_meta_keys = array( |
|
24 | + '_wpinv_price', |
|
25 | + '_wpinv_vat_rule', |
|
26 | + '_wpinv_vat_class', |
|
27 | + '_wpinv_type', |
|
28 | + '_wpinv_custom_id', |
|
29 | + '_wpinv_custom_name', |
|
30 | + '_wpinv_custom_singular_name', |
|
31 | + '_wpinv_editable', |
|
32 | + '_wpinv_dynamic_pricing', |
|
33 | + '_minimum_price', |
|
34 | + '_wpinv_is_recurring', |
|
35 | + '_wpinv_recurring_period', |
|
36 | + '_wpinv_recurring_interval', |
|
37 | + '_wpinv_recurring_limit', |
|
38 | + '_wpinv_free_trial', |
|
39 | + '_wpinv_trial_period', |
|
40 | + '_wpinv_trial_interval', |
|
41 | + ); |
|
42 | + |
|
43 | + /** |
|
44 | + * A map of meta keys to data props. |
|
45 | + * |
|
46 | + * @since 1.0.19 |
|
47 | + * |
|
48 | + * @var array |
|
49 | + */ |
|
50 | + protected $meta_key_to_props = array( |
|
51 | + '_wpinv_price' => 'price', |
|
52 | + '_wpinv_vat_rule' => 'vat_rule', |
|
53 | + '_wpinv_vat_class' => 'vat_class', |
|
54 | + '_wpinv_type' => 'type', |
|
55 | + '_wpinv_custom_id' => 'custom_id', |
|
56 | + '_wpinv_custom_name' => 'custom_name', |
|
57 | + '_wpinv_custom_singular_name' => 'custom_singular_name', |
|
58 | + '_wpinv_editable' => 'is_editable', |
|
59 | + '_wpinv_dynamic_pricing' => 'is_dynamic_pricing', |
|
60 | + '_minimum_price' => 'minimum_price', |
|
61 | + '_wpinv_custom_name' => 'custom_name', |
|
62 | + '_wpinv_is_recurring' => 'is_recurring', |
|
63 | + '_wpinv_recurring_period' => 'recurring_period', |
|
64 | + '_wpinv_recurring_interval' => 'recurring_interval', |
|
65 | + '_wpinv_recurring_limit' => 'recurring_limit', |
|
66 | + '_wpinv_free_trial' => 'is_free_trial', |
|
67 | + '_wpinv_trial_period' => 'trial_period', |
|
68 | + '_wpinv_trial_interval' => 'trial_interval', |
|
69 | + '_wpinv_version' => 'version', |
|
70 | + ); |
|
71 | + |
|
72 | + /* |
|
73 | 73 | |-------------------------------------------------------------------------- |
74 | 74 | | CRUD Methods |
75 | 75 | |-------------------------------------------------------------------------- |
76 | 76 | */ |
77 | 77 | |
78 | - /** |
|
79 | - * Method to create a new item in the database. |
|
80 | - * |
|
81 | - * @param WPInv_Item $item Item object. |
|
82 | - */ |
|
83 | - public function create( &$item ) { |
|
84 | - $item->set_version( WPINV_VERSION ); |
|
85 | - $item->set_date_created( current_time( 'mysql' ) ); |
|
86 | - |
|
87 | - // Create a new post. |
|
88 | - $id = wp_insert_post( |
|
89 | - apply_filters( |
|
90 | - 'getpaid_new_item_data', |
|
91 | - array( |
|
92 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
93 | - 'post_type' => 'wpi_item', |
|
94 | - 'post_status' => $this->get_post_status( $item ), |
|
95 | - 'ping_status' => 'closed', |
|
96 | - 'post_author' => $item->get_author( 'edit' ), |
|
97 | - 'post_title' => $item->get_name( 'edit' ), |
|
98 | - 'post_parent' => $item->get_parent_id(), |
|
99 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
100 | - ) |
|
101 | - ), |
|
102 | - true |
|
103 | - ); |
|
104 | - |
|
105 | - if ( $id && ! is_wp_error( $id ) ) { |
|
106 | - $item->set_id( $id ); |
|
107 | - $this->update_post_meta( $item ); |
|
108 | - $item->save_meta_data(); |
|
109 | - $item->apply_changes(); |
|
110 | - $this->clear_caches( $item ); |
|
111 | - do_action( 'getpaid_new_item', $item ); |
|
112 | - return true; |
|
113 | - } |
|
114 | - |
|
115 | - if ( is_wp_error( $id ) ) { |
|
116 | - $item->last_error = $id->get_error_message(); |
|
117 | - } |
|
118 | - |
|
119 | - return false; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Method to read an item from the database. |
|
124 | - * |
|
125 | - * @param WPInv_Item $item Item object. |
|
126 | - * |
|
127 | - */ |
|
128 | - public function read( &$item ) { |
|
129 | - |
|
130 | - $item->set_defaults(); |
|
131 | - $item_object = get_post( $item->get_id() ); |
|
132 | - |
|
133 | - if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) { |
|
134 | - $item->last_error = __( 'Invalid item.', 'invoicing' ); |
|
135 | - $item->set_id( 0 ); |
|
136 | - return false; |
|
137 | - } |
|
138 | - |
|
139 | - $item->set_props( |
|
140 | - array( |
|
141 | - 'parent_id' => $item_object->post_parent, |
|
142 | - 'date_created' => 0 < $item_object->post_date ? $item_object->post_date : null, |
|
143 | - 'date_modified' => 0 < $item_object->post_modified ? $item_object->post_modified : null, |
|
144 | - 'status' => $item_object->post_status, |
|
145 | - 'name' => $item_object->post_title, |
|
146 | - 'description' => $item_object->post_excerpt, |
|
147 | - 'author' => $item_object->post_author, |
|
148 | - ) |
|
149 | - ); |
|
150 | - |
|
151 | - $this->read_object_data( $item, $item_object ); |
|
152 | - $item->read_meta_data(); |
|
153 | - $item->set_object_read( true ); |
|
154 | - do_action( 'getpaid_read_item', $item ); |
|
155 | - |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * Method to update an item in the database. |
|
160 | - * |
|
161 | - * @param WPInv_Item $item Item object. |
|
162 | - */ |
|
163 | - public function update( &$item ) { |
|
164 | - $item->save_meta_data(); |
|
165 | - $item->set_version( WPINV_VERSION ); |
|
166 | - |
|
167 | - if ( null === $item->get_date_created( 'edit' ) ) { |
|
168 | - $item->set_date_created( current_time( 'mysql' ) ); |
|
169 | - } |
|
170 | - |
|
171 | - // Grab the current status so we can compare. |
|
172 | - $previous_status = get_post_status( $item->get_id() ); |
|
173 | - |
|
174 | - $changes = $item->get_changes(); |
|
175 | - |
|
176 | - // Only update the post when the post data changes. |
|
177 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'description', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
178 | - $post_data = array( |
|
179 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
180 | - 'post_status' => $item->get_status( 'edit' ), |
|
181 | - 'post_parent' => $item->get_parent_id( 'edit' ), |
|
182 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
183 | - 'post_modified' => $item->get_date_modified( 'edit' ), |
|
184 | - 'post_title' => $item->get_name( 'edit' ), |
|
185 | - 'post_author' => $item->get_author( 'edit' ), |
|
186 | - ); |
|
187 | - |
|
188 | - /** |
|
189 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
190 | - * to update data, since wp_update_post spawns more calls to the |
|
191 | - * save_post action. |
|
192 | - * |
|
193 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
194 | - * or an update purely from CRUD. |
|
195 | - */ |
|
196 | - if ( doing_action( 'save_post' ) ) { |
|
197 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) ); |
|
198 | - clean_post_cache( $item->get_id() ); |
|
199 | - } else { |
|
200 | - wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) ); |
|
201 | - } |
|
202 | - $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
203 | - } |
|
204 | - $this->update_post_meta( $item ); |
|
205 | - $item->apply_changes(); |
|
206 | - $this->clear_caches( $item ); |
|
207 | - |
|
208 | - // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
209 | - $new_status = $item->get_status( 'edit' ); |
|
210 | - |
|
211 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
212 | - do_action( 'getpaid_new_item', $item ); |
|
213 | - } else { |
|
214 | - do_action( 'getpaid_update_item', $item ); |
|
215 | - } |
|
216 | - |
|
217 | - } |
|
218 | - |
|
219 | - /* |
|
78 | + /** |
|
79 | + * Method to create a new item in the database. |
|
80 | + * |
|
81 | + * @param WPInv_Item $item Item object. |
|
82 | + */ |
|
83 | + public function create( &$item ) { |
|
84 | + $item->set_version( WPINV_VERSION ); |
|
85 | + $item->set_date_created( current_time( 'mysql' ) ); |
|
86 | + |
|
87 | + // Create a new post. |
|
88 | + $id = wp_insert_post( |
|
89 | + apply_filters( |
|
90 | + 'getpaid_new_item_data', |
|
91 | + array( |
|
92 | + 'post_date' => $item->get_date_created( 'edit' ), |
|
93 | + 'post_type' => 'wpi_item', |
|
94 | + 'post_status' => $this->get_post_status( $item ), |
|
95 | + 'ping_status' => 'closed', |
|
96 | + 'post_author' => $item->get_author( 'edit' ), |
|
97 | + 'post_title' => $item->get_name( 'edit' ), |
|
98 | + 'post_parent' => $item->get_parent_id(), |
|
99 | + 'post_excerpt' => $item->get_description( 'edit' ), |
|
100 | + ) |
|
101 | + ), |
|
102 | + true |
|
103 | + ); |
|
104 | + |
|
105 | + if ( $id && ! is_wp_error( $id ) ) { |
|
106 | + $item->set_id( $id ); |
|
107 | + $this->update_post_meta( $item ); |
|
108 | + $item->save_meta_data(); |
|
109 | + $item->apply_changes(); |
|
110 | + $this->clear_caches( $item ); |
|
111 | + do_action( 'getpaid_new_item', $item ); |
|
112 | + return true; |
|
113 | + } |
|
114 | + |
|
115 | + if ( is_wp_error( $id ) ) { |
|
116 | + $item->last_error = $id->get_error_message(); |
|
117 | + } |
|
118 | + |
|
119 | + return false; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Method to read an item from the database. |
|
124 | + * |
|
125 | + * @param WPInv_Item $item Item object. |
|
126 | + * |
|
127 | + */ |
|
128 | + public function read( &$item ) { |
|
129 | + |
|
130 | + $item->set_defaults(); |
|
131 | + $item_object = get_post( $item->get_id() ); |
|
132 | + |
|
133 | + if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) { |
|
134 | + $item->last_error = __( 'Invalid item.', 'invoicing' ); |
|
135 | + $item->set_id( 0 ); |
|
136 | + return false; |
|
137 | + } |
|
138 | + |
|
139 | + $item->set_props( |
|
140 | + array( |
|
141 | + 'parent_id' => $item_object->post_parent, |
|
142 | + 'date_created' => 0 < $item_object->post_date ? $item_object->post_date : null, |
|
143 | + 'date_modified' => 0 < $item_object->post_modified ? $item_object->post_modified : null, |
|
144 | + 'status' => $item_object->post_status, |
|
145 | + 'name' => $item_object->post_title, |
|
146 | + 'description' => $item_object->post_excerpt, |
|
147 | + 'author' => $item_object->post_author, |
|
148 | + ) |
|
149 | + ); |
|
150 | + |
|
151 | + $this->read_object_data( $item, $item_object ); |
|
152 | + $item->read_meta_data(); |
|
153 | + $item->set_object_read( true ); |
|
154 | + do_action( 'getpaid_read_item', $item ); |
|
155 | + |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * Method to update an item in the database. |
|
160 | + * |
|
161 | + * @param WPInv_Item $item Item object. |
|
162 | + */ |
|
163 | + public function update( &$item ) { |
|
164 | + $item->save_meta_data(); |
|
165 | + $item->set_version( WPINV_VERSION ); |
|
166 | + |
|
167 | + if ( null === $item->get_date_created( 'edit' ) ) { |
|
168 | + $item->set_date_created( current_time( 'mysql' ) ); |
|
169 | + } |
|
170 | + |
|
171 | + // Grab the current status so we can compare. |
|
172 | + $previous_status = get_post_status( $item->get_id() ); |
|
173 | + |
|
174 | + $changes = $item->get_changes(); |
|
175 | + |
|
176 | + // Only update the post when the post data changes. |
|
177 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'description', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
178 | + $post_data = array( |
|
179 | + 'post_date' => $item->get_date_created( 'edit' ), |
|
180 | + 'post_status' => $item->get_status( 'edit' ), |
|
181 | + 'post_parent' => $item->get_parent_id( 'edit' ), |
|
182 | + 'post_excerpt' => $item->get_description( 'edit' ), |
|
183 | + 'post_modified' => $item->get_date_modified( 'edit' ), |
|
184 | + 'post_title' => $item->get_name( 'edit' ), |
|
185 | + 'post_author' => $item->get_author( 'edit' ), |
|
186 | + ); |
|
187 | + |
|
188 | + /** |
|
189 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
190 | + * to update data, since wp_update_post spawns more calls to the |
|
191 | + * save_post action. |
|
192 | + * |
|
193 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
194 | + * or an update purely from CRUD. |
|
195 | + */ |
|
196 | + if ( doing_action( 'save_post' ) ) { |
|
197 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) ); |
|
198 | + clean_post_cache( $item->get_id() ); |
|
199 | + } else { |
|
200 | + wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) ); |
|
201 | + } |
|
202 | + $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
203 | + } |
|
204 | + $this->update_post_meta( $item ); |
|
205 | + $item->apply_changes(); |
|
206 | + $this->clear_caches( $item ); |
|
207 | + |
|
208 | + // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
209 | + $new_status = $item->get_status( 'edit' ); |
|
210 | + |
|
211 | + if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
212 | + do_action( 'getpaid_new_item', $item ); |
|
213 | + } else { |
|
214 | + do_action( 'getpaid_update_item', $item ); |
|
215 | + } |
|
216 | + |
|
217 | + } |
|
218 | + |
|
219 | + /* |
|
220 | 220 | |-------------------------------------------------------------------------- |
221 | 221 | | Additional Methods |
222 | 222 | |-------------------------------------------------------------------------- |
223 | 223 | */ |
224 | 224 | |
225 | - /** |
|
226 | - * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class. |
|
227 | - * |
|
228 | - * @param WPInv_Item $item WPInv_Item object. |
|
229 | - * @since 1.0.19 |
|
230 | - */ |
|
231 | - protected function update_post_meta( &$item ) { |
|
225 | + /** |
|
226 | + * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class. |
|
227 | + * |
|
228 | + * @param WPInv_Item $item WPInv_Item object. |
|
229 | + * @since 1.0.19 |
|
230 | + */ |
|
231 | + protected function update_post_meta( &$item ) { |
|
232 | 232 | |
233 | - // Ensure that we have a custom id. |
|
233 | + // Ensure that we have a custom id. |
|
234 | 234 | if ( ! $item->get_custom_id() ) { |
235 | 235 | $item->set_custom_id( $item->get_id() ); |
236 | - } |
|
236 | + } |
|
237 | 237 | |
238 | - parent::update_post_meta( $item ); |
|
239 | - } |
|
238 | + parent::update_post_meta( $item ); |
|
239 | + } |
|
240 | 240 | |
241 | 241 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * GetPaid_Item_Data_Store class file. |
4 | 4 | * |
5 | 5 | */ |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -80,39 +80,39 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @param WPInv_Item $item Item object. |
82 | 82 | */ |
83 | - public function create( &$item ) { |
|
84 | - $item->set_version( WPINV_VERSION ); |
|
85 | - $item->set_date_created( current_time( 'mysql' ) ); |
|
83 | + public function create(&$item) { |
|
84 | + $item->set_version(WPINV_VERSION); |
|
85 | + $item->set_date_created(current_time('mysql')); |
|
86 | 86 | |
87 | 87 | // Create a new post. |
88 | 88 | $id = wp_insert_post( |
89 | 89 | apply_filters( |
90 | 90 | 'getpaid_new_item_data', |
91 | 91 | array( |
92 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
92 | + 'post_date' => $item->get_date_created('edit'), |
|
93 | 93 | 'post_type' => 'wpi_item', |
94 | - 'post_status' => $this->get_post_status( $item ), |
|
94 | + 'post_status' => $this->get_post_status($item), |
|
95 | 95 | 'ping_status' => 'closed', |
96 | - 'post_author' => $item->get_author( 'edit' ), |
|
97 | - 'post_title' => $item->get_name( 'edit' ), |
|
96 | + 'post_author' => $item->get_author('edit'), |
|
97 | + 'post_title' => $item->get_name('edit'), |
|
98 | 98 | 'post_parent' => $item->get_parent_id(), |
99 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
99 | + 'post_excerpt' => $item->get_description('edit'), |
|
100 | 100 | ) |
101 | 101 | ), |
102 | 102 | true |
103 | 103 | ); |
104 | 104 | |
105 | - if ( $id && ! is_wp_error( $id ) ) { |
|
106 | - $item->set_id( $id ); |
|
107 | - $this->update_post_meta( $item ); |
|
105 | + if ($id && !is_wp_error($id)) { |
|
106 | + $item->set_id($id); |
|
107 | + $this->update_post_meta($item); |
|
108 | 108 | $item->save_meta_data(); |
109 | 109 | $item->apply_changes(); |
110 | - $this->clear_caches( $item ); |
|
111 | - do_action( 'getpaid_new_item', $item ); |
|
110 | + $this->clear_caches($item); |
|
111 | + do_action('getpaid_new_item', $item); |
|
112 | 112 | return true; |
113 | 113 | } |
114 | 114 | |
115 | - if ( is_wp_error( $id ) ) { |
|
115 | + if (is_wp_error($id)) { |
|
116 | 116 | $item->last_error = $id->get_error_message(); |
117 | 117 | } |
118 | 118 | |
@@ -125,14 +125,14 @@ discard block |
||
125 | 125 | * @param WPInv_Item $item Item object. |
126 | 126 | * |
127 | 127 | */ |
128 | - public function read( &$item ) { |
|
128 | + public function read(&$item) { |
|
129 | 129 | |
130 | 130 | $item->set_defaults(); |
131 | - $item_object = get_post( $item->get_id() ); |
|
131 | + $item_object = get_post($item->get_id()); |
|
132 | 132 | |
133 | - if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) { |
|
134 | - $item->last_error = __( 'Invalid item.', 'invoicing' ); |
|
135 | - $item->set_id( 0 ); |
|
133 | + if (!$item->get_id() || !$item_object || $item_object->post_type != 'wpi_item') { |
|
134 | + $item->last_error = __('Invalid item.', 'invoicing'); |
|
135 | + $item->set_id(0); |
|
136 | 136 | return false; |
137 | 137 | } |
138 | 138 | |
@@ -148,10 +148,10 @@ discard block |
||
148 | 148 | ) |
149 | 149 | ); |
150 | 150 | |
151 | - $this->read_object_data( $item, $item_object ); |
|
151 | + $this->read_object_data($item, $item_object); |
|
152 | 152 | $item->read_meta_data(); |
153 | - $item->set_object_read( true ); |
|
154 | - do_action( 'getpaid_read_item', $item ); |
|
153 | + $item->set_object_read(true); |
|
154 | + do_action('getpaid_read_item', $item); |
|
155 | 155 | |
156 | 156 | } |
157 | 157 | |
@@ -160,29 +160,29 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @param WPInv_Item $item Item object. |
162 | 162 | */ |
163 | - public function update( &$item ) { |
|
163 | + public function update(&$item) { |
|
164 | 164 | $item->save_meta_data(); |
165 | - $item->set_version( WPINV_VERSION ); |
|
165 | + $item->set_version(WPINV_VERSION); |
|
166 | 166 | |
167 | - if ( null === $item->get_date_created( 'edit' ) ) { |
|
168 | - $item->set_date_created( current_time( 'mysql' ) ); |
|
167 | + if (null === $item->get_date_created('edit')) { |
|
168 | + $item->set_date_created(current_time('mysql')); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | // Grab the current status so we can compare. |
172 | - $previous_status = get_post_status( $item->get_id() ); |
|
172 | + $previous_status = get_post_status($item->get_id()); |
|
173 | 173 | |
174 | 174 | $changes = $item->get_changes(); |
175 | 175 | |
176 | 176 | // Only update the post when the post data changes. |
177 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'description', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
177 | + if (array_intersect(array('date_created', 'date_modified', 'status', 'parent_id', 'description', 'name', 'author'), array_keys($changes))) { |
|
178 | 178 | $post_data = array( |
179 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
180 | - 'post_status' => $item->get_status( 'edit' ), |
|
181 | - 'post_parent' => $item->get_parent_id( 'edit' ), |
|
182 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
183 | - 'post_modified' => $item->get_date_modified( 'edit' ), |
|
184 | - 'post_title' => $item->get_name( 'edit' ), |
|
185 | - 'post_author' => $item->get_author( 'edit' ), |
|
179 | + 'post_date' => $item->get_date_created('edit'), |
|
180 | + 'post_status' => $item->get_status('edit'), |
|
181 | + 'post_parent' => $item->get_parent_id('edit'), |
|
182 | + 'post_excerpt' => $item->get_description('edit'), |
|
183 | + 'post_modified' => $item->get_date_modified('edit'), |
|
184 | + 'post_title' => $item->get_name('edit'), |
|
185 | + 'post_author' => $item->get_author('edit'), |
|
186 | 186 | ); |
187 | 187 | |
188 | 188 | /** |
@@ -193,25 +193,25 @@ discard block |
||
193 | 193 | * This ensures hooks are fired by either WP itself (admin screen save), |
194 | 194 | * or an update purely from CRUD. |
195 | 195 | */ |
196 | - if ( doing_action( 'save_post' ) ) { |
|
197 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) ); |
|
198 | - clean_post_cache( $item->get_id() ); |
|
196 | + if (doing_action('save_post')) { |
|
197 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $item->get_id())); |
|
198 | + clean_post_cache($item->get_id()); |
|
199 | 199 | } else { |
200 | - wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) ); |
|
200 | + wp_update_post(array_merge(array('ID' => $item->get_id()), $post_data)); |
|
201 | 201 | } |
202 | - $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
202 | + $item->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
203 | 203 | } |
204 | - $this->update_post_meta( $item ); |
|
204 | + $this->update_post_meta($item); |
|
205 | 205 | $item->apply_changes(); |
206 | - $this->clear_caches( $item ); |
|
206 | + $this->clear_caches($item); |
|
207 | 207 | |
208 | 208 | // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
209 | - $new_status = $item->get_status( 'edit' ); |
|
209 | + $new_status = $item->get_status('edit'); |
|
210 | 210 | |
211 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
212 | - do_action( 'getpaid_new_item', $item ); |
|
211 | + if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) { |
|
212 | + do_action('getpaid_new_item', $item); |
|
213 | 213 | } else { |
214 | - do_action( 'getpaid_update_item', $item ); |
|
214 | + do_action('getpaid_update_item', $item); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | } |
@@ -228,14 +228,14 @@ discard block |
||
228 | 228 | * @param WPInv_Item $item WPInv_Item object. |
229 | 229 | * @since 1.0.19 |
230 | 230 | */ |
231 | - protected function update_post_meta( &$item ) { |
|
231 | + protected function update_post_meta(&$item) { |
|
232 | 232 | |
233 | 233 | // Ensure that we have a custom id. |
234 | - if ( ! $item->get_custom_id() ) { |
|
235 | - $item->set_custom_id( $item->get_id() ); |
|
234 | + if (!$item->get_custom_id()) { |
|
235 | + $item->set_custom_id($item->get_id()); |
|
236 | 236 | } |
237 | 237 | |
238 | - parent::update_post_meta( $item ); |
|
238 | + parent::update_post_meta($item); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,199 +10,199 @@ discard block |
||
10 | 10 | class GetPaid_Payment_Form_Submission { |
11 | 11 | |
12 | 12 | /** |
13 | - * Submission ID |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - public $id = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * The raw submission data. |
|
21 | - * |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $data = null; |
|
25 | - |
|
26 | - /** |
|
27 | - * Submission totals |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $totals = array( |
|
32 | - |
|
33 | - 'subtotal' => array( |
|
34 | - 'initial' => 0, |
|
35 | - 'recurring' => 0, |
|
36 | - ), |
|
37 | - |
|
38 | - 'discount' => array( |
|
39 | - 'initial' => 0, |
|
40 | - 'recurring' => 0, |
|
41 | - ), |
|
42 | - |
|
43 | - 'fees' => array( |
|
44 | - 'initial' => 0, |
|
45 | - 'recurring' => 0, |
|
46 | - ), |
|
47 | - |
|
48 | - 'taxes' => array( |
|
49 | - 'initial' => 0, |
|
50 | - 'recurring' => 0, |
|
51 | - ), |
|
52 | - |
|
53 | - 'shipping' => array( |
|
54 | - 'initial' => 0, |
|
55 | - 'recurring' => 0, |
|
56 | - ), |
|
57 | - |
|
58 | - ); |
|
59 | - |
|
60 | - /** |
|
61 | - * Sets the associated payment form. |
|
62 | - * |
|
63 | - * @var GetPaid_Payment_Form |
|
64 | - */ |
|
13 | + * Submission ID |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + public $id = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * The raw submission data. |
|
21 | + * |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $data = null; |
|
25 | + |
|
26 | + /** |
|
27 | + * Submission totals |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $totals = array( |
|
32 | + |
|
33 | + 'subtotal' => array( |
|
34 | + 'initial' => 0, |
|
35 | + 'recurring' => 0, |
|
36 | + ), |
|
37 | + |
|
38 | + 'discount' => array( |
|
39 | + 'initial' => 0, |
|
40 | + 'recurring' => 0, |
|
41 | + ), |
|
42 | + |
|
43 | + 'fees' => array( |
|
44 | + 'initial' => 0, |
|
45 | + 'recurring' => 0, |
|
46 | + ), |
|
47 | + |
|
48 | + 'taxes' => array( |
|
49 | + 'initial' => 0, |
|
50 | + 'recurring' => 0, |
|
51 | + ), |
|
52 | + |
|
53 | + 'shipping' => array( |
|
54 | + 'initial' => 0, |
|
55 | + 'recurring' => 0, |
|
56 | + ), |
|
57 | + |
|
58 | + ); |
|
59 | + |
|
60 | + /** |
|
61 | + * Sets the associated payment form. |
|
62 | + * |
|
63 | + * @var GetPaid_Payment_Form |
|
64 | + */ |
|
65 | 65 | protected $payment_form = null; |
66 | 66 | |
67 | 67 | /** |
68 | - * The country for the submission. |
|
69 | - * |
|
70 | - * @var string |
|
71 | - */ |
|
72 | - public $country = null; |
|
73 | - |
|
74 | - /** |
|
75 | - * The state for the submission. |
|
76 | - * |
|
77 | - * @since 1.0.19 |
|
78 | - * @var string |
|
79 | - */ |
|
80 | - public $state = null; |
|
81 | - |
|
82 | - /** |
|
83 | - * The invoice associated with the submission. |
|
84 | - * |
|
85 | - * @var WPInv_Invoice |
|
86 | - */ |
|
87 | - protected $invoice = null; |
|
88 | - |
|
89 | - /** |
|
90 | - * The recurring item for the submission. |
|
91 | - * |
|
92 | - * @var int |
|
93 | - */ |
|
94 | - public $has_recurring = 0; |
|
95 | - |
|
96 | - /** |
|
97 | - * An array of fees for the submission. |
|
98 | - * |
|
99 | - * @var array |
|
100 | - */ |
|
101 | - protected $fees = array(); |
|
102 | - |
|
103 | - /** |
|
104 | - * An array of discounts for the submission. |
|
105 | - * |
|
106 | - * @var array |
|
107 | - */ |
|
108 | - protected $discounts = array(); |
|
109 | - |
|
110 | - /** |
|
111 | - * An array of taxes for the submission. |
|
112 | - * |
|
113 | - * @var array |
|
114 | - */ |
|
115 | - protected $taxes = array(); |
|
116 | - |
|
117 | - /** |
|
118 | - * An array of items for the submission. |
|
119 | - * |
|
120 | - * @var GetPaid_Form_Item[] |
|
121 | - */ |
|
122 | - protected $items = array(); |
|
123 | - |
|
124 | - /** |
|
125 | - * The last error. |
|
126 | - * |
|
127 | - * @var string |
|
128 | - */ |
|
129 | - public $last_error = null; |
|
130 | - |
|
131 | - /** |
|
132 | - * The last error code. |
|
133 | - * |
|
134 | - * @var string |
|
135 | - */ |
|
136 | - public $last_error_code = null; |
|
137 | - |
|
138 | - /** |
|
139 | - * Class constructor. |
|
140 | - * |
|
141 | - */ |
|
142 | - public function __construct() { |
|
143 | - |
|
144 | - // Set the state and country to the default state and country. |
|
145 | - $this->country = wpinv_default_billing_country(); |
|
146 | - $this->state = wpinv_get_default_state(); |
|
147 | - |
|
148 | - // Do we have an actual submission? |
|
149 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
150 | - $this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) ); |
|
151 | - } |
|
152 | - |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Loads submission data. |
|
157 | - * |
|
158 | - * @param array $data |
|
159 | - */ |
|
160 | - public function load_data( $data ) { |
|
161 | - |
|
162 | - // Allow plugins to filter the data. |
|
163 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
164 | - |
|
165 | - // Cache it... |
|
166 | - $this->data = $data; |
|
167 | - |
|
168 | - // Then generate a unique id from the data. |
|
169 | - $this->id = md5( wp_json_encode( $data ) ); |
|
170 | - |
|
171 | - // Finally, process the submission. |
|
172 | - try { |
|
173 | - |
|
174 | - // Each process is passed an instance of the class (with reference) |
|
175 | - // and should throw an Exception whenever it encounters one. |
|
176 | - $processors = apply_filters( |
|
177 | - 'getpaid_payment_form_submission_processors', |
|
178 | - array( |
|
179 | - array( $this, 'process_payment_form' ), |
|
180 | - array( $this, 'process_invoice' ), |
|
181 | - array( $this, 'process_fees' ), |
|
182 | - array( $this, 'process_items' ), |
|
183 | - array( $this, 'process_discount' ), |
|
184 | - array( $this, 'process_taxes' ), |
|
185 | - ), |
|
186 | - $this |
|
187 | - ); |
|
188 | - |
|
189 | - foreach ( $processors as $processor ) { |
|
190 | - call_user_func_array( $processor, array( &$this ) ); |
|
191 | - } |
|
192 | - } catch ( GetPaid_Payment_Exception $e ) { |
|
193 | - $this->last_error = $e->getMessage(); |
|
194 | - $this->last_error_code = $e->getErrorCode(); |
|
195 | - } catch ( Exception $e ) { |
|
196 | - $this->last_error = $e->getMessage(); |
|
197 | - $this->last_error_code = $e->getCode(); |
|
198 | - } |
|
199 | - |
|
200 | - // Fired when we are done processing a submission. |
|
201 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
202 | - |
|
203 | - } |
|
204 | - |
|
205 | - /* |
|
68 | + * The country for the submission. |
|
69 | + * |
|
70 | + * @var string |
|
71 | + */ |
|
72 | + public $country = null; |
|
73 | + |
|
74 | + /** |
|
75 | + * The state for the submission. |
|
76 | + * |
|
77 | + * @since 1.0.19 |
|
78 | + * @var string |
|
79 | + */ |
|
80 | + public $state = null; |
|
81 | + |
|
82 | + /** |
|
83 | + * The invoice associated with the submission. |
|
84 | + * |
|
85 | + * @var WPInv_Invoice |
|
86 | + */ |
|
87 | + protected $invoice = null; |
|
88 | + |
|
89 | + /** |
|
90 | + * The recurring item for the submission. |
|
91 | + * |
|
92 | + * @var int |
|
93 | + */ |
|
94 | + public $has_recurring = 0; |
|
95 | + |
|
96 | + /** |
|
97 | + * An array of fees for the submission. |
|
98 | + * |
|
99 | + * @var array |
|
100 | + */ |
|
101 | + protected $fees = array(); |
|
102 | + |
|
103 | + /** |
|
104 | + * An array of discounts for the submission. |
|
105 | + * |
|
106 | + * @var array |
|
107 | + */ |
|
108 | + protected $discounts = array(); |
|
109 | + |
|
110 | + /** |
|
111 | + * An array of taxes for the submission. |
|
112 | + * |
|
113 | + * @var array |
|
114 | + */ |
|
115 | + protected $taxes = array(); |
|
116 | + |
|
117 | + /** |
|
118 | + * An array of items for the submission. |
|
119 | + * |
|
120 | + * @var GetPaid_Form_Item[] |
|
121 | + */ |
|
122 | + protected $items = array(); |
|
123 | + |
|
124 | + /** |
|
125 | + * The last error. |
|
126 | + * |
|
127 | + * @var string |
|
128 | + */ |
|
129 | + public $last_error = null; |
|
130 | + |
|
131 | + /** |
|
132 | + * The last error code. |
|
133 | + * |
|
134 | + * @var string |
|
135 | + */ |
|
136 | + public $last_error_code = null; |
|
137 | + |
|
138 | + /** |
|
139 | + * Class constructor. |
|
140 | + * |
|
141 | + */ |
|
142 | + public function __construct() { |
|
143 | + |
|
144 | + // Set the state and country to the default state and country. |
|
145 | + $this->country = wpinv_default_billing_country(); |
|
146 | + $this->state = wpinv_get_default_state(); |
|
147 | + |
|
148 | + // Do we have an actual submission? |
|
149 | + if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
150 | + $this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) ); |
|
151 | + } |
|
152 | + |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Loads submission data. |
|
157 | + * |
|
158 | + * @param array $data |
|
159 | + */ |
|
160 | + public function load_data( $data ) { |
|
161 | + |
|
162 | + // Allow plugins to filter the data. |
|
163 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
164 | + |
|
165 | + // Cache it... |
|
166 | + $this->data = $data; |
|
167 | + |
|
168 | + // Then generate a unique id from the data. |
|
169 | + $this->id = md5( wp_json_encode( $data ) ); |
|
170 | + |
|
171 | + // Finally, process the submission. |
|
172 | + try { |
|
173 | + |
|
174 | + // Each process is passed an instance of the class (with reference) |
|
175 | + // and should throw an Exception whenever it encounters one. |
|
176 | + $processors = apply_filters( |
|
177 | + 'getpaid_payment_form_submission_processors', |
|
178 | + array( |
|
179 | + array( $this, 'process_payment_form' ), |
|
180 | + array( $this, 'process_invoice' ), |
|
181 | + array( $this, 'process_fees' ), |
|
182 | + array( $this, 'process_items' ), |
|
183 | + array( $this, 'process_discount' ), |
|
184 | + array( $this, 'process_taxes' ), |
|
185 | + ), |
|
186 | + $this |
|
187 | + ); |
|
188 | + |
|
189 | + foreach ( $processors as $processor ) { |
|
190 | + call_user_func_array( $processor, array( &$this ) ); |
|
191 | + } |
|
192 | + } catch ( GetPaid_Payment_Exception $e ) { |
|
193 | + $this->last_error = $e->getMessage(); |
|
194 | + $this->last_error_code = $e->getErrorCode(); |
|
195 | + } catch ( Exception $e ) { |
|
196 | + $this->last_error = $e->getMessage(); |
|
197 | + $this->last_error_code = $e->getCode(); |
|
198 | + } |
|
199 | + |
|
200 | + // Fired when we are done processing a submission. |
|
201 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
202 | + |
|
203 | + } |
|
204 | + |
|
205 | + /* |
|
206 | 206 | |-------------------------------------------------------------------------- |
207 | 207 | | Payment Forms. |
208 | 208 | |-------------------------------------------------------------------------- |
@@ -211,39 +211,39 @@ discard block |
||
211 | 211 | | submission has an active payment form etc. |
212 | 212 | */ |
213 | 213 | |
214 | - /** |
|
215 | - * Prepares the submission's payment form. |
|
216 | - * |
|
217 | - * @since 1.0.19 |
|
218 | - */ |
|
219 | - public function process_payment_form() { |
|
214 | + /** |
|
215 | + * Prepares the submission's payment form. |
|
216 | + * |
|
217 | + * @since 1.0.19 |
|
218 | + */ |
|
219 | + public function process_payment_form() { |
|
220 | 220 | |
221 | - // Every submission needs an active payment form. |
|
222 | - if ( empty( $this->data['form_id'] ) ) { |
|
223 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
224 | - } |
|
221 | + // Every submission needs an active payment form. |
|
222 | + if ( empty( $this->data['form_id'] ) ) { |
|
223 | + throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
224 | + } |
|
225 | 225 | |
226 | - // Fetch the payment form. |
|
227 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
226 | + // Fetch the payment form. |
|
227 | + $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
228 | 228 | |
229 | - if ( ! $this->payment_form->is_active() ) { |
|
230 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
231 | - } |
|
229 | + if ( ! $this->payment_form->is_active() ) { |
|
230 | + throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
231 | + } |
|
232 | 232 | |
233 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
234 | - } |
|
233 | + do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
234 | + } |
|
235 | 235 | |
236 | 236 | /** |
237 | - * Returns the payment form. |
|
238 | - * |
|
239 | - * @since 1.0.19 |
|
240 | - * @return GetPaid_Payment_Form |
|
241 | - */ |
|
242 | - public function get_payment_form() { |
|
243 | - return $this->payment_form; |
|
244 | - } |
|
237 | + * Returns the payment form. |
|
238 | + * |
|
239 | + * @since 1.0.19 |
|
240 | + * @return GetPaid_Payment_Form |
|
241 | + */ |
|
242 | + public function get_payment_form() { |
|
243 | + return $this->payment_form; |
|
244 | + } |
|
245 | 245 | |
246 | - /* |
|
246 | + /* |
|
247 | 247 | |-------------------------------------------------------------------------- |
248 | 248 | | Invoices. |
249 | 249 | |-------------------------------------------------------------------------- |
@@ -252,95 +252,95 @@ discard block |
||
252 | 252 | | might be for an existing invoice. |
253 | 253 | */ |
254 | 254 | |
255 | - /** |
|
256 | - * Prepares the submission's invoice. |
|
257 | - * |
|
258 | - * @since 1.0.19 |
|
259 | - */ |
|
260 | - public function process_invoice() { |
|
261 | - |
|
262 | - // Abort if there is no invoice. |
|
263 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
264 | - |
|
265 | - // Check if we are resuming a payment. |
|
266 | - if ( empty( $this->data['maybe_use_invoice'] ) ) { |
|
267 | - return; |
|
268 | - } |
|
269 | - |
|
270 | - $invoice = wpinv_get_invoice( $this->data['maybe_use_invoice'] ); |
|
271 | - if ( empty( $invoice ) || ! $invoice->has_status( 'draft, auto-draft, wpi-pending' ) ) { |
|
272 | - return; |
|
273 | - } |
|
274 | - } |
|
275 | - |
|
276 | - // If the submission is for an existing invoice, ensure that it exists |
|
277 | - // and that it is not paid for. |
|
278 | - if ( empty( $invoice ) ) { |
|
279 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
280 | - } |
|
255 | + /** |
|
256 | + * Prepares the submission's invoice. |
|
257 | + * |
|
258 | + * @since 1.0.19 |
|
259 | + */ |
|
260 | + public function process_invoice() { |
|
261 | + |
|
262 | + // Abort if there is no invoice. |
|
263 | + if ( empty( $this->data['invoice_id'] ) ) { |
|
264 | + |
|
265 | + // Check if we are resuming a payment. |
|
266 | + if ( empty( $this->data['maybe_use_invoice'] ) ) { |
|
267 | + return; |
|
268 | + } |
|
269 | + |
|
270 | + $invoice = wpinv_get_invoice( $this->data['maybe_use_invoice'] ); |
|
271 | + if ( empty( $invoice ) || ! $invoice->has_status( 'draft, auto-draft, wpi-pending' ) ) { |
|
272 | + return; |
|
273 | + } |
|
274 | + } |
|
275 | + |
|
276 | + // If the submission is for an existing invoice, ensure that it exists |
|
277 | + // and that it is not paid for. |
|
278 | + if ( empty( $invoice ) ) { |
|
279 | + $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
280 | + } |
|
281 | 281 | |
282 | 282 | if ( empty( $invoice ) ) { |
283 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
284 | - } |
|
285 | - |
|
286 | - if ( $invoice->is_paid() ) { |
|
287 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
288 | - } |
|
289 | - |
|
290 | - $this->payment_form->invoice = $invoice; |
|
291 | - if ( ! $this->payment_form->is_default() ) { |
|
292 | - |
|
293 | - $items = array(); |
|
294 | - $item_ids = array(); |
|
295 | - |
|
296 | - foreach ( $invoice->get_items() as $item ) { |
|
297 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
298 | - $item_ids[] = $item->get_id(); |
|
299 | - $items[] = $item; |
|
300 | - } |
|
301 | - } |
|
302 | - |
|
303 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
304 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
305 | - $item_ids[] = $item->get_id(); |
|
306 | - $items[] = $item; |
|
307 | - } |
|
308 | - } |
|
309 | - |
|
310 | - $this->payment_form->set_items( $items ); |
|
311 | - |
|
312 | - } else { |
|
313 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
314 | - } |
|
315 | - |
|
316 | - $this->country = $invoice->get_country(); |
|
317 | - $this->state = $invoice->get_state(); |
|
318 | - $this->invoice = $invoice; |
|
319 | - |
|
320 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * Returns the associated invoice. |
|
325 | - * |
|
326 | - * @since 1.0.19 |
|
327 | - * @return WPInv_Invoice |
|
328 | - */ |
|
329 | - public function get_invoice() { |
|
330 | - return $this->invoice; |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * Checks whether there is an invoice associated with this submission. |
|
335 | - * |
|
336 | - * @since 1.0.19 |
|
337 | - * @return bool |
|
338 | - */ |
|
339 | - public function has_invoice() { |
|
340 | - return ! empty( $this->invoice ); |
|
341 | - } |
|
342 | - |
|
343 | - /* |
|
283 | + throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
284 | + } |
|
285 | + |
|
286 | + if ( $invoice->is_paid() ) { |
|
287 | + throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
288 | + } |
|
289 | + |
|
290 | + $this->payment_form->invoice = $invoice; |
|
291 | + if ( ! $this->payment_form->is_default() ) { |
|
292 | + |
|
293 | + $items = array(); |
|
294 | + $item_ids = array(); |
|
295 | + |
|
296 | + foreach ( $invoice->get_items() as $item ) { |
|
297 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
298 | + $item_ids[] = $item->get_id(); |
|
299 | + $items[] = $item; |
|
300 | + } |
|
301 | + } |
|
302 | + |
|
303 | + foreach ( $this->payment_form->get_items() as $item ) { |
|
304 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
305 | + $item_ids[] = $item->get_id(); |
|
306 | + $items[] = $item; |
|
307 | + } |
|
308 | + } |
|
309 | + |
|
310 | + $this->payment_form->set_items( $items ); |
|
311 | + |
|
312 | + } else { |
|
313 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
314 | + } |
|
315 | + |
|
316 | + $this->country = $invoice->get_country(); |
|
317 | + $this->state = $invoice->get_state(); |
|
318 | + $this->invoice = $invoice; |
|
319 | + |
|
320 | + do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * Returns the associated invoice. |
|
325 | + * |
|
326 | + * @since 1.0.19 |
|
327 | + * @return WPInv_Invoice |
|
328 | + */ |
|
329 | + public function get_invoice() { |
|
330 | + return $this->invoice; |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * Checks whether there is an invoice associated with this submission. |
|
335 | + * |
|
336 | + * @since 1.0.19 |
|
337 | + * @return bool |
|
338 | + */ |
|
339 | + public function has_invoice() { |
|
340 | + return ! empty( $this->invoice ); |
|
341 | + } |
|
342 | + |
|
343 | + /* |
|
344 | 344 | |-------------------------------------------------------------------------- |
345 | 345 | | Items. |
346 | 346 | |-------------------------------------------------------------------------- |
@@ -349,129 +349,129 @@ discard block |
||
349 | 349 | | recurring item. But can have an unlimited number of non-recurring items. |
350 | 350 | */ |
351 | 351 | |
352 | - /** |
|
353 | - * Prepares the submission's items. |
|
354 | - * |
|
355 | - * @since 1.0.19 |
|
356 | - */ |
|
357 | - public function process_items() { |
|
358 | - |
|
359 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
360 | - |
|
361 | - foreach ( $processor->items as $item ) { |
|
362 | - $this->add_item( $item ); |
|
363 | - } |
|
364 | - |
|
365 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * Adds an item to the submission. |
|
370 | - * |
|
371 | - * @since 1.0.19 |
|
372 | - * @param GetPaid_Form_Item $item |
|
373 | - */ |
|
374 | - public function add_item( $item ) { |
|
375 | - |
|
376 | - // Make sure that it is available for purchase. |
|
377 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
378 | - return; |
|
379 | - } |
|
380 | - |
|
381 | - // Each submission can only contain one recurring item. |
|
382 | - if ( $item->is_recurring() ) { |
|
383 | - $this->has_recurring = $item->get_id(); |
|
384 | - } |
|
385 | - |
|
386 | - // Update the items and totals. |
|
387 | - $this->items[ $item->get_id() ] = $item; |
|
388 | - $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
389 | - $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
390 | - |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * Removes a specific item. |
|
395 | - * |
|
396 | - * You should not call this method after the discounts and taxes |
|
397 | - * have been calculated. |
|
398 | - * |
|
399 | - * @since 1.0.19 |
|
400 | - */ |
|
401 | - public function remove_item( $item_id ) { |
|
402 | - |
|
403 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
404 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
405 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
406 | - |
|
407 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
408 | - $this->has_recurring = 0; |
|
409 | - } |
|
410 | - |
|
411 | - unset( $this->items[ $item_id ] ); |
|
412 | - } |
|
413 | - |
|
414 | - } |
|
415 | - |
|
416 | - /** |
|
417 | - * Returns the subtotal. |
|
418 | - * |
|
419 | - * @since 1.0.19 |
|
420 | - */ |
|
421 | - public function get_subtotal() { |
|
422 | - |
|
423 | - if ( wpinv_prices_include_tax() ) { |
|
424 | - return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
425 | - } |
|
426 | - |
|
427 | - return $this->totals['subtotal']['initial']; |
|
428 | - } |
|
429 | - |
|
430 | - /** |
|
431 | - * Returns the recurring subtotal. |
|
432 | - * |
|
433 | - * @since 1.0.19 |
|
434 | - */ |
|
435 | - public function get_recurring_subtotal() { |
|
436 | - |
|
437 | - if ( wpinv_prices_include_tax() ) { |
|
438 | - return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
439 | - } |
|
440 | - |
|
441 | - return $this->totals['subtotal']['recurring']; |
|
442 | - } |
|
443 | - |
|
444 | - /** |
|
445 | - * Returns all items. |
|
446 | - * |
|
447 | - * @since 1.0.19 |
|
448 | - * @return GetPaid_Form_Item[] |
|
449 | - */ |
|
450 | - public function get_items() { |
|
451 | - return $this->items; |
|
452 | - } |
|
453 | - |
|
454 | - /** |
|
455 | - * Checks if there's a single subscription group in the submission. |
|
456 | - * |
|
457 | - * @since 2.3.0 |
|
458 | - * @return bool |
|
459 | - */ |
|
460 | - public function has_subscription_group() { |
|
461 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * Checks if there are multipe subscription groups in the submission. |
|
466 | - * |
|
467 | - * @since 2.3.0 |
|
468 | - * @return bool |
|
469 | - */ |
|
470 | - public function has_multiple_subscription_groups() { |
|
471 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
472 | - } |
|
473 | - |
|
474 | - /* |
|
352 | + /** |
|
353 | + * Prepares the submission's items. |
|
354 | + * |
|
355 | + * @since 1.0.19 |
|
356 | + */ |
|
357 | + public function process_items() { |
|
358 | + |
|
359 | + $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
360 | + |
|
361 | + foreach ( $processor->items as $item ) { |
|
362 | + $this->add_item( $item ); |
|
363 | + } |
|
364 | + |
|
365 | + do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * Adds an item to the submission. |
|
370 | + * |
|
371 | + * @since 1.0.19 |
|
372 | + * @param GetPaid_Form_Item $item |
|
373 | + */ |
|
374 | + public function add_item( $item ) { |
|
375 | + |
|
376 | + // Make sure that it is available for purchase. |
|
377 | + if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
378 | + return; |
|
379 | + } |
|
380 | + |
|
381 | + // Each submission can only contain one recurring item. |
|
382 | + if ( $item->is_recurring() ) { |
|
383 | + $this->has_recurring = $item->get_id(); |
|
384 | + } |
|
385 | + |
|
386 | + // Update the items and totals. |
|
387 | + $this->items[ $item->get_id() ] = $item; |
|
388 | + $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
389 | + $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
390 | + |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * Removes a specific item. |
|
395 | + * |
|
396 | + * You should not call this method after the discounts and taxes |
|
397 | + * have been calculated. |
|
398 | + * |
|
399 | + * @since 1.0.19 |
|
400 | + */ |
|
401 | + public function remove_item( $item_id ) { |
|
402 | + |
|
403 | + if ( isset( $this->items[ $item_id ] ) ) { |
|
404 | + $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
405 | + $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
406 | + |
|
407 | + if ( $this->items[ $item_id ]->is_recurring() ) { |
|
408 | + $this->has_recurring = 0; |
|
409 | + } |
|
410 | + |
|
411 | + unset( $this->items[ $item_id ] ); |
|
412 | + } |
|
413 | + |
|
414 | + } |
|
415 | + |
|
416 | + /** |
|
417 | + * Returns the subtotal. |
|
418 | + * |
|
419 | + * @since 1.0.19 |
|
420 | + */ |
|
421 | + public function get_subtotal() { |
|
422 | + |
|
423 | + if ( wpinv_prices_include_tax() ) { |
|
424 | + return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
425 | + } |
|
426 | + |
|
427 | + return $this->totals['subtotal']['initial']; |
|
428 | + } |
|
429 | + |
|
430 | + /** |
|
431 | + * Returns the recurring subtotal. |
|
432 | + * |
|
433 | + * @since 1.0.19 |
|
434 | + */ |
|
435 | + public function get_recurring_subtotal() { |
|
436 | + |
|
437 | + if ( wpinv_prices_include_tax() ) { |
|
438 | + return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
439 | + } |
|
440 | + |
|
441 | + return $this->totals['subtotal']['recurring']; |
|
442 | + } |
|
443 | + |
|
444 | + /** |
|
445 | + * Returns all items. |
|
446 | + * |
|
447 | + * @since 1.0.19 |
|
448 | + * @return GetPaid_Form_Item[] |
|
449 | + */ |
|
450 | + public function get_items() { |
|
451 | + return $this->items; |
|
452 | + } |
|
453 | + |
|
454 | + /** |
|
455 | + * Checks if there's a single subscription group in the submission. |
|
456 | + * |
|
457 | + * @since 2.3.0 |
|
458 | + * @return bool |
|
459 | + */ |
|
460 | + public function has_subscription_group() { |
|
461 | + return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | + * Checks if there are multipe subscription groups in the submission. |
|
466 | + * |
|
467 | + * @since 2.3.0 |
|
468 | + * @return bool |
|
469 | + */ |
|
470 | + public function has_multiple_subscription_groups() { |
|
471 | + return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
472 | + } |
|
473 | + |
|
474 | + /* |
|
475 | 475 | |-------------------------------------------------------------------------- |
476 | 476 | | Taxes |
477 | 477 | |-------------------------------------------------------------------------- |
@@ -480,128 +480,128 @@ discard block |
||
480 | 480 | | or only one-time. |
481 | 481 | */ |
482 | 482 | |
483 | - /** |
|
484 | - * Prepares the submission's taxes. |
|
485 | - * |
|
486 | - * @since 1.0.19 |
|
487 | - */ |
|
488 | - public function process_taxes() { |
|
489 | - |
|
490 | - // Abort if we're not using taxes. |
|
491 | - if ( ! $this->use_taxes() ) { |
|
492 | - return; |
|
493 | - } |
|
494 | - |
|
495 | - // If a custom country && state has been passed in, use it to calculate taxes. |
|
496 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
497 | - if ( ! empty( $country ) ) { |
|
498 | - $this->country = $country; |
|
499 | - } |
|
500 | - |
|
501 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
502 | - if ( ! empty( $state ) ) { |
|
503 | - $this->state = $state; |
|
504 | - } |
|
505 | - |
|
506 | - // Confirm if the provided country and the ip country are similar. |
|
507 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
508 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
509 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
510 | - } |
|
511 | - |
|
512 | - // Abort if the country is not taxable. |
|
513 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
514 | - return; |
|
515 | - } |
|
516 | - |
|
517 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
518 | - |
|
519 | - foreach ( $processor->taxes as $tax ) { |
|
520 | - $this->add_tax( $tax ); |
|
521 | - } |
|
522 | - |
|
523 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * Adds a tax to the submission. |
|
528 | - * |
|
529 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
530 | - * @since 1.0.19 |
|
531 | - */ |
|
532 | - public function add_tax( $tax ) { |
|
533 | - |
|
534 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
535 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
536 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
537 | - } |
|
538 | - |
|
539 | - $this->taxes[ $tax['name'] ] = $tax; |
|
540 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
541 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
542 | - |
|
543 | - } |
|
544 | - |
|
545 | - /** |
|
546 | - * Removes a specific tax. |
|
547 | - * |
|
548 | - * @since 1.0.19 |
|
549 | - */ |
|
550 | - public function remove_tax( $tax_name ) { |
|
551 | - |
|
552 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
553 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
554 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
555 | - unset( $this->taxes[ $tax_name ] ); |
|
556 | - } |
|
557 | - |
|
558 | - } |
|
559 | - |
|
560 | - /** |
|
561 | - * Whether or not we'll use taxes for the submission. |
|
562 | - * |
|
563 | - * @since 1.0.19 |
|
564 | - */ |
|
565 | - public function use_taxes() { |
|
566 | - |
|
567 | - $use_taxes = wpinv_use_taxes(); |
|
568 | - |
|
569 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
570 | - $use_taxes = false; |
|
571 | - } |
|
572 | - |
|
573 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
574 | - |
|
575 | - } |
|
576 | - |
|
577 | - /** |
|
578 | - * Returns the tax. |
|
579 | - * |
|
580 | - * @since 1.0.19 |
|
581 | - */ |
|
582 | - public function get_tax() { |
|
583 | - return $this->totals['taxes']['initial']; |
|
584 | - } |
|
585 | - |
|
586 | - /** |
|
587 | - * Returns the recurring tax. |
|
588 | - * |
|
589 | - * @since 1.0.19 |
|
590 | - */ |
|
591 | - public function get_recurring_tax() { |
|
592 | - return $this->totals['taxes']['recurring']; |
|
593 | - } |
|
594 | - |
|
595 | - /** |
|
596 | - * Returns all taxes. |
|
597 | - * |
|
598 | - * @since 1.0.19 |
|
599 | - */ |
|
600 | - public function get_taxes() { |
|
601 | - return $this->taxes; |
|
602 | - } |
|
603 | - |
|
604 | - /* |
|
483 | + /** |
|
484 | + * Prepares the submission's taxes. |
|
485 | + * |
|
486 | + * @since 1.0.19 |
|
487 | + */ |
|
488 | + public function process_taxes() { |
|
489 | + |
|
490 | + // Abort if we're not using taxes. |
|
491 | + if ( ! $this->use_taxes() ) { |
|
492 | + return; |
|
493 | + } |
|
494 | + |
|
495 | + // If a custom country && state has been passed in, use it to calculate taxes. |
|
496 | + $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
497 | + if ( ! empty( $country ) ) { |
|
498 | + $this->country = $country; |
|
499 | + } |
|
500 | + |
|
501 | + $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
502 | + if ( ! empty( $state ) ) { |
|
503 | + $this->state = $state; |
|
504 | + } |
|
505 | + |
|
506 | + // Confirm if the provided country and the ip country are similar. |
|
507 | + $address_confirmed = $this->get_field( 'confirm-address' ); |
|
508 | + if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
509 | + throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
510 | + } |
|
511 | + |
|
512 | + // Abort if the country is not taxable. |
|
513 | + if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
514 | + return; |
|
515 | + } |
|
516 | + |
|
517 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
518 | + |
|
519 | + foreach ( $processor->taxes as $tax ) { |
|
520 | + $this->add_tax( $tax ); |
|
521 | + } |
|
522 | + |
|
523 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * Adds a tax to the submission. |
|
528 | + * |
|
529 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
530 | + * @since 1.0.19 |
|
531 | + */ |
|
532 | + public function add_tax( $tax ) { |
|
533 | + |
|
534 | + if ( wpinv_round_tax_per_tax_rate() ) { |
|
535 | + $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
536 | + $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
537 | + } |
|
538 | + |
|
539 | + $this->taxes[ $tax['name'] ] = $tax; |
|
540 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
541 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
542 | + |
|
543 | + } |
|
544 | + |
|
545 | + /** |
|
546 | + * Removes a specific tax. |
|
547 | + * |
|
548 | + * @since 1.0.19 |
|
549 | + */ |
|
550 | + public function remove_tax( $tax_name ) { |
|
551 | + |
|
552 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
553 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
554 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
555 | + unset( $this->taxes[ $tax_name ] ); |
|
556 | + } |
|
557 | + |
|
558 | + } |
|
559 | + |
|
560 | + /** |
|
561 | + * Whether or not we'll use taxes for the submission. |
|
562 | + * |
|
563 | + * @since 1.0.19 |
|
564 | + */ |
|
565 | + public function use_taxes() { |
|
566 | + |
|
567 | + $use_taxes = wpinv_use_taxes(); |
|
568 | + |
|
569 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
570 | + $use_taxes = false; |
|
571 | + } |
|
572 | + |
|
573 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
574 | + |
|
575 | + } |
|
576 | + |
|
577 | + /** |
|
578 | + * Returns the tax. |
|
579 | + * |
|
580 | + * @since 1.0.19 |
|
581 | + */ |
|
582 | + public function get_tax() { |
|
583 | + return $this->totals['taxes']['initial']; |
|
584 | + } |
|
585 | + |
|
586 | + /** |
|
587 | + * Returns the recurring tax. |
|
588 | + * |
|
589 | + * @since 1.0.19 |
|
590 | + */ |
|
591 | + public function get_recurring_tax() { |
|
592 | + return $this->totals['taxes']['recurring']; |
|
593 | + } |
|
594 | + |
|
595 | + /** |
|
596 | + * Returns all taxes. |
|
597 | + * |
|
598 | + * @since 1.0.19 |
|
599 | + */ |
|
600 | + public function get_taxes() { |
|
601 | + return $this->taxes; |
|
602 | + } |
|
603 | + |
|
604 | + /* |
|
605 | 605 | |-------------------------------------------------------------------------- |
606 | 606 | | Discounts |
607 | 607 | |-------------------------------------------------------------------------- |
@@ -610,99 +610,99 @@ discard block |
||
610 | 610 | | or only one-time. They also do not have to come from a discount code. |
611 | 611 | */ |
612 | 612 | |
613 | - /** |
|
614 | - * Prepares the submission's discount. |
|
615 | - * |
|
616 | - * @since 1.0.19 |
|
617 | - */ |
|
618 | - public function process_discount() { |
|
619 | - |
|
620 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
621 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
622 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
623 | - |
|
624 | - foreach ( $processor->discounts as $discount ) { |
|
625 | - $this->add_discount( $discount ); |
|
626 | - } |
|
627 | - |
|
628 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
629 | - } |
|
630 | - |
|
631 | - /** |
|
632 | - * Adds a discount to the submission. |
|
633 | - * |
|
634 | - * @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. |
|
635 | - * @since 1.0.19 |
|
636 | - */ |
|
637 | - public function add_discount( $discount ) { |
|
638 | - $this->discounts[ $discount['name'] ] = $discount; |
|
639 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
640 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
641 | - } |
|
642 | - |
|
643 | - /** |
|
644 | - * Removes a discount from the submission. |
|
645 | - * |
|
646 | - * @since 1.0.19 |
|
647 | - */ |
|
648 | - public function remove_discount( $name ) { |
|
649 | - |
|
650 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
651 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
652 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
653 | - unset( $this->discounts[ $name ] ); |
|
654 | - } |
|
655 | - |
|
656 | - } |
|
657 | - |
|
658 | - /** |
|
659 | - * Checks whether there is a discount code associated with this submission. |
|
660 | - * |
|
661 | - * @since 1.0.19 |
|
662 | - * @return bool |
|
663 | - */ |
|
664 | - public function has_discount_code() { |
|
665 | - return ! empty( $this->discounts['discount_code'] ); |
|
666 | - } |
|
667 | - |
|
668 | - /** |
|
669 | - * Returns the discount code. |
|
670 | - * |
|
671 | - * @since 1.0.19 |
|
672 | - * @return string |
|
673 | - */ |
|
674 | - public function get_discount_code() { |
|
675 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
676 | - } |
|
677 | - |
|
678 | - /** |
|
679 | - * Returns the discount. |
|
680 | - * |
|
681 | - * @since 1.0.19 |
|
682 | - */ |
|
683 | - public function get_discount() { |
|
684 | - return $this->totals['discount']['initial']; |
|
685 | - } |
|
686 | - |
|
687 | - /** |
|
688 | - * Returns the recurring discount. |
|
689 | - * |
|
690 | - * @since 1.0.19 |
|
691 | - */ |
|
692 | - public function get_recurring_discount() { |
|
693 | - return $this->totals['discount']['recurring']; |
|
694 | - } |
|
695 | - |
|
696 | - /** |
|
697 | - * Returns all discounts. |
|
698 | - * |
|
699 | - * @since 1.0.19 |
|
700 | - */ |
|
701 | - public function get_discounts() { |
|
702 | - return $this->discounts; |
|
703 | - } |
|
704 | - |
|
705 | - /* |
|
613 | + /** |
|
614 | + * Prepares the submission's discount. |
|
615 | + * |
|
616 | + * @since 1.0.19 |
|
617 | + */ |
|
618 | + public function process_discount() { |
|
619 | + |
|
620 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
621 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
622 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
623 | + |
|
624 | + foreach ( $processor->discounts as $discount ) { |
|
625 | + $this->add_discount( $discount ); |
|
626 | + } |
|
627 | + |
|
628 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
629 | + } |
|
630 | + |
|
631 | + /** |
|
632 | + * Adds a discount to the submission. |
|
633 | + * |
|
634 | + * @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. |
|
635 | + * @since 1.0.19 |
|
636 | + */ |
|
637 | + public function add_discount( $discount ) { |
|
638 | + $this->discounts[ $discount['name'] ] = $discount; |
|
639 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
640 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
641 | + } |
|
642 | + |
|
643 | + /** |
|
644 | + * Removes a discount from the submission. |
|
645 | + * |
|
646 | + * @since 1.0.19 |
|
647 | + */ |
|
648 | + public function remove_discount( $name ) { |
|
649 | + |
|
650 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
651 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
652 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
653 | + unset( $this->discounts[ $name ] ); |
|
654 | + } |
|
655 | + |
|
656 | + } |
|
657 | + |
|
658 | + /** |
|
659 | + * Checks whether there is a discount code associated with this submission. |
|
660 | + * |
|
661 | + * @since 1.0.19 |
|
662 | + * @return bool |
|
663 | + */ |
|
664 | + public function has_discount_code() { |
|
665 | + return ! empty( $this->discounts['discount_code'] ); |
|
666 | + } |
|
667 | + |
|
668 | + /** |
|
669 | + * Returns the discount code. |
|
670 | + * |
|
671 | + * @since 1.0.19 |
|
672 | + * @return string |
|
673 | + */ |
|
674 | + public function get_discount_code() { |
|
675 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
676 | + } |
|
677 | + |
|
678 | + /** |
|
679 | + * Returns the discount. |
|
680 | + * |
|
681 | + * @since 1.0.19 |
|
682 | + */ |
|
683 | + public function get_discount() { |
|
684 | + return $this->totals['discount']['initial']; |
|
685 | + } |
|
686 | + |
|
687 | + /** |
|
688 | + * Returns the recurring discount. |
|
689 | + * |
|
690 | + * @since 1.0.19 |
|
691 | + */ |
|
692 | + public function get_recurring_discount() { |
|
693 | + return $this->totals['discount']['recurring']; |
|
694 | + } |
|
695 | + |
|
696 | + /** |
|
697 | + * Returns all discounts. |
|
698 | + * |
|
699 | + * @since 1.0.19 |
|
700 | + */ |
|
701 | + public function get_discounts() { |
|
702 | + return $this->discounts; |
|
703 | + } |
|
704 | + |
|
705 | + /* |
|
706 | 706 | |-------------------------------------------------------------------------- |
707 | 707 | | Fees |
708 | 708 | |-------------------------------------------------------------------------- |
@@ -712,100 +712,100 @@ discard block |
||
712 | 712 | | fees. |
713 | 713 | */ |
714 | 714 | |
715 | - /** |
|
716 | - * Prepares the submission's fees. |
|
717 | - * |
|
718 | - * @since 1.0.19 |
|
719 | - */ |
|
720 | - public function process_fees() { |
|
721 | - |
|
722 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
723 | - |
|
724 | - foreach ( $fees_processor->fees as $fee ) { |
|
725 | - $this->add_fee( $fee ); |
|
726 | - } |
|
727 | - |
|
728 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
729 | - } |
|
730 | - |
|
731 | - /** |
|
732 | - * Adds a fee to the submission. |
|
733 | - * |
|
734 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
735 | - * @since 1.0.19 |
|
736 | - */ |
|
737 | - public function add_fee( $fee ) { |
|
738 | - |
|
739 | - if ( $fee['name'] == 'shipping' ) { |
|
740 | - $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
741 | - $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
742 | - return; |
|
743 | - } |
|
744 | - |
|
745 | - $this->fees[ $fee['name'] ] = $fee; |
|
746 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
747 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
748 | - |
|
749 | - } |
|
750 | - |
|
751 | - /** |
|
752 | - * Removes a fee from the submission. |
|
753 | - * |
|
754 | - * @since 1.0.19 |
|
755 | - */ |
|
756 | - public function remove_fee( $name ) { |
|
757 | - |
|
758 | - if ( isset( $this->fees[ $name ] ) ) { |
|
759 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
760 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
761 | - unset( $this->fees[ $name ] ); |
|
762 | - } |
|
763 | - |
|
764 | - if ( 'shipping' == $name ) { |
|
765 | - $this->totals['shipping']['initial'] = 0; |
|
766 | - $this->totals['shipping']['recurring'] = 0; |
|
767 | - } |
|
768 | - |
|
769 | - } |
|
770 | - |
|
771 | - /** |
|
772 | - * Returns the fees. |
|
773 | - * |
|
774 | - * @since 1.0.19 |
|
775 | - */ |
|
776 | - public function get_fee() { |
|
777 | - return $this->totals['fees']['initial']; |
|
778 | - } |
|
779 | - |
|
780 | - /** |
|
781 | - * Returns the recurring fees. |
|
782 | - * |
|
783 | - * @since 1.0.19 |
|
784 | - */ |
|
785 | - public function get_recurring_fee() { |
|
786 | - return $this->totals['fees']['recurring']; |
|
787 | - } |
|
788 | - |
|
789 | - /** |
|
790 | - * Returns all fees. |
|
791 | - * |
|
792 | - * @since 1.0.19 |
|
793 | - */ |
|
794 | - public function get_fees() { |
|
795 | - return $this->fees; |
|
796 | - } |
|
797 | - |
|
798 | - /** |
|
799 | - * Checks if there are any fees for the form. |
|
800 | - * |
|
801 | - * @return bool |
|
802 | - * @since 1.0.19 |
|
803 | - */ |
|
804 | - public function has_fees() { |
|
805 | - return count( $this->fees ) !== 0; |
|
806 | - } |
|
807 | - |
|
808 | - /* |
|
715 | + /** |
|
716 | + * Prepares the submission's fees. |
|
717 | + * |
|
718 | + * @since 1.0.19 |
|
719 | + */ |
|
720 | + public function process_fees() { |
|
721 | + |
|
722 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
723 | + |
|
724 | + foreach ( $fees_processor->fees as $fee ) { |
|
725 | + $this->add_fee( $fee ); |
|
726 | + } |
|
727 | + |
|
728 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
729 | + } |
|
730 | + |
|
731 | + /** |
|
732 | + * Adds a fee to the submission. |
|
733 | + * |
|
734 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
735 | + * @since 1.0.19 |
|
736 | + */ |
|
737 | + public function add_fee( $fee ) { |
|
738 | + |
|
739 | + if ( $fee['name'] == 'shipping' ) { |
|
740 | + $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
741 | + $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
742 | + return; |
|
743 | + } |
|
744 | + |
|
745 | + $this->fees[ $fee['name'] ] = $fee; |
|
746 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
747 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
748 | + |
|
749 | + } |
|
750 | + |
|
751 | + /** |
|
752 | + * Removes a fee from the submission. |
|
753 | + * |
|
754 | + * @since 1.0.19 |
|
755 | + */ |
|
756 | + public function remove_fee( $name ) { |
|
757 | + |
|
758 | + if ( isset( $this->fees[ $name ] ) ) { |
|
759 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
760 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
761 | + unset( $this->fees[ $name ] ); |
|
762 | + } |
|
763 | + |
|
764 | + if ( 'shipping' == $name ) { |
|
765 | + $this->totals['shipping']['initial'] = 0; |
|
766 | + $this->totals['shipping']['recurring'] = 0; |
|
767 | + } |
|
768 | + |
|
769 | + } |
|
770 | + |
|
771 | + /** |
|
772 | + * Returns the fees. |
|
773 | + * |
|
774 | + * @since 1.0.19 |
|
775 | + */ |
|
776 | + public function get_fee() { |
|
777 | + return $this->totals['fees']['initial']; |
|
778 | + } |
|
779 | + |
|
780 | + /** |
|
781 | + * Returns the recurring fees. |
|
782 | + * |
|
783 | + * @since 1.0.19 |
|
784 | + */ |
|
785 | + public function get_recurring_fee() { |
|
786 | + return $this->totals['fees']['recurring']; |
|
787 | + } |
|
788 | + |
|
789 | + /** |
|
790 | + * Returns all fees. |
|
791 | + * |
|
792 | + * @since 1.0.19 |
|
793 | + */ |
|
794 | + public function get_fees() { |
|
795 | + return $this->fees; |
|
796 | + } |
|
797 | + |
|
798 | + /** |
|
799 | + * Checks if there are any fees for the form. |
|
800 | + * |
|
801 | + * @return bool |
|
802 | + * @since 1.0.19 |
|
803 | + */ |
|
804 | + public function has_fees() { |
|
805 | + return count( $this->fees ) !== 0; |
|
806 | + } |
|
807 | + |
|
808 | + /* |
|
809 | 809 | |-------------------------------------------------------------------------- |
810 | 810 | | MISC |
811 | 811 | |-------------------------------------------------------------------------- |
@@ -813,147 +813,147 @@ discard block |
||
813 | 813 | | Extra submission functions. |
814 | 814 | */ |
815 | 815 | |
816 | - /** |
|
817 | - * Returns the shipping amount. |
|
818 | - * |
|
819 | - * @since 1.0.19 |
|
820 | - */ |
|
821 | - public function get_shipping() { |
|
822 | - return $this->totals['shipping']['initial']; |
|
823 | - } |
|
824 | - |
|
825 | - /** |
|
826 | - * Returns the recurring shipping. |
|
827 | - * |
|
828 | - * @since 1.0.19 |
|
829 | - */ |
|
830 | - public function get_recurring_shipping() { |
|
831 | - return $this->totals['shipping']['recurring']; |
|
832 | - } |
|
833 | - |
|
834 | - /** |
|
835 | - * Checks if there are any shipping fees for the form. |
|
836 | - * |
|
837 | - * @return bool |
|
838 | - * @since 1.0.19 |
|
839 | - */ |
|
840 | - public function has_shipping() { |
|
841 | - return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
842 | - } |
|
843 | - |
|
844 | - /** |
|
845 | - * Checks if this is the initial fetch. |
|
846 | - * |
|
847 | - * @return bool |
|
848 | - * @since 1.0.19 |
|
849 | - */ |
|
850 | - public function is_initial_fetch() { |
|
851 | - return isset( $this->data['initial_state'] ) && empty( $this->data['initial_state'] ); |
|
852 | - } |
|
853 | - |
|
854 | - /** |
|
855 | - * Returns the total amount to collect for this submission. |
|
856 | - * |
|
857 | - * @since 1.0.19 |
|
858 | - */ |
|
859 | - public function get_total() { |
|
860 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
|
861 | - return max( $total, 0 ); |
|
862 | - } |
|
863 | - |
|
864 | - /** |
|
865 | - * Returns the recurring total amount to collect for this submission. |
|
866 | - * |
|
867 | - * @since 1.0.19 |
|
868 | - */ |
|
869 | - public function get_recurring_total() { |
|
870 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
|
871 | - return max( $total, 0 ); |
|
872 | - } |
|
873 | - |
|
874 | - /** |
|
875 | - * Whether payment details should be collected for this submission. |
|
876 | - * |
|
877 | - * @since 1.0.19 |
|
878 | - */ |
|
879 | - public function should_collect_payment_details() { |
|
880 | - $initial = $this->get_total(); |
|
881 | - $recurring = $this->get_recurring_total(); |
|
882 | - |
|
883 | - if ( $this->has_recurring == 0 ) { |
|
884 | - $recurring = 0; |
|
885 | - } |
|
886 | - |
|
887 | - $collect = $initial > 0 || $recurring > 0; |
|
888 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
889 | - } |
|
890 | - |
|
891 | - /** |
|
892 | - * Returns the billing email of the user. |
|
893 | - * |
|
894 | - * @since 1.0.19 |
|
895 | - */ |
|
896 | - public function get_billing_email() { |
|
897 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
898 | - } |
|
899 | - |
|
900 | - /** |
|
901 | - * Checks if the submitter has a billing email. |
|
902 | - * |
|
903 | - * @since 1.0.19 |
|
904 | - */ |
|
905 | - public function has_billing_email() { |
|
906 | - $billing_email = $this->get_billing_email(); |
|
907 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
908 | - } |
|
909 | - |
|
910 | - /** |
|
911 | - * Returns the appropriate currency for the submission. |
|
912 | - * |
|
913 | - * @since 1.0.19 |
|
914 | - * @return string |
|
915 | - */ |
|
916 | - public function get_currency() { |
|
917 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
918 | - } |
|
919 | - |
|
920 | - /** |
|
921 | - * Returns the raw submission data. |
|
922 | - * |
|
923 | - * @since 1.0.19 |
|
924 | - * @return array |
|
925 | - */ |
|
926 | - public function get_data() { |
|
927 | - return $this->data; |
|
928 | - } |
|
929 | - |
|
930 | - /** |
|
931 | - * Returns a field from the submission data |
|
932 | - * |
|
933 | - * @param string $field |
|
934 | - * @since 1.0.19 |
|
935 | - * @return mixed|null |
|
936 | - */ |
|
937 | - public function get_field( $field, $sub_array_key = null ) { |
|
938 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
939 | - } |
|
940 | - |
|
941 | - /** |
|
942 | - * Checks if a required field is set. |
|
943 | - * |
|
944 | - * @since 1.0.19 |
|
945 | - */ |
|
946 | - public function is_required_field_set( $field ) { |
|
947 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
948 | - } |
|
949 | - |
|
950 | - /** |
|
951 | - * Formats an amount |
|
952 | - * |
|
953 | - * @since 1.0.19 |
|
954 | - */ |
|
955 | - public function format_amount( $amount ) { |
|
956 | - return wpinv_price( $amount, $this->get_currency() ); |
|
957 | - } |
|
816 | + /** |
|
817 | + * Returns the shipping amount. |
|
818 | + * |
|
819 | + * @since 1.0.19 |
|
820 | + */ |
|
821 | + public function get_shipping() { |
|
822 | + return $this->totals['shipping']['initial']; |
|
823 | + } |
|
824 | + |
|
825 | + /** |
|
826 | + * Returns the recurring shipping. |
|
827 | + * |
|
828 | + * @since 1.0.19 |
|
829 | + */ |
|
830 | + public function get_recurring_shipping() { |
|
831 | + return $this->totals['shipping']['recurring']; |
|
832 | + } |
|
833 | + |
|
834 | + /** |
|
835 | + * Checks if there are any shipping fees for the form. |
|
836 | + * |
|
837 | + * @return bool |
|
838 | + * @since 1.0.19 |
|
839 | + */ |
|
840 | + public function has_shipping() { |
|
841 | + return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
842 | + } |
|
843 | + |
|
844 | + /** |
|
845 | + * Checks if this is the initial fetch. |
|
846 | + * |
|
847 | + * @return bool |
|
848 | + * @since 1.0.19 |
|
849 | + */ |
|
850 | + public function is_initial_fetch() { |
|
851 | + return isset( $this->data['initial_state'] ) && empty( $this->data['initial_state'] ); |
|
852 | + } |
|
853 | + |
|
854 | + /** |
|
855 | + * Returns the total amount to collect for this submission. |
|
856 | + * |
|
857 | + * @since 1.0.19 |
|
858 | + */ |
|
859 | + public function get_total() { |
|
860 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
|
861 | + return max( $total, 0 ); |
|
862 | + } |
|
863 | + |
|
864 | + /** |
|
865 | + * Returns the recurring total amount to collect for this submission. |
|
866 | + * |
|
867 | + * @since 1.0.19 |
|
868 | + */ |
|
869 | + public function get_recurring_total() { |
|
870 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
|
871 | + return max( $total, 0 ); |
|
872 | + } |
|
873 | + |
|
874 | + /** |
|
875 | + * Whether payment details should be collected for this submission. |
|
876 | + * |
|
877 | + * @since 1.0.19 |
|
878 | + */ |
|
879 | + public function should_collect_payment_details() { |
|
880 | + $initial = $this->get_total(); |
|
881 | + $recurring = $this->get_recurring_total(); |
|
882 | + |
|
883 | + if ( $this->has_recurring == 0 ) { |
|
884 | + $recurring = 0; |
|
885 | + } |
|
886 | + |
|
887 | + $collect = $initial > 0 || $recurring > 0; |
|
888 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
889 | + } |
|
890 | + |
|
891 | + /** |
|
892 | + * Returns the billing email of the user. |
|
893 | + * |
|
894 | + * @since 1.0.19 |
|
895 | + */ |
|
896 | + public function get_billing_email() { |
|
897 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
898 | + } |
|
899 | + |
|
900 | + /** |
|
901 | + * Checks if the submitter has a billing email. |
|
902 | + * |
|
903 | + * @since 1.0.19 |
|
904 | + */ |
|
905 | + public function has_billing_email() { |
|
906 | + $billing_email = $this->get_billing_email(); |
|
907 | + return ! empty( $billing_email ) && is_email( $billing_email ); |
|
908 | + } |
|
909 | + |
|
910 | + /** |
|
911 | + * Returns the appropriate currency for the submission. |
|
912 | + * |
|
913 | + * @since 1.0.19 |
|
914 | + * @return string |
|
915 | + */ |
|
916 | + public function get_currency() { |
|
917 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
918 | + } |
|
919 | + |
|
920 | + /** |
|
921 | + * Returns the raw submission data. |
|
922 | + * |
|
923 | + * @since 1.0.19 |
|
924 | + * @return array |
|
925 | + */ |
|
926 | + public function get_data() { |
|
927 | + return $this->data; |
|
928 | + } |
|
929 | + |
|
930 | + /** |
|
931 | + * Returns a field from the submission data |
|
932 | + * |
|
933 | + * @param string $field |
|
934 | + * @since 1.0.19 |
|
935 | + * @return mixed|null |
|
936 | + */ |
|
937 | + public function get_field( $field, $sub_array_key = null ) { |
|
938 | + return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
939 | + } |
|
940 | + |
|
941 | + /** |
|
942 | + * Checks if a required field is set. |
|
943 | + * |
|
944 | + * @since 1.0.19 |
|
945 | + */ |
|
946 | + public function is_required_field_set( $field ) { |
|
947 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
948 | + } |
|
949 | + |
|
950 | + /** |
|
951 | + * Formats an amount |
|
952 | + * |
|
953 | + * @since 1.0.19 |
|
954 | + */ |
|
955 | + public function format_amount( $amount ) { |
|
956 | + return wpinv_price( $amount, $this->get_currency() ); |
|
957 | + } |
|
958 | 958 | |
959 | 959 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | $this->state = wpinv_get_default_state(); |
147 | 147 | |
148 | 148 | // Do we have an actual submission? |
149 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
150 | - $this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) ); |
|
149 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
150 | + $this->load_data(wp_kses_post_deep(wp_unslash($_POST))); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | } |
@@ -157,16 +157,16 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @param array $data |
159 | 159 | */ |
160 | - public function load_data( $data ) { |
|
160 | + public function load_data($data) { |
|
161 | 161 | |
162 | 162 | // Allow plugins to filter the data. |
163 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
163 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
164 | 164 | |
165 | 165 | // Cache it... |
166 | 166 | $this->data = $data; |
167 | 167 | |
168 | 168 | // Then generate a unique id from the data. |
169 | - $this->id = md5( wp_json_encode( $data ) ); |
|
169 | + $this->id = md5(wp_json_encode($data)); |
|
170 | 170 | |
171 | 171 | // Finally, process the submission. |
172 | 172 | try { |
@@ -176,29 +176,29 @@ discard block |
||
176 | 176 | $processors = apply_filters( |
177 | 177 | 'getpaid_payment_form_submission_processors', |
178 | 178 | array( |
179 | - array( $this, 'process_payment_form' ), |
|
180 | - array( $this, 'process_invoice' ), |
|
181 | - array( $this, 'process_fees' ), |
|
182 | - array( $this, 'process_items' ), |
|
183 | - array( $this, 'process_discount' ), |
|
184 | - array( $this, 'process_taxes' ), |
|
179 | + array($this, 'process_payment_form'), |
|
180 | + array($this, 'process_invoice'), |
|
181 | + array($this, 'process_fees'), |
|
182 | + array($this, 'process_items'), |
|
183 | + array($this, 'process_discount'), |
|
184 | + array($this, 'process_taxes'), |
|
185 | 185 | ), |
186 | 186 | $this |
187 | 187 | ); |
188 | 188 | |
189 | - foreach ( $processors as $processor ) { |
|
190 | - call_user_func_array( $processor, array( &$this ) ); |
|
189 | + foreach ($processors as $processor) { |
|
190 | + call_user_func_array($processor, array(&$this)); |
|
191 | 191 | } |
192 | - } catch ( GetPaid_Payment_Exception $e ) { |
|
192 | + } catch (GetPaid_Payment_Exception $e) { |
|
193 | 193 | $this->last_error = $e->getMessage(); |
194 | 194 | $this->last_error_code = $e->getErrorCode(); |
195 | - } catch ( Exception $e ) { |
|
195 | + } catch (Exception $e) { |
|
196 | 196 | $this->last_error = $e->getMessage(); |
197 | 197 | $this->last_error_code = $e->getCode(); |
198 | 198 | } |
199 | 199 | |
200 | 200 | // Fired when we are done processing a submission. |
201 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
201 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
202 | 202 | |
203 | 203 | } |
204 | 204 | |
@@ -219,18 +219,18 @@ discard block |
||
219 | 219 | public function process_payment_form() { |
220 | 220 | |
221 | 221 | // Every submission needs an active payment form. |
222 | - if ( empty( $this->data['form_id'] ) ) { |
|
223 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
222 | + if (empty($this->data['form_id'])) { |
|
223 | + throw new Exception(__('Missing payment form', 'invoicing')); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | // Fetch the payment form. |
227 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
227 | + $this->payment_form = new GetPaid_Payment_Form($this->data['form_id']); |
|
228 | 228 | |
229 | - if ( ! $this->payment_form->is_active() ) { |
|
230 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
229 | + if (!$this->payment_form->is_active()) { |
|
230 | + throw new Exception(__('Payment form not active', 'invoicing')); |
|
231 | 231 | } |
232 | 232 | |
233 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
233 | + do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this)); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -260,64 +260,64 @@ discard block |
||
260 | 260 | public function process_invoice() { |
261 | 261 | |
262 | 262 | // Abort if there is no invoice. |
263 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
263 | + if (empty($this->data['invoice_id'])) { |
|
264 | 264 | |
265 | 265 | // Check if we are resuming a payment. |
266 | - if ( empty( $this->data['maybe_use_invoice'] ) ) { |
|
266 | + if (empty($this->data['maybe_use_invoice'])) { |
|
267 | 267 | return; |
268 | 268 | } |
269 | 269 | |
270 | - $invoice = wpinv_get_invoice( $this->data['maybe_use_invoice'] ); |
|
271 | - if ( empty( $invoice ) || ! $invoice->has_status( 'draft, auto-draft, wpi-pending' ) ) { |
|
270 | + $invoice = wpinv_get_invoice($this->data['maybe_use_invoice']); |
|
271 | + if (empty($invoice) || !$invoice->has_status('draft, auto-draft, wpi-pending')) { |
|
272 | 272 | return; |
273 | 273 | } |
274 | 274 | } |
275 | 275 | |
276 | 276 | // If the submission is for an existing invoice, ensure that it exists |
277 | 277 | // and that it is not paid for. |
278 | - if ( empty( $invoice ) ) { |
|
279 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
278 | + if (empty($invoice)) { |
|
279 | + $invoice = wpinv_get_invoice($this->data['invoice_id']); |
|
280 | 280 | } |
281 | 281 | |
282 | - if ( empty( $invoice ) ) { |
|
283 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
282 | + if (empty($invoice)) { |
|
283 | + throw new Exception(__('Invalid invoice', 'invoicing')); |
|
284 | 284 | } |
285 | 285 | |
286 | - if ( $invoice->is_paid() ) { |
|
287 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
286 | + if ($invoice->is_paid()) { |
|
287 | + throw new Exception(__('This invoice is already paid for.', 'invoicing')); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | $this->payment_form->invoice = $invoice; |
291 | - if ( ! $this->payment_form->is_default() ) { |
|
291 | + if (!$this->payment_form->is_default()) { |
|
292 | 292 | |
293 | 293 | $items = array(); |
294 | 294 | $item_ids = array(); |
295 | 295 | |
296 | - foreach ( $invoice->get_items() as $item ) { |
|
297 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
296 | + foreach ($invoice->get_items() as $item) { |
|
297 | + if (!in_array($item->get_id(), $item_ids)) { |
|
298 | 298 | $item_ids[] = $item->get_id(); |
299 | 299 | $items[] = $item; |
300 | 300 | } |
301 | 301 | } |
302 | 302 | |
303 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
304 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
303 | + foreach ($this->payment_form->get_items() as $item) { |
|
304 | + if (!in_array($item->get_id(), $item_ids)) { |
|
305 | 305 | $item_ids[] = $item->get_id(); |
306 | 306 | $items[] = $item; |
307 | 307 | } |
308 | 308 | } |
309 | 309 | |
310 | - $this->payment_form->set_items( $items ); |
|
310 | + $this->payment_form->set_items($items); |
|
311 | 311 | |
312 | 312 | } else { |
313 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
313 | + $this->payment_form->set_items($invoice->get_items()); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | $this->country = $invoice->get_country(); |
317 | 317 | $this->state = $invoice->get_state(); |
318 | 318 | $this->invoice = $invoice; |
319 | 319 | |
320 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
320 | + do_action_ref_array('getpaid_submissions_process_invoice', array(&$this)); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | /** |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | * @return bool |
338 | 338 | */ |
339 | 339 | public function has_invoice() { |
340 | - return ! empty( $this->invoice ); |
|
340 | + return !empty($this->invoice); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | /* |
@@ -356,13 +356,13 @@ discard block |
||
356 | 356 | */ |
357 | 357 | public function process_items() { |
358 | 358 | |
359 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
359 | + $processor = new GetPaid_Payment_Form_Submission_Items($this); |
|
360 | 360 | |
361 | - foreach ( $processor->items as $item ) { |
|
362 | - $this->add_item( $item ); |
|
361 | + foreach ($processor->items as $item) { |
|
362 | + $this->add_item($item); |
|
363 | 363 | } |
364 | 364 | |
365 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
365 | + do_action_ref_array('getpaid_submissions_process_items', array(&$this)); |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | /** |
@@ -371,20 +371,20 @@ discard block |
||
371 | 371 | * @since 1.0.19 |
372 | 372 | * @param GetPaid_Form_Item $item |
373 | 373 | */ |
374 | - public function add_item( $item ) { |
|
374 | + public function add_item($item) { |
|
375 | 375 | |
376 | 376 | // Make sure that it is available for purchase. |
377 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
377 | + if (!$item->can_purchase() || isset($this->items[$item->get_id()])) { |
|
378 | 378 | return; |
379 | 379 | } |
380 | 380 | |
381 | 381 | // Each submission can only contain one recurring item. |
382 | - if ( $item->is_recurring() ) { |
|
382 | + if ($item->is_recurring()) { |
|
383 | 383 | $this->has_recurring = $item->get_id(); |
384 | 384 | } |
385 | 385 | |
386 | 386 | // Update the items and totals. |
387 | - $this->items[ $item->get_id() ] = $item; |
|
387 | + $this->items[$item->get_id()] = $item; |
|
388 | 388 | $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
389 | 389 | $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
390 | 390 | |
@@ -398,17 +398,17 @@ discard block |
||
398 | 398 | * |
399 | 399 | * @since 1.0.19 |
400 | 400 | */ |
401 | - public function remove_item( $item_id ) { |
|
401 | + public function remove_item($item_id) { |
|
402 | 402 | |
403 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
404 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
405 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
403 | + if (isset($this->items[$item_id])) { |
|
404 | + $this->totals['subtotal']['initial'] -= $this->items[$item_id]->get_sub_total(); |
|
405 | + $this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total(); |
|
406 | 406 | |
407 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
407 | + if ($this->items[$item_id]->is_recurring()) { |
|
408 | 408 | $this->has_recurring = 0; |
409 | 409 | } |
410 | 410 | |
411 | - unset( $this->items[ $item_id ] ); |
|
411 | + unset($this->items[$item_id]); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | } |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | */ |
421 | 421 | public function get_subtotal() { |
422 | 422 | |
423 | - if ( wpinv_prices_include_tax() ) { |
|
423 | + if (wpinv_prices_include_tax()) { |
|
424 | 424 | return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
425 | 425 | } |
426 | 426 | |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | */ |
435 | 435 | public function get_recurring_subtotal() { |
436 | 436 | |
437 | - if ( wpinv_prices_include_tax() ) { |
|
437 | + if (wpinv_prices_include_tax()) { |
|
438 | 438 | return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
439 | 439 | } |
440 | 440 | |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | * @return bool |
459 | 459 | */ |
460 | 460 | public function has_subscription_group() { |
461 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
461 | + return $this->has_recurring && getpaid_should_group_subscriptions($this) && 1 == count(getpaid_get_subscription_groups($this)); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | /** |
@@ -468,7 +468,7 @@ discard block |
||
468 | 468 | * @return bool |
469 | 469 | */ |
470 | 470 | public function has_multiple_subscription_groups() { |
471 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
471 | + return $this->has_recurring && 1 < count(getpaid_get_subscription_groups($this)); |
|
472 | 472 | } |
473 | 473 | |
474 | 474 | /* |
@@ -488,39 +488,39 @@ discard block |
||
488 | 488 | public function process_taxes() { |
489 | 489 | |
490 | 490 | // Abort if we're not using taxes. |
491 | - if ( ! $this->use_taxes() ) { |
|
491 | + if (!$this->use_taxes()) { |
|
492 | 492 | return; |
493 | 493 | } |
494 | 494 | |
495 | 495 | // If a custom country && state has been passed in, use it to calculate taxes. |
496 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
497 | - if ( ! empty( $country ) ) { |
|
496 | + $country = $this->get_field('wpinv_country', 'billing'); |
|
497 | + if (!empty($country)) { |
|
498 | 498 | $this->country = $country; |
499 | 499 | } |
500 | 500 | |
501 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
502 | - if ( ! empty( $state ) ) { |
|
501 | + $state = $this->get_field('wpinv_state', 'billing'); |
|
502 | + if (!empty($state)) { |
|
503 | 503 | $this->state = $state; |
504 | 504 | } |
505 | 505 | |
506 | 506 | // Confirm if the provided country and the ip country are similar. |
507 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
508 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
509 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
507 | + $address_confirmed = $this->get_field('confirm-address'); |
|
508 | + if (isset($_POST['billing']['country']) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) { |
|
509 | + throw new Exception(__('The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing')); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | // Abort if the country is not taxable. |
513 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
513 | + if (!wpinv_is_country_taxable($this->country)) { |
|
514 | 514 | return; |
515 | 515 | } |
516 | 516 | |
517 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
517 | + $processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
518 | 518 | |
519 | - foreach ( $processor->taxes as $tax ) { |
|
520 | - $this->add_tax( $tax ); |
|
519 | + foreach ($processor->taxes as $tax) { |
|
520 | + $this->add_tax($tax); |
|
521 | 521 | } |
522 | 522 | |
523 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
523 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | /** |
@@ -529,16 +529,16 @@ discard block |
||
529 | 529 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
530 | 530 | * @since 1.0.19 |
531 | 531 | */ |
532 | - public function add_tax( $tax ) { |
|
532 | + public function add_tax($tax) { |
|
533 | 533 | |
534 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
535 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
536 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
534 | + if (wpinv_round_tax_per_tax_rate()) { |
|
535 | + $tax['initial_tax'] = wpinv_round_amount($tax['initial_tax']); |
|
536 | + $tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']); |
|
537 | 537 | } |
538 | 538 | |
539 | - $this->taxes[ $tax['name'] ] = $tax; |
|
540 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
541 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
539 | + $this->taxes[$tax['name']] = $tax; |
|
540 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount($tax['initial_tax']); |
|
541 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']); |
|
542 | 542 | |
543 | 543 | } |
544 | 544 | |
@@ -547,12 +547,12 @@ discard block |
||
547 | 547 | * |
548 | 548 | * @since 1.0.19 |
549 | 549 | */ |
550 | - public function remove_tax( $tax_name ) { |
|
550 | + public function remove_tax($tax_name) { |
|
551 | 551 | |
552 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
553 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
554 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
555 | - unset( $this->taxes[ $tax_name ] ); |
|
552 | + if (isset($this->taxes[$tax_name])) { |
|
553 | + $this->totals['taxes']['initial'] -= $this->taxes[$tax_name]['initial_tax']; |
|
554 | + $this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax']; |
|
555 | + unset($this->taxes[$tax_name]); |
|
556 | 556 | } |
557 | 557 | |
558 | 558 | } |
@@ -566,11 +566,11 @@ discard block |
||
566 | 566 | |
567 | 567 | $use_taxes = wpinv_use_taxes(); |
568 | 568 | |
569 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
569 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
570 | 570 | $use_taxes = false; |
571 | 571 | } |
572 | 572 | |
573 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
573 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
574 | 574 | |
575 | 575 | } |
576 | 576 | |
@@ -619,13 +619,13 @@ discard block |
||
619 | 619 | |
620 | 620 | $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
621 | 621 | $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
622 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
622 | + $processor = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total); |
|
623 | 623 | |
624 | - foreach ( $processor->discounts as $discount ) { |
|
625 | - $this->add_discount( $discount ); |
|
624 | + foreach ($processor->discounts as $discount) { |
|
625 | + $this->add_discount($discount); |
|
626 | 626 | } |
627 | 627 | |
628 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
628 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
629 | 629 | } |
630 | 630 | |
631 | 631 | /** |
@@ -634,10 +634,10 @@ discard block |
||
634 | 634 | * @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. |
635 | 635 | * @since 1.0.19 |
636 | 636 | */ |
637 | - public function add_discount( $discount ) { |
|
638 | - $this->discounts[ $discount['name'] ] = $discount; |
|
639 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
640 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
637 | + public function add_discount($discount) { |
|
638 | + $this->discounts[$discount['name']] = $discount; |
|
639 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount($discount['initial_discount']); |
|
640 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']); |
|
641 | 641 | } |
642 | 642 | |
643 | 643 | /** |
@@ -645,12 +645,12 @@ discard block |
||
645 | 645 | * |
646 | 646 | * @since 1.0.19 |
647 | 647 | */ |
648 | - public function remove_discount( $name ) { |
|
648 | + public function remove_discount($name) { |
|
649 | 649 | |
650 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
651 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
652 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
653 | - unset( $this->discounts[ $name ] ); |
|
650 | + if (isset($this->discounts[$name])) { |
|
651 | + $this->totals['discount']['initial'] -= $this->discounts[$name]['initial_discount']; |
|
652 | + $this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount']; |
|
653 | + unset($this->discounts[$name]); |
|
654 | 654 | } |
655 | 655 | |
656 | 656 | } |
@@ -662,7 +662,7 @@ discard block |
||
662 | 662 | * @return bool |
663 | 663 | */ |
664 | 664 | public function has_discount_code() { |
665 | - return ! empty( $this->discounts['discount_code'] ); |
|
665 | + return !empty($this->discounts['discount_code']); |
|
666 | 666 | } |
667 | 667 | |
668 | 668 | /** |
@@ -719,13 +719,13 @@ discard block |
||
719 | 719 | */ |
720 | 720 | public function process_fees() { |
721 | 721 | |
722 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
722 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
723 | 723 | |
724 | - foreach ( $fees_processor->fees as $fee ) { |
|
725 | - $this->add_fee( $fee ); |
|
724 | + foreach ($fees_processor->fees as $fee) { |
|
725 | + $this->add_fee($fee); |
|
726 | 726 | } |
727 | 727 | |
728 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
728 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
729 | 729 | } |
730 | 730 | |
731 | 731 | /** |
@@ -734,17 +734,17 @@ discard block |
||
734 | 734 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
735 | 735 | * @since 1.0.19 |
736 | 736 | */ |
737 | - public function add_fee( $fee ) { |
|
737 | + public function add_fee($fee) { |
|
738 | 738 | |
739 | - if ( $fee['name'] == 'shipping' ) { |
|
740 | - $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
741 | - $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
739 | + if ($fee['name'] == 'shipping') { |
|
740 | + $this->totals['shipping']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
741 | + $this->totals['shipping']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
742 | 742 | return; |
743 | 743 | } |
744 | 744 | |
745 | - $this->fees[ $fee['name'] ] = $fee; |
|
746 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
747 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
745 | + $this->fees[$fee['name']] = $fee; |
|
746 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
747 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
748 | 748 | |
749 | 749 | } |
750 | 750 | |
@@ -753,15 +753,15 @@ discard block |
||
753 | 753 | * |
754 | 754 | * @since 1.0.19 |
755 | 755 | */ |
756 | - public function remove_fee( $name ) { |
|
756 | + public function remove_fee($name) { |
|
757 | 757 | |
758 | - if ( isset( $this->fees[ $name ] ) ) { |
|
759 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
760 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
761 | - unset( $this->fees[ $name ] ); |
|
758 | + if (isset($this->fees[$name])) { |
|
759 | + $this->totals['fees']['initial'] -= $this->fees[$name]['initial_fee']; |
|
760 | + $this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee']; |
|
761 | + unset($this->fees[$name]); |
|
762 | 762 | } |
763 | 763 | |
764 | - if ( 'shipping' == $name ) { |
|
764 | + if ('shipping' == $name) { |
|
765 | 765 | $this->totals['shipping']['initial'] = 0; |
766 | 766 | $this->totals['shipping']['recurring'] = 0; |
767 | 767 | } |
@@ -802,7 +802,7 @@ discard block |
||
802 | 802 | * @since 1.0.19 |
803 | 803 | */ |
804 | 804 | public function has_fees() { |
805 | - return count( $this->fees ) !== 0; |
|
805 | + return count($this->fees) !== 0; |
|
806 | 806 | } |
807 | 807 | |
808 | 808 | /* |
@@ -838,7 +838,7 @@ discard block |
||
838 | 838 | * @since 1.0.19 |
839 | 839 | */ |
840 | 840 | public function has_shipping() { |
841 | - return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
841 | + return apply_filters('getpaid_payment_form_has_shipping', false, $this); |
|
842 | 842 | } |
843 | 843 | |
844 | 844 | /** |
@@ -848,7 +848,7 @@ discard block |
||
848 | 848 | * @since 1.0.19 |
849 | 849 | */ |
850 | 850 | public function is_initial_fetch() { |
851 | - return isset( $this->data['initial_state'] ) && empty( $this->data['initial_state'] ); |
|
851 | + return isset($this->data['initial_state']) && empty($this->data['initial_state']); |
|
852 | 852 | } |
853 | 853 | |
854 | 854 | /** |
@@ -858,7 +858,7 @@ discard block |
||
858 | 858 | */ |
859 | 859 | public function get_total() { |
860 | 860 | $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
861 | - return max( $total, 0 ); |
|
861 | + return max($total, 0); |
|
862 | 862 | } |
863 | 863 | |
864 | 864 | /** |
@@ -868,7 +868,7 @@ discard block |
||
868 | 868 | */ |
869 | 869 | public function get_recurring_total() { |
870 | 870 | $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
871 | - return max( $total, 0 ); |
|
871 | + return max($total, 0); |
|
872 | 872 | } |
873 | 873 | |
874 | 874 | /** |
@@ -880,12 +880,12 @@ discard block |
||
880 | 880 | $initial = $this->get_total(); |
881 | 881 | $recurring = $this->get_recurring_total(); |
882 | 882 | |
883 | - if ( $this->has_recurring == 0 ) { |
|
883 | + if ($this->has_recurring == 0) { |
|
884 | 884 | $recurring = 0; |
885 | 885 | } |
886 | 886 | |
887 | 887 | $collect = $initial > 0 || $recurring > 0; |
888 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
888 | + return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this); |
|
889 | 889 | } |
890 | 890 | |
891 | 891 | /** |
@@ -894,7 +894,7 @@ discard block |
||
894 | 894 | * @since 1.0.19 |
895 | 895 | */ |
896 | 896 | public function get_billing_email() { |
897 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
897 | + return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this); |
|
898 | 898 | } |
899 | 899 | |
900 | 900 | /** |
@@ -904,7 +904,7 @@ discard block |
||
904 | 904 | */ |
905 | 905 | public function has_billing_email() { |
906 | 906 | $billing_email = $this->get_billing_email(); |
907 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
907 | + return !empty($billing_email) && is_email($billing_email); |
|
908 | 908 | } |
909 | 909 | |
910 | 910 | /** |
@@ -934,8 +934,8 @@ discard block |
||
934 | 934 | * @since 1.0.19 |
935 | 935 | * @return mixed|null |
936 | 936 | */ |
937 | - public function get_field( $field, $sub_array_key = null ) { |
|
938 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
937 | + public function get_field($field, $sub_array_key = null) { |
|
938 | + return getpaid_get_array_field($this->data, $field, $sub_array_key); |
|
939 | 939 | } |
940 | 940 | |
941 | 941 | /** |
@@ -943,8 +943,8 @@ discard block |
||
943 | 943 | * |
944 | 944 | * @since 1.0.19 |
945 | 945 | */ |
946 | - public function is_required_field_set( $field ) { |
|
947 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
946 | + public function is_required_field_set($field) { |
|
947 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
948 | 948 | } |
949 | 949 | |
950 | 950 | /** |
@@ -952,8 +952,8 @@ discard block |
||
952 | 952 | * |
953 | 953 | * @since 1.0.19 |
954 | 954 | */ |
955 | - public function format_amount( $amount ) { |
|
956 | - return wpinv_price( $amount, $this->get_currency() ); |
|
955 | + public function format_amount($amount) { |
|
956 | + return wpinv_price($amount, $this->get_currency()); |
|
957 | 957 | } |
958 | 958 | |
959 | 959 | } |
@@ -52,27 +52,27 @@ |
||
52 | 52 | |
53 | 53 | // Total Fee. |
54 | 54 | if ( 'fee' === $key ) { |
55 | - wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() ); |
|
55 | + wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() ); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | // Total discount. |
59 | 59 | if ( 'discount' === $key ) { |
60 | - wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); |
|
60 | + wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | // Shipping. |
64 | 64 | if ( 'shipping' === $key ) { |
65 | - wpinv_the_price( $invoice->get_shipping(), $invoice->get_currency() ); |
|
65 | + wpinv_the_price( $invoice->get_shipping(), $invoice->get_currency() ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | // Sub total. |
69 | 69 | if ( 'subtotal' === $key ) { |
70 | - wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); |
|
70 | + wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // Total. |
74 | 74 | if ( 'total' === $key ) { |
75 | - wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
75 | + wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // Fires when printing a cart total. |
@@ -9,26 +9,26 @@ discard block |
||
9 | 9 | * @var WPInv_Invoice $invoice |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | // Totals rows. |
15 | -$totals = getpaid_invoice_totals_rows( $invoice ); |
|
15 | +$totals = getpaid_invoice_totals_rows($invoice); |
|
16 | 16 | |
17 | -do_action( 'getpaid_before_invoice_line_totals', $invoice, $totals ); |
|
17 | +do_action('getpaid_before_invoice_line_totals', $invoice, $totals); |
|
18 | 18 | |
19 | 19 | ?> |
20 | 20 | <div class='getpaid-invoice-line-totals'> |
21 | 21 | <div class="row"> |
22 | 22 | <div class="col-12 offset-sm-6 col-sm-6 border-sm-left pl-sm-0"> |
23 | 23 | |
24 | - <?php foreach ( $totals as $key => $label ) : ?> |
|
24 | + <?php foreach ($totals as $key => $label) : ?> |
|
25 | 25 | |
26 | - <div class="getpaid-invoice-line-totals-col <?php echo esc_attr( $key ); ?>"> |
|
26 | + <div class="getpaid-invoice-line-totals-col <?php echo esc_attr($key); ?>"> |
|
27 | 27 | |
28 | 28 | <div class="form-row row"> |
29 | 29 | |
30 | 30 | <div class="col-8 getpaid-invoice-line-totals-label"> |
31 | - <?php echo esc_html( $label ); ?> |
|
31 | + <?php echo esc_html($label); ?> |
|
32 | 32 | </div> |
33 | 33 | |
34 | 34 | <div class="col-4 getpaid-invoice-line-totals-value pl-0"> |
@@ -36,62 +36,62 @@ discard block |
||
36 | 36 | <?php |
37 | 37 | |
38 | 38 | // Total tax. |
39 | - if ( 'tax' === $key ) { |
|
40 | - wpinv_the_price( $invoice->get_total_tax(), $invoice->get_currency() ); |
|
39 | + if ('tax' === $key) { |
|
40 | + wpinv_the_price($invoice->get_total_tax(), $invoice->get_currency()); |
|
41 | 41 | |
42 | - if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
42 | + if (wpinv_use_taxes() && !$invoice->get_disable_taxes()) { |
|
43 | 43 | |
44 | 44 | $taxes = $invoice->get_total_tax(); |
45 | - if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) { |
|
45 | + if (empty($taxes) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction($invoice->get_country())) { |
|
46 | 46 | echo ' <em class="text-muted small">'; |
47 | - _x( '(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing' ); |
|
47 | + _x('(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing'); |
|
48 | 48 | echo '</em>'; |
49 | 49 | } |
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
53 | 53 | // Check if field starts with tax__. |
54 | - if ( 0 === strpos( $key, 'tax__' ) ) { |
|
55 | - $tax_amount = $invoice->get_tax_total_by_name( str_replace( 'tax__', '', $key ) ); |
|
56 | - wpinv_the_price( $tax_amount, $invoice->get_currency() ); |
|
54 | + if (0 === strpos($key, 'tax__')) { |
|
55 | + $tax_amount = $invoice->get_tax_total_by_name(str_replace('tax__', '', $key)); |
|
56 | + wpinv_the_price($tax_amount, $invoice->get_currency()); |
|
57 | 57 | |
58 | - if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
58 | + if (wpinv_use_taxes() && !$invoice->get_disable_taxes()) { |
|
59 | 59 | |
60 | - if ( empty( $tax_amount ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) { |
|
60 | + if (empty($tax_amount) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction($invoice->get_country())) { |
|
61 | 61 | echo ' <em class="text-muted small">'; |
62 | - _x( '(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing' ); |
|
62 | + _x('(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing'); |
|
63 | 63 | echo '</em>'; |
64 | 64 | } |
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
68 | 68 | // Total Fee. |
69 | - if ( 'fee' === $key ) { |
|
70 | - wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() ); |
|
69 | + if ('fee' === $key) { |
|
70 | + wpinv_the_price($invoice->get_total_fees(), $invoice->get_currency()); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // Total discount. |
74 | - if ( 'discount' === $key ) { |
|
75 | - wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); |
|
74 | + if ('discount' === $key) { |
|
75 | + wpinv_the_price($invoice->get_total_discount(), $invoice->get_currency()); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // Shipping. |
79 | - if ( 'shipping' === $key ) { |
|
80 | - wpinv_the_price( $invoice->get_shipping(), $invoice->get_currency() ); |
|
79 | + if ('shipping' === $key) { |
|
80 | + wpinv_the_price($invoice->get_shipping(), $invoice->get_currency()); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | // Sub total. |
84 | - if ( 'subtotal' === $key ) { |
|
85 | - wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); |
|
84 | + if ('subtotal' === $key) { |
|
85 | + wpinv_the_price($invoice->get_subtotal(), $invoice->get_currency()); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | // Total. |
89 | - if ( 'total' === $key ) { |
|
90 | - wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
89 | + if ('total' === $key) { |
|
90 | + wpinv_the_price($invoice->get_total(), $invoice->get_currency()); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | // Fires when printing a cart total. |
94 | - do_action( "getpaid_invoice_cart_totals_$key", $invoice ); |
|
94 | + do_action("getpaid_invoice_cart_totals_$key", $invoice); |
|
95 | 95 | |
96 | 96 | ?> |
97 | 97 | |
@@ -105,4 +105,4 @@ discard block |
||
105 | 105 | </div> |
106 | 106 | </div> <!-- end .getpaid-invoice-line-totals --> |
107 | 107 | |
108 | -<?php do_action( 'getpaid_after_invoice_line_totals', $invoice, $totals ); ?> |
|
108 | +<?php do_action('getpaid_after_invoice_line_totals', $invoice, $totals); ?> |
@@ -12,294 +12,294 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports_Helper { |
14 | 14 | |
15 | - /** |
|
16 | - * Get report totals such as invoice totals and discount amounts. |
|
17 | - * |
|
18 | - * Data example: |
|
19 | - * |
|
20 | - * 'subtotal' => array( |
|
21 | - * 'type' => 'invoice_data', |
|
22 | - * 'function' => 'SUM', |
|
23 | - * 'name' => 'subtotal' |
|
24 | - * ) |
|
25 | - * |
|
26 | - * @param array $args |
|
27 | - * @return mixed depending on query_type |
|
28 | - */ |
|
29 | - public static function get_invoice_report_data( $args = array() ) { |
|
30 | - global $wpdb; |
|
31 | - |
|
32 | - $default_args = array( |
|
33 | - 'data' => array(), // The data to retrieve. |
|
34 | - 'where' => array(), // An array of where queries. |
|
35 | - 'query_type' => 'get_row', // wpdb query to run. |
|
36 | - 'group_by' => '', // What to group results by. |
|
37 | - 'order_by' => '', // What to order by. |
|
38 | - 'limit' => '', // Results limit. |
|
39 | - 'filter_range' => array(), // An array of before and after dates to limit results by. |
|
40 | - 'invoice_types' => array( 'wpi_invoice' ), // An array of post types to retrieve. |
|
41 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold' ), |
|
42 | - 'parent_invoice_status' => false, // Optionally filter by parent invoice status. |
|
43 | - ); |
|
44 | - |
|
45 | - $args = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args ); |
|
46 | - $args = wp_parse_args( $args, $default_args ); |
|
47 | - |
|
48 | - extract( $args ); |
|
49 | - |
|
50 | - if ( empty( $data ) ) { |
|
51 | - return ''; |
|
52 | - } |
|
53 | - |
|
54 | - $query = array(); |
|
55 | - $query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) ); |
|
56 | - $query['from'] = "FROM {$wpdb->posts} AS posts"; |
|
57 | - $query['join'] = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) ); |
|
58 | - |
|
59 | - $query['where'] = " |
|
15 | + /** |
|
16 | + * Get report totals such as invoice totals and discount amounts. |
|
17 | + * |
|
18 | + * Data example: |
|
19 | + * |
|
20 | + * 'subtotal' => array( |
|
21 | + * 'type' => 'invoice_data', |
|
22 | + * 'function' => 'SUM', |
|
23 | + * 'name' => 'subtotal' |
|
24 | + * ) |
|
25 | + * |
|
26 | + * @param array $args |
|
27 | + * @return mixed depending on query_type |
|
28 | + */ |
|
29 | + public static function get_invoice_report_data( $args = array() ) { |
|
30 | + global $wpdb; |
|
31 | + |
|
32 | + $default_args = array( |
|
33 | + 'data' => array(), // The data to retrieve. |
|
34 | + 'where' => array(), // An array of where queries. |
|
35 | + 'query_type' => 'get_row', // wpdb query to run. |
|
36 | + 'group_by' => '', // What to group results by. |
|
37 | + 'order_by' => '', // What to order by. |
|
38 | + 'limit' => '', // Results limit. |
|
39 | + 'filter_range' => array(), // An array of before and after dates to limit results by. |
|
40 | + 'invoice_types' => array( 'wpi_invoice' ), // An array of post types to retrieve. |
|
41 | + 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold' ), |
|
42 | + 'parent_invoice_status' => false, // Optionally filter by parent invoice status. |
|
43 | + ); |
|
44 | + |
|
45 | + $args = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args ); |
|
46 | + $args = wp_parse_args( $args, $default_args ); |
|
47 | + |
|
48 | + extract( $args ); |
|
49 | + |
|
50 | + if ( empty( $data ) ) { |
|
51 | + return ''; |
|
52 | + } |
|
53 | + |
|
54 | + $query = array(); |
|
55 | + $query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) ); |
|
56 | + $query['from'] = "FROM {$wpdb->posts} AS posts"; |
|
57 | + $query['join'] = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) ); |
|
58 | + |
|
59 | + $query['where'] = " |
|
60 | 60 | WHERE posts.post_type IN ( '" . implode( "','", $invoice_types ) . "' ) |
61 | 61 | "; |
62 | 62 | |
63 | - if ( ! empty( $invoice_status ) ) { |
|
64 | - $query['where'] .= " |
|
63 | + if ( ! empty( $invoice_status ) ) { |
|
64 | + $query['where'] .= " |
|
65 | 65 | AND posts.post_status IN ( '" . implode( "','", $invoice_status ) . "' ) |
66 | 66 | "; |
67 | - } |
|
68 | - |
|
69 | - if ( ! empty( $parent_invoice_status ) ) { |
|
70 | - if ( ! empty( $invoice_status ) ) { |
|
71 | - $query['where'] .= " AND ( parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) OR parent.ID IS NULL ) "; |
|
72 | - } else { |
|
73 | - $query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) "; |
|
74 | - } |
|
75 | - } |
|
76 | - |
|
77 | - if ( ! empty( $filter_range['before'] ) ) { |
|
78 | - $query['where'] .= " |
|
67 | + } |
|
68 | + |
|
69 | + if ( ! empty( $parent_invoice_status ) ) { |
|
70 | + if ( ! empty( $invoice_status ) ) { |
|
71 | + $query['where'] .= " AND ( parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) OR parent.ID IS NULL ) "; |
|
72 | + } else { |
|
73 | + $query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) "; |
|
74 | + } |
|
75 | + } |
|
76 | + |
|
77 | + if ( ! empty( $filter_range['before'] ) ) { |
|
78 | + $query['where'] .= " |
|
79 | 79 | AND posts.post_date <= '" . gmdate( 'Y-m-d 23:59:59', strtotime( $filter_range['before'] ) ) . "' |
80 | 80 | "; |
81 | - } |
|
81 | + } |
|
82 | 82 | |
83 | - if ( ! empty( $filter_range['after'] ) ) { |
|
84 | - $query['where'] .= " |
|
83 | + if ( ! empty( $filter_range['after'] ) ) { |
|
84 | + $query['where'] .= " |
|
85 | 85 | AND posts.post_date >= '" . gmdate( 'Y-m-d 00:00:00', strtotime( $filter_range['after'] ) ) . "' |
86 | 86 | "; |
87 | - } |
|
87 | + } |
|
88 | 88 | |
89 | - if ( ! empty( $where ) ) { |
|
89 | + if ( ! empty( $where ) ) { |
|
90 | 90 | |
91 | - foreach ( $where as $value ) { |
|
91 | + foreach ( $where as $value ) { |
|
92 | 92 | |
93 | - if ( strtolower( $value['operator'] ) === 'in' || strtolower( $value['operator'] ) === 'not in' ) { |
|
94 | - |
|
95 | - if ( is_array( $value['value'] ) ) { |
|
96 | - $value['value'] = implode( "','", $value['value'] ); |
|
97 | - } |
|
98 | - |
|
99 | - if ( ! empty( $value['value'] ) ) { |
|
100 | - $where_value = "{$value['operator']} ('{$value['value']}')"; |
|
101 | - } |
|
102 | - } else { |
|
103 | - $where_value = "{$value['operator']} '{$value['value']}'"; |
|
104 | - } |
|
105 | - |
|
106 | - if ( ! empty( $where_value ) ) { |
|
107 | - $query['where'] .= " AND {$value['key']} {$where_value}"; |
|
108 | - } |
|
109 | - } |
|
110 | - } |
|
111 | - |
|
112 | - if ( $group_by ) { |
|
113 | - $query['group_by'] = "GROUP BY {$group_by}"; |
|
114 | - } |
|
115 | - |
|
116 | - if ( $order_by ) { |
|
117 | - $query['order_by'] = "ORDER BY {$order_by}"; |
|
118 | - } |
|
119 | - |
|
120 | - if ( $limit ) { |
|
121 | - $query['limit'] = "LIMIT {$limit}"; |
|
122 | - } |
|
123 | - |
|
124 | - $query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data ); |
|
125 | - $query = implode( ' ', $query ); |
|
126 | - |
|
127 | - return self::execute( $query_type, $query ); |
|
128 | - |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Prepares the data to select. |
|
133 | - * |
|
134 | - * |
|
135 | - * @param array $data |
|
136 | - * @return array |
|
137 | - */ |
|
138 | - public static function prepare_invoice_data( $data ) { |
|
139 | - |
|
140 | - $prepared = array(); |
|
141 | - |
|
142 | - foreach ( $data as $raw_key => $value ) { |
|
143 | - $key = sanitize_key( $raw_key ); |
|
144 | - $distinct = ''; |
|
145 | - |
|
146 | - if ( isset( $value['distinct'] ) ) { |
|
147 | - $distinct = 'DISTINCT'; |
|
148 | - } |
|
149 | - |
|
150 | - $get_key = self::get_invoice_table_key( $key, $value['type'] ); |
|
151 | - |
|
152 | - if ( false === $get_key ) { |
|
153 | - // Skip to the next foreach iteration else the query will be invalid. |
|
154 | - continue; |
|
155 | - } |
|
156 | - |
|
157 | - if ( ! empty( $value['function'] ) ) { |
|
158 | - $get = "{$value['function']}({$distinct} {$get_key})"; |
|
159 | - } else { |
|
160 | - $get = "{$distinct} {$get_key}"; |
|
161 | - } |
|
162 | - |
|
163 | - $prepared[] = "{$get} as {$value['name']}"; |
|
164 | - } |
|
165 | - |
|
166 | - return $prepared; |
|
167 | - |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Prepares the joins to use. |
|
172 | - * |
|
173 | - * |
|
174 | - * @param array $data |
|
175 | - * @param bool $with_parent |
|
176 | - * @return array |
|
177 | - */ |
|
178 | - public static function prepare_invoice_joins( $data, $with_parent ) { |
|
179 | - global $wpdb; |
|
180 | - |
|
181 | - $prepared = array(); |
|
182 | - |
|
183 | - foreach ( $data as $raw_key => $value ) { |
|
184 | - $join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER'; |
|
185 | - $type = isset( $value['type'] ) ? $value['type'] : false; |
|
186 | - $key = sanitize_key( $raw_key ); |
|
187 | - |
|
188 | - switch ( $type ) { |
|
189 | - case 'meta': |
|
190 | - $prepared[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )"; |
|
191 | - break; |
|
192 | - case 'parent_meta': |
|
193 | - $prepared[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')"; |
|
194 | - break; |
|
195 | - case 'invoice_data': |
|
196 | - $prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id"; |
|
197 | - break; |
|
198 | - case 'invoice_item': |
|
199 | - $prepared['invoice_items'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoice_items AS invoice_items ON posts.ID = invoice_items.post_id"; |
|
200 | - break; |
|
201 | - } |
|
202 | - } |
|
203 | - |
|
204 | - if ( $with_parent ) { |
|
205 | - $prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID"; |
|
206 | - } |
|
207 | - |
|
208 | - return $prepared; |
|
209 | - |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Retrieves the appropriate table key to use. |
|
214 | - * |
|
215 | - * |
|
216 | - * @param string $key |
|
217 | - * @param string $table |
|
218 | - * @return string|false |
|
219 | - */ |
|
220 | - public static function get_invoice_table_key( $key, $table ) { |
|
221 | - |
|
222 | - $keys = array( |
|
223 | - 'meta' => "meta_{$key}.meta_value", |
|
224 | - 'parent_meta' => "parent_meta_{$key}.meta_value", |
|
225 | - 'post_data' => "posts.{$key}", |
|
226 | - 'invoice_data' => "invoices.{$key}", |
|
227 | - 'invoice_item' => "invoice_items.{$key}", |
|
228 | - ); |
|
229 | - |
|
230 | - return isset( $keys[ $table ] ) ? $keys[ $table ] : false; |
|
231 | - |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Executes a query and caches the result for a minute. |
|
236 | - * |
|
237 | - * |
|
238 | - * @param string $query_type |
|
239 | - * @param string $query |
|
240 | - * @return mixed depending on query_type |
|
241 | - */ |
|
242 | - public static function execute( $query_type, $query ) { |
|
243 | - global $wpdb; |
|
244 | - |
|
245 | - $query_hash = md5( $query_type . $query ); |
|
246 | - $result = self::get_cached_query( $query_hash ); |
|
247 | - if ( $result === false ) { |
|
248 | - self::enable_big_selects(); |
|
249 | - |
|
250 | - $result = $wpdb->$query_type( $query ); |
|
251 | - self::set_cached_query( $query_hash, $result ); |
|
252 | - } |
|
253 | - |
|
254 | - return $result; |
|
255 | - |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Enables big mysql selects for reports, just once for this session. |
|
260 | - */ |
|
261 | - protected static function enable_big_selects() { |
|
262 | - static $big_selects = false; |
|
263 | - |
|
264 | - global $wpdb; |
|
265 | - |
|
266 | - if ( ! $big_selects ) { |
|
267 | - $wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' ); |
|
268 | - $big_selects = true; |
|
269 | - } |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Get the cached query result or null if it's not in the cache. |
|
274 | - * |
|
275 | - * @param string $query_hash The query hash. |
|
276 | - * |
|
277 | - * @return mixed|false The cache contents on success, false on failure to retrieve contents. |
|
278 | - */ |
|
279 | - protected static function get_cached_query( $query_hash ) { |
|
280 | - |
|
281 | - return wp_cache_get( |
|
282 | - $query_hash, |
|
283 | - strtolower( __CLASS__ ) |
|
284 | - ); |
|
285 | - |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Set the cached query result. |
|
290 | - * |
|
291 | - * @param string $query_hash The query hash. |
|
292 | - * @param mixed $data The data to cache. |
|
293 | - */ |
|
294 | - protected static function set_cached_query( $query_hash, $data ) { |
|
295 | - |
|
296 | - wp_cache_set( |
|
297 | - $query_hash, |
|
298 | - $data, |
|
299 | - strtolower( __CLASS__ ), |
|
300 | - MINUTE_IN_SECONDS |
|
301 | - ); |
|
302 | - |
|
303 | - } |
|
93 | + if ( strtolower( $value['operator'] ) === 'in' || strtolower( $value['operator'] ) === 'not in' ) { |
|
94 | + |
|
95 | + if ( is_array( $value['value'] ) ) { |
|
96 | + $value['value'] = implode( "','", $value['value'] ); |
|
97 | + } |
|
98 | + |
|
99 | + if ( ! empty( $value['value'] ) ) { |
|
100 | + $where_value = "{$value['operator']} ('{$value['value']}')"; |
|
101 | + } |
|
102 | + } else { |
|
103 | + $where_value = "{$value['operator']} '{$value['value']}'"; |
|
104 | + } |
|
105 | + |
|
106 | + if ( ! empty( $where_value ) ) { |
|
107 | + $query['where'] .= " AND {$value['key']} {$where_value}"; |
|
108 | + } |
|
109 | + } |
|
110 | + } |
|
111 | + |
|
112 | + if ( $group_by ) { |
|
113 | + $query['group_by'] = "GROUP BY {$group_by}"; |
|
114 | + } |
|
115 | + |
|
116 | + if ( $order_by ) { |
|
117 | + $query['order_by'] = "ORDER BY {$order_by}"; |
|
118 | + } |
|
119 | + |
|
120 | + if ( $limit ) { |
|
121 | + $query['limit'] = "LIMIT {$limit}"; |
|
122 | + } |
|
123 | + |
|
124 | + $query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data ); |
|
125 | + $query = implode( ' ', $query ); |
|
126 | + |
|
127 | + return self::execute( $query_type, $query ); |
|
128 | + |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Prepares the data to select. |
|
133 | + * |
|
134 | + * |
|
135 | + * @param array $data |
|
136 | + * @return array |
|
137 | + */ |
|
138 | + public static function prepare_invoice_data( $data ) { |
|
139 | + |
|
140 | + $prepared = array(); |
|
141 | + |
|
142 | + foreach ( $data as $raw_key => $value ) { |
|
143 | + $key = sanitize_key( $raw_key ); |
|
144 | + $distinct = ''; |
|
145 | + |
|
146 | + if ( isset( $value['distinct'] ) ) { |
|
147 | + $distinct = 'DISTINCT'; |
|
148 | + } |
|
149 | + |
|
150 | + $get_key = self::get_invoice_table_key( $key, $value['type'] ); |
|
151 | + |
|
152 | + if ( false === $get_key ) { |
|
153 | + // Skip to the next foreach iteration else the query will be invalid. |
|
154 | + continue; |
|
155 | + } |
|
156 | + |
|
157 | + if ( ! empty( $value['function'] ) ) { |
|
158 | + $get = "{$value['function']}({$distinct} {$get_key})"; |
|
159 | + } else { |
|
160 | + $get = "{$distinct} {$get_key}"; |
|
161 | + } |
|
162 | + |
|
163 | + $prepared[] = "{$get} as {$value['name']}"; |
|
164 | + } |
|
165 | + |
|
166 | + return $prepared; |
|
167 | + |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Prepares the joins to use. |
|
172 | + * |
|
173 | + * |
|
174 | + * @param array $data |
|
175 | + * @param bool $with_parent |
|
176 | + * @return array |
|
177 | + */ |
|
178 | + public static function prepare_invoice_joins( $data, $with_parent ) { |
|
179 | + global $wpdb; |
|
180 | + |
|
181 | + $prepared = array(); |
|
182 | + |
|
183 | + foreach ( $data as $raw_key => $value ) { |
|
184 | + $join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER'; |
|
185 | + $type = isset( $value['type'] ) ? $value['type'] : false; |
|
186 | + $key = sanitize_key( $raw_key ); |
|
187 | + |
|
188 | + switch ( $type ) { |
|
189 | + case 'meta': |
|
190 | + $prepared[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )"; |
|
191 | + break; |
|
192 | + case 'parent_meta': |
|
193 | + $prepared[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')"; |
|
194 | + break; |
|
195 | + case 'invoice_data': |
|
196 | + $prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id"; |
|
197 | + break; |
|
198 | + case 'invoice_item': |
|
199 | + $prepared['invoice_items'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoice_items AS invoice_items ON posts.ID = invoice_items.post_id"; |
|
200 | + break; |
|
201 | + } |
|
202 | + } |
|
203 | + |
|
204 | + if ( $with_parent ) { |
|
205 | + $prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID"; |
|
206 | + } |
|
207 | + |
|
208 | + return $prepared; |
|
209 | + |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Retrieves the appropriate table key to use. |
|
214 | + * |
|
215 | + * |
|
216 | + * @param string $key |
|
217 | + * @param string $table |
|
218 | + * @return string|false |
|
219 | + */ |
|
220 | + public static function get_invoice_table_key( $key, $table ) { |
|
221 | + |
|
222 | + $keys = array( |
|
223 | + 'meta' => "meta_{$key}.meta_value", |
|
224 | + 'parent_meta' => "parent_meta_{$key}.meta_value", |
|
225 | + 'post_data' => "posts.{$key}", |
|
226 | + 'invoice_data' => "invoices.{$key}", |
|
227 | + 'invoice_item' => "invoice_items.{$key}", |
|
228 | + ); |
|
229 | + |
|
230 | + return isset( $keys[ $table ] ) ? $keys[ $table ] : false; |
|
231 | + |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Executes a query and caches the result for a minute. |
|
236 | + * |
|
237 | + * |
|
238 | + * @param string $query_type |
|
239 | + * @param string $query |
|
240 | + * @return mixed depending on query_type |
|
241 | + */ |
|
242 | + public static function execute( $query_type, $query ) { |
|
243 | + global $wpdb; |
|
244 | + |
|
245 | + $query_hash = md5( $query_type . $query ); |
|
246 | + $result = self::get_cached_query( $query_hash ); |
|
247 | + if ( $result === false ) { |
|
248 | + self::enable_big_selects(); |
|
249 | + |
|
250 | + $result = $wpdb->$query_type( $query ); |
|
251 | + self::set_cached_query( $query_hash, $result ); |
|
252 | + } |
|
253 | + |
|
254 | + return $result; |
|
255 | + |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Enables big mysql selects for reports, just once for this session. |
|
260 | + */ |
|
261 | + protected static function enable_big_selects() { |
|
262 | + static $big_selects = false; |
|
263 | + |
|
264 | + global $wpdb; |
|
265 | + |
|
266 | + if ( ! $big_selects ) { |
|
267 | + $wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' ); |
|
268 | + $big_selects = true; |
|
269 | + } |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Get the cached query result or null if it's not in the cache. |
|
274 | + * |
|
275 | + * @param string $query_hash The query hash. |
|
276 | + * |
|
277 | + * @return mixed|false The cache contents on success, false on failure to retrieve contents. |
|
278 | + */ |
|
279 | + protected static function get_cached_query( $query_hash ) { |
|
280 | + |
|
281 | + return wp_cache_get( |
|
282 | + $query_hash, |
|
283 | + strtolower( __CLASS__ ) |
|
284 | + ); |
|
285 | + |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Set the cached query result. |
|
290 | + * |
|
291 | + * @param string $query_hash The query hash. |
|
292 | + * @param mixed $data The data to cache. |
|
293 | + */ |
|
294 | + protected static function set_cached_query( $query_hash, $data ) { |
|
295 | + |
|
296 | + wp_cache_set( |
|
297 | + $query_hash, |
|
298 | + $data, |
|
299 | + strtolower( __CLASS__ ), |
|
300 | + MINUTE_IN_SECONDS |
|
301 | + ); |
|
302 | + |
|
303 | + } |
|
304 | 304 | |
305 | 305 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Reports_Helper Class. |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * @param array $args |
27 | 27 | * @return mixed depending on query_type |
28 | 28 | */ |
29 | - public static function get_invoice_report_data( $args = array() ) { |
|
29 | + public static function get_invoice_report_data($args = array()) { |
|
30 | 30 | global $wpdb; |
31 | 31 | |
32 | 32 | $default_args = array( |
@@ -37,94 +37,94 @@ discard block |
||
37 | 37 | 'order_by' => '', // What to order by. |
38 | 38 | 'limit' => '', // Results limit. |
39 | 39 | 'filter_range' => array(), // An array of before and after dates to limit results by. |
40 | - 'invoice_types' => array( 'wpi_invoice' ), // An array of post types to retrieve. |
|
41 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold' ), |
|
40 | + 'invoice_types' => array('wpi_invoice'), // An array of post types to retrieve. |
|
41 | + 'invoice_status' => array('publish', 'wpi-processing', 'wpi-onhold'), |
|
42 | 42 | 'parent_invoice_status' => false, // Optionally filter by parent invoice status. |
43 | 43 | ); |
44 | 44 | |
45 | - $args = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args ); |
|
46 | - $args = wp_parse_args( $args, $default_args ); |
|
45 | + $args = apply_filters('getpaid_reports_get_invoice_report_data_args', $args); |
|
46 | + $args = wp_parse_args($args, $default_args); |
|
47 | 47 | |
48 | - extract( $args ); |
|
48 | + extract($args); |
|
49 | 49 | |
50 | - if ( empty( $data ) ) { |
|
50 | + if (empty($data)) { |
|
51 | 51 | return ''; |
52 | 52 | } |
53 | 53 | |
54 | 54 | $query = array(); |
55 | - $query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) ); |
|
55 | + $query['select'] = 'SELECT ' . implode(',', self::prepare_invoice_data($data)); |
|
56 | 56 | $query['from'] = "FROM {$wpdb->posts} AS posts"; |
57 | - $query['join'] = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) ); |
|
57 | + $query['join'] = implode(' ', self::prepare_invoice_joins($data + $where, !empty($parent_invoice_status))); |
|
58 | 58 | |
59 | 59 | $query['where'] = " |
60 | - WHERE posts.post_type IN ( '" . implode( "','", $invoice_types ) . "' ) |
|
60 | + WHERE posts.post_type IN ( '" . implode("','", $invoice_types) . "' ) |
|
61 | 61 | "; |
62 | 62 | |
63 | - if ( ! empty( $invoice_status ) ) { |
|
63 | + if (!empty($invoice_status)) { |
|
64 | 64 | $query['where'] .= " |
65 | - AND posts.post_status IN ( '" . implode( "','", $invoice_status ) . "' ) |
|
65 | + AND posts.post_status IN ( '" . implode("','", $invoice_status) . "' ) |
|
66 | 66 | "; |
67 | 67 | } |
68 | 68 | |
69 | - if ( ! empty( $parent_invoice_status ) ) { |
|
70 | - if ( ! empty( $invoice_status ) ) { |
|
71 | - $query['where'] .= " AND ( parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) OR parent.ID IS NULL ) "; |
|
69 | + if (!empty($parent_invoice_status)) { |
|
70 | + if (!empty($invoice_status)) { |
|
71 | + $query['where'] .= " AND ( parent.post_status IN ( '" . implode("','", $parent_invoice_status) . "' ) OR parent.ID IS NULL ) "; |
|
72 | 72 | } else { |
73 | - $query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) "; |
|
73 | + $query['where'] .= " AND parent.post_status IN ( '" . implode("','", $parent_invoice_status) . "' ) "; |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
77 | - if ( ! empty( $filter_range['before'] ) ) { |
|
77 | + if (!empty($filter_range['before'])) { |
|
78 | 78 | $query['where'] .= " |
79 | - AND posts.post_date <= '" . gmdate( 'Y-m-d 23:59:59', strtotime( $filter_range['before'] ) ) . "' |
|
79 | + AND posts.post_date <= '" . gmdate('Y-m-d 23:59:59', strtotime($filter_range['before'])) . "' |
|
80 | 80 | "; |
81 | 81 | } |
82 | 82 | |
83 | - if ( ! empty( $filter_range['after'] ) ) { |
|
83 | + if (!empty($filter_range['after'])) { |
|
84 | 84 | $query['where'] .= " |
85 | - AND posts.post_date >= '" . gmdate( 'Y-m-d 00:00:00', strtotime( $filter_range['after'] ) ) . "' |
|
85 | + AND posts.post_date >= '" . gmdate('Y-m-d 00:00:00', strtotime($filter_range['after'])) . "' |
|
86 | 86 | "; |
87 | 87 | } |
88 | 88 | |
89 | - if ( ! empty( $where ) ) { |
|
89 | + if (!empty($where)) { |
|
90 | 90 | |
91 | - foreach ( $where as $value ) { |
|
91 | + foreach ($where as $value) { |
|
92 | 92 | |
93 | - if ( strtolower( $value['operator'] ) === 'in' || strtolower( $value['operator'] ) === 'not in' ) { |
|
93 | + if (strtolower($value['operator']) === 'in' || strtolower($value['operator']) === 'not in') { |
|
94 | 94 | |
95 | - if ( is_array( $value['value'] ) ) { |
|
96 | - $value['value'] = implode( "','", $value['value'] ); |
|
95 | + if (is_array($value['value'])) { |
|
96 | + $value['value'] = implode("','", $value['value']); |
|
97 | 97 | } |
98 | 98 | |
99 | - if ( ! empty( $value['value'] ) ) { |
|
99 | + if (!empty($value['value'])) { |
|
100 | 100 | $where_value = "{$value['operator']} ('{$value['value']}')"; |
101 | 101 | } |
102 | 102 | } else { |
103 | 103 | $where_value = "{$value['operator']} '{$value['value']}'"; |
104 | 104 | } |
105 | 105 | |
106 | - if ( ! empty( $where_value ) ) { |
|
106 | + if (!empty($where_value)) { |
|
107 | 107 | $query['where'] .= " AND {$value['key']} {$where_value}"; |
108 | 108 | } |
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
112 | - if ( $group_by ) { |
|
112 | + if ($group_by) { |
|
113 | 113 | $query['group_by'] = "GROUP BY {$group_by}"; |
114 | 114 | } |
115 | 115 | |
116 | - if ( $order_by ) { |
|
116 | + if ($order_by) { |
|
117 | 117 | $query['order_by'] = "ORDER BY {$order_by}"; |
118 | 118 | } |
119 | 119 | |
120 | - if ( $limit ) { |
|
120 | + if ($limit) { |
|
121 | 121 | $query['limit'] = "LIMIT {$limit}"; |
122 | 122 | } |
123 | 123 | |
124 | - $query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data ); |
|
125 | - $query = implode( ' ', $query ); |
|
124 | + $query = apply_filters('getpaid_reports_get_invoice_report_query', $query, $data); |
|
125 | + $query = implode(' ', $query); |
|
126 | 126 | |
127 | - return self::execute( $query_type, $query ); |
|
127 | + return self::execute($query_type, $query); |
|
128 | 128 | |
129 | 129 | } |
130 | 130 | |
@@ -135,26 +135,26 @@ discard block |
||
135 | 135 | * @param array $data |
136 | 136 | * @return array |
137 | 137 | */ |
138 | - public static function prepare_invoice_data( $data ) { |
|
138 | + public static function prepare_invoice_data($data) { |
|
139 | 139 | |
140 | 140 | $prepared = array(); |
141 | 141 | |
142 | - foreach ( $data as $raw_key => $value ) { |
|
143 | - $key = sanitize_key( $raw_key ); |
|
142 | + foreach ($data as $raw_key => $value) { |
|
143 | + $key = sanitize_key($raw_key); |
|
144 | 144 | $distinct = ''; |
145 | 145 | |
146 | - if ( isset( $value['distinct'] ) ) { |
|
146 | + if (isset($value['distinct'])) { |
|
147 | 147 | $distinct = 'DISTINCT'; |
148 | 148 | } |
149 | 149 | |
150 | - $get_key = self::get_invoice_table_key( $key, $value['type'] ); |
|
150 | + $get_key = self::get_invoice_table_key($key, $value['type']); |
|
151 | 151 | |
152 | - if ( false === $get_key ) { |
|
152 | + if (false === $get_key) { |
|
153 | 153 | // Skip to the next foreach iteration else the query will be invalid. |
154 | 154 | continue; |
155 | 155 | } |
156 | 156 | |
157 | - if ( ! empty( $value['function'] ) ) { |
|
157 | + if (!empty($value['function'])) { |
|
158 | 158 | $get = "{$value['function']}({$distinct} {$get_key})"; |
159 | 159 | } else { |
160 | 160 | $get = "{$distinct} {$get_key}"; |
@@ -175,22 +175,22 @@ discard block |
||
175 | 175 | * @param bool $with_parent |
176 | 176 | * @return array |
177 | 177 | */ |
178 | - public static function prepare_invoice_joins( $data, $with_parent ) { |
|
178 | + public static function prepare_invoice_joins($data, $with_parent) { |
|
179 | 179 | global $wpdb; |
180 | 180 | |
181 | 181 | $prepared = array(); |
182 | 182 | |
183 | - foreach ( $data as $raw_key => $value ) { |
|
184 | - $join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER'; |
|
185 | - $type = isset( $value['type'] ) ? $value['type'] : false; |
|
186 | - $key = sanitize_key( $raw_key ); |
|
183 | + foreach ($data as $raw_key => $value) { |
|
184 | + $join_type = isset($value['join_type']) ? $value['join_type'] : 'INNER'; |
|
185 | + $type = isset($value['type']) ? $value['type'] : false; |
|
186 | + $key = sanitize_key($raw_key); |
|
187 | 187 | |
188 | - switch ( $type ) { |
|
188 | + switch ($type) { |
|
189 | 189 | case 'meta': |
190 | - $prepared[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )"; |
|
190 | + $prepared["meta_{$key}"] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )"; |
|
191 | 191 | break; |
192 | 192 | case 'parent_meta': |
193 | - $prepared[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')"; |
|
193 | + $prepared["parent_meta_{$key}"] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')"; |
|
194 | 194 | break; |
195 | 195 | case 'invoice_data': |
196 | 196 | $prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id"; |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
204 | - if ( $with_parent ) { |
|
204 | + if ($with_parent) { |
|
205 | 205 | $prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID"; |
206 | 206 | } |
207 | 207 | |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * @param string $table |
218 | 218 | * @return string|false |
219 | 219 | */ |
220 | - public static function get_invoice_table_key( $key, $table ) { |
|
220 | + public static function get_invoice_table_key($key, $table) { |
|
221 | 221 | |
222 | 222 | $keys = array( |
223 | 223 | 'meta' => "meta_{$key}.meta_value", |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | 'invoice_item' => "invoice_items.{$key}", |
228 | 228 | ); |
229 | 229 | |
230 | - return isset( $keys[ $table ] ) ? $keys[ $table ] : false; |
|
230 | + return isset($keys[$table]) ? $keys[$table] : false; |
|
231 | 231 | |
232 | 232 | } |
233 | 233 | |
@@ -239,16 +239,16 @@ discard block |
||
239 | 239 | * @param string $query |
240 | 240 | * @return mixed depending on query_type |
241 | 241 | */ |
242 | - public static function execute( $query_type, $query ) { |
|
242 | + public static function execute($query_type, $query) { |
|
243 | 243 | global $wpdb; |
244 | 244 | |
245 | - $query_hash = md5( $query_type . $query ); |
|
246 | - $result = self::get_cached_query( $query_hash ); |
|
247 | - if ( $result === false ) { |
|
245 | + $query_hash = md5($query_type . $query); |
|
246 | + $result = self::get_cached_query($query_hash); |
|
247 | + if ($result === false) { |
|
248 | 248 | self::enable_big_selects(); |
249 | 249 | |
250 | - $result = $wpdb->$query_type( $query ); |
|
251 | - self::set_cached_query( $query_hash, $result ); |
|
250 | + $result = $wpdb->$query_type($query); |
|
251 | + self::set_cached_query($query_hash, $result); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | return $result; |
@@ -263,8 +263,8 @@ discard block |
||
263 | 263 | |
264 | 264 | global $wpdb; |
265 | 265 | |
266 | - if ( ! $big_selects ) { |
|
267 | - $wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' ); |
|
266 | + if (!$big_selects) { |
|
267 | + $wpdb->query('SET SESSION SQL_BIG_SELECTS=1'); |
|
268 | 268 | $big_selects = true; |
269 | 269 | } |
270 | 270 | } |
@@ -276,11 +276,11 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @return mixed|false The cache contents on success, false on failure to retrieve contents. |
278 | 278 | */ |
279 | - protected static function get_cached_query( $query_hash ) { |
|
279 | + protected static function get_cached_query($query_hash) { |
|
280 | 280 | |
281 | 281 | return wp_cache_get( |
282 | 282 | $query_hash, |
283 | - strtolower( __CLASS__ ) |
|
283 | + strtolower(__CLASS__) |
|
284 | 284 | ); |
285 | 285 | |
286 | 286 | } |
@@ -291,12 +291,12 @@ discard block |
||
291 | 291 | * @param string $query_hash The query hash. |
292 | 292 | * @param mixed $data The data to cache. |
293 | 293 | */ |
294 | - protected static function set_cached_query( $query_hash, $data ) { |
|
294 | + protected static function set_cached_query($query_hash, $data) { |
|
295 | 295 | |
296 | 296 | wp_cache_set( |
297 | 297 | $query_hash, |
298 | 298 | $data, |
299 | - strtolower( __CLASS__ ), |
|
299 | + strtolower(__CLASS__), |
|
300 | 300 | MINUTE_IN_SECONDS |
301 | 301 | ); |
302 | 302 |