@@ -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 |
@@ -12,492 +12,492 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Invoice_Notification_Emails { |
14 | 14 | |
15 | - /** |
|
16 | - * The array of invoice email actions. |
|
17 | - * |
|
18 | - * @param array |
|
19 | - */ |
|
20 | - public $invoice_actions; |
|
21 | - |
|
22 | - /** |
|
23 | - * Class constructor |
|
24 | - * |
|
25 | - */ |
|
26 | - public function __construct() { |
|
27 | - |
|
28 | - $this->invoice_actions = apply_filters( |
|
29 | - 'getpaid_notification_email_invoice_triggers', |
|
30 | - array( |
|
31 | - 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
32 | - 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
33 | - 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
34 | - 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
35 | - 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
36 | - 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
37 | - 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
38 | - 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
39 | - 'getpaid_new_customer_note' => 'user_note', |
|
40 | - 'getpaid_daily_maintenance' => 'overdue', |
|
41 | - ) |
|
42 | - ); |
|
43 | - |
|
44 | - $this->init_hooks(); |
|
45 | - |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Registers email hooks. |
|
50 | - */ |
|
51 | - public function init_hooks() { |
|
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 ); |
|
55 | - |
|
56 | - foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | - $this->init_email_type_hook( $hook, $email_type ); |
|
58 | - } |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Registers an email hook for an invoice action. |
|
63 | - * |
|
64 | - * @param string $hook |
|
65 | - * @param string|array $email_type |
|
66 | - */ |
|
67 | - public function init_email_type_hook( $hook, $email_type ) { |
|
68 | - |
|
69 | - $email_type = wpinv_parse_list( $email_type ); |
|
70 | - |
|
71 | - foreach ( $email_type as $type ) { |
|
72 | - |
|
73 | - $email = new GetPaid_Notification_Email( $type ); |
|
74 | - |
|
75 | - // Abort if it is not active. |
|
76 | - if ( ! $email->is_active() ) { |
|
77 | - continue; |
|
78 | - } |
|
79 | - |
|
80 | - if ( method_exists( $this, $type ) ) { |
|
81 | - add_action( $hook, array( $this, $type ), 100, 2 ); |
|
82 | - continue; |
|
83 | - } |
|
84 | - |
|
85 | - do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
86 | - } |
|
87 | - |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Filters invoice merge tags. |
|
92 | - * |
|
93 | - * @param array $merge_tags |
|
94 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
95 | - */ |
|
96 | - public function invoice_merge_tags( $merge_tags, $object ) { |
|
97 | - |
|
98 | - if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
99 | - return array_merge( |
|
100 | - $merge_tags, |
|
101 | - $this->get_invoice_merge_tags( $object ) |
|
102 | - ); |
|
103 | - } |
|
104 | - |
|
105 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
106 | - return array_merge( |
|
107 | - $merge_tags, |
|
108 | - $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
109 | - ); |
|
110 | - } |
|
111 | - |
|
112 | - return $merge_tags; |
|
113 | - |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Generates invoice merge tags. |
|
118 | - * |
|
119 | - * @param WPInv_Invoice $invoice |
|
120 | - * @return array |
|
121 | - */ |
|
122 | - public function get_invoice_merge_tags( $invoice ) { |
|
123 | - |
|
124 | - // Abort if it does not exist. |
|
125 | - if ( ! $invoice->get_id() ) { |
|
126 | - return array(); |
|
127 | - } |
|
128 | - |
|
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' ), |
|
148 | - ); |
|
149 | - |
|
150 | - $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
151 | - |
|
152 | - if ( is_array( $payment_form_data ) ) { |
|
153 | - |
|
154 | - foreach ( $payment_form_data as $label => $value ) { |
|
155 | - |
|
156 | - $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
157 | - $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
158 | - |
|
159 | - if ( is_scalar ( $value ) ) { |
|
160 | - $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
161 | - } |
|
162 | - |
|
163 | - } |
|
164 | - |
|
165 | - } |
|
166 | - |
|
167 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Helper function to send an email. |
|
172 | - * |
|
173 | - * @param WPInv_Invoice $invoice |
|
174 | - * @param GetPaid_Notification_Email $email |
|
175 | - * @param string $type |
|
176 | - * @param string|array $recipients |
|
177 | - * @param array $extra_args Extra template args. |
|
178 | - */ |
|
179 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
180 | - |
|
181 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
182 | - |
|
183 | - $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
184 | - if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
185 | - return; |
|
186 | - } |
|
187 | - |
|
188 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
189 | - $merge_tags = $email->get_merge_tags(); |
|
190 | - |
|
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 ), |
|
195 | - $email->get_attachments() |
|
196 | - ); |
|
197 | - |
|
198 | - // Maybe send a copy to the admin. |
|
199 | - if ( $email->include_admin_bcc() ) { |
|
200 | - $mailer->send( |
|
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 ), |
|
204 | - $email->get_attachments() |
|
205 | - ); |
|
206 | - } |
|
207 | - |
|
208 | - if ( $result ) { |
|
209 | - $invoice->add_system_note( |
|
210 | - sprintf( |
|
211 | - __( 'Successfully sent %s notification email to %s.', 'invoicing' ), |
|
212 | - sanitize_key( $type ), |
|
213 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
214 | - ) |
|
215 | - ); |
|
216 | - } else { |
|
217 | - $invoice->add_system_note( |
|
218 | - sprintf( |
|
219 | - __( 'Failed sending %s notification email to %s.', 'invoicing' ), |
|
220 | - sanitize_key( $type ), |
|
221 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
222 | - ) |
|
223 | - ); |
|
224 | - } |
|
225 | - |
|
226 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
227 | - |
|
228 | - return $result; |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * Also send emails to any cc users. |
|
233 | - * |
|
234 | - * @param array $recipients |
|
235 | - * @param GetPaid_Notification_Email $email |
|
236 | - */ |
|
237 | - public function filter_email_recipients( $recipients, $email ) { |
|
238 | - |
|
239 | - if ( ! $email->is_admin_email() ) { |
|
240 | - $cc = $email->object->get_email_cc(); |
|
241 | - $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
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 ) ) ); |
|
246 | - } |
|
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 ) ) ); |
|
251 | - } |
|
252 | - |
|
253 | - } |
|
254 | - |
|
255 | - return $recipients; |
|
256 | - |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Sends a new invoice notification. |
|
261 | - * |
|
262 | - * @param WPInv_Invoice $invoice |
|
263 | - */ |
|
264 | - public function new_invoice( $invoice ) { |
|
265 | - |
|
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() ) ) { |
|
268 | - return; |
|
269 | - } |
|
270 | - |
|
271 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
272 | - $recipient = wpinv_get_admin_email(); |
|
273 | - |
|
274 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
275 | - |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Sends a cancelled invoice notification. |
|
280 | - * |
|
281 | - * @param WPInv_Invoice $invoice |
|
282 | - */ |
|
283 | - public function cancelled_invoice( $invoice ) { |
|
284 | - |
|
285 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
286 | - $recipient = wpinv_get_admin_email(); |
|
287 | - |
|
288 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
289 | - |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * Sends a failed invoice notification. |
|
294 | - * |
|
295 | - * @param WPInv_Invoice $invoice |
|
296 | - */ |
|
297 | - public function failed_invoice( $invoice ) { |
|
298 | - |
|
299 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
300 | - $recipient = wpinv_get_admin_email(); |
|
301 | - |
|
302 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
303 | - |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Sends a notification whenever an invoice is put on hold. |
|
308 | - * |
|
309 | - * @param WPInv_Invoice $invoice |
|
310 | - */ |
|
311 | - public function onhold_invoice( $invoice ) { |
|
312 | - |
|
313 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
314 | - $recipient = $invoice->get_email(); |
|
15 | + /** |
|
16 | + * The array of invoice email actions. |
|
17 | + * |
|
18 | + * @param array |
|
19 | + */ |
|
20 | + public $invoice_actions; |
|
21 | + |
|
22 | + /** |
|
23 | + * Class constructor |
|
24 | + * |
|
25 | + */ |
|
26 | + public function __construct() { |
|
27 | + |
|
28 | + $this->invoice_actions = apply_filters( |
|
29 | + 'getpaid_notification_email_invoice_triggers', |
|
30 | + array( |
|
31 | + 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
32 | + 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
33 | + 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
34 | + 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
35 | + 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
36 | + 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
37 | + 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
38 | + 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
39 | + 'getpaid_new_customer_note' => 'user_note', |
|
40 | + 'getpaid_daily_maintenance' => 'overdue', |
|
41 | + ) |
|
42 | + ); |
|
43 | + |
|
44 | + $this->init_hooks(); |
|
45 | + |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Registers email hooks. |
|
50 | + */ |
|
51 | + public function init_hooks() { |
|
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 ); |
|
55 | + |
|
56 | + foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | + $this->init_email_type_hook( $hook, $email_type ); |
|
58 | + } |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Registers an email hook for an invoice action. |
|
63 | + * |
|
64 | + * @param string $hook |
|
65 | + * @param string|array $email_type |
|
66 | + */ |
|
67 | + public function init_email_type_hook( $hook, $email_type ) { |
|
68 | + |
|
69 | + $email_type = wpinv_parse_list( $email_type ); |
|
70 | + |
|
71 | + foreach ( $email_type as $type ) { |
|
72 | + |
|
73 | + $email = new GetPaid_Notification_Email( $type ); |
|
74 | + |
|
75 | + // Abort if it is not active. |
|
76 | + if ( ! $email->is_active() ) { |
|
77 | + continue; |
|
78 | + } |
|
79 | + |
|
80 | + if ( method_exists( $this, $type ) ) { |
|
81 | + add_action( $hook, array( $this, $type ), 100, 2 ); |
|
82 | + continue; |
|
83 | + } |
|
84 | + |
|
85 | + do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
86 | + } |
|
87 | + |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Filters invoice merge tags. |
|
92 | + * |
|
93 | + * @param array $merge_tags |
|
94 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
95 | + */ |
|
96 | + public function invoice_merge_tags( $merge_tags, $object ) { |
|
97 | + |
|
98 | + if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
99 | + return array_merge( |
|
100 | + $merge_tags, |
|
101 | + $this->get_invoice_merge_tags( $object ) |
|
102 | + ); |
|
103 | + } |
|
104 | + |
|
105 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
106 | + return array_merge( |
|
107 | + $merge_tags, |
|
108 | + $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
109 | + ); |
|
110 | + } |
|
111 | + |
|
112 | + return $merge_tags; |
|
113 | + |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Generates invoice merge tags. |
|
118 | + * |
|
119 | + * @param WPInv_Invoice $invoice |
|
120 | + * @return array |
|
121 | + */ |
|
122 | + public function get_invoice_merge_tags( $invoice ) { |
|
123 | + |
|
124 | + // Abort if it does not exist. |
|
125 | + if ( ! $invoice->get_id() ) { |
|
126 | + return array(); |
|
127 | + } |
|
128 | + |
|
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' ), |
|
148 | + ); |
|
149 | + |
|
150 | + $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
151 | + |
|
152 | + if ( is_array( $payment_form_data ) ) { |
|
153 | + |
|
154 | + foreach ( $payment_form_data as $label => $value ) { |
|
155 | + |
|
156 | + $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
157 | + $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
158 | + |
|
159 | + if ( is_scalar ( $value ) ) { |
|
160 | + $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
161 | + } |
|
162 | + |
|
163 | + } |
|
164 | + |
|
165 | + } |
|
166 | + |
|
167 | + return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Helper function to send an email. |
|
172 | + * |
|
173 | + * @param WPInv_Invoice $invoice |
|
174 | + * @param GetPaid_Notification_Email $email |
|
175 | + * @param string $type |
|
176 | + * @param string|array $recipients |
|
177 | + * @param array $extra_args Extra template args. |
|
178 | + */ |
|
179 | + public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
180 | + |
|
181 | + do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
182 | + |
|
183 | + $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
184 | + if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
185 | + return; |
|
186 | + } |
|
187 | + |
|
188 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
189 | + $merge_tags = $email->get_merge_tags(); |
|
190 | + |
|
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 ), |
|
195 | + $email->get_attachments() |
|
196 | + ); |
|
197 | + |
|
198 | + // Maybe send a copy to the admin. |
|
199 | + if ( $email->include_admin_bcc() ) { |
|
200 | + $mailer->send( |
|
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 ), |
|
204 | + $email->get_attachments() |
|
205 | + ); |
|
206 | + } |
|
207 | + |
|
208 | + if ( $result ) { |
|
209 | + $invoice->add_system_note( |
|
210 | + sprintf( |
|
211 | + __( 'Successfully sent %s notification email to %s.', 'invoicing' ), |
|
212 | + sanitize_key( $type ), |
|
213 | + $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
214 | + ) |
|
215 | + ); |
|
216 | + } else { |
|
217 | + $invoice->add_system_note( |
|
218 | + sprintf( |
|
219 | + __( 'Failed sending %s notification email to %s.', 'invoicing' ), |
|
220 | + sanitize_key( $type ), |
|
221 | + $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
222 | + ) |
|
223 | + ); |
|
224 | + } |
|
225 | + |
|
226 | + do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
227 | + |
|
228 | + return $result; |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Also send emails to any cc users. |
|
233 | + * |
|
234 | + * @param array $recipients |
|
235 | + * @param GetPaid_Notification_Email $email |
|
236 | + */ |
|
237 | + public function filter_email_recipients( $recipients, $email ) { |
|
238 | + |
|
239 | + if ( ! $email->is_admin_email() ) { |
|
240 | + $cc = $email->object->get_email_cc(); |
|
241 | + $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
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 ) ) ); |
|
246 | + } |
|
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 ) ) ); |
|
251 | + } |
|
252 | + |
|
253 | + } |
|
254 | + |
|
255 | + return $recipients; |
|
256 | + |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Sends a new invoice notification. |
|
261 | + * |
|
262 | + * @param WPInv_Invoice $invoice |
|
263 | + */ |
|
264 | + public function new_invoice( $invoice ) { |
|
265 | + |
|
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() ) ) { |
|
268 | + return; |
|
269 | + } |
|
270 | + |
|
271 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
272 | + $recipient = wpinv_get_admin_email(); |
|
273 | + |
|
274 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
275 | + |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Sends a cancelled invoice notification. |
|
280 | + * |
|
281 | + * @param WPInv_Invoice $invoice |
|
282 | + */ |
|
283 | + public function cancelled_invoice( $invoice ) { |
|
284 | + |
|
285 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
286 | + $recipient = wpinv_get_admin_email(); |
|
287 | + |
|
288 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
289 | + |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * Sends a failed invoice notification. |
|
294 | + * |
|
295 | + * @param WPInv_Invoice $invoice |
|
296 | + */ |
|
297 | + public function failed_invoice( $invoice ) { |
|
298 | + |
|
299 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
300 | + $recipient = wpinv_get_admin_email(); |
|
301 | + |
|
302 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
303 | + |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Sends a notification whenever an invoice is put on hold. |
|
308 | + * |
|
309 | + * @param WPInv_Invoice $invoice |
|
310 | + */ |
|
311 | + public function onhold_invoice( $invoice ) { |
|
312 | + |
|
313 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
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 | |
320 | - /** |
|
321 | - * Sends a notification whenever an invoice is marked as processing payment. |
|
322 | - * |
|
323 | - * @param WPInv_Invoice $invoice |
|
324 | - */ |
|
325 | - public function processing_invoice( $invoice ) { |
|
320 | + /** |
|
321 | + * Sends a notification whenever an invoice is marked as processing payment. |
|
322 | + * |
|
323 | + * @param WPInv_Invoice $invoice |
|
324 | + */ |
|
325 | + public function processing_invoice( $invoice ) { |
|
326 | 326 | |
327 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
328 | - $recipient = $invoice->get_email(); |
|
327 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
328 | + $recipient = $invoice->get_email(); |
|
329 | 329 | |
330 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
331 | - |
|
332 | - } |
|
333 | - |
|
334 | - /** |
|
335 | - * Sends a notification whenever an invoice is paid. |
|
336 | - * |
|
337 | - * @param WPInv_Invoice $invoice |
|
338 | - */ |
|
339 | - public function completed_invoice( $invoice ) { |
|
330 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
331 | + |
|
332 | + } |
|
333 | + |
|
334 | + /** |
|
335 | + * Sends a notification whenever an invoice is paid. |
|
336 | + * |
|
337 | + * @param WPInv_Invoice $invoice |
|
338 | + */ |
|
339 | + public function completed_invoice( $invoice ) { |
|
340 | 340 | |
341 | - // (Maybe) abort if it is a renewal invoice. |
|
342 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
343 | - return; |
|
344 | - } |
|
341 | + // (Maybe) abort if it is a renewal invoice. |
|
342 | + if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
343 | + return; |
|
344 | + } |
|
345 | 345 | |
346 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
347 | - $recipient = $invoice->get_email(); |
|
346 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
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 | |
353 | - /** |
|
354 | - * Sends a notification whenever an invoice is refunded. |
|
355 | - * |
|
356 | - * @param WPInv_Invoice $invoice |
|
357 | - */ |
|
358 | - public function refunded_invoice( $invoice ) { |
|
353 | + /** |
|
354 | + * Sends a notification whenever an invoice is refunded. |
|
355 | + * |
|
356 | + * @param WPInv_Invoice $invoice |
|
357 | + */ |
|
358 | + public function refunded_invoice( $invoice ) { |
|
359 | 359 | |
360 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
361 | - $recipient = $invoice->get_email(); |
|
360 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
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 | |
367 | - /** |
|
368 | - * Notifies a user about new invoices |
|
369 | - * |
|
370 | - * @param WPInv_Invoice $invoice |
|
371 | - * @param bool $force |
|
372 | - */ |
|
373 | - public function user_invoice( $invoice, $force = false ) { |
|
367 | + /** |
|
368 | + * Notifies a user about new invoices |
|
369 | + * |
|
370 | + * @param WPInv_Invoice $invoice |
|
371 | + * @param bool $force |
|
372 | + */ |
|
373 | + public function user_invoice( $invoice, $force = false ) { |
|
374 | 374 | |
375 | - if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
376 | - return; |
|
377 | - } |
|
378 | - |
|
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() ) ) ) { |
|
381 | - return; |
|
382 | - } |
|
375 | + if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
376 | + return; |
|
377 | + } |
|
378 | + |
|
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() ) ) ) { |
|
381 | + return; |
|
382 | + } |
|
383 | 383 | |
384 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
385 | - $recipient = $invoice->get_email(); |
|
384 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
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 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * Checks if an invoice is a payment form invoice. |
|
393 | - * |
|
394 | - * @param int $invoice |
|
395 | - * @return bool |
|
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 ); |
|
400 | - } |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * Checks if an invoice is a payment form invoice. |
|
393 | + * |
|
394 | + * @param int $invoice |
|
395 | + * @return bool |
|
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 ); |
|
400 | + } |
|
401 | 401 | |
402 | - /** |
|
403 | - * Notifies admin about new invoice notes |
|
404 | - * |
|
405 | - * @param WPInv_Invoice $invoice |
|
406 | - * @param string $note |
|
407 | - */ |
|
408 | - public function user_note( $invoice, $note ) { |
|
409 | - |
|
410 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
411 | - $recipient = $invoice->get_email(); |
|
402 | + /** |
|
403 | + * Notifies admin about new invoice notes |
|
404 | + * |
|
405 | + * @param WPInv_Invoice $invoice |
|
406 | + * @param string $note |
|
407 | + */ |
|
408 | + public function user_note( $invoice, $note ) { |
|
409 | + |
|
410 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
411 | + $recipient = $invoice->get_email(); |
|
412 | 412 | |
413 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
414 | - |
|
415 | - } |
|
416 | - |
|
417 | - /** |
|
418 | - * (Force) Sends overdue notices. |
|
419 | - * |
|
420 | - * @param WPInv_Invoice $invoice |
|
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() ); |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * Sends overdue notices. |
|
429 | - * |
|
430 | - * @TODO: Create an invoices query class. |
|
431 | - */ |
|
432 | - public function overdue() { |
|
433 | - global $wpdb; |
|
434 | - |
|
435 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
436 | - |
|
437 | - // Fetch reminder days. |
|
438 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
439 | - |
|
440 | - // Abort if non is set. |
|
441 | - if ( empty( $reminder_days ) ) { |
|
442 | - return; |
|
443 | - } |
|
444 | - |
|
445 | - // Retrieve date query. |
|
446 | - $date_query = $this->get_date_query( $reminder_days ); |
|
447 | - |
|
448 | - // Invoices table. |
|
449 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
450 | - |
|
451 | - // Fetch invoices. |
|
452 | - $invoices = $wpdb->get_col( |
|
453 | - "SELECT posts.ID FROM $wpdb->posts as posts |
|
413 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
414 | + |
|
415 | + } |
|
416 | + |
|
417 | + /** |
|
418 | + * (Force) Sends overdue notices. |
|
419 | + * |
|
420 | + * @param WPInv_Invoice $invoice |
|
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() ); |
|
425 | + } |
|
426 | + |
|
427 | + /** |
|
428 | + * Sends overdue notices. |
|
429 | + * |
|
430 | + * @TODO: Create an invoices query class. |
|
431 | + */ |
|
432 | + public function overdue() { |
|
433 | + global $wpdb; |
|
434 | + |
|
435 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
436 | + |
|
437 | + // Fetch reminder days. |
|
438 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
439 | + |
|
440 | + // Abort if non is set. |
|
441 | + if ( empty( $reminder_days ) ) { |
|
442 | + return; |
|
443 | + } |
|
444 | + |
|
445 | + // Retrieve date query. |
|
446 | + $date_query = $this->get_date_query( $reminder_days ); |
|
447 | + |
|
448 | + // Invoices table. |
|
449 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
450 | + |
|
451 | + // Fetch invoices. |
|
452 | + $invoices = $wpdb->get_col( |
|
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 | - // 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 ); |
|
462 | - $email->object = $invoice; |
|
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 ); |
|
462 | + $email->object = $invoice; |
|
463 | 463 | |
464 | - if ( $invoice->needs_payment() ) { |
|
465 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
466 | - } |
|
464 | + if ( $invoice->needs_payment() ) { |
|
465 | + $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
466 | + } |
|
467 | 467 | |
468 | - } |
|
468 | + } |
|
469 | 469 | |
470 | - } |
|
470 | + } |
|
471 | 471 | |
472 | - } |
|
472 | + } |
|
473 | 473 | |
474 | - /** |
|
475 | - * Calculates the date query for an invoices query |
|
476 | - * |
|
477 | - * @param array $reminder_days |
|
478 | - * @return string |
|
479 | - */ |
|
480 | - public function get_date_query( $reminder_days ) { |
|
474 | + /** |
|
475 | + * Calculates the date query for an invoices query |
|
476 | + * |
|
477 | + * @param array $reminder_days |
|
478 | + * @return string |
|
479 | + */ |
|
480 | + public function get_date_query( $reminder_days ) { |
|
481 | 481 | |
482 | - $date_query = array( |
|
483 | - 'relation' => 'OR' |
|
484 | - ); |
|
482 | + $date_query = array( |
|
483 | + 'relation' => 'OR' |
|
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 | - $date_query[] = array( |
|
490 | - 'year' => $date['year'], |
|
491 | - 'month' => $date['month'], |
|
492 | - 'day' => $date['day'], |
|
493 | - ); |
|
489 | + $date_query[] = array( |
|
490 | + 'year' => $date['year'], |
|
491 | + 'month' => $date['month'], |
|
492 | + 'day' => $date['day'], |
|
493 | + ); |
|
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 | - return $date_query->get_sql(); |
|
499 | + return $date_query->get_sql(); |
|
500 | 500 | |
501 | - } |
|
501 | + } |
|
502 | 502 | |
503 | 503 | } |
@@ -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 |
@@ -24,64 +24,64 @@ discard block |
||
24 | 24 | |
25 | 25 | <?php |
26 | 26 | |
27 | - // Fires before printing a line item column. |
|
28 | - do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
27 | + // Fires before printing a line item column. |
|
28 | + do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
29 | 29 | |
30 | - // Item name. |
|
31 | - if ( 'name' == $key ) { |
|
30 | + // Item name. |
|
31 | + if ( 'name' == $key ) { |
|
32 | 32 | |
33 | - // Display the name. |
|
34 | - echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>'; |
|
33 | + // Display the name. |
|
34 | + echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>'; |
|
35 | 35 | |
36 | - // And an optional description. |
|
36 | + // And an optional description. |
|
37 | 37 | $description = $item->get_description(); |
38 | 38 | |
39 | 39 | if ( ! empty( $description ) ) { |
40 | 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 | - // Price help text. |
|
44 | + // Price help text. |
|
45 | 45 | $description = getpaid_item_recurring_price_help_text( $item, $currency ); |
46 | 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 | - // Item price. |
|
53 | - if ( 'price' == $key ) { |
|
52 | + // Item price. |
|
53 | + if ( 'price' == $key ) { |
|
54 | 54 | |
55 | - // Set the currency position. |
|
56 | - $position = wpinv_currency_position(); |
|
55 | + // Set the currency position. |
|
56 | + $position = wpinv_currency_position(); |
|
57 | 57 | |
58 | - if ( $position == 'left_space' ) { |
|
59 | - $position = 'left'; |
|
60 | - } |
|
58 | + if ( $position == 'left_space' ) { |
|
59 | + $position = 'left'; |
|
60 | + } |
|
61 | 61 | |
62 | - if ( $position == 'right_space' ) { |
|
63 | - $position = 'right'; |
|
64 | - } |
|
62 | + if ( $position == 'right_space' ) { |
|
63 | + $position = 'right'; |
|
64 | + } |
|
65 | 65 | |
66 | - if ( $item->user_can_set_their_price() ) { |
|
67 | - $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
68 | - $minimum = (float) $item->get_minimum_price(); |
|
69 | - $validate_minimum = ''; |
|
70 | - $class = ''; |
|
71 | - $data_minimum = ''; |
|
66 | + if ( $item->user_can_set_their_price() ) { |
|
67 | + $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
68 | + $minimum = (float) $item->get_minimum_price(); |
|
69 | + $validate_minimum = ''; |
|
70 | + $class = ''; |
|
71 | + $data_minimum = ''; |
|
72 | 72 | |
73 | - if ( $minimum > 0 ) { |
|
74 | - $validate_minimum = sprintf( |
|
75 | - esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ), |
|
76 | - sanitize_text_field( wpinv_price( $minimum, $currency ) ) |
|
77 | - ); |
|
73 | + if ( $minimum > 0 ) { |
|
74 | + $validate_minimum = sprintf( |
|
75 | + esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ), |
|
76 | + sanitize_text_field( wpinv_price( $minimum, $currency ) ) |
|
77 | + ); |
|
78 | 78 | |
79 | - $class = 'getpaid-validate-minimum-amount'; |
|
79 | + $class = 'getpaid-validate-minimum-amount'; |
|
80 | 80 | |
81 | - $data_minimum = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'"; |
|
82 | - } |
|
81 | + $data_minimum = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'"; |
|
82 | + } |
|
83 | 83 | |
84 | - ?> |
|
84 | + ?> |
|
85 | 85 | <div class="input-group input-group-sm"> |
86 | 86 | <?php if( 'left' == $position ) : ?> |
87 | 87 | <div class="input-group-prepend"> |
@@ -105,37 +105,37 @@ discard block |
||
105 | 105 | </div> |
106 | 106 | |
107 | 107 | <?php |
108 | - } else { |
|
109 | - echo wpinv_price( $item->get_price(), $currency ); |
|
110 | - ?> |
|
108 | + } else { |
|
109 | + echo wpinv_price( $item->get_price(), $currency ); |
|
110 | + ?> |
|
111 | 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 | - } |
|
114 | - } |
|
113 | + } |
|
114 | + } |
|
115 | 115 | |
116 | - // Item quantity. |
|
117 | - if ( 'quantity' == $key ) { |
|
116 | + // Item quantity. |
|
117 | + if ( 'quantity' == $key ) { |
|
118 | 118 | |
119 | - if ( $item->allows_quantities() ) { |
|
120 | - ?> |
|
119 | + if ( $item->allows_quantities() ) { |
|
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 |
123 | - } else { |
|
124 | - echo (float) $item->get_quantity(); |
|
125 | - echo ' '; |
|
126 | - ?> |
|
123 | + } else { |
|
124 | + echo (float) $item->get_quantity(); |
|
125 | + echo ' '; |
|
126 | + ?> |
|
127 | 127 | <input type='hidden' name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' class='getpaid-item-quantity-input' value='<?php echo (float) $item->get_quantity(); ?>'> |
128 | 128 | <?php |
129 | - } |
|
130 | - } |
|
129 | + } |
|
130 | + } |
|
131 | 131 | |
132 | - // Item sub total. |
|
133 | - if ( 'subtotal' == $key ) { |
|
134 | - echo wpinv_price( $item->get_sub_total(), $currency ); |
|
135 | - } |
|
132 | + // Item sub total. |
|
133 | + if ( 'subtotal' == $key ) { |
|
134 | + echo wpinv_price( $item->get_sub_total(), $currency ); |
|
135 | + } |
|
136 | 136 | |
137 | - do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
138 | - ?> |
|
137 | + do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
138 | + ?> |
|
139 | 139 | |
140 | 140 | </div> |
141 | 141 |
@@ -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); |
@@ -14,592 +14,592 @@ |
||
14 | 14 | */ |
15 | 15 | class WPInv_Plugin { |
16 | 16 | |
17 | - /** |
|
18 | - * GetPaid version. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $version; |
|
23 | - |
|
24 | - /** |
|
25 | - * Data container. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $data = array(); |
|
30 | - |
|
31 | - /** |
|
32 | - * Form elements instance. |
|
33 | - * |
|
34 | - * @var WPInv_Payment_Form_Elements |
|
35 | - */ |
|
36 | - public $form_elements; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var array An array of payment gateways. |
|
40 | - */ |
|
41 | - public $gateways; |
|
42 | - |
|
43 | - /** |
|
44 | - * Class constructor. |
|
45 | - */ |
|
46 | - public function __construct() { |
|
47 | - $this->define_constants(); |
|
48 | - $this->includes(); |
|
49 | - $this->init_hooks(); |
|
50 | - $this->set_properties(); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Sets a custom data property. |
|
55 | - * |
|
56 | - * @param string $prop The prop to set. |
|
57 | - * @param mixed $value The value to retrieve. |
|
58 | - */ |
|
59 | - public function set( $prop, $value ) { |
|
60 | - $this->data[ $prop ] = $value; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Gets a custom data property. |
|
65 | - * |
|
66 | - * @param string $prop The prop to set. |
|
67 | - * @return mixed The value. |
|
68 | - */ |
|
69 | - public function get( $prop ) { |
|
70 | - |
|
71 | - if ( isset( $this->data[ $prop ] ) ) { |
|
72 | - return $this->data[ $prop ]; |
|
73 | - } |
|
74 | - |
|
75 | - return null; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Define class properties. |
|
80 | - */ |
|
81 | - public function set_properties() { |
|
82 | - |
|
83 | - // Sessions. |
|
84 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
86 | - $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
87 | - |
|
88 | - // Init other objects. |
|
89 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
90 | - $this->set( 'notes', new WPInv_Notes() ); |
|
91 | - $this->set( 'api', new WPInv_API() ); |
|
92 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | - $this->set( 'template', new GetPaid_Template() ); |
|
94 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Define plugin constants. |
|
106 | - */ |
|
107 | - public function define_constants() { |
|
108 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
110 | - $this->version = WPINV_VERSION; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Hook into actions and filters. |
|
115 | - * |
|
116 | - * @since 1.0.19 |
|
117 | - */ |
|
118 | - protected function init_hooks() { |
|
119 | - /* Internationalize the text strings used. */ |
|
120 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
121 | - |
|
122 | - // Init the plugin after WordPress inits. |
|
123 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
127 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
128 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
129 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
130 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
131 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
132 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
133 | - |
|
134 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
17 | + /** |
|
18 | + * GetPaid version. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $version; |
|
23 | + |
|
24 | + /** |
|
25 | + * Data container. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $data = array(); |
|
30 | + |
|
31 | + /** |
|
32 | + * Form elements instance. |
|
33 | + * |
|
34 | + * @var WPInv_Payment_Form_Elements |
|
35 | + */ |
|
36 | + public $form_elements; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var array An array of payment gateways. |
|
40 | + */ |
|
41 | + public $gateways; |
|
42 | + |
|
43 | + /** |
|
44 | + * Class constructor. |
|
45 | + */ |
|
46 | + public function __construct() { |
|
47 | + $this->define_constants(); |
|
48 | + $this->includes(); |
|
49 | + $this->init_hooks(); |
|
50 | + $this->set_properties(); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Sets a custom data property. |
|
55 | + * |
|
56 | + * @param string $prop The prop to set. |
|
57 | + * @param mixed $value The value to retrieve. |
|
58 | + */ |
|
59 | + public function set( $prop, $value ) { |
|
60 | + $this->data[ $prop ] = $value; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Gets a custom data property. |
|
65 | + * |
|
66 | + * @param string $prop The prop to set. |
|
67 | + * @return mixed The value. |
|
68 | + */ |
|
69 | + public function get( $prop ) { |
|
70 | + |
|
71 | + if ( isset( $this->data[ $prop ] ) ) { |
|
72 | + return $this->data[ $prop ]; |
|
73 | + } |
|
74 | + |
|
75 | + return null; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Define class properties. |
|
80 | + */ |
|
81 | + public function set_properties() { |
|
82 | + |
|
83 | + // Sessions. |
|
84 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
86 | + $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
87 | + |
|
88 | + // Init other objects. |
|
89 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
90 | + $this->set( 'notes', new WPInv_Notes() ); |
|
91 | + $this->set( 'api', new WPInv_API() ); |
|
92 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | + $this->set( 'template', new GetPaid_Template() ); |
|
94 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Define plugin constants. |
|
106 | + */ |
|
107 | + public function define_constants() { |
|
108 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
110 | + $this->version = WPINV_VERSION; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Hook into actions and filters. |
|
115 | + * |
|
116 | + * @since 1.0.19 |
|
117 | + */ |
|
118 | + protected function init_hooks() { |
|
119 | + /* Internationalize the text strings used. */ |
|
120 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
121 | + |
|
122 | + // Init the plugin after WordPress inits. |
|
123 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
127 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
128 | + add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
129 | + add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
130 | + add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
131 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
132 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
133 | + |
|
134 | + add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
135 | 135 | add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
136 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
137 | - |
|
138 | - // Fires after registering actions. |
|
139 | - do_action( 'wpinv_actions', $this ); |
|
140 | - do_action( 'getpaid_actions', $this ); |
|
141 | - |
|
142 | - } |
|
143 | - |
|
144 | - public function plugins_loaded() { |
|
145 | - /* Internationalize the text strings used. */ |
|
146 | - $this->load_textdomain(); |
|
147 | - |
|
148 | - do_action( 'wpinv_loaded' ); |
|
149 | - |
|
150 | - // Fix oxygen page builder conflict |
|
151 | - if ( function_exists( 'ct_css_output' ) ) { |
|
152 | - wpinv_oxygen_fix_conflict(); |
|
153 | - } |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Load the translation of the plugin. |
|
158 | - * |
|
159 | - * @since 1.0 |
|
160 | - */ |
|
161 | - public function load_textdomain( $locale = NULL ) { |
|
162 | - if ( empty( $locale ) ) { |
|
163 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
164 | - } |
|
165 | - |
|
166 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
167 | - |
|
168 | - unload_textdomain( 'invoicing' ); |
|
169 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
170 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
171 | - |
|
172 | - /** |
|
173 | - * Define language constants. |
|
174 | - */ |
|
175 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Include required core files used in admin and on the frontend. |
|
180 | - */ |
|
181 | - public function includes() { |
|
182 | - |
|
183 | - // Start with the settings. |
|
184 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
185 | - |
|
186 | - // Packages/libraries. |
|
187 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
188 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
189 | - |
|
190 | - // Load functions. |
|
191 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
192 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
193 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
194 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
195 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
196 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
198 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
199 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
200 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' ); |
|
205 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
206 | - |
|
207 | - // Register autoloader. |
|
208 | - try { |
|
209 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
210 | - } catch ( Exception $e ) { |
|
211 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
212 | - } |
|
213 | - |
|
214 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
215 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
216 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
217 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
218 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
219 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
220 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
221 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
222 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
223 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
224 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
234 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
235 | - |
|
236 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
237 | - GetPaid_Post_Types_Admin::init(); |
|
238 | - |
|
239 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
240 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
241 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
242 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
243 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
244 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
245 | - // load the user class only on the users.php page |
|
246 | - global $pagenow; |
|
247 | - if($pagenow=='users.php'){ |
|
248 | - new WPInv_Admin_Users(); |
|
249 | - } |
|
250 | - } |
|
251 | - |
|
252 | - // Register cli commands |
|
253 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
254 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
255 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
256 | - } |
|
257 | - |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Class autoloader |
|
262 | - * |
|
263 | - * @param string $class_name The name of the class to load. |
|
264 | - * @access public |
|
265 | - * @since 1.0.19 |
|
266 | - * @return void |
|
267 | - */ |
|
268 | - public function autoload( $class_name ) { |
|
269 | - |
|
270 | - // Normalize the class name... |
|
271 | - $class_name = strtolower( $class_name ); |
|
272 | - |
|
273 | - // ... and make sure it is our class. |
|
274 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
275 | - return; |
|
276 | - } |
|
277 | - |
|
278 | - // Next, prepare the file name from the class. |
|
279 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
280 | - |
|
281 | - // Base path of the classes. |
|
282 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
283 | - |
|
284 | - // And an array of possible locations in order of importance. |
|
285 | - $locations = array( |
|
286 | - "$plugin_path/includes", |
|
287 | - "$plugin_path/includes/data-stores", |
|
288 | - "$plugin_path/includes/gateways", |
|
289 | - "$plugin_path/includes/payments", |
|
290 | - "$plugin_path/includes/geolocation", |
|
291 | - "$plugin_path/includes/reports", |
|
292 | - "$plugin_path/includes/api", |
|
293 | - "$plugin_path/includes/admin", |
|
294 | - "$plugin_path/includes/admin/meta-boxes", |
|
295 | - ); |
|
296 | - |
|
297 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
298 | - |
|
299 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
300 | - include trailingslashit( $location ) . $file_name; |
|
301 | - break; |
|
302 | - } |
|
303 | - |
|
304 | - } |
|
305 | - |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Inits hooks etc. |
|
310 | - */ |
|
311 | - public function init() { |
|
312 | - |
|
313 | - // Fires before getpaid inits. |
|
314 | - do_action( 'before_getpaid_init', $this ); |
|
315 | - |
|
316 | - // Maybe upgrade. |
|
317 | - $this->maybe_upgrade_database(); |
|
318 | - |
|
319 | - // Load default gateways. |
|
320 | - $gateways = apply_filters( |
|
321 | - 'getpaid_default_gateways', |
|
322 | - array( |
|
323 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
324 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
325 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
326 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
327 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
328 | - ) |
|
329 | - ); |
|
330 | - |
|
331 | - foreach ( $gateways as $id => $class ) { |
|
332 | - $this->gateways[ $id ] = new $class(); |
|
333 | - } |
|
334 | - |
|
335 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
336 | - GetPaid_Installer::rename_gateways_label(); |
|
337 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
338 | - } |
|
339 | - |
|
340 | - // Fires after getpaid inits. |
|
341 | - do_action( 'getpaid_init', $this ); |
|
342 | - |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * Checks if this is an IPN request and processes it. |
|
347 | - */ |
|
348 | - public function maybe_process_ipn() { |
|
349 | - |
|
350 | - // Ensure that this is an IPN request. |
|
351 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
352 | - return; |
|
353 | - } |
|
354 | - |
|
355 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
356 | - |
|
357 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
358 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
359 | - exit; |
|
360 | - |
|
361 | - } |
|
362 | - |
|
363 | - public function enqueue_scripts() { |
|
364 | - |
|
365 | - // Fires before adding scripts. |
|
366 | - do_action( 'getpaid_enqueue_scripts' ); |
|
367 | - |
|
368 | - $localize = array(); |
|
369 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
370 | - $localize['thousands'] = wpinv_thousands_separator(); |
|
371 | - $localize['decimals'] = wpinv_decimal_separator(); |
|
372 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
373 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
374 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
375 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
376 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
377 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
378 | - |
|
379 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
380 | - |
|
381 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
382 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
383 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
384 | - } |
|
385 | - |
|
386 | - public function wpinv_actions() { |
|
387 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
388 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
389 | - } |
|
390 | - } |
|
391 | - |
|
392 | - /** |
|
136 | + add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
137 | + |
|
138 | + // Fires after registering actions. |
|
139 | + do_action( 'wpinv_actions', $this ); |
|
140 | + do_action( 'getpaid_actions', $this ); |
|
141 | + |
|
142 | + } |
|
143 | + |
|
144 | + public function plugins_loaded() { |
|
145 | + /* Internationalize the text strings used. */ |
|
146 | + $this->load_textdomain(); |
|
147 | + |
|
148 | + do_action( 'wpinv_loaded' ); |
|
149 | + |
|
150 | + // Fix oxygen page builder conflict |
|
151 | + if ( function_exists( 'ct_css_output' ) ) { |
|
152 | + wpinv_oxygen_fix_conflict(); |
|
153 | + } |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Load the translation of the plugin. |
|
158 | + * |
|
159 | + * @since 1.0 |
|
160 | + */ |
|
161 | + public function load_textdomain( $locale = NULL ) { |
|
162 | + if ( empty( $locale ) ) { |
|
163 | + $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
164 | + } |
|
165 | + |
|
166 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
167 | + |
|
168 | + unload_textdomain( 'invoicing' ); |
|
169 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
170 | + load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
171 | + |
|
172 | + /** |
|
173 | + * Define language constants. |
|
174 | + */ |
|
175 | + require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Include required core files used in admin and on the frontend. |
|
180 | + */ |
|
181 | + public function includes() { |
|
182 | + |
|
183 | + // Start with the settings. |
|
184 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
185 | + |
|
186 | + // Packages/libraries. |
|
187 | + require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
188 | + require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
189 | + |
|
190 | + // Load functions. |
|
191 | + require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
192 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
193 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
194 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
195 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
196 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
197 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
198 | + require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
199 | + require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
200 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
201 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
202 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
203 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
204 | + require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' ); |
|
205 | + require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
206 | + |
|
207 | + // Register autoloader. |
|
208 | + try { |
|
209 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
210 | + } catch ( Exception $e ) { |
|
211 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
212 | + } |
|
213 | + |
|
214 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
215 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
216 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
217 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
218 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
219 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
220 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
221 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
222 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
223 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
224 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
225 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
226 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
227 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
228 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
229 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
230 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
231 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
232 | + require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
233 | + require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
234 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
235 | + |
|
236 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
237 | + GetPaid_Post_Types_Admin::init(); |
|
238 | + |
|
239 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
240 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
241 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
242 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
243 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
244 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
245 | + // load the user class only on the users.php page |
|
246 | + global $pagenow; |
|
247 | + if($pagenow=='users.php'){ |
|
248 | + new WPInv_Admin_Users(); |
|
249 | + } |
|
250 | + } |
|
251 | + |
|
252 | + // Register cli commands |
|
253 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
254 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
255 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
256 | + } |
|
257 | + |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Class autoloader |
|
262 | + * |
|
263 | + * @param string $class_name The name of the class to load. |
|
264 | + * @access public |
|
265 | + * @since 1.0.19 |
|
266 | + * @return void |
|
267 | + */ |
|
268 | + public function autoload( $class_name ) { |
|
269 | + |
|
270 | + // Normalize the class name... |
|
271 | + $class_name = strtolower( $class_name ); |
|
272 | + |
|
273 | + // ... and make sure it is our class. |
|
274 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
275 | + return; |
|
276 | + } |
|
277 | + |
|
278 | + // Next, prepare the file name from the class. |
|
279 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
280 | + |
|
281 | + // Base path of the classes. |
|
282 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
283 | + |
|
284 | + // And an array of possible locations in order of importance. |
|
285 | + $locations = array( |
|
286 | + "$plugin_path/includes", |
|
287 | + "$plugin_path/includes/data-stores", |
|
288 | + "$plugin_path/includes/gateways", |
|
289 | + "$plugin_path/includes/payments", |
|
290 | + "$plugin_path/includes/geolocation", |
|
291 | + "$plugin_path/includes/reports", |
|
292 | + "$plugin_path/includes/api", |
|
293 | + "$plugin_path/includes/admin", |
|
294 | + "$plugin_path/includes/admin/meta-boxes", |
|
295 | + ); |
|
296 | + |
|
297 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
298 | + |
|
299 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
300 | + include trailingslashit( $location ) . $file_name; |
|
301 | + break; |
|
302 | + } |
|
303 | + |
|
304 | + } |
|
305 | + |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Inits hooks etc. |
|
310 | + */ |
|
311 | + public function init() { |
|
312 | + |
|
313 | + // Fires before getpaid inits. |
|
314 | + do_action( 'before_getpaid_init', $this ); |
|
315 | + |
|
316 | + // Maybe upgrade. |
|
317 | + $this->maybe_upgrade_database(); |
|
318 | + |
|
319 | + // Load default gateways. |
|
320 | + $gateways = apply_filters( |
|
321 | + 'getpaid_default_gateways', |
|
322 | + array( |
|
323 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
324 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
325 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
326 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
327 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
328 | + ) |
|
329 | + ); |
|
330 | + |
|
331 | + foreach ( $gateways as $id => $class ) { |
|
332 | + $this->gateways[ $id ] = new $class(); |
|
333 | + } |
|
334 | + |
|
335 | + if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
336 | + GetPaid_Installer::rename_gateways_label(); |
|
337 | + update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
338 | + } |
|
339 | + |
|
340 | + // Fires after getpaid inits. |
|
341 | + do_action( 'getpaid_init', $this ); |
|
342 | + |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * Checks if this is an IPN request and processes it. |
|
347 | + */ |
|
348 | + public function maybe_process_ipn() { |
|
349 | + |
|
350 | + // Ensure that this is an IPN request. |
|
351 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
352 | + return; |
|
353 | + } |
|
354 | + |
|
355 | + $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
356 | + |
|
357 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
358 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
359 | + exit; |
|
360 | + |
|
361 | + } |
|
362 | + |
|
363 | + public function enqueue_scripts() { |
|
364 | + |
|
365 | + // Fires before adding scripts. |
|
366 | + do_action( 'getpaid_enqueue_scripts' ); |
|
367 | + |
|
368 | + $localize = array(); |
|
369 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
370 | + $localize['thousands'] = wpinv_thousands_separator(); |
|
371 | + $localize['decimals'] = wpinv_decimal_separator(); |
|
372 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
373 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
374 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
375 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
376 | + $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
377 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
378 | + |
|
379 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
380 | + |
|
381 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
382 | + wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
383 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
384 | + } |
|
385 | + |
|
386 | + public function wpinv_actions() { |
|
387 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
388 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
389 | + } |
|
390 | + } |
|
391 | + |
|
392 | + /** |
|
393 | 393 | * Fires an action after verifying that a user can fire them. |
394 | - * |
|
395 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
396 | - * current user owns the invoice/subscription. |
|
394 | + * |
|
395 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
396 | + * current user owns the invoice/subscription. |
|
397 | 397 | */ |
398 | 398 | public function maybe_do_authenticated_action() { |
399 | 399 | |
400 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
400 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
401 | + |
|
402 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
403 | + $data = wp_unslash( $_REQUEST ); |
|
404 | + if ( is_user_logged_in() ) { |
|
405 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
406 | + } |
|
407 | + |
|
408 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
409 | + |
|
410 | + } |
|
401 | 411 | |
402 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
403 | - $data = wp_unslash( $_REQUEST ); |
|
404 | - if ( is_user_logged_in() ) { |
|
405 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
406 | - } |
|
412 | + } |
|
407 | 413 | |
408 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
414 | + public function pre_get_posts( $wp_query ) { |
|
409 | 415 | |
410 | - } |
|
416 | + if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
417 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
418 | + } |
|
411 | 419 | |
420 | + return $wp_query; |
|
412 | 421 | } |
413 | 422 | |
414 | - public function pre_get_posts( $wp_query ) { |
|
415 | - |
|
416 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
417 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
418 | - } |
|
419 | - |
|
420 | - return $wp_query; |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * Register widgets |
|
425 | - * |
|
426 | - */ |
|
427 | - public function register_widgets() { |
|
428 | - |
|
429 | - // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
430 | - // So we disable our widgets when editing a page with UX Builder. |
|
431 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
432 | - return; |
|
433 | - } |
|
434 | - |
|
435 | - $widgets = apply_filters( |
|
436 | - 'getpaid_widget_classes', |
|
437 | - array( |
|
438 | - 'WPInv_Checkout_Widget', |
|
439 | - 'WPInv_History_Widget', |
|
440 | - 'WPInv_Receipt_Widget', |
|
441 | - 'WPInv_Subscriptions_Widget', |
|
442 | - 'WPInv_Buy_Item_Widget', |
|
443 | - 'WPInv_Messages_Widget', |
|
444 | - 'WPInv_GetPaid_Widget' |
|
445 | - ) |
|
446 | - ); |
|
447 | - |
|
448 | - foreach ( $widgets as $widget ) { |
|
449 | - register_widget( $widget ); |
|
450 | - } |
|
423 | + /** |
|
424 | + * Register widgets |
|
425 | + * |
|
426 | + */ |
|
427 | + public function register_widgets() { |
|
428 | + |
|
429 | + // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
430 | + // So we disable our widgets when editing a page with UX Builder. |
|
431 | + if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
432 | + return; |
|
433 | + } |
|
434 | + |
|
435 | + $widgets = apply_filters( |
|
436 | + 'getpaid_widget_classes', |
|
437 | + array( |
|
438 | + 'WPInv_Checkout_Widget', |
|
439 | + 'WPInv_History_Widget', |
|
440 | + 'WPInv_Receipt_Widget', |
|
441 | + 'WPInv_Subscriptions_Widget', |
|
442 | + 'WPInv_Buy_Item_Widget', |
|
443 | + 'WPInv_Messages_Widget', |
|
444 | + 'WPInv_GetPaid_Widget' |
|
445 | + ) |
|
446 | + ); |
|
447 | + |
|
448 | + foreach ( $widgets as $widget ) { |
|
449 | + register_widget( $widget ); |
|
450 | + } |
|
451 | 451 | |
452 | - } |
|
452 | + } |
|
453 | 453 | |
454 | - /** |
|
455 | - * Upgrades the database. |
|
456 | - * |
|
457 | - * @since 2.0.2 |
|
458 | - */ |
|
459 | - public function maybe_upgrade_database() { |
|
454 | + /** |
|
455 | + * Upgrades the database. |
|
456 | + * |
|
457 | + * @since 2.0.2 |
|
458 | + */ |
|
459 | + public function maybe_upgrade_database() { |
|
460 | 460 | |
461 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
461 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
462 | 462 | |
463 | - if ( $wpi_version == WPINV_VERSION ) { |
|
464 | - return; |
|
465 | - } |
|
463 | + if ( $wpi_version == WPINV_VERSION ) { |
|
464 | + return; |
|
465 | + } |
|
466 | 466 | |
467 | - $installer = new GetPaid_Installer(); |
|
467 | + $installer = new GetPaid_Installer(); |
|
468 | 468 | |
469 | - if ( empty( $wpi_version ) ) { |
|
470 | - return $installer->upgrade_db( 0 ); |
|
471 | - } |
|
469 | + if ( empty( $wpi_version ) ) { |
|
470 | + return $installer->upgrade_db( 0 ); |
|
471 | + } |
|
472 | 472 | |
473 | - $upgrades = array( |
|
474 | - '0.0.5' => '004', |
|
475 | - '1.0.3' => '102', |
|
476 | - '2.0.0' => '118', |
|
477 | - '2.0.8' => '207', |
|
478 | - ); |
|
473 | + $upgrades = array( |
|
474 | + '0.0.5' => '004', |
|
475 | + '1.0.3' => '102', |
|
476 | + '2.0.0' => '118', |
|
477 | + '2.0.8' => '207', |
|
478 | + ); |
|
479 | 479 | |
480 | - foreach ( $upgrades as $key => $method ) { |
|
480 | + foreach ( $upgrades as $key => $method ) { |
|
481 | 481 | |
482 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
483 | - return $installer->upgrade_db( $method ); |
|
484 | - } |
|
482 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
483 | + return $installer->upgrade_db( $method ); |
|
484 | + } |
|
485 | 485 | |
486 | - } |
|
486 | + } |
|
487 | 487 | |
488 | - } |
|
488 | + } |
|
489 | 489 | |
490 | - /** |
|
491 | - * Flushes the permalinks if needed. |
|
492 | - * |
|
493 | - * @since 2.0.8 |
|
494 | - */ |
|
495 | - public function maybe_flush_permalinks() { |
|
490 | + /** |
|
491 | + * Flushes the permalinks if needed. |
|
492 | + * |
|
493 | + * @since 2.0.8 |
|
494 | + */ |
|
495 | + public function maybe_flush_permalinks() { |
|
496 | 496 | |
497 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
497 | + $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
498 | 498 | |
499 | - if ( ! empty( $flush ) ) { |
|
500 | - flush_rewrite_rules(); |
|
501 | - delete_option( 'wpinv_flush_permalinks' ); |
|
502 | - } |
|
499 | + if ( ! empty( $flush ) ) { |
|
500 | + flush_rewrite_rules(); |
|
501 | + delete_option( 'wpinv_flush_permalinks' ); |
|
502 | + } |
|
503 | 503 | |
504 | - } |
|
504 | + } |
|
505 | 505 | |
506 | - /** |
|
507 | - * Remove our pages from yoast sitemaps. |
|
508 | - * |
|
509 | - * @since 1.0.19 |
|
510 | - * @param int[] $excluded_posts_ids |
|
511 | - */ |
|
512 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
506 | + /** |
|
507 | + * Remove our pages from yoast sitemaps. |
|
508 | + * |
|
509 | + * @since 1.0.19 |
|
510 | + * @param int[] $excluded_posts_ids |
|
511 | + */ |
|
512 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
513 | 513 | |
514 | - // Ensure that we have an array. |
|
515 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
516 | - $excluded_posts_ids = array(); |
|
517 | - } |
|
514 | + // Ensure that we have an array. |
|
515 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
516 | + $excluded_posts_ids = array(); |
|
517 | + } |
|
518 | 518 | |
519 | - // Prepare our pages. |
|
520 | - $our_pages = array(); |
|
519 | + // Prepare our pages. |
|
520 | + $our_pages = array(); |
|
521 | 521 | |
522 | - // Checkout page. |
|
523 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
522 | + // Checkout page. |
|
523 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
524 | 524 | |
525 | - // Success page. |
|
526 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
525 | + // Success page. |
|
526 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
527 | 527 | |
528 | - // Failure page. |
|
529 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
528 | + // Failure page. |
|
529 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
530 | 530 | |
531 | - // History page. |
|
532 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
531 | + // History page. |
|
532 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
533 | 533 | |
534 | - // Subscriptions page. |
|
535 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
534 | + // Subscriptions page. |
|
535 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
536 | 536 | |
537 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
537 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
538 | 538 | |
539 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
540 | - return array_unique( $excluded_posts_ids ); |
|
539 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
540 | + return array_unique( $excluded_posts_ids ); |
|
541 | 541 | |
542 | - } |
|
542 | + } |
|
543 | 543 | |
544 | - /** |
|
545 | - * Displays additional footer code. |
|
546 | - * |
|
547 | - * @since 2.0.0 |
|
548 | - */ |
|
549 | - public function wp_footer() { |
|
550 | - wpinv_get_template( 'frontend-footer.php' ); |
|
551 | - } |
|
544 | + /** |
|
545 | + * Displays additional footer code. |
|
546 | + * |
|
547 | + * @since 2.0.0 |
|
548 | + */ |
|
549 | + public function wp_footer() { |
|
550 | + wpinv_get_template( 'frontend-footer.php' ); |
|
551 | + } |
|
552 | 552 | |
553 | - /** |
|
554 | - * Displays additional header code. |
|
555 | - * |
|
556 | - * @since 2.0.0 |
|
557 | - */ |
|
558 | - public function wp_head() { |
|
559 | - wpinv_get_template( 'frontend-head.php' ); |
|
560 | - } |
|
553 | + /** |
|
554 | + * Displays additional header code. |
|
555 | + * |
|
556 | + * @since 2.0.0 |
|
557 | + */ |
|
558 | + public function wp_head() { |
|
559 | + wpinv_get_template( 'frontend-head.php' ); |
|
560 | + } |
|
561 | 561 | |
562 | - /** |
|
563 | - * Custom query vars. |
|
564 | - * |
|
565 | - */ |
|
566 | - public function custom_query_vars( $vars ) { |
|
562 | + /** |
|
563 | + * Custom query vars. |
|
564 | + * |
|
565 | + */ |
|
566 | + public function custom_query_vars( $vars ) { |
|
567 | 567 | $vars[] = 'getpaid-ipn'; |
568 | 568 | return $vars; |
569 | - } |
|
569 | + } |
|
570 | 570 | |
571 | - /** |
|
572 | - * Add rewrite tags and rules. |
|
573 | - * |
|
574 | - */ |
|
575 | - public function add_rewrite_rule() { |
|
571 | + /** |
|
572 | + * Add rewrite tags and rules. |
|
573 | + * |
|
574 | + */ |
|
575 | + public function add_rewrite_rule() { |
|
576 | 576 | $tag = 'getpaid-ipn'; |
577 | 577 | add_rewrite_tag( "%$tag%", '([^&]+)' ); |
578 | 578 | add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]",'top' ); |
579 | - } |
|
579 | + } |
|
580 | 580 | |
581 | - /** |
|
582 | - * Processes non-query string ipns. |
|
583 | - * |
|
584 | - */ |
|
585 | - public function maybe_process_new_ipn( $query ) { |
|
581 | + /** |
|
582 | + * Processes non-query string ipns. |
|
583 | + * |
|
584 | + */ |
|
585 | + public function maybe_process_new_ipn( $query ) { |
|
586 | 586 | |
587 | 587 | if ( is_admin() || ! $query->is_main_query() ) { |
588 | 588 | return; |
589 | 589 | } |
590 | 590 | |
591 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
591 | + $gateway = get_query_var( 'getpaid-ipn' ); |
|
592 | 592 | |
593 | 593 | if ( ! empty( $gateway ) ){ |
594 | 594 | |
595 | - $gateway = sanitize_text_field( $gateway ); |
|
596 | - nocache_headers(); |
|
597 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
598 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
599 | - exit; |
|
595 | + $gateway = sanitize_text_field( $gateway ); |
|
596 | + nocache_headers(); |
|
597 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
598 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
599 | + exit; |
|
600 | 600 | |
601 | 601 | } |
602 | 602 | |
603 | - } |
|
603 | + } |
|
604 | 604 | |
605 | 605 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 1.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Main Invoicing class. |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | * @param string $prop The prop to set. |
57 | 57 | * @param mixed $value The value to retrieve. |
58 | 58 | */ |
59 | - public function set( $prop, $value ) { |
|
60 | - $this->data[ $prop ] = $value; |
|
59 | + public function set($prop, $value) { |
|
60 | + $this->data[$prop] = $value; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | * @param string $prop The prop to set. |
67 | 67 | * @return mixed The value. |
68 | 68 | */ |
69 | - public function get( $prop ) { |
|
69 | + public function get($prop) { |
|
70 | 70 | |
71 | - if ( isset( $this->data[ $prop ] ) ) { |
|
72 | - return $this->data[ $prop ]; |
|
71 | + if (isset($this->data[$prop])) { |
|
72 | + return $this->data[$prop]; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | return null; |
@@ -81,23 +81,23 @@ discard block |
||
81 | 81 | public function set_properties() { |
82 | 82 | |
83 | 83 | // Sessions. |
84 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
84 | + $this->set('session', new WPInv_Session_Handler()); |
|
85 | + $GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility. |
|
86 | 86 | $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
87 | 87 | |
88 | 88 | // Init other objects. |
89 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
90 | - $this->set( 'notes', new WPInv_Notes() ); |
|
91 | - $this->set( 'api', new WPInv_API() ); |
|
92 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | - $this->set( 'template', new GetPaid_Template() ); |
|
94 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
89 | + $this->set('session', new WPInv_Session_Handler()); |
|
90 | + $this->set('notes', new WPInv_Notes()); |
|
91 | + $this->set('api', new WPInv_API()); |
|
92 | + $this->set('post_types', new GetPaid_Post_Types()); |
|
93 | + $this->set('template', new GetPaid_Template()); |
|
94 | + $this->set('admin', new GetPaid_Admin()); |
|
95 | + $this->set('subscriptions', new WPInv_Subscriptions()); |
|
96 | + $this->set('invoice_emails', new GetPaid_Invoice_Notification_Emails()); |
|
97 | + $this->set('subscription_emails', new GetPaid_Subscription_Notification_Emails()); |
|
98 | + $this->set('daily_maintenace', new GetPaid_Daily_Maintenance()); |
|
99 | + $this->set('payment_forms', new GetPaid_Payment_Forms()); |
|
100 | + $this->set('maxmind', new GetPaid_MaxMind_Geolocation()); |
|
101 | 101 | |
102 | 102 | } |
103 | 103 | |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | * Define plugin constants. |
106 | 106 | */ |
107 | 107 | public function define_constants() { |
108 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
108 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
109 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
110 | 110 | $this->version = WPINV_VERSION; |
111 | 111 | } |
112 | 112 | |
@@ -117,27 +117,27 @@ discard block |
||
117 | 117 | */ |
118 | 118 | protected function init_hooks() { |
119 | 119 | /* Internationalize the text strings used. */ |
120 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
120 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
121 | 121 | |
122 | 122 | // Init the plugin after WordPress inits. |
123 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
127 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
128 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
129 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
130 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
131 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
132 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
133 | - |
|
134 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
135 | - add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
136 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
123 | + add_action('init', array($this, 'init'), 1); |
|
124 | + add_action('init', array($this, 'maybe_process_ipn'), 10); |
|
125 | + add_action('init', array($this, 'wpinv_actions')); |
|
126 | + add_action('init', array($this, 'maybe_do_authenticated_action'), 100); |
|
127 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 11); |
|
128 | + add_action('wp_footer', array($this, 'wp_footer')); |
|
129 | + add_action('wp_head', array($this, 'wp_head')); |
|
130 | + add_action('widgets_init', array(&$this, 'register_widgets')); |
|
131 | + add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids')); |
|
132 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
133 | + |
|
134 | + add_filter('query_vars', array($this, 'custom_query_vars')); |
|
135 | + add_action('init', array($this, 'add_rewrite_rule'), 10, 0); |
|
136 | + add_action('pre_get_posts', array($this, 'maybe_process_new_ipn'), 1); |
|
137 | 137 | |
138 | 138 | // Fires after registering actions. |
139 | - do_action( 'wpinv_actions', $this ); |
|
140 | - do_action( 'getpaid_actions', $this ); |
|
139 | + do_action('wpinv_actions', $this); |
|
140 | + do_action('getpaid_actions', $this); |
|
141 | 141 | |
142 | 142 | } |
143 | 143 | |
@@ -145,10 +145,10 @@ discard block |
||
145 | 145 | /* Internationalize the text strings used. */ |
146 | 146 | $this->load_textdomain(); |
147 | 147 | |
148 | - do_action( 'wpinv_loaded' ); |
|
148 | + do_action('wpinv_loaded'); |
|
149 | 149 | |
150 | 150 | // Fix oxygen page builder conflict |
151 | - if ( function_exists( 'ct_css_output' ) ) { |
|
151 | + if (function_exists('ct_css_output')) { |
|
152 | 152 | wpinv_oxygen_fix_conflict(); |
153 | 153 | } |
154 | 154 | } |
@@ -158,21 +158,21 @@ discard block |
||
158 | 158 | * |
159 | 159 | * @since 1.0 |
160 | 160 | */ |
161 | - public function load_textdomain( $locale = NULL ) { |
|
162 | - if ( empty( $locale ) ) { |
|
163 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
161 | + public function load_textdomain($locale = NULL) { |
|
162 | + if (empty($locale)) { |
|
163 | + $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
|
164 | 164 | } |
165 | 165 | |
166 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
166 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
167 | 167 | |
168 | - unload_textdomain( 'invoicing' ); |
|
169 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
170 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
168 | + unload_textdomain('invoicing'); |
|
169 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
170 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
171 | 171 | |
172 | 172 | /** |
173 | 173 | * Define language constants. |
174 | 174 | */ |
175 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
175 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -181,78 +181,78 @@ discard block |
||
181 | 181 | public function includes() { |
182 | 182 | |
183 | 183 | // Start with the settings. |
184 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
184 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
185 | 185 | |
186 | 186 | // Packages/libraries. |
187 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
188 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
187 | + require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php'); |
|
188 | + require_once(WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'); |
|
189 | 189 | |
190 | 190 | // Load functions. |
191 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
192 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
193 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
194 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
195 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
196 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
198 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
199 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
200 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' ); |
|
205 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
191 | + require_once(WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'); |
|
192 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
193 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
194 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
195 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
196 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
197 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
198 | + require_once(WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'); |
|
199 | + require_once(WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'); |
|
200 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
201 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
202 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
203 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
204 | + require_once(WPINV_PLUGIN_DIR . 'includes/user-functions.php'); |
|
205 | + require_once(WPINV_PLUGIN_DIR . 'includes/error-functions.php'); |
|
206 | 206 | |
207 | 207 | // Register autoloader. |
208 | 208 | try { |
209 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
210 | - } catch ( Exception $e ) { |
|
211 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
209 | + spl_autoload_register(array($this, 'autoload'), true); |
|
210 | + } catch (Exception $e) { |
|
211 | + wpinv_error_log($e->getMessage(), '', __FILE__, 149, true); |
|
212 | 212 | } |
213 | 213 | |
214 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
215 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
216 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
217 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
218 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
219 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
220 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
221 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
222 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
223 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
224 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
234 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
235 | - |
|
236 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
214 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'); |
|
215 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'); |
|
216 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
217 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
218 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'); |
|
219 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'); |
|
220 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'); |
|
221 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'); |
|
222 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'); |
|
223 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'); |
|
224 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'); |
|
225 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'); |
|
226 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'); |
|
227 | + require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php'); |
|
228 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'); |
|
229 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'); |
|
230 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'); |
|
231 | + require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'); |
|
232 | + require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php'); |
|
233 | + require_once(WPINV_PLUGIN_DIR . 'widgets/getpaid.php'); |
|
234 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
235 | + |
|
236 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
237 | 237 | GetPaid_Post_Types_Admin::init(); |
238 | 238 | |
239 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
240 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
241 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
242 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
243 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
244 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
239 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
240 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'); |
|
241 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
242 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'); |
|
243 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'); |
|
244 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'); |
|
245 | 245 | // load the user class only on the users.php page |
246 | 246 | global $pagenow; |
247 | - if($pagenow=='users.php'){ |
|
247 | + if ($pagenow == 'users.php') { |
|
248 | 248 | new WPInv_Admin_Users(); |
249 | 249 | } |
250 | 250 | } |
251 | 251 | |
252 | 252 | // Register cli commands |
253 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
254 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
255 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
253 | + if (defined('WP_CLI') && WP_CLI) { |
|
254 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'); |
|
255 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | } |
@@ -265,21 +265,21 @@ discard block |
||
265 | 265 | * @since 1.0.19 |
266 | 266 | * @return void |
267 | 267 | */ |
268 | - public function autoload( $class_name ) { |
|
268 | + public function autoload($class_name) { |
|
269 | 269 | |
270 | 270 | // Normalize the class name... |
271 | - $class_name = strtolower( $class_name ); |
|
271 | + $class_name = strtolower($class_name); |
|
272 | 272 | |
273 | 273 | // ... and make sure it is our class. |
274 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
274 | + if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) { |
|
275 | 275 | return; |
276 | 276 | } |
277 | 277 | |
278 | 278 | // Next, prepare the file name from the class. |
279 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
279 | + $file_name = 'class-' . str_replace('_', '-', $class_name) . '.php'; |
|
280 | 280 | |
281 | 281 | // Base path of the classes. |
282 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
282 | + $plugin_path = untrailingslashit(WPINV_PLUGIN_DIR); |
|
283 | 283 | |
284 | 284 | // And an array of possible locations in order of importance. |
285 | 285 | $locations = array( |
@@ -294,10 +294,10 @@ discard block |
||
294 | 294 | "$plugin_path/includes/admin/meta-boxes", |
295 | 295 | ); |
296 | 296 | |
297 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
297 | + foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) { |
|
298 | 298 | |
299 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
300 | - include trailingslashit( $location ) . $file_name; |
|
299 | + if (file_exists(trailingslashit($location) . $file_name)) { |
|
300 | + include trailingslashit($location) . $file_name; |
|
301 | 301 | break; |
302 | 302 | } |
303 | 303 | |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | public function init() { |
312 | 312 | |
313 | 313 | // Fires before getpaid inits. |
314 | - do_action( 'before_getpaid_init', $this ); |
|
314 | + do_action('before_getpaid_init', $this); |
|
315 | 315 | |
316 | 316 | // Maybe upgrade. |
317 | 317 | $this->maybe_upgrade_database(); |
@@ -328,17 +328,17 @@ discard block |
||
328 | 328 | ) |
329 | 329 | ); |
330 | 330 | |
331 | - foreach ( $gateways as $id => $class ) { |
|
332 | - $this->gateways[ $id ] = new $class(); |
|
331 | + foreach ($gateways as $id => $class) { |
|
332 | + $this->gateways[$id] = new $class(); |
|
333 | 333 | } |
334 | 334 | |
335 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
335 | + if ('yes' != get_option('wpinv_renamed_gateways')) { |
|
336 | 336 | GetPaid_Installer::rename_gateways_label(); |
337 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
337 | + update_option('wpinv_renamed_gateways', 'yes'); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | // Fires after getpaid inits. |
341 | - do_action( 'getpaid_init', $this ); |
|
341 | + do_action('getpaid_init', $this); |
|
342 | 342 | |
343 | 343 | } |
344 | 344 | |
@@ -348,14 +348,14 @@ discard block |
||
348 | 348 | public function maybe_process_ipn() { |
349 | 349 | |
350 | 350 | // Ensure that this is an IPN request. |
351 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
351 | + if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) { |
|
352 | 352 | return; |
353 | 353 | } |
354 | 354 | |
355 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
355 | + $gateway = wpinv_clean($_GET['wpi-gateway']); |
|
356 | 356 | |
357 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
358 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
357 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
358 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
359 | 359 | exit; |
360 | 360 | |
361 | 361 | } |
@@ -363,29 +363,29 @@ discard block |
||
363 | 363 | public function enqueue_scripts() { |
364 | 364 | |
365 | 365 | // Fires before adding scripts. |
366 | - do_action( 'getpaid_enqueue_scripts' ); |
|
366 | + do_action('getpaid_enqueue_scripts'); |
|
367 | 367 | |
368 | 368 | $localize = array(); |
369 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
369 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
370 | 370 | $localize['thousands'] = wpinv_thousands_separator(); |
371 | 371 | $localize['decimals'] = wpinv_decimal_separator(); |
372 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
373 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
372 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
373 | + $localize['txtComplete'] = __('Continue', 'invoicing'); |
|
374 | 374 | $localize['UseTaxes'] = wpinv_use_taxes(); |
375 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
376 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
377 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
375 | + $localize['formNonce'] = wp_create_nonce('getpaid_form_nonce'); |
|
376 | + $localize['loading'] = __('Loading...', 'invoicing'); |
|
377 | + $localize['connectionError'] = __('Could not establish a connection to the server.', 'invoicing'); |
|
378 | 378 | |
379 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
379 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
380 | 380 | |
381 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
382 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
383 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
381 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js'); |
|
382 | + wp_enqueue_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('jquery'), $version, true); |
|
383 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | public function wpinv_actions() { |
387 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
388 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
387 | + if (isset($_REQUEST['wpi_action'])) { |
|
388 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
389 | 389 | } |
390 | 390 | } |
391 | 391 | |
@@ -397,24 +397,24 @@ discard block |
||
397 | 397 | */ |
398 | 398 | public function maybe_do_authenticated_action() { |
399 | 399 | |
400 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
400 | + if (isset($_REQUEST['getpaid-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
401 | 401 | |
402 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
403 | - $data = wp_unslash( $_REQUEST ); |
|
404 | - if ( is_user_logged_in() ) { |
|
405 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
402 | + $key = sanitize_key($_REQUEST['getpaid-action']); |
|
403 | + $data = wp_unslash($_REQUEST); |
|
404 | + if (is_user_logged_in()) { |
|
405 | + do_action("getpaid_authenticated_action_$key", $data); |
|
406 | 406 | } |
407 | 407 | |
408 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
408 | + do_action("getpaid_unauthenticated_action_$key", $data); |
|
409 | 409 | |
410 | 410 | } |
411 | 411 | |
412 | 412 | } |
413 | 413 | |
414 | - public function pre_get_posts( $wp_query ) { |
|
414 | + public function pre_get_posts($wp_query) { |
|
415 | 415 | |
416 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
417 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
416 | + if (!is_admin() && !empty($wp_query->query_vars['post_type']) && getpaid_is_invoice_post_type($wp_query->query_vars['post_type']) && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
417 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses(false, false, $wp_query->query_vars['post_type'])); |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | return $wp_query; |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | |
429 | 429 | // Currently, UX Builder does not work particulaly well with SuperDuper. |
430 | 430 | // So we disable our widgets when editing a page with UX Builder. |
431 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
431 | + if (function_exists('ux_builder_is_active') && ux_builder_is_active()) { |
|
432 | 432 | return; |
433 | 433 | } |
434 | 434 | |
@@ -445,8 +445,8 @@ discard block |
||
445 | 445 | ) |
446 | 446 | ); |
447 | 447 | |
448 | - foreach ( $widgets as $widget ) { |
|
449 | - register_widget( $widget ); |
|
448 | + foreach ($widgets as $widget) { |
|
449 | + register_widget($widget); |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | } |
@@ -458,29 +458,29 @@ discard block |
||
458 | 458 | */ |
459 | 459 | public function maybe_upgrade_database() { |
460 | 460 | |
461 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
461 | + $wpi_version = get_option('wpinv_version', 0); |
|
462 | 462 | |
463 | - if ( $wpi_version == WPINV_VERSION ) { |
|
463 | + if ($wpi_version == WPINV_VERSION) { |
|
464 | 464 | return; |
465 | 465 | } |
466 | 466 | |
467 | 467 | $installer = new GetPaid_Installer(); |
468 | 468 | |
469 | - if ( empty( $wpi_version ) ) { |
|
470 | - return $installer->upgrade_db( 0 ); |
|
469 | + if (empty($wpi_version)) { |
|
470 | + return $installer->upgrade_db(0); |
|
471 | 471 | } |
472 | 472 | |
473 | - $upgrades = array( |
|
473 | + $upgrades = array( |
|
474 | 474 | '0.0.5' => '004', |
475 | 475 | '1.0.3' => '102', |
476 | 476 | '2.0.0' => '118', |
477 | 477 | '2.0.8' => '207', |
478 | 478 | ); |
479 | 479 | |
480 | - foreach ( $upgrades as $key => $method ) { |
|
480 | + foreach ($upgrades as $key => $method) { |
|
481 | 481 | |
482 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
483 | - return $installer->upgrade_db( $method ); |
|
482 | + if (version_compare($wpi_version, $key, '<')) { |
|
483 | + return $installer->upgrade_db($method); |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | } |
@@ -494,11 +494,11 @@ discard block |
||
494 | 494 | */ |
495 | 495 | public function maybe_flush_permalinks() { |
496 | 496 | |
497 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
497 | + $flush = get_option('wpinv_flush_permalinks', 0); |
|
498 | 498 | |
499 | - if ( ! empty( $flush ) ) { |
|
499 | + if (!empty($flush)) { |
|
500 | 500 | flush_rewrite_rules(); |
501 | - delete_option( 'wpinv_flush_permalinks' ); |
|
501 | + delete_option('wpinv_flush_permalinks'); |
|
502 | 502 | } |
503 | 503 | |
504 | 504 | } |
@@ -509,10 +509,10 @@ discard block |
||
509 | 509 | * @since 1.0.19 |
510 | 510 | * @param int[] $excluded_posts_ids |
511 | 511 | */ |
512 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
512 | + public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) { |
|
513 | 513 | |
514 | 514 | // Ensure that we have an array. |
515 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
515 | + if (!is_array($excluded_posts_ids)) { |
|
516 | 516 | $excluded_posts_ids = array(); |
517 | 517 | } |
518 | 518 | |
@@ -520,24 +520,24 @@ discard block |
||
520 | 520 | $our_pages = array(); |
521 | 521 | |
522 | 522 | // Checkout page. |
523 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
523 | + $our_pages[] = wpinv_get_option('checkout_page', false); |
|
524 | 524 | |
525 | 525 | // Success page. |
526 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
526 | + $our_pages[] = wpinv_get_option('success_page', false); |
|
527 | 527 | |
528 | 528 | // Failure page. |
529 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
529 | + $our_pages[] = wpinv_get_option('failure_page', false); |
|
530 | 530 | |
531 | 531 | // History page. |
532 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
532 | + $our_pages[] = wpinv_get_option('invoice_history_page', false); |
|
533 | 533 | |
534 | 534 | // Subscriptions page. |
535 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
535 | + $our_pages[] = wpinv_get_option('invoice_subscription_page', false); |
|
536 | 536 | |
537 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
537 | + $our_pages = array_map('intval', array_filter($our_pages)); |
|
538 | 538 | |
539 | 539 | $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
540 | - return array_unique( $excluded_posts_ids ); |
|
540 | + return array_unique($excluded_posts_ids); |
|
541 | 541 | |
542 | 542 | } |
543 | 543 | |
@@ -547,7 +547,7 @@ discard block |
||
547 | 547 | * @since 2.0.0 |
548 | 548 | */ |
549 | 549 | public function wp_footer() { |
550 | - wpinv_get_template( 'frontend-footer.php' ); |
|
550 | + wpinv_get_template('frontend-footer.php'); |
|
551 | 551 | } |
552 | 552 | |
553 | 553 | /** |
@@ -556,14 +556,14 @@ discard block |
||
556 | 556 | * @since 2.0.0 |
557 | 557 | */ |
558 | 558 | public function wp_head() { |
559 | - wpinv_get_template( 'frontend-head.php' ); |
|
559 | + wpinv_get_template('frontend-head.php'); |
|
560 | 560 | } |
561 | 561 | |
562 | 562 | /** |
563 | 563 | * Custom query vars. |
564 | 564 | * |
565 | 565 | */ |
566 | - public function custom_query_vars( $vars ) { |
|
566 | + public function custom_query_vars($vars) { |
|
567 | 567 | $vars[] = 'getpaid-ipn'; |
568 | 568 | return $vars; |
569 | 569 | } |
@@ -574,28 +574,28 @@ discard block |
||
574 | 574 | */ |
575 | 575 | public function add_rewrite_rule() { |
576 | 576 | $tag = 'getpaid-ipn'; |
577 | - add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
578 | - add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]",'top' ); |
|
577 | + add_rewrite_tag("%$tag%", '([^&]+)'); |
|
578 | + add_rewrite_rule("^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top'); |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | /** |
582 | 582 | * Processes non-query string ipns. |
583 | 583 | * |
584 | 584 | */ |
585 | - public function maybe_process_new_ipn( $query ) { |
|
585 | + public function maybe_process_new_ipn($query) { |
|
586 | 586 | |
587 | - if ( is_admin() || ! $query->is_main_query() ) { |
|
587 | + if (is_admin() || !$query->is_main_query()) { |
|
588 | 588 | return; |
589 | 589 | } |
590 | 590 | |
591 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
591 | + $gateway = get_query_var('getpaid-ipn'); |
|
592 | 592 | |
593 | - if ( ! empty( $gateway ) ){ |
|
593 | + if (!empty($gateway)) { |
|
594 | 594 | |
595 | - $gateway = sanitize_text_field( $gateway ); |
|
595 | + $gateway = sanitize_text_field($gateway); |
|
596 | 596 | nocache_headers(); |
597 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
598 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
597 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
598 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
599 | 599 | exit; |
600 | 600 | |
601 | 601 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | class GetPaid_Meta_Box_Item_Details { |
18 | 18 | |
19 | 19 | /** |
20 | - * Output the metabox. |
|
21 | - * |
|
22 | - * @param WP_Post $post |
|
23 | - */ |
|
20 | + * Output the metabox. |
|
21 | + * |
|
22 | + * @param WP_Post $post |
|
23 | + */ |
|
24 | 24 | public static function output( $post ) { |
25 | 25 | |
26 | 26 | // Prepare the item. |
@@ -270,35 +270,35 @@ discard block |
||
270 | 270 | } |
271 | 271 | |
272 | 272 | /** |
273 | - * Save meta box data. |
|
274 | - * |
|
275 | - * @param int $post_id |
|
276 | - */ |
|
277 | - public static function save( $post_id ) { |
|
273 | + * Save meta box data. |
|
274 | + * |
|
275 | + * @param int $post_id |
|
276 | + */ |
|
277 | + public static function save( $post_id ) { |
|
278 | 278 | |
279 | 279 | // Prepare the item. |
280 | 280 | $item = new WPInv_Item( $post_id ); |
281 | 281 | |
282 | 282 | // Load new data. |
283 | 283 | $item->set_props( |
284 | - array( |
|
285 | - 'price' => isset( $_POST['wpinv_item_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_item_price'] ) : null, |
|
286 | - 'vat_rule' => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null, |
|
287 | - 'vat_class' => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null, |
|
288 | - 'type' => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null, |
|
289 | - 'is_dynamic_pricing' => isset( $_POST['wpinv_name_your_price'] ), |
|
284 | + array( |
|
285 | + 'price' => isset( $_POST['wpinv_item_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_item_price'] ) : null, |
|
286 | + 'vat_rule' => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null, |
|
287 | + 'vat_class' => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null, |
|
288 | + 'type' => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null, |
|
289 | + 'is_dynamic_pricing' => isset( $_POST['wpinv_name_your_price'] ), |
|
290 | 290 | 'minimum_price' => isset( $_POST['wpinv_minimum_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_minimum_price'] ) : null, |
291 | - 'is_recurring' => isset( $_POST['wpinv_is_recurring'] ), |
|
292 | - 'recurring_period' => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null, |
|
293 | - 'recurring_interval' => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : 1, |
|
294 | - 'recurring_limit' => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null, |
|
295 | - 'is_free_trial' => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null, |
|
296 | - 'trial_period' => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null, |
|
297 | - 'trial_interval' => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null, |
|
298 | - ) |
|
291 | + 'is_recurring' => isset( $_POST['wpinv_is_recurring'] ), |
|
292 | + 'recurring_period' => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null, |
|
293 | + 'recurring_interval' => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : 1, |
|
294 | + 'recurring_limit' => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null, |
|
295 | + 'is_free_trial' => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null, |
|
296 | + 'trial_period' => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null, |
|
297 | + 'trial_interval' => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null, |
|
298 | + ) |
|
299 | 299 | ); |
300 | 300 | |
301 | - $item->save(); |
|
302 | - do_action( 'getpaid_item_metabox_save', $post_id, $item ); |
|
303 | - } |
|
301 | + $item->save(); |
|
302 | + do_action( 'getpaid_item_metabox_save', $post_id, $item ); |
|
303 | + } |
|
304 | 304 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if (!defined('ABSPATH')) { |
|
11 | 11 | exit; // Exit if accessed directly |
12 | 12 | } |
13 | 13 | |
@@ -21,27 +21,27 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param WP_Post $post |
23 | 23 | */ |
24 | - public static function output( $post ) { |
|
24 | + public static function output($post) { |
|
25 | 25 | |
26 | 26 | // Prepare the item. |
27 | - $item = new WPInv_Item( $post ); |
|
27 | + $item = new WPInv_Item($post); |
|
28 | 28 | |
29 | 29 | // Nonce field. |
30 | - wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
30 | + wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce'); |
|
31 | 31 | |
32 | 32 | // Set the currency position. |
33 | 33 | $position = wpinv_currency_position(); |
34 | 34 | |
35 | - if ( $position == 'left_space' ) { |
|
35 | + if ($position == 'left_space') { |
|
36 | 36 | $position = 'left'; |
37 | 37 | } |
38 | 38 | |
39 | - if ( $position == 'right_space' ) { |
|
39 | + if ($position == 'right_space') { |
|
40 | 40 | $position = 'right'; |
41 | 41 | } |
42 | 42 | |
43 | 43 | ?> |
44 | - <input type="hidden" id="_wpi_current_type" value="<?php echo esc_attr( $item->get_type( 'edit' ) ); ?>" /> |
|
44 | + <input type="hidden" id="_wpi_current_type" value="<?php echo esc_attr($item->get_type('edit')); ?>" /> |
|
45 | 45 | <style> |
46 | 46 | #poststuff .input-group-text, |
47 | 47 | #poststuff .form-control { |
@@ -55,21 +55,21 @@ discard block |
||
55 | 55 | </style> |
56 | 56 | <div class='bsui' style='max-width: 600px;padding-top: 10px;'> |
57 | 57 | |
58 | - <?php do_action( 'wpinv_item_details_metabox_before_price', $item ); ?> |
|
58 | + <?php do_action('wpinv_item_details_metabox_before_price', $item); ?> |
|
59 | 59 | <div class="form-group row"> |
60 | - <label class="col-sm-3 col-form-label" for="wpinv_item_price"><span><?php _e( 'Item Price', 'invoicing' )?></span></label> |
|
60 | + <label class="col-sm-3 col-form-label" for="wpinv_item_price"><span><?php _e('Item Price', 'invoicing')?></span></label> |
|
61 | 61 | <div class="col-sm-8"> |
62 | 62 | <div class="row"> |
63 | 63 | <div class="col-sm-4 getpaid-price-input"> |
64 | 64 | <div class="input-group input-group-sm"> |
65 | - <?php if( 'left' == $position ) : ?> |
|
65 | + <?php if ('left' == $position) : ?> |
|
66 | 66 | <div class="input-group-prepend"> |
67 | 67 | <span class="input-group-text" id="wpinv_item_price_symbol"><?php echo wpinv_currency_symbol(); ?></span> |
68 | 68 | </div> |
69 | 69 | <?php endif; ?> |
70 | - <input type="text" name="wpinv_item_price" id="wpinv_item_price" value="<?php echo esc_attr( getpaid_unstandardize_amount( $item->get_price( 'edit' ) ) ); ?>" placeholder="<?php echo esc_attr( wpinv_sanitize_amount( 0 ) ); ?>" class="form-control"> |
|
70 | + <input type="text" name="wpinv_item_price" id="wpinv_item_price" value="<?php echo esc_attr(getpaid_unstandardize_amount($item->get_price('edit'))); ?>" placeholder="<?php echo esc_attr(wpinv_sanitize_amount(0)); ?>" class="form-control"> |
|
71 | 71 | |
72 | - <?php if( 'left' != $position ) : ?> |
|
72 | + <?php if ('left' != $position) : ?> |
|
73 | 73 | <div class="input-group-append"> |
74 | 74 | <span class="input-group-text" id="wpinv_item_price_symbol"><?php echo wpinv_currency_symbol(); ?></span> |
75 | 75 | </div> |
@@ -79,10 +79,10 @@ discard block |
||
79 | 79 | </div> |
80 | 80 | <div class="col-sm-4 wpinv_show_if_recurring"> |
81 | 81 | <?php |
82 | - _e( 'every' ); |
|
82 | + _e('every'); |
|
83 | 83 | echo " "; |
84 | 84 | ?> |
85 | - <input type="number" style="max-width: 60px;" value="<?php echo esc_attr( $item->get_recurring_interval( 'edit' ) ); ?>" placeholder="1" name="wpinv_recurring_interval" id="wpinv_recurring_interval" /> |
|
85 | + <input type="number" style="max-width: 60px;" value="<?php echo esc_attr($item->get_recurring_interval('edit')); ?>" placeholder="1" name="wpinv_recurring_interval" id="wpinv_recurring_interval" /> |
|
86 | 86 | </div> |
87 | 87 | <div class="col-sm-4 wpinv_show_if_recurring"> |
88 | 88 | <?php |
@@ -90,16 +90,16 @@ discard block |
||
90 | 90 | array( |
91 | 91 | 'id' => 'wpinv_recurring_period', |
92 | 92 | 'name' => 'wpinv_recurring_period', |
93 | - 'label' => __( 'Period', 'invoicing' ), |
|
94 | - 'placeholder' => __( 'Select Period', 'invoicing' ), |
|
95 | - 'value' => $item->get_recurring_period( 'edit' ), |
|
93 | + 'label' => __('Period', 'invoicing'), |
|
94 | + 'placeholder' => __('Select Period', 'invoicing'), |
|
95 | + 'value' => $item->get_recurring_period('edit'), |
|
96 | 96 | 'select2' => true, |
97 | 97 | 'data-allow-clear' => 'false', |
98 | 98 | 'options' => array( |
99 | - 'D' => __( 'day(s)', 'invoicing' ), |
|
100 | - 'W' => __( 'week(s)', 'invoicing' ), |
|
101 | - 'M' => __( 'month(s)', 'invoicing' ), |
|
102 | - 'Y' => __( 'year(s)', 'invoicing' ), |
|
99 | + 'D' => __('day(s)', 'invoicing'), |
|
100 | + 'W' => __('week(s)', 'invoicing'), |
|
101 | + 'M' => __('month(s)', 'invoicing'), |
|
102 | + 'Y' => __('year(s)', 'invoicing'), |
|
103 | 103 | ) |
104 | 104 | ) |
105 | 105 | ); |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | <?php |
112 | 112 | |
113 | 113 | // Dynamic pricing. |
114 | - if( $item->supports_dynamic_pricing() ) { |
|
114 | + if ($item->supports_dynamic_pricing()) { |
|
115 | 115 | |
116 | - do_action( 'wpinv_item_details_metabox_before_dynamic_pricing_checkbox', $item ); |
|
116 | + do_action('wpinv_item_details_metabox_before_dynamic_pricing_checkbox', $item); |
|
117 | 117 | |
118 | 118 | // NYP toggle. |
119 | 119 | echo aui()->input( |
@@ -121,31 +121,31 @@ discard block |
||
121 | 121 | 'id' => 'wpinv_name_your_price', |
122 | 122 | 'name' => 'wpinv_name_your_price', |
123 | 123 | 'type' => 'checkbox', |
124 | - 'label' => apply_filters( 'wpinv_name_your_price_toggle_text', __( 'Let customers name their price', 'invoicing' ) ), |
|
124 | + 'label' => apply_filters('wpinv_name_your_price_toggle_text', __('Let customers name their price', 'invoicing')), |
|
125 | 125 | 'value' => '1', |
126 | 126 | 'checked' => $item->user_can_set_their_price(), |
127 | 127 | 'no_wrap' => true, |
128 | 128 | ) |
129 | 129 | ); |
130 | 130 | |
131 | - do_action( 'wpinv_item_details_metabox_dynamic_pricing_checkbox', $item ); |
|
131 | + do_action('wpinv_item_details_metabox_dynamic_pricing_checkbox', $item); |
|
132 | 132 | |
133 | 133 | } |
134 | 134 | |
135 | 135 | // Subscriptions. |
136 | - do_action( 'wpinv_item_details_metabox_before_subscription_checkbox', $item ); |
|
136 | + do_action('wpinv_item_details_metabox_before_subscription_checkbox', $item); |
|
137 | 137 | echo aui()->input( |
138 | 138 | array( |
139 | 139 | 'id' => 'wpinv_is_recurring', |
140 | 140 | 'name' => 'wpinv_is_recurring', |
141 | 141 | 'type' => 'checkbox', |
142 | - 'label' => apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Charge customers a recurring amount for this item', 'invoicing' ) ), |
|
142 | + 'label' => apply_filters('wpinv_is_recurring_toggle_text', __('Charge customers a recurring amount for this item', 'invoicing')), |
|
143 | 143 | 'value' => '1', |
144 | 144 | 'checked' => $item->is_recurring(), |
145 | 145 | 'no_wrap' => true, |
146 | 146 | ) |
147 | 147 | ); |
148 | - do_action( 'wpinv_item_details_metabox_subscription_checkbox', $item ); |
|
148 | + do_action('wpinv_item_details_metabox_subscription_checkbox', $item); |
|
149 | 149 | |
150 | 150 | ?> |
151 | 151 | <div class="wpinv_show_if_recurring"> |
@@ -155,30 +155,30 @@ discard block |
||
155 | 155 | </div> |
156 | 156 | </div> |
157 | 157 | <div class="col-sm-1 pt-2 pl-0"> |
158 | - <span class="wpi-help-tip dashicons dashicons-editor-help wpinv_show_if_recurring" title="<?php esc_attr_e( 'Set the subscription price, billing interval and period.', 'invoicing' ); ?>"></span> |
|
158 | + <span class="wpi-help-tip dashicons dashicons-editor-help wpinv_show_if_recurring" title="<?php esc_attr_e('Set the subscription price, billing interval and period.', 'invoicing'); ?>"></span> |
|
159 | 159 | </div> |
160 | 160 | </div> |
161 | - <?php do_action( 'wpinv_item_details_metabox_after_price', $item ); ?> |
|
161 | + <?php do_action('wpinv_item_details_metabox_after_price', $item); ?> |
|
162 | 162 | |
163 | - <?php if( $item->supports_dynamic_pricing() ) : ?> |
|
164 | - <?php do_action( 'wpinv_item_details_metabox_before_minimum_price', $item ); ?> |
|
163 | + <?php if ($item->supports_dynamic_pricing()) : ?> |
|
164 | + <?php do_action('wpinv_item_details_metabox_before_minimum_price', $item); ?> |
|
165 | 165 | <div class="wpinv_show_if_dynamic wpinv_minimum_price"> |
166 | 166 | |
167 | 167 | <div class="form-group row"> |
168 | 168 | <label for="wpinv_minimum_price" class="col-sm-3 col-form-label"> |
169 | - <?php _e( 'Minimum Price', 'invoicing' );?> |
|
169 | + <?php _e('Minimum Price', 'invoicing'); ?> |
|
170 | 170 | </label> |
171 | 171 | <div class="col-sm-8"> |
172 | 172 | <div class="input-group input-group-sm"> |
173 | - <?php if( 'left' == $position ) : ?> |
|
173 | + <?php if ('left' == $position) : ?> |
|
174 | 174 | <div class="input-group-prepend"> |
175 | 175 | <span class="input-group-text" id="wpinv_item_minimum_price_symbol"><?php echo wpinv_currency_symbol(); ?></span> |
176 | 176 | </div> |
177 | 177 | <?php endif; ?> |
178 | 178 | |
179 | - <input type="text" name="wpinv_minimum_price" id="wpinv_minimum_price" value="<?php echo esc_attr( getpaid_unstandardize_amount( $item->get_minimum_price( 'edit' ) ) ); ?>" placeholder="<?php echo esc_attr( wpinv_sanitize_amount( 0 ) ); ?>" class="form-control"> |
|
179 | + <input type="text" name="wpinv_minimum_price" id="wpinv_minimum_price" value="<?php echo esc_attr(getpaid_unstandardize_amount($item->get_minimum_price('edit'))); ?>" placeholder="<?php echo esc_attr(wpinv_sanitize_amount(0)); ?>" class="form-control"> |
|
180 | 180 | |
181 | - <?php if( 'left' != $position ) : ?> |
|
181 | + <?php if ('left' != $position) : ?> |
|
182 | 182 | <div class="input-group-append"> |
183 | 183 | <span class="input-group-text" id="wpinv_item_minimum_price_symbol"><?php echo wpinv_currency_symbol(); ?></span> |
184 | 184 | </div> |
@@ -187,45 +187,45 @@ discard block |
||
187 | 187 | </div> |
188 | 188 | |
189 | 189 | <div class="col-sm-1 pt-2 pl-0"> |
190 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter the minimum amount that users are allowed to set', 'invoicing' ); ?>"></span> |
|
190 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Enter the minimum amount that users are allowed to set', 'invoicing'); ?>"></span> |
|
191 | 191 | </div> |
192 | 192 | </div> |
193 | 193 | |
194 | 194 | </div> |
195 | - <?php do_action( 'wpinv_item_details_metabox_minimum_price', $item ); ?> |
|
195 | + <?php do_action('wpinv_item_details_metabox_minimum_price', $item); ?> |
|
196 | 196 | <?php endif; ?> |
197 | 197 | |
198 | - <?php do_action( 'wpinv_item_details_metabox_before_maximum_renewals', $item ); ?> |
|
198 | + <?php do_action('wpinv_item_details_metabox_before_maximum_renewals', $item); ?> |
|
199 | 199 | <div class="wpinv_show_if_recurring wpinv_maximum_renewals"> |
200 | 200 | |
201 | 201 | <div class="form-group row"> |
202 | 202 | <label for="wpinv_recurring_limit" class="col-sm-3 col-form-label"> |
203 | - <?php _e( 'Maximum Renewals', 'invoicing' );?> |
|
203 | + <?php _e('Maximum Renewals', 'invoicing'); ?> |
|
204 | 204 | </label> |
205 | 205 | <div class="col-sm-8"> |
206 | - <input type="number" value="<?php echo esc_attr( $item->get_recurring_limit( 'edit' ) ); ?>" placeholder="0" name="wpinv_recurring_limit" id="wpinv_recurring_limit" style="width: 100%;" /> |
|
206 | + <input type="number" value="<?php echo esc_attr($item->get_recurring_limit('edit')); ?>" placeholder="0" name="wpinv_recurring_limit" id="wpinv_recurring_limit" style="width: 100%;" /> |
|
207 | 207 | </div> |
208 | 208 | <div class="col-sm-1 pt-2 pl-0"> |
209 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Leave empty if you want the subscription to renew until it is cancelled.', 'invoicing' ); ?>"></span> |
|
209 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Leave empty if you want the subscription to renew until it is cancelled.', 'invoicing'); ?>"></span> |
|
210 | 210 | </div> |
211 | 211 | </div> |
212 | 212 | |
213 | 213 | </div> |
214 | - <?php do_action( 'wpinv_item_details_metabox_maximum_renewals', $item ); ?> |
|
214 | + <?php do_action('wpinv_item_details_metabox_maximum_renewals', $item); ?> |
|
215 | 215 | |
216 | - <?php do_action( 'wpinv_item_details_metabox_before_free_trial', $item ); ?> |
|
216 | + <?php do_action('wpinv_item_details_metabox_before_free_trial', $item); ?> |
|
217 | 217 | <div class="wpinv_show_if_recurring wpinv_free_trial"> |
218 | 218 | |
219 | 219 | <div class="form-group row"> |
220 | - <label class="col-sm-3 col-form-label" for="wpinv_trial_interval"><?php _e( 'Free Trial', 'invoicing' )?></label> |
|
220 | + <label class="col-sm-3 col-form-label" for="wpinv_trial_interval"><?php _e('Free Trial', 'invoicing')?></label> |
|
221 | 221 | |
222 | 222 | <div class="col-sm-8"> |
223 | 223 | <div class="row"> |
224 | 224 | <div class="col-sm-6"> |
225 | - <?php $value = $item->has_free_trial() ? $item->get_trial_interval( 'edit' ) : 0;?> |
|
225 | + <?php $value = $item->has_free_trial() ? $item->get_trial_interval('edit') : 0; ?> |
|
226 | 226 | |
227 | 227 | <div> |
228 | - <input type="number" name="wpinv_trial_interval" style="width: 100%;" placeholder="0" id="wpinv_trial_interval" value="<?php echo esc_attr( $value ); ?>" > |
|
228 | + <input type="number" name="wpinv_trial_interval" style="width: 100%;" placeholder="0" id="wpinv_trial_interval" value="<?php echo esc_attr($value); ?>" > |
|
229 | 229 | </div> |
230 | 230 | </div> |
231 | 231 | <div class="col-sm-6"> |
@@ -234,17 +234,17 @@ discard block |
||
234 | 234 | array( |
235 | 235 | 'id' => 'wpinv_trial_period', |
236 | 236 | 'name' => 'wpinv_trial_period', |
237 | - 'label' => __( 'Trial Period', 'invoicing' ), |
|
238 | - 'placeholder' => __( 'Trial Period', 'invoicing' ), |
|
239 | - 'value' => $item->get_trial_period( 'edit' ), |
|
237 | + 'label' => __('Trial Period', 'invoicing'), |
|
238 | + 'placeholder' => __('Trial Period', 'invoicing'), |
|
239 | + 'value' => $item->get_trial_period('edit'), |
|
240 | 240 | 'select2' => true, |
241 | 241 | 'data-allow-clear' => 'false', |
242 | 242 | 'no_wrap' => true, |
243 | 243 | 'options' => array( |
244 | - 'D' => __( 'day(s)', 'invoicing' ), |
|
245 | - 'W' => __( 'week(s)', 'invoicing' ), |
|
246 | - 'M' => __( 'month(s)', 'invoicing' ), |
|
247 | - 'Y' => __( 'year(s)', 'invoicing' ), |
|
244 | + 'D' => __('day(s)', 'invoicing'), |
|
245 | + 'W' => __('week(s)', 'invoicing'), |
|
246 | + 'M' => __('month(s)', 'invoicing'), |
|
247 | + 'Y' => __('year(s)', 'invoicing'), |
|
248 | 248 | ) |
249 | 249 | ) |
250 | 250 | ); |
@@ -255,15 +255,15 @@ discard block |
||
255 | 255 | </div> |
256 | 256 | |
257 | 257 | <div class="col-sm-1 pt-2 pl-0"> |
258 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'An optional period of time to wait before charging the first recurring payment.', 'invoicing' ); ?>"></span> |
|
258 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('An optional period of time to wait before charging the first recurring payment.', 'invoicing'); ?>"></span> |
|
259 | 259 | </div> |
260 | 260 | |
261 | 261 | </div> |
262 | 262 | |
263 | 263 | </div> |
264 | - <?php do_action( 'wpinv_item_details_metabox__free_trial', $item ); ?> |
|
264 | + <?php do_action('wpinv_item_details_metabox__free_trial', $item); ?> |
|
265 | 265 | |
266 | - <?php do_action( 'wpinv_item_details_metabox_item_details', $item ); ?> |
|
266 | + <?php do_action('wpinv_item_details_metabox_item_details', $item); ?> |
|
267 | 267 | </div> |
268 | 268 | <?php |
269 | 269 | |
@@ -274,31 +274,31 @@ discard block |
||
274 | 274 | * |
275 | 275 | * @param int $post_id |
276 | 276 | */ |
277 | - public static function save( $post_id ) { |
|
277 | + public static function save($post_id) { |
|
278 | 278 | |
279 | 279 | // Prepare the item. |
280 | - $item = new WPInv_Item( $post_id ); |
|
280 | + $item = new WPInv_Item($post_id); |
|
281 | 281 | |
282 | 282 | // Load new data. |
283 | 283 | $item->set_props( |
284 | 284 | array( |
285 | - 'price' => isset( $_POST['wpinv_item_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_item_price'] ) : null, |
|
286 | - 'vat_rule' => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null, |
|
287 | - 'vat_class' => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null, |
|
288 | - 'type' => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null, |
|
289 | - 'is_dynamic_pricing' => isset( $_POST['wpinv_name_your_price'] ), |
|
290 | - 'minimum_price' => isset( $_POST['wpinv_minimum_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_minimum_price'] ) : null, |
|
291 | - 'is_recurring' => isset( $_POST['wpinv_is_recurring'] ), |
|
292 | - 'recurring_period' => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null, |
|
293 | - 'recurring_interval' => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : 1, |
|
294 | - 'recurring_limit' => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null, |
|
295 | - 'is_free_trial' => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null, |
|
296 | - 'trial_period' => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null, |
|
297 | - 'trial_interval' => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null, |
|
285 | + 'price' => isset($_POST['wpinv_item_price']) ? getpaid_standardize_amount($_POST['wpinv_item_price']) : null, |
|
286 | + 'vat_rule' => isset($_POST['wpinv_vat_rules']) ? wpinv_clean($_POST['wpinv_vat_rules']) : null, |
|
287 | + 'vat_class' => isset($_POST['wpinv_vat_class']) ? wpinv_clean($_POST['wpinv_vat_class']) : null, |
|
288 | + 'type' => isset($_POST['wpinv_item_type']) ? wpinv_clean($_POST['wpinv_item_type']) : null, |
|
289 | + 'is_dynamic_pricing' => isset($_POST['wpinv_name_your_price']), |
|
290 | + 'minimum_price' => isset($_POST['wpinv_minimum_price']) ? getpaid_standardize_amount($_POST['wpinv_minimum_price']) : null, |
|
291 | + 'is_recurring' => isset($_POST['wpinv_is_recurring']), |
|
292 | + 'recurring_period' => isset($_POST['wpinv_recurring_period']) ? wpinv_clean($_POST['wpinv_recurring_period']) : null, |
|
293 | + 'recurring_interval' => isset($_POST['wpinv_recurring_interval']) ? (int) $_POST['wpinv_recurring_interval'] : 1, |
|
294 | + 'recurring_limit' => isset($_POST['wpinv_recurring_limit']) ? (int) $_POST['wpinv_recurring_limit'] : null, |
|
295 | + 'is_free_trial' => isset($_POST['wpinv_trial_interval']) ? (0 != (int) $_POST['wpinv_trial_interval']) : null, |
|
296 | + 'trial_period' => isset($_POST['wpinv_trial_period']) ? wpinv_clean($_POST['wpinv_trial_period']) : null, |
|
297 | + 'trial_interval' => isset($_POST['wpinv_trial_interval']) ? (int) $_POST['wpinv_trial_interval'] : null, |
|
298 | 298 | ) |
299 | 299 | ); |
300 | 300 | |
301 | 301 | $item->save(); |
302 | - do_action( 'getpaid_item_metabox_save', $post_id, $item ); |
|
302 | + do_action('getpaid_item_metabox_save', $post_id, $item); |
|
303 | 303 | } |
304 | 304 | } |
@@ -12,80 +12,80 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Items { |
14 | 14 | |
15 | - /** |
|
16 | - * Submission items. |
|
17 | - * @var GetPaid_Form_Item[] |
|
18 | - */ |
|
19 | - public $items = array(); |
|
15 | + /** |
|
16 | + * Submission items. |
|
17 | + * @var GetPaid_Form_Item[] |
|
18 | + */ |
|
19 | + public $items = array(); |
|
20 | + |
|
21 | + /** |
|
22 | + * Class constructor |
|
23 | + * |
|
24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
25 | + */ |
|
26 | + public function __construct( $submission ) { |
|
27 | + |
|
28 | + $data = $submission->get_data(); |
|
29 | + $payment_form = $submission->get_payment_form(); |
|
30 | + |
|
31 | + // Prepare the selected items. |
|
32 | + $selected_items = array(); |
|
33 | + if ( ! empty( $data['getpaid-items'] ) ) { |
|
34 | + $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
35 | + } |
|
36 | + |
|
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 ) ); |
|
41 | + } |
|
42 | + |
|
43 | + // Process each individual item. |
|
44 | + foreach ( $payment_form->get_items() as $item ) { |
|
45 | + $this->process_item( $item, $selected_items, $submission ); |
|
46 | + } |
|
47 | + |
|
48 | + } |
|
20 | 49 | |
21 | 50 | /** |
22 | - * Class constructor |
|
23 | - * |
|
24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
25 | - */ |
|
26 | - public function __construct( $submission ) { |
|
27 | - |
|
28 | - $data = $submission->get_data(); |
|
29 | - $payment_form = $submission->get_payment_form(); |
|
30 | - |
|
31 | - // Prepare the selected items. |
|
32 | - $selected_items = array(); |
|
33 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
34 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
35 | - } |
|
36 | - |
|
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 ) ); |
|
41 | - } |
|
42 | - |
|
43 | - // Process each individual item. |
|
44 | - foreach ( $payment_form->get_items() as $item ) { |
|
45 | - $this->process_item( $item, $selected_items, $submission ); |
|
46 | - } |
|
47 | - |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Process a single item. |
|
52 | - * |
|
53 | - * @param GetPaid_Form_Item $item |
|
54 | - * @param array $selected_items |
|
55 | - * @param GetPaid_Payment_Form_Submission $submission |
|
56 | - */ |
|
57 | - public function process_item( $item, $selected_items, $submission ) { |
|
58 | - |
|
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() ] ) ) { |
|
61 | - return; |
|
62 | - } |
|
63 | - |
|
64 | - // (maybe) let customers change the quantities and prices. |
|
65 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
66 | - |
|
67 | - // Maybe change the quantities. |
|
68 | - if ( $item->allows_quantities() ) { |
|
69 | - $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
70 | - } |
|
71 | - |
|
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'] ); |
|
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() ) ) ); |
|
78 | - } |
|
79 | - |
|
80 | - $item->set_price( $price ); |
|
81 | - |
|
82 | - } |
|
83 | - |
|
84 | - } |
|
85 | - |
|
86 | - // Save the item. |
|
87 | - $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission ); |
|
88 | - |
|
89 | - } |
|
51 | + * Process a single item. |
|
52 | + * |
|
53 | + * @param GetPaid_Form_Item $item |
|
54 | + * @param array $selected_items |
|
55 | + * @param GetPaid_Payment_Form_Submission $submission |
|
56 | + */ |
|
57 | + public function process_item( $item, $selected_items, $submission ) { |
|
58 | + |
|
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() ] ) ) { |
|
61 | + return; |
|
62 | + } |
|
63 | + |
|
64 | + // (maybe) let customers change the quantities and prices. |
|
65 | + if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
66 | + |
|
67 | + // Maybe change the quantities. |
|
68 | + if ( $item->allows_quantities() ) { |
|
69 | + $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
70 | + } |
|
71 | + |
|
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'] ); |
|
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() ) ) ); |
|
78 | + } |
|
79 | + |
|
80 | + $item->set_price( $price ); |
|
81 | + |
|
82 | + } |
|
83 | + |
|
84 | + } |
|
85 | + |
|
86 | + // Save the item. |
|
87 | + $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission ); |
|
88 | + |
|
89 | + } |
|
90 | 90 | |
91 | 91 | } |
@@ -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 |
@@ -12,114 +12,114 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Fees { |
14 | 14 | |
15 | - /** |
|
16 | - * The fee validation error. |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - public $fee_error; |
|
20 | - |
|
21 | - /** |
|
22 | - * Submission fees. |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - public $fees = array(); |
|
15 | + /** |
|
16 | + * The fee validation error. |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + public $fee_error; |
|
20 | + |
|
21 | + /** |
|
22 | + * Submission fees. |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + public $fees = array(); |
|
26 | + |
|
27 | + /** |
|
28 | + * Class constructor |
|
29 | + * |
|
30 | + * @param GetPaid_Payment_Form_Submission $submission |
|
31 | + */ |
|
32 | + public function __construct( $submission ) { |
|
33 | + |
|
34 | + // Process any existing invoice fees. |
|
35 | + if ( $submission->has_invoice() ) { |
|
36 | + $this->fees = $submission->get_invoice()->get_fees(); |
|
37 | + } |
|
38 | + |
|
39 | + // Process price fields. |
|
40 | + $data = $submission->get_data(); |
|
41 | + $payment_form = $submission->get_payment_form(); |
|
42 | + |
|
43 | + foreach ( $payment_form->get_elements() as $element ) { |
|
44 | + |
|
45 | + if ( 'price_input' == $element['type'] ) { |
|
46 | + $this->process_price_input( $element, $data, $submission ); |
|
47 | + } |
|
48 | + |
|
49 | + if ( 'price_select' == $element['type'] ) { |
|
50 | + $this->process_price_select( $element, $data ); |
|
51 | + } |
|
52 | + |
|
53 | + } |
|
54 | + |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Process a price input field. |
|
59 | + * |
|
60 | + * @param array $element |
|
61 | + * @param array $data |
|
62 | + * @param GetPaid_Payment_Form_Submission $submission |
|
63 | + */ |
|
64 | + public function process_price_input( $element, $data, $submission ) { |
|
65 | + |
|
66 | + // Abort if not passed. |
|
67 | + if ( empty( $data[ $element['id'] ] ) ) { |
|
68 | + return; |
|
69 | + } |
|
70 | + |
|
71 | + $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
72 | + $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
73 | + |
|
74 | + if ( $amount < $minimum ) { |
|
75 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $minimum, $submission->get_currency() ) ) ); |
|
76 | + } |
|
77 | + |
|
78 | + $this->fees[ $element['label'] ] = array( |
|
79 | + 'name' => $element['label'], |
|
80 | + 'initial_fee' => $amount, |
|
81 | + 'recurring_fee' => 0, |
|
82 | + ); |
|
83 | + |
|
84 | + } |
|
26 | 85 | |
27 | 86 | /** |
28 | - * Class constructor |
|
29 | - * |
|
30 | - * @param GetPaid_Payment_Form_Submission $submission |
|
31 | - */ |
|
32 | - public function __construct( $submission ) { |
|
33 | - |
|
34 | - // Process any existing invoice fees. |
|
35 | - if ( $submission->has_invoice() ) { |
|
36 | - $this->fees = $submission->get_invoice()->get_fees(); |
|
37 | - } |
|
38 | - |
|
39 | - // Process price fields. |
|
40 | - $data = $submission->get_data(); |
|
41 | - $payment_form = $submission->get_payment_form(); |
|
42 | - |
|
43 | - foreach ( $payment_form->get_elements() as $element ) { |
|
44 | - |
|
45 | - if ( 'price_input' == $element['type'] ) { |
|
46 | - $this->process_price_input( $element, $data, $submission ); |
|
47 | - } |
|
48 | - |
|
49 | - if ( 'price_select' == $element['type'] ) { |
|
50 | - $this->process_price_select( $element, $data ); |
|
51 | - } |
|
52 | - |
|
53 | - } |
|
54 | - |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Process a price input field. |
|
59 | - * |
|
60 | - * @param array $element |
|
61 | - * @param array $data |
|
62 | - * @param GetPaid_Payment_Form_Submission $submission |
|
63 | - */ |
|
64 | - public function process_price_input( $element, $data, $submission ) { |
|
65 | - |
|
66 | - // Abort if not passed. |
|
67 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
68 | - return; |
|
69 | - } |
|
70 | - |
|
71 | - $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
72 | - $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
73 | - |
|
74 | - if ( $amount < $minimum ) { |
|
75 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $minimum, $submission->get_currency() ) ) ); |
|
76 | - } |
|
77 | - |
|
78 | - $this->fees[ $element['label'] ] = array( |
|
79 | - 'name' => $element['label'], |
|
80 | - 'initial_fee' => $amount, |
|
81 | - 'recurring_fee' => 0, |
|
82 | - ); |
|
83 | - |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Process a price select field. |
|
88 | - * |
|
89 | - * @param array $element |
|
90 | - * @param array $data |
|
91 | - */ |
|
92 | - public function process_price_select( $element, $data ) { |
|
93 | - |
|
94 | - // Abort if not passed. |
|
95 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
96 | - return; |
|
97 | - } |
|
98 | - |
|
99 | - $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
100 | - $selected = array_filter( array_map( 'trim', explode( ',', $data[ $element['id'] ] ) ) ); |
|
101 | - $total = 0; |
|
102 | - $sub_labels = array(); |
|
103 | - |
|
104 | - foreach ( $selected as $price ) { |
|
105 | - |
|
106 | - if ( ! isset( $options[ $price ] ) ) { |
|
107 | - throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
108 | - } |
|
109 | - |
|
110 | - $price = explode( '|', $price ); |
|
111 | - |
|
112 | - $sub_labels[] = $price[0]; |
|
113 | - $total += (float) wpinv_sanitize_amount( $price[1] ); |
|
114 | - } |
|
115 | - |
|
116 | - $this->fees[ $element['label'] ] = array( |
|
117 | - 'name' => $element['label'], |
|
118 | - 'initial_fee' => $total, |
|
119 | - 'recurring_fee' => 0, |
|
120 | - 'description' => implode( ', ', $sub_labels ), |
|
121 | - ); |
|
122 | - |
|
123 | - } |
|
87 | + * Process a price select field. |
|
88 | + * |
|
89 | + * @param array $element |
|
90 | + * @param array $data |
|
91 | + */ |
|
92 | + public function process_price_select( $element, $data ) { |
|
93 | + |
|
94 | + // Abort if not passed. |
|
95 | + if ( empty( $data[ $element['id'] ] ) ) { |
|
96 | + return; |
|
97 | + } |
|
98 | + |
|
99 | + $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
100 | + $selected = array_filter( array_map( 'trim', explode( ',', $data[ $element['id'] ] ) ) ); |
|
101 | + $total = 0; |
|
102 | + $sub_labels = array(); |
|
103 | + |
|
104 | + foreach ( $selected as $price ) { |
|
105 | + |
|
106 | + if ( ! isset( $options[ $price ] ) ) { |
|
107 | + throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
108 | + } |
|
109 | + |
|
110 | + $price = explode( '|', $price ); |
|
111 | + |
|
112 | + $sub_labels[] = $price[0]; |
|
113 | + $total += (float) wpinv_sanitize_amount( $price[1] ); |
|
114 | + } |
|
115 | + |
|
116 | + $this->fees[ $element['label'] ] = array( |
|
117 | + 'name' => $element['label'], |
|
118 | + 'initial_fee' => $total, |
|
119 | + 'recurring_fee' => 0, |
|
120 | + 'description' => implode( ', ', $sub_labels ), |
|
121 | + ); |
|
122 | + |
|
123 | + } |
|
124 | 124 | |
125 | 125 | } |
@@ -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 fees class |
@@ -29,10 +29,10 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @param GetPaid_Payment_Form_Submission $submission |
31 | 31 | */ |
32 | - public function __construct( $submission ) { |
|
32 | + public function __construct($submission) { |
|
33 | 33 | |
34 | 34 | // Process any existing invoice fees. |
35 | - if ( $submission->has_invoice() ) { |
|
35 | + if ($submission->has_invoice()) { |
|
36 | 36 | $this->fees = $submission->get_invoice()->get_fees(); |
37 | 37 | } |
38 | 38 | |
@@ -40,14 +40,14 @@ discard block |
||
40 | 40 | $data = $submission->get_data(); |
41 | 41 | $payment_form = $submission->get_payment_form(); |
42 | 42 | |
43 | - foreach ( $payment_form->get_elements() as $element ) { |
|
43 | + foreach ($payment_form->get_elements() as $element) { |
|
44 | 44 | |
45 | - if ( 'price_input' == $element['type'] ) { |
|
46 | - $this->process_price_input( $element, $data, $submission ); |
|
45 | + if ('price_input' == $element['type']) { |
|
46 | + $this->process_price_input($element, $data, $submission); |
|
47 | 47 | } |
48 | 48 | |
49 | - if ( 'price_select' == $element['type'] ) { |
|
50 | - $this->process_price_select( $element, $data ); |
|
49 | + if ('price_select' == $element['type']) { |
|
50 | + $this->process_price_select($element, $data); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | } |
@@ -61,21 +61,21 @@ discard block |
||
61 | 61 | * @param array $data |
62 | 62 | * @param GetPaid_Payment_Form_Submission $submission |
63 | 63 | */ |
64 | - public function process_price_input( $element, $data, $submission ) { |
|
64 | + public function process_price_input($element, $data, $submission) { |
|
65 | 65 | |
66 | 66 | // Abort if not passed. |
67 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
67 | + if (empty($data[$element['id']])) { |
|
68 | 68 | return; |
69 | 69 | } |
70 | 70 | |
71 | - $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
72 | - $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
71 | + $amount = (float) wpinv_sanitize_amount($data[$element['id']]); |
|
72 | + $minimum = empty($element['minimum']) ? 0 : (float) wpinv_sanitize_amount($element['minimum']); |
|
73 | 73 | |
74 | - if ( $amount < $minimum ) { |
|
75 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $minimum, $submission->get_currency() ) ) ); |
|
74 | + if ($amount < $minimum) { |
|
75 | + throw new Exception(sprintf(__('The minimum allowed amount is %s', 'invoicing'), getpaid_unstandardize_amount($minimum, $submission->get_currency()))); |
|
76 | 76 | } |
77 | 77 | |
78 | - $this->fees[ $element['label'] ] = array( |
|
78 | + $this->fees[$element['label']] = array( |
|
79 | 79 | 'name' => $element['label'], |
80 | 80 | 'initial_fee' => $amount, |
81 | 81 | 'recurring_fee' => 0, |
@@ -89,35 +89,35 @@ discard block |
||
89 | 89 | * @param array $element |
90 | 90 | * @param array $data |
91 | 91 | */ |
92 | - public function process_price_select( $element, $data ) { |
|
92 | + public function process_price_select($element, $data) { |
|
93 | 93 | |
94 | 94 | // Abort if not passed. |
95 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
95 | + if (empty($data[$element['id']])) { |
|
96 | 96 | return; |
97 | 97 | } |
98 | 98 | |
99 | - $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
100 | - $selected = array_filter( array_map( 'trim', explode( ',', $data[ $element['id'] ] ) ) ); |
|
99 | + $options = getpaid_convert_price_string_to_options($element['options']); |
|
100 | + $selected = array_filter(array_map('trim', explode(',', $data[$element['id']]))); |
|
101 | 101 | $total = 0; |
102 | 102 | $sub_labels = array(); |
103 | 103 | |
104 | - foreach ( $selected as $price ) { |
|
104 | + foreach ($selected as $price) { |
|
105 | 105 | |
106 | - if ( ! isset( $options[ $price ] ) ) { |
|
107 | - throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
106 | + if (!isset($options[$price])) { |
|
107 | + throw new Exception(__('You have selected an invalid amount', 'invoicing')); |
|
108 | 108 | } |
109 | 109 | |
110 | - $price = explode( '|', $price ); |
|
110 | + $price = explode('|', $price); |
|
111 | 111 | |
112 | 112 | $sub_labels[] = $price[0]; |
113 | - $total += (float) wpinv_sanitize_amount( $price[1] ); |
|
113 | + $total += (float) wpinv_sanitize_amount($price[1]); |
|
114 | 114 | } |
115 | 115 | |
116 | - $this->fees[ $element['label'] ] = array( |
|
116 | + $this->fees[$element['label']] = array( |
|
117 | 117 | 'name' => $element['label'], |
118 | 118 | 'initial_fee' => $total, |
119 | 119 | 'recurring_fee' => 0, |
120 | - 'description' => implode( ', ', $sub_labels ), |
|
120 | + 'description' => implode(', ', $sub_labels), |
|
121 | 121 | ); |
122 | 122 | |
123 | 123 | } |
@@ -17,397 +17,397 @@ |
||
17 | 17 | */ |
18 | 18 | class GetPaid_Admin_Setup_Wizard { |
19 | 19 | |
20 | - /** |
|
21 | - * @var string Current Step |
|
22 | - */ |
|
23 | - protected $step = ''; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var string|false Previous Step |
|
27 | - */ |
|
28 | - protected $previous_step = ''; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string|false Next Step |
|
32 | - */ |
|
33 | - protected $next_step = ''; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var array All available steps for the setup wizard |
|
37 | - */ |
|
38 | - protected $steps = array(); |
|
39 | - |
|
40 | - /** |
|
41 | - * Class constructor. |
|
42 | - * |
|
43 | - * @since 2.4.0 |
|
44 | - */ |
|
45 | - public function __construct() { |
|
46 | - |
|
47 | - if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) { |
|
48 | - add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
|
49 | - add_action( 'current_screen', array( $this, 'setup_wizard' ) ); |
|
50 | - } |
|
51 | - |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Add admin menus/screens. |
|
56 | - * |
|
57 | - * @since 2.4.0 |
|
58 | - */ |
|
59 | - public function add_menu() { |
|
60 | - add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' ); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Sets up the setup wizard. |
|
65 | - * |
|
66 | - * @since 2.4.0 |
|
67 | - */ |
|
68 | - public function setup_wizard() { |
|
69 | - |
|
70 | - if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) { |
|
71 | - $this->setup_globals(); |
|
72 | - $this->maybe_save_current_step(); |
|
73 | - $this->display_wizard(); |
|
74 | - exit; |
|
75 | - } |
|
76 | - |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Sets up class variables. |
|
81 | - * |
|
82 | - * @since 2.4.0 |
|
83 | - */ |
|
84 | - protected function setup_globals() { |
|
85 | - $this->steps = $this->get_setup_steps(); |
|
86 | - $this->step = $this->get_current_step(); |
|
87 | - $this->previous_step = $this->get_previous_step(); |
|
88 | - $this->next_step = $this->get_next_step(); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Saves the current step. |
|
93 | - * |
|
94 | - * @since 2.4.0 |
|
95 | - */ |
|
96 | - protected function maybe_save_current_step() { |
|
97 | - if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) { |
|
98 | - call_user_func( $this->steps[ $this->step ]['handler'], $this ); |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Returns the setup steps. |
|
104 | - * |
|
105 | - * @since 2.4.0 |
|
106 | - * @return array |
|
107 | - */ |
|
108 | - protected function get_setup_steps() { |
|
109 | - |
|
110 | - $steps = array( |
|
111 | - |
|
112 | - 'introduction' => array( |
|
113 | - 'name' => __( 'Introduction', 'invoicing' ), |
|
114 | - 'view' => array( $this, 'setup_introduction' ), |
|
115 | - 'handler' => '', |
|
116 | - ), |
|
117 | - |
|
118 | - 'business_details' => array( |
|
119 | - 'name' => __( "Business Details", 'invoicing' ), |
|
120 | - 'view' => array( $this, 'setup_business' ), |
|
121 | - 'handler' => '', |
|
122 | - ), |
|
123 | - |
|
124 | - 'currency' => array( |
|
125 | - 'name' => __( 'Currency', 'invoicing' ), |
|
126 | - 'view' => array( $this, 'setup_currency' ), |
|
127 | - 'handler' => '', |
|
128 | - ), |
|
129 | - |
|
130 | - 'payments' => array( |
|
131 | - 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
132 | - 'view' => array( $this, 'setup_payments' ), |
|
133 | - 'handler' => array( $this, 'setup_payments_save' ), |
|
134 | - ), |
|
135 | - |
|
136 | - 'recommend' => array( |
|
137 | - 'name' => __( 'Recommend', 'invoicing' ), |
|
138 | - 'view' => array( $this, 'setup_recommend' ), |
|
139 | - 'handler' => '', |
|
140 | - ), |
|
141 | - |
|
142 | - 'next_steps' => array( |
|
143 | - 'name' => __( 'Get Paid', 'invoicing' ), |
|
144 | - 'view' => array( $this, 'setup_ready' ), |
|
145 | - 'handler' => '', |
|
146 | - ), |
|
147 | - |
|
148 | - ); |
|
149 | - |
|
150 | - return apply_filters( 'getpaid_setup_wizard_steps', $steps ); |
|
151 | - |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Returns the current step. |
|
156 | - * |
|
157 | - * @since 2.4.0 |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - protected function get_current_step() { |
|
161 | - $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : ''; |
|
162 | - return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) ); |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Returns the previous step. |
|
167 | - * |
|
168 | - * @since 2.4.0 |
|
169 | - * @return string|false |
|
170 | - */ |
|
171 | - protected function get_previous_step() { |
|
172 | - |
|
173 | - $previous = false; |
|
174 | - $current = $this->step; |
|
175 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
176 | - if ( $current === $step ) { |
|
177 | - return $previous; |
|
178 | - } |
|
179 | - |
|
180 | - $previous = $step; |
|
181 | - } |
|
182 | - |
|
183 | - return false; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Returns the next step. |
|
188 | - * |
|
189 | - * @since 2.4.0 |
|
190 | - * @return string|false |
|
191 | - */ |
|
192 | - protected function get_next_step() { |
|
193 | - |
|
194 | - $on_current = false; |
|
195 | - $current = $this->step; |
|
196 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
197 | - |
|
198 | - if ( $on_current ) { |
|
199 | - return $step; |
|
200 | - } |
|
201 | - |
|
202 | - if ( $current === $step ) { |
|
203 | - return $on_current = true; |
|
204 | - } |
|
205 | - |
|
206 | - } |
|
207 | - |
|
208 | - return false; |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * Displays the setup wizard. |
|
213 | - * |
|
214 | - * @since 2.4.0 |
|
215 | - */ |
|
216 | - public function display_wizard() { |
|
217 | - $this->display_header(); |
|
218 | - $this->display_current_step(); |
|
219 | - $this->display_footer(); |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Displays the Wizard Header. |
|
224 | - * |
|
225 | - * @since 2.0.0 |
|
226 | - */ |
|
227 | - public function display_header() { |
|
228 | - $steps = $this->steps; |
|
229 | - $current = $this->step; |
|
230 | - $next_step = $this->next_step; |
|
231 | - array_shift( $steps ); |
|
232 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php'; |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Displays the content for the current step. |
|
237 | - * |
|
238 | - * @since 2.4.0 |
|
239 | - */ |
|
240 | - public function display_current_step() { |
|
241 | - ?> |
|
20 | + /** |
|
21 | + * @var string Current Step |
|
22 | + */ |
|
23 | + protected $step = ''; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var string|false Previous Step |
|
27 | + */ |
|
28 | + protected $previous_step = ''; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string|false Next Step |
|
32 | + */ |
|
33 | + protected $next_step = ''; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var array All available steps for the setup wizard |
|
37 | + */ |
|
38 | + protected $steps = array(); |
|
39 | + |
|
40 | + /** |
|
41 | + * Class constructor. |
|
42 | + * |
|
43 | + * @since 2.4.0 |
|
44 | + */ |
|
45 | + public function __construct() { |
|
46 | + |
|
47 | + if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) { |
|
48 | + add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
|
49 | + add_action( 'current_screen', array( $this, 'setup_wizard' ) ); |
|
50 | + } |
|
51 | + |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Add admin menus/screens. |
|
56 | + * |
|
57 | + * @since 2.4.0 |
|
58 | + */ |
|
59 | + public function add_menu() { |
|
60 | + add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' ); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Sets up the setup wizard. |
|
65 | + * |
|
66 | + * @since 2.4.0 |
|
67 | + */ |
|
68 | + public function setup_wizard() { |
|
69 | + |
|
70 | + if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) { |
|
71 | + $this->setup_globals(); |
|
72 | + $this->maybe_save_current_step(); |
|
73 | + $this->display_wizard(); |
|
74 | + exit; |
|
75 | + } |
|
76 | + |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Sets up class variables. |
|
81 | + * |
|
82 | + * @since 2.4.0 |
|
83 | + */ |
|
84 | + protected function setup_globals() { |
|
85 | + $this->steps = $this->get_setup_steps(); |
|
86 | + $this->step = $this->get_current_step(); |
|
87 | + $this->previous_step = $this->get_previous_step(); |
|
88 | + $this->next_step = $this->get_next_step(); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Saves the current step. |
|
93 | + * |
|
94 | + * @since 2.4.0 |
|
95 | + */ |
|
96 | + protected function maybe_save_current_step() { |
|
97 | + if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) { |
|
98 | + call_user_func( $this->steps[ $this->step ]['handler'], $this ); |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Returns the setup steps. |
|
104 | + * |
|
105 | + * @since 2.4.0 |
|
106 | + * @return array |
|
107 | + */ |
|
108 | + protected function get_setup_steps() { |
|
109 | + |
|
110 | + $steps = array( |
|
111 | + |
|
112 | + 'introduction' => array( |
|
113 | + 'name' => __( 'Introduction', 'invoicing' ), |
|
114 | + 'view' => array( $this, 'setup_introduction' ), |
|
115 | + 'handler' => '', |
|
116 | + ), |
|
117 | + |
|
118 | + 'business_details' => array( |
|
119 | + 'name' => __( "Business Details", 'invoicing' ), |
|
120 | + 'view' => array( $this, 'setup_business' ), |
|
121 | + 'handler' => '', |
|
122 | + ), |
|
123 | + |
|
124 | + 'currency' => array( |
|
125 | + 'name' => __( 'Currency', 'invoicing' ), |
|
126 | + 'view' => array( $this, 'setup_currency' ), |
|
127 | + 'handler' => '', |
|
128 | + ), |
|
129 | + |
|
130 | + 'payments' => array( |
|
131 | + 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
132 | + 'view' => array( $this, 'setup_payments' ), |
|
133 | + 'handler' => array( $this, 'setup_payments_save' ), |
|
134 | + ), |
|
135 | + |
|
136 | + 'recommend' => array( |
|
137 | + 'name' => __( 'Recommend', 'invoicing' ), |
|
138 | + 'view' => array( $this, 'setup_recommend' ), |
|
139 | + 'handler' => '', |
|
140 | + ), |
|
141 | + |
|
142 | + 'next_steps' => array( |
|
143 | + 'name' => __( 'Get Paid', 'invoicing' ), |
|
144 | + 'view' => array( $this, 'setup_ready' ), |
|
145 | + 'handler' => '', |
|
146 | + ), |
|
147 | + |
|
148 | + ); |
|
149 | + |
|
150 | + return apply_filters( 'getpaid_setup_wizard_steps', $steps ); |
|
151 | + |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Returns the current step. |
|
156 | + * |
|
157 | + * @since 2.4.0 |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + protected function get_current_step() { |
|
161 | + $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : ''; |
|
162 | + return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) ); |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Returns the previous step. |
|
167 | + * |
|
168 | + * @since 2.4.0 |
|
169 | + * @return string|false |
|
170 | + */ |
|
171 | + protected function get_previous_step() { |
|
172 | + |
|
173 | + $previous = false; |
|
174 | + $current = $this->step; |
|
175 | + foreach ( array_keys( $this->steps ) as $step ) { |
|
176 | + if ( $current === $step ) { |
|
177 | + return $previous; |
|
178 | + } |
|
179 | + |
|
180 | + $previous = $step; |
|
181 | + } |
|
182 | + |
|
183 | + return false; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Returns the next step. |
|
188 | + * |
|
189 | + * @since 2.4.0 |
|
190 | + * @return string|false |
|
191 | + */ |
|
192 | + protected function get_next_step() { |
|
193 | + |
|
194 | + $on_current = false; |
|
195 | + $current = $this->step; |
|
196 | + foreach ( array_keys( $this->steps ) as $step ) { |
|
197 | + |
|
198 | + if ( $on_current ) { |
|
199 | + return $step; |
|
200 | + } |
|
201 | + |
|
202 | + if ( $current === $step ) { |
|
203 | + return $on_current = true; |
|
204 | + } |
|
205 | + |
|
206 | + } |
|
207 | + |
|
208 | + return false; |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * Displays the setup wizard. |
|
213 | + * |
|
214 | + * @since 2.4.0 |
|
215 | + */ |
|
216 | + public function display_wizard() { |
|
217 | + $this->display_header(); |
|
218 | + $this->display_current_step(); |
|
219 | + $this->display_footer(); |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Displays the Wizard Header. |
|
224 | + * |
|
225 | + * @since 2.0.0 |
|
226 | + */ |
|
227 | + public function display_header() { |
|
228 | + $steps = $this->steps; |
|
229 | + $current = $this->step; |
|
230 | + $next_step = $this->next_step; |
|
231 | + array_shift( $steps ); |
|
232 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php'; |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Displays the content for the current step. |
|
237 | + * |
|
238 | + * @since 2.4.0 |
|
239 | + */ |
|
240 | + public function display_current_step() { |
|
241 | + ?> |
|
242 | 242 | <div class="gp-setup-content rowx mw-100 text-center mb-3"> |
243 | 243 | <div class="col-12 col-md-5 m-auto"> |
244 | 244 | <?php call_user_func( $this->steps[ $this->step ]['view'], $this ); ?> |
245 | 245 | </div> |
246 | 246 | </div> |
247 | 247 | <?php |
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Setup Wizard Footer. |
|
252 | - * |
|
253 | - * @since 2.4.0 |
|
254 | - */ |
|
255 | - public function display_footer() { |
|
256 | - |
|
257 | - if ( isset( $_GET['step'] ) ) { |
|
258 | - $next_url = esc_url( $this->get_next_step_link() ); |
|
259 | - $label = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' ); |
|
260 | - |
|
261 | - echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . $next_url . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . $label . '</a></p>'; |
|
262 | - } |
|
263 | - |
|
264 | - echo '</body></html>'; |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * Introduction step. |
|
269 | - * |
|
270 | - * @since 2.0.0 |
|
271 | - */ |
|
272 | - public function setup_introduction() { |
|
273 | - $next_url = $this->get_next_step_link(); |
|
274 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php'; |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Get the URL for the next step's screen. |
|
279 | - * |
|
280 | - * @param string step slug (default: current step) |
|
281 | - * |
|
282 | - * @return string URL for next step if a next step exists. |
|
283 | - * Admin URL if it's the last step. |
|
284 | - * Empty string on failure. |
|
285 | - * @since 3.0.0 |
|
286 | - */ |
|
287 | - public function get_next_step_link( $step = '' ) { |
|
288 | - if ( ! $step ) { |
|
289 | - $step = $this->step; |
|
290 | - } |
|
291 | - |
|
292 | - $keys = array_keys( $this->steps ); |
|
293 | - if ( end( $keys ) === $step ) { |
|
294 | - return admin_url(); |
|
295 | - } |
|
296 | - |
|
297 | - $step_index = array_search( $step, $keys ); |
|
298 | - if ( false === $step_index ) { |
|
299 | - return ''; |
|
300 | - } |
|
301 | - |
|
302 | - return remove_query_arg('settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] )); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Setup maps api. |
|
307 | - * |
|
308 | - * @since 2.0.0 |
|
309 | - */ |
|
310 | - public function setup_business() { |
|
311 | - $next_url = $this->get_next_step_link(); |
|
312 | - $wizard = $this; |
|
313 | - $page = 'wpinv_settings_general_main'; |
|
314 | - $section = 'wpinv_settings_general_main'; |
|
315 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * Default Location settings. |
|
320 | - * |
|
321 | - * @since 2.0.0 |
|
322 | - */ |
|
323 | - public function setup_currency() { |
|
324 | - $next_url = $this->get_next_step_link(); |
|
325 | - $wizard = $this; |
|
326 | - $page = 'wpinv_settings_general_currency_section'; |
|
327 | - $section = 'wpinv_settings_general_currency_section'; |
|
328 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * Installation of recommended plugins. |
|
333 | - * |
|
334 | - * @since 1.0.0 |
|
335 | - */ |
|
336 | - public function setup_recommend() { |
|
337 | - $next_url = $this->get_next_step_link(); |
|
338 | - $recommended_plugins = self::get_recommend_wp_plugins(); |
|
339 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php'; |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * A list of recommended wp.org plugins. |
|
344 | - * @return array |
|
345 | - */ |
|
346 | - public static function get_recommend_wp_plugins(){ |
|
347 | - return array( |
|
348 | - 'ayecode-connect' => array( |
|
349 | - 'file' => 'ayecode-connect/ayecode-connect.php', |
|
350 | - 'url' => 'https://wordpress.org/plugins/ayecode-connect/', |
|
351 | - 'slug' => 'ayecode-connect', |
|
352 | - 'name' => 'AyeCode Connect', |
|
353 | - 'desc' => __( 'Documentation and Support from within your WordPress admin.', 'geodirectory' ), |
|
354 | - ), |
|
355 | - 'invoicing-quotes' => array( |
|
356 | - 'file' => 'invoicing-quotes/wpinv-quote.php', |
|
357 | - 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
|
358 | - 'slug' => 'invoicing-quotes', |
|
359 | - 'name' => 'Customer Quotes', |
|
360 | - 'desc' => __('Create & Send Quotes to Customers and have them accept and pay.','geodirectory'), |
|
361 | - ), |
|
362 | - 'userswp' => array( |
|
363 | - 'file' => 'userswp/userswp.php', |
|
364 | - 'url' => 'https://wordpress.org/plugins/userswp/', |
|
365 | - 'slug' => 'userswp', |
|
366 | - 'name' => 'UsersWP', |
|
367 | - 'desc' => __('Frontend user login and registration as well as slick profile pages.','geodirectory'), |
|
368 | - ), |
|
369 | - ); |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Dummy Data setup. |
|
374 | - * |
|
375 | - * @since 2.4.0 |
|
376 | - */ |
|
377 | - public function setup_payments() { |
|
378 | - $next_url = $this->get_next_step_link(); |
|
379 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php'; |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * Dummy data save. |
|
384 | - * |
|
385 | - * This is done via ajax so we just pass onto the next step. |
|
386 | - * |
|
387 | - * @since 2.0.0 |
|
388 | - */ |
|
389 | - public function setup_payments_save() { |
|
390 | - check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); |
|
391 | - wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) ); |
|
392 | - |
|
393 | - if ( ! empty( $_POST['paypal-email'] ) ) { |
|
394 | - wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) ); |
|
395 | - wpinv_update_option( 'paypal_active', 1 ); |
|
396 | - wpinv_update_option( 'paypal_sandbox', 0 ); |
|
397 | - } |
|
398 | - |
|
399 | - wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
|
400 | - exit; |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * Final step. |
|
405 | - * |
|
406 | - * @since 2.0.0 |
|
407 | - */ |
|
408 | - public function setup_ready() { |
|
409 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php'; |
|
410 | - } |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Setup Wizard Footer. |
|
252 | + * |
|
253 | + * @since 2.4.0 |
|
254 | + */ |
|
255 | + public function display_footer() { |
|
256 | + |
|
257 | + if ( isset( $_GET['step'] ) ) { |
|
258 | + $next_url = esc_url( $this->get_next_step_link() ); |
|
259 | + $label = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' ); |
|
260 | + |
|
261 | + echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . $next_url . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . $label . '</a></p>'; |
|
262 | + } |
|
263 | + |
|
264 | + echo '</body></html>'; |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * Introduction step. |
|
269 | + * |
|
270 | + * @since 2.0.0 |
|
271 | + */ |
|
272 | + public function setup_introduction() { |
|
273 | + $next_url = $this->get_next_step_link(); |
|
274 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php'; |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Get the URL for the next step's screen. |
|
279 | + * |
|
280 | + * @param string step slug (default: current step) |
|
281 | + * |
|
282 | + * @return string URL for next step if a next step exists. |
|
283 | + * Admin URL if it's the last step. |
|
284 | + * Empty string on failure. |
|
285 | + * @since 3.0.0 |
|
286 | + */ |
|
287 | + public function get_next_step_link( $step = '' ) { |
|
288 | + if ( ! $step ) { |
|
289 | + $step = $this->step; |
|
290 | + } |
|
291 | + |
|
292 | + $keys = array_keys( $this->steps ); |
|
293 | + if ( end( $keys ) === $step ) { |
|
294 | + return admin_url(); |
|
295 | + } |
|
296 | + |
|
297 | + $step_index = array_search( $step, $keys ); |
|
298 | + if ( false === $step_index ) { |
|
299 | + return ''; |
|
300 | + } |
|
301 | + |
|
302 | + return remove_query_arg('settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] )); |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Setup maps api. |
|
307 | + * |
|
308 | + * @since 2.0.0 |
|
309 | + */ |
|
310 | + public function setup_business() { |
|
311 | + $next_url = $this->get_next_step_link(); |
|
312 | + $wizard = $this; |
|
313 | + $page = 'wpinv_settings_general_main'; |
|
314 | + $section = 'wpinv_settings_general_main'; |
|
315 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * Default Location settings. |
|
320 | + * |
|
321 | + * @since 2.0.0 |
|
322 | + */ |
|
323 | + public function setup_currency() { |
|
324 | + $next_url = $this->get_next_step_link(); |
|
325 | + $wizard = $this; |
|
326 | + $page = 'wpinv_settings_general_currency_section'; |
|
327 | + $section = 'wpinv_settings_general_currency_section'; |
|
328 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * Installation of recommended plugins. |
|
333 | + * |
|
334 | + * @since 1.0.0 |
|
335 | + */ |
|
336 | + public function setup_recommend() { |
|
337 | + $next_url = $this->get_next_step_link(); |
|
338 | + $recommended_plugins = self::get_recommend_wp_plugins(); |
|
339 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php'; |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * A list of recommended wp.org plugins. |
|
344 | + * @return array |
|
345 | + */ |
|
346 | + public static function get_recommend_wp_plugins(){ |
|
347 | + return array( |
|
348 | + 'ayecode-connect' => array( |
|
349 | + 'file' => 'ayecode-connect/ayecode-connect.php', |
|
350 | + 'url' => 'https://wordpress.org/plugins/ayecode-connect/', |
|
351 | + 'slug' => 'ayecode-connect', |
|
352 | + 'name' => 'AyeCode Connect', |
|
353 | + 'desc' => __( 'Documentation and Support from within your WordPress admin.', 'geodirectory' ), |
|
354 | + ), |
|
355 | + 'invoicing-quotes' => array( |
|
356 | + 'file' => 'invoicing-quotes/wpinv-quote.php', |
|
357 | + 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
|
358 | + 'slug' => 'invoicing-quotes', |
|
359 | + 'name' => 'Customer Quotes', |
|
360 | + 'desc' => __('Create & Send Quotes to Customers and have them accept and pay.','geodirectory'), |
|
361 | + ), |
|
362 | + 'userswp' => array( |
|
363 | + 'file' => 'userswp/userswp.php', |
|
364 | + 'url' => 'https://wordpress.org/plugins/userswp/', |
|
365 | + 'slug' => 'userswp', |
|
366 | + 'name' => 'UsersWP', |
|
367 | + 'desc' => __('Frontend user login and registration as well as slick profile pages.','geodirectory'), |
|
368 | + ), |
|
369 | + ); |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Dummy Data setup. |
|
374 | + * |
|
375 | + * @since 2.4.0 |
|
376 | + */ |
|
377 | + public function setup_payments() { |
|
378 | + $next_url = $this->get_next_step_link(); |
|
379 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php'; |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * Dummy data save. |
|
384 | + * |
|
385 | + * This is done via ajax so we just pass onto the next step. |
|
386 | + * |
|
387 | + * @since 2.0.0 |
|
388 | + */ |
|
389 | + public function setup_payments_save() { |
|
390 | + check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); |
|
391 | + wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) ); |
|
392 | + |
|
393 | + if ( ! empty( $_POST['paypal-email'] ) ) { |
|
394 | + wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) ); |
|
395 | + wpinv_update_option( 'paypal_active', 1 ); |
|
396 | + wpinv_update_option( 'paypal_sandbox', 0 ); |
|
397 | + } |
|
398 | + |
|
399 | + wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
|
400 | + exit; |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * Final step. |
|
405 | + * |
|
406 | + * @since 2.0.0 |
|
407 | + */ |
|
408 | + public function setup_ready() { |
|
409 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php'; |
|
410 | + } |
|
411 | 411 | |
412 | 412 | } |
413 | 413 |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @version 2.4.0 |
11 | 11 | * @info GetPaid Setup Wizard. |
12 | 12 | */ |
13 | -defined( 'ABSPATH' ) || exit; |
|
13 | +defined('ABSPATH') || exit; |
|
14 | 14 | |
15 | 15 | /** |
16 | 16 | * GetPaid_Admin_Setup_Wizard class. |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public function __construct() { |
46 | 46 | |
47 | - if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) { |
|
48 | - add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
|
49 | - add_action( 'current_screen', array( $this, 'setup_wizard' ) ); |
|
47 | + if (apply_filters('getpaid_enable_setup_wizard', true) && wpinv_current_user_can_manage_invoicing()) { |
|
48 | + add_action('admin_menu', array($this, 'add_menu')); |
|
49 | + add_action('current_screen', array($this, 'setup_wizard')); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @since 2.4.0 |
58 | 58 | */ |
59 | 59 | public function add_menu() { |
60 | - add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' ); |
|
60 | + add_dashboard_page('', '', wpinv_get_capability(), 'gp-setup', ''); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function setup_wizard() { |
69 | 69 | |
70 | - if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) { |
|
70 | + if (isset($_GET['page']) && 'gp-setup' === $_GET['page']) { |
|
71 | 71 | $this->setup_globals(); |
72 | 72 | $this->maybe_save_current_step(); |
73 | 73 | $this->display_wizard(); |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | * @since 2.4.0 |
95 | 95 | */ |
96 | 96 | protected function maybe_save_current_step() { |
97 | - if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) { |
|
98 | - call_user_func( $this->steps[ $this->step ]['handler'], $this ); |
|
97 | + if (!empty($_POST['save_step']) && is_callable($this->steps[$this->step]['handler'])) { |
|
98 | + call_user_func($this->steps[$this->step]['handler'], $this); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
@@ -110,44 +110,44 @@ discard block |
||
110 | 110 | $steps = array( |
111 | 111 | |
112 | 112 | 'introduction' => array( |
113 | - 'name' => __( 'Introduction', 'invoicing' ), |
|
114 | - 'view' => array( $this, 'setup_introduction' ), |
|
113 | + 'name' => __('Introduction', 'invoicing'), |
|
114 | + 'view' => array($this, 'setup_introduction'), |
|
115 | 115 | 'handler' => '', |
116 | 116 | ), |
117 | 117 | |
118 | 118 | 'business_details' => array( |
119 | - 'name' => __( "Business Details", 'invoicing' ), |
|
120 | - 'view' => array( $this, 'setup_business' ), |
|
119 | + 'name' => __("Business Details", 'invoicing'), |
|
120 | + 'view' => array($this, 'setup_business'), |
|
121 | 121 | 'handler' => '', |
122 | 122 | ), |
123 | 123 | |
124 | 124 | 'currency' => array( |
125 | - 'name' => __( 'Currency', 'invoicing' ), |
|
126 | - 'view' => array( $this, 'setup_currency' ), |
|
125 | + 'name' => __('Currency', 'invoicing'), |
|
126 | + 'view' => array($this, 'setup_currency'), |
|
127 | 127 | 'handler' => '', |
128 | 128 | ), |
129 | 129 | |
130 | 130 | 'payments' => array( |
131 | - 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
132 | - 'view' => array( $this, 'setup_payments' ), |
|
133 | - 'handler' => array( $this, 'setup_payments_save' ), |
|
131 | + 'name' => __('Payment Gateways', 'invoicing'), |
|
132 | + 'view' => array($this, 'setup_payments'), |
|
133 | + 'handler' => array($this, 'setup_payments_save'), |
|
134 | 134 | ), |
135 | 135 | |
136 | 136 | 'recommend' => array( |
137 | - 'name' => __( 'Recommend', 'invoicing' ), |
|
138 | - 'view' => array( $this, 'setup_recommend' ), |
|
137 | + 'name' => __('Recommend', 'invoicing'), |
|
138 | + 'view' => array($this, 'setup_recommend'), |
|
139 | 139 | 'handler' => '', |
140 | 140 | ), |
141 | 141 | |
142 | 142 | 'next_steps' => array( |
143 | - 'name' => __( 'Get Paid', 'invoicing' ), |
|
144 | - 'view' => array( $this, 'setup_ready' ), |
|
143 | + 'name' => __('Get Paid', 'invoicing'), |
|
144 | + 'view' => array($this, 'setup_ready'), |
|
145 | 145 | 'handler' => '', |
146 | 146 | ), |
147 | 147 | |
148 | 148 | ); |
149 | 149 | |
150 | - return apply_filters( 'getpaid_setup_wizard_steps', $steps ); |
|
150 | + return apply_filters('getpaid_setup_wizard_steps', $steps); |
|
151 | 151 | |
152 | 152 | } |
153 | 153 | |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | protected function get_current_step() { |
161 | - $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : ''; |
|
162 | - return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) ); |
|
161 | + $step = isset($_GET['step']) ? sanitize_key($_GET['step']) : ''; |
|
162 | + return !empty($step) && in_array($step, array_keys($this->steps)) ? $step : current(array_keys($this->steps)); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -172,8 +172,8 @@ discard block |
||
172 | 172 | |
173 | 173 | $previous = false; |
174 | 174 | $current = $this->step; |
175 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
176 | - if ( $current === $step ) { |
|
175 | + foreach (array_keys($this->steps) as $step) { |
|
176 | + if ($current === $step) { |
|
177 | 177 | return $previous; |
178 | 178 | } |
179 | 179 | |
@@ -193,13 +193,13 @@ discard block |
||
193 | 193 | |
194 | 194 | $on_current = false; |
195 | 195 | $current = $this->step; |
196 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
196 | + foreach (array_keys($this->steps) as $step) { |
|
197 | 197 | |
198 | - if ( $on_current ) { |
|
198 | + if ($on_current) { |
|
199 | 199 | return $step; |
200 | 200 | } |
201 | 201 | |
202 | - if ( $current === $step ) { |
|
202 | + if ($current === $step) { |
|
203 | 203 | return $on_current = true; |
204 | 204 | } |
205 | 205 | |
@@ -228,8 +228,8 @@ discard block |
||
228 | 228 | $steps = $this->steps; |
229 | 229 | $current = $this->step; |
230 | 230 | $next_step = $this->next_step; |
231 | - array_shift( $steps ); |
|
232 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php'; |
|
231 | + array_shift($steps); |
|
232 | + include plugin_dir_path(__FILE__) . 'views/wizard-header.php'; |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | ?> |
242 | 242 | <div class="gp-setup-content rowx mw-100 text-center mb-3"> |
243 | 243 | <div class="col-12 col-md-5 m-auto"> |
244 | - <?php call_user_func( $this->steps[ $this->step ]['view'], $this ); ?> |
|
244 | + <?php call_user_func($this->steps[$this->step]['view'], $this); ?> |
|
245 | 245 | </div> |
246 | 246 | </div> |
247 | 247 | <?php |
@@ -254,9 +254,9 @@ discard block |
||
254 | 254 | */ |
255 | 255 | public function display_footer() { |
256 | 256 | |
257 | - if ( isset( $_GET['step'] ) ) { |
|
258 | - $next_url = esc_url( $this->get_next_step_link() ); |
|
259 | - $label = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' ); |
|
257 | + if (isset($_GET['step'])) { |
|
258 | + $next_url = esc_url($this->get_next_step_link()); |
|
259 | + $label = $this->step == 'next_steps' ? __('Return to the WordPress Dashboard', 'invoicing') : __('Skip this step', 'invoicing'); |
|
260 | 260 | |
261 | 261 | echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . $next_url . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . $label . '</a></p>'; |
262 | 262 | } |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | */ |
272 | 272 | public function setup_introduction() { |
273 | 273 | $next_url = $this->get_next_step_link(); |
274 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php'; |
|
274 | + include plugin_dir_path(__FILE__) . 'views/wizard-introduction.php'; |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -284,22 +284,22 @@ discard block |
||
284 | 284 | * Empty string on failure. |
285 | 285 | * @since 3.0.0 |
286 | 286 | */ |
287 | - public function get_next_step_link( $step = '' ) { |
|
288 | - if ( ! $step ) { |
|
287 | + public function get_next_step_link($step = '') { |
|
288 | + if (!$step) { |
|
289 | 289 | $step = $this->step; |
290 | 290 | } |
291 | 291 | |
292 | - $keys = array_keys( $this->steps ); |
|
293 | - if ( end( $keys ) === $step ) { |
|
292 | + $keys = array_keys($this->steps); |
|
293 | + if (end($keys) === $step) { |
|
294 | 294 | return admin_url(); |
295 | 295 | } |
296 | 296 | |
297 | - $step_index = array_search( $step, $keys ); |
|
298 | - if ( false === $step_index ) { |
|
297 | + $step_index = array_search($step, $keys); |
|
298 | + if (false === $step_index) { |
|
299 | 299 | return ''; |
300 | 300 | } |
301 | 301 | |
302 | - return remove_query_arg('settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] )); |
|
302 | + return remove_query_arg('settings-updated', add_query_arg('step', $keys[$step_index + 1])); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | $wizard = $this; |
313 | 313 | $page = 'wpinv_settings_general_main'; |
314 | 314 | $section = 'wpinv_settings_general_main'; |
315 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
315 | + include plugin_dir_path(__FILE__) . 'views/wizard-settings.php'; |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | /** |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | $wizard = $this; |
326 | 326 | $page = 'wpinv_settings_general_currency_section'; |
327 | 327 | $section = 'wpinv_settings_general_currency_section'; |
328 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
328 | + include plugin_dir_path(__FILE__) . 'views/wizard-settings.php'; |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | /** |
@@ -336,35 +336,35 @@ discard block |
||
336 | 336 | public function setup_recommend() { |
337 | 337 | $next_url = $this->get_next_step_link(); |
338 | 338 | $recommended_plugins = self::get_recommend_wp_plugins(); |
339 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php'; |
|
339 | + include plugin_dir_path(__FILE__) . 'views/wizard-plugins.php'; |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | /** |
343 | 343 | * A list of recommended wp.org plugins. |
344 | 344 | * @return array |
345 | 345 | */ |
346 | - public static function get_recommend_wp_plugins(){ |
|
346 | + public static function get_recommend_wp_plugins() { |
|
347 | 347 | return array( |
348 | 348 | 'ayecode-connect' => array( |
349 | 349 | 'file' => 'ayecode-connect/ayecode-connect.php', |
350 | 350 | 'url' => 'https://wordpress.org/plugins/ayecode-connect/', |
351 | 351 | 'slug' => 'ayecode-connect', |
352 | 352 | 'name' => 'AyeCode Connect', |
353 | - 'desc' => __( 'Documentation and Support from within your WordPress admin.', 'geodirectory' ), |
|
353 | + 'desc' => __('Documentation and Support from within your WordPress admin.', 'geodirectory'), |
|
354 | 354 | ), |
355 | 355 | 'invoicing-quotes' => array( |
356 | 356 | 'file' => 'invoicing-quotes/wpinv-quote.php', |
357 | 357 | 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
358 | 358 | 'slug' => 'invoicing-quotes', |
359 | 359 | 'name' => 'Customer Quotes', |
360 | - 'desc' => __('Create & Send Quotes to Customers and have them accept and pay.','geodirectory'), |
|
360 | + 'desc' => __('Create & Send Quotes to Customers and have them accept and pay.', 'geodirectory'), |
|
361 | 361 | ), |
362 | 362 | 'userswp' => array( |
363 | 363 | 'file' => 'userswp/userswp.php', |
364 | 364 | 'url' => 'https://wordpress.org/plugins/userswp/', |
365 | 365 | 'slug' => 'userswp', |
366 | 366 | 'name' => 'UsersWP', |
367 | - 'desc' => __('Frontend user login and registration as well as slick profile pages.','geodirectory'), |
|
367 | + 'desc' => __('Frontend user login and registration as well as slick profile pages.', 'geodirectory'), |
|
368 | 368 | ), |
369 | 369 | ); |
370 | 370 | } |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | */ |
377 | 377 | public function setup_payments() { |
378 | 378 | $next_url = $this->get_next_step_link(); |
379 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php'; |
|
379 | + include plugin_dir_path(__FILE__) . 'views/wizard-gateways.php'; |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | /** |
@@ -387,16 +387,16 @@ discard block |
||
387 | 387 | * @since 2.0.0 |
388 | 388 | */ |
389 | 389 | public function setup_payments_save() { |
390 | - check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); |
|
391 | - wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) ); |
|
390 | + check_admin_referer('getpaid-setup-wizard', 'getpaid-setup-wizard'); |
|
391 | + wpinv_update_option('manual_active', !empty($_POST['enable-manual-gateway'])); |
|
392 | 392 | |
393 | - if ( ! empty( $_POST['paypal-email'] ) ) { |
|
394 | - wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) ); |
|
395 | - wpinv_update_option( 'paypal_active', 1 ); |
|
396 | - wpinv_update_option( 'paypal_sandbox', 0 ); |
|
393 | + if (!empty($_POST['paypal-email'])) { |
|
394 | + wpinv_update_option('paypal_email', sanitize_email($_POST['paypal-email'])); |
|
395 | + wpinv_update_option('paypal_active', 1); |
|
396 | + wpinv_update_option('paypal_sandbox', 0); |
|
397 | 397 | } |
398 | 398 | |
399 | - wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
|
399 | + wp_redirect(esc_url_raw($this->get_next_step_link())); |
|
400 | 400 | exit; |
401 | 401 | } |
402 | 402 | |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | * @since 2.0.0 |
407 | 407 | */ |
408 | 408 | public function setup_ready() { |
409 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php'; |
|
409 | + include plugin_dir_path(__FILE__) . 'views/wizard-thank-you.php'; |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | } |