@@ -7,49 +7,49 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 | |
14 | 14 | <div class='form-group'> |
15 | 15 | <label class="d-block"> |
16 | - <span><?php esc_html_e( 'Field Label', 'invoicing' ); ?></span> |
|
16 | + <span><?php esc_html_e('Field Label', 'invoicing'); ?></span> |
|
17 | 17 | <input v-model='active_form_element.label' class='form-control' type="text"/> |
18 | 18 | </label> |
19 | 19 | </div> |
20 | 20 | |
21 | 21 | <div class='form-group'> |
22 | 22 | <label class="d-block"> |
23 | - <span><?php esc_html_e( 'Placeholder text', 'invoicing' ); ?></span> |
|
23 | + <span><?php esc_html_e('Placeholder text', 'invoicing'); ?></span> |
|
24 | 24 | <input v-model='active_form_element.placeholder' class='form-control' type="text"/> |
25 | 25 | </label> |
26 | 26 | </div> |
27 | 27 | |
28 | 28 | <div class='form-group'> |
29 | 29 | <label class="d-block"> |
30 | - <span><?php esc_html_e( 'Help Text', 'invoicing' ); ?></span> |
|
31 | - <textarea placeholder='<?php esc_attr_e( 'Add some help text for this field', 'invoicing' ); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea> |
|
32 | - <small class="form-text text-muted"><?php _e( 'HTML is allowed', 'invoicing' ); ?></small> |
|
30 | + <span><?php esc_html_e('Help Text', 'invoicing'); ?></span> |
|
31 | + <textarea placeholder='<?php esc_attr_e('Add some help text for this field', 'invoicing'); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea> |
|
32 | + <small class="form-text text-muted"><?php _e('HTML is allowed', 'invoicing'); ?></small> |
|
33 | 33 | </label> |
34 | 34 | </div> |
35 | 35 | |
36 | 36 | <div class='form-group form-check'> |
37 | 37 | <input :id="active_form_element.id + '_edit'" v-model='active_form_element.required' type='checkbox' class='form-check-input' /> |
38 | - <label class='form-check-label' :for="active_form_element.id + '_edit'"><?php esc_html_e( 'Is this field required?', 'invoicing' ); ?></label> |
|
38 | + <label class='form-check-label' :for="active_form_element.id + '_edit'"><?php esc_html_e('Is this field required?', 'invoicing'); ?></label> |
|
39 | 39 | </div> |
40 | 40 | |
41 | 41 | <div class='form-group form-check'> |
42 | 42 | <input :id="active_form_element.id + '_add_meta'" v-model='active_form_element.add_meta' type='checkbox' class='form-check-input' /> |
43 | - <label class='form-check-label' :for="active_form_element.id + '_add_meta'"><?php esc_html_e( 'Show this field in receipts and emails?', 'invoicing' ); ?></label> |
|
43 | + <label class='form-check-label' :for="active_form_element.id + '_add_meta'"><?php esc_html_e('Show this field in receipts and emails?', 'invoicing'); ?></label> |
|
44 | 44 | </div> |
45 | 45 | |
46 | 46 | <hr class='featurette-divider mt-4'> |
47 | 47 | |
48 | 48 | <div class='form-group'> |
49 | 49 | <label class="d-block"> |
50 | - <span><?php esc_html_e( 'Email Merge Tag', 'invoicing' ); ?></span> |
|
50 | + <span><?php esc_html_e('Email Merge Tag', 'invoicing'); ?></span> |
|
51 | 51 | <input :value='active_form_element.label | formatMergeTag' class='form-control bg-white' type="text" readonly onclick="this.select()" /> |
52 | - <span class="form-text text-muted"><?php esc_html_e( 'You can use this merge tag in notification emails', 'invoicing' ); ?></span> |
|
52 | + <span class="form-text text-muted"><?php esc_html_e('You can use this merge tag in notification emails', 'invoicing'); ?></span> |
|
53 | 53 | </label> |
54 | 54 | </div> |
55 | 55 |
@@ -7,49 +7,49 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 | |
14 | 14 | <div class='form-group'> |
15 | 15 | <label class="d-block"> |
16 | - <span><?php esc_html_e( 'Field Label', 'invoicing' ); ?></span> |
|
16 | + <span><?php esc_html_e('Field Label', 'invoicing'); ?></span> |
|
17 | 17 | <input v-model='active_form_element.label' class='form-control' type="text"/> |
18 | 18 | </label> |
19 | 19 | </div> |
20 | 20 | |
21 | 21 | <div class='form-group'> |
22 | 22 | <label class="d-block"> |
23 | - <span><?php esc_html_e( 'Placeholder text', 'invoicing' ); ?></span> |
|
23 | + <span><?php esc_html_e('Placeholder text', 'invoicing'); ?></span> |
|
24 | 24 | <input v-model='active_form_element.placeholder' class='form-control' type="text"/> |
25 | 25 | </label> |
26 | 26 | </div> |
27 | 27 | |
28 | 28 | <div class='form-group'> |
29 | 29 | <label class="d-block"> |
30 | - <span><?php esc_html_e( 'Help Text', 'invoicing' ); ?></span> |
|
31 | - <textarea placeholder='<?php esc_attr_e( 'Add some help text for this field', 'invoicing' ); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea> |
|
32 | - <small class="form-text text-muted"><?php _e( 'HTML is allowed', 'invoicing' ); ?></small> |
|
30 | + <span><?php esc_html_e('Help Text', 'invoicing'); ?></span> |
|
31 | + <textarea placeholder='<?php esc_attr_e('Add some help text for this field', 'invoicing'); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea> |
|
32 | + <small class="form-text text-muted"><?php _e('HTML is allowed', 'invoicing'); ?></small> |
|
33 | 33 | </label> |
34 | 34 | </div> |
35 | 35 | |
36 | 36 | <div class='form-group form-check'> |
37 | 37 | <input :id="active_form_element.id + '_edit'" v-model='active_form_element.required' type='checkbox' class='form-check-input' /> |
38 | - <label class='form-check-label' :for="active_form_element.id + '_edit'"><?php esc_html_e( 'Is this field required?', 'invoicing' ); ?></label> |
|
38 | + <label class='form-check-label' :for="active_form_element.id + '_edit'"><?php esc_html_e('Is this field required?', 'invoicing'); ?></label> |
|
39 | 39 | </div> |
40 | 40 | |
41 | 41 | <div class='form-group form-check'> |
42 | 42 | <input :id="active_form_element.id + '_add_meta'" v-model='active_form_element.add_meta' type='checkbox' class='form-check-input' /> |
43 | - <label class='form-check-label' :for="active_form_element.id + '_add_meta'"><?php esc_html_e( 'Show this field in receipts and emails?', 'invoicing' ); ?></label> |
|
43 | + <label class='form-check-label' :for="active_form_element.id + '_add_meta'"><?php esc_html_e('Show this field in receipts and emails?', 'invoicing'); ?></label> |
|
44 | 44 | </div> |
45 | 45 | |
46 | 46 | <hr class='featurette-divider mt-4'> |
47 | 47 | |
48 | 48 | <div class='form-group'> |
49 | 49 | <label class="d-block"> |
50 | - <span><?php esc_html_e( 'Email Merge Tag', 'invoicing' ); ?></span> |
|
50 | + <span><?php esc_html_e('Email Merge Tag', 'invoicing'); ?></span> |
|
51 | 51 | <input :value='active_form_element.label | formatMergeTag' class='form-control bg-white' type="text" readonly onclick="this.select()" /> |
52 | - <span class="form-text text-muted"><?php esc_html_e( 'You can use this merge tag in notification emails', 'invoicing' ); ?></span> |
|
52 | + <span class="form-text text-muted"><?php esc_html_e('You can use this merge tag in notification emails', 'invoicing'); ?></span> |
|
53 | 53 | </label> |
54 | 54 | </div> |
55 | 55 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * This class handles invoice notificaiton emails. |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | $this->invoice_actions = apply_filters( |
29 | 29 | 'getpaid_notification_email_invoice_triggers', |
30 | 30 | array( |
31 | - 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
31 | + 'getpaid_new_invoice' => array('new_invoice', 'user_invoice'), |
|
32 | 32 | 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
33 | 33 | 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
34 | 34 | 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function init_hooks() { |
52 | 52 | |
53 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
54 | - add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
53 | + add_filter('getpaid_get_email_merge_tags', array($this, 'invoice_merge_tags'), 10, 2); |
|
54 | + add_filter('getpaid_invoice_email_recipients', array($this, 'filter_email_recipients'), 10, 2); |
|
55 | 55 | |
56 | - foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | - $this->init_email_type_hook( $hook, $email_type ); |
|
56 | + foreach ($this->invoice_actions as $hook => $email_type) { |
|
57 | + $this->init_email_type_hook($hook, $email_type); |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
@@ -64,25 +64,25 @@ discard block |
||
64 | 64 | * @param string $hook |
65 | 65 | * @param string|array $email_type |
66 | 66 | */ |
67 | - public function init_email_type_hook( $hook, $email_type ) { |
|
67 | + public function init_email_type_hook($hook, $email_type) { |
|
68 | 68 | |
69 | - $email_type = wpinv_parse_list( $email_type ); |
|
69 | + $email_type = wpinv_parse_list($email_type); |
|
70 | 70 | |
71 | - foreach ( $email_type as $type ) { |
|
71 | + foreach ($email_type as $type) { |
|
72 | 72 | |
73 | - $email = new GetPaid_Notification_Email( $type ); |
|
73 | + $email = new GetPaid_Notification_Email($type); |
|
74 | 74 | |
75 | 75 | // Abort if it is not active. |
76 | - if ( ! $email->is_active() ) { |
|
76 | + if (!$email->is_active()) { |
|
77 | 77 | continue; |
78 | 78 | } |
79 | 79 | |
80 | - if ( method_exists( $this, $type ) ) { |
|
81 | - add_action( $hook, array( $this, $type ), 100, 2 ); |
|
80 | + if (method_exists($this, $type)) { |
|
81 | + add_action($hook, array($this, $type), 100, 2); |
|
82 | 82 | continue; |
83 | 83 | } |
84 | 84 | |
85 | - do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
85 | + do_action('getpaid_invoice_init_email_type_hook', $type, $hook); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | } |
@@ -93,19 +93,19 @@ discard block |
||
93 | 93 | * @param array $merge_tags |
94 | 94 | * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
95 | 95 | */ |
96 | - public function invoice_merge_tags( $merge_tags, $object ) { |
|
96 | + public function invoice_merge_tags($merge_tags, $object) { |
|
97 | 97 | |
98 | - if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
98 | + if (is_a($object, 'WPInv_Invoice')) { |
|
99 | 99 | return array_merge( |
100 | 100 | $merge_tags, |
101 | - $this->get_invoice_merge_tags( $object ) |
|
101 | + $this->get_invoice_merge_tags($object) |
|
102 | 102 | ); |
103 | 103 | } |
104 | 104 | |
105 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
105 | + if (is_a($object, 'WPInv_Subscription')) { |
|
106 | 106 | return array_merge( |
107 | 107 | $merge_tags, |
108 | - $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
108 | + $this->get_invoice_merge_tags($object->get_parent_payment()) |
|
109 | 109 | ); |
110 | 110 | } |
111 | 111 | |
@@ -119,52 +119,52 @@ discard block |
||
119 | 119 | * @param WPInv_Invoice $invoice |
120 | 120 | * @return array |
121 | 121 | */ |
122 | - public function get_invoice_merge_tags( $invoice ) { |
|
122 | + public function get_invoice_merge_tags($invoice) { |
|
123 | 123 | |
124 | 124 | // Abort if it does not exist. |
125 | - if ( ! $invoice->get_id() ) { |
|
125 | + if (!$invoice->get_id()) { |
|
126 | 126 | return array(); |
127 | 127 | } |
128 | 128 | |
129 | 129 | $merge_tags = array( |
130 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
131 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
133 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
134 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
135 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
136 | - '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
137 | - '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
138 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
139 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
140 | - '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ), |
|
141 | - '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
142 | - '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
143 | - '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
144 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
145 | - '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
146 | - '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
147 | - '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
130 | + '{name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
131 | + '{full_name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
132 | + '{first_name}' => sanitize_text_field($invoice->get_first_name()), |
|
133 | + '{last_name}' => sanitize_text_field($invoice->get_last_name()), |
|
134 | + '{email}' => sanitize_email($invoice->get_email()), |
|
135 | + '{invoice_number}' => sanitize_text_field($invoice->get_number()), |
|
136 | + '{invoice_currency}' => sanitize_text_field($invoice->get_currency()), |
|
137 | + '{invoice_total}' => sanitize_text_field(wpinv_price($invoice->get_total(), $invoice->get_currency())), |
|
138 | + '{invoice_link}' => esc_url($invoice->get_view_url()), |
|
139 | + '{invoice_pay_link}' => esc_url($invoice->get_checkout_payment_url()), |
|
140 | + '{invoice_receipt_link}'=> esc_url($invoice->get_receipt_url()), |
|
141 | + '{invoice_date}' => getpaid_format_date_value($invoice->get_date_created()), |
|
142 | + '{invoice_due_date}' => getpaid_format_date_value($invoice->get_due_date(), __('on receipt', 'invoicing')), |
|
143 | + '{invoice_quote}' => sanitize_text_field(strtolower($invoice->get_label())), |
|
144 | + '{invoice_label}' => sanitize_text_field(ucfirst($invoice->get_label())), |
|
145 | + '{invoice_description}' => wp_kses_post($invoice->get_description()), |
|
146 | + '{subscription_name}' => wp_kses_post($invoice->get_subscription_name()), |
|
147 | + '{is_was}' => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'), |
|
148 | 148 | ); |
149 | 149 | |
150 | - $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
150 | + $payment_form_data = $invoice->get_meta('payment_form_data', true); |
|
151 | 151 | |
152 | - if ( is_array( $payment_form_data ) ) { |
|
152 | + if (is_array($payment_form_data)) { |
|
153 | 153 | |
154 | - foreach ( $payment_form_data as $label => $value ) { |
|
154 | + foreach ($payment_form_data as $label => $value) { |
|
155 | 155 | |
156 | - $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
157 | - $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
156 | + $label = preg_replace('/[^a-z0-9]+/', '_', strtolower($label)); |
|
157 | + $value = is_array($value) ? implode(', ', $value) : $value; |
|
158 | 158 | |
159 | - if ( is_scalar ( $value ) ) { |
|
160 | - $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
159 | + if (is_scalar($value)) { |
|
160 | + $merge_tags["{{$label}}"] = wp_kses_post($value); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | } |
164 | 164 | |
165 | 165 | } |
166 | 166 | |
167 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
167 | + return apply_filters('getpaid_invoice_email_merge_tags', $merge_tags, $invoice); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -176,12 +176,12 @@ discard block |
||
176 | 176 | * @param string|array $recipients |
177 | 177 | * @param array $extra_args Extra template args. |
178 | 178 | */ |
179 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
179 | + public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) { |
|
180 | 180 | |
181 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
181 | + do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email); |
|
182 | 182 | |
183 | - $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
184 | - if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
183 | + $skip = $invoice->is_free() && wpinv_get_option('skip_email_free_invoice'); |
|
184 | + if (apply_filters('getpaid_skip_invoice_email', $skip, $type, $invoice)) { |
|
185 | 185 | return; |
186 | 186 | } |
187 | 187 | |
@@ -189,41 +189,41 @@ discard block |
||
189 | 189 | $merge_tags = $email->get_merge_tags(); |
190 | 190 | |
191 | 191 | $result = $mailer->send( |
192 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
193 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
194 | - $email->get_content( $merge_tags, $extra_args ), |
|
192 | + apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email), |
|
193 | + $email->add_merge_tags($email->get_subject(), $merge_tags), |
|
194 | + $email->get_content($merge_tags, $extra_args), |
|
195 | 195 | $email->get_attachments() |
196 | 196 | ); |
197 | 197 | |
198 | 198 | // Maybe send a copy to the admin. |
199 | - if ( $email->include_admin_bcc() ) { |
|
199 | + if ($email->include_admin_bcc()) { |
|
200 | 200 | $mailer->send( |
201 | 201 | wpinv_get_admin_email(), |
202 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
203 | - $email->get_content( $merge_tags ), |
|
202 | + $email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags), |
|
203 | + $email->get_content($merge_tags), |
|
204 | 204 | $email->get_attachments() |
205 | 205 | ); |
206 | 206 | } |
207 | 207 | |
208 | - if ( $result ) { |
|
208 | + if ($result) { |
|
209 | 209 | $invoice->add_system_note( |
210 | 210 | sprintf( |
211 | - __( 'Successfully sent %s notification email to %s.', 'invoicing' ), |
|
212 | - sanitize_key( $type ), |
|
213 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
211 | + __('Successfully sent %s notification email to %s.', 'invoicing'), |
|
212 | + sanitize_key($type), |
|
213 | + $email->is_admin_email() ? __('admin') : __('the customer') |
|
214 | 214 | ) |
215 | 215 | ); |
216 | 216 | } else { |
217 | 217 | $invoice->add_system_note( |
218 | 218 | sprintf( |
219 | - __( 'Failed sending %s notification email to %s.', 'invoicing' ), |
|
220 | - sanitize_key( $type ), |
|
221 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
219 | + __('Failed sending %s notification email to %s.', 'invoicing'), |
|
220 | + sanitize_key($type), |
|
221 | + $email->is_admin_email() ? __('admin') : __('the customer') |
|
222 | 222 | ) |
223 | 223 | ); |
224 | 224 | } |
225 | 225 | |
226 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
226 | + do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email); |
|
227 | 227 | |
228 | 228 | return $result; |
229 | 229 | } |
@@ -234,20 +234,20 @@ discard block |
||
234 | 234 | * @param array $recipients |
235 | 235 | * @param GetPaid_Notification_Email $email |
236 | 236 | */ |
237 | - public function filter_email_recipients( $recipients, $email ) { |
|
237 | + public function filter_email_recipients($recipients, $email) { |
|
238 | 238 | |
239 | - if ( ! $email->is_admin_email() ) { |
|
239 | + if (!$email->is_admin_email()) { |
|
240 | 240 | $cc = $email->object->get_email_cc(); |
241 | - $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
241 | + $cc_2 = get_user_meta($email->object->get_user_id(), '_wpinv_email_cc', true); |
|
242 | 242 | |
243 | - if ( ! empty( $cc ) ) { |
|
244 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
245 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
243 | + if (!empty($cc)) { |
|
244 | + $cc = array_map('sanitize_email', wpinv_parse_list($cc)); |
|
245 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc))); |
|
246 | 246 | } |
247 | 247 | |
248 | - if ( ! empty( $cc_2 ) ) { |
|
249 | - $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
250 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
248 | + if (!empty($cc_2)) { |
|
249 | + $cc_2 = array_map('sanitize_email', wpinv_parse_list($cc_2)); |
|
250 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc_2))); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | } |
@@ -261,17 +261,17 @@ discard block |
||
261 | 261 | * |
262 | 262 | * @param WPInv_Invoice $invoice |
263 | 263 | */ |
264 | - public function new_invoice( $invoice ) { |
|
264 | + public function new_invoice($invoice) { |
|
265 | 265 | |
266 | 266 | // Only send this email for invoices created via the admin page. |
267 | - if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
267 | + if (!$invoice->is_type('invoice') || $this->is_payment_form_invoice($invoice->get_id())) { |
|
268 | 268 | return; |
269 | 269 | } |
270 | 270 | |
271 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
271 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
272 | 272 | $recipient = wpinv_get_admin_email(); |
273 | 273 | |
274 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
274 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
275 | 275 | |
276 | 276 | } |
277 | 277 | |
@@ -280,12 +280,12 @@ discard block |
||
280 | 280 | * |
281 | 281 | * @param WPInv_Invoice $invoice |
282 | 282 | */ |
283 | - public function cancelled_invoice( $invoice ) { |
|
283 | + public function cancelled_invoice($invoice) { |
|
284 | 284 | |
285 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
285 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
286 | 286 | $recipient = wpinv_get_admin_email(); |
287 | 287 | |
288 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
288 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
289 | 289 | |
290 | 290 | } |
291 | 291 | |
@@ -294,12 +294,12 @@ discard block |
||
294 | 294 | * |
295 | 295 | * @param WPInv_Invoice $invoice |
296 | 296 | */ |
297 | - public function failed_invoice( $invoice ) { |
|
297 | + public function failed_invoice($invoice) { |
|
298 | 298 | |
299 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
299 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
300 | 300 | $recipient = wpinv_get_admin_email(); |
301 | 301 | |
302 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
302 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
303 | 303 | |
304 | 304 | } |
305 | 305 | |
@@ -308,12 +308,12 @@ discard block |
||
308 | 308 | * |
309 | 309 | * @param WPInv_Invoice $invoice |
310 | 310 | */ |
311 | - public function onhold_invoice( $invoice ) { |
|
311 | + public function onhold_invoice($invoice) { |
|
312 | 312 | |
313 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
313 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
314 | 314 | $recipient = $invoice->get_email(); |
315 | 315 | |
316 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
316 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
317 | 317 | |
318 | 318 | } |
319 | 319 | |
@@ -322,12 +322,12 @@ discard block |
||
322 | 322 | * |
323 | 323 | * @param WPInv_Invoice $invoice |
324 | 324 | */ |
325 | - public function processing_invoice( $invoice ) { |
|
325 | + public function processing_invoice($invoice) { |
|
326 | 326 | |
327 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
327 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
328 | 328 | $recipient = $invoice->get_email(); |
329 | 329 | |
330 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
330 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
331 | 331 | |
332 | 332 | } |
333 | 333 | |
@@ -336,17 +336,17 @@ discard block |
||
336 | 336 | * |
337 | 337 | * @param WPInv_Invoice $invoice |
338 | 338 | */ |
339 | - public function completed_invoice( $invoice ) { |
|
339 | + public function completed_invoice($invoice) { |
|
340 | 340 | |
341 | 341 | // (Maybe) abort if it is a renewal invoice. |
342 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
342 | + if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) { |
|
343 | 343 | return; |
344 | 344 | } |
345 | 345 | |
346 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
346 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
347 | 347 | $recipient = $invoice->get_email(); |
348 | 348 | |
349 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
349 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
350 | 350 | |
351 | 351 | } |
352 | 352 | |
@@ -355,12 +355,12 @@ discard block |
||
355 | 355 | * |
356 | 356 | * @param WPInv_Invoice $invoice |
357 | 357 | */ |
358 | - public function refunded_invoice( $invoice ) { |
|
358 | + public function refunded_invoice($invoice) { |
|
359 | 359 | |
360 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
360 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
361 | 361 | $recipient = $invoice->get_email(); |
362 | 362 | |
363 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
363 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
364 | 364 | |
365 | 365 | } |
366 | 366 | |
@@ -370,21 +370,21 @@ discard block |
||
370 | 370 | * @param WPInv_Invoice $invoice |
371 | 371 | * @param bool $force |
372 | 372 | */ |
373 | - public function user_invoice( $invoice, $force = false ) { |
|
373 | + public function user_invoice($invoice, $force = false) { |
|
374 | 374 | |
375 | - if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
375 | + if (!empty($GLOBALS['wpinv_skip_invoice_notification'])) { |
|
376 | 376 | return; |
377 | 377 | } |
378 | 378 | |
379 | 379 | // Only send this email for invoices created via the admin page. |
380 | - if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
380 | + if (!$invoice->is_type('invoice') || (empty($force) && $this->is_payment_form_invoice($invoice->get_id()))) { |
|
381 | 381 | return; |
382 | 382 | } |
383 | 383 | |
384 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
384 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
385 | 385 | $recipient = $invoice->get_email(); |
386 | 386 | |
387 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
387 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
388 | 388 | |
389 | 389 | } |
390 | 390 | |
@@ -394,9 +394,9 @@ discard block |
||
394 | 394 | * @param int $invoice |
395 | 395 | * @return bool |
396 | 396 | */ |
397 | - public function is_payment_form_invoice( $invoice ) { |
|
398 | - $is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) ); |
|
399 | - return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
397 | + public function is_payment_form_invoice($invoice) { |
|
398 | + $is_payment_form_invoice = empty($_GET['getpaid-admin-action']) && ('payment_form' == get_post_meta($invoice, 'wpinv_created_via', true) || 'geodirectory' == get_post_meta($invoice, 'wpinv_created_via', true)); |
|
399 | + return apply_filters('getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice); |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | /** |
@@ -405,12 +405,12 @@ discard block |
||
405 | 405 | * @param WPInv_Invoice $invoice |
406 | 406 | * @param string $note |
407 | 407 | */ |
408 | - public function user_note( $invoice, $note ) { |
|
408 | + public function user_note($invoice, $note) { |
|
409 | 409 | |
410 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
410 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
411 | 411 | $recipient = $invoice->get_email(); |
412 | 412 | |
413 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
413 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note)); |
|
414 | 414 | |
415 | 415 | } |
416 | 416 | |
@@ -419,9 +419,9 @@ discard block |
||
419 | 419 | * |
420 | 420 | * @param WPInv_Invoice $invoice |
421 | 421 | */ |
422 | - public function force_send_overdue_notice( $invoice ) { |
|
423 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
424 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
422 | + public function force_send_overdue_notice($invoice) { |
|
423 | + $email = new GetPaid_Notification_Email('overdue', $invoice); |
|
424 | + return $this->send_email($invoice, $email, 'overdue', $invoice->get_email()); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
@@ -432,37 +432,37 @@ discard block |
||
432 | 432 | public function overdue() { |
433 | 433 | global $wpdb; |
434 | 434 | |
435 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
435 | + $email = new GetPaid_Notification_Email(__FUNCTION__); |
|
436 | 436 | |
437 | 437 | // Fetch reminder days. |
438 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
438 | + $reminder_days = array_unique(wp_parse_id_list($email->get_option('days'))); |
|
439 | 439 | |
440 | 440 | // Abort if non is set. |
441 | - if ( empty( $reminder_days ) ) { |
|
441 | + if (empty($reminder_days)) { |
|
442 | 442 | return; |
443 | 443 | } |
444 | 444 | |
445 | 445 | // Retrieve date query. |
446 | - $date_query = $this->get_date_query( $reminder_days ); |
|
446 | + $date_query = $this->get_date_query($reminder_days); |
|
447 | 447 | |
448 | 448 | // Invoices table. |
449 | 449 | $table = $wpdb->prefix . 'getpaid_invoices'; |
450 | 450 | |
451 | 451 | // Fetch invoices. |
452 | - $invoices = $wpdb->get_col( |
|
452 | + $invoices = $wpdb->get_col( |
|
453 | 453 | "SELECT posts.ID FROM $wpdb->posts as posts |
454 | 454 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
455 | 455 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query"); |
456 | 456 | |
457 | - foreach ( $invoices as $invoice ) { |
|
457 | + foreach ($invoices as $invoice) { |
|
458 | 458 | |
459 | 459 | // Only send this email for invoices created via the admin page. |
460 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
461 | - $invoice = new WPInv_Invoice( $invoice ); |
|
460 | + if (!$this->is_payment_form_invoice($invoice)) { |
|
461 | + $invoice = new WPInv_Invoice($invoice); |
|
462 | 462 | $email->object = $invoice; |
463 | 463 | |
464 | - if ( $invoice->needs_payment() ) { |
|
465 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
464 | + if ($invoice->needs_payment()) { |
|
465 | + $this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email()); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | } |
@@ -477,14 +477,14 @@ discard block |
||
477 | 477 | * @param array $reminder_days |
478 | 478 | * @return string |
479 | 479 | */ |
480 | - public function get_date_query( $reminder_days ) { |
|
480 | + public function get_date_query($reminder_days) { |
|
481 | 481 | |
482 | 482 | $date_query = array( |
483 | 483 | 'relation' => 'OR' |
484 | 484 | ); |
485 | 485 | |
486 | - foreach ( $reminder_days as $days ) { |
|
487 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
486 | + foreach ($reminder_days as $days) { |
|
487 | + $date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp')))); |
|
488 | 488 | |
489 | 489 | $date_query[] = array( |
490 | 490 | 'year' => $date['year'], |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | |
495 | 495 | } |
496 | 496 | |
497 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
497 | + $date_query = new WP_Date_Query($date_query, 'invoices.due_date'); |
|
498 | 498 | |
499 | 499 | return $date_query->get_sql(); |
500 | 500 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package GetPaid |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Generates a users select dropdown. |
@@ -16,13 +16,13 @@ discard block |
||
16 | 16 | * @param array $args |
17 | 17 | * @see wp_dropdown_users |
18 | 18 | */ |
19 | -function wpinv_dropdown_users( $args = '' ) { |
|
19 | +function wpinv_dropdown_users($args = '') { |
|
20 | 20 | |
21 | - if ( is_array( $args ) && ! empty( $args['show'] ) && 'display_name_with_email' == $args['show'] ) { |
|
21 | + if (is_array($args) && !empty($args['show']) && 'display_name_with_email' == $args['show']) { |
|
22 | 22 | $args['show'] = 'display_name_with_login'; |
23 | 23 | } |
24 | 24 | |
25 | - return wp_dropdown_users( $args ); |
|
25 | + return wp_dropdown_users($args); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -32,9 +32,9 @@ discard block |
||
32 | 32 | * @return string capability to check against |
33 | 33 | * @param string $capalibilty Optional. The alternative capability to check against. |
34 | 34 | */ |
35 | -function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) { |
|
35 | +function wpinv_get_capability($capalibilty = 'manage_invoicing') { |
|
36 | 36 | |
37 | - if ( current_user_can( 'manage_options' ) ) { |
|
37 | + if (current_user_can('manage_options')) { |
|
38 | 38 | return 'manage_options'; |
39 | 39 | }; |
40 | 40 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @return bool |
49 | 49 | */ |
50 | 50 | function wpinv_current_user_can_manage_invoicing() { |
51 | - return current_user_can( wpinv_get_capability() ); |
|
51 | + return current_user_can(wpinv_get_capability()); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -57,19 +57,19 @@ discard block |
||
57 | 57 | * @since 1.0.19 |
58 | 58 | * @return int|WP_Error |
59 | 59 | */ |
60 | -function wpinv_create_user( $email, $prefix = '' ) { |
|
60 | +function wpinv_create_user($email, $prefix = '') { |
|
61 | 61 | |
62 | 62 | // Prepare user values. |
63 | - $prefix = preg_replace( '/\s+/', '', $prefix ); |
|
64 | - $prefix = empty( $prefix ) ? $email : $prefix; |
|
65 | - $args = array( |
|
66 | - 'user_login' => wpinv_generate_user_name( $prefix ), |
|
63 | + $prefix = preg_replace('/\s+/', '', $prefix); |
|
64 | + $prefix = empty($prefix) ? $email : $prefix; |
|
65 | + $args = array( |
|
66 | + 'user_login' => wpinv_generate_user_name($prefix), |
|
67 | 67 | 'user_pass' => wp_generate_password(), |
68 | 68 | 'user_email' => $email, |
69 | 69 | 'role' => 'subscriber', |
70 | 70 | ); |
71 | 71 | |
72 | - return wp_insert_user( $args ); |
|
72 | + return wp_insert_user($args); |
|
73 | 73 | |
74 | 74 | } |
75 | 75 | |
@@ -79,26 +79,26 @@ discard block |
||
79 | 79 | * @since 1.0.19 |
80 | 80 | * @return bool|WP_User |
81 | 81 | */ |
82 | -function wpinv_generate_user_name( $prefix = '' ) { |
|
82 | +function wpinv_generate_user_name($prefix = '') { |
|
83 | 83 | |
84 | 84 | // If prefix is an email, retrieve the part before the email. |
85 | - $prefix = strtok( $prefix, '@' ); |
|
86 | - $prefix = trim( $prefix, '.' ); |
|
85 | + $prefix = strtok($prefix, '@'); |
|
86 | + $prefix = trim($prefix, '.'); |
|
87 | 87 | |
88 | 88 | // Sanitize the username. |
89 | - $prefix = sanitize_user( $prefix, true ); |
|
89 | + $prefix = sanitize_user($prefix, true); |
|
90 | 90 | |
91 | - $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
92 | - if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
93 | - $prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
91 | + $illegal_logins = (array) apply_filters('illegal_user_logins', array()); |
|
92 | + if (empty($prefix) || in_array(strtolower($prefix), array_map('strtolower', $illegal_logins), true)) { |
|
93 | + $prefix = 'gtp_' . zeroise(wp_rand(0, 9999), 4); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | $username = $prefix; |
97 | 97 | $postfix = 2; |
98 | 98 | |
99 | - while ( username_exists( $username ) ) { |
|
99 | + while (username_exists($username)) { |
|
100 | 100 | $username = $prefix + $postfix; |
101 | - $postfix ++; |
|
101 | + $postfix++; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | return $username; |
@@ -115,31 +115,31 @@ discard block |
||
115 | 115 | $tabs = array( |
116 | 116 | |
117 | 117 | 'gp-invoices' => array( |
118 | - 'label' => __( 'Invoices', 'invoicing' ), // Name of the tab. |
|
118 | + 'label' => __('Invoices', 'invoicing'), // Name of the tab. |
|
119 | 119 | 'content' => '[wpinv_history]', // Content of the tab. Or specify "callback" to provide a callback instead. |
120 | 120 | 'icon' => 'fas fa-file-invoice', // Shown on some profile plugins. |
121 | 121 | ), |
122 | 122 | |
123 | 123 | 'gp-subscriptions' => array( |
124 | - 'label' => __( 'Subscriptions', 'invoicing' ), |
|
124 | + 'label' => __('Subscriptions', 'invoicing'), |
|
125 | 125 | 'content' => '[wpinv_subscriptions]', |
126 | 126 | 'icon' => 'fas fa-redo', |
127 | 127 | ), |
128 | 128 | |
129 | 129 | 'gp-edit-address' => array( |
130 | - 'label' => __( 'Billing Address', 'invoicing' ), |
|
130 | + 'label' => __('Billing Address', 'invoicing'), |
|
131 | 131 | 'callback' => 'getpaid_display_address_edit_tab', |
132 | 132 | 'icon' => 'fas fa-credit-card', |
133 | 133 | ), |
134 | 134 | |
135 | 135 | ); |
136 | 136 | |
137 | - $tabs = apply_filters( 'getpaid_user_content_tabs', $tabs ); |
|
137 | + $tabs = apply_filters('getpaid_user_content_tabs', $tabs); |
|
138 | 138 | |
139 | 139 | // Make sure address editing is last on the list. |
140 | - if ( isset( $tabs['gp-edit-address'] ) ) { |
|
140 | + if (isset($tabs['gp-edit-address'])) { |
|
141 | 141 | $address = $tabs['gp-edit-address']; |
142 | - unset( $tabs['gp-edit-address'] ); |
|
142 | + unset($tabs['gp-edit-address']); |
|
143 | 143 | $tabs['gp-edit-address'] = $address; |
144 | 144 | } |
145 | 145 | |
@@ -153,19 +153,19 @@ discard block |
||
153 | 153 | * @param array $tab |
154 | 154 | * @return array |
155 | 155 | */ |
156 | -function getpaid_prepare_user_content_tab( $tab ) { |
|
156 | +function getpaid_prepare_user_content_tab($tab) { |
|
157 | 157 | |
158 | - if ( ! empty( $tab['callback'] ) ) { |
|
159 | - return call_user_func( $tab['callback'] ); |
|
158 | + if (!empty($tab['callback'])) { |
|
159 | + return call_user_func($tab['callback']); |
|
160 | 160 | } |
161 | 161 | |
162 | - if ( ! empty( $tab['content'] ) ) { |
|
163 | - return convert_smilies( capital_P_dangit( wp_filter_content_tags( do_shortcode( shortcode_unautop( wpautop( wptexturize( do_blocks( $tab['content'] ) ) ) ) ) ) ) ); |
|
162 | + if (!empty($tab['content'])) { |
|
163 | + return convert_smilies(capital_P_dangit(wp_filter_content_tags(do_shortcode(shortcode_unautop(wpautop(wptexturize(do_blocks($tab['content'])))))))); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | $notice = aui()->alert( |
167 | 167 | array( |
168 | - 'content' => __( 'This tab has no content or content callback.', 'invoicing' ), |
|
168 | + 'content' => __('This tab has no content or content callback.', 'invoicing'), |
|
169 | 169 | 'type' => 'error', |
170 | 170 | ) |
171 | 171 | ); |
@@ -181,14 +181,14 @@ discard block |
||
181 | 181 | * @param string $default |
182 | 182 | * @return array |
183 | 183 | */ |
184 | -function getpaid_get_tab_url( $tab, $default ) { |
|
184 | +function getpaid_get_tab_url($tab, $default) { |
|
185 | 185 | global $getpaid_tab_url; |
186 | 186 | |
187 | - if ( empty( $getpaid_tab_url ) ) { |
|
187 | + if (empty($getpaid_tab_url)) { |
|
188 | 188 | return $default; |
189 | 189 | } |
190 | 190 | |
191 | - return sprintf( $getpaid_tab_url, $tab ); |
|
191 | + return sprintf($getpaid_tab_url, $tab); |
|
192 | 192 | |
193 | 193 | } |
194 | 194 | |
@@ -208,19 +208,19 @@ discard block |
||
208 | 208 | |
209 | 209 | <?php |
210 | 210 | |
211 | - foreach ( getpaid_user_address_fields() as $key => $label ) { |
|
211 | + foreach (getpaid_user_address_fields() as $key => $label) { |
|
212 | 212 | |
213 | 213 | // Display the country. |
214 | - if ( 'country' == $key ) { |
|
214 | + if ('country' == $key) { |
|
215 | 215 | |
216 | 216 | echo aui()->select( |
217 | 217 | array( |
218 | 218 | 'options' => wpinv_get_country_list(), |
219 | - 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
|
220 | - 'id' => 'wpinv-' . sanitize_html_class( $key ), |
|
221 | - 'value' => sanitize_text_field( getpaid_get_user_address_field( get_current_user_id(), $key ) ), |
|
219 | + 'name' => 'getpaid_address[' . esc_attr($key) . ']', |
|
220 | + 'id' => 'wpinv-' . sanitize_html_class($key), |
|
221 | + 'value' => sanitize_text_field(getpaid_get_user_address_field(get_current_user_id(), $key)), |
|
222 | 222 | 'placeholder' => $label, |
223 | - 'label' => wp_kses_post( $label ), |
|
223 | + 'label' => wp_kses_post($label), |
|
224 | 224 | 'label_type' => 'vertical', |
225 | 225 | 'class' => 'getpaid-address-field', |
226 | 226 | ) |
@@ -229,30 +229,30 @@ discard block |
||
229 | 229 | } |
230 | 230 | |
231 | 231 | // Display the state. |
232 | - else if ( 'state' == $key ) { |
|
232 | + else if ('state' == $key) { |
|
233 | 233 | |
234 | - echo getpaid_get_states_select_markup ( |
|
235 | - getpaid_get_user_address_field( get_current_user_id(), 'country' ), |
|
236 | - getpaid_get_user_address_field( get_current_user_id(), 'state' ), |
|
234 | + echo getpaid_get_states_select_markup( |
|
235 | + getpaid_get_user_address_field(get_current_user_id(), 'country'), |
|
236 | + getpaid_get_user_address_field(get_current_user_id(), 'state'), |
|
237 | 237 | $label, |
238 | 238 | $label, |
239 | 239 | '', |
240 | 240 | false, |
241 | 241 | '', |
242 | - 'getpaid_address[' . esc_attr( $key ) . ']' |
|
242 | + 'getpaid_address[' . esc_attr($key) . ']' |
|
243 | 243 | ); |
244 | 244 | |
245 | 245 | } else { |
246 | 246 | |
247 | 247 | echo aui()->input( |
248 | 248 | array( |
249 | - 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
|
250 | - 'id' => 'wpinv-' . sanitize_html_class( $key ), |
|
249 | + 'name' => 'getpaid_address[' . esc_attr($key) . ']', |
|
250 | + 'id' => 'wpinv-' . sanitize_html_class($key), |
|
251 | 251 | 'placeholder' => $label, |
252 | - 'label' => wp_kses_post( $label ), |
|
252 | + 'label' => wp_kses_post($label), |
|
253 | 253 | 'label_type' => 'vertical', |
254 | 254 | 'type' => 'text', |
255 | - 'value' => sanitize_text_field( getpaid_get_user_address_field( get_current_user_id(), $key ) ), |
|
255 | + 'value' => sanitize_text_field(getpaid_get_user_address_field(get_current_user_id(), $key)), |
|
256 | 256 | 'class' => 'getpaid-address-field', |
257 | 257 | ) |
258 | 258 | ); |
@@ -266,30 +266,30 @@ discard block |
||
266 | 266 | 'name' => 'getpaid_address[email_cc]', |
267 | 267 | 'id' => 'wpinv-email_cc', |
268 | 268 | 'placeholder' => '[email protected], [email protected]', |
269 | - 'label' => __( 'Other email addresses', 'invoicing' ), |
|
269 | + 'label' => __('Other email addresses', 'invoicing'), |
|
270 | 270 | 'label_type' => 'vertical', |
271 | 271 | 'type' => 'text', |
272 | - 'value' => sanitize_text_field( get_user_meta( get_current_user_id(), '_wpinv_email_cc', true ) ), |
|
272 | + 'value' => sanitize_text_field(get_user_meta(get_current_user_id(), '_wpinv_email_cc', true)), |
|
273 | 273 | 'class' => 'getpaid-address-field', |
274 | - 'help_text' => __( 'Optionally provide other email addresses where we should send payment notifications', 'invoicing' ), |
|
274 | + 'help_text' => __('Optionally provide other email addresses where we should send payment notifications', 'invoicing'), |
|
275 | 275 | ) |
276 | 276 | ); |
277 | 277 | |
278 | - do_action( 'getpaid_display_address_edit_tab' ); |
|
278 | + do_action('getpaid_display_address_edit_tab'); |
|
279 | 279 | |
280 | 280 | echo aui()->input( |
281 | 281 | array( |
282 | 282 | 'name' => 'getpaid_profile_edit_submit_button', |
283 | 283 | 'id' => 'getpaid_profile_edit_submit_button', |
284 | - 'value' => __( 'Save Address', 'invoicing' ), |
|
285 | - 'help_text' => __( 'New invoices will use this address as the billing address.', 'invoicing' ), |
|
284 | + 'value' => __('Save Address', 'invoicing'), |
|
285 | + 'help_text' => __('New invoices will use this address as the billing address.', 'invoicing'), |
|
286 | 286 | 'type' => 'submit', |
287 | 287 | 'class' => 'btn btn-primary btn-block submit-button', |
288 | 288 | ) |
289 | 289 | ); |
290 | 290 | |
291 | - wp_nonce_field( 'getpaid-nonce', 'getpaid-nonce' ); |
|
292 | - getpaid_hidden_field( 'getpaid-action', 'edit_billing_details' ); |
|
291 | + wp_nonce_field('getpaid-nonce', 'getpaid-nonce'); |
|
292 | + getpaid_hidden_field('getpaid-action', 'edit_billing_details'); |
|
293 | 293 | ?> |
294 | 294 | |
295 | 295 | </form> |
@@ -306,31 +306,31 @@ discard block |
||
306 | 306 | * @since 2.1.4 |
307 | 307 | * @param array $data |
308 | 308 | */ |
309 | -function getpaid_save_address_edit_tab( $data ) { |
|
309 | +function getpaid_save_address_edit_tab($data) { |
|
310 | 310 | |
311 | - if ( empty( $data['getpaid_address'] ) || ! is_array( $data['getpaid_address'] ) ) { |
|
311 | + if (empty($data['getpaid_address']) || !is_array($data['getpaid_address'])) { |
|
312 | 312 | return; |
313 | 313 | } |
314 | 314 | |
315 | 315 | $data = $data['getpaid_address']; |
316 | 316 | $user_id = get_current_user_id(); |
317 | 317 | |
318 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
318 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
319 | 319 | |
320 | - if ( isset( $data[ $field ] ) ) { |
|
321 | - $value = sanitize_text_field( $data[ $field ] ); |
|
322 | - update_user_meta( $user_id, '_wpinv_' . $field, $value ); |
|
320 | + if (isset($data[$field])) { |
|
321 | + $value = sanitize_text_field($data[$field]); |
|
322 | + update_user_meta($user_id, '_wpinv_' . $field, $value); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | } |
326 | 326 | |
327 | - if ( isset( $data['email_cc'] ) ) { |
|
328 | - update_user_meta( $user_id, '_wpinv_email_cc', sanitize_text_field( $data['email_cc'] ) ); |
|
327 | + if (isset($data['email_cc'])) { |
|
328 | + update_user_meta($user_id, '_wpinv_email_cc', sanitize_text_field($data['email_cc'])); |
|
329 | 329 | } |
330 | 330 | |
331 | - wpinv_set_error( 'address_updated', __( 'Your billing address has been updated', 'invoicing' ), 'success'); |
|
331 | + wpinv_set_error('address_updated', __('Your billing address has been updated', 'invoicing'), 'success'); |
|
332 | 332 | } |
333 | -add_action( 'getpaid_authenticated_action_edit_billing_details', 'getpaid_save_address_edit_tab' ); |
|
333 | +add_action('getpaid_authenticated_action_edit_billing_details', 'getpaid_save_address_edit_tab'); |
|
334 | 334 | |
335 | 335 | |
336 | 336 | /* |
@@ -348,27 +348,27 @@ discard block |
||
348 | 348 | * @param array $tabs |
349 | 349 | * @return array |
350 | 350 | */ |
351 | -function getpaid_filter_userswp_account_tabs( $tabs ) { |
|
351 | +function getpaid_filter_userswp_account_tabs($tabs) { |
|
352 | 352 | |
353 | 353 | // Abort if the integration is inactive. |
354 | - if ( ! getpaid_is_userswp_integration_active() ) { |
|
354 | + if (!getpaid_is_userswp_integration_active()) { |
|
355 | 355 | return $tabs; |
356 | 356 | } |
357 | 357 | |
358 | - $new_tabs = array(); |
|
358 | + $new_tabs = array(); |
|
359 | 359 | |
360 | - foreach ( getpaid_get_user_content_tabs() as $slug => $tab ) { |
|
360 | + foreach (getpaid_get_user_content_tabs() as $slug => $tab) { |
|
361 | 361 | |
362 | - $new_tabs[ $slug ] = array( |
|
363 | - 'title' => $tab[ 'label'], |
|
364 | - 'icon' => $tab[ 'icon'], |
|
362 | + $new_tabs[$slug] = array( |
|
363 | + 'title' => $tab['label'], |
|
364 | + 'icon' => $tab['icon'], |
|
365 | 365 | ); |
366 | 366 | |
367 | 367 | } |
368 | 368 | |
369 | - return array_merge( $tabs, $new_tabs ); |
|
369 | + return array_merge($tabs, $new_tabs); |
|
370 | 370 | } |
371 | -add_filter( 'uwp_account_available_tabs', 'getpaid_filter_userswp_account_tabs' ); |
|
371 | +add_filter('uwp_account_available_tabs', 'getpaid_filter_userswp_account_tabs'); |
|
372 | 372 | |
373 | 373 | /** |
374 | 374 | * Display our UsersWP account tabs. |
@@ -377,18 +377,18 @@ discard block |
||
377 | 377 | * @param array $tabs |
378 | 378 | * @return array |
379 | 379 | */ |
380 | -function getpaid_display_userswp_account_tabs( $tab ) { |
|
380 | +function getpaid_display_userswp_account_tabs($tab) { |
|
381 | 381 | global $getpaid_tab_url; |
382 | 382 | |
383 | 383 | $our_tabs = getpaid_get_user_content_tabs(); |
384 | 384 | |
385 | - if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) { |
|
386 | - $getpaid_tab_url = add_query_arg( 'type', '%s', uwp_get_account_page_url() ); |
|
387 | - echo getpaid_prepare_user_content_tab( $our_tabs[ $tab ] ); |
|
385 | + if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) { |
|
386 | + $getpaid_tab_url = add_query_arg('type', '%s', uwp_get_account_page_url()); |
|
387 | + echo getpaid_prepare_user_content_tab($our_tabs[$tab]); |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | } |
391 | -add_action( 'uwp_account_form_display', 'getpaid_display_userswp_account_tabs' ); |
|
391 | +add_action('uwp_account_form_display', 'getpaid_display_userswp_account_tabs'); |
|
392 | 392 | |
393 | 393 | |
394 | 394 | /** |
@@ -399,17 +399,17 @@ discard block |
||
399 | 399 | * @param string $tab Current tab. |
400 | 400 | * @return string Title. |
401 | 401 | */ |
402 | -function getpaid_filter_userswp_account_title( $title, $tab ) { |
|
402 | +function getpaid_filter_userswp_account_title($title, $tab) { |
|
403 | 403 | |
404 | - $our_tabs = getpaid_get_user_content_tabs(); |
|
404 | + $our_tabs = getpaid_get_user_content_tabs(); |
|
405 | 405 | |
406 | - if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) { |
|
407 | - return $our_tabs[ $tab ]['label']; |
|
406 | + if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) { |
|
407 | + return $our_tabs[$tab]['label']; |
|
408 | 408 | } |
409 | 409 | |
410 | 410 | return $title; |
411 | 411 | } |
412 | -add_filter( 'uwp_account_page_title', 'getpaid_filter_userswp_account_title', 10, 2 ); |
|
412 | +add_filter('uwp_account_page_title', 'getpaid_filter_userswp_account_title', 10, 2); |
|
413 | 413 | |
414 | 414 | /** |
415 | 415 | * Registers the UsersWP integration settings. |
@@ -418,26 +418,26 @@ discard block |
||
418 | 418 | * @param array $settings An array of integration settings. |
419 | 419 | * @return array |
420 | 420 | */ |
421 | -function getpaid_register_userswp_settings( $settings ) { |
|
421 | +function getpaid_register_userswp_settings($settings) { |
|
422 | 422 | |
423 | - if ( defined( 'USERSWP_PLUGIN_FILE' ) ) { |
|
423 | + if (defined('USERSWP_PLUGIN_FILE')) { |
|
424 | 424 | |
425 | 425 | $settings[] = array( |
426 | 426 | |
427 | 427 | 'id' => 'userswp', |
428 | - 'label' => __( 'UsersWP', 'invoicing' ), |
|
428 | + 'label' => __('UsersWP', 'invoicing'), |
|
429 | 429 | 'settings' => array( |
430 | 430 | |
431 | 431 | 'userswp_settings' => array( |
432 | 432 | 'id' => 'userswp_settings', |
433 | - 'name' => '<h3>' . __( 'UsersWP', 'invoicing' ) . '</h3>', |
|
433 | + 'name' => '<h3>' . __('UsersWP', 'invoicing') . '</h3>', |
|
434 | 434 | 'type' => 'header', |
435 | 435 | ), |
436 | 436 | |
437 | 437 | 'enable_userswp' => array( |
438 | 438 | 'id' => 'enable_userswp', |
439 | - 'name' => __( 'Enable Integration', 'invoicing' ), |
|
440 | - 'desc' => __( 'Display GetPaid items on UsersWP account page.', 'invoicing' ), |
|
439 | + 'name' => __('Enable Integration', 'invoicing'), |
|
440 | + 'desc' => __('Display GetPaid items on UsersWP account page.', 'invoicing'), |
|
441 | 441 | 'type' => 'checkbox', |
442 | 442 | 'std' => 1, |
443 | 443 | ) |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | |
451 | 451 | return $settings; |
452 | 452 | } |
453 | -add_filter( 'getpaid_integration_settings', 'getpaid_register_userswp_settings' ); |
|
453 | +add_filter('getpaid_integration_settings', 'getpaid_register_userswp_settings'); |
|
454 | 454 | |
455 | 455 | /** |
456 | 456 | * Ovewrites the invoices history page to UsersWP. |
@@ -458,18 +458,18 @@ discard block |
||
458 | 458 | * @since 2.3.1 |
459 | 459 | * @return bool |
460 | 460 | */ |
461 | -function getpaid_userswp_overwrite_invoice_history_page( $url, $post_type ) { |
|
461 | +function getpaid_userswp_overwrite_invoice_history_page($url, $post_type) { |
|
462 | 462 | |
463 | 463 | $our_tabs = getpaid_get_user_content_tabs(); |
464 | 464 | $tab = "gp-{$post_type}s"; |
465 | - if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) { |
|
466 | - return add_query_arg( 'type', $tab, uwp_get_account_page_url() ); |
|
465 | + if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) { |
|
466 | + return add_query_arg('type', $tab, uwp_get_account_page_url()); |
|
467 | 467 | } |
468 | 468 | |
469 | 469 | return $url; |
470 | 470 | |
471 | 471 | } |
472 | -add_filter( 'wpinv_get_history_page_uri', 'getpaid_userswp_overwrite_invoice_history_page', 10, 2 ); |
|
472 | +add_filter('wpinv_get_history_page_uri', 'getpaid_userswp_overwrite_invoice_history_page', 10, 2); |
|
473 | 473 | |
474 | 474 | /** |
475 | 475 | * Checks if the integration is enabled. |
@@ -478,8 +478,8 @@ discard block |
||
478 | 478 | * @return bool |
479 | 479 | */ |
480 | 480 | function getpaid_is_userswp_integration_active() { |
481 | - $enabled = wpinv_get_option( 'enable_userswp', 1 ); |
|
482 | - return defined( 'USERSWP_PLUGIN_FILE' ) && ! empty( $enabled ); |
|
481 | + $enabled = wpinv_get_option('enable_userswp', 1); |
|
482 | + return defined('USERSWP_PLUGIN_FILE') && !empty($enabled); |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | /* |
@@ -497,26 +497,26 @@ discard block |
||
497 | 497 | * @param array $settings An array of integration settings. |
498 | 498 | * @return array |
499 | 499 | */ |
500 | -function getpaid_register_buddypress_settings( $settings ) { |
|
500 | +function getpaid_register_buddypress_settings($settings) { |
|
501 | 501 | |
502 | - if ( class_exists( 'BuddyPress' ) ) { |
|
502 | + if (class_exists('BuddyPress')) { |
|
503 | 503 | |
504 | 504 | $settings[] = array( |
505 | 505 | |
506 | 506 | 'id' => 'buddypress', |
507 | - 'label' => __( 'BuddyPress', 'invoicing' ), |
|
507 | + 'label' => __('BuddyPress', 'invoicing'), |
|
508 | 508 | 'settings' => array( |
509 | 509 | |
510 | 510 | 'buddypress_settings' => array( |
511 | 511 | 'id' => 'buddypress_settings', |
512 | - 'name' => '<h3>' . __( 'BuddyPress', 'invoicing' ) . '</h3>', |
|
512 | + 'name' => '<h3>' . __('BuddyPress', 'invoicing') . '</h3>', |
|
513 | 513 | 'type' => 'header', |
514 | 514 | ), |
515 | 515 | |
516 | 516 | 'enable_buddypress' => array( |
517 | 517 | 'id' => 'enable_buddypress', |
518 | - 'name' => __( 'Enable Integration', 'invoicing' ), |
|
519 | - 'desc' => __( 'Display GetPaid items on BuddyPress account pages.', 'invoicing' ), |
|
518 | + 'name' => __('Enable Integration', 'invoicing'), |
|
519 | + 'desc' => __('Display GetPaid items on BuddyPress account pages.', 'invoicing'), |
|
520 | 520 | 'type' => 'checkbox', |
521 | 521 | 'std' => 1, |
522 | 522 | ) |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | |
530 | 530 | return $settings; |
531 | 531 | } |
532 | -add_filter( 'getpaid_integration_settings', 'getpaid_register_buddypress_settings' ); |
|
532 | +add_filter('getpaid_integration_settings', 'getpaid_register_buddypress_settings'); |
|
533 | 533 | |
534 | 534 | /** |
535 | 535 | * Checks if the integration is enabled. |
@@ -538,8 +538,8 @@ discard block |
||
538 | 538 | * @return bool |
539 | 539 | */ |
540 | 540 | function getpaid_is_buddypress_integration_active() { |
541 | - $enabled = wpinv_get_option( 'enable_buddypress', 1 ); |
|
542 | - return class_exists( 'BuddyPress' ) && ! empty( $enabled ); |
|
541 | + $enabled = wpinv_get_option('enable_buddypress', 1); |
|
542 | + return class_exists('BuddyPress') && !empty($enabled); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | /** |
@@ -550,10 +550,10 @@ discard block |
||
550 | 550 | */ |
551 | 551 | function getpaid_setup_buddypress_integration() { |
552 | 552 | |
553 | - if ( getpaid_is_buddypress_integration_active() ) { |
|
554 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-bp-getpaid-component.php' ); |
|
553 | + if (getpaid_is_buddypress_integration_active()) { |
|
554 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-bp-getpaid-component.php'); |
|
555 | 555 | buddypress()->getpaid = new BP_GetPaid_Component(); |
556 | 556 | } |
557 | 557 | |
558 | 558 | } |
559 | -add_action( 'bp_setup_components', 'getpaid_setup_buddypress_integration' ); |
|
559 | +add_action('bp_setup_components', 'getpaid_setup_buddypress_integration'); |
@@ -7,65 +7,65 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | -function wpinv_bulk_actions( $actions ) { |
|
15 | - if ( isset( $actions['edit'] ) ) { |
|
16 | - unset( $actions['edit'] ); |
|
14 | +function wpinv_bulk_actions($actions) { |
|
15 | + if (isset($actions['edit'])) { |
|
16 | + unset($actions['edit']); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | return $actions; |
20 | 20 | } |
21 | -add_filter( 'bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions' ); |
|
22 | -add_filter( 'bulk_actions-edit-wpi_item', 'wpinv_bulk_actions' ); |
|
21 | +add_filter('bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions'); |
|
22 | +add_filter('bulk_actions-edit-wpi_item', 'wpinv_bulk_actions'); |
|
23 | 23 | |
24 | -function wpinv_admin_post_id( $id = 0 ) { |
|
24 | +function wpinv_admin_post_id($id = 0) { |
|
25 | 25 | global $post; |
26 | 26 | |
27 | - if ( isset( $id ) && ! empty( $id ) ) { |
|
28 | - return (int)$id; |
|
29 | - } else if ( get_the_ID() ) { |
|
27 | + if (isset($id) && !empty($id)) { |
|
28 | + return (int) $id; |
|
29 | + } else if (get_the_ID()) { |
|
30 | 30 | return (int) get_the_ID(); |
31 | - } else if ( isset( $post->ID ) && !empty( $post->ID ) ) { |
|
31 | + } else if (isset($post->ID) && !empty($post->ID)) { |
|
32 | 32 | return (int) $post->ID; |
33 | - } else if ( isset( $_GET['post'] ) && !empty( $_GET['post'] ) ) { |
|
33 | + } else if (isset($_GET['post']) && !empty($_GET['post'])) { |
|
34 | 34 | return (int) $_GET['post']; |
35 | - } else if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) { |
|
35 | + } else if (isset($_GET['id']) && !empty($_GET['id'])) { |
|
36 | 36 | return (int) $_GET['id']; |
37 | - } else if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) { |
|
37 | + } else if (isset($_POST['id']) && !empty($_POST['id'])) { |
|
38 | 38 | return (int) $_POST['id']; |
39 | 39 | } |
40 | 40 | |
41 | 41 | return null; |
42 | 42 | } |
43 | 43 | |
44 | -function wpinv_admin_post_type( $id = 0 ) { |
|
45 | - if ( !$id ) { |
|
44 | +function wpinv_admin_post_type($id = 0) { |
|
45 | + if (!$id) { |
|
46 | 46 | $id = wpinv_admin_post_id(); |
47 | 47 | } |
48 | 48 | |
49 | - $type = get_post_type( $id ); |
|
49 | + $type = get_post_type($id); |
|
50 | 50 | |
51 | - if ( !$type ) { |
|
52 | - $type = isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) ? $_GET['post_type'] : null; |
|
51 | + if (!$type) { |
|
52 | + $type = isset($_GET['post_type']) && !empty($_GET['post_type']) ? $_GET['post_type'] : null; |
|
53 | 53 | } |
54 | 54 | |
55 | - return apply_filters( 'wpinv_admin_post_type', $type, $id ); |
|
55 | + return apply_filters('wpinv_admin_post_type', $type, $id); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | function wpinv_admin_messages() { |
59 | - settings_errors( 'wpinv-notices' ); |
|
59 | + settings_errors('wpinv-notices'); |
|
60 | 60 | } |
61 | -add_action( 'admin_notices', 'wpinv_admin_messages' ); |
|
61 | +add_action('admin_notices', 'wpinv_admin_messages'); |
|
62 | 62 | |
63 | -add_action( 'admin_init', 'wpinv_show_test_payment_gateway_notice' ); |
|
64 | -function wpinv_show_test_payment_gateway_notice(){ |
|
65 | - add_action( 'admin_notices', 'wpinv_test_payment_gateway_messages' ); |
|
63 | +add_action('admin_init', 'wpinv_show_test_payment_gateway_notice'); |
|
64 | +function wpinv_show_test_payment_gateway_notice() { |
|
65 | + add_action('admin_notices', 'wpinv_test_payment_gateway_messages'); |
|
66 | 66 | } |
67 | 67 | |
68 | -function wpinv_test_payment_gateway_messages(){ |
|
68 | +function wpinv_test_payment_gateway_messages() { |
|
69 | 69 | $gateways = wpinv_get_enabled_payment_gateways(); |
70 | 70 | $name = array(); $test_gateways = ''; |
71 | 71 | if ($gateways) { |
@@ -76,9 +76,9 @@ discard block |
||
76 | 76 | } |
77 | 77 | $test_gateways = implode(', ', $name); |
78 | 78 | } |
79 | - if(isset($test_gateways) && !empty($test_gateways) && wpinv_current_user_can_manage_invoicing()){ |
|
79 | + if (isset($test_gateways) && !empty($test_gateways) && wpinv_current_user_can_manage_invoicing()) { |
|
80 | 80 | $link = admin_url('admin.php?page=wpinv-settings&tab=gateways'); |
81 | - $notice = wp_sprintf( __('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link ); |
|
81 | + $notice = wp_sprintf(__('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link); |
|
82 | 82 | ?> |
83 | 83 | <div class="notice notice-warning is-dismissible"> |
84 | 84 | <p><?php echo $notice; ?></p> |
@@ -95,29 +95,29 @@ discard block |
||
95 | 95 | global $wpdb; |
96 | 96 | |
97 | 97 | // Only do this on our settings page. |
98 | - if ( empty( $_GET[ 'page' ] ) || 'wpinv-settings' !== $_GET[ 'page' ] ) { |
|
98 | + if (empty($_GET['page']) || 'wpinv-settings' !== $_GET['page']) { |
|
99 | 99 | return; |
100 | 100 | } |
101 | 101 | |
102 | 102 | // Check tables. |
103 | - $tables = array( |
|
103 | + $tables = array( |
|
104 | 104 | "{$wpdb->prefix}wpinv_subscriptions", |
105 | 105 | "{$wpdb->prefix}getpaid_invoices", |
106 | 106 | "{$wpdb->prefix}getpaid_invoice_items", |
107 | 107 | ); |
108 | 108 | |
109 | - foreach ( $tables as $table ) { |
|
110 | - if ( $table != $wpdb->get_var( "SHOW TABLES LIKE '$table'" ) ) { |
|
109 | + foreach ($tables as $table) { |
|
110 | + if ($table != $wpdb->get_var("SHOW TABLES LIKE '$table'")) { |
|
111 | 111 | |
112 | - $url = esc_url( |
|
112 | + $url = esc_url( |
|
113 | 113 | wp_nonce_url( |
114 | - add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ), |
|
114 | + add_query_arg('getpaid-admin-action', 'create_missing_tables'), |
|
115 | 115 | 'getpaid-nonce', |
116 | 116 | 'getpaid-nonce' |
117 | 117 | ) |
118 | 118 | ); |
119 | - $message = __( 'Some GetPaid database tables are missing. To use GetPaid without any issues, click on the button below to create the missing tables.', 'invoicing' ); |
|
120 | - $message2 = __( 'Create Tables', 'invoicing' ); |
|
119 | + $message = __('Some GetPaid database tables are missing. To use GetPaid without any issues, click on the button below to create the missing tables.', 'invoicing'); |
|
120 | + $message2 = __('Create Tables', 'invoicing'); |
|
121 | 121 | echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"; |
122 | 122 | break; |
123 | 123 | |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | } |
126 | 126 | |
127 | 127 | } |
128 | -add_action( 'admin_notices', 'wpinv_check_for_missing_tables' ); |
|
128 | +add_action('admin_notices', 'wpinv_check_for_missing_tables'); |
|
129 | 129 | |
130 | 130 | add_action('admin_init', 'wpinv_admin_search_by_invoice'); |
131 | 131 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | function wpinv_admin_search_by_invoice() { |
136 | 136 | global $typenow; |
137 | 137 | |
138 | - if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote' ) { |
|
138 | + if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote') { |
|
139 | 139 | add_filter('posts_search', 'wpinv_posts_search_example_type', 10, 2); |
140 | 140 | } |
141 | 141 | } |
@@ -150,9 +150,9 @@ discard block |
||
150 | 150 | global $wpdb; |
151 | 151 | |
152 | 152 | if ($query->is_main_query() && !empty($query->query['s'])) { |
153 | - $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql( $query->query['s'] ) . "%' )"; |
|
154 | - if ( ! empty( $search ) ) { |
|
155 | - $search = preg_replace( '/^ AND /', '', $search ); |
|
153 | + $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql($query->query['s']) . "%' )"; |
|
154 | + if (!empty($search)) { |
|
155 | + $search = preg_replace('/^ AND /', '', $search); |
|
156 | 156 | $search = " AND ( {$search} OR ( {$conditions_str} ) )"; |
157 | 157 | } else { |
158 | 158 | $search = " AND ( {$conditions_str} )"; |
@@ -165,17 +165,17 @@ discard block |
||
165 | 165 | /** |
166 | 166 | * Resets invoice counts. |
167 | 167 | */ |
168 | -function wpinv_reset_invoice_count(){ |
|
169 | - if ( ! empty( $_GET['reset_invoice_count'] ) && isset( $_GET['_nonce'] ) && wp_verify_nonce( $_GET['_nonce'], 'reset_invoice_count' ) ) { |
|
168 | +function wpinv_reset_invoice_count() { |
|
169 | + if (!empty($_GET['reset_invoice_count']) && isset($_GET['_nonce']) && wp_verify_nonce($_GET['_nonce'], 'reset_invoice_count')) { |
|
170 | 170 | wpinv_update_option('invoice_sequence_start', 1); |
171 | 171 | delete_option('wpinv_last_invoice_number'); |
172 | - getpaid_admin()->show_success( __( 'Invoice number sequence reset successfully.', 'invoicing' ) ); |
|
173 | - $url = remove_query_arg( array('reset_invoice_count', '_nonce') ); |
|
172 | + getpaid_admin()->show_success(__('Invoice number sequence reset successfully.', 'invoicing')); |
|
173 | + $url = remove_query_arg(array('reset_invoice_count', '_nonce')); |
|
174 | 174 | wp_redirect($url); |
175 | 175 | exit(); |
176 | 176 | } |
177 | 177 | } |
178 | -add_action( 'admin_init', 'wpinv_reset_invoice_count' ); |
|
178 | +add_action('admin_init', 'wpinv_reset_invoice_count'); |
|
179 | 179 | |
180 | 180 | /** |
181 | 181 | * Displays line items on the invoice edit page. |
@@ -184,29 +184,29 @@ discard block |
||
184 | 184 | * @param array $columns |
185 | 185 | * @return string |
186 | 186 | */ |
187 | -function wpinv_admin_get_line_items( $invoice, $columns ) { |
|
187 | +function wpinv_admin_get_line_items($invoice, $columns) { |
|
188 | 188 | |
189 | 189 | ob_start(); |
190 | 190 | |
191 | - do_action( 'getpaid_admin_before_line_items', $invoice ); |
|
191 | + do_action('getpaid_admin_before_line_items', $invoice); |
|
192 | 192 | |
193 | 193 | $count = 0; |
194 | - foreach ( $invoice->get_items() as $item ) { |
|
194 | + foreach ($invoice->get_items() as $item) { |
|
195 | 195 | |
196 | - $item_price = wpinv_price( $item->get_price(), $invoice->get_currency() ); |
|
196 | + $item_price = wpinv_price($item->get_price(), $invoice->get_currency()); |
|
197 | 197 | $quantity = (int) $item->get_quantity(); |
198 | - $item_subtotal = wpinv_price( $item->get_sub_total(), $invoice->get_currency() ); |
|
199 | - $summary = apply_filters( 'getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice ); |
|
198 | + $item_subtotal = wpinv_price($item->get_sub_total(), $invoice->get_currency()); |
|
199 | + $summary = apply_filters('getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice); |
|
200 | 200 | $item_tax = $item->item_tax; |
201 | - $tax_rate = wpinv_round_amount( getpaid_get_invoice_tax_rate( $invoice, $item ), 2, true ) . '%';; |
|
202 | - $tax_rate = empty( $tax_rate ) ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : ''; |
|
201 | + $tax_rate = wpinv_round_amount(getpaid_get_invoice_tax_rate($invoice, $item), 2, true) . '%'; ; |
|
202 | + $tax_rate = empty($tax_rate) ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : ''; |
|
203 | 203 | $line_item_tax = $item_tax . $tax_rate; |
204 | - $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . esc_attr( $item->get_id() ) . '">'; |
|
204 | + $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . esc_attr($item->get_id()) . '">'; |
|
205 | 205 | $line_item .= '<td class="id">' . (int) $item->get_id() . '</td>'; |
206 | - $line_item .= '<td class="title"><a href="' . get_edit_post_link( $item->get_id() ) . '" target="_blank">' . $item->get_name() . '</a>'; |
|
206 | + $line_item .= '<td class="title"><a href="' . get_edit_post_link($item->get_id()) . '" target="_blank">' . $item->get_name() . '</a>'; |
|
207 | 207 | |
208 | - if ( $summary !== '' ) { |
|
209 | - $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>'; |
|
208 | + if ($summary !== '') { |
|
209 | + $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>'; |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | $line_item .= '</td>'; |
@@ -214,23 +214,23 @@ discard block |
||
214 | 214 | $line_item .= '<td class="qty" data-quantity="' . $quantity . '"> × ' . $quantity . '</td>'; |
215 | 215 | $line_item .= '<td class="total">' . $item_subtotal . '</td>'; |
216 | 216 | |
217 | - if ( wpinv_use_taxes() && $invoice->is_taxable() ) { |
|
217 | + if (wpinv_use_taxes() && $invoice->is_taxable()) { |
|
218 | 218 | $line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
219 | 219 | } |
220 | 220 | |
221 | 221 | $line_item .= '<td class="action">'; |
222 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
222 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
223 | 223 | $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>'; |
224 | 224 | } |
225 | 225 | $line_item .= '</td>'; |
226 | 226 | $line_item .= '</tr>'; |
227 | 227 | |
228 | - echo apply_filters( 'getpaid_admin_line_item', $line_item, $item, $invoice ); |
|
228 | + echo apply_filters('getpaid_admin_line_item', $line_item, $item, $invoice); |
|
229 | 229 | |
230 | 230 | $count++; |
231 | 231 | } |
232 | 232 | |
233 | - do_action( 'getpaid_admin_after_line_items', $invoice ); |
|
233 | + do_action('getpaid_admin_after_line_items', $invoice); |
|
234 | 234 | |
235 | 235 | return ob_get_clean(); |
236 | 236 | } |
@@ -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 | * Are we supporting item quantities? |
@@ -20,35 +20,35 @@ discard block |
||
20 | 20 | */ |
21 | 21 | function wpinv_get_ip() { |
22 | 22 | |
23 | - if ( isset( $_SERVER['HTTP_X_REAL_IP'] ) ) { |
|
24 | - return sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_REAL_IP'] ) ); |
|
23 | + if (isset($_SERVER['HTTP_X_REAL_IP'])) { |
|
24 | + return sanitize_text_field(wp_unslash($_SERVER['HTTP_X_REAL_IP'])); |
|
25 | 25 | } |
26 | 26 | |
27 | - if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { |
|
27 | + if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
28 | 28 | // Proxy servers can send through this header like this: X-Forwarded-For: client1, proxy1, proxy2 |
29 | 29 | // Make sure we always only send through the first IP in the list which should always be the client IP. |
30 | - return (string) rest_is_ip_address( trim( current( preg_split( '/,/', sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) ) ) ) ); |
|
30 | + return (string) rest_is_ip_address(trim(current(preg_split('/,/', sanitize_text_field(wp_unslash($_SERVER['HTTP_X_FORWARDED_FOR'])))))); |
|
31 | 31 | } |
32 | 32 | |
33 | - if ( isset( $_SERVER['HTTP_CLIENT_IP'] ) ) { |
|
34 | - return sanitize_text_field( wp_unslash( $_SERVER['HTTP_CLIENT_IP'] ) ); |
|
33 | + if (isset($_SERVER['HTTP_CLIENT_IP'])) { |
|
34 | + return sanitize_text_field(wp_unslash($_SERVER['HTTP_CLIENT_IP'])); |
|
35 | 35 | } |
36 | 36 | |
37 | - if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { |
|
38 | - return sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ); |
|
37 | + if (isset($_SERVER['REMOTE_ADDR'])) { |
|
38 | + return sanitize_text_field(wp_unslash($_SERVER['REMOTE_ADDR'])); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | return ''; |
42 | 42 | } |
43 | 43 | |
44 | 44 | function wpinv_get_user_agent() { |
45 | - if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
|
46 | - $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ); |
|
45 | + if (!empty($_SERVER['HTTP_USER_AGENT'])) { |
|
46 | + $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']); |
|
47 | 47 | } else { |
48 | 48 | $user_agent = ''; |
49 | 49 | } |
50 | 50 | |
51 | - return apply_filters( 'wpinv_get_user_agent', $user_agent ); |
|
51 | + return apply_filters('wpinv_get_user_agent', $user_agent); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -57,16 +57,16 @@ discard block |
||
57 | 57 | * @param string $amount The amount to sanitize. |
58 | 58 | * @return float |
59 | 59 | */ |
60 | -function getpaid_standardize_amount( $amount ) { |
|
60 | +function getpaid_standardize_amount($amount) { |
|
61 | 61 | |
62 | - $amount = str_replace( wpinv_thousands_separator(), '', $amount ); |
|
63 | - $amount = str_replace( wpinv_decimal_separator(), '.', $amount ); |
|
64 | - if ( is_numeric( $amount ) ) { |
|
65 | - return floatval( $amount ); |
|
62 | + $amount = str_replace(wpinv_thousands_separator(), '', $amount); |
|
63 | + $amount = str_replace(wpinv_decimal_separator(), '.', $amount); |
|
64 | + if (is_numeric($amount)) { |
|
65 | + return floatval($amount); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | // Cast the remaining to a float. |
69 | - return wpinv_round_amount( preg_replace( '/[^0-9\.\-]/', '', $amount ) ); |
|
69 | + return wpinv_round_amount(preg_replace('/[^0-9\.\-]/', '', $amount)); |
|
70 | 70 | |
71 | 71 | } |
72 | 72 | |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @param string $amount The amount to sanitize. |
77 | 77 | */ |
78 | -function getpaid_unstandardize_amount( $amount ) { |
|
79 | - return str_replace( '.', wpinv_decimal_separator(), $amount ); |
|
78 | +function getpaid_unstandardize_amount($amount) { |
|
79 | + return str_replace('.', wpinv_decimal_separator(), $amount); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -84,23 +84,23 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @param string $amount The amount to sanitize. |
86 | 86 | */ |
87 | -function wpinv_sanitize_amount( $amount ) { |
|
87 | +function wpinv_sanitize_amount($amount) { |
|
88 | 88 | |
89 | - if ( is_numeric( $amount ) ) { |
|
90 | - return floatval( $amount ); |
|
89 | + if (is_numeric($amount)) { |
|
90 | + return floatval($amount); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | // Separate the decimals and thousands. |
94 | - $amount = explode( wpinv_decimal_separator(), $amount ); |
|
94 | + $amount = explode(wpinv_decimal_separator(), $amount); |
|
95 | 95 | |
96 | 96 | // Remove thousands. |
97 | - $amount[0] = str_replace( wpinv_thousands_separator(), '', $amount[0] ); |
|
97 | + $amount[0] = str_replace(wpinv_thousands_separator(), '', $amount[0]); |
|
98 | 98 | |
99 | 99 | // Convert back to string. |
100 | - $amount = count( $amount ) > 1 ? "{$amount[0]}.{$amount[1]}" : $amount[0]; |
|
100 | + $amount = count($amount) > 1 ? "{$amount[0]}.{$amount[1]}" : $amount[0]; |
|
101 | 101 | |
102 | 102 | // Cast the remaining to a float. |
103 | - return (float) preg_replace( '/[^0-9\.\-]/', '', $amount ); |
|
103 | + return (float) preg_replace('/[^0-9\.\-]/', '', $amount); |
|
104 | 104 | |
105 | 105 | } |
106 | 106 | |
@@ -110,19 +110,19 @@ discard block |
||
110 | 110 | * @param float $amount |
111 | 111 | * @param float|string|int|null $decimals |
112 | 112 | */ |
113 | -function wpinv_round_amount( $amount, $decimals = null, $use_sprintf = false ) { |
|
113 | +function wpinv_round_amount($amount, $decimals = null, $use_sprintf = false) { |
|
114 | 114 | |
115 | - if ( $decimals === null ) { |
|
115 | + if ($decimals === null) { |
|
116 | 116 | $decimals = wpinv_decimals(); |
117 | 117 | } |
118 | 118 | |
119 | - if ( $use_sprintf ) { |
|
120 | - $amount = sprintf( "%.{$decimals}f", (float) $amount ); |
|
119 | + if ($use_sprintf) { |
|
120 | + $amount = sprintf("%.{$decimals}f", (float) $amount); |
|
121 | 121 | } else { |
122 | - $amount = round( (float) $amount, absint( $decimals ) ); |
|
122 | + $amount = round((float) $amount, absint($decimals)); |
|
123 | 123 | } |
124 | 124 | |
125 | - return apply_filters( 'wpinv_round_amount', $amount, $decimals ); |
|
125 | + return apply_filters('wpinv_round_amount', $amount, $decimals); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -134,32 +134,32 @@ discard block |
||
134 | 134 | * @param string|WPInv_Invoice $invoice The invoice object|post type|type |
135 | 135 | * @return array |
136 | 136 | */ |
137 | -function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) { |
|
137 | +function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) { |
|
138 | 138 | |
139 | 139 | $invoice_statuses = array( |
140 | - 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
141 | - 'publish' => _x( 'Paid', 'Invoice status', 'invoicing' ), |
|
142 | - 'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
143 | - 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
144 | - 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
145 | - 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
146 | - 'wpi-failed' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
147 | - 'wpi-renewal' => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ), |
|
140 | + 'wpi-pending' => _x('Pending payment', 'Invoice status', 'invoicing'), |
|
141 | + 'publish' => _x('Paid', 'Invoice status', 'invoicing'), |
|
142 | + 'wpi-processing' => _x('Processing', 'Invoice status', 'invoicing'), |
|
143 | + 'wpi-onhold' => _x('On hold', 'Invoice status', 'invoicing'), |
|
144 | + 'wpi-cancelled' => _x('Cancelled', 'Invoice status', 'invoicing'), |
|
145 | + 'wpi-refunded' => _x('Refunded', 'Invoice status', 'invoicing'), |
|
146 | + 'wpi-failed' => _x('Failed', 'Invoice status', 'invoicing'), |
|
147 | + 'wpi-renewal' => _x('Renewal Payment', 'Invoice status', 'invoicing'), |
|
148 | 148 | ); |
149 | 149 | |
150 | - if ( $draft ) { |
|
151 | - $invoice_statuses['draft'] = __( 'Draft', 'invoicing' ); |
|
150 | + if ($draft) { |
|
151 | + $invoice_statuses['draft'] = __('Draft', 'invoicing'); |
|
152 | 152 | } |
153 | 153 | |
154 | - if ( $trashed ) { |
|
155 | - $invoice_statuses['trash'] = __( 'Trash', 'invoicing' ); |
|
154 | + if ($trashed) { |
|
155 | + $invoice_statuses['trash'] = __('Trash', 'invoicing'); |
|
156 | 156 | } |
157 | 157 | |
158 | - if ( $invoice instanceof WPInv_Invoice ) { |
|
158 | + if ($invoice instanceof WPInv_Invoice) { |
|
159 | 159 | $invoice = $invoice->get_post_type(); |
160 | 160 | } |
161 | 161 | |
162 | - return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
162 | + return apply_filters('wpinv_statuses', $invoice_statuses, $invoice); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -168,11 +168,11 @@ discard block |
||
168 | 168 | * @param string $status The raw status |
169 | 169 | * @param string|WPInv_Invoice $invoice The invoice object|post type|type |
170 | 170 | */ |
171 | -function wpinv_status_nicename( $status, $invoice = false ) { |
|
172 | - $statuses = wpinv_get_invoice_statuses( true, true, $invoice ); |
|
173 | - $status = isset( $statuses[$status] ) ? $statuses[$status] : $status; |
|
171 | +function wpinv_status_nicename($status, $invoice = false) { |
|
172 | + $statuses = wpinv_get_invoice_statuses(true, true, $invoice); |
|
173 | + $status = isset($statuses[$status]) ? $statuses[$status] : $status; |
|
174 | 174 | |
175 | - return sanitize_text_field( $status ); |
|
175 | + return sanitize_text_field($status); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -180,13 +180,13 @@ discard block |
||
180 | 180 | * |
181 | 181 | * @param string $current |
182 | 182 | */ |
183 | -function wpinv_get_currency( $current = '' ) { |
|
183 | +function wpinv_get_currency($current = '') { |
|
184 | 184 | |
185 | - if ( empty( $current ) ) { |
|
186 | - $current = apply_filters( 'wpinv_currency', wpinv_get_option( 'currency', 'USD' ) ); |
|
185 | + if (empty($current)) { |
|
186 | + $current = apply_filters('wpinv_currency', wpinv_get_option('currency', 'USD')); |
|
187 | 187 | } |
188 | 188 | |
189 | - return trim( strtoupper( $current ) ); |
|
189 | + return trim(strtoupper($current)); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -194,25 +194,25 @@ discard block |
||
194 | 194 | * |
195 | 195 | * @param string|null $currency The currency code. Defaults to the default currency. |
196 | 196 | */ |
197 | -function wpinv_currency_symbol( $currency = null ) { |
|
197 | +function wpinv_currency_symbol($currency = null) { |
|
198 | 198 | |
199 | 199 | // Prepare the currency. |
200 | - $currency = empty( $currency ) ? wpinv_get_currency() : wpinv_clean( $currency ); |
|
200 | + $currency = empty($currency) ? wpinv_get_currency() : wpinv_clean($currency); |
|
201 | 201 | |
202 | 202 | // Fetch all symbols. |
203 | 203 | $symbols = wpinv_get_currency_symbols(); |
204 | 204 | |
205 | 205 | // Fetch this currencies symbol. |
206 | - $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : $currency; |
|
206 | + $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency; |
|
207 | 207 | |
208 | 208 | // Filter the symbol. |
209 | - return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency ); |
|
209 | + return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | function wpinv_currency_position() { |
213 | - $position = wpinv_get_option( 'currency_position', 'left' ); |
|
213 | + $position = wpinv_get_option('currency_position', 'left'); |
|
214 | 214 | |
215 | - return apply_filters( 'wpinv_currency_position', $position ); |
|
215 | + return apply_filters('wpinv_currency_position', $position); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -220,13 +220,13 @@ discard block |
||
220 | 220 | * |
221 | 221 | * @param $string|null $current |
222 | 222 | */ |
223 | -function wpinv_thousands_separator( $current = null ) { |
|
223 | +function wpinv_thousands_separator($current = null) { |
|
224 | 224 | |
225 | - if ( null == $current ) { |
|
226 | - $current = wpinv_get_option( 'thousands_separator', ',' ); |
|
225 | + if (null == $current) { |
|
226 | + $current = wpinv_get_option('thousands_separator', ','); |
|
227 | 227 | } |
228 | 228 | |
229 | - return trim( $current ); |
|
229 | + return trim($current); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -234,13 +234,13 @@ discard block |
||
234 | 234 | * |
235 | 235 | * @param $string|null $current |
236 | 236 | */ |
237 | -function wpinv_decimal_separator( $current = null ) { |
|
237 | +function wpinv_decimal_separator($current = null) { |
|
238 | 238 | |
239 | - if ( null == $current ) { |
|
240 | - $current = wpinv_get_option( 'decimal_separator', '.' ); |
|
239 | + if (null == $current) { |
|
240 | + $current = wpinv_get_option('decimal_separator', '.'); |
|
241 | 241 | } |
242 | 242 | |
243 | - return trim( $current ); |
|
243 | + return trim($current); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | /** |
@@ -248,27 +248,27 @@ discard block |
||
248 | 248 | * |
249 | 249 | * @param $string|null $current |
250 | 250 | */ |
251 | -function wpinv_decimals( $current = null ) { |
|
251 | +function wpinv_decimals($current = null) { |
|
252 | 252 | |
253 | - if ( null == $current ) { |
|
254 | - $current = wpinv_get_option( 'decimals', 2 ); |
|
253 | + if (null == $current) { |
|
254 | + $current = wpinv_get_option('decimals', 2); |
|
255 | 255 | } |
256 | 256 | |
257 | - return absint( $current ); |
|
257 | + return absint($current); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
261 | 261 | * Retrieves a list of all supported currencies. |
262 | 262 | */ |
263 | 263 | function wpinv_get_currencies() { |
264 | - return apply_filters( 'wpinv_currencies', wpinv_get_data( 'currencies' ) ); |
|
264 | + return apply_filters('wpinv_currencies', wpinv_get_data('currencies')); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
268 | 268 | * Retrieves a list of all currency symbols. |
269 | 269 | */ |
270 | 270 | function wpinv_get_currency_symbols() { |
271 | - return apply_filters( 'wpinv_currency_symbols', wpinv_get_data( 'currency-symbols' ) ); |
|
271 | + return apply_filters('wpinv_currency_symbols', wpinv_get_data('currency-symbols')); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | $currency_pos = wpinv_currency_position(); |
281 | 281 | $format = '%1$s%2$s'; |
282 | 282 | |
283 | - switch ( $currency_pos ) { |
|
283 | + switch ($currency_pos) { |
|
284 | 284 | case 'left': |
285 | 285 | $format = '%1$s%2$s'; |
286 | 286 | break; |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | break; |
296 | 296 | } |
297 | 297 | |
298 | - return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
298 | + return apply_filters('getpaid_price_format', $format, $currency_pos); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | /** |
@@ -305,25 +305,25 @@ discard block |
||
305 | 305 | * @param string $currency Currency. |
306 | 306 | * @return string |
307 | 307 | */ |
308 | -function wpinv_price( $amount = 0, $currency = '' ) { |
|
308 | +function wpinv_price($amount = 0, $currency = '') { |
|
309 | 309 | |
310 | 310 | // Backwards compatibility. |
311 | - $amount = wpinv_sanitize_amount( $amount ); |
|
311 | + $amount = wpinv_sanitize_amount($amount); |
|
312 | 312 | |
313 | 313 | // Prepare variables. |
314 | - $currency = wpinv_get_currency( $currency ); |
|
314 | + $currency = wpinv_get_currency($currency); |
|
315 | 315 | $amount = (float) $amount; |
316 | 316 | $unformatted_amount = $amount; |
317 | 317 | $negative = $amount < 0; |
318 | - $amount = apply_filters( 'getpaid_raw_amount', floatval( $negative ? $amount * -1 : $amount ) ); |
|
319 | - $amount = wpinv_format_amount( $amount ); |
|
318 | + $amount = apply_filters('getpaid_raw_amount', floatval($negative ? $amount * -1 : $amount)); |
|
319 | + $amount = wpinv_format_amount($amount); |
|
320 | 320 | |
321 | 321 | // Format the amount. |
322 | 322 | $format = getpaid_get_price_format(); |
323 | - $formatted_amount = ( $negative ? '-' : '' ) . sprintf( $format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol( $currency ) . '</span>', $amount ); |
|
323 | + $formatted_amount = ($negative ? '-' : '') . sprintf($format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol($currency) . '</span>', $amount); |
|
324 | 324 | |
325 | 325 | // Filter the formatting. |
326 | - return apply_filters( 'wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount ); |
|
326 | + return apply_filters('wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
@@ -334,25 +334,25 @@ discard block |
||
334 | 334 | * @param bool $calculate Whether or not to apply separators. |
335 | 335 | * @return string |
336 | 336 | */ |
337 | -function wpinv_format_amount( $amount, $decimals = null, $calculate = false ) { |
|
337 | +function wpinv_format_amount($amount, $decimals = null, $calculate = false) { |
|
338 | 338 | $thousands_sep = wpinv_thousands_separator(); |
339 | 339 | $decimal_sep = wpinv_decimal_separator(); |
340 | - $decimals = wpinv_decimals( $decimals ); |
|
341 | - $amount = wpinv_sanitize_amount( $amount ); |
|
340 | + $decimals = wpinv_decimals($decimals); |
|
341 | + $amount = wpinv_sanitize_amount($amount); |
|
342 | 342 | |
343 | - if ( $calculate ) { |
|
343 | + if ($calculate) { |
|
344 | 344 | return $amount; |
345 | 345 | } |
346 | 346 | |
347 | 347 | // Fomart the amount. |
348 | - return number_format( $amount, $decimals, $decimal_sep, $thousands_sep ); |
|
348 | + return number_format($amount, $decimals, $decimal_sep, $thousands_sep); |
|
349 | 349 | } |
350 | 350 | |
351 | -function wpinv_sanitize_key( $key ) { |
|
351 | +function wpinv_sanitize_key($key) { |
|
352 | 352 | $raw_key = $key; |
353 | - $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key ); |
|
353 | + $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key); |
|
354 | 354 | |
355 | - return apply_filters( 'wpinv_sanitize_key', $key, $raw_key ); |
|
355 | + return apply_filters('wpinv_sanitize_key', $key, $raw_key); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | /** |
@@ -360,8 +360,8 @@ discard block |
||
360 | 360 | * |
361 | 361 | * @param $str the file whose extension should be retrieved. |
362 | 362 | */ |
363 | -function wpinv_get_file_extension( $str ) { |
|
364 | - $filetype = wp_check_filetype( $str ); |
|
363 | +function wpinv_get_file_extension($str) { |
|
364 | + $filetype = wp_check_filetype($str); |
|
365 | 365 | return $filetype['ext']; |
366 | 366 | } |
367 | 367 | |
@@ -370,16 +370,16 @@ discard block |
||
370 | 370 | * |
371 | 371 | * @param string $string |
372 | 372 | */ |
373 | -function wpinv_string_is_image_url( $string ) { |
|
374 | - $extension = strtolower( wpinv_get_file_extension( $string ) ); |
|
375 | - return in_array( $extension, array( 'jpeg', 'jpg', 'png', 'gif', 'ico' ), true ); |
|
373 | +function wpinv_string_is_image_url($string) { |
|
374 | + $extension = strtolower(wpinv_get_file_extension($string)); |
|
375 | + return in_array($extension, array('jpeg', 'jpg', 'png', 'gif', 'ico'), true); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | /** |
379 | 379 | * Returns the current URL. |
380 | 380 | */ |
381 | 381 | function wpinv_get_current_page_url() { |
382 | - return ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
|
382 | + return (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | /** |
@@ -389,46 +389,46 @@ discard block |
||
389 | 389 | * @param string $name Constant name. |
390 | 390 | * @param mixed $value Value. |
391 | 391 | */ |
392 | -function getpaid_maybe_define_constant( $name, $value ) { |
|
393 | - if ( ! defined( $name ) ) { |
|
394 | - define( $name, $value ); |
|
392 | +function getpaid_maybe_define_constant($name, $value) { |
|
393 | + if (!defined($name)) { |
|
394 | + define($name, $value); |
|
395 | 395 | } |
396 | 396 | } |
397 | 397 | |
398 | 398 | function wpinv_get_php_arg_separator_output() { |
399 | - return ini_get( 'arg_separator.output' ); |
|
399 | + return ini_get('arg_separator.output'); |
|
400 | 400 | } |
401 | 401 | |
402 | -function wpinv_rgb_from_hex( $color ) { |
|
403 | - $color = str_replace( '#', '', $color ); |
|
402 | +function wpinv_rgb_from_hex($color) { |
|
403 | + $color = str_replace('#', '', $color); |
|
404 | 404 | |
405 | 405 | // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF" |
406 | - $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color ); |
|
407 | - if ( empty( $color ) ) { |
|
406 | + $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color); |
|
407 | + if (empty($color)) { |
|
408 | 408 | return NULL; |
409 | 409 | } |
410 | 410 | |
411 | - $color = str_split( $color ); |
|
411 | + $color = str_split($color); |
|
412 | 412 | |
413 | 413 | $rgb = array(); |
414 | - $rgb['R'] = hexdec( $color[0] . $color[1] ); |
|
415 | - $rgb['G'] = hexdec( $color[2] . $color[3] ); |
|
416 | - $rgb['B'] = hexdec( $color[4] . $color[5] ); |
|
414 | + $rgb['R'] = hexdec($color[0] . $color[1]); |
|
415 | + $rgb['G'] = hexdec($color[2] . $color[3]); |
|
416 | + $rgb['B'] = hexdec($color[4] . $color[5]); |
|
417 | 417 | |
418 | 418 | return $rgb; |
419 | 419 | } |
420 | 420 | |
421 | -function wpinv_hex_darker( $color, $factor = 30 ) { |
|
422 | - $base = wpinv_rgb_from_hex( $color ); |
|
421 | +function wpinv_hex_darker($color, $factor = 30) { |
|
422 | + $base = wpinv_rgb_from_hex($color); |
|
423 | 423 | $color = '#'; |
424 | 424 | |
425 | - foreach ( $base as $k => $v ) { |
|
425 | + foreach ($base as $k => $v) { |
|
426 | 426 | $amount = $v / 100; |
427 | - $amount = round( $amount * $factor ); |
|
427 | + $amount = round($amount * $factor); |
|
428 | 428 | $new_decimal = $v - $amount; |
429 | 429 | |
430 | - $new_hex_component = dechex( $new_decimal ); |
|
431 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
430 | + $new_hex_component = dechex($new_decimal); |
|
431 | + if (strlen($new_hex_component) < 2) { |
|
432 | 432 | $new_hex_component = "0" . $new_hex_component; |
433 | 433 | } |
434 | 434 | $color .= $new_hex_component; |
@@ -437,18 +437,18 @@ discard block |
||
437 | 437 | return $color; |
438 | 438 | } |
439 | 439 | |
440 | -function wpinv_hex_lighter( $color, $factor = 30 ) { |
|
441 | - $base = wpinv_rgb_from_hex( $color ); |
|
440 | +function wpinv_hex_lighter($color, $factor = 30) { |
|
441 | + $base = wpinv_rgb_from_hex($color); |
|
442 | 442 | $color = '#'; |
443 | 443 | |
444 | - foreach ( $base as $k => $v ) { |
|
444 | + foreach ($base as $k => $v) { |
|
445 | 445 | $amount = 255 - $v; |
446 | 446 | $amount = $amount / 100; |
447 | - $amount = round( $amount * $factor ); |
|
447 | + $amount = round($amount * $factor); |
|
448 | 448 | $new_decimal = $v + $amount; |
449 | 449 | |
450 | - $new_hex_component = dechex( $new_decimal ); |
|
451 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
450 | + $new_hex_component = dechex($new_decimal); |
|
451 | + if (strlen($new_hex_component) < 2) { |
|
452 | 452 | $new_hex_component = "0" . $new_hex_component; |
453 | 453 | } |
454 | 454 | $color .= $new_hex_component; |
@@ -457,22 +457,22 @@ discard block |
||
457 | 457 | return $color; |
458 | 458 | } |
459 | 459 | |
460 | -function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { |
|
461 | - $hex = str_replace( '#', '', $color ); |
|
460 | +function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') { |
|
461 | + $hex = str_replace('#', '', $color); |
|
462 | 462 | |
463 | - $c_r = hexdec( substr( $hex, 0, 2 ) ); |
|
464 | - $c_g = hexdec( substr( $hex, 2, 2 ) ); |
|
465 | - $c_b = hexdec( substr( $hex, 4, 2 ) ); |
|
463 | + $c_r = hexdec(substr($hex, 0, 2)); |
|
464 | + $c_g = hexdec(substr($hex, 2, 2)); |
|
465 | + $c_b = hexdec(substr($hex, 4, 2)); |
|
466 | 466 | |
467 | - $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; |
|
467 | + $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000; |
|
468 | 468 | |
469 | 469 | return $brightness > 155 ? $dark : $light; |
470 | 470 | } |
471 | 471 | |
472 | -function wpinv_format_hex( $hex ) { |
|
473 | - $hex = trim( str_replace( '#', '', $hex ) ); |
|
472 | +function wpinv_format_hex($hex) { |
|
473 | + $hex = trim(str_replace('#', '', $hex)); |
|
474 | 474 | |
475 | - if ( strlen( $hex ) == 3 ) { |
|
475 | + if (strlen($hex) == 3) { |
|
476 | 476 | $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; |
477 | 477 | } |
478 | 478 | |
@@ -492,12 +492,12 @@ discard block |
||
492 | 492 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
493 | 493 | * @return string |
494 | 494 | */ |
495 | -function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) { |
|
496 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
497 | - return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding ); |
|
495 | +function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') { |
|
496 | + if (function_exists('mb_strimwidth')) { |
|
497 | + return mb_strimwidth($str, $start, $width, $trimmaker, $encoding); |
|
498 | 498 | } |
499 | 499 | |
500 | - return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker; |
|
500 | + return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker; |
|
501 | 501 | } |
502 | 502 | |
503 | 503 | /** |
@@ -509,28 +509,28 @@ discard block |
||
509 | 509 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
510 | 510 | * @return int Returns the number of characters in string. |
511 | 511 | */ |
512 | -function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) { |
|
513 | - if ( function_exists( 'mb_strlen' ) ) { |
|
514 | - return mb_strlen( $str, $encoding ); |
|
512 | +function wpinv_utf8_strlen($str, $encoding = 'UTF-8') { |
|
513 | + if (function_exists('mb_strlen')) { |
|
514 | + return mb_strlen($str, $encoding); |
|
515 | 515 | } |
516 | 516 | |
517 | - return strlen( $str ); |
|
517 | + return strlen($str); |
|
518 | 518 | } |
519 | 519 | |
520 | -function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) { |
|
521 | - if ( function_exists( 'mb_strtolower' ) ) { |
|
522 | - return mb_strtolower( $str, $encoding ); |
|
520 | +function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') { |
|
521 | + if (function_exists('mb_strtolower')) { |
|
522 | + return mb_strtolower($str, $encoding); |
|
523 | 523 | } |
524 | 524 | |
525 | - return strtolower( $str ); |
|
525 | + return strtolower($str); |
|
526 | 526 | } |
527 | 527 | |
528 | -function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) { |
|
529 | - if ( function_exists( 'mb_strtoupper' ) ) { |
|
530 | - return mb_strtoupper( $str, $encoding ); |
|
528 | +function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') { |
|
529 | + if (function_exists('mb_strtoupper')) { |
|
530 | + return mb_strtoupper($str, $encoding); |
|
531 | 531 | } |
532 | 532 | |
533 | - return strtoupper( $str ); |
|
533 | + return strtoupper($str); |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | /** |
@@ -544,12 +544,12 @@ discard block |
||
544 | 544 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
545 | 545 | * @return int Returns the position of the first occurrence of search in the string. |
546 | 546 | */ |
547 | -function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
548 | - if ( function_exists( 'mb_strpos' ) ) { |
|
549 | - return mb_strpos( $str, $find, $offset, $encoding ); |
|
547 | +function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
548 | + if (function_exists('mb_strpos')) { |
|
549 | + return mb_strpos($str, $find, $offset, $encoding); |
|
550 | 550 | } |
551 | 551 | |
552 | - return strpos( $str, $find, $offset ); |
|
552 | + return strpos($str, $find, $offset); |
|
553 | 553 | } |
554 | 554 | |
555 | 555 | /** |
@@ -563,12 +563,12 @@ discard block |
||
563 | 563 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
564 | 564 | * @return int Returns the position of the last occurrence of search. |
565 | 565 | */ |
566 | -function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
567 | - if ( function_exists( 'mb_strrpos' ) ) { |
|
568 | - return mb_strrpos( $str, $find, $offset, $encoding ); |
|
566 | +function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
567 | + if (function_exists('mb_strrpos')) { |
|
568 | + return mb_strrpos($str, $find, $offset, $encoding); |
|
569 | 569 | } |
570 | 570 | |
571 | - return strrpos( $str, $find, $offset ); |
|
571 | + return strrpos($str, $find, $offset); |
|
572 | 572 | } |
573 | 573 | |
574 | 574 | /** |
@@ -583,16 +583,16 @@ discard block |
||
583 | 583 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
584 | 584 | * @return string |
585 | 585 | */ |
586 | -function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) { |
|
587 | - if ( function_exists( 'mb_substr' ) ) { |
|
588 | - if ( $length === null ) { |
|
589 | - return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
586 | +function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') { |
|
587 | + if (function_exists('mb_substr')) { |
|
588 | + if ($length === null) { |
|
589 | + return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
590 | 590 | } else { |
591 | - return mb_substr( $str, $start, $length, $encoding ); |
|
591 | + return mb_substr($str, $start, $length, $encoding); |
|
592 | 592 | } |
593 | 593 | } |
594 | 594 | |
595 | - return substr( $str, $start, $length ); |
|
595 | + return substr($str, $start, $length); |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | /** |
@@ -604,48 +604,48 @@ discard block |
||
604 | 604 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
605 | 605 | * @return string The width of string. |
606 | 606 | */ |
607 | -function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) { |
|
608 | - if ( function_exists( 'mb_strwidth' ) ) { |
|
609 | - return mb_strwidth( $str, $encoding ); |
|
607 | +function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') { |
|
608 | + if (function_exists('mb_strwidth')) { |
|
609 | + return mb_strwidth($str, $encoding); |
|
610 | 610 | } |
611 | 611 | |
612 | - return wpinv_utf8_strlen( $str, $encoding ); |
|
612 | + return wpinv_utf8_strlen($str, $encoding); |
|
613 | 613 | } |
614 | 614 | |
615 | -function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) { |
|
616 | - if ( function_exists( 'mb_strlen' ) ) { |
|
617 | - $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding ); |
|
615 | +function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') { |
|
616 | + if (function_exists('mb_strlen')) { |
|
617 | + $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding); |
|
618 | 618 | $str_end = ""; |
619 | 619 | |
620 | - if ( $lower_str_end ) { |
|
621 | - $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding ); |
|
620 | + if ($lower_str_end) { |
|
621 | + $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding); |
|
622 | 622 | } else { |
623 | - $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
623 | + $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
624 | 624 | } |
625 | 625 | |
626 | 626 | return $first_letter . $str_end; |
627 | 627 | } |
628 | 628 | |
629 | - return ucfirst( $str ); |
|
629 | + return ucfirst($str); |
|
630 | 630 | } |
631 | 631 | |
632 | -function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) { |
|
633 | - if ( function_exists( 'mb_convert_case' ) ) { |
|
634 | - return mb_convert_case( $str, MB_CASE_TITLE, $encoding ); |
|
632 | +function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') { |
|
633 | + if (function_exists('mb_convert_case')) { |
|
634 | + return mb_convert_case($str, MB_CASE_TITLE, $encoding); |
|
635 | 635 | } |
636 | 636 | |
637 | - return ucwords( $str ); |
|
637 | + return ucwords($str); |
|
638 | 638 | } |
639 | 639 | |
640 | -function wpinv_period_in_days( $period, $unit ) { |
|
641 | - $period = absint( $period ); |
|
640 | +function wpinv_period_in_days($period, $unit) { |
|
641 | + $period = absint($period); |
|
642 | 642 | |
643 | - if ( $period > 0 ) { |
|
644 | - if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) { |
|
643 | + if ($period > 0) { |
|
644 | + if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) { |
|
645 | 645 | $period = $period * 7; |
646 | - } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) { |
|
646 | + } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) { |
|
647 | 647 | $period = $period * 30; |
648 | - } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) { |
|
648 | + } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) { |
|
649 | 649 | $period = $period * 365; |
650 | 650 | } |
651 | 651 | } |
@@ -653,14 +653,14 @@ discard block |
||
653 | 653 | return $period; |
654 | 654 | } |
655 | 655 | |
656 | -function wpinv_cal_days_in_month( $calendar, $month, $year ) { |
|
657 | - if ( function_exists( 'cal_days_in_month' ) ) { |
|
658 | - return cal_days_in_month( $calendar, $month, $year ); |
|
656 | +function wpinv_cal_days_in_month($calendar, $month, $year) { |
|
657 | + if (function_exists('cal_days_in_month')) { |
|
658 | + return cal_days_in_month($calendar, $month, $year); |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | // Fallback in case the calendar extension is not loaded in PHP |
662 | 662 | // Only supports Gregorian calendar |
663 | - return date( 't', mktime( 0, 0, 0, $month, 1, $year ) ); |
|
663 | + return date('t', mktime(0, 0, 0, $month, 1, $year)); |
|
664 | 664 | } |
665 | 665 | |
666 | 666 | /** |
@@ -671,12 +671,12 @@ discard block |
||
671 | 671 | * |
672 | 672 | * @return string |
673 | 673 | */ |
674 | -function wpi_help_tip( $tip, $allow_html = false ) { |
|
674 | +function wpi_help_tip($tip, $allow_html = false) { |
|
675 | 675 | |
676 | - if ( $allow_html ) { |
|
677 | - $tip = wpi_sanitize_tooltip( $tip ); |
|
676 | + if ($allow_html) { |
|
677 | + $tip = wpi_sanitize_tooltip($tip); |
|
678 | 678 | } else { |
679 | - $tip = esc_attr( $tip ); |
|
679 | + $tip = esc_attr($tip); |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
@@ -690,8 +690,8 @@ discard block |
||
690 | 690 | * @param string $var |
691 | 691 | * @return string |
692 | 692 | */ |
693 | -function wpi_sanitize_tooltip( $var ) { |
|
694 | - return wp_kses( html_entity_decode( $var ), array( |
|
693 | +function wpi_sanitize_tooltip($var) { |
|
694 | + return wp_kses(html_entity_decode($var), array( |
|
695 | 695 | 'br' => array(), |
696 | 696 | 'em' => array(), |
697 | 697 | 'strong' => array(), |
@@ -702,7 +702,7 @@ discard block |
||
702 | 702 | 'li' => array(), |
703 | 703 | 'ol' => array(), |
704 | 704 | 'p' => array(), |
705 | - ) ); |
|
705 | + )); |
|
706 | 706 | } |
707 | 707 | |
708 | 708 | /** |
@@ -712,7 +712,7 @@ discard block |
||
712 | 712 | */ |
713 | 713 | function wpinv_get_screen_ids() { |
714 | 714 | |
715 | - $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) ); |
|
715 | + $screen_id = sanitize_title(__('Invoicing', 'invoicing')); |
|
716 | 716 | |
717 | 717 | $screen_ids = array( |
718 | 718 | 'toplevel_page_' . $screen_id, |
@@ -731,10 +731,10 @@ discard block |
||
731 | 731 | 'getpaid_page_wpinv-reports', |
732 | 732 | 'getpaid_page_wpi-addons', |
733 | 733 | 'getpaid_page_wpinv-customers', |
734 | - 'gp-setup',// setup wizard |
|
734 | + 'gp-setup', // setup wizard |
|
735 | 735 | ); |
736 | 736 | |
737 | - return apply_filters( 'wpinv_screen_ids', $screen_ids ); |
|
737 | + return apply_filters('wpinv_screen_ids', $screen_ids); |
|
738 | 738 | } |
739 | 739 | |
740 | 740 | /** |
@@ -745,14 +745,14 @@ discard block |
||
745 | 745 | * @param array|string $list List of values. |
746 | 746 | * @return array Sanitized array of values. |
747 | 747 | */ |
748 | -function wpinv_parse_list( $list ) { |
|
748 | +function wpinv_parse_list($list) { |
|
749 | 749 | |
750 | - if ( empty( $list ) ) { |
|
750 | + if (empty($list)) { |
|
751 | 751 | $list = array(); |
752 | 752 | } |
753 | 753 | |
754 | - if ( ! is_array( $list ) ) { |
|
755 | - return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
754 | + if (!is_array($list)) { |
|
755 | + return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY); |
|
756 | 756 | } |
757 | 757 | |
758 | 758 | return $list; |
@@ -766,16 +766,16 @@ discard block |
||
766 | 766 | * @param string $key Type of data to fetch. |
767 | 767 | * @return mixed Fetched data. |
768 | 768 | */ |
769 | -function wpinv_get_data( $key ) { |
|
769 | +function wpinv_get_data($key) { |
|
770 | 770 | |
771 | 771 | // Try fetching it from the cache. |
772 | - $data = wp_cache_get( "wpinv-data-$key", 'wpinv' ); |
|
773 | - if( $data ) { |
|
772 | + $data = wp_cache_get("wpinv-data-$key", 'wpinv'); |
|
773 | + if ($data) { |
|
774 | 774 | return $data; |
775 | 775 | } |
776 | 776 | |
777 | - $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" ); |
|
778 | - wp_cache_set( "wpinv-data-$key", $data, 'wpinv' ); |
|
777 | + $data = apply_filters("wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php"); |
|
778 | + wp_cache_set("wpinv-data-$key", $data, 'wpinv'); |
|
779 | 779 | |
780 | 780 | return $data; |
781 | 781 | } |
@@ -789,10 +789,10 @@ discard block |
||
789 | 789 | * @param bool $first_empty Whether or not the first item in the list should be empty |
790 | 790 | * @return mixed Fetched data. |
791 | 791 | */ |
792 | -function wpinv_maybe_add_empty_option( $options, $first_empty ) { |
|
792 | +function wpinv_maybe_add_empty_option($options, $first_empty) { |
|
793 | 793 | |
794 | - if ( ! empty( $options ) && $first_empty ) { |
|
795 | - return array_merge( array( '' => '' ), $options ); |
|
794 | + if (!empty($options) && $first_empty) { |
|
795 | + return array_merge(array('' => ''), $options); |
|
796 | 796 | } |
797 | 797 | return $options; |
798 | 798 | |
@@ -804,21 +804,21 @@ discard block |
||
804 | 804 | * @param mixed $var Data to sanitize. |
805 | 805 | * @return string|array |
806 | 806 | */ |
807 | -function wpinv_clean( $var ) { |
|
807 | +function wpinv_clean($var) { |
|
808 | 808 | |
809 | - if ( is_array( $var ) ) { |
|
810 | - return array_map( 'wpinv_clean', $var ); |
|
809 | + if (is_array($var)) { |
|
810 | + return array_map('wpinv_clean', $var); |
|
811 | 811 | } |
812 | 812 | |
813 | - if ( is_object( $var ) ) { |
|
814 | - $object_vars = get_object_vars( $var ); |
|
815 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
816 | - $var->$property_name = wpinv_clean( $property_value ); |
|
813 | + if (is_object($var)) { |
|
814 | + $object_vars = get_object_vars($var); |
|
815 | + foreach ($object_vars as $property_name => $property_value) { |
|
816 | + $var->$property_name = wpinv_clean($property_value); |
|
817 | 817 | } |
818 | 818 | return $var; |
819 | 819 | } |
820 | 820 | |
821 | - return is_string( $var ) ? sanitize_text_field( stripslashes( $var ) ) : $var; |
|
821 | + return is_string($var) ? sanitize_text_field(stripslashes($var)) : $var; |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | /** |
@@ -827,43 +827,43 @@ discard block |
||
827 | 827 | * @param string $str Data to convert. |
828 | 828 | * @return string|array |
829 | 829 | */ |
830 | -function getpaid_convert_price_string_to_options( $str ) { |
|
830 | +function getpaid_convert_price_string_to_options($str) { |
|
831 | 831 | |
832 | - $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
833 | - $options = array(); |
|
832 | + $raw_options = array_map('trim', explode(',', $str)); |
|
833 | + $options = array(); |
|
834 | 834 | |
835 | - foreach ( $raw_options as $option ) { |
|
835 | + foreach ($raw_options as $option) { |
|
836 | 836 | |
837 | - if ( '' == $option ) { |
|
837 | + if ('' == $option) { |
|
838 | 838 | continue; |
839 | 839 | } |
840 | 840 | |
841 | - $option = array_map( 'trim', explode( '|', $option ) ); |
|
841 | + $option = array_map('trim', explode('|', $option)); |
|
842 | 842 | |
843 | 843 | $price = null; |
844 | 844 | $label = null; |
845 | 845 | |
846 | - if ( isset( $option[0] ) && '' != $option[0] ) { |
|
847 | - $label = $option[0]; |
|
846 | + if (isset($option[0]) && '' != $option[0]) { |
|
847 | + $label = $option[0]; |
|
848 | 848 | } |
849 | 849 | |
850 | - if ( isset( $option[1] ) && '' != $option[1] ) { |
|
850 | + if (isset($option[1]) && '' != $option[1]) { |
|
851 | 851 | $price = $option[1]; |
852 | 852 | } |
853 | 853 | |
854 | - if ( ! isset( $price ) ) { |
|
854 | + if (!isset($price)) { |
|
855 | 855 | $price = $label; |
856 | 856 | } |
857 | 857 | |
858 | - if ( ! isset( $price ) || ! is_numeric( $price ) ) { |
|
858 | + if (!isset($price) || !is_numeric($price)) { |
|
859 | 859 | continue; |
860 | 860 | } |
861 | 861 | |
862 | - if ( ! isset( $label ) ) { |
|
862 | + if (!isset($label)) { |
|
863 | 863 | $label = $price; |
864 | 864 | } |
865 | 865 | |
866 | - $options[ "$label|$price" ] = $label; |
|
866 | + $options["$label|$price"] = $label; |
|
867 | 867 | } |
868 | 868 | |
869 | 869 | return $options; |
@@ -872,27 +872,27 @@ discard block |
||
872 | 872 | /** |
873 | 873 | * Returns the help tip. |
874 | 874 | */ |
875 | -function getpaid_get_help_tip( $tip, $additional_classes = '' ) { |
|
876 | - $additional_classes = sanitize_html_class( $additional_classes ); |
|
877 | - $tip = esc_attr__( $tip ); |
|
875 | +function getpaid_get_help_tip($tip, $additional_classes = '') { |
|
876 | + $additional_classes = sanitize_html_class($additional_classes); |
|
877 | + $tip = esc_attr__($tip); |
|
878 | 878 | return "<span class='wpi-help-tip dashicons dashicons-editor-help $additional_classes' title='$tip'></span>"; |
879 | 879 | } |
880 | 880 | |
881 | 881 | /** |
882 | 882 | * Formats a date |
883 | 883 | */ |
884 | -function getpaid_format_date( $date, $with_time = false ) { |
|
884 | +function getpaid_format_date($date, $with_time = false) { |
|
885 | 885 | |
886 | - if ( empty( $date ) || $date == '0000-00-00 00:00:00' ) { |
|
886 | + if (empty($date) || $date == '0000-00-00 00:00:00') { |
|
887 | 887 | return ''; |
888 | 888 | } |
889 | 889 | |
890 | 890 | $format = getpaid_date_format(); |
891 | 891 | |
892 | - if ( $with_time ) { |
|
892 | + if ($with_time) { |
|
893 | 893 | $format .= ' ' . getpaid_time_format(); |
894 | 894 | } |
895 | - return date_i18n( $format, strtotime( $date ) ); |
|
895 | + return date_i18n($format, strtotime($date)); |
|
896 | 896 | |
897 | 897 | } |
898 | 898 | |
@@ -901,9 +901,9 @@ discard block |
||
901 | 901 | * |
902 | 902 | * @return string |
903 | 903 | */ |
904 | -function getpaid_format_date_value( $date, $default = "—", $with_time = false ) { |
|
905 | - $date = getpaid_format_date( $date, $with_time ); |
|
906 | - return empty( $date ) ? $default : $date; |
|
904 | +function getpaid_format_date_value($date, $default = "—", $with_time = false) { |
|
905 | + $date = getpaid_format_date($date, $with_time); |
|
906 | + return empty($date) ? $default : $date; |
|
907 | 907 | } |
908 | 908 | |
909 | 909 | /** |
@@ -912,7 +912,7 @@ discard block |
||
912 | 912 | * @return string |
913 | 913 | */ |
914 | 914 | function getpaid_date_format() { |
915 | - return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
915 | + return apply_filters('getpaid_date_format', get_option('date_format')); |
|
916 | 916 | } |
917 | 917 | |
918 | 918 | /** |
@@ -921,7 +921,7 @@ discard block |
||
921 | 921 | * @return string |
922 | 922 | */ |
923 | 923 | function getpaid_time_format() { |
924 | - return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
924 | + return apply_filters('getpaid_time_format', get_option('time_format')); |
|
925 | 925 | } |
926 | 926 | |
927 | 927 | /** |
@@ -931,16 +931,16 @@ discard block |
||
931 | 931 | * @param integer $limit Limit size in characters. |
932 | 932 | * @return string |
933 | 933 | */ |
934 | -function getpaid_limit_length( $string, $limit ) { |
|
934 | +function getpaid_limit_length($string, $limit) { |
|
935 | 935 | $str_limit = $limit - 3; |
936 | 936 | |
937 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
938 | - if ( mb_strlen( $string ) > $limit ) { |
|
939 | - $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
937 | + if (function_exists('mb_strimwidth')) { |
|
938 | + if (mb_strlen($string) > $limit) { |
|
939 | + $string = mb_strimwidth($string, 0, $str_limit) . '...'; |
|
940 | 940 | } |
941 | 941 | } else { |
942 | - if ( strlen( $string ) > $limit ) { |
|
943 | - $string = substr( $string, 0, $str_limit ) . '...'; |
|
942 | + if (strlen($string) > $limit) { |
|
943 | + $string = substr($string, 0, $str_limit) . '...'; |
|
944 | 944 | } |
945 | 945 | } |
946 | 946 | return $string; |
@@ -954,7 +954,7 @@ discard block |
||
954 | 954 | * @since 1.0.19 |
955 | 955 | */ |
956 | 956 | function getpaid_api() { |
957 | - return getpaid()->get( 'api' ); |
|
957 | + return getpaid()->get('api'); |
|
958 | 958 | } |
959 | 959 | |
960 | 960 | /** |
@@ -964,7 +964,7 @@ discard block |
||
964 | 964 | * @since 1.0.19 |
965 | 965 | */ |
966 | 966 | function getpaid_post_types() { |
967 | - return getpaid()->get( 'post_types' ); |
|
967 | + return getpaid()->get('post_types'); |
|
968 | 968 | } |
969 | 969 | |
970 | 970 | /** |
@@ -974,7 +974,7 @@ discard block |
||
974 | 974 | * @since 1.0.19 |
975 | 975 | */ |
976 | 976 | function getpaid_session() { |
977 | - return getpaid()->get( 'session' ); |
|
977 | + return getpaid()->get('session'); |
|
978 | 978 | } |
979 | 979 | |
980 | 980 | /** |
@@ -984,7 +984,7 @@ discard block |
||
984 | 984 | * @since 1.0.19 |
985 | 985 | */ |
986 | 986 | function getpaid_notes() { |
987 | - return getpaid()->get( 'notes' ); |
|
987 | + return getpaid()->get('notes'); |
|
988 | 988 | } |
989 | 989 | |
990 | 990 | /** |
@@ -993,7 +993,7 @@ discard block |
||
993 | 993 | * @return GetPaid_Admin |
994 | 994 | */ |
995 | 995 | function getpaid_admin() { |
996 | - return getpaid()->get( 'admin' ); |
|
996 | + return getpaid()->get('admin'); |
|
997 | 997 | } |
998 | 998 | |
999 | 999 | /** |
@@ -1003,8 +1003,8 @@ discard block |
||
1003 | 1003 | * @param string $base the base url |
1004 | 1004 | * @return string |
1005 | 1005 | */ |
1006 | -function getpaid_get_authenticated_action_url( $action, $base = false ) { |
|
1007 | - return wp_nonce_url( add_query_arg( 'getpaid-action', $action, $base ), 'getpaid-nonce', 'getpaid-nonce' ); |
|
1006 | +function getpaid_get_authenticated_action_url($action, $base = false) { |
|
1007 | + return wp_nonce_url(add_query_arg('getpaid-action', $action, $base), 'getpaid-nonce', 'getpaid-nonce'); |
|
1008 | 1008 | } |
1009 | 1009 | |
1010 | 1010 | /** |
@@ -1012,11 +1012,11 @@ discard block |
||
1012 | 1012 | * |
1013 | 1013 | * @return string |
1014 | 1014 | */ |
1015 | -function getpaid_get_post_type_label( $post_type, $plural = true ) { |
|
1015 | +function getpaid_get_post_type_label($post_type, $plural = true) { |
|
1016 | 1016 | |
1017 | - $post_type = get_post_type_object( $post_type ); |
|
1017 | + $post_type = get_post_type_object($post_type); |
|
1018 | 1018 | |
1019 | - if ( ! is_object( $post_type ) ) { |
|
1019 | + if (!is_object($post_type)) { |
|
1020 | 1020 | return null; |
1021 | 1021 | } |
1022 | 1022 | |
@@ -1029,18 +1029,18 @@ discard block |
||
1029 | 1029 | * |
1030 | 1030 | * @return mixed|null |
1031 | 1031 | */ |
1032 | -function getpaid_get_array_field( $array, $key, $secondary_key = null ) { |
|
1032 | +function getpaid_get_array_field($array, $key, $secondary_key = null) { |
|
1033 | 1033 | |
1034 | - if ( ! is_array( $array ) ) { |
|
1034 | + if (!is_array($array)) { |
|
1035 | 1035 | return null; |
1036 | 1036 | } |
1037 | 1037 | |
1038 | - if ( ! empty( $secondary_key ) ) { |
|
1039 | - $array = isset( $array[ $secondary_key ] ) ? $array[ $secondary_key ] : array(); |
|
1040 | - return getpaid_get_array_field( $array, $key ); |
|
1038 | + if (!empty($secondary_key)) { |
|
1039 | + $array = isset($array[$secondary_key]) ? $array[$secondary_key] : array(); |
|
1040 | + return getpaid_get_array_field($array, $key); |
|
1041 | 1041 | } |
1042 | 1042 | |
1043 | - return isset( $array[ $key ] ) ? $array[ $key ] : null; |
|
1043 | + return isset($array[$key]) ? $array[$key] : null; |
|
1044 | 1044 | |
1045 | 1045 | } |
1046 | 1046 | |
@@ -1049,12 +1049,12 @@ discard block |
||
1049 | 1049 | * |
1050 | 1050 | * @return array |
1051 | 1051 | */ |
1052 | -function getpaid_array_merge_if_empty( $args, $defaults ) { |
|
1052 | +function getpaid_array_merge_if_empty($args, $defaults) { |
|
1053 | 1053 | |
1054 | - foreach ( $defaults as $key => $value ) { |
|
1054 | + foreach ($defaults as $key => $value) { |
|
1055 | 1055 | |
1056 | - if ( array_key_exists( $key, $args ) && empty( $args[ $key ] ) ) { |
|
1057 | - $args[ $key ] = $value; |
|
1056 | + if (array_key_exists($key, $args) && empty($args[$key])) { |
|
1057 | + $args[$key] = $value; |
|
1058 | 1058 | } |
1059 | 1059 | |
1060 | 1060 | } |
@@ -7,116 +7,116 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | -do_action( 'getpaid_before_payment_form_cart_item', $form, $item ); |
|
12 | +do_action('getpaid_before_payment_form_cart_item', $form, $item); |
|
13 | 13 | |
14 | 14 | $currency = $form->get_currency(); |
15 | 15 | |
16 | 16 | ?> |
17 | -<div class='getpaid-payment-form-items-cart-item getpaid-<?php echo $item->is_required() ? 'required' : 'selectable'; ?> item-<?php echo $item->get_id(); ?> border-bottom py-2 px-3'> |
|
17 | +<div class='getpaid-payment-form-items-cart-item getpaid-<?php echo $item->is_required() ? 'required' : 'selectable'; ?> item-<?php echo $item->get_id(); ?> border-bottom py-2 px-3'> |
|
18 | 18 | |
19 | 19 | <div class="form-row needs-validation"> |
20 | 20 | |
21 | - <?php foreach ( array_keys( $columns ) as $key ) : ?> |
|
21 | + <?php foreach (array_keys($columns) as $key) : ?> |
|
22 | 22 | |
23 | - <div class="<?php echo 'name' == $key ? 'col-12 col-sm-6' : 'col-12 col-sm' ?> position-relative getpaid-form-cart-item-<?php echo sanitize_html_class( $key ); ?> getpaid-form-cart-item-<?php echo sanitize_html_class( $key ); ?>-<?php echo $item->get_id(); ?>"> |
|
23 | + <div class="<?php echo 'name' == $key ? 'col-12 col-sm-6' : 'col-12 col-sm' ?> position-relative getpaid-form-cart-item-<?php echo sanitize_html_class($key); ?> getpaid-form-cart-item-<?php echo sanitize_html_class($key); ?>-<?php echo $item->get_id(); ?>"> |
|
24 | 24 | |
25 | 25 | <?php |
26 | 26 | |
27 | 27 | // Fires before printing a line item column. |
28 | - do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
28 | + do_action("getpaid_form_cart_item_before_$key", $item, $form); |
|
29 | 29 | |
30 | 30 | // Item name. |
31 | - if ( 'name' == $key ) { |
|
31 | + if ('name' == $key) { |
|
32 | 32 | |
33 | 33 | // Display the name. |
34 | - echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>'; |
|
34 | + echo '<div class="mb-1">' . sanitize_text_field($item->get_name()) . '</div>'; |
|
35 | 35 | |
36 | 36 | // And an optional description. |
37 | 37 | $description = $item->get_description(); |
38 | 38 | |
39 | - if ( ! empty( $description ) ) { |
|
40 | - $description = wp_kses_post( $description ); |
|
39 | + if (!empty($description)) { |
|
40 | + $description = wp_kses_post($description); |
|
41 | 41 | echo "<small class='form-text text-muted pr-2 m-0'>$description</small>"; |
42 | 42 | } |
43 | 43 | |
44 | 44 | // Price help text. |
45 | - $description = getpaid_item_recurring_price_help_text( $item, $currency ); |
|
46 | - if ( $description ) { |
|
45 | + $description = getpaid_item_recurring_price_help_text($item, $currency); |
|
46 | + if ($description) { |
|
47 | 47 | echo "<small class='getpaid-form-item-price-desc form-text text-muted pr-2 m-0'>$description</small>"; |
48 | 48 | } |
49 | 49 | |
50 | 50 | } |
51 | 51 | |
52 | 52 | // Item price. |
53 | - if ( 'price' == $key ) { |
|
53 | + if ('price' == $key) { |
|
54 | 54 | |
55 | 55 | // Set the currency position. |
56 | 56 | $position = wpinv_currency_position(); |
57 | 57 | |
58 | - if ( $position == 'left_space' ) { |
|
58 | + if ($position == 'left_space') { |
|
59 | 59 | $position = 'left'; |
60 | 60 | } |
61 | 61 | |
62 | - if ( $position == 'right_space' ) { |
|
62 | + if ($position == 'right_space') { |
|
63 | 63 | $position = 'right'; |
64 | 64 | } |
65 | 65 | |
66 | - if ( $item->user_can_set_their_price() ) { |
|
67 | - $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
66 | + if ($item->user_can_set_their_price()) { |
|
67 | + $price = max((float) $item->get_price(), (float) $item->get_minimum_price()); |
|
68 | 68 | $minimum = (float) $item->get_minimum_price(); |
69 | 69 | $validate_minimum = ''; |
70 | 70 | $class = ''; |
71 | 71 | $data_minimum = ''; |
72 | 72 | |
73 | - if ( $minimum > 0 ) { |
|
73 | + if ($minimum > 0) { |
|
74 | 74 | $validate_minimum = sprintf( |
75 | - esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ), |
|
76 | - sanitize_text_field( wpinv_price( $minimum, $currency ) ) |
|
75 | + esc_attr__('The minimum allowed amount is %s', 'invoicing'), |
|
76 | + sanitize_text_field(wpinv_price($minimum, $currency)) |
|
77 | 77 | ); |
78 | 78 | |
79 | 79 | $class = 'getpaid-validate-minimum-amount'; |
80 | 80 | |
81 | - $data_minimum = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'"; |
|
81 | + $data_minimum = "data-minimum-amount='" . esc_attr(getpaid_unstandardize_amount($minimum)) . "'"; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | ?> |
85 | 85 | <div class="input-group input-group-sm"> |
86 | - <?php if( 'left' == $position ) : ?> |
|
86 | + <?php if ('left' == $position) : ?> |
|
87 | 87 | <div class="input-group-prepend"> |
88 | - <span class="input-group-text"><?php echo wpinv_currency_symbol( $currency ); ?></span> |
|
88 | + <span class="input-group-text"><?php echo wpinv_currency_symbol($currency); ?></span> |
|
89 | 89 | </div> |
90 | 90 | <?php endif; ?> |
91 | 91 | |
92 | - <input type="text" <?php echo $data_minimum; ?> name="getpaid-items[<?php echo (int) $item->get_id(); ?>][price]" value="<?php echo esc_attr( getpaid_unstandardize_amount( $price ) ); ?>" placeholder="<?php echo esc_attr( getpaid_unstandardize_amount( $item->get_minimum_price() ) ); ?>" class="getpaid-item-price-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border <?php echo $class; ?>" style="width: 64px; line-height: 1; min-height: 35px;"> |
|
92 | + <input type="text" <?php echo $data_minimum; ?> name="getpaid-items[<?php echo (int) $item->get_id(); ?>][price]" value="<?php echo esc_attr(getpaid_unstandardize_amount($price)); ?>" placeholder="<?php echo esc_attr(getpaid_unstandardize_amount($item->get_minimum_price())); ?>" class="getpaid-item-price-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border <?php echo $class; ?>" style="width: 64px; line-height: 1; min-height: 35px;"> |
|
93 | 93 | |
94 | - <?php if ( ! empty( $validate_minimum ) ) : ?> |
|
94 | + <?php if (!empty($validate_minimum)) : ?> |
|
95 | 95 | <div class="invalid-tooltip"> |
96 | 96 | <?php echo $validate_minimum; ?> |
97 | 97 | </div> |
98 | 98 | <?php endif; ?> |
99 | 99 | |
100 | - <?php if( 'left' != $position ) : ?> |
|
100 | + <?php if ('left' != $position) : ?> |
|
101 | 101 | <div class="input-group-append"> |
102 | - <span class="input-group-text"><?php echo wpinv_currency_symbol( $currency ); ?></span> |
|
102 | + <span class="input-group-text"><?php echo wpinv_currency_symbol($currency); ?></span> |
|
103 | 103 | </div> |
104 | 104 | <?php endif; ?> |
105 | 105 | </div> |
106 | 106 | |
107 | 107 | <?php |
108 | 108 | } else { |
109 | - echo wpinv_price( $item->get_price(), $currency ); |
|
109 | + echo wpinv_price($item->get_price(), $currency); |
|
110 | 110 | ?> |
111 | - <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr( $item->get_price() ); ?>'> |
|
111 | + <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr($item->get_price()); ?>'> |
|
112 | 112 | <?php |
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
116 | 116 | // Item quantity. |
117 | - if ( 'quantity' == $key ) { |
|
117 | + if ('quantity' == $key) { |
|
118 | 118 | |
119 | - if ( $item->allows_quantities() ) { |
|
119 | + if ($item->allows_quantities()) { |
|
120 | 120 | ?> |
121 | 121 | <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' type='text' style='width: 64px; line-height: 1; min-height: 35px;' class='getpaid-item-quantity-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border' value='<?php echo (float) $item->get_quantity(); ?>' min='1' required> |
122 | 122 | <?php |
@@ -130,11 +130,11 @@ discard block |
||
130 | 130 | } |
131 | 131 | |
132 | 132 | // Item sub total. |
133 | - if ( 'subtotal' == $key ) { |
|
134 | - echo wpinv_price( $item->get_sub_total(), $currency ); |
|
133 | + if ('subtotal' == $key) { |
|
134 | + echo wpinv_price($item->get_sub_total(), $currency); |
|
135 | 135 | } |
136 | 136 | |
137 | - do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
137 | + do_action("getpaid_payment_form_cart_item_$key", $item, $form); |
|
138 | 138 | ?> |
139 | 139 | |
140 | 140 | </div> |
@@ -145,4 +145,4 @@ discard block |
||
145 | 145 | |
146 | 146 | </div> |
147 | 147 | <?php |
148 | -do_action( 'getpaid_payment_form_cart_item', $form, $item ); |
|
148 | +do_action('getpaid_payment_form_cart_item', $form, $item); |
@@ -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 | * WPInv_Ajax class. |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | * Hook in ajax handlers. |
18 | 18 | */ |
19 | 19 | public static function init() { |
20 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
20 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
21 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
22 | 22 | self::add_ajax_events(); |
23 | 23 | } |
24 | 24 | |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public static function define_ajax() { |
29 | 29 | |
30 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | - getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | - getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
30 | + if (!empty($_GET['wpinv-ajax'])) { |
|
31 | + getpaid_maybe_define_constant('DOING_AJAX', true); |
|
32 | + getpaid_maybe_define_constant('WPInv_DOING_AJAX', true); |
|
33 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
34 | + /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0); |
|
35 | 35 | } |
36 | 36 | $GLOBALS['wpdb']->hide_errors(); |
37 | 37 | } |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | * @since 1.0.18 |
45 | 45 | */ |
46 | 46 | private static function wpinv_ajax_headers() { |
47 | - if ( ! headers_sent() ) { |
|
47 | + if (!headers_sent()) { |
|
48 | 48 | send_origin_headers(); |
49 | 49 | send_nosniff_header(); |
50 | 50 | nocache_headers(); |
51 | - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | - header( 'X-Robots-Tag: noindex' ); |
|
53 | - status_header( 200 ); |
|
51 | + header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
52 | + header('X-Robots-Tag: noindex'); |
|
53 | + status_header(200); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
@@ -60,16 +60,16 @@ discard block |
||
60 | 60 | public static function do_wpinv_ajax() { |
61 | 61 | global $wp_query; |
62 | 62 | |
63 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
63 | + if (!empty($_GET['wpinv-ajax'])) { |
|
64 | + $wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax']))); |
|
65 | 65 | } |
66 | 66 | |
67 | - $action = $wp_query->get( 'wpinv-ajax' ); |
|
67 | + $action = $wp_query->get('wpinv-ajax'); |
|
68 | 68 | |
69 | - if ( $action ) { |
|
69 | + if ($action) { |
|
70 | 70 | self::wpinv_ajax_headers(); |
71 | - $action = sanitize_text_field( $action ); |
|
72 | - do_action( 'wpinv_ajax_' . $action ); |
|
71 | + $action = sanitize_text_field($action); |
|
72 | + do_action('wpinv_ajax_' . $action); |
|
73 | 73 | wp_die(); |
74 | 74 | } |
75 | 75 | |
@@ -105,36 +105,36 @@ discard block |
||
105 | 105 | 'payment_form_refresh_prices' => true, |
106 | 106 | ); |
107 | 107 | |
108 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
109 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
110 | - add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
108 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
109 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
110 | + add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
111 | 111 | |
112 | - if ( $nopriv ) { |
|
113 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
114 | - add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
115 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
112 | + if ($nopriv) { |
|
113 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
114 | + add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
115 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | 120 | public static function add_note() { |
121 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
121 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
122 | 122 | |
123 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
123 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
124 | 124 | die(-1); |
125 | 125 | } |
126 | 126 | |
127 | - $post_id = absint( $_POST['post_id'] ); |
|
128 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
129 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
127 | + $post_id = absint($_POST['post_id']); |
|
128 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
129 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
130 | 130 | |
131 | 131 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
132 | 132 | |
133 | - if ( $post_id > 0 ) { |
|
134 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
133 | + if ($post_id > 0) { |
|
134 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
135 | 135 | |
136 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
137 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
136 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
137 | + wpinv_get_invoice_note_line_item($note_id); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
@@ -142,16 +142,16 @@ discard block |
||
142 | 142 | } |
143 | 143 | |
144 | 144 | public static function delete_note() { |
145 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
145 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
146 | 146 | |
147 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
147 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
148 | 148 | die(-1); |
149 | 149 | } |
150 | 150 | |
151 | - $note_id = (int)$_POST['note_id']; |
|
151 | + $note_id = (int) $_POST['note_id']; |
|
152 | 152 | |
153 | - if ( $note_id > 0 ) { |
|
154 | - wp_delete_comment( $note_id, true ); |
|
153 | + if ($note_id > 0) { |
|
154 | + wp_delete_comment($note_id, true); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | die(); |
@@ -169,34 +169,34 @@ discard block |
||
169 | 169 | public static function get_billing_details() { |
170 | 170 | |
171 | 171 | // Verify nonce. |
172 | - check_ajax_referer( 'wpinv-nonce' ); |
|
172 | + check_ajax_referer('wpinv-nonce'); |
|
173 | 173 | |
174 | 174 | // Can the user manage the plugin? |
175 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
175 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
176 | 176 | die(-1); |
177 | 177 | } |
178 | 178 | |
179 | 179 | // Do we have a user id? |
180 | 180 | $user_id = $_GET['user_id']; |
181 | 181 | |
182 | - if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
|
182 | + if (empty($user_id) || !is_numeric($user_id)) { |
|
183 | 183 | die(-1); |
184 | 184 | } |
185 | 185 | |
186 | 186 | // Fetch the billing details. |
187 | - $billing_details = wpinv_get_user_address( $user_id ); |
|
188 | - $billing_details = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id ); |
|
187 | + $billing_details = wpinv_get_user_address($user_id); |
|
188 | + $billing_details = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id); |
|
189 | 189 | |
190 | 190 | // unset the user id and email. |
191 | - $to_ignore = array( 'user_id', 'email' ); |
|
191 | + $to_ignore = array('user_id', 'email'); |
|
192 | 192 | |
193 | - foreach ( $to_ignore as $key ) { |
|
194 | - if ( isset( $billing_details[ $key ] ) ) { |
|
195 | - unset( $billing_details[ $key ] ); |
|
193 | + foreach ($to_ignore as $key) { |
|
194 | + if (isset($billing_details[$key])) { |
|
195 | + unset($billing_details[$key]); |
|
196 | 196 | } |
197 | 197 | } |
198 | 198 | |
199 | - wp_send_json_success( $billing_details ); |
|
199 | + wp_send_json_success($billing_details); |
|
200 | 200 | |
201 | 201 | } |
202 | 202 | |
@@ -206,47 +206,47 @@ discard block |
||
206 | 206 | public static function check_new_user_email() { |
207 | 207 | |
208 | 208 | // Verify nonce. |
209 | - check_ajax_referer( 'wpinv-nonce' ); |
|
209 | + check_ajax_referer('wpinv-nonce'); |
|
210 | 210 | |
211 | 211 | // Can the user manage the plugin? |
212 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
212 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
213 | 213 | die(-1); |
214 | 214 | } |
215 | 215 | |
216 | 216 | // We need an email address. |
217 | - if ( empty( $_GET['email'] ) ) { |
|
218 | - _e( "Provide the new user's email address", 'invoicing' ); |
|
217 | + if (empty($_GET['email'])) { |
|
218 | + _e("Provide the new user's email address", 'invoicing'); |
|
219 | 219 | exit; |
220 | 220 | } |
221 | 221 | |
222 | 222 | // Ensure the email is valid. |
223 | - $email = sanitize_text_field( $_GET['email'] ); |
|
224 | - if ( ! is_email( $email ) ) { |
|
225 | - _e( 'Invalid email address', 'invoicing' ); |
|
223 | + $email = sanitize_text_field($_GET['email']); |
|
224 | + if (!is_email($email)) { |
|
225 | + _e('Invalid email address', 'invoicing'); |
|
226 | 226 | exit; |
227 | 227 | } |
228 | 228 | |
229 | 229 | // And it does not exist. |
230 | - $id = email_exists( $email ); |
|
231 | - if ( $id ) { |
|
232 | - wp_send_json_success( compact( 'id' ) ); |
|
230 | + $id = email_exists($email); |
|
231 | + if ($id) { |
|
232 | + wp_send_json_success(compact('id')); |
|
233 | 233 | } |
234 | 234 | |
235 | - wp_send_json_success( true ); |
|
235 | + wp_send_json_success(true); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | public static function run_tool() { |
239 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
240 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
239 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
240 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
241 | 241 | die(-1); |
242 | 242 | } |
243 | 243 | |
244 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
244 | + $tool = sanitize_text_field($_POST['tool']); |
|
245 | 245 | |
246 | - do_action( 'wpinv_run_tool' ); |
|
246 | + do_action('wpinv_run_tool'); |
|
247 | 247 | |
248 | - if ( !empty( $tool ) ) { |
|
249 | - do_action( 'wpinv_tool_' . $tool ); |
|
248 | + if (!empty($tool)) { |
|
249 | + do_action('wpinv_tool_' . $tool); |
|
250 | 250 | } |
251 | 251 | } |
252 | 252 | |
@@ -256,27 +256,27 @@ discard block |
||
256 | 256 | public static function get_payment_form() { |
257 | 257 | |
258 | 258 | // Check nonce. |
259 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
259 | + check_ajax_referer('getpaid_form_nonce'); |
|
260 | 260 | |
261 | 261 | // Is the request set up correctly? |
262 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
262 | + if (empty($_GET['form']) && empty($_GET['item'])) { |
|
263 | 263 | echo aui()->alert( |
264 | 264 | array( |
265 | 265 | 'type' => 'warning', |
266 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
266 | + 'content' => __('No payment form or item provided', 'invoicing'), |
|
267 | 267 | ) |
268 | 268 | ); |
269 | 269 | exit; |
270 | 270 | } |
271 | 271 | |
272 | 272 | // Payment form or button? |
273 | - if ( ! empty( $_GET['form'] ) ) { |
|
274 | - getpaid_display_payment_form( urldecode( $_GET['form'] ) ); |
|
275 | - } else if( ! empty( $_GET['invoice'] ) ) { |
|
276 | - getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) ); |
|
273 | + if (!empty($_GET['form'])) { |
|
274 | + getpaid_display_payment_form(urldecode($_GET['form'])); |
|
275 | + } else if (!empty($_GET['invoice'])) { |
|
276 | + getpaid_display_invoice_payment_form(urldecode($_GET['invoice'])); |
|
277 | 277 | } else { |
278 | - $items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) ); |
|
279 | - getpaid_display_item_payment_form( $items ); |
|
278 | + $items = getpaid_convert_items_to_array(urldecode($_GET['item'])); |
|
279 | + getpaid_display_item_payment_form($items); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | exit; |
@@ -291,17 +291,17 @@ discard block |
||
291 | 291 | public static function payment_form() { |
292 | 292 | |
293 | 293 | // Check nonce. |
294 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
294 | + check_ajax_referer('getpaid_form_nonce'); |
|
295 | 295 | |
296 | 296 | // ... form fields... |
297 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
298 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
297 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
298 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
299 | 299 | exit; |
300 | 300 | } |
301 | 301 | |
302 | 302 | // Process the payment form. |
303 | - $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' ); |
|
304 | - $checkout = new $checkout_class( new GetPaid_Payment_Form_Submission() ); |
|
303 | + $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout'); |
|
304 | + $checkout = new $checkout_class(new GetPaid_Payment_Form_Submission()); |
|
305 | 305 | $checkout->process_checkout(); |
306 | 306 | |
307 | 307 | exit; |
@@ -314,55 +314,55 @@ discard block |
||
314 | 314 | */ |
315 | 315 | public static function get_payment_form_states_field() { |
316 | 316 | |
317 | - if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) { |
|
317 | + if (empty($_GET['country']) || empty($_GET['form'])) { |
|
318 | 318 | exit; |
319 | 319 | } |
320 | 320 | |
321 | - $elements = getpaid_get_payment_form_elements( $_GET['form'] ); |
|
321 | + $elements = getpaid_get_payment_form_elements($_GET['form']); |
|
322 | 322 | |
323 | - if ( empty( $elements ) ) { |
|
323 | + if (empty($elements)) { |
|
324 | 324 | exit; |
325 | 325 | } |
326 | 326 | |
327 | 327 | $address_fields = array(); |
328 | - foreach ( $elements as $element ) { |
|
329 | - if ( 'address' === $element['type'] ) { |
|
328 | + foreach ($elements as $element) { |
|
329 | + if ('address' === $element['type']) { |
|
330 | 330 | $address_fields = $element; |
331 | 331 | break; |
332 | 332 | } |
333 | 333 | } |
334 | 334 | |
335 | - if ( empty( $address_fields ) ) { |
|
335 | + if (empty($address_fields)) { |
|
336 | 336 | exit; |
337 | 337 | } |
338 | 338 | |
339 | - foreach ( $address_fields['fields'] as $address_field ) { |
|
339 | + foreach ($address_fields['fields'] as $address_field) { |
|
340 | 340 | |
341 | - if ( 'wpinv_state' == $address_field['name'] ) { |
|
341 | + if ('wpinv_state' == $address_field['name']) { |
|
342 | 342 | |
343 | - $wrap_class = getpaid_get_form_element_grid_class( $address_field ); |
|
344 | - $wrap_class = esc_attr( "$wrap_class getpaid-address-field-wrapper" ); |
|
345 | - $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] ); |
|
346 | - $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] ); |
|
347 | - $value = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : ''; |
|
348 | - $label = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] ); |
|
343 | + $wrap_class = getpaid_get_form_element_grid_class($address_field); |
|
344 | + $wrap_class = esc_attr("$wrap_class getpaid-address-field-wrapper"); |
|
345 | + $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']); |
|
346 | + $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']); |
|
347 | + $value = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : ''; |
|
348 | + $label = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']); |
|
349 | 349 | |
350 | - if ( ! empty( $address_field['required'] ) ) { |
|
350 | + if (!empty($address_field['required'])) { |
|
351 | 351 | $label .= "<span class='text-danger'> *</span>"; |
352 | 352 | } |
353 | 353 | |
354 | - $html = getpaid_get_states_select_markup ( |
|
355 | - sanitize_text_field( $_GET['country'] ), |
|
354 | + $html = getpaid_get_states_select_markup( |
|
355 | + sanitize_text_field($_GET['country']), |
|
356 | 356 | $value, |
357 | 357 | $placeholder, |
358 | 358 | $label, |
359 | 359 | $description, |
360 | - ! empty( $address_field['required'] ), |
|
360 | + !empty($address_field['required']), |
|
361 | 361 | $wrap_class, |
362 | - wpinv_clean( $_GET['name'] ) |
|
362 | + wpinv_clean($_GET['name']) |
|
363 | 363 | ); |
364 | 364 | |
365 | - wp_send_json_success( $html ); |
|
365 | + wp_send_json_success($html); |
|
366 | 366 | exit; |
367 | 367 | |
368 | 368 | } |
@@ -378,66 +378,66 @@ discard block |
||
378 | 378 | public static function recalculate_invoice_totals() { |
379 | 379 | |
380 | 380 | // Verify nonce. |
381 | - check_ajax_referer( 'wpinv-nonce' ); |
|
381 | + check_ajax_referer('wpinv-nonce'); |
|
382 | 382 | |
383 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
383 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
384 | 384 | exit; |
385 | 385 | } |
386 | 386 | |
387 | 387 | // We need an invoice. |
388 | - if ( empty( $_POST['post_id'] ) ) { |
|
388 | + if (empty($_POST['post_id'])) { |
|
389 | 389 | exit; |
390 | 390 | } |
391 | 391 | |
392 | 392 | // Fetch the invoice. |
393 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
393 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
394 | 394 | |
395 | 395 | // Ensure it exists. |
396 | - if ( ! $invoice->get_id() ) { |
|
396 | + if (!$invoice->get_id()) { |
|
397 | 397 | exit; |
398 | 398 | } |
399 | 399 | |
400 | 400 | // Maybe set the country, state, currency. |
401 | - foreach ( array( 'country', 'state', 'currency', 'vat_number', 'discount_code' ) as $key ) { |
|
402 | - if ( isset( $_POST[ $key ] ) ) { |
|
401 | + foreach (array('country', 'state', 'currency', 'vat_number', 'discount_code') as $key) { |
|
402 | + if (isset($_POST[$key])) { |
|
403 | 403 | $method = "set_$key"; |
404 | - $invoice->$method( sanitize_text_field( $_POST[ $key ] ) ); |
|
404 | + $invoice->$method(sanitize_text_field($_POST[$key])); |
|
405 | 405 | } |
406 | 406 | } |
407 | 407 | |
408 | 408 | // Maybe disable taxes. |
409 | - $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) ); |
|
409 | + $invoice->set_disable_taxes(!empty($_POST['taxes'])); |
|
410 | 410 | |
411 | 411 | // Discount code. |
412 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
413 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
414 | - if ( $discount->exists() ) { |
|
415 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
412 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
413 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
414 | + if ($discount->exists()) { |
|
415 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
416 | 416 | } else { |
417 | - $invoice->remove_discount( 'discount_code' ); |
|
417 | + $invoice->remove_discount('discount_code'); |
|
418 | 418 | } |
419 | 419 | } |
420 | 420 | |
421 | 421 | // Recalculate totals. |
422 | 422 | $invoice->recalculate_total(); |
423 | 423 | |
424 | - $total = wpinv_price( $invoice->get_total(), $invoice->get_currency() ); |
|
425 | - $suscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
426 | - if ( is_a( $suscriptions, 'WPInv_Subscription' ) && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) { |
|
427 | - $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() ); |
|
428 | - $total .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>'; |
|
424 | + $total = wpinv_price($invoice->get_total(), $invoice->get_currency()); |
|
425 | + $suscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
426 | + if (is_a($suscriptions, 'WPInv_Subscription') && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) { |
|
427 | + $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency()); |
|
428 | + $total .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>'; |
|
429 | 429 | } |
430 | 430 | |
431 | 431 | $totals = array( |
432 | - 'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ), |
|
433 | - 'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
|
434 | - 'tax' => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ), |
|
432 | + 'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()), |
|
433 | + 'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()), |
|
434 | + 'tax' => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()), |
|
435 | 435 | 'total' => $total, |
436 | 436 | ); |
437 | 437 | |
438 | - $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice ); |
|
438 | + $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice); |
|
439 | 439 | |
440 | - wp_send_json_success( compact( 'totals' ) ); |
|
440 | + wp_send_json_success(compact('totals')); |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | /** |
@@ -446,33 +446,33 @@ discard block |
||
446 | 446 | public static function get_invoice_items() { |
447 | 447 | |
448 | 448 | // Verify nonce. |
449 | - check_ajax_referer( 'wpinv-nonce' ); |
|
449 | + check_ajax_referer('wpinv-nonce'); |
|
450 | 450 | |
451 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
451 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
452 | 452 | exit; |
453 | 453 | } |
454 | 454 | |
455 | 455 | // We need an invoice and items. |
456 | - if ( empty( $_POST['post_id'] ) ) { |
|
456 | + if (empty($_POST['post_id'])) { |
|
457 | 457 | exit; |
458 | 458 | } |
459 | 459 | |
460 | 460 | // Fetch the invoice. |
461 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
461 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
462 | 462 | |
463 | 463 | // Ensure it exists. |
464 | - if ( ! $invoice->get_id() ) { |
|
464 | + if (!$invoice->get_id()) { |
|
465 | 465 | exit; |
466 | 466 | } |
467 | 467 | |
468 | 468 | // Return an array of invoice items. |
469 | 469 | $items = array(); |
470 | 470 | |
471 | - foreach ( $invoice->get_items() as $item ) { |
|
472 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency(), $invoice->is_renewal() ); |
|
471 | + foreach ($invoice->get_items() as $item) { |
|
472 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency(), $invoice->is_renewal()); |
|
473 | 473 | } |
474 | 474 | |
475 | - wp_send_json_success( compact( 'items' ) ); |
|
475 | + wp_send_json_success(compact('items')); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | /** |
@@ -481,50 +481,50 @@ discard block |
||
481 | 481 | public static function edit_invoice_item() { |
482 | 482 | |
483 | 483 | // Verify nonce. |
484 | - check_ajax_referer( 'wpinv-nonce' ); |
|
484 | + check_ajax_referer('wpinv-nonce'); |
|
485 | 485 | |
486 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
486 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
487 | 487 | exit; |
488 | 488 | } |
489 | 489 | |
490 | 490 | // We need an invoice and item details. |
491 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) { |
|
491 | + if (empty($_POST['post_id']) || empty($_POST['data'])) { |
|
492 | 492 | exit; |
493 | 493 | } |
494 | 494 | |
495 | 495 | // Fetch the invoice. |
496 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
496 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
497 | 497 | |
498 | 498 | // Ensure it exists and its not been paid for. |
499 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
499 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
500 | 500 | exit; |
501 | 501 | } |
502 | 502 | |
503 | 503 | // Format the data. |
504 | - $data = wp_unslash( wp_list_pluck( $_POST['data'], 'value', 'field' ) ); |
|
504 | + $data = wp_unslash(wp_list_pluck($_POST['data'], 'value', 'field')); |
|
505 | 505 | |
506 | 506 | // Ensure that we have an item id. |
507 | - if ( empty( $data['id'] ) ) { |
|
507 | + if (empty($data['id'])) { |
|
508 | 508 | exit; |
509 | 509 | } |
510 | 510 | |
511 | 511 | // Abort if the invoice does not have the specified item. |
512 | - $item = $invoice->get_item( (int) $data['id'] ); |
|
512 | + $item = $invoice->get_item((int) $data['id']); |
|
513 | 513 | |
514 | - if ( empty( $item ) ) { |
|
514 | + if (empty($item)) { |
|
515 | 515 | exit; |
516 | 516 | } |
517 | 517 | |
518 | 518 | // Update the item. |
519 | - $item->set_price( getpaid_standardize_amount( $data['price'] ) ); |
|
520 | - $item->set_name( sanitize_text_field( $data['name'] ) ); |
|
521 | - $item->set_description( wp_kses_post( $data['description'] ) ); |
|
522 | - $item->set_quantity( floatval( $data['quantity'] ) ); |
|
519 | + $item->set_price(getpaid_standardize_amount($data['price'])); |
|
520 | + $item->set_name(sanitize_text_field($data['name'])); |
|
521 | + $item->set_description(wp_kses_post($data['description'])); |
|
522 | + $item->set_quantity(floatval($data['quantity'])); |
|
523 | 523 | |
524 | 524 | // Add it to the invoice. |
525 | - $error = $invoice->add_item( $item ); |
|
525 | + $error = $invoice->add_item($item); |
|
526 | 526 | $alert = false; |
527 | - if ( is_wp_error( $error ) ) { |
|
527 | + if (is_wp_error($error)) { |
|
528 | 528 | $alert = $error->get_error_message(); |
529 | 529 | } |
530 | 530 | |
@@ -537,11 +537,11 @@ discard block |
||
537 | 537 | // Return an array of invoice items. |
538 | 538 | $items = array(); |
539 | 539 | |
540 | - foreach ( $invoice->get_items() as $item ) { |
|
541 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
540 | + foreach ($invoice->get_items() as $item) { |
|
541 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
542 | 542 | } |
543 | 543 | |
544 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
544 | + wp_send_json_success(compact('items', 'alert')); |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | /** |
@@ -550,53 +550,53 @@ discard block |
||
550 | 550 | public static function create_invoice_item() { |
551 | 551 | |
552 | 552 | // Verify nonce. |
553 | - check_ajax_referer( 'wpinv-nonce' ); |
|
553 | + check_ajax_referer('wpinv-nonce'); |
|
554 | 554 | |
555 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
555 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
556 | 556 | exit; |
557 | 557 | } |
558 | 558 | |
559 | 559 | // We need an invoice and item details. |
560 | - if ( empty( $_POST['invoice_id'] ) || empty( $_POST['_wpinv_quick'] ) ) { |
|
560 | + if (empty($_POST['invoice_id']) || empty($_POST['_wpinv_quick'])) { |
|
561 | 561 | exit; |
562 | 562 | } |
563 | 563 | |
564 | 564 | // Fetch the invoice. |
565 | - $invoice = new WPInv_Invoice( trim( $_POST['invoice_id'] ) ); |
|
565 | + $invoice = new WPInv_Invoice(trim($_POST['invoice_id'])); |
|
566 | 566 | |
567 | 567 | // Ensure it exists and its not been paid for. |
568 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
568 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
569 | 569 | exit; |
570 | 570 | } |
571 | 571 | |
572 | 572 | // Format the data. |
573 | - $data = wp_unslash( $_POST['_wpinv_quick'] ); |
|
573 | + $data = wp_unslash($_POST['_wpinv_quick']); |
|
574 | 574 | |
575 | 575 | $item = new WPInv_Item(); |
576 | - $item->set_price( getpaid_standardize_amount( $data['price'] ) ); |
|
577 | - $item->set_name( sanitize_text_field( $data['name'] ) ); |
|
578 | - $item->set_description( wp_kses_post( $data['description'] ) ); |
|
579 | - $item->set_type( sanitize_text_field( $data['type'] ) ); |
|
580 | - $item->set_vat_rule( sanitize_text_field( $data['vat_rule'] ) ); |
|
581 | - $item->set_vat_class( sanitize_text_field( $data['vat_class'] ) ); |
|
582 | - $item->set_status( 'publish' ); |
|
576 | + $item->set_price(getpaid_standardize_amount($data['price'])); |
|
577 | + $item->set_name(sanitize_text_field($data['name'])); |
|
578 | + $item->set_description(wp_kses_post($data['description'])); |
|
579 | + $item->set_type(sanitize_text_field($data['type'])); |
|
580 | + $item->set_vat_rule(sanitize_text_field($data['vat_rule'])); |
|
581 | + $item->set_vat_class(sanitize_text_field($data['vat_class'])); |
|
582 | + $item->set_status('publish'); |
|
583 | 583 | $item->save(); |
584 | 584 | |
585 | - if ( ! $item->exists() ) { |
|
586 | - $alert = __( 'Could not create invoice item. Please try again.', 'invoicing' ); |
|
587 | - wp_send_json_success( compact( 'alert' ) ); |
|
585 | + if (!$item->exists()) { |
|
586 | + $alert = __('Could not create invoice item. Please try again.', 'invoicing'); |
|
587 | + wp_send_json_success(compact('alert')); |
|
588 | 588 | } |
589 | 589 | |
590 | - $item = new GetPaid_Form_Item( $item->get_id() ); |
|
591 | - $item->set_quantity( floatval( $data['qty'] ) ); |
|
590 | + $item = new GetPaid_Form_Item($item->get_id()); |
|
591 | + $item->set_quantity(floatval($data['qty'])); |
|
592 | 592 | |
593 | 593 | // Add it to the invoice. |
594 | - $error = $invoice->add_item( $item ); |
|
594 | + $error = $invoice->add_item($item); |
|
595 | 595 | $alert = false; |
596 | 596 | |
597 | - if ( is_wp_error( $error ) ) { |
|
597 | + if (is_wp_error($error)) { |
|
598 | 598 | $alert = $error->get_error_message(); |
599 | - wp_send_json_success( compact( 'alert' ) ); |
|
599 | + wp_send_json_success(compact('alert')); |
|
600 | 600 | } |
601 | 601 | |
602 | 602 | // Update totals. |
@@ -609,9 +609,9 @@ discard block |
||
609 | 609 | $invoice->recalculate_total(); |
610 | 610 | $invoice->save(); |
611 | 611 | ob_start(); |
612 | - GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice ); |
|
612 | + GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice); |
|
613 | 613 | $row = ob_get_clean(); |
614 | - wp_send_json_success( compact( 'row' ) ); |
|
614 | + wp_send_json_success(compact('row')); |
|
615 | 615 | } |
616 | 616 | |
617 | 617 | /** |
@@ -620,33 +620,33 @@ discard block |
||
620 | 620 | public static function remove_invoice_item() { |
621 | 621 | |
622 | 622 | // Verify nonce. |
623 | - check_ajax_referer( 'wpinv-nonce' ); |
|
623 | + check_ajax_referer('wpinv-nonce'); |
|
624 | 624 | |
625 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
625 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
626 | 626 | exit; |
627 | 627 | } |
628 | 628 | |
629 | 629 | // We need an invoice and an item. |
630 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
630 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
631 | 631 | exit; |
632 | 632 | } |
633 | 633 | |
634 | 634 | // Fetch the invoice. |
635 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
635 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
636 | 636 | |
637 | 637 | // Ensure it exists and its not been paid for. |
638 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
638 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
639 | 639 | exit; |
640 | 640 | } |
641 | 641 | |
642 | 642 | // Abort if the invoice does not have the specified item. |
643 | - $item = $invoice->get_item( (int) $_POST['item_id'] ); |
|
643 | + $item = $invoice->get_item((int) $_POST['item_id']); |
|
644 | 644 | |
645 | - if ( empty( $item ) ) { |
|
645 | + if (empty($item)) { |
|
646 | 646 | exit; |
647 | 647 | } |
648 | 648 | |
649 | - $invoice->remove_item( (int) $_POST['item_id'] ); |
|
649 | + $invoice->remove_item((int) $_POST['item_id']); |
|
650 | 650 | |
651 | 651 | // Update totals. |
652 | 652 | $invoice->recalculate_total(); |
@@ -657,11 +657,11 @@ discard block |
||
657 | 657 | // Return an array of invoice items. |
658 | 658 | $items = array(); |
659 | 659 | |
660 | - foreach ( $invoice->get_items() as $item ) { |
|
661 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
660 | + foreach ($invoice->get_items() as $item) { |
|
661 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
662 | 662 | } |
663 | 663 | |
664 | - wp_send_json_success( compact( 'items' ) ); |
|
664 | + wp_send_json_success(compact('items')); |
|
665 | 665 | } |
666 | 666 | |
667 | 667 | /** |
@@ -670,69 +670,69 @@ discard block |
||
670 | 670 | public static function recalculate_full_prices() { |
671 | 671 | |
672 | 672 | // Verify nonce. |
673 | - check_ajax_referer( 'wpinv-nonce' ); |
|
673 | + check_ajax_referer('wpinv-nonce'); |
|
674 | 674 | |
675 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
675 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
676 | 676 | exit; |
677 | 677 | } |
678 | 678 | |
679 | 679 | // We need an invoice and item. |
680 | - if ( empty( $_POST['post_id'] ) ) { |
|
680 | + if (empty($_POST['post_id'])) { |
|
681 | 681 | exit; |
682 | 682 | } |
683 | 683 | |
684 | 684 | // Fetch the invoice. |
685 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
685 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
686 | 686 | $alert = false; |
687 | 687 | |
688 | 688 | // Ensure it exists and its not been paid for. |
689 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
689 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
690 | 690 | exit; |
691 | 691 | } |
692 | 692 | |
693 | - $invoice->set_items( array() ); |
|
693 | + $invoice->set_items(array()); |
|
694 | 694 | |
695 | - if ( ! empty( $_POST['getpaid_items'] ) ) { |
|
695 | + if (!empty($_POST['getpaid_items'])) { |
|
696 | 696 | |
697 | - foreach ( $_POST['getpaid_items'] as $item_id => $args ) { |
|
698 | - $item = new GetPaid_Form_Item( $item_id ); |
|
697 | + foreach ($_POST['getpaid_items'] as $item_id => $args) { |
|
698 | + $item = new GetPaid_Form_Item($item_id); |
|
699 | 699 | |
700 | - if ( $item->exists() ) { |
|
701 | - $item->set_price( getpaid_standardize_amount( $args['price'] ) ); |
|
702 | - $item->set_quantity( floatval( $args['quantity'] ) ); |
|
703 | - $item->set_name( sanitize_text_field( $args['name'] ) ); |
|
704 | - $item->set_description( wp_kses_post( $args['description'] ) ); |
|
705 | - $invoice->add_item( $item ); |
|
700 | + if ($item->exists()) { |
|
701 | + $item->set_price(getpaid_standardize_amount($args['price'])); |
|
702 | + $item->set_quantity(floatval($args['quantity'])); |
|
703 | + $item->set_name(sanitize_text_field($args['name'])); |
|
704 | + $item->set_description(wp_kses_post($args['description'])); |
|
705 | + $invoice->add_item($item); |
|
706 | 706 | } |
707 | 707 | } |
708 | 708 | |
709 | 709 | } |
710 | 710 | |
711 | - $invoice->set_disable_taxes( ! empty( $_POST['disable_taxes'] ) ); |
|
711 | + $invoice->set_disable_taxes(!empty($_POST['disable_taxes'])); |
|
712 | 712 | |
713 | 713 | // Maybe set the country, state, currency. |
714 | - foreach ( array( 'wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code' ) as $key ) { |
|
715 | - if ( isset( $_POST[ $key ] ) ) { |
|
716 | - $_key = str_replace( 'wpinv_', '', $key ); |
|
714 | + foreach (array('wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code') as $key) { |
|
715 | + if (isset($_POST[$key])) { |
|
716 | + $_key = str_replace('wpinv_', '', $key); |
|
717 | 717 | $method = "set_$_key"; |
718 | - $invoice->$method( sanitize_text_field( $_POST[ $key ] ) ); |
|
718 | + $invoice->$method(sanitize_text_field($_POST[$key])); |
|
719 | 719 | } |
720 | 720 | } |
721 | 721 | |
722 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
723 | - if ( $discount->exists() ) { |
|
724 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
722 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
723 | + if ($discount->exists()) { |
|
724 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
725 | 725 | } else { |
726 | - $invoice->remove_discount( 'discount_code' ); |
|
726 | + $invoice->remove_discount('discount_code'); |
|
727 | 727 | } |
728 | 728 | |
729 | 729 | // Save the invoice. |
730 | 730 | $invoice->recalculate_total(); |
731 | 731 | $invoice->save(); |
732 | 732 | ob_start(); |
733 | - GetPaid_Meta_Box_Invoice_Items::output( get_post( $invoice->get_id() ), $invoice ); |
|
733 | + GetPaid_Meta_Box_Invoice_Items::output(get_post($invoice->get_id()), $invoice); |
|
734 | 734 | $table = ob_get_clean(); |
735 | - wp_send_json_success( compact( 'table' ) ); |
|
735 | + wp_send_json_success(compact('table')); |
|
736 | 736 | } |
737 | 737 | |
738 | 738 | /** |
@@ -741,42 +741,42 @@ discard block |
||
741 | 741 | public static function admin_add_invoice_item() { |
742 | 742 | |
743 | 743 | // Verify nonce. |
744 | - check_ajax_referer( 'wpinv-nonce' ); |
|
744 | + check_ajax_referer('wpinv-nonce'); |
|
745 | 745 | |
746 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
746 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
747 | 747 | exit; |
748 | 748 | } |
749 | 749 | |
750 | 750 | // We need an invoice and item. |
751 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
751 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
752 | 752 | exit; |
753 | 753 | } |
754 | 754 | |
755 | 755 | // Fetch the invoice. |
756 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
756 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
757 | 757 | $alert = false; |
758 | 758 | |
759 | 759 | // Ensure it exists and its not been paid for. |
760 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
760 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
761 | 761 | exit; |
762 | 762 | } |
763 | 763 | |
764 | 764 | // Add the item. |
765 | - $item = new GetPaid_Form_Item( (int) $_POST['item_id'] ); |
|
766 | - $error = $invoice->add_item( $item ); |
|
765 | + $item = new GetPaid_Form_Item((int) $_POST['item_id']); |
|
766 | + $error = $invoice->add_item($item); |
|
767 | 767 | |
768 | - if ( is_wp_error( $error ) ) { |
|
768 | + if (is_wp_error($error)) { |
|
769 | 769 | $alert = $error->get_error_message(); |
770 | - wp_send_json_success( compact( 'alert' ) ); |
|
770 | + wp_send_json_success(compact('alert')); |
|
771 | 771 | } |
772 | 772 | |
773 | 773 | // Save the invoice. |
774 | 774 | $invoice->recalculate_total(); |
775 | 775 | $invoice->save(); |
776 | 776 | ob_start(); |
777 | - GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice ); |
|
777 | + GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice); |
|
778 | 778 | $row = ob_get_clean(); |
779 | - wp_send_json_success( compact( 'row' ) ); |
|
779 | + wp_send_json_success(compact('row')); |
|
780 | 780 | } |
781 | 781 | |
782 | 782 | /** |
@@ -785,39 +785,39 @@ discard block |
||
785 | 785 | public static function add_invoice_items() { |
786 | 786 | |
787 | 787 | // Verify nonce. |
788 | - check_ajax_referer( 'wpinv-nonce' ); |
|
788 | + check_ajax_referer('wpinv-nonce'); |
|
789 | 789 | |
790 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
790 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
791 | 791 | exit; |
792 | 792 | } |
793 | 793 | |
794 | 794 | // We need an invoice and items. |
795 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) { |
|
795 | + if (empty($_POST['post_id']) || empty($_POST['items'])) { |
|
796 | 796 | exit; |
797 | 797 | } |
798 | 798 | |
799 | 799 | // Fetch the invoice. |
800 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
800 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
801 | 801 | $alert = false; |
802 | 802 | |
803 | 803 | // Ensure it exists and its not been paid for. |
804 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
804 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
805 | 805 | exit; |
806 | 806 | } |
807 | 807 | |
808 | 808 | // Add the items. |
809 | - foreach ( $_POST['items'] as $data ) { |
|
809 | + foreach ($_POST['items'] as $data) { |
|
810 | 810 | |
811 | - $item = new GetPaid_Form_Item( $data[ 'id' ] ); |
|
811 | + $item = new GetPaid_Form_Item($data['id']); |
|
812 | 812 | |
813 | - if ( is_numeric( $data[ 'qty' ] ) && (float) $data[ 'qty' ] > 0 ) { |
|
814 | - $item->set_quantity( $data[ 'qty' ] ); |
|
813 | + if (is_numeric($data['qty']) && (float) $data['qty'] > 0) { |
|
814 | + $item->set_quantity($data['qty']); |
|
815 | 815 | } |
816 | 816 | |
817 | - if ( $item->get_id() > 0 ) { |
|
818 | - $error = $invoice->add_item( $item ); |
|
817 | + if ($item->get_id() > 0) { |
|
818 | + $error = $invoice->add_item($item); |
|
819 | 819 | |
820 | - if ( is_wp_error( $error ) ) { |
|
820 | + if (is_wp_error($error)) { |
|
821 | 821 | $alert = $error->get_error_message(); |
822 | 822 | } |
823 | 823 | |
@@ -832,11 +832,11 @@ discard block |
||
832 | 832 | // Return an array of invoice items. |
833 | 833 | $items = array(); |
834 | 834 | |
835 | - foreach ( $invoice->get_items() as $item ) { |
|
836 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
835 | + foreach ($invoice->get_items() as $item) { |
|
836 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
837 | 837 | } |
838 | 838 | |
839 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
839 | + wp_send_json_success(compact('items', 'alert')); |
|
840 | 840 | } |
841 | 841 | |
842 | 842 | /** |
@@ -845,15 +845,15 @@ discard block |
||
845 | 845 | public static function get_invoicing_items() { |
846 | 846 | |
847 | 847 | // Verify nonce. |
848 | - check_ajax_referer( 'wpinv-nonce' ); |
|
848 | + check_ajax_referer('wpinv-nonce'); |
|
849 | 849 | |
850 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
850 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
851 | 851 | exit; |
852 | 852 | } |
853 | 853 | |
854 | 854 | // We need a search term. |
855 | - if ( empty( $_GET['search'] ) ) { |
|
856 | - wp_send_json_success( array() ); |
|
855 | + if (empty($_GET['search'])) { |
|
856 | + wp_send_json_success(array()); |
|
857 | 857 | } |
858 | 858 | |
859 | 859 | // Retrieve items. |
@@ -862,8 +862,8 @@ discard block |
||
862 | 862 | 'orderby' => 'title', |
863 | 863 | 'order' => 'ASC', |
864 | 864 | 'posts_per_page' => -1, |
865 | - 'post_status' => array( 'publish' ), |
|
866 | - 's' => trim( $_GET['search'] ), |
|
865 | + 'post_status' => array('publish'), |
|
866 | + 's' => trim($_GET['search']), |
|
867 | 867 | 'meta_query' => array( |
868 | 868 | array( |
869 | 869 | 'key' => '_wpinv_type', |
@@ -873,21 +873,21 @@ discard block |
||
873 | 873 | ) |
874 | 874 | ); |
875 | 875 | |
876 | - $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) ); |
|
876 | + $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args)); |
|
877 | 877 | $data = array(); |
878 | 878 | |
879 | - $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) ); |
|
879 | + $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id'])); |
|
880 | 880 | |
881 | - foreach ( $items as $item ) { |
|
882 | - $item = new GetPaid_Form_Item( $item ); |
|
881 | + foreach ($items as $item) { |
|
882 | + $item = new GetPaid_Form_Item($item); |
|
883 | 883 | $data[] = array( |
884 | 884 | 'id' => (int) $item->get_id(), |
885 | - 'text' => strip_tags( $item->get_name() ), |
|
886 | - 'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '', |
|
885 | + 'text' => strip_tags($item->get_name()), |
|
886 | + 'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '', |
|
887 | 887 | ); |
888 | 888 | } |
889 | 889 | |
890 | - wp_send_json_success( $data ); |
|
890 | + wp_send_json_success($data); |
|
891 | 891 | |
892 | 892 | } |
893 | 893 | |
@@ -897,37 +897,37 @@ discard block |
||
897 | 897 | public static function get_customers() { |
898 | 898 | |
899 | 899 | // Verify nonce. |
900 | - check_ajax_referer( 'wpinv-nonce' ); |
|
900 | + check_ajax_referer('wpinv-nonce'); |
|
901 | 901 | |
902 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
902 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
903 | 903 | exit; |
904 | 904 | } |
905 | 905 | |
906 | 906 | // We need a search term. |
907 | - if ( empty( $_GET['search'] ) ) { |
|
908 | - wp_send_json_success( array() ); |
|
907 | + if (empty($_GET['search'])) { |
|
908 | + wp_send_json_success(array()); |
|
909 | 909 | } |
910 | 910 | |
911 | 911 | // Retrieve customers. |
912 | 912 | |
913 | 913 | $customer_args = array( |
914 | - 'fields' => array( 'ID', 'user_email', 'display_name' ), |
|
914 | + 'fields' => array('ID', 'user_email', 'display_name'), |
|
915 | 915 | 'orderby' => 'display_name', |
916 | - 'search' => '*' . sanitize_text_field( $_GET['search'] ) . '*', |
|
917 | - 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
916 | + 'search' => '*' . sanitize_text_field($_GET['search']) . '*', |
|
917 | + 'search_columns' => array('user_login', 'user_email', 'display_name'), |
|
918 | 918 | ); |
919 | 919 | |
920 | - $customers = get_users( apply_filters( 'getpaid_ajax_invoice_customers_query_args', $customer_args ) ); |
|
920 | + $customers = get_users(apply_filters('getpaid_ajax_invoice_customers_query_args', $customer_args)); |
|
921 | 921 | $data = array(); |
922 | 922 | |
923 | - foreach ( $customers as $customer ) { |
|
923 | + foreach ($customers as $customer) { |
|
924 | 924 | $data[] = array( |
925 | 925 | 'id' => (int) $customer->ID, |
926 | - 'text' => strip_tags( sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ) ), |
|
926 | + 'text' => strip_tags(sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email)), |
|
927 | 927 | ); |
928 | 928 | } |
929 | 929 | |
930 | - wp_send_json_success( $data ); |
|
930 | + wp_send_json_success($data); |
|
931 | 931 | |
932 | 932 | } |
933 | 933 | |
@@ -937,28 +937,28 @@ discard block |
||
937 | 937 | public static function get_aui_states_field() { |
938 | 938 | |
939 | 939 | // Verify nonce. |
940 | - check_ajax_referer( 'wpinv-nonce' ); |
|
940 | + check_ajax_referer('wpinv-nonce'); |
|
941 | 941 | |
942 | 942 | // We need a country. |
943 | - if ( empty( $_GET['country'] ) ) { |
|
943 | + if (empty($_GET['country'])) { |
|
944 | 944 | exit; |
945 | 945 | } |
946 | 946 | |
947 | - $states = wpinv_get_country_states( sanitize_text_field( $_GET['country'] ) ); |
|
948 | - $state = isset( $_GET['state'] ) ? sanitize_text_field( $_GET['state'] ) : wpinv_get_default_state(); |
|
949 | - $name = isset( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : 'wpinv_state'; |
|
950 | - $class = isset( $_GET['class'] ) ? sanitize_text_field( $_GET['class'] ) : 'form-control-sm'; |
|
947 | + $states = wpinv_get_country_states(sanitize_text_field($_GET['country'])); |
|
948 | + $state = isset($_GET['state']) ? sanitize_text_field($_GET['state']) : wpinv_get_default_state(); |
|
949 | + $name = isset($_GET['name']) ? sanitize_text_field($_GET['name']) : 'wpinv_state'; |
|
950 | + $class = isset($_GET['class']) ? sanitize_text_field($_GET['class']) : 'form-control-sm'; |
|
951 | 951 | |
952 | - if ( empty( $states ) ) { |
|
952 | + if (empty($states)) { |
|
953 | 953 | |
954 | 954 | $html = aui()->input( |
955 | 955 | array( |
956 | 956 | 'type' => 'text', |
957 | 957 | 'id' => 'wpinv_state', |
958 | 958 | 'name' => $name, |
959 | - 'label' => __( 'State', 'invoicing' ), |
|
959 | + 'label' => __('State', 'invoicing'), |
|
960 | 960 | 'label_type' => 'vertical', |
961 | - 'placeholder' => __( 'State', 'invoicing' ), |
|
961 | + 'placeholder' => __('State', 'invoicing'), |
|
962 | 962 | 'class' => $class, |
963 | 963 | 'value' => $state, |
964 | 964 | ) |
@@ -970,9 +970,9 @@ discard block |
||
970 | 970 | array( |
971 | 971 | 'id' => 'wpinv_state', |
972 | 972 | 'name' => $name, |
973 | - 'label' => __( 'State', 'invoicing' ), |
|
973 | + 'label' => __('State', 'invoicing'), |
|
974 | 974 | 'label_type' => 'vertical', |
975 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
975 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
976 | 976 | 'class' => $class, |
977 | 977 | 'value' => $state, |
978 | 978 | 'options' => $states, |
@@ -986,7 +986,7 @@ discard block |
||
986 | 986 | wp_send_json_success( |
987 | 987 | array( |
988 | 988 | 'html' => $html, |
989 | - 'select' => ! empty ( $states ) |
|
989 | + 'select' => !empty ($states) |
|
990 | 990 | ) |
991 | 991 | ); |
992 | 992 | |
@@ -1000,11 +1000,11 @@ discard block |
||
1000 | 1000 | public static function payment_form_refresh_prices() { |
1001 | 1001 | |
1002 | 1002 | // Check nonce. |
1003 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
1003 | + check_ajax_referer('getpaid_form_nonce'); |
|
1004 | 1004 | |
1005 | 1005 | // ... form fields... |
1006 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
1007 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
1006 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
1007 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
1008 | 1008 | exit; |
1009 | 1009 | } |
1010 | 1010 | |
@@ -1012,7 +1012,7 @@ discard block |
||
1012 | 1012 | $submission = new GetPaid_Payment_Form_Submission(); |
1013 | 1013 | |
1014 | 1014 | // Do we have an error? |
1015 | - if ( ! empty( $submission->last_error ) ) { |
|
1015 | + if (!empty($submission->last_error)) { |
|
1016 | 1016 | wp_send_json_error( |
1017 | 1017 | array( |
1018 | 1018 | 'code' => $submission->last_error_code, |
@@ -1022,12 +1022,12 @@ discard block |
||
1022 | 1022 | } |
1023 | 1023 | |
1024 | 1024 | // Prepare the response. |
1025 | - $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission ); |
|
1025 | + $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission); |
|
1026 | 1026 | |
1027 | 1027 | // Filter the response. |
1028 | - $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission ); |
|
1028 | + $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission); |
|
1029 | 1029 | |
1030 | - wp_send_json_success( $response ); |
|
1030 | + wp_send_json_success($response); |
|
1031 | 1031 | } |
1032 | 1032 | |
1033 | 1033 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Payment form submission itemss class |
@@ -23,26 +23,26 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @param GetPaid_Payment_Form_Submission $submission |
25 | 25 | */ |
26 | - public function __construct( $submission ) { |
|
26 | + public function __construct($submission) { |
|
27 | 27 | |
28 | 28 | $data = $submission->get_data(); |
29 | 29 | $payment_form = $submission->get_payment_form(); |
30 | 30 | |
31 | 31 | // Prepare the selected items. |
32 | 32 | $selected_items = array(); |
33 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
34 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
33 | + if (!empty($data['getpaid-items'])) { |
|
34 | + $selected_items = wpinv_clean($data['getpaid-items']); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | // For default forms, ensure that an item has been set. |
38 | - if ( $payment_form->is_default() && ( ! $submission->has_invoice() || 'payment_form' == $submission->get_invoice()->get_created_via() ) && isset( $data['getpaid-form-items'] ) ) { |
|
39 | - $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
40 | - $payment_form->set_items( getpaid_convert_items_to_array( $form_items ) ); |
|
38 | + if ($payment_form->is_default() && (!$submission->has_invoice() || 'payment_form' == $submission->get_invoice()->get_created_via()) && isset($data['getpaid-form-items'])) { |
|
39 | + $form_items = wpinv_clean($data['getpaid-form-items']); |
|
40 | + $payment_form->set_items(getpaid_convert_items_to_array($form_items)); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | // Process each individual item. |
44 | - foreach ( $payment_form->get_items() as $item ) { |
|
45 | - $this->process_item( $item, $selected_items, $submission ); |
|
44 | + foreach ($payment_form->get_items() as $item) { |
|
45 | + $this->process_item($item, $selected_items, $submission); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | } |
@@ -54,37 +54,37 @@ discard block |
||
54 | 54 | * @param array $selected_items |
55 | 55 | * @param GetPaid_Payment_Form_Submission $submission |
56 | 56 | */ |
57 | - public function process_item( $item, $selected_items, $submission ) { |
|
57 | + public function process_item($item, $selected_items, $submission) { |
|
58 | 58 | |
59 | 59 | // Abort if this is an optional item and it has not been selected. |
60 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
60 | + if (!$item->is_required() && !isset($selected_items[$item->get_id()])) { |
|
61 | 61 | return; |
62 | 62 | } |
63 | 63 | |
64 | 64 | // (maybe) let customers change the quantities and prices. |
65 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
65 | + if (isset($selected_items[$item->get_id()])) { |
|
66 | 66 | |
67 | 67 | // Maybe change the quantities. |
68 | - if ( $item->allows_quantities() ) { |
|
69 | - $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
68 | + if ($item->allows_quantities()) { |
|
69 | + $item->set_quantity((float) $selected_items[$item->get_id()]['quantity']); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | // Maybe change the price. |
73 | - if ( $item->user_can_set_their_price() ) { |
|
74 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
73 | + if ($item->user_can_set_their_price()) { |
|
74 | + $price = (float) wpinv_sanitize_amount($selected_items[$item->get_id()]['price']); |
|
75 | 75 | |
76 | - if ( $item->get_minimum_price() > $price ) { |
|
77 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) ); |
|
76 | + if ($item->get_minimum_price() > $price) { |
|
77 | + throw new Exception(sprintf(__('The minimum allowed amount is %s', 'invoicing'), getpaid_unstandardize_amount($item->get_minimum_price()))); |
|
78 | 78 | } |
79 | 79 | |
80 | - $item->set_price( $price ); |
|
80 | + $item->set_price($price); |
|
81 | 81 | |
82 | 82 | } |
83 | 83 | |
84 | 84 | } |
85 | 85 | |
86 | 86 | // Save the item. |
87 | - $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission ); |
|
87 | + $this->items[] = apply_filters('getpaid_payment_form_submission_processed_item', $item, $submission); |
|
88 | 88 | |
89 | 89 | } |
90 | 90 |