Passed
Push — master ( b23fa6...8cf7d7 )
by Brian
15:03
created
includes/class-getpaid-invoice-notification-emails.php 2 patches
Indentation   +454 added lines, -454 removed lines patch added patch discarded remove patch
@@ -12,489 +12,489 @@
 block discarded – undo
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
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
166
-	}
167
-
168
-	/**
169
-	 * Helper function to send an email.
170
-	 *
171
-	 * @param WPInv_Invoice $invoice
172
-	 * @param GetPaid_Notification_Email $email
173
-	 * @param string $type
174
-	 * @param string|array $recipients
175
-	 * @param array $extra_args Extra template args.
176
-	 */
177
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
178
-
179
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
180
-
181
-		$skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
182
-		if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
183
-			return;
184
-		}
185
-
186
-		$mailer     = new GetPaid_Notification_Email_Sender();
187
-		$merge_tags = $email->get_merge_tags();
188
-
189
-		$result = $mailer->send(
190
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
191
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
192
-			$email->get_content( $merge_tags, $extra_args ),
193
-			$email->get_attachments()
194
-		);
195
-
196
-		// Maybe send a copy to the admin.
197
-		if ( $email->include_admin_bcc() ) {
198
-			$mailer->send(
199
-				wpinv_get_admin_email(),
200
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
201
-				$email->get_content( $merge_tags ),
202
-				$email->get_attachments()
203
-			);
204
-		}
205
-
206
-		if ( $result ) {
207
-			$invoice->add_system_note(
208
-				sprintf(
209
-					// translators: %1 is the email type, %2 is the invoice recipient.
210
-					__( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ),
211
-					sanitize_key( $type ),
212
-					$email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
213
-				)
214
-			);
215
-		} else {
216
-			$invoice->add_system_note(
217
-				sprintf(
218
-					// translators: %1 is the email type, %2 is the invoice recipient.
219
-					__( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ),
220
-					sanitize_key( $type ),
221
-					$email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
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
-		return $recipients;
255
-
256
-	}
257
-
258
-	/**
259
-	 * Sends a new invoice notification.
260
-	 *
261
-	 * @param WPInv_Invoice $invoice
262
-	 */
263
-	public function new_invoice( $invoice ) {
264
-
265
-		// Only send this email for invoices created via the admin page.
266
-		if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
267
-			return;
268
-		}
269
-
270
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
271
-		$recipient = wpinv_get_admin_email();
272
-
273
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
274
-
275
-	}
276
-
277
-	/**
278
-	 * Sends a cancelled invoice notification.
279
-	 *
280
-	 * @param WPInv_Invoice $invoice
281
-	 */
282
-	public function cancelled_invoice( $invoice ) {
283
-
284
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
285
-		$recipient = $invoice->get_email();
286
-
287
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
288
-	}
289
-
290
-	/**
291
-	 * Sends a failed invoice notification.
292
-	 *
293
-	 * @param WPInv_Invoice $invoice
294
-	 */
295
-	public function failed_invoice( $invoice ) {
296
-
297
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
298
-		$recipient = wpinv_get_admin_email();
299
-
300
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
301
-
302
-	}
303
-
304
-	/**
305
-	 * Sends a notification whenever an invoice is put on hold.
306
-	 *
307
-	 * @param WPInv_Invoice $invoice
308
-	 */
309
-	public function onhold_invoice( $invoice ) {
310
-
311
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
312
-		$recipient = $invoice->get_email();
313
-
314
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
315
-
316
-	}
317
-
318
-	/**
319
-	 * Sends a notification whenever an invoice is marked as processing payment.
320
-	 *
321
-	 * @param WPInv_Invoice $invoice
322
-	 */
323
-	public function processing_invoice( $invoice ) {
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 ) ) {
324 153
 
325
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
326
-		$recipient = $invoice->get_email();
327
-
328
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
329
-
330
-	}
331
-
332
-	/**
333
-	 * Sends a notification whenever an invoice is paid.
334
-	 *
335
-	 * @param WPInv_Invoice $invoice
336
-	 */
337
-	public function completed_invoice( $invoice ) {
154
+            foreach ( $payment_form_data as $label => $value ) {
338 155
 
339
-		// (Maybe) abort if it is a renewal invoice.
340
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
341
-			return;
342
-		}
343
-
344
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
345
-		$recipient = $invoice->get_email();
156
+                $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
+                $value = is_array( $value ) ? implode( ', ', $value ) : $value;
346 158
 
347
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
159
+                if ( is_scalar( $value ) ) {
160
+                    $merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
161
+                }
162
+            }
163
+        }
348 164
 
349
-	}
165
+        return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
166
+    }
350 167
 
351
-	/**
352
-	 * Sends a notification whenever an invoice is refunded.
353
-	 *
354
-	 * @param WPInv_Invoice $invoice
355
-	 */
356
-	public function refunded_invoice( $invoice ) {
168
+    /**
169
+     * Helper function to send an email.
170
+     *
171
+     * @param WPInv_Invoice $invoice
172
+     * @param GetPaid_Notification_Email $email
173
+     * @param string $type
174
+     * @param string|array $recipients
175
+     * @param array $extra_args Extra template args.
176
+     */
177
+    public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
357 178
 
358
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
359
-		$recipient = $invoice->get_email();
360
-
361
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
179
+        do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
180
+
181
+        $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
182
+        if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
183
+            return;
184
+        }
185
+
186
+        $mailer     = new GetPaid_Notification_Email_Sender();
187
+        $merge_tags = $email->get_merge_tags();
188
+
189
+        $result = $mailer->send(
190
+            apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
191
+            $email->add_merge_tags( $email->get_subject(), $merge_tags ),
192
+            $email->get_content( $merge_tags, $extra_args ),
193
+            $email->get_attachments()
194
+        );
362 195
 
363
-	}
196
+        // Maybe send a copy to the admin.
197
+        if ( $email->include_admin_bcc() ) {
198
+            $mailer->send(
199
+                wpinv_get_admin_email(),
200
+                $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
201
+                $email->get_content( $merge_tags ),
202
+                $email->get_attachments()
203
+            );
204
+        }
205
+
206
+        if ( $result ) {
207
+            $invoice->add_system_note(
208
+                sprintf(
209
+                    // translators: %1 is the email type, %2 is the invoice recipient.
210
+                    __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ),
211
+                    sanitize_key( $type ),
212
+                    $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
213
+                )
214
+            );
215
+        } else {
216
+            $invoice->add_system_note(
217
+                sprintf(
218
+                    // translators: %1 is the email type, %2 is the invoice recipient.
219
+                    __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ),
220
+                    sanitize_key( $type ),
221
+                    $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
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
+        return $recipients;
255
+
256
+    }
257
+
258
+    /**
259
+     * Sends a new invoice notification.
260
+     *
261
+     * @param WPInv_Invoice $invoice
262
+     */
263
+    public function new_invoice( $invoice ) {
264
+
265
+        // Only send this email for invoices created via the admin page.
266
+        if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
267
+            return;
268
+        }
269
+
270
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
271
+        $recipient = wpinv_get_admin_email();
272
+
273
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
274
+
275
+    }
276
+
277
+    /**
278
+     * Sends a cancelled invoice notification.
279
+     *
280
+     * @param WPInv_Invoice $invoice
281
+     */
282
+    public function cancelled_invoice( $invoice ) {
283
+
284
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
285
+        $recipient = $invoice->get_email();
286
+
287
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
288
+    }
289
+
290
+    /**
291
+     * Sends a failed invoice notification.
292
+     *
293
+     * @param WPInv_Invoice $invoice
294
+     */
295
+    public function failed_invoice( $invoice ) {
296
+
297
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
298
+        $recipient = wpinv_get_admin_email();
299
+
300
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
301
+
302
+    }
303
+
304
+    /**
305
+     * Sends a notification whenever an invoice is put on hold.
306
+     *
307
+     * @param WPInv_Invoice $invoice
308
+     */
309
+    public function onhold_invoice( $invoice ) {
310
+
311
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
312
+        $recipient = $invoice->get_email();
313
+
314
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
315
+
316
+    }
317
+
318
+    /**
319
+     * Sends a notification whenever an invoice is marked as processing payment.
320
+     *
321
+     * @param WPInv_Invoice $invoice
322
+     */
323
+    public function processing_invoice( $invoice ) {
364 324
 
365
-	/**
366
-	 * Notifies a user about new invoices
367
-	 *
368
-	 * @param WPInv_Invoice $invoice
369
-	 * @param bool $force
370
-	 */
371
-	public function user_invoice( $invoice, $force = false ) {
325
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
326
+        $recipient = $invoice->get_email();
327
+
328
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
329
+
330
+    }
331
+
332
+    /**
333
+     * Sends a notification whenever an invoice is paid.
334
+     *
335
+     * @param WPInv_Invoice $invoice
336
+     */
337
+    public function completed_invoice( $invoice ) {
372 338
 
373
-		if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
374
-			return;
375
-		}
376
-
377
-		// Only send this email for invoices created via the admin page.
378
-		if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
379
-			return;
380
-		}
339
+        // (Maybe) abort if it is a renewal invoice.
340
+        if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
341
+            return;
342
+        }
343
+
344
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
345
+        $recipient = $invoice->get_email();
381 346
 
382
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
383
-		$recipient = $invoice->get_email();
384
-
385
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
347
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
386 348
 
387
-	}
388
-
389
-	/**
390
-	 * Checks if an invoice is a payment form invoice.
391
-	 *
392
-	 * @param int $invoice
393
-	 * @return bool
394
-	 */
395
-	public function is_payment_form_invoice( $invoice ) {
396
-		$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 ) );
397
-		return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
398
-	}
349
+    }
399 350
 
400
-	/**
401
-	 * Notifies admin about new invoice notes
402
-	 *
403
-	 * @param WPInv_Invoice $invoice
404
-	 * @param string $note
405
-	 */
406
-	public function user_note( $invoice, $note ) {
407
-
408
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
409
-		$recipient = $invoice->get_email();
351
+    /**
352
+     * Sends a notification whenever an invoice is refunded.
353
+     *
354
+     * @param WPInv_Invoice $invoice
355
+     */
356
+    public function refunded_invoice( $invoice ) {
410 357
 
411
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
412
-
413
-	}
414
-
415
-	/**
416
-	 * (Force) Sends overdue notices.
417
-	 *
418
-	 * @param WPInv_Invoice $invoice
419
-	 */
420
-	public function force_send_overdue_notice( $invoice ) {
421
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
422
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
423
-	}
424
-
425
-	/**
426
-	 * Sends overdue notices.
427
-	 *
428
-	 * @TODO: Create an invoices query class.
429
-	 */
430
-	public function overdue() {
431
-		global $wpdb;
432
-
433
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
434
-
435
-		// Fetch reminder days.
436
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
437
-
438
-		// Abort if non is set.
439
-		if ( empty( $reminder_days ) ) {
440
-			return;
441
-		}
442
-
443
-		// Retrieve date query.
444
-		$date_query = $this->get_date_query( $reminder_days );
445
-
446
-		// Invoices table.
447
-		$table = $wpdb->prefix . 'getpaid_invoices';
448
-
449
-		// Fetch invoices.
450
-		$invoices  = $wpdb->get_col(
451
-			"SELECT posts.ID FROM $wpdb->posts as posts
358
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
359
+        $recipient = $invoice->get_email();
360
+
361
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
362
+
363
+    }
364
+
365
+    /**
366
+     * Notifies a user about new invoices
367
+     *
368
+     * @param WPInv_Invoice $invoice
369
+     * @param bool $force
370
+     */
371
+    public function user_invoice( $invoice, $force = false ) {
372
+
373
+        if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
374
+            return;
375
+        }
376
+
377
+        // Only send this email for invoices created via the admin page.
378
+        if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
379
+            return;
380
+        }
381
+
382
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
383
+        $recipient = $invoice->get_email();
384
+
385
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
386
+
387
+    }
388
+
389
+    /**
390
+     * Checks if an invoice is a payment form invoice.
391
+     *
392
+     * @param int $invoice
393
+     * @return bool
394
+     */
395
+    public function is_payment_form_invoice( $invoice ) {
396
+        $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 ) );
397
+        return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
398
+    }
399
+
400
+    /**
401
+     * Notifies admin about new invoice notes
402
+     *
403
+     * @param WPInv_Invoice $invoice
404
+     * @param string $note
405
+     */
406
+    public function user_note( $invoice, $note ) {
407
+
408
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
409
+        $recipient = $invoice->get_email();
410
+
411
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
412
+
413
+    }
414
+
415
+    /**
416
+     * (Force) Sends overdue notices.
417
+     *
418
+     * @param WPInv_Invoice $invoice
419
+     */
420
+    public function force_send_overdue_notice( $invoice ) {
421
+        $email = new GetPaid_Notification_Email( 'overdue', $invoice );
422
+        return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
423
+    }
424
+
425
+    /**
426
+     * Sends overdue notices.
427
+     *
428
+     * @TODO: Create an invoices query class.
429
+     */
430
+    public function overdue() {
431
+        global $wpdb;
432
+
433
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
434
+
435
+        // Fetch reminder days.
436
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
437
+
438
+        // Abort if non is set.
439
+        if ( empty( $reminder_days ) ) {
440
+            return;
441
+        }
442
+
443
+        // Retrieve date query.
444
+        $date_query = $this->get_date_query( $reminder_days );
445
+
446
+        // Invoices table.
447
+        $table = $wpdb->prefix . 'getpaid_invoices';
448
+
449
+        // Fetch invoices.
450
+        $invoices  = $wpdb->get_col(
451
+            "SELECT posts.ID FROM $wpdb->posts as posts
452 452
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
453 453
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query"
454 454
         );
455 455
 
456
-		foreach ( $invoices as $invoice ) {
456
+        foreach ( $invoices as $invoice ) {
457 457
 
458
-			// Only send this email for invoices created via the admin page.
459
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
460
-				$invoice       = new WPInv_Invoice( $invoice );
461
-				$email->object = $invoice;
458
+            // Only send this email for invoices created via the admin page.
459
+            if ( ! $this->is_payment_form_invoice( $invoice ) ) {
460
+                $invoice       = new WPInv_Invoice( $invoice );
461
+                $email->object = $invoice;
462 462
 
463
-				if ( $invoice->needs_payment() ) {
464
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
465
-				}
463
+                if ( $invoice->needs_payment() ) {
464
+                    $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
465
+                }
466 466
 }
467 467
 }
468 468
 
469
-	}
469
+    }
470 470
 
471
-	/**
472
-	 * Calculates the date query for an invoices query
473
-	 *
474
-	 * @param array $reminder_days
475
-	 * @return string
476
-	 */
477
-	public function get_date_query( $reminder_days ) {
471
+    /**
472
+     * Calculates the date query for an invoices query
473
+     *
474
+     * @param array $reminder_days
475
+     * @return string
476
+     */
477
+    public function get_date_query( $reminder_days ) {
478 478
 
479
-		$date_query = array(
480
-			'relation' => 'OR',
481
-		);
479
+        $date_query = array(
480
+            'relation' => 'OR',
481
+        );
482 482
 
483
-		foreach ( $reminder_days as $days ) {
484
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
483
+        foreach ( $reminder_days as $days ) {
484
+            $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
485 485
 
486
-			$date_query[] = array(
487
-				'year'  => $date['year'],
488
-				'month' => $date['month'],
489
-				'day'   => $date['day'],
490
-			);
486
+            $date_query[] = array(
487
+                'year'  => $date['year'],
488
+                'month' => $date['month'],
489
+                'day'   => $date['day'],
490
+            );
491 491
 
492
-		}
492
+        }
493 493
 
494
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
494
+        $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
495 495
 
496
-		return $date_query->get_sql();
496
+        return $date_query->get_sql();
497 497
 
498
-	}
498
+    }
499 499
 
500 500
 }
Please login to merge, or discard this patch.
Spacing   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,50 +119,50 @@  discard block
 block discarded – undo
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
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
165
+		return apply_filters('getpaid_invoice_email_merge_tags', $merge_tags, $invoice);
166 166
 	}
167 167
 
168 168
 	/**
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
 	 * @param string|array $recipients
175 175
 	 * @param array $extra_args Extra template args.
176 176
 	 */
177
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
177
+	public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) {
178 178
 
179
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
179
+		do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email);
180 180
 
181
-		$skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
182
-		if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
181
+		$skip = $invoice->is_free() && wpinv_get_option('skip_email_free_invoice');
182
+		if (apply_filters('getpaid_skip_invoice_email', $skip, $type, $invoice)) {
183 183
 			return;
184 184
 		}
185 185
 
@@ -187,43 +187,43 @@  discard block
 block discarded – undo
187 187
 		$merge_tags = $email->get_merge_tags();
188 188
 
189 189
 		$result = $mailer->send(
190
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
191
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
192
-			$email->get_content( $merge_tags, $extra_args ),
190
+			apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email),
191
+			$email->add_merge_tags($email->get_subject(), $merge_tags),
192
+			$email->get_content($merge_tags, $extra_args),
193 193
 			$email->get_attachments()
194 194
 		);
195 195
 
196 196
 		// Maybe send a copy to the admin.
197
-		if ( $email->include_admin_bcc() ) {
197
+		if ($email->include_admin_bcc()) {
198 198
 			$mailer->send(
199 199
 				wpinv_get_admin_email(),
200
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
201
-				$email->get_content( $merge_tags ),
200
+				$email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags),
201
+				$email->get_content($merge_tags),
202 202
 				$email->get_attachments()
203 203
 			);
204 204
 		}
205 205
 
206
-		if ( $result ) {
206
+		if ($result) {
207 207
 			$invoice->add_system_note(
208 208
 				sprintf(
209 209
 					// translators: %1 is the email type, %2 is the invoice recipient.
210
-					__( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ),
211
-					sanitize_key( $type ),
212
-					$email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
210
+					__('Successfully sent %1$s notification email to %2$s.', 'invoicing'),
211
+					sanitize_key($type),
212
+					$email->is_admin_email() ? __('admin', 'invoicing') : __('the customer', 'invoicing')
213 213
 				)
214 214
 			);
215 215
 		} else {
216 216
 			$invoice->add_system_note(
217 217
 				sprintf(
218 218
 					// translators: %1 is the email type, %2 is the invoice recipient.
219
-					__( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ),
220
-					sanitize_key( $type ),
221
-					$email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
219
+					__('Failed sending %1$s notification email to %2$s.', 'invoicing'),
220
+					sanitize_key($type),
221
+					$email->is_admin_email() ? __('admin', 'invoicing') : __('the customer', 'invoicing')
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
 block discarded – undo
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
 
@@ -260,17 +260,17 @@  discard block
 block discarded – undo
260 260
 	 *
261 261
 	 * @param WPInv_Invoice $invoice
262 262
 	 */
263
-	public function new_invoice( $invoice ) {
263
+	public function new_invoice($invoice) {
264 264
 
265 265
 		// Only send this email for invoices created via the admin page.
266
-		if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
266
+		if (!$invoice->is_type('invoice') || $invoice->is_paid() || $this->is_payment_form_invoice($invoice->get_id())) {
267 267
 			return;
268 268
 		}
269 269
 
270
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
270
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
271 271
 		$recipient = wpinv_get_admin_email();
272 272
 
273
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
273
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
274 274
 
275 275
 	}
276 276
 
@@ -279,12 +279,12 @@  discard block
 block discarded – undo
279 279
 	 *
280 280
 	 * @param WPInv_Invoice $invoice
281 281
 	 */
282
-	public function cancelled_invoice( $invoice ) {
282
+	public function cancelled_invoice($invoice) {
283 283
 
284
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
284
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
285 285
 		$recipient = $invoice->get_email();
286 286
 
287
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
287
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
288 288
 	}
289 289
 
290 290
 	/**
@@ -292,12 +292,12 @@  discard block
 block discarded – undo
292 292
 	 *
293 293
 	 * @param WPInv_Invoice $invoice
294 294
 	 */
295
-	public function failed_invoice( $invoice ) {
295
+	public function failed_invoice($invoice) {
296 296
 
297
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
297
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
298 298
 		$recipient = wpinv_get_admin_email();
299 299
 
300
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
300
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
301 301
 
302 302
 	}
303 303
 
@@ -306,12 +306,12 @@  discard block
 block discarded – undo
306 306
 	 *
307 307
 	 * @param WPInv_Invoice $invoice
308 308
 	 */
309
-	public function onhold_invoice( $invoice ) {
309
+	public function onhold_invoice($invoice) {
310 310
 
311
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
311
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
312 312
 		$recipient = $invoice->get_email();
313 313
 
314
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
314
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
315 315
 
316 316
 	}
317 317
 
@@ -320,12 +320,12 @@  discard block
 block discarded – undo
320 320
 	 *
321 321
 	 * @param WPInv_Invoice $invoice
322 322
 	 */
323
-	public function processing_invoice( $invoice ) {
323
+	public function processing_invoice($invoice) {
324 324
 
325
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
325
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
326 326
 		$recipient = $invoice->get_email();
327 327
 
328
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
328
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
329 329
 
330 330
 	}
331 331
 
@@ -334,17 +334,17 @@  discard block
 block discarded – undo
334 334
 	 *
335 335
 	 * @param WPInv_Invoice $invoice
336 336
 	 */
337
-	public function completed_invoice( $invoice ) {
337
+	public function completed_invoice($invoice) {
338 338
 
339 339
 		// (Maybe) abort if it is a renewal invoice.
340
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
340
+		if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) {
341 341
 			return;
342 342
 		}
343 343
 
344
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
344
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
345 345
 		$recipient = $invoice->get_email();
346 346
 
347
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
347
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
348 348
 
349 349
 	}
350 350
 
@@ -353,12 +353,12 @@  discard block
 block discarded – undo
353 353
 	 *
354 354
 	 * @param WPInv_Invoice $invoice
355 355
 	 */
356
-	public function refunded_invoice( $invoice ) {
356
+	public function refunded_invoice($invoice) {
357 357
 
358
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
358
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
359 359
 		$recipient = $invoice->get_email();
360 360
 
361
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
361
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
362 362
 
363 363
 	}
364 364
 
@@ -368,21 +368,21 @@  discard block
 block discarded – undo
368 368
 	 * @param WPInv_Invoice $invoice
369 369
 	 * @param bool $force
370 370
 	 */
371
-	public function user_invoice( $invoice, $force = false ) {
371
+	public function user_invoice($invoice, $force = false) {
372 372
 
373
-		if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
373
+		if (!$force && !empty($GLOBALS['wpinv_skip_invoice_notification'])) {
374 374
 			return;
375 375
 		}
376 376
 
377 377
 		// Only send this email for invoices created via the admin page.
378
-		if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
378
+		if (!$invoice->is_type('invoice') || (empty($force) && $invoice->is_paid()) || (empty($force) && $this->is_payment_form_invoice($invoice->get_id()))) {
379 379
 			return;
380 380
 		}
381 381
 
382
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
382
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
383 383
 		$recipient = $invoice->get_email();
384 384
 
385
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
385
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
386 386
 
387 387
 	}
388 388
 
@@ -392,9 +392,9 @@  discard block
 block discarded – undo
392 392
 	 * @param int $invoice
393 393
 	 * @return bool
394 394
 	 */
395
-	public function is_payment_form_invoice( $invoice ) {
396
-		$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 ) );
397
-		return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
395
+	public function is_payment_form_invoice($invoice) {
396
+		$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));
397
+		return apply_filters('getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice);
398 398
 	}
399 399
 
400 400
 	/**
@@ -403,12 +403,12 @@  discard block
 block discarded – undo
403 403
 	 * @param WPInv_Invoice $invoice
404 404
 	 * @param string $note
405 405
 	 */
406
-	public function user_note( $invoice, $note ) {
406
+	public function user_note($invoice, $note) {
407 407
 
408
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
408
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
409 409
 		$recipient = $invoice->get_email();
410 410
 
411
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
411
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note));
412 412
 
413 413
 	}
414 414
 
@@ -417,9 +417,9 @@  discard block
 block discarded – undo
417 417
 	 *
418 418
 	 * @param WPInv_Invoice $invoice
419 419
 	 */
420
-	public function force_send_overdue_notice( $invoice ) {
421
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
422
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
420
+	public function force_send_overdue_notice($invoice) {
421
+		$email = new GetPaid_Notification_Email('overdue', $invoice);
422
+		return $this->send_email($invoice, $email, 'overdue', $invoice->get_email());
423 423
 	}
424 424
 
425 425
 	/**
@@ -430,38 +430,38 @@  discard block
 block discarded – undo
430 430
 	public function overdue() {
431 431
 		global $wpdb;
432 432
 
433
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
433
+		$email = new GetPaid_Notification_Email(__FUNCTION__);
434 434
 
435 435
 		// Fetch reminder days.
436
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
436
+		$reminder_days = array_unique(wp_parse_id_list($email->get_option('days')));
437 437
 
438 438
 		// Abort if non is set.
439
-		if ( empty( $reminder_days ) ) {
439
+		if (empty($reminder_days)) {
440 440
 			return;
441 441
 		}
442 442
 
443 443
 		// Retrieve date query.
444
-		$date_query = $this->get_date_query( $reminder_days );
444
+		$date_query = $this->get_date_query($reminder_days);
445 445
 
446 446
 		// Invoices table.
447 447
 		$table = $wpdb->prefix . 'getpaid_invoices';
448 448
 
449 449
 		// Fetch invoices.
450
-		$invoices  = $wpdb->get_col(
450
+		$invoices = $wpdb->get_col(
451 451
 			"SELECT posts.ID FROM $wpdb->posts as posts
452 452
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
453 453
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query"
454 454
         );
455 455
 
456
-		foreach ( $invoices as $invoice ) {
456
+		foreach ($invoices as $invoice) {
457 457
 
458 458
 			// Only send this email for invoices created via the admin page.
459
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
460
-				$invoice       = new WPInv_Invoice( $invoice );
459
+			if (!$this->is_payment_form_invoice($invoice)) {
460
+				$invoice       = new WPInv_Invoice($invoice);
461 461
 				$email->object = $invoice;
462 462
 
463
-				if ( $invoice->needs_payment() ) {
464
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
463
+				if ($invoice->needs_payment()) {
464
+					$this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email());
465 465
 				}
466 466
 }
467 467
 }
@@ -474,14 +474,14 @@  discard block
 block discarded – undo
474 474
 	 * @param array $reminder_days
475 475
 	 * @return string
476 476
 	 */
477
-	public function get_date_query( $reminder_days ) {
477
+	public function get_date_query($reminder_days) {
478 478
 
479 479
 		$date_query = array(
480 480
 			'relation' => 'OR',
481 481
 		);
482 482
 
483
-		foreach ( $reminder_days as $days ) {
484
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
483
+		foreach ($reminder_days as $days) {
484
+			$date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp'))));
485 485
 
486 486
 			$date_query[] = array(
487 487
 				'year'  => $date['year'],
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
 
492 492
 		}
493 493
 
494
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
494
+		$date_query = new WP_Date_Query($date_query, 'invoices.due_date');
495 495
 
496 496
 		return $date_query->get_sql();
497 497
 
Please login to merge, or discard this patch.
includes/reports/class-getpaid-reports-export.php 2 patches
Indentation   +181 added lines, -181 removed lines patch added patch discarded remove patch
@@ -12,47 +12,47 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Reports_Export {
14 14
 
15
-	/**
16
-	 * Displays the reports tab.
17
-	 *
18
-	 */
19
-	public function display() {
20
-
21
-		echo "<div class='row mt-4' style='max-width: 920px;' >";
22
-		foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
23
-			$this->display_post_type_export( $post_type );
24
-		}
25
-		$this->display_subscription_export();
26
-		echo '</div>';
27
-
28
-	}
29
-
30
-	/**
31
-	 * Retrieves the download url.
32
-	 *
33
-	 */
34
-	public function get_download_url( $post_type ) {
35
-
36
-		return wp_nonce_url(
37
-			add_query_arg(
38
-				array(
39
-					'getpaid-admin-action' => 'export_invoices',
40
-					'post_type'            => urlencode( $post_type ),
41
-				)
42
-			),
43
-			'getpaid-nonce',
44
-			'getpaid-nonce'
45
-		);
46
-
47
-	}
48
-
49
-	/**
50
-	 * Displays a single post type export card.
51
-	 *
52
-	 */
53
-	public function display_post_type_export( $post_type ) {
54
-
55
-		?>
15
+    /**
16
+     * Displays the reports tab.
17
+     *
18
+     */
19
+    public function display() {
20
+
21
+        echo "<div class='row mt-4' style='max-width: 920px;' >";
22
+        foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
23
+            $this->display_post_type_export( $post_type );
24
+        }
25
+        $this->display_subscription_export();
26
+        echo '</div>';
27
+
28
+    }
29
+
30
+    /**
31
+     * Retrieves the download url.
32
+     *
33
+     */
34
+    public function get_download_url( $post_type ) {
35
+
36
+        return wp_nonce_url(
37
+            add_query_arg(
38
+                array(
39
+                    'getpaid-admin-action' => 'export_invoices',
40
+                    'post_type'            => urlencode( $post_type ),
41
+                )
42
+            ),
43
+            'getpaid-nonce',
44
+            'getpaid-nonce'
45
+        );
46
+
47
+    }
48
+
49
+    /**
50
+     * Displays a single post type export card.
51
+     *
52
+     */
53
+    public function display_post_type_export( $post_type ) {
54
+
55
+        ?>
56 56
 
57 57
 		<div class="col-12 col-md-6">
58 58
 			<div class="card m-0 p-0" style="max-width:100%">
@@ -60,11 +60,11 @@  discard block
 block discarded – undo
60 60
 				<div class="card-header">
61 61
 					<strong>
62 62
 						<?php
63
-							printf(
64
-								esc_html__( 'Export %s', 'invoicing' ),
65
-								esc_html( getpaid_get_post_type_label( $post_type ) )
66
-							);
67
-						?>
63
+                            printf(
64
+                                esc_html__( 'Export %s', 'invoicing' ),
65
+                                esc_html( getpaid_get_post_type_label( $post_type ) )
66
+                            );
67
+                        ?>
68 68
 					</strong>
69 69
 				</div>
70 70
 
@@ -73,12 +73,12 @@  discard block
 block discarded – undo
73 73
 					<form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>">
74 74
 
75 75
 						<?php
76
-							$this->display_markup( $this->generate_from_date( $post_type ) );
77
-							$this->display_markup( $this->generate_to_date( $post_type ) );
78
-							$this->display_markup( $this->generate_post_status_select( $post_type ) );
79
-							$this->display_markup( $this->generate_file_type_select( $post_type ) );
80
-							submit_button( __( 'Download', 'invoicing' ) );
81
-						?>
76
+                            $this->display_markup( $this->generate_from_date( $post_type ) );
77
+                            $this->display_markup( $this->generate_to_date( $post_type ) );
78
+                            $this->display_markup( $this->generate_post_status_select( $post_type ) );
79
+                            $this->display_markup( $this->generate_file_type_select( $post_type ) );
80
+                            submit_button( __( 'Download', 'invoicing' ) );
81
+                        ?>
82 82
 
83 83
 					</form>
84 84
 
@@ -89,128 +89,128 @@  discard block
 block discarded – undo
89 89
 
90 90
 		<?php
91 91
 
92
-	}
93
-
94
-	/**
95
-	 * Generates the from date input field.
96
-	 *
97
-	 */
98
-	public function generate_from_date( $post_type ) {
99
-
100
-		return aui()->input(
101
-			array(
102
-				'type'             => 'datepicker',
103
-				'id'               => esc_attr( "$post_type-from_date" ),
104
-				'name'             => 'from_date',
105
-				'label'            => __( 'From Date', 'invoicing' ),
106
-				'placeholder'      => 'YYYY-MM-DD',
107
-				'extra_attributes' => array(
108
-					'data-enable-time' => 'false',
109
-					'data-allow-input' => 'true',
110
-				),
111
-			),
112
-			false
113
-		);
114
-
115
-	}
116
-
117
-	/**
118
-	 * Generates the to date input field.
119
-	 *
120
-	 */
121
-	public function generate_to_date( $post_type ) {
122
-
123
-		return aui()->input(
124
-			array(
125
-				'name'        => 'to_date',
126
-				'id'          => esc_attr( "$post_type-to_date" ),
127
-				'placeholder' => 'yy-mm-dd',
128
-				'label'       => __( 'To Date', 'invoicing' ),
129
-				'label_type'  => 'vertical',
130
-				'label_class' => 'd-block',
131
-				'type'        => 'datepicker',
132
-			)
133
-		);
134
-
135
-	}
136
-
137
-	/**
138
-	 * Generates the to post status select field.
139
-	 *
140
-	 */
141
-	public function generate_post_status_select( $post_type ) {
142
-
143
-		if ( 'subscriptions' === $post_type ) {
144
-			$options = getpaid_get_subscription_statuses();
145
-		} else {
146
-			$options = wpinv_get_invoice_statuses( true, false, $post_type );
147
-		}
148
-
149
-		return aui()->select(
150
-			array(
151
-				'name'        => 'status',
152
-				'id'          => esc_attr( "$post_type-status" ),
153
-				'placeholder' => __( 'All Statuses', 'invoicing' ),
154
-				'label'       => __( 'Status', 'invoicing' ),
155
-				'label_type'  => 'vertical',
156
-				'label_class' => 'd-block',
157
-				'options'     => $options,
158
-			)
159
-		);
160
-
161
-	}
162
-
163
-	/**
164
-	 * Generates the to file type select field.
165
-	 *
166
-	 */
167
-	public function generate_file_type_select( $post_type ) {
168
-
169
-		return aui()->select(
170
-			array(
171
-				'name'        => 'file_type',
172
-				'id'          => esc_attr( "$post_type-file_type" ),
173
-				'placeholder' => __( 'Select File Type', 'invoicing' ),
174
-				'label'       => __( 'Export File', 'invoicing' ),
175
-				'label_type'  => 'vertical',
176
-				'label_class' => 'd-block',
177
-				'options'     => array(
178
-					'csv'  => __( 'CSV', 'invoicing' ),
179
-					'xml'  => __( 'XML', 'invoicing' ),
180
-					'json' => __( 'JSON', 'invoicing' ),
181
-				),
182
-			)
183
-		);
184
-
185
-	}
186
-
187
-	/**
188
-	 * Displays a field's markup.
189
-	 *
190
-	 */
191
-	public function display_markup( $markup ) {
192
-
193
-		echo wp_kses(
194
-			str_replace(
195
-				array(
196
-					'form-control',
197
-					'custom-select',
198
-				),
199
-				'regular-text',
200
-				$markup
201
-			),
202
-			getpaid_allowed_html()
203
-		);
204
-
205
-	}
206
-
207
-	/**
208
-	 * Displays a subscription export card.
209
-	 *
210
-	 */
211
-	public function display_subscription_export() {
212
-
213
-		?>
92
+    }
93
+
94
+    /**
95
+     * Generates the from date input field.
96
+     *
97
+     */
98
+    public function generate_from_date( $post_type ) {
99
+
100
+        return aui()->input(
101
+            array(
102
+                'type'             => 'datepicker',
103
+                'id'               => esc_attr( "$post_type-from_date" ),
104
+                'name'             => 'from_date',
105
+                'label'            => __( 'From Date', 'invoicing' ),
106
+                'placeholder'      => 'YYYY-MM-DD',
107
+                'extra_attributes' => array(
108
+                    'data-enable-time' => 'false',
109
+                    'data-allow-input' => 'true',
110
+                ),
111
+            ),
112
+            false
113
+        );
114
+
115
+    }
116
+
117
+    /**
118
+     * Generates the to date input field.
119
+     *
120
+     */
121
+    public function generate_to_date( $post_type ) {
122
+
123
+        return aui()->input(
124
+            array(
125
+                'name'        => 'to_date',
126
+                'id'          => esc_attr( "$post_type-to_date" ),
127
+                'placeholder' => 'yy-mm-dd',
128
+                'label'       => __( 'To Date', 'invoicing' ),
129
+                'label_type'  => 'vertical',
130
+                'label_class' => 'd-block',
131
+                'type'        => 'datepicker',
132
+            )
133
+        );
134
+
135
+    }
136
+
137
+    /**
138
+     * Generates the to post status select field.
139
+     *
140
+     */
141
+    public function generate_post_status_select( $post_type ) {
142
+
143
+        if ( 'subscriptions' === $post_type ) {
144
+            $options = getpaid_get_subscription_statuses();
145
+        } else {
146
+            $options = wpinv_get_invoice_statuses( true, false, $post_type );
147
+        }
148
+
149
+        return aui()->select(
150
+            array(
151
+                'name'        => 'status',
152
+                'id'          => esc_attr( "$post_type-status" ),
153
+                'placeholder' => __( 'All Statuses', 'invoicing' ),
154
+                'label'       => __( 'Status', 'invoicing' ),
155
+                'label_type'  => 'vertical',
156
+                'label_class' => 'd-block',
157
+                'options'     => $options,
158
+            )
159
+        );
160
+
161
+    }
162
+
163
+    /**
164
+     * Generates the to file type select field.
165
+     *
166
+     */
167
+    public function generate_file_type_select( $post_type ) {
168
+
169
+        return aui()->select(
170
+            array(
171
+                'name'        => 'file_type',
172
+                'id'          => esc_attr( "$post_type-file_type" ),
173
+                'placeholder' => __( 'Select File Type', 'invoicing' ),
174
+                'label'       => __( 'Export File', 'invoicing' ),
175
+                'label_type'  => 'vertical',
176
+                'label_class' => 'd-block',
177
+                'options'     => array(
178
+                    'csv'  => __( 'CSV', 'invoicing' ),
179
+                    'xml'  => __( 'XML', 'invoicing' ),
180
+                    'json' => __( 'JSON', 'invoicing' ),
181
+                ),
182
+            )
183
+        );
184
+
185
+    }
186
+
187
+    /**
188
+     * Displays a field's markup.
189
+     *
190
+     */
191
+    public function display_markup( $markup ) {
192
+
193
+        echo wp_kses(
194
+            str_replace(
195
+                array(
196
+                    'form-control',
197
+                    'custom-select',
198
+                ),
199
+                'regular-text',
200
+                $markup
201
+            ),
202
+            getpaid_allowed_html()
203
+        );
204
+
205
+    }
206
+
207
+    /**
208
+     * Displays a subscription export card.
209
+     *
210
+     */
211
+    public function display_subscription_export() {
212
+
213
+        ?>
214 214
 
215 215
 		<div class="col-12 col-md-6">
216 216
 			<div class="card m-0 p-0" style="max-width:100%">
@@ -226,12 +226,12 @@  discard block
 block discarded – undo
226 226
 					<form method="post" action="<?php echo esc_url( $this->get_download_url( 'subscriptions' ) ); ?>">
227 227
 
228 228
 						<?php
229
-							$this->display_markup( $this->generate_from_date( 'subscriptions' ) );
230
-							$this->display_markup( $this->generate_to_date( 'subscriptions' ) );
231
-							$this->display_markup( $this->generate_post_status_select( 'subscriptions' ) );
232
-							$this->display_markup( $this->generate_file_type_select( 'subscriptions' ) );
233
-							submit_button( __( 'Download', 'invoicing' ) );
234
-						?>
229
+                            $this->display_markup( $this->generate_from_date( 'subscriptions' ) );
230
+                            $this->display_markup( $this->generate_to_date( 'subscriptions' ) );
231
+                            $this->display_markup( $this->generate_post_status_select( 'subscriptions' ) );
232
+                            $this->display_markup( $this->generate_file_type_select( 'subscriptions' ) );
233
+                            submit_button( __( 'Download', 'invoicing' ) );
234
+                        ?>
235 235
 
236 236
 					</form>
237 237
 
@@ -242,6 +242,6 @@  discard block
 block discarded – undo
242 242
 
243 243
 		<?php
244 244
 
245
-	}
245
+    }
246 246
 
247 247
 }
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * GetPaid_Reports_Export Class.
@@ -19,8 +19,8 @@  discard block
 block discarded – undo
19 19
 	public function display() {
20 20
 
21 21
 		echo "<div class='row mt-4' style='max-width: 920px;' >";
22
-		foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
23
-			$this->display_post_type_export( $post_type );
22
+		foreach (array_keys(getpaid_get_invoice_post_types()) as $post_type) {
23
+			$this->display_post_type_export($post_type);
24 24
 		}
25 25
 		$this->display_subscription_export();
26 26
 		echo '</div>';
@@ -31,13 +31,13 @@  discard block
 block discarded – undo
31 31
 	 * Retrieves the download url.
32 32
 	 *
33 33
 	 */
34
-	public function get_download_url( $post_type ) {
34
+	public function get_download_url($post_type) {
35 35
 
36 36
 		return wp_nonce_url(
37 37
 			add_query_arg(
38 38
 				array(
39 39
 					'getpaid-admin-action' => 'export_invoices',
40
-					'post_type'            => urlencode( $post_type ),
40
+					'post_type'            => urlencode($post_type),
41 41
 				)
42 42
 			),
43 43
 			'getpaid-nonce',
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	 * Displays a single post type export card.
51 51
 	 *
52 52
 	 */
53
-	public function display_post_type_export( $post_type ) {
53
+	public function display_post_type_export($post_type) {
54 54
 
55 55
 		?>
56 56
 
@@ -61,8 +61,8 @@  discard block
 block discarded – undo
61 61
 					<strong>
62 62
 						<?php
63 63
 							printf(
64
-								esc_html__( 'Export %s', 'invoicing' ),
65
-								esc_html( getpaid_get_post_type_label( $post_type ) )
64
+								esc_html__('Export %s', 'invoicing'),
65
+								esc_html(getpaid_get_post_type_label($post_type))
66 66
 							);
67 67
 						?>
68 68
 					</strong>
@@ -70,14 +70,14 @@  discard block
 block discarded – undo
70 70
 
71 71
 				<div class="card-body">
72 72
 
73
-					<form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>">
73
+					<form method="post" action="<?php echo esc_url($this->get_download_url($post_type)); ?>">
74 74
 
75 75
 						<?php
76
-							$this->display_markup( $this->generate_from_date( $post_type ) );
77
-							$this->display_markup( $this->generate_to_date( $post_type ) );
78
-							$this->display_markup( $this->generate_post_status_select( $post_type ) );
79
-							$this->display_markup( $this->generate_file_type_select( $post_type ) );
80
-							submit_button( __( 'Download', 'invoicing' ) );
76
+							$this->display_markup($this->generate_from_date($post_type));
77
+							$this->display_markup($this->generate_to_date($post_type));
78
+							$this->display_markup($this->generate_post_status_select($post_type));
79
+							$this->display_markup($this->generate_file_type_select($post_type));
80
+							submit_button(__('Download', 'invoicing'));
81 81
 						?>
82 82
 
83 83
 					</form>
@@ -95,14 +95,14 @@  discard block
 block discarded – undo
95 95
 	 * Generates the from date input field.
96 96
 	 *
97 97
 	 */
98
-	public function generate_from_date( $post_type ) {
98
+	public function generate_from_date($post_type) {
99 99
 
100 100
 		return aui()->input(
101 101
 			array(
102 102
 				'type'             => 'datepicker',
103
-				'id'               => esc_attr( "$post_type-from_date" ),
103
+				'id'               => esc_attr("$post_type-from_date"),
104 104
 				'name'             => 'from_date',
105
-				'label'            => __( 'From Date', 'invoicing' ),
105
+				'label'            => __('From Date', 'invoicing'),
106 106
 				'placeholder'      => 'YYYY-MM-DD',
107 107
 				'extra_attributes' => array(
108 108
 					'data-enable-time' => 'false',
@@ -118,14 +118,14 @@  discard block
 block discarded – undo
118 118
 	 * Generates the to date input field.
119 119
 	 *
120 120
 	 */
121
-	public function generate_to_date( $post_type ) {
121
+	public function generate_to_date($post_type) {
122 122
 
123 123
 		return aui()->input(
124 124
 			array(
125 125
 				'name'        => 'to_date',
126
-				'id'          => esc_attr( "$post_type-to_date" ),
126
+				'id'          => esc_attr("$post_type-to_date"),
127 127
 				'placeholder' => 'yy-mm-dd',
128
-				'label'       => __( 'To Date', 'invoicing' ),
128
+				'label'       => __('To Date', 'invoicing'),
129 129
 				'label_type'  => 'vertical',
130 130
 				'label_class' => 'd-block',
131 131
 				'type'        => 'datepicker',
@@ -138,20 +138,20 @@  discard block
 block discarded – undo
138 138
 	 * Generates the to post status select field.
139 139
 	 *
140 140
 	 */
141
-	public function generate_post_status_select( $post_type ) {
141
+	public function generate_post_status_select($post_type) {
142 142
 
143
-		if ( 'subscriptions' === $post_type ) {
143
+		if ('subscriptions' === $post_type) {
144 144
 			$options = getpaid_get_subscription_statuses();
145 145
 		} else {
146
-			$options = wpinv_get_invoice_statuses( true, false, $post_type );
146
+			$options = wpinv_get_invoice_statuses(true, false, $post_type);
147 147
 		}
148 148
 
149 149
 		return aui()->select(
150 150
 			array(
151 151
 				'name'        => 'status',
152
-				'id'          => esc_attr( "$post_type-status" ),
153
-				'placeholder' => __( 'All Statuses', 'invoicing' ),
154
-				'label'       => __( 'Status', 'invoicing' ),
152
+				'id'          => esc_attr("$post_type-status"),
153
+				'placeholder' => __('All Statuses', 'invoicing'),
154
+				'label'       => __('Status', 'invoicing'),
155 155
 				'label_type'  => 'vertical',
156 156
 				'label_class' => 'd-block',
157 157
 				'options'     => $options,
@@ -164,20 +164,20 @@  discard block
 block discarded – undo
164 164
 	 * Generates the to file type select field.
165 165
 	 *
166 166
 	 */
167
-	public function generate_file_type_select( $post_type ) {
167
+	public function generate_file_type_select($post_type) {
168 168
 
169 169
 		return aui()->select(
170 170
 			array(
171 171
 				'name'        => 'file_type',
172
-				'id'          => esc_attr( "$post_type-file_type" ),
173
-				'placeholder' => __( 'Select File Type', 'invoicing' ),
174
-				'label'       => __( 'Export File', 'invoicing' ),
172
+				'id'          => esc_attr("$post_type-file_type"),
173
+				'placeholder' => __('Select File Type', 'invoicing'),
174
+				'label'       => __('Export File', 'invoicing'),
175 175
 				'label_type'  => 'vertical',
176 176
 				'label_class' => 'd-block',
177 177
 				'options'     => array(
178
-					'csv'  => __( 'CSV', 'invoicing' ),
179
-					'xml'  => __( 'XML', 'invoicing' ),
180
-					'json' => __( 'JSON', 'invoicing' ),
178
+					'csv'  => __('CSV', 'invoicing'),
179
+					'xml'  => __('XML', 'invoicing'),
180
+					'json' => __('JSON', 'invoicing'),
181 181
 				),
182 182
 			)
183 183
 		);
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 	 * Displays a field's markup.
189 189
 	 *
190 190
 	 */
191
-	public function display_markup( $markup ) {
191
+	public function display_markup($markup) {
192 192
 
193 193
 		echo wp_kses(
194 194
 			str_replace(
@@ -217,20 +217,20 @@  discard block
 block discarded – undo
217 217
 
218 218
 				<div class="card-header">
219 219
 					<strong>
220
-						<?php esc_html_e( 'Export Subscriptions', 'invoicing' ); ?>
220
+						<?php esc_html_e('Export Subscriptions', 'invoicing'); ?>
221 221
 					</strong>
222 222
 				</div>
223 223
 
224 224
 				<div class="card-body">
225 225
 
226
-					<form method="post" action="<?php echo esc_url( $this->get_download_url( 'subscriptions' ) ); ?>">
226
+					<form method="post" action="<?php echo esc_url($this->get_download_url('subscriptions')); ?>">
227 227
 
228 228
 						<?php
229
-							$this->display_markup( $this->generate_from_date( 'subscriptions' ) );
230
-							$this->display_markup( $this->generate_to_date( 'subscriptions' ) );
231
-							$this->display_markup( $this->generate_post_status_select( 'subscriptions' ) );
232
-							$this->display_markup( $this->generate_file_type_select( 'subscriptions' ) );
233
-							submit_button( __( 'Download', 'invoicing' ) );
229
+							$this->display_markup($this->generate_from_date('subscriptions'));
230
+							$this->display_markup($this->generate_to_date('subscriptions'));
231
+							$this->display_markup($this->generate_post_status_select('subscriptions'));
232
+							$this->display_markup($this->generate_file_type_select('subscriptions'));
233
+							submit_button(__('Download', 'invoicing'));
234 234
 						?>
235 235
 
236 236
 					</form>
Please login to merge, or discard this patch.
includes/class-getpaid-notification-email-sender.php 2 patches
Indentation   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -13,17 +13,17 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Notification_Email_Sender {
14 14
 
15 15
     /**
16
-	 * Whether or not we should inline CSS into the email.
17
-	 */
18
-	public $inline_css = true;
16
+     * Whether or not we should inline CSS into the email.
17
+     */
18
+    public $inline_css = true;
19 19
 
20 20
     /**
21
-	 * The wp_mail() data.
22
-	 */
21
+     * The wp_mail() data.
22
+     */
23 23
     public $wp_mail_data = null;
24 24
 
25 25
     /**
26
-	 * Sends a new email.
26
+     * Sends a new email.
27 27
      *
28 28
      * @param string|array $to The recipients email or an array of recipient emails.
29 29
      * @param string $subject The email's subject.
@@ -31,49 +31,49 @@  discard block
 block discarded – undo
31 31
      * @param array $attachments The email attachments.
32 32
      *
33 33
      * @return bool
34
-	 */
35
-	public function send( $to, $subject, $email, $attachments = array() ) {
34
+     */
35
+    public function send( $to, $subject, $email, $attachments = array() ) {
36 36
 
37
-		/*
37
+        /*
38 38
 		 * Allow to filter data on per-email basis.
39 39
 		 */
40
-		$data = apply_filters(
41
-			'getpaid_email_data',
42
-			array(
43
-				'to'          => array_filter( array_unique( wpinv_parse_list( $to ) ) ),
44
-				'subject'     => htmlspecialchars_decode( wp_strip_all_tags( $subject ), ENT_QUOTES ),
45
-				'email'       => apply_filters( 'wpinv_mail_content', $email ),
46
-				'headers'     => $this->get_headers(),
47
-				'attachments' => $attachments,
48
-			),
49
-			$this
50
-		);
40
+        $data = apply_filters(
41
+            'getpaid_email_data',
42
+            array(
43
+                'to'          => array_filter( array_unique( wpinv_parse_list( $to ) ) ),
44
+                'subject'     => htmlspecialchars_decode( wp_strip_all_tags( $subject ), ENT_QUOTES ),
45
+                'email'       => apply_filters( 'wpinv_mail_content', $email ),
46
+                'headers'     => $this->get_headers(),
47
+                'attachments' => $attachments,
48
+            ),
49
+            $this
50
+        );
51 51
 
52 52
         // Remove slashes.
53 53
         $data               = (array) wp_unslash( $data );
54 54
 
55 55
         // Cache it.
56
-		$this->wp_mail_data = $data;
56
+        $this->wp_mail_data = $data;
57 57
 
58
-		// Attach our own hooks.
59
-		$this->before_sending();
58
+        // Attach our own hooks.
59
+        $this->before_sending();
60 60
 
61 61
         $result = false;
62 62
 
63 63
         foreach ( $this->wp_mail_data['to'] as $to ) {
64
-			$result = $this->_send( $to, $data );
64
+            $result = $this->_send( $to, $data );
65 65
         }
66 66
 
67
-		// Remove our hooks.
68
-		$this->after_sending();
67
+        // Remove our hooks.
68
+        $this->after_sending();
69 69
 
70
-		$this->wp_mail_data = null;
70
+        $this->wp_mail_data = null;
71 71
 
72
-		return $result;
73
-	}
72
+        return $result;
73
+    }
74 74
 
75
-	/**
76
-	 * Does the actual sending.
75
+    /**
76
+     * Does the actual sending.
77 77
      *
78 78
      * @param string $to The recipient's email.
79 79
      * @param array $data The email's data.
@@ -81,81 +81,81 @@  discard block
 block discarded – undo
81 81
      * @param array $attachments The email attachments.
82 82
      *
83 83
      * @return bool
84
-	 */
85
-	protected function _send( $to, $data ) {
86
-
87
-		// Prepare the sending function.
88
-		$sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' );
89
-
90
-		// Send the actual email.
91
-		$result = call_user_func(
92
-			$sending_function,
93
-			$to,
94
-			html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ),
95
-			$data['email'],
96
-			$data['headers'],
97
-			$data['attachments']
98
-		);
99
-
100
-		if ( ! $result ) {
101
-			$log_message = wp_sprintf( __( "\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] );
102
-			wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ );
103
-		}
104
-
105
-		return $result;
106
-	}
84
+     */
85
+    protected function _send( $to, $data ) {
86
+
87
+        // Prepare the sending function.
88
+        $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' );
89
+
90
+        // Send the actual email.
91
+        $result = call_user_func(
92
+            $sending_function,
93
+            $to,
94
+            html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ),
95
+            $data['email'],
96
+            $data['headers'],
97
+            $data['attachments']
98
+        );
99
+
100
+        if ( ! $result ) {
101
+            $log_message = wp_sprintf( __( "\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] );
102
+            wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ );
103
+        }
104
+
105
+        return $result;
106
+    }
107 107
 
108 108
     /**
109
-	 * Retrieves email headers.
110
-	 */
111
-	public function get_headers() {
109
+     * Retrieves email headers.
110
+     */
111
+    public function get_headers() {
112 112
 
113
-		$name       = $this->get_from_name();
114
-		$reply_to   = $this->get_reply_to();
115
-		$headers    = array( "Reply-To:$name <$reply_to>" );
113
+        $name       = $this->get_from_name();
114
+        $reply_to   = $this->get_reply_to();
115
+        $headers    = array( "Reply-To:$name <$reply_to>" );
116 116
 
117
-		return apply_filters( 'getpaid_email_headers', $headers, $this );
117
+        return apply_filters( 'getpaid_email_headers', $headers, $this );
118 118
 
119
-	}
119
+    }
120 120
 
121 121
     /**
122
-	 * Fires before an email is sent
123
-	 *
124
-	 * @since 1.0.0
125
-	 */
126
-	public function before_sending() {
122
+     * Fires before an email is sent
123
+     *
124
+     * @since 1.0.0
125
+     */
126
+    public function before_sending() {
127 127
 
128 128
         do_action( 'getpaid_before_send_email', $this );
129
-		add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
130
-		add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
131
-		add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
132
-		add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
129
+        add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
130
+        add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
131
+        add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
132
+        add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
133 133
 
134
-	}
134
+    }
135 135
 
136 136
     /**
137
-	 * Returns the from name.
138
-	 */
139
-	public function get_from_name() {
137
+     * Returns the from name.
138
+     */
139
+    public function get_from_name() {
140 140
 
141 141
         $from_name = wpinv_get_option( 'email_from_name', get_bloginfo( 'name' ) );
142 142
 
143
-		if ( empty( $from_name ) ) {
144
-			$from_name = get_bloginfo( 'name' );
143
+        if ( empty( $from_name ) ) {
144
+            $from_name = get_bloginfo( 'name' );
145 145
         }
146 146
 
147
-		return wp_specialchars_decode( $from_name, ENT_QUOTES );
147
+        return wp_specialchars_decode( $from_name, ENT_QUOTES );
148 148
     }
149 149
 
150 150
     /**
151
-	 * Returns the from email.
152
-	 */
153
-	public function get_from_address() {
151
+     * Returns the from email.
152
+     */
153
+    public function get_from_address() {
154 154
 
155 155
         $from_address = wpinv_get_option( 'email_from', $this->default_from_address() );
156 156
 
157
-		if ( ! is_email( $from_address ) ) {
158
-			$from_address = $this->default_from_address();
157
+        if ( ! is_email( $from_address ) ) {
158
+            $from_address = $this->default_from_address();
159 159
         }
160 160
 
161 161
         return $from_address;
@@ -163,75 +163,75 @@  discard block
 block discarded – undo
163 163
     }
164 164
 
165 165
     /**
166
-	 * The default emails from address.
167
-	 *
168
-	 * Defaults to wordpress@$sitename
169
-	 * Some hosts will block outgoing mail from this address if it doesn't exist,
170
-	 * but there's no easy alternative. Defaulting to admin_email might appear to be
171
-	 * another option, but some hosts may refuse to relay mail from an unknown domain.
172
-	 *
173
-	 */
174
-	public function default_from_address() {
175
-
176
-		// Get the site domain and get rid of www.
177
-		$sitename = strtolower( $_SERVER['SERVER_NAME'] );
178
-		if ( substr( $sitename, 0, 4 ) == 'www.' ) {
179
-			$sitename = substr( $sitename, 4 );
180
-		}
181
-
182
-		$from_email = 'wordpress@' . $sitename;
183
-
184
-		return apply_filters( 'getpaid_default_from_address', $from_email );
166
+     * The default emails from address.
167
+     *
168
+     * Defaults to wordpress@$sitename
169
+     * Some hosts will block outgoing mail from this address if it doesn't exist,
170
+     * but there's no easy alternative. Defaulting to admin_email might appear to be
171
+     * another option, but some hosts may refuse to relay mail from an unknown domain.
172
+     *
173
+     */
174
+    public function default_from_address() {
175
+
176
+        // Get the site domain and get rid of www.
177
+        $sitename = strtolower( $_SERVER['SERVER_NAME'] );
178
+        if ( substr( $sitename, 0, 4 ) == 'www.' ) {
179
+            $sitename = substr( $sitename, 4 );
180
+        }
181
+
182
+        $from_email = 'wordpress@' . $sitename;
183
+
184
+        return apply_filters( 'getpaid_default_from_address', $from_email );
185 185
 
186 186
     }
187 187
 
188 188
     /**
189
-	 * Get the email reply-to.
190
-	 *
191
-	 *
192
-	 * @return string The email reply-to address.
193
-	 */
194
-	public function get_reply_to() {
189
+     * Get the email reply-to.
190
+     *
191
+     *
192
+     * @return string The email reply-to address.
193
+     */
194
+    public function get_reply_to() {
195 195
 
196
-		$reply_to = current( wpinv_parse_list( wpinv_get_admin_email() ) );
196
+        $reply_to = current( wpinv_parse_list( wpinv_get_admin_email() ) );
197 197
 
198
-		if ( ! is_email( $reply_to ) ) {
199
-			$reply_to = get_option( 'admin_email' );
200
-		}
198
+        if ( ! is_email( $reply_to ) ) {
199
+            $reply_to = get_option( 'admin_email' );
200
+        }
201 201
 
202
-		return $reply_to;
202
+        return $reply_to;
203 203
     }
204 204
 
205 205
     /**
206
-	 * Get the email content type.
207
-	 *
208
-	 */
209
-	public function get_content_type() {
210
-		return apply_filters( 'getpaid_email_content_type', 'text/html', $this );
206
+     * Get the email content type.
207
+     *
208
+     */
209
+    public function get_content_type() {
210
+        return apply_filters( 'getpaid_email_content_type', 'text/html', $this );
211 211
     }
212 212
 
213 213
     /**
214
-	 * Ensures that our email messages are not messed up by template plugins.
215
-	 *
216
-	 * @return array wp_mail_data.
217
-	 */
218
-	public function ensure_email_content( $args ) {
219
-		$args['message'] = $this->wp_mail_data['email'];
220
-		return $args;
214
+     * Ensures that our email messages are not messed up by template plugins.
215
+     *
216
+     * @return array wp_mail_data.
217
+     */
218
+    public function ensure_email_content( $args ) {
219
+        $args['message'] = $this->wp_mail_data['email'];
220
+        return $args;
221 221
     }
222 222
 
223 223
     /**
224
-	 * A little house keeping after an email is sent.
225
-	 *
226
- 	 */
227
-	public function after_sending() {
224
+     * A little house keeping after an email is sent.
225
+     *
226
+     */
227
+    public function after_sending() {
228 228
 
229 229
         do_action( 'getpaid_after_send_email', $this->wp_mail_data );
230
-		remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
231
-		remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
232
-		remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
233
-		remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
230
+        remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
231
+        remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
232
+        remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
233
+        remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
234 234
 
235
-	}
235
+    }
236 236
 
237 237
 }
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * This function is responsible for sending emails.
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
      *
33 33
      * @return bool
34 34
 	 */
35
-	public function send( $to, $subject, $email, $attachments = array() ) {
35
+	public function send($to, $subject, $email, $attachments = array()) {
36 36
 
37 37
 		/*
38 38
 		 * Allow to filter data on per-email basis.
@@ -40,9 +40,9 @@  discard block
 block discarded – undo
40 40
 		$data = apply_filters(
41 41
 			'getpaid_email_data',
42 42
 			array(
43
-				'to'          => array_filter( array_unique( wpinv_parse_list( $to ) ) ),
44
-				'subject'     => htmlspecialchars_decode( wp_strip_all_tags( $subject ), ENT_QUOTES ),
45
-				'email'       => apply_filters( 'wpinv_mail_content', $email ),
43
+				'to'          => array_filter(array_unique(wpinv_parse_list($to))),
44
+				'subject'     => htmlspecialchars_decode(wp_strip_all_tags($subject), ENT_QUOTES),
45
+				'email'       => apply_filters('wpinv_mail_content', $email),
46 46
 				'headers'     => $this->get_headers(),
47 47
 				'attachments' => $attachments,
48 48
 			),
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 		);
51 51
 
52 52
         // Remove slashes.
53
-        $data               = (array) wp_unslash( $data );
53
+        $data = (array) wp_unslash($data);
54 54
 
55 55
         // Cache it.
56 56
 		$this->wp_mail_data = $data;
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
 
61 61
         $result = false;
62 62
 
63
-        foreach ( $this->wp_mail_data['to'] as $to ) {
64
-			$result = $this->_send( $to, $data );
63
+        foreach ($this->wp_mail_data['to'] as $to) {
64
+			$result = $this->_send($to, $data);
65 65
         }
66 66
 
67 67
 		// Remove our hooks.
@@ -82,24 +82,24 @@  discard block
 block discarded – undo
82 82
      *
83 83
      * @return bool
84 84
 	 */
85
-	protected function _send( $to, $data ) {
85
+	protected function _send($to, $data) {
86 86
 
87 87
 		// Prepare the sending function.
88
-		$sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' );
88
+		$sending_function = apply_filters('getpaid_email_email_sending_function', 'wp_mail');
89 89
 
90 90
 		// Send the actual email.
91 91
 		$result = call_user_func(
92 92
 			$sending_function,
93 93
 			$to,
94
-			html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ),
94
+			html_entity_decode($data['subject'], ENT_QUOTES, get_bloginfo('charset')),
95 95
 			$data['email'],
96 96
 			$data['headers'],
97 97
 			$data['attachments']
98 98
 		);
99 99
 
100
-		if ( ! $result ) {
101
-			$log_message = wp_sprintf( __( "\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] );
102
-			wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ );
100
+		if (!$result) {
101
+			$log_message = wp_sprintf(__("\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing'), date_i18n('F j Y H:i:s', current_time('timestamp')), $to, $data['subject']);
102
+			wpinv_error_log($log_message, __('Email from Invoicing plugin failed to send', 'invoicing'), __FILE__, __LINE__);
103 103
 		}
104 104
 
105 105
 		return $result;
@@ -112,9 +112,9 @@  discard block
 block discarded – undo
112 112
 
113 113
 		$name       = $this->get_from_name();
114 114
 		$reply_to   = $this->get_reply_to();
115
-		$headers    = array( "Reply-To:$name <$reply_to>" );
115
+		$headers    = array("Reply-To:$name <$reply_to>");
116 116
 
117
-		return apply_filters( 'getpaid_email_headers', $headers, $this );
117
+		return apply_filters('getpaid_email_headers', $headers, $this);
118 118
 
119 119
 	}
120 120
 
@@ -125,11 +125,11 @@  discard block
 block discarded – undo
125 125
 	 */
126 126
 	public function before_sending() {
127 127
 
128
-        do_action( 'getpaid_before_send_email', $this );
129
-		add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
130
-		add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
131
-		add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
132
-		add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
128
+        do_action('getpaid_before_send_email', $this);
129
+		add_filter('wp_mail_from', array($this, 'get_from_address'), 1000);
130
+		add_filter('wp_mail_from_name', array($this, 'get_from_name'), 1000);
131
+		add_filter('wp_mail_content_type', array($this, 'get_content_type'), 1000);
132
+		add_filter('wp_mail', array($this, 'ensure_email_content'), 1000);
133 133
 
134 134
 	}
135 135
 
@@ -138,13 +138,13 @@  discard block
 block discarded – undo
138 138
 	 */
139 139
 	public function get_from_name() {
140 140
 
141
-        $from_name = wpinv_get_option( 'email_from_name', get_bloginfo( 'name' ) );
141
+        $from_name = wpinv_get_option('email_from_name', get_bloginfo('name'));
142 142
 
143
-		if ( empty( $from_name ) ) {
144
-			$from_name = get_bloginfo( 'name' );
143
+		if (empty($from_name)) {
144
+			$from_name = get_bloginfo('name');
145 145
         }
146 146
 
147
-		return wp_specialchars_decode( $from_name, ENT_QUOTES );
147
+		return wp_specialchars_decode($from_name, ENT_QUOTES);
148 148
     }
149 149
 
150 150
     /**
@@ -152,9 +152,9 @@  discard block
 block discarded – undo
152 152
 	 */
153 153
 	public function get_from_address() {
154 154
 
155
-        $from_address = wpinv_get_option( 'email_from', $this->default_from_address() );
155
+        $from_address = wpinv_get_option('email_from', $this->default_from_address());
156 156
 
157
-		if ( ! is_email( $from_address ) ) {
157
+		if (!is_email($from_address)) {
158 158
 			$from_address = $this->default_from_address();
159 159
         }
160 160
 
@@ -174,14 +174,14 @@  discard block
 block discarded – undo
174 174
 	public function default_from_address() {
175 175
 
176 176
 		// Get the site domain and get rid of www.
177
-		$sitename = strtolower( $_SERVER['SERVER_NAME'] );
178
-		if ( substr( $sitename, 0, 4 ) == 'www.' ) {
179
-			$sitename = substr( $sitename, 4 );
177
+		$sitename = strtolower($_SERVER['SERVER_NAME']);
178
+		if (substr($sitename, 0, 4) == 'www.') {
179
+			$sitename = substr($sitename, 4);
180 180
 		}
181 181
 
182 182
 		$from_email = 'wordpress@' . $sitename;
183 183
 
184
-		return apply_filters( 'getpaid_default_from_address', $from_email );
184
+		return apply_filters('getpaid_default_from_address', $from_email);
185 185
 
186 186
     }
187 187
 
@@ -193,10 +193,10 @@  discard block
 block discarded – undo
193 193
 	 */
194 194
 	public function get_reply_to() {
195 195
 
196
-		$reply_to = current( wpinv_parse_list( wpinv_get_admin_email() ) );
196
+		$reply_to = current(wpinv_parse_list(wpinv_get_admin_email()));
197 197
 
198
-		if ( ! is_email( $reply_to ) ) {
199
-			$reply_to = get_option( 'admin_email' );
198
+		if (!is_email($reply_to)) {
199
+			$reply_to = get_option('admin_email');
200 200
 		}
201 201
 
202 202
 		return $reply_to;
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 	 *
208 208
 	 */
209 209
 	public function get_content_type() {
210
-		return apply_filters( 'getpaid_email_content_type', 'text/html', $this );
210
+		return apply_filters('getpaid_email_content_type', 'text/html', $this);
211 211
     }
212 212
 
213 213
     /**
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 	 *
216 216
 	 * @return array wp_mail_data.
217 217
 	 */
218
-	public function ensure_email_content( $args ) {
218
+	public function ensure_email_content($args) {
219 219
 		$args['message'] = $this->wp_mail_data['email'];
220 220
 		return $args;
221 221
     }
@@ -226,11 +226,11 @@  discard block
 block discarded – undo
226 226
  	 */
227 227
 	public function after_sending() {
228 228
 
229
-        do_action( 'getpaid_after_send_email', $this->wp_mail_data );
230
-		remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
231
-		remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
232
-		remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
233
-		remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
229
+        do_action('getpaid_after_send_email', $this->wp_mail_data);
230
+		remove_filter('wp_mail_from', array($this, 'get_from_address'), 1000);
231
+		remove_filter('wp_mail_from_name', array($this, 'get_from_name'), 1000);
232
+		remove_filter('wp_mail_content_type', array($this, 'get_content_type'), 1000);
233
+		remove_filter('wp_mail', array($this, 'ensure_email_content'), 1000);
234 234
 
235 235
 	}
236 236
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-checkout.php 2 patches
Indentation   +303 added lines, -303 removed lines patch added patch discarded remove patch
@@ -12,184 +12,184 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Checkout {
14 14
 
15
-	/**
16
-	 * @var GetPaid_Payment_Form_Submission
17
-	 */
18
-	protected $payment_form_submission;
19
-
20
-	/**
21
-	 * Class constructor.
22
-	 *
23
-	 * @param GetPaid_Payment_Form_Submission $submission
24
-	 */
25
-	public function __construct( $submission ) {
26
-		$this->payment_form_submission = $submission;
27
-	}
28
-
29
-	/**
30
-	 * Processes the checkout.
31
-	 *
32
-	 */
33
-	public function process_checkout() {
34
-
35
-		// Validate the submission.
36
-		$this->validate_submission();
37
-
38
-		// Prepare the invoice.
39
-		$items      = $this->get_submission_items();
40
-		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared   = $this->prepare_submission_data_for_saving();
43
-
44
-		$this->prepare_billing_info( $invoice );
45
-
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
47
-
48
-		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
50
-		$invoice->recalculate_total();
15
+    /**
16
+     * @var GetPaid_Payment_Form_Submission
17
+     */
18
+    protected $payment_form_submission;
19
+
20
+    /**
21
+     * Class constructor.
22
+     *
23
+     * @param GetPaid_Payment_Form_Submission $submission
24
+     */
25
+    public function __construct( $submission ) {
26
+        $this->payment_form_submission = $submission;
27
+    }
28
+
29
+    /**
30
+     * Processes the checkout.
31
+     *
32
+     */
33
+    public function process_checkout() {
34
+
35
+        // Validate the submission.
36
+        $this->validate_submission();
37
+
38
+        // Prepare the invoice.
39
+        $items      = $this->get_submission_items();
40
+        $invoice    = $this->get_submission_invoice();
41
+        $invoice    = $this->process_submission_invoice( $invoice, $items );
42
+        $prepared   = $this->prepare_submission_data_for_saving();
43
+
44
+        $this->prepare_billing_info( $invoice );
45
+
46
+        $shipping   = $this->prepare_shipping_info( $invoice );
47
+
48
+        // Save the invoice.
49
+        $invoice->set_is_viewed( true );
50
+        $invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+        do_action( 'getpaid_checkout_invoice_updated', $invoice );
54 54
 
55
-		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
57
-	}
55
+        // Send to the gateway.
56
+        $this->post_process_submission( $invoice, $prepared, $shipping );
57
+    }
58 58
 
59
-	/**
60
-	 * Validates the submission.
61
-	 *
62
-	 */
63
-	protected function validate_submission() {
59
+    /**
60
+     * Validates the submission.
61
+     *
62
+     */
63
+    protected function validate_submission() {
64 64
 
65
-		$submission = $this->payment_form_submission;
66
-		$data       = $submission->get_data();
65
+        $submission = $this->payment_form_submission;
66
+        $data       = $submission->get_data();
67 67
 
68
-		// Do we have an error?
68
+        // Do we have an error?
69 69
         if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
70
+            wp_send_json_error( $submission->last_error );
71 71
         }
72 72
 
73
-		// We need a billing email.
73
+        // We need a billing email.
74 74
         if ( ! $submission->has_billing_email() ) {
75 75
             wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
76
-		}
76
+        }
77 77
 
78
-		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
-		}
78
+        // Non-recurring gateways should not be allowed to process recurring invoices.
79
+        if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
+            wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
+        }
82 82
 
83
-		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
86
-		}
83
+        // Ensure the gateway is active.
84
+        if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
+            wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
86
+        }
87 87
 
88
-		// Clear any existing errors.
89
-		wpinv_clear_errors();
88
+        // Clear any existing errors.
89
+        wpinv_clear_errors();
90 90
 
91
-		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
91
+        // Allow themes and plugins to hook to errors
92
+        do_action( 'getpaid_checkout_error_checks', $submission );
93 93
 
94
-		// Do we have any errors?
94
+        // Do we have any errors?
95 95
         if ( wpinv_get_errors() ) {
96 96
             wp_send_json_error( getpaid_get_errors_html() );
97
-		}
97
+        }
98 98
 
99
-	}
99
+    }
100 100
 
101
-	/**
102
-	 * Retrieves submission items.
103
-	 *
104
-	 * @return GetPaid_Form_Item[]
105
-	 */
106
-	protected function get_submission_items() {
101
+    /**
102
+     * Retrieves submission items.
103
+     *
104
+     * @return GetPaid_Form_Item[]
105
+     */
106
+    protected function get_submission_items() {
107 107
 
108
-		$items = $this->payment_form_submission->get_items();
108
+        $items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111 111
         if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112 112
             wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
113
-		}
114
-
115
-		return $items;
116
-	}
117
-
118
-	/**
119
-	 * Retrieves submission invoice.
120
-	 *
121
-	 * @return WPInv_Invoice
122
-	 */
123
-	protected function get_submission_invoice() {
124
-		$submission = $this->payment_form_submission;
125
-
126
-		if ( ! $submission->has_invoice() ) {
127
-			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
129
-			return $invoice;
130 113
         }
131 114
 
132
-		$invoice = $submission->get_invoice();
115
+        return $items;
116
+    }
133 117
 
134
-		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
-		}
118
+    /**
119
+     * Retrieves submission invoice.
120
+     *
121
+     * @return WPInv_Invoice
122
+     */
123
+    protected function get_submission_invoice() {
124
+        $submission = $this->payment_form_submission;
138 125
 
139
-		return $invoice;
140
-	}
126
+        if ( ! $submission->has_invoice() ) {
127
+            $invoice = new WPInv_Invoice();
128
+            $invoice->set_created_via( 'payment_form' );
129
+            return $invoice;
130
+        }
141 131
 
142
-	/**
143
-	 * Processes the submission invoice.
144
-	 *
145
-	 * @param WPInv_Invoice $invoice
146
-	 * @param GetPaid_Form_Item[] $items
147
-	 * @return WPInv_Invoice
148
-	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
132
+        $invoice = $submission->get_invoice();
150 133
 
151
-		$submission = $this->payment_form_submission;
134
+        // Make sure that it is neither paid or refunded.
135
+        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
+            wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
+        }
152 138
 
153
-		// Set-up the invoice details.
154
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
-		$invoice->set_user_id( $this->get_submission_customer() );
156
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
139
+        return $invoice;
140
+    }
141
+
142
+    /**
143
+     * Processes the submission invoice.
144
+     *
145
+     * @param WPInv_Invoice $invoice
146
+     * @param GetPaid_Form_Item[] $items
147
+     * @return WPInv_Invoice
148
+     */
149
+    protected function process_submission_invoice( $invoice, $items ) {
150
+
151
+        $submission = $this->payment_form_submission;
152
+
153
+        // Set-up the invoice details.
154
+        $invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
+        $invoice->set_user_id( $this->get_submission_customer() );
156
+        $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
157 157
         $invoice->set_items( $items );
158 158
         $invoice->set_fees( $submission->get_fees() );
159 159
         $invoice->set_taxes( $submission->get_taxes() );
160
-		$invoice->set_discounts( $submission->get_discounts() );
161
-		$invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
162
-		$invoice->set_currency( $submission->get_currency() );
160
+        $invoice->set_discounts( $submission->get_discounts() );
161
+        $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
162
+        $invoice->set_currency( $submission->get_currency() );
163 163
 
164
-		if ( $submission->has_shipping() ) {
165
-			$invoice->set_shipping( $submission->get_shipping() );
166
-		}
164
+        if ( $submission->has_shipping() ) {
165
+            $invoice->set_shipping( $submission->get_shipping() );
166
+        }
167 167
 
168
-		$address_confirmed = $submission->get_field( 'confirm-address' );
169
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
168
+        $address_confirmed = $submission->get_field( 'confirm-address' );
169
+        $invoice->set_address_confirmed( ! empty( $address_confirmed ) );
170 170
 
171
-		if ( $submission->has_discount_code() ) {
171
+        if ( $submission->has_discount_code() ) {
172 172
             $invoice->set_discount_code( $submission->get_discount_code() );
173
-		}
174
-
175
-		getpaid_maybe_add_default_address( $invoice );
176
-		return $invoice;
177
-	}
178
-
179
-	/**
180
-	 * Retrieves the submission's customer.
181
-	 *
182
-	 * @return int The customer id.
183
-	 */
184
-	protected function get_submission_customer() {
185
-		$submission = $this->payment_form_submission;
186
-
187
-		// If this is an existing invoice...
188
-		if ( $submission->has_invoice() ) {
189
-			return $submission->get_invoice()->get_user_id();
190
-		}
191
-
192
-		// (Maybe) create the user.
173
+        }
174
+
175
+        getpaid_maybe_add_default_address( $invoice );
176
+        return $invoice;
177
+    }
178
+
179
+    /**
180
+     * Retrieves the submission's customer.
181
+     *
182
+     * @return int The customer id.
183
+     */
184
+    protected function get_submission_customer() {
185
+        $submission = $this->payment_form_submission;
186
+
187
+        // If this is an existing invoice...
188
+        if ( $submission->has_invoice() ) {
189
+            return $submission->get_invoice()->get_user_id();
190
+        }
191
+
192
+        // (Maybe) create the user.
193 193
         $user = get_current_user_id();
194 194
 
195 195
         if ( empty( $user ) ) {
@@ -197,16 +197,16 @@  discard block
 block discarded – undo
197 197
         }
198 198
 
199 199
         if ( empty( $user ) ) {
200
-			$name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) );
201
-			$name = implode( '', array_filter( $name ) );
200
+            $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) );
201
+            $name = implode( '', array_filter( $name ) );
202 202
             $user = wpinv_create_user( $submission->get_billing_email(), $name );
203 203
 
204
-			// (Maybe) send new user notification.
205
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
206
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
207
-				wp_send_new_user_notifications( $user, 'user' );
208
-			}
209
-		}
204
+            // (Maybe) send new user notification.
205
+            $should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
206
+            if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
207
+                wp_send_new_user_notifications( $user, 'user' );
208
+            }
209
+        }
210 210
 
211 211
         if ( is_wp_error( $user ) ) {
212 212
             wp_send_json_error( $user->get_error_message() );
@@ -214,49 +214,49 @@  discard block
 block discarded – undo
214 214
 
215 215
         if ( is_numeric( $user ) ) {
216 216
             return $user;
217
-		}
217
+        }
218 218
 
219
-		return $user->ID;
219
+        return $user->ID;
220 220
 
221
-	}
221
+    }
222 222
 
223
-	/**
223
+    /**
224 224
      * Prepares submission data for saving to the database.
225 225
      *
226
-	 * @return array
226
+     * @return array
227 227
      */
228 228
     public function prepare_submission_data_for_saving() {
229 229
 
230
-		$submission = $this->payment_form_submission;
230
+        $submission = $this->payment_form_submission;
231 231
 
232
-		// Prepared submission details.
232
+        // Prepared submission details.
233 233
         $prepared = array(
234
-			'all'  => array(),
235
-			'meta' => array(),
236
-		);
234
+            'all'  => array(),
235
+            'meta' => array(),
236
+        );
237 237
 
238 238
         // Raw submission details.
239
-		$data     = $submission->get_data();
239
+        $data     = $submission->get_data();
240 240
 
241
-		// Loop through the submitted details.
241
+        // Loop through the submitted details.
242 242
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
243 243
 
244
-			// Skip premade fields.
244
+            // Skip premade fields.
245 245
             if ( ! empty( $field['premade'] ) ) {
246 246
                 continue;
247 247
             }
248 248
 
249
-			// Ensure address is provided.
250
-			if ( $field['type'] == 'address' ) {
249
+            // Ensure address is provided.
250
+            if ( $field['type'] == 'address' ) {
251 251
                 $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
252 252
 
253
-				foreach ( $field['fields'] as $address_field ) {
253
+                foreach ( $field['fields'] as $address_field ) {
254 254
 
255
-					if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) {
256
-						wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
257
-					}
258
-			}
259
-		}
255
+                    if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) {
256
+                        wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
257
+                    }
258
+            }
259
+        }
260 260
 
261 261
             // If it is required and not set, abort.
262 262
             if ( ! $submission->is_required_field_set( $field ) ) {
@@ -266,31 +266,31 @@  discard block
 block discarded – undo
266 266
             // Handle misc fields.
267 267
             if ( isset( $data[ $field['id'] ] ) ) {
268 268
 
269
-				// Uploads.
270
-				if ( $field['type'] == 'file_upload' ) {
271
-					$max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
269
+                // Uploads.
270
+                if ( $field['type'] == 'file_upload' ) {
271
+                    $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
272 272
 
273
-					if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
274
-						wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
275
-					}
273
+                    if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
274
+                        wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
275
+                    }
276 276
 
277
-					$value = array();
277
+                    $value = array();
278 278
 
279
-					foreach ( $data[ $field['id'] ] as $url => $name ) {
280
-						$value[] = sprintf(
281
-							'<a href="%s" target="_blank">%s</a>',
282
-							esc_url_raw( $url ),
283
-							esc_html( $name )
284
-						);
285
-					}
279
+                    foreach ( $data[ $field['id'] ] as $url => $name ) {
280
+                        $value[] = sprintf(
281
+                            '<a href="%s" target="_blank">%s</a>',
282
+                            esc_url_raw( $url ),
283
+                            esc_html( $name )
284
+                        );
285
+                    }
286 286
 
287
-					$value = implode( ' | ', $value );
287
+                    $value = implode( ' | ', $value );
288 288
 
289
-				} elseif ( $field['type'] == 'checkbox' ) {
290
-					$value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
291
-				} else {
292
-					$value = wp_kses_post( $data[ $field['id'] ] );
293
-				}
289
+                } elseif ( $field['type'] == 'checkbox' ) {
290
+                    $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
291
+                } else {
292
+                    $value = wp_kses_post( $data[ $field['id'] ] );
293
+                }
294 294
 
295 295
                 $label = $field['id'];
296 296
 
@@ -298,188 +298,188 @@  discard block
 block discarded – undo
298 298
                     $label = $field['label'];
299 299
                 }
300 300
 
301
-				if ( ! empty( $field['add_meta'] ) ) {
302
-					$prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
303
-				}
304
-				$prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
301
+                if ( ! empty( $field['add_meta'] ) ) {
302
+                    $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
303
+                }
304
+                $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
305 305
 
306 306
             }
307 307
 }
308 308
 
309
-		return $prepared;
309
+        return $prepared;
310 310
 
311
-	}
311
+    }
312 312
 
313
-	/**
313
+    /**
314 314
      * Retrieves address details.
315 315
      *
316
-	 * @return array
317
-	 * @param WPInv_Invoice $invoice
318
-	 * @param string $type
316
+     * @return array
317
+     * @param WPInv_Invoice $invoice
318
+     * @param string $type
319 319
      */
320 320
     public function prepare_address_details( $invoice, $type = 'billing' ) {
321 321
 
322
-		$data     = $this->payment_form_submission->get_data();
323
-		$type     = sanitize_key( $type );
324
-		$address  = array();
325
-		$prepared = array();
322
+        $data     = $this->payment_form_submission->get_data();
323
+        $type     = sanitize_key( $type );
324
+        $address  = array();
325
+        $prepared = array();
326 326
 
327
-		if ( ! empty( $data[ $type ] ) ) {
328
-			$address = $data[ $type ];
329
-		}
327
+        if ( ! empty( $data[ $type ] ) ) {
328
+            $address = $data[ $type ];
329
+        }
330 330
 
331
-		// Clean address details.
332
-		foreach ( $address as $key => $value ) {
333
-			$key             = sanitize_key( $key );
334
-			$key             = str_replace( 'wpinv_', '', $key );
335
-			$value           = wpinv_clean( $value );
336
-			$prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
337
-		}
331
+        // Clean address details.
332
+        foreach ( $address as $key => $value ) {
333
+            $key             = sanitize_key( $key );
334
+            $key             = str_replace( 'wpinv_', '', $key );
335
+            $value           = wpinv_clean( $value );
336
+            $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
337
+        }
338 338
 
339
-		// Filter address details.
340
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
339
+        // Filter address details.
340
+        $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
341 341
 
342
-		// Remove non-whitelisted values.
343
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
342
+        // Remove non-whitelisted values.
343
+        return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
344 344
 
345
-	}
345
+    }
346 346
 
347
-	/**
347
+    /**
348 348
      * Prepares the billing details.
349 349
      *
350
-	 * @return array
351
-	 * @param WPInv_Invoice $invoice
350
+     * @return array
351
+     * @param WPInv_Invoice $invoice
352 352
      */
353 353
     protected function prepare_billing_info( &$invoice ) {
354 354
 
355
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
355
+        $billing_address = $this->prepare_address_details( $invoice, 'billing' );
356 356
 
357
-		// Update the invoice with the billing details.
358
-		$invoice->set_props( $billing_address );
357
+        // Update the invoice with the billing details.
358
+        $invoice->set_props( $billing_address );
359 359
 
360
-	}
360
+    }
361 361
 
362
-	/**
362
+    /**
363 363
      * Prepares the shipping details.
364 364
      *
365
-	 * @return array
366
-	 * @param WPInv_Invoice $invoice
365
+     * @return array
366
+     * @param WPInv_Invoice $invoice
367 367
      */
368 368
     protected function prepare_shipping_info( $invoice ) {
369 369
 
370
-		$data = $this->payment_form_submission->get_data();
370
+        $data = $this->payment_form_submission->get_data();
371 371
 
372
-		if ( empty( $data['same-shipping-address'] ) ) {
373
-			return $this->prepare_address_details( $invoice, 'shipping' );
374
-		}
372
+        if ( empty( $data['same-shipping-address'] ) ) {
373
+            return $this->prepare_address_details( $invoice, 'shipping' );
374
+        }
375 375
 
376
-		return $this->prepare_address_details( $invoice, 'billing' );
376
+        return $this->prepare_address_details( $invoice, 'billing' );
377 377
 
378
-	}
378
+    }
379 379
 
380
-	/**
381
-	 * Confirms the submission is valid and send users to the gateway.
382
-	 *
383
-	 * @param WPInv_Invoice $invoice
384
-	 * @param array $prepared_payment_form_data
385
-	 * @param array $shipping
386
-	 */
387
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
380
+    /**
381
+     * Confirms the submission is valid and send users to the gateway.
382
+     *
383
+     * @param WPInv_Invoice $invoice
384
+     * @param array $prepared_payment_form_data
385
+     * @param array $shipping
386
+     */
387
+    protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
388 388
 
389
-		// Ensure the invoice exists.
389
+        // Ensure the invoice exists.
390 390
         if ( ! $invoice->exists() ) {
391 391
             wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
392 392
         }
393 393
 
394
-		// Save payment form data.
395
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
394
+        // Save payment form data.
395
+        $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
396 396
         delete_post_meta( $invoice->get_id(), 'payment_form_data' );
397
-		delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
398
-		if ( ! empty( $prepared_payment_form_data ) ) {
397
+        delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
398
+        if ( ! empty( $prepared_payment_form_data ) ) {
399 399
 
400
-			if ( ! empty( $prepared_payment_form_data['all'] ) ) {
401
-				update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
402
-			}
400
+            if ( ! empty( $prepared_payment_form_data['all'] ) ) {
401
+                update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
402
+            }
403 403
 
404
-			if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
405
-				update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
406
-			}
404
+            if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
405
+                update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
406
+            }
407 407
 }
408 408
 
409
-		// Save payment form data.
410
-		$shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
409
+        // Save payment form data.
410
+        $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
411 411
         if ( ! empty( $shipping ) ) {
412 412
             update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
413
-		}
413
+        }
414 414
 
415
-		// Backwards compatibility.
415
+        // Backwards compatibility.
416 416
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
417 417
 
418
-		$this->process_payment( $invoice );
418
+        $this->process_payment( $invoice );
419 419
 
420 420
         // If we are here, there was an error.
421
-		wpinv_send_back_to_checkout( $invoice );
421
+        wpinv_send_back_to_checkout( $invoice );
422 422
 
423
-	}
423
+    }
424 424
 
425
-	/**
426
-	 * Processes the actual payment.
427
-	 *
428
-	 * @param WPInv_Invoice $invoice
429
-	 */
430
-	protected function process_payment( $invoice ) {
425
+    /**
426
+     * Processes the actual payment.
427
+     *
428
+     * @param WPInv_Invoice $invoice
429
+     */
430
+    protected function process_payment( $invoice ) {
431 431
 
432
-		// Clear any checkout errors.
433
-		wpinv_clear_errors();
432
+        // Clear any checkout errors.
433
+        wpinv_clear_errors();
434 434
 
435
-		// No need to send free invoices to the gateway.
436
-		if ( $invoice->is_free() ) {
437
-			$this->process_free_payment( $invoice );
438
-		}
435
+        // No need to send free invoices to the gateway.
436
+        if ( $invoice->is_free() ) {
437
+            $this->process_free_payment( $invoice );
438
+        }
439 439
 
440
-		$submission = $this->payment_form_submission;
440
+        $submission = $this->payment_form_submission;
441 441
 
442
-		// Fires before sending to the gateway.
443
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
442
+        // Fires before sending to the gateway.
443
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
444 444
 
445
-		// Allow the sumission data to be modified before it is sent to the gateway.
446
-		$submission_data    = $submission->get_data();
447
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
448
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
445
+        // Allow the sumission data to be modified before it is sent to the gateway.
446
+        $submission_data    = $submission->get_data();
447
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
448
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
449 449
 
450
-		// Validate the currency.
451
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
452
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
453
-		}
450
+        // Validate the currency.
451
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
452
+            wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
453
+        }
454 454
 
455
-		// Check to see if we have any errors.
456
-		if ( wpinv_get_errors() ) {
457
-			wpinv_send_back_to_checkout( $invoice );
458
-		}
455
+        // Check to see if we have any errors.
456
+        if ( wpinv_get_errors() ) {
457
+            wpinv_send_back_to_checkout( $invoice );
458
+        }
459 459
 
460
-		// Send info to the gateway for payment processing
461
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
460
+        // Send info to the gateway for payment processing
461
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
462 462
 
463
-		// Backwards compatibility.
464
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
463
+        // Backwards compatibility.
464
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
465 465
 
466
-	}
466
+    }
467 467
 
468
-	/**
469
-	 * Marks the invoice as paid in case the checkout is free.
470
-	 *
471
-	 * @param WPInv_Invoice $invoice
472
-	 */
473
-	protected function process_free_payment( $invoice ) {
468
+    /**
469
+     * Marks the invoice as paid in case the checkout is free.
470
+     *
471
+     * @param WPInv_Invoice $invoice
472
+     */
473
+    protected function process_free_payment( $invoice ) {
474 474
 
475
-		$invoice->set_gateway( 'none' );
476
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
477
-		$invoice->mark_paid();
478
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
475
+        $invoice->set_gateway( 'none' );
476
+        $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
477
+        $invoice->mark_paid();
478
+        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
479 479
 
480
-	}
480
+    }
481 481
 
482
-	/**
482
+    /**
483 483
      * Sends a redrect response to payment details.
484 484
      *
485 485
      */
Please login to merge, or discard this patch.
Spacing   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Main Checkout Class.
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 *
23 23
 	 * @param GetPaid_Payment_Form_Submission $submission
24 24
 	 */
25
-	public function __construct( $submission ) {
25
+	public function __construct($submission) {
26 26
 		$this->payment_form_submission = $submission;
27 27
 	}
28 28
 
@@ -38,22 +38,22 @@  discard block
 block discarded – undo
38 38
 		// Prepare the invoice.
39 39
 		$items      = $this->get_submission_items();
40 40
 		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
41
+		$invoice    = $this->process_submission_invoice($invoice, $items);
42 42
 		$prepared   = $this->prepare_submission_data_for_saving();
43 43
 
44
-		$this->prepare_billing_info( $invoice );
44
+		$this->prepare_billing_info($invoice);
45 45
 
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
46
+		$shipping = $this->prepare_shipping_info($invoice);
47 47
 
48 48
 		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
49
+		$invoice->set_is_viewed(true);
50 50
 		$invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+		do_action('getpaid_checkout_invoice_updated', $invoice);
54 54
 
55 55
 		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
56
+		$this->post_process_submission($invoice, $prepared, $shipping);
57 57
 	}
58 58
 
59 59
 	/**
@@ -66,34 +66,34 @@  discard block
 block discarded – undo
66 66
 		$data       = $submission->get_data();
67 67
 
68 68
 		// Do we have an error?
69
-        if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
69
+        if (!empty($submission->last_error)) {
70
+			wp_send_json_error($submission->last_error);
71 71
         }
72 72
 
73 73
 		// We need a billing email.
74
-        if ( ! $submission->has_billing_email() ) {
75
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
74
+        if (!$submission->has_billing_email()) {
75
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
76 76
 		}
77 77
 
78 78
 		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
79
+		if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) {
80
+			wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing'));
81 81
 		}
82 82
 
83 83
 		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
84
+		if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) {
85
+			wp_send_json_error(__('The selected payment gateway is not active', 'invoicing'));
86 86
 		}
87 87
 
88 88
 		// Clear any existing errors.
89 89
 		wpinv_clear_errors();
90 90
 
91 91
 		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
92
+		do_action('getpaid_checkout_error_checks', $submission);
93 93
 
94 94
 		// Do we have any errors?
95
-        if ( wpinv_get_errors() ) {
96
-            wp_send_json_error( getpaid_get_errors_html() );
95
+        if (wpinv_get_errors()) {
96
+            wp_send_json_error(getpaid_get_errors_html());
97 97
 		}
98 98
 
99 99
 	}
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 		$items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111
-        if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112
-            wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
111
+        if (empty($items) && !$this->payment_form_submission->has_fees()) {
112
+            wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing'));
113 113
 		}
114 114
 
115 115
 		return $items;
@@ -123,17 +123,17 @@  discard block
 block discarded – undo
123 123
 	protected function get_submission_invoice() {
124 124
 		$submission = $this->payment_form_submission;
125 125
 
126
-		if ( ! $submission->has_invoice() ) {
126
+		if (!$submission->has_invoice()) {
127 127
 			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
128
+			$invoice->set_created_via('payment_form');
129 129
 			return $invoice;
130 130
         }
131 131
 
132 132
 		$invoice = $submission->get_invoice();
133 133
 
134 134
 		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
135
+		if ($invoice->is_paid() || $invoice->is_refunded()) {
136
+			wp_send_json_error(__('This invoice has already been paid for.', 'invoicing'));
137 137
 		}
138 138
 
139 139
 		return $invoice;
@@ -146,33 +146,33 @@  discard block
 block discarded – undo
146 146
 	 * @param GetPaid_Form_Item[] $items
147 147
 	 * @return WPInv_Invoice
148 148
 	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
149
+	protected function process_submission_invoice($invoice, $items) {
150 150
 
151 151
 		$submission = $this->payment_form_submission;
152 152
 
153 153
 		// Set-up the invoice details.
154
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
-		$invoice->set_user_id( $this->get_submission_customer() );
156
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
157
-        $invoice->set_items( $items );
158
-        $invoice->set_fees( $submission->get_fees() );
159
-        $invoice->set_taxes( $submission->get_taxes() );
160
-		$invoice->set_discounts( $submission->get_discounts() );
161
-		$invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
162
-		$invoice->set_currency( $submission->get_currency() );
163
-
164
-		if ( $submission->has_shipping() ) {
165
-			$invoice->set_shipping( $submission->get_shipping() );
154
+		$invoice->set_email(sanitize_email($submission->get_billing_email()));
155
+		$invoice->set_user_id($this->get_submission_customer());
156
+		$invoice->set_payment_form(absint($submission->get_payment_form()->get_id()));
157
+        $invoice->set_items($items);
158
+        $invoice->set_fees($submission->get_fees());
159
+        $invoice->set_taxes($submission->get_taxes());
160
+		$invoice->set_discounts($submission->get_discounts());
161
+		$invoice->set_gateway($submission->get_field('wpi-gateway'));
162
+		$invoice->set_currency($submission->get_currency());
163
+
164
+		if ($submission->has_shipping()) {
165
+			$invoice->set_shipping($submission->get_shipping());
166 166
 		}
167 167
 
168
-		$address_confirmed = $submission->get_field( 'confirm-address' );
169
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
168
+		$address_confirmed = $submission->get_field('confirm-address');
169
+		$invoice->set_address_confirmed(!empty($address_confirmed));
170 170
 
171
-		if ( $submission->has_discount_code() ) {
172
-            $invoice->set_discount_code( $submission->get_discount_code() );
171
+		if ($submission->has_discount_code()) {
172
+            $invoice->set_discount_code($submission->get_discount_code());
173 173
 		}
174 174
 
175
-		getpaid_maybe_add_default_address( $invoice );
175
+		getpaid_maybe_add_default_address($invoice);
176 176
 		return $invoice;
177 177
 	}
178 178
 
@@ -185,34 +185,34 @@  discard block
 block discarded – undo
185 185
 		$submission = $this->payment_form_submission;
186 186
 
187 187
 		// If this is an existing invoice...
188
-		if ( $submission->has_invoice() ) {
188
+		if ($submission->has_invoice()) {
189 189
 			return $submission->get_invoice()->get_user_id();
190 190
 		}
191 191
 
192 192
 		// (Maybe) create the user.
193 193
         $user = get_current_user_id();
194 194
 
195
-        if ( empty( $user ) ) {
196
-            $user = get_user_by( 'email', $submission->get_billing_email() );
195
+        if (empty($user)) {
196
+            $user = get_user_by('email', $submission->get_billing_email());
197 197
         }
198 198
 
199
-        if ( empty( $user ) ) {
200
-			$name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) );
201
-			$name = implode( '', array_filter( $name ) );
202
-            $user = wpinv_create_user( $submission->get_billing_email(), $name );
199
+        if (empty($user)) {
200
+			$name = array($submission->get_field('wpinv_first_name', 'billing'), $submission->get_field('wpinv_last_name', 'billing'));
201
+			$name = implode('', array_filter($name));
202
+            $user = wpinv_create_user($submission->get_billing_email(), $name);
203 203
 
204 204
 			// (Maybe) send new user notification.
205
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
206
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
207
-				wp_send_new_user_notifications( $user, 'user' );
205
+			$should_send_notification = wpinv_get_option('disable_new_user_emails');
206
+			if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification), $user)) {
207
+				wp_send_new_user_notifications($user, 'user');
208 208
 			}
209 209
 		}
210 210
 
211
-        if ( is_wp_error( $user ) ) {
212
-            wp_send_json_error( $user->get_error_message() );
211
+        if (is_wp_error($user)) {
212
+            wp_send_json_error($user->get_error_message());
213 213
         }
214 214
 
215
-        if ( is_numeric( $user ) ) {
215
+        if (is_numeric($user)) {
216 216
             return $user;
217 217
 		}
218 218
 
@@ -236,72 +236,72 @@  discard block
 block discarded – undo
236 236
 		);
237 237
 
238 238
         // Raw submission details.
239
-		$data     = $submission->get_data();
239
+		$data = $submission->get_data();
240 240
 
241 241
 		// Loop through the submitted details.
242
-        foreach ( $submission->get_payment_form()->get_elements() as $field ) {
242
+        foreach ($submission->get_payment_form()->get_elements() as $field) {
243 243
 
244 244
 			// Skip premade fields.
245
-            if ( ! empty( $field['premade'] ) ) {
245
+            if (!empty($field['premade'])) {
246 246
                 continue;
247 247
             }
248 248
 
249 249
 			// Ensure address is provided.
250
-			if ( $field['type'] == 'address' ) {
251
-                $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
250
+			if ($field['type'] == 'address') {
251
+                $address_type = isset($field['address_type']) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
252 252
 
253
-				foreach ( $field['fields'] as $address_field ) {
253
+				foreach ($field['fields'] as $address_field) {
254 254
 
255
-					if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) {
256
-						wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
255
+					if (!empty($address_field['visible']) && !empty($address_field['required']) && '' === trim($_POST[$address_type][$address_field['name']])) {
256
+						wp_send_json_error(__('Please fill all required fields.', 'invoicing'));
257 257
 					}
258 258
 			}
259 259
 		}
260 260
 
261 261
             // If it is required and not set, abort.
262
-            if ( ! $submission->is_required_field_set( $field ) ) {
263
-                wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
262
+            if (!$submission->is_required_field_set($field)) {
263
+                wp_send_json_error(__('Please fill all required fields.', 'invoicing'));
264 264
             }
265 265
 
266 266
             // Handle misc fields.
267
-            if ( isset( $data[ $field['id'] ] ) ) {
267
+            if (isset($data[$field['id']])) {
268 268
 
269 269
 				// Uploads.
270
-				if ( $field['type'] == 'file_upload' ) {
271
-					$max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
270
+				if ($field['type'] == 'file_upload') {
271
+					$max_file_num = empty($field['max_file_num']) ? 1 : absint($field['max_file_num']);
272 272
 
273
-					if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
274
-						wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
273
+					if (count($data[$field['id']]) > $max_file_num) {
274
+						wp_send_json_error(__('Maximum number of allowed files exceeded.', 'invoicing'));
275 275
 					}
276 276
 
277 277
 					$value = array();
278 278
 
279
-					foreach ( $data[ $field['id'] ] as $url => $name ) {
279
+					foreach ($data[$field['id']] as $url => $name) {
280 280
 						$value[] = sprintf(
281 281
 							'<a href="%s" target="_blank">%s</a>',
282
-							esc_url_raw( $url ),
283
-							esc_html( $name )
282
+							esc_url_raw($url),
283
+							esc_html($name)
284 284
 						);
285 285
 					}
286 286
 
287
-					$value = implode( ' | ', $value );
287
+					$value = implode(' | ', $value);
288 288
 
289
-				} elseif ( $field['type'] == 'checkbox' ) {
290
-					$value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
289
+				} elseif ($field['type'] == 'checkbox') {
290
+					$value = isset($data[$field['id']]) ? __('Yes', 'invoicing') : __('No', 'invoicing');
291 291
 				} else {
292
-					$value = wp_kses_post( $data[ $field['id'] ] );
292
+					$value = wp_kses_post($data[$field['id']]);
293 293
 				}
294 294
 
295 295
                 $label = $field['id'];
296 296
 
297
-                if ( isset( $field['label'] ) ) {
297
+                if (isset($field['label'])) {
298 298
                     $label = $field['label'];
299 299
                 }
300 300
 
301
-				if ( ! empty( $field['add_meta'] ) ) {
302
-					$prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
301
+				if (!empty($field['add_meta'])) {
302
+					$prepared['meta'][wpinv_clean($label)] = wp_kses_post_deep($value);
303 303
 				}
304
-				$prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
304
+				$prepared['all'][wpinv_clean($label)] = wp_kses_post_deep($value);
305 305
 
306 306
             }
307 307
 }
@@ -317,30 +317,30 @@  discard block
 block discarded – undo
317 317
 	 * @param WPInv_Invoice $invoice
318 318
 	 * @param string $type
319 319
      */
320
-    public function prepare_address_details( $invoice, $type = 'billing' ) {
320
+    public function prepare_address_details($invoice, $type = 'billing') {
321 321
 
322 322
 		$data     = $this->payment_form_submission->get_data();
323
-		$type     = sanitize_key( $type );
323
+		$type     = sanitize_key($type);
324 324
 		$address  = array();
325 325
 		$prepared = array();
326 326
 
327
-		if ( ! empty( $data[ $type ] ) ) {
328
-			$address = $data[ $type ];
327
+		if (!empty($data[$type])) {
328
+			$address = $data[$type];
329 329
 		}
330 330
 
331 331
 		// Clean address details.
332
-		foreach ( $address as $key => $value ) {
333
-			$key             = sanitize_key( $key );
334
-			$key             = str_replace( 'wpinv_', '', $key );
335
-			$value           = wpinv_clean( $value );
336
-			$prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
332
+		foreach ($address as $key => $value) {
333
+			$key             = sanitize_key($key);
334
+			$key             = str_replace('wpinv_', '', $key);
335
+			$value           = wpinv_clean($value);
336
+			$prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice);
337 337
 		}
338 338
 
339 339
 		// Filter address details.
340
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
340
+		$prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice);
341 341
 
342 342
 		// Remove non-whitelisted values.
343
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
343
+		return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY);
344 344
 
345 345
 	}
346 346
 
@@ -350,12 +350,12 @@  discard block
 block discarded – undo
350 350
 	 * @return array
351 351
 	 * @param WPInv_Invoice $invoice
352 352
      */
353
-    protected function prepare_billing_info( &$invoice ) {
353
+    protected function prepare_billing_info(&$invoice) {
354 354
 
355
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
355
+		$billing_address = $this->prepare_address_details($invoice, 'billing');
356 356
 
357 357
 		// Update the invoice with the billing details.
358
-		$invoice->set_props( $billing_address );
358
+		$invoice->set_props($billing_address);
359 359
 
360 360
 	}
361 361
 
@@ -365,15 +365,15 @@  discard block
 block discarded – undo
365 365
 	 * @return array
366 366
 	 * @param WPInv_Invoice $invoice
367 367
      */
368
-    protected function prepare_shipping_info( $invoice ) {
368
+    protected function prepare_shipping_info($invoice) {
369 369
 
370 370
 		$data = $this->payment_form_submission->get_data();
371 371
 
372
-		if ( empty( $data['same-shipping-address'] ) ) {
373
-			return $this->prepare_address_details( $invoice, 'shipping' );
372
+		if (empty($data['same-shipping-address'])) {
373
+			return $this->prepare_address_details($invoice, 'shipping');
374 374
 		}
375 375
 
376
-		return $this->prepare_address_details( $invoice, 'billing' );
376
+		return $this->prepare_address_details($invoice, 'billing');
377 377
 
378 378
 	}
379 379
 
@@ -384,41 +384,41 @@  discard block
 block discarded – undo
384 384
 	 * @param array $prepared_payment_form_data
385 385
 	 * @param array $shipping
386 386
 	 */
387
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
387
+	protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) {
388 388
 
389 389
 		// Ensure the invoice exists.
390
-        if ( ! $invoice->exists() ) {
391
-            wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
390
+        if (!$invoice->exists()) {
391
+            wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing'));
392 392
         }
393 393
 
394 394
 		// Save payment form data.
395
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
396
-        delete_post_meta( $invoice->get_id(), 'payment_form_data' );
397
-		delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
398
-		if ( ! empty( $prepared_payment_form_data ) ) {
395
+		$prepared_payment_form_data = apply_filters('getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice);
396
+        delete_post_meta($invoice->get_id(), 'payment_form_data');
397
+		delete_post_meta($invoice->get_id(), 'additional_meta_data');
398
+		if (!empty($prepared_payment_form_data)) {
399 399
 
400
-			if ( ! empty( $prepared_payment_form_data['all'] ) ) {
401
-				update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
400
+			if (!empty($prepared_payment_form_data['all'])) {
401
+				update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all']);
402 402
 			}
403 403
 
404
-			if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
405
-				update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
404
+			if (!empty($prepared_payment_form_data['meta'])) {
405
+				update_post_meta($invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta']);
406 406
 			}
407 407
 }
408 408
 
409 409
 		// Save payment form data.
410
-		$shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
411
-        if ( ! empty( $shipping ) ) {
412
-            update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
410
+		$shipping = apply_filters('getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission);
411
+        if (!empty($shipping)) {
412
+            update_post_meta($invoice->get_id(), 'shipping_address', $shipping);
413 413
 		}
414 414
 
415 415
 		// Backwards compatibility.
416
-        add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
416
+        add_filter('wp_redirect', array($this, 'send_redirect_response'));
417 417
 
418
-		$this->process_payment( $invoice );
418
+		$this->process_payment($invoice);
419 419
 
420 420
         // If we are here, there was an error.
421
-		wpinv_send_back_to_checkout( $invoice );
421
+		wpinv_send_back_to_checkout($invoice);
422 422
 
423 423
 	}
424 424
 
@@ -427,41 +427,41 @@  discard block
 block discarded – undo
427 427
 	 *
428 428
 	 * @param WPInv_Invoice $invoice
429 429
 	 */
430
-	protected function process_payment( $invoice ) {
430
+	protected function process_payment($invoice) {
431 431
 
432 432
 		// Clear any checkout errors.
433 433
 		wpinv_clear_errors();
434 434
 
435 435
 		// No need to send free invoices to the gateway.
436
-		if ( $invoice->is_free() ) {
437
-			$this->process_free_payment( $invoice );
436
+		if ($invoice->is_free()) {
437
+			$this->process_free_payment($invoice);
438 438
 		}
439 439
 
440 440
 		$submission = $this->payment_form_submission;
441 441
 
442 442
 		// Fires before sending to the gateway.
443
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
443
+		do_action('getpaid_checkout_before_gateway', $invoice, $submission);
444 444
 
445 445
 		// Allow the sumission data to be modified before it is sent to the gateway.
446 446
 		$submission_data    = $submission->get_data();
447
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
448
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
447
+		$submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice);
448
+		$submission_data    = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice);
449 449
 
450 450
 		// Validate the currency.
451
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
452
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
451
+		if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) {
452
+			wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support this currency', 'invoicing'));
453 453
 		}
454 454
 
455 455
 		// Check to see if we have any errors.
456
-		if ( wpinv_get_errors() ) {
457
-			wpinv_send_back_to_checkout( $invoice );
456
+		if (wpinv_get_errors()) {
457
+			wpinv_send_back_to_checkout($invoice);
458 458
 		}
459 459
 
460 460
 		// Send info to the gateway for payment processing
461
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
461
+		do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission);
462 462
 
463 463
 		// Backwards compatibility.
464
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
464
+		wpinv_send_to_gateway($submission_gateway, $invoice);
465 465
 
466 466
 	}
467 467
 
@@ -470,12 +470,12 @@  discard block
 block discarded – undo
470 470
 	 *
471 471
 	 * @param WPInv_Invoice $invoice
472 472
 	 */
473
-	protected function process_free_payment( $invoice ) {
473
+	protected function process_free_payment($invoice) {
474 474
 
475
-		$invoice->set_gateway( 'none' );
476
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
475
+		$invoice->set_gateway('none');
476
+		$invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true);
477 477
 		$invoice->mark_paid();
478
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
478
+		wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
479 479
 
480 480
 	}
481 481
 
@@ -483,9 +483,9 @@  discard block
 block discarded – undo
483 483
      * Sends a redrect response to payment details.
484 484
      *
485 485
      */
486
-    public function send_redirect_response( $url ) {
487
-        $url = urlencode( $url );
488
-        wp_send_json_success( $url );
486
+    public function send_redirect_response($url) {
487
+        $url = urlencode($url);
488
+        wp_send_json_success($url);
489 489
     }
490 490
 
491 491
 }
Please login to merge, or discard this patch.
includes/class-bp-getpaid-component.php 2 patches
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -17,45 +17,45 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class BP_GetPaid_Component extends BP_Component {
19 19
 
20
-	/**
21
-	 * Start the component setup process.
22
-	 *
23
-	 * @since 2.1.5
24
-	 */
25
-	public function __construct() {
26
-		parent::start(
27
-			'getpaid',
28
-			'GetPaid',
29
-			buddypress()->plugin_dir,
30
-			array(
31
-				'adminbar_myaccount_order' => 30,
32
-			)
33
-		);
34
-	}
20
+    /**
21
+     * Start the component setup process.
22
+     *
23
+     * @since 2.1.5
24
+     */
25
+    public function __construct() {
26
+        parent::start(
27
+            'getpaid',
28
+            'GetPaid',
29
+            buddypress()->plugin_dir,
30
+            array(
31
+                'adminbar_myaccount_order' => 30,
32
+            )
33
+        );
34
+    }
35 35
 
36 36
     /**
37
-	 * Set up component global variables.
38
-	 *
39
-	 * @since 2.1.5
40
-	 *
41
-	 *
42
-	 * @param array $args {
43
-	 *     All values are optional.
44
-	 *     @type string   $slug                  The component slug. Used to construct certain URLs, such as 'friends' in
45
-	 *                                           http://example.com/members/joe/friends/. Default: the value of $this->id.
46
-	 *     @type string   $root_slug             The component root slug. Note that this value is generally unused if the
47
-	 *                                           component has a root directory (the slug will be overridden by the
48
-	 *                                           post_name of the directory page). Default: the slug of the directory page
49
-	 *                                           if one is found, otherwise an empty string.
50
-	 *     @type bool     $has_directory         Set to true if the component requires an associated WordPress page.
51
-	 *     @type callable $notification_callback Optional. The callable function that formats the component's notifications.
52
-	 *     @type string   $search_term           Optional. The placeholder text in the component directory search box. Eg,
53
-	 *                                           'Search Groups...'.
54
-	 *     @type array    $global_tables         Optional. An array of database table names.
55
-	 *     @type array    $meta_tables           Optional. An array of metadata table names.
56
-	 * }
57
-	 */
58
-	public function setup_globals( $args = array() ) {
37
+     * Set up component global variables.
38
+     *
39
+     * @since 2.1.5
40
+     *
41
+     *
42
+     * @param array $args {
43
+     *     All values are optional.
44
+     *     @type string   $slug                  The component slug. Used to construct certain URLs, such as 'friends' in
45
+     *                                           http://example.com/members/joe/friends/. Default: the value of $this->id.
46
+     *     @type string   $root_slug             The component root slug. Note that this value is generally unused if the
47
+     *                                           component has a root directory (the slug will be overridden by the
48
+     *                                           post_name of the directory page). Default: the slug of the directory page
49
+     *                                           if one is found, otherwise an empty string.
50
+     *     @type bool     $has_directory         Set to true if the component requires an associated WordPress page.
51
+     *     @type callable $notification_callback Optional. The callable function that formats the component's notifications.
52
+     *     @type string   $search_term           Optional. The placeholder text in the component directory search box. Eg,
53
+     *                                           'Search Groups...'.
54
+     *     @type array    $global_tables         Optional. An array of database table names.
55
+     *     @type array    $meta_tables           Optional. An array of metadata table names.
56
+     * }
57
+     */
58
+    public function setup_globals( $args = array() ) {
59 59
         parent::setup_globals(
60 60
             array(
61 61
                 'id'            => 'getpaid',
@@ -64,21 +64,21 @@  discard block
 block discarded – undo
64 64
                 'has_directory' => false,
65 65
             )
66 66
         );
67
-	}
68
-
69
-	/**
70
-	 * Set up component navigation.
71
-	 *
72
-	 * @since 2.1.5
73
-	 *
74
-	 * @see BP_Component::setup_nav() for a description of arguments.
75
-	 *
76
-	 * @param array $main_nav Optional. See BP_Component::setup_nav() for description.
77
-	 * @param array $sub_nav  Optional. See BP_Component::setup_nav() for description.
78
-	 */
79
-	public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
80
-
81
-		// Abort if the integration is inactive.
67
+    }
68
+
69
+    /**
70
+     * Set up component navigation.
71
+     *
72
+     * @since 2.1.5
73
+     *
74
+     * @see BP_Component::setup_nav() for a description of arguments.
75
+     *
76
+     * @param array $main_nav Optional. See BP_Component::setup_nav() for description.
77
+     * @param array $sub_nav  Optional. See BP_Component::setup_nav() for description.
78
+     */
79
+    public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
80
+
81
+        // Abort if the integration is inactive.
82 82
         if ( ! getpaid_is_buddypress_integration_active() || ! is_user_logged_in() ) {
83 83
             return;
84 84
         }
@@ -88,25 +88,25 @@  discard block
 block discarded – undo
88 88
             return;
89 89
         }
90 90
 
91
-		// Determine user to use.
92
-		$user_domain   = bp_loggedin_user_domain();
93
-		$slug          = 'getpaid';
94
-		$payments_link = trailingslashit( $user_domain . $slug );
95
-
96
-		// Add 'Payments' to the main navigation.
97
-		$main_nav = array(
98
-			'name'                    => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ),
99
-			'slug'                    => $slug,
100
-			'position'                => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ),
101
-			'screen_function'         => array( $this, 'display_current_tab' ),
102
-			'default_subnav_slug'     => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ),
91
+        // Determine user to use.
92
+        $user_domain   = bp_loggedin_user_domain();
93
+        $slug          = 'getpaid';
94
+        $payments_link = trailingslashit( $user_domain . $slug );
95
+
96
+        // Add 'Payments' to the main navigation.
97
+        $main_nav = array(
98
+            'name'                    => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ),
99
+            'slug'                    => $slug,
100
+            'position'                => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ),
101
+            'screen_function'         => array( $this, 'display_current_tab' ),
102
+            'default_subnav_slug'     => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ),
103 103
             'show_for_displayed_user' => false,
104
-			'item_css_id'             => $this->id,
105
-			'parent_url'              => $user_domain,
106
-			'parent_slug'             => buddypress()->slug,
107
-		);
104
+            'item_css_id'             => $this->id,
105
+            'parent_url'              => $user_domain,
106
+            'parent_slug'             => buddypress()->slug,
107
+        );
108 108
 
109
-		// Add the subnav items to the payments nav item if we are using a theme that supports this.
109
+        // Add the subnav items to the payments nav item if we are using a theme that supports this.
110 110
         foreach ( getpaid_get_user_content_tabs() as $_slug => $tab ) {
111 111
 
112 112
             $sub_nav[] = array(
@@ -116,8 +116,8 @@  discard block
 block discarded – undo
116 116
                 'parent_slug'             => $slug,
117 117
                 'position'                => 10,
118 118
                 'screen_function'         => function() use ( $tab ) {
119
-					$GLOBALS['getpaid_bp_current_tab'] = $tab;
120
-					$this->display_current_tab();
119
+                    $GLOBALS['getpaid_bp_current_tab'] = $tab;
120
+                    $this->display_current_tab();
121 121
                 },
122 122
                 'show_for_displayed_user' => false,
123 123
                 'item_css_id'             => "getpaid-bp-$_slug",
@@ -125,27 +125,27 @@  discard block
 block discarded – undo
125 125
 
126 126
         }
127 127
 
128
-		parent::setup_nav( $main_nav, $sub_nav );
129
-	}
130
-
131
-	/**
132
-	 * Set up the component entries in the WordPress Admin Bar.
133
-	 *
134
-	 * @since 2.1.5
135
-	 *
136
-	 * @see BP_Component::setup_nav() for a description of the $wp_admin_nav
137
-	 *      parameter array.
138
-	 *
139
-	 * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a
140
-	 *                            description.
141
-	 */
142
-	public function setup_admin_bar( $wp_admin_nav = array() ) {
128
+        parent::setup_nav( $main_nav, $sub_nav );
129
+    }
143 130
 
144
-		// Menus for logged in user.
145
-		if ( is_user_logged_in() ) {
146
-
147
-			// Setup the logged in user variables.
148
-			$payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' );
131
+    /**
132
+     * Set up the component entries in the WordPress Admin Bar.
133
+     *
134
+     * @since 2.1.5
135
+     *
136
+     * @see BP_Component::setup_nav() for a description of the $wp_admin_nav
137
+     *      parameter array.
138
+     *
139
+     * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a
140
+     *                            description.
141
+     */
142
+    public function setup_admin_bar( $wp_admin_nav = array() ) {
143
+
144
+        // Menus for logged in user.
145
+        if ( is_user_logged_in() ) {
146
+
147
+            // Setup the logged in user variables.
148
+            $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' );
149 149
 
150 150
             // Add the "Payments" sub menu.
151 151
             $wp_admin_nav[] = array(
@@ -168,48 +168,48 @@  discard block
 block discarded – undo
168 168
             }
169 169
 }
170 170
 
171
-		parent::setup_admin_bar( $wp_admin_nav );
172
-	}
173
-
174
-	/**
175
-	 * Retrieves the current tab.
176
-	 *
177
-	 * @since 2.1.5
178
-	 */
179
-	public function get_current_tab() {
180
-		global $getpaid_bp_current_tab;
181
-
182
-		if ( empty( $getpaid_bp_current_tab ) ) {
183
-			return array(
184
-				'label'   => __( 'Invoices', 'invoicing' ),
185
-				'content' => '[wpinv_history]',
186
-				'icon'    => 'fas fa-file-invoice',
187
-			);
188
-		}
189
-
190
-		return $getpaid_bp_current_tab;
191
-	}
192
-
193
-	/**
194
-	 * Displays the current tab.
195
-	 *
196
-	 * @since 2.1.5
197
-	 */
198
-	public function display_current_tab() {
199
-
200
-		add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) );
201
-		$template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' );
171
+        parent::setup_admin_bar( $wp_admin_nav );
172
+    }
173
+
174
+    /**
175
+     * Retrieves the current tab.
176
+     *
177
+     * @since 2.1.5
178
+     */
179
+    public function get_current_tab() {
180
+        global $getpaid_bp_current_tab;
181
+
182
+        if ( empty( $getpaid_bp_current_tab ) ) {
183
+            return array(
184
+                'label'   => __( 'Invoices', 'invoicing' ),
185
+                'content' => '[wpinv_history]',
186
+                'icon'    => 'fas fa-file-invoice',
187
+            );
188
+        }
189
+
190
+        return $getpaid_bp_current_tab;
191
+    }
192
+
193
+    /**
194
+     * Displays the current tab.
195
+     *
196
+     * @since 2.1.5
197
+     */
198
+    public function display_current_tab() {
199
+
200
+        add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) );
201
+        $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' );
202 202
 
203 203
         bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) );
204
-	}
205
-
206
-	/**
207
-	 * Handles the actual display of the current tab.
208
-	 *
209
-	 * @since 2.1.5
210
-	 */
211
-	public function handle_display_current_tab() {
212
-		echo getpaid_prepare_user_content_tab( $this->get_current_tab() );
213
-	}
204
+    }
205
+
206
+    /**
207
+     * Handles the actual display of the current tab.
208
+     *
209
+     * @since 2.1.5
210
+     */
211
+    public function handle_display_current_tab() {
212
+        echo getpaid_prepare_user_content_tab( $this->get_current_tab() );
213
+    }
214 214
 
215 215
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 
10 10
 // Exit if accessed directly.
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * Main GetPaid Class.
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	 *     @type array    $meta_tables           Optional. An array of metadata table names.
56 56
 	 * }
57 57
 	 */
58
-	public function setup_globals( $args = array() ) {
58
+	public function setup_globals($args = array()) {
59 59
         parent::setup_globals(
60 60
             array(
61 61
                 'id'            => 'getpaid',
@@ -76,30 +76,30 @@  discard block
 block discarded – undo
76 76
 	 * @param array $main_nav Optional. See BP_Component::setup_nav() for description.
77 77
 	 * @param array $sub_nav  Optional. See BP_Component::setup_nav() for description.
78 78
 	 */
79
-	public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
79
+	public function setup_nav($main_nav = array(), $sub_nav = array()) {
80 80
 
81 81
 		// Abort if the integration is inactive.
82
-        if ( ! getpaid_is_buddypress_integration_active() || ! is_user_logged_in() ) {
82
+        if (!getpaid_is_buddypress_integration_active() || !is_user_logged_in()) {
83 83
             return;
84 84
         }
85 85
 
86 86
         // Or a user is not viewing their profile.
87
-        if ( bp_displayed_user_id() !== bp_loggedin_user_id() ) {
87
+        if (bp_displayed_user_id() !== bp_loggedin_user_id()) {
88 88
             return;
89 89
         }
90 90
 
91 91
 		// Determine user to use.
92 92
 		$user_domain   = bp_loggedin_user_domain();
93 93
 		$slug          = 'getpaid';
94
-		$payments_link = trailingslashit( $user_domain . $slug );
94
+		$payments_link = trailingslashit($user_domain . $slug);
95 95
 
96 96
 		// Add 'Payments' to the main navigation.
97 97
 		$main_nav = array(
98
-			'name'                    => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ),
98
+			'name'                    => _x('Billing', 'BuddyPress profile payments screen nav', 'invoicing'),
99 99
 			'slug'                    => $slug,
100
-			'position'                => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ),
101
-			'screen_function'         => array( $this, 'display_current_tab' ),
102
-			'default_subnav_slug'     => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ),
100
+			'position'                => apply_filters('wpinv_bp_nav_position', wpinv_get_option('wpinv_menu_position', 91), $slug),
101
+			'screen_function'         => array($this, 'display_current_tab'),
102
+			'default_subnav_slug'     => apply_filters('getpaid_default_tab', 'gp-edit-address'),
103 103
             'show_for_displayed_user' => false,
104 104
 			'item_css_id'             => $this->id,
105 105
 			'parent_url'              => $user_domain,
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 		);
108 108
 
109 109
 		// Add the subnav items to the payments nav item if we are using a theme that supports this.
110
-        foreach ( getpaid_get_user_content_tabs() as $_slug => $tab ) {
110
+        foreach (getpaid_get_user_content_tabs() as $_slug => $tab) {
111 111
 
112 112
             $sub_nav[] = array(
113 113
                 'name'                    => $tab['label'],
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
                 'parent_url'              => $payments_link,
116 116
                 'parent_slug'             => $slug,
117 117
                 'position'                => 10,
118
-                'screen_function'         => function() use ( $tab ) {
118
+                'screen_function'         => function() use ($tab) {
119 119
 					$GLOBALS['getpaid_bp_current_tab'] = $tab;
120 120
 					$this->display_current_tab();
121 121
                 },
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 
126 126
         }
127 127
 
128
-		parent::setup_nav( $main_nav, $sub_nav );
128
+		parent::setup_nav($main_nav, $sub_nav);
129 129
 	}
130 130
 
131 131
 	/**
@@ -139,36 +139,36 @@  discard block
 block discarded – undo
139 139
 	 * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a
140 140
 	 *                            description.
141 141
 	 */
142
-	public function setup_admin_bar( $wp_admin_nav = array() ) {
142
+	public function setup_admin_bar($wp_admin_nav = array()) {
143 143
 
144 144
 		// Menus for logged in user.
145
-		if ( is_user_logged_in() ) {
145
+		if (is_user_logged_in()) {
146 146
 
147 147
 			// Setup the logged in user variables.
148
-			$payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' );
148
+			$payments_link = trailingslashit(bp_loggedin_user_domain() . 'getpaid/');
149 149
 
150 150
             // Add the "Payments" sub menu.
151 151
             $wp_admin_nav[] = array(
152 152
                 'parent' => buddypress()->my_account_menu_id,
153 153
                 'id'     => 'my-account-getpaid',
154
-                'title'  => _x( 'Billing', 'BuddyPress my account payments sub nav', 'invoicing' ),
155
-                'href'   => $payments_link . apply_filters( 'getpaid_default_tab', 'gp-edit-address' ),
154
+                'title'  => _x('Billing', 'BuddyPress my account payments sub nav', 'invoicing'),
155
+                'href'   => $payments_link . apply_filters('getpaid_default_tab', 'gp-edit-address'),
156 156
             );
157 157
 
158
-            foreach ( getpaid_get_user_content_tabs() as $slug => $tab ) {
158
+            foreach (getpaid_get_user_content_tabs() as $slug => $tab) {
159 159
 
160 160
                 $wp_admin_nav[] = array(
161 161
                     'parent'   => 'my-account-getpaid',
162 162
                     'id'       => 'my-account-getpaid' . $slug,
163 163
                     'title'    => $tab['label'],
164
-                    'href'     => trailingslashit( $payments_link . $slug ),
164
+                    'href'     => trailingslashit($payments_link . $slug),
165 165
                     'position' => 20,
166 166
                 );
167 167
 
168 168
             }
169 169
 }
170 170
 
171
-		parent::setup_admin_bar( $wp_admin_nav );
171
+		parent::setup_admin_bar($wp_admin_nav);
172 172
 	}
173 173
 
174 174
 	/**
@@ -179,9 +179,9 @@  discard block
 block discarded – undo
179 179
 	public function get_current_tab() {
180 180
 		global $getpaid_bp_current_tab;
181 181
 
182
-		if ( empty( $getpaid_bp_current_tab ) ) {
182
+		if (empty($getpaid_bp_current_tab)) {
183 183
 			return array(
184
-				'label'   => __( 'Invoices', 'invoicing' ),
184
+				'label'   => __('Invoices', 'invoicing'),
185 185
 				'content' => '[wpinv_history]',
186 186
 				'icon'    => 'fas fa-file-invoice',
187 187
 			);
@@ -197,10 +197,10 @@  discard block
 block discarded – undo
197 197
 	 */
198 198
 	public function display_current_tab() {
199 199
 
200
-		add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) );
201
-		$template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' );
200
+		add_action('bp_template_content', array($this, 'handle_display_current_tab'));
201
+		$template = apply_filters('bp_core_template_plugin', 'members/single/plugins');
202 202
 
203
-        bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) );
203
+        bp_core_load_template(apply_filters('wpinv_bp_core_template_plugin', $template));
204 204
 	}
205 205
 
206 206
 	/**
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 	 * @since 2.1.5
210 210
 	 */
211 211
 	public function handle_display_current_tab() {
212
-		echo getpaid_prepare_user_content_tab( $this->get_current_tab() );
212
+		echo getpaid_prepare_user_content_tab($this->get_current_tab());
213 213
 	}
214 214
 
215 215
 }
Please login to merge, or discard this patch.
templates/payment-forms/cart-item.php 2 patches
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -26,71 +26,71 @@  discard block
 block discarded – undo
26 26
 
27 27
 				<?php
28 28
 
29
-					// Fires before printing a line item column.
30
-					do_action( "getpaid_form_cart_item_before_$key", $item, $form );
29
+                    // Fires before printing a line item column.
30
+                    do_action( "getpaid_form_cart_item_before_$key", $item, $form );
31 31
 
32
-					// Item name.
33
-					if ( 'name' === $key ) {
32
+                    // Item name.
33
+                    if ( 'name' === $key ) {
34 34
 
35 35
 
36
-						ob_start();
36
+                        ob_start();
37 37
 
38
-						// Add an optional description.
39
-						$description = $item->get_description();
38
+                        // Add an optional description.
39
+                        $description = $item->get_description();
40 40
 
41
-						if ( ! empty( $description ) ) {
42
-							echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post( $description ) . '</small>';
43
-						}
41
+                        if ( ! empty( $description ) ) {
42
+                            echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post( $description ) . '</small>';
43
+                        }
44 44
 
45
-						// Price help text.
46
-						$description = getpaid_item_recurring_price_help_text( $item, $currency );
47
-						if ( $description ) {
48
-							echo "<small class='getpaid-form-item-price-desc form-text text-muted font-italic pr-2 m-0'>" . wp_kses_post( $description ) . '</small>';
49
-						}
45
+                        // Price help text.
46
+                        $description = getpaid_item_recurring_price_help_text( $item, $currency );
47
+                        if ( $description ) {
48
+                            echo "<small class='getpaid-form-item-price-desc form-text text-muted font-italic pr-2 m-0'>" . wp_kses_post( $description ) . '</small>';
49
+                        }
50 50
 
51
-						do_action( 'getpaid_payment_form_cart_item_description', $item, $form );
51
+                        do_action( 'getpaid_payment_form_cart_item_description', $item, $form );
52 52
 
53
-						if ( wpinv_current_user_can_manage_invoicing() ) {
53
+                        if ( wpinv_current_user_can_manage_invoicing() ) {
54 54
 
55
-							edit_post_link(
56
-								__( 'Edit this item.', 'invoicing' ),
57
-								'<small class="form-text text-muted">',
58
-								'</small>',
59
-								$item->get_id(),
60
-								'text-danger'
61
-							);
55
+                            edit_post_link(
56
+                                __( 'Edit this item.', 'invoicing' ),
57
+                                '<small class="form-text text-muted">',
58
+                                '</small>',
59
+                                $item->get_id(),
60
+                                'text-danger'
61
+                            );
62 62
 
63
-						}
63
+                        }
64 64
 
65
-						$description = ob_get_clean();
65
+                        $description = ob_get_clean();
66 66
 
67
-						// Display the name.
68
-						$tootip = empty( $description ) ? '' : '&nbsp;<i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>';
67
+                        // Display the name.
68
+                        $tootip = empty( $description ) ? '' : '&nbsp;<i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>';
69 69
 
70
-						$has_featured_image = has_post_thumbnail( $item->get_id() );
70
+                        $has_featured_image = has_post_thumbnail( $item->get_id() );
71 71
 
72
-						if ( $has_featured_image ) {
73
-							echo '<div class="d-flex align-items-center getpaid-form-item-has-featured-image">';
74
-							echo '<div class="getpaid-form-item-image-container mr-2">';
75
-							echo get_the_post_thumbnail( $item->get_id(), 'thumbnail', array( 'class' => 'getpaid-form-item-image mb-0' ) );
76
-							echo '</div>';
77
-							echo '<div class="getpaid-form-item-name-container">';
78
-						}
72
+                        if ( $has_featured_image ) {
73
+                            echo '<div class="d-flex align-items-center getpaid-form-item-has-featured-image">';
74
+                            echo '<div class="getpaid-form-item-image-container mr-2">';
75
+                            echo get_the_post_thumbnail( $item->get_id(), 'thumbnail', array( 'class' => 'getpaid-form-item-image mb-0' ) );
76
+                            echo '</div>';
77
+                            echo '<div class="getpaid-form-item-name-container">';
78
+                        }
79 79
 
80
-						echo '<div class="mb-1 font-weight-bold">' . esc_html( $item->get_name() ) . wp_kses_post( $tootip ) . '</div>';
80
+                        echo '<div class="mb-1 font-weight-bold">' . esc_html( $item->get_name() ) . wp_kses_post( $tootip ) . '</div>';
81 81
 
82
-						if ( ! empty( $description ) ) {
83
-							printf( '<span class="d-none d-sm-block getpaid-item-desc">%s</span>', wp_kses_post( $description ) );
84
-						}
82
+                        if ( ! empty( $description ) ) {
83
+                            printf( '<span class="d-none d-sm-block getpaid-item-desc">%s</span>', wp_kses_post( $description ) );
84
+                        }
85 85
 
86
-						if ( $item->allows_quantities() ) {
87
-							printf(
88
-								'<small class="d-sm-none text-muted form-text">%s</small>',
89
-								sprintf(
90
-									// translators: %s is the item quantity.
91
-									esc_html__( 'Qty %s', 'invoicing' ),
92
-									sprintf(
93
-										'<input
86
+                        if ( $item->allows_quantities() ) {
87
+                            printf(
88
+                                '<small class="d-sm-none text-muted form-text">%s</small>',
89
+                                sprintf(
90
+                                    // translators: %s is the item quantity.
91
+                                    esc_html__( 'Qty %s', 'invoicing' ),
92
+                                    sprintf(
93
+                                        '<input
94 94
 												type="number"
95 95
 												step="0.01"
96 96
 												style="width: 48px;"
@@ -99,62 +99,62 @@  discard block
 block discarded – undo
99 99
 												min="1"
100 100
 												max="%s"
101 101
 												>',
102
-										(float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(),
103
-										floatval( null !== $max_qty ? $max_qty : 1000000000000 )
104
-									)
105
-								)
106
-							);
107
-						} else {
108
-							printf(
109
-								'<small class="d-sm-none text-muted form-text">%s</small>',
110
-								sprintf(
111
-									// translators: %s is the item quantity.
112
-									esc_html__( 'Qty %s', 'invoicing' ),
113
-									(float) $item->get_quantity()
114
-								)
115
-							);
116
-						}
117
-
118
-						if ( $has_featured_image ) {
119
-							echo '</div>';
120
-							echo '</div>';
121
-						}
122
-					}
123
-
124
-					// Item price.
125
-					if ( 'price' === $key ) {
126
-
127
-					// Set the currency position.
128
-					$position = wpinv_currency_position();
129
-
130
-					if ( 'left_space' === $position ) {
131
-						$position = 'left';
132
-					}
133
-
134
-					if ( 'right_space' === $position ) {
135
-						$position = 'right';
136
-					}
137
-
138
-					if ( $item->user_can_set_their_price() ) {
139
-						$price            = max( (float) $item->get_price(), (float) $item->get_minimum_price() );
140
-						$minimum          = (float) $item->get_minimum_price();
141
-						$validate_minimum = '';
142
-						$class            = '';
143
-						$data_minimum     = '';
144
-
145
-						if ( $minimum > 0 ) {
146
-							$validate_minimum = sprintf(
147
-								// translators: %s is the minimum price.
148
-								esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ),
149
-								wp_strip_all_tags( wpinv_price( $minimum, $currency ) )
150
-							);
151
-
152
-							$class = 'getpaid-validate-minimum-amount';
153
-
154
-							$data_minimum     = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'";
155
-						}
156
-
157
-						?>
102
+                                        (float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(),
103
+                                        floatval( null !== $max_qty ? $max_qty : 1000000000000 )
104
+                                    )
105
+                                )
106
+                            );
107
+                        } else {
108
+                            printf(
109
+                                '<small class="d-sm-none text-muted form-text">%s</small>',
110
+                                sprintf(
111
+                                    // translators: %s is the item quantity.
112
+                                    esc_html__( 'Qty %s', 'invoicing' ),
113
+                                    (float) $item->get_quantity()
114
+                                )
115
+                            );
116
+                        }
117
+
118
+                        if ( $has_featured_image ) {
119
+                            echo '</div>';
120
+                            echo '</div>';
121
+                        }
122
+                    }
123
+
124
+                    // Item price.
125
+                    if ( 'price' === $key ) {
126
+
127
+                    // Set the currency position.
128
+                    $position = wpinv_currency_position();
129
+
130
+                    if ( 'left_space' === $position ) {
131
+                        $position = 'left';
132
+                    }
133
+
134
+                    if ( 'right_space' === $position ) {
135
+                        $position = 'right';
136
+                    }
137
+
138
+                    if ( $item->user_can_set_their_price() ) {
139
+                        $price            = max( (float) $item->get_price(), (float) $item->get_minimum_price() );
140
+                        $minimum          = (float) $item->get_minimum_price();
141
+                        $validate_minimum = '';
142
+                        $class            = '';
143
+                        $data_minimum     = '';
144
+
145
+                        if ( $minimum > 0 ) {
146
+                            $validate_minimum = sprintf(
147
+                                // translators: %s is the minimum price.
148
+                                esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ),
149
+                                wp_strip_all_tags( wpinv_price( $minimum, $currency ) )
150
+                            );
151
+
152
+                            $class = 'getpaid-validate-minimum-amount';
153
+
154
+                            $data_minimum     = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'";
155
+                        }
156
+
157
+                        ?>
158 158
 								<div class="input-group input-group-sm">
159 159
 								<?php if ( 'left' === $position ) : ?>
160 160
 										<div class="input-group-prepend">
@@ -179,44 +179,44 @@  discard block
 block discarded – undo
179 179
 
180 180
 							<?php
181 181
 
182
-						} else {
183
-						echo wp_kses_post( wpinv_price( $item->get_price(), $currency ) );
182
+                        } else {
183
+                        echo wp_kses_post( wpinv_price( $item->get_price(), $currency ) );
184 184
 
185
-						?>
185
+                        ?>
186 186
 								<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() ); ?>'>
187 187
 						<?php
188
-						}
188
+                        }
189 189
 
190
-					printf(
190
+                    printf(
191 191
                         '<small class="d-sm-none text-muted form-text getpaid-mobile-item-subtotal">%s</small>',
192
-						// translators: %s is the item subtotal.
192
+                        // translators: %s is the item subtotal.
193 193
                         sprintf( esc_html__( 'Subtotal: %s', 'invoicing' ), wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ) )
194 194
                     );
195
-					}
195
+                    }
196 196
 
197
-					// Item quantity.
198
-					if ( 'quantity' === $key ) {
197
+                    // Item quantity.
198
+                    if ( 'quantity' === $key ) {
199 199
 
200
-					if ( $item->allows_quantities() ) {
201
-						?>
200
+                    if ( $item->allows_quantities() ) {
201
+                        ?>
202 202
 								<input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' type="number" step="any" 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() == 0 ? 1 : (float) $item->get_quantity(); ?>' min='1' <?php echo null !== $max_qty ? 'max="' . (float) $max_qty . '"' : ''; ?> required>
203 203
 							<?php
204
-						} else {
205
-						echo (float) $item->get_quantity();
206
-						echo '&nbsp;&nbsp;&nbsp;';
207
-						?>
204
+                        } else {
205
+                        echo (float) $item->get_quantity();
206
+                        echo '&nbsp;&nbsp;&nbsp;';
207
+                        ?>
208 208
 								<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(); ?>'>
209 209
 						<?php
210
-						}
210
+                        }
211 211
 }
212 212
 
213
-					// Item sub total.
214
-					if ( 'subtotal' === $key ) {
215
-					echo wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) );
216
-					}
213
+                    // Item sub total.
214
+                    if ( 'subtotal' === $key ) {
215
+                    echo wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) );
216
+                    }
217 217
 
218
-					do_action( "getpaid_payment_form_cart_item_$key", $item, $form );
219
-				?>
218
+                    do_action( "getpaid_payment_form_cart_item_$key", $item, $form );
219
+                ?>
220 220
 
221 221
 			</div>
222 222
 
Please login to merge, or discard this patch.
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -9,28 +9,28 @@  discard block
 block discarded – undo
9 9
  * @var GetPaid_Form_Item $item
10 10
  */
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14
-do_action( 'getpaid_before_payment_form_cart_item', $form, $item );
14
+do_action('getpaid_before_payment_form_cart_item', $form, $item);
15 15
 
16 16
 $currency = $form->get_currency();
17
-$max_qty  = wpinv_item_max_buyable_quantity( $item->get_id() );
17
+$max_qty  = wpinv_item_max_buyable_quantity($item->get_id());
18 18
 ?>
19 19
 <div class='getpaid-payment-form-items-cart-item getpaid-<?php echo $item->is_required() ? 'required' : 'selectable'; ?> item-<?php echo (int) $item->get_id(); ?> border-bottom py-2 px-3'>
20 20
 
21 21
 	<div class="form-row align-items-center needs-validation">
22 22
 
23
-		<?php foreach ( array_keys( $columns ) as $key ) : ?>
23
+		<?php foreach (array_keys($columns) as $key) : ?>
24 24
 
25
-			<div class="<?php echo 'name' === $key ? 'col-6' : 'col'; ?> <?php echo ( in_array( $key, array( 'subtotal', 'quantity', 'tax_rate' ), true ) ) ? 'd-none d-sm-block' : ''; ?> position-relative getpaid-form-cart-item-<?php echo esc_attr( $key ); ?> getpaid-form-cart-item-<?php echo esc_attr( $key ); ?>-<?php echo (int) $item->get_id(); ?>">
25
+			<div class="<?php echo 'name' === $key ? 'col-6' : 'col'; ?> <?php echo (in_array($key, array('subtotal', 'quantity', 'tax_rate'), true)) ? 'd-none d-sm-block' : ''; ?> position-relative getpaid-form-cart-item-<?php echo esc_attr($key); ?> getpaid-form-cart-item-<?php echo esc_attr($key); ?>-<?php echo (int) $item->get_id(); ?>">
26 26
 
27 27
 				<?php
28 28
 
29 29
 					// Fires before printing a line item column.
30
-					do_action( "getpaid_form_cart_item_before_$key", $item, $form );
30
+					do_action("getpaid_form_cart_item_before_$key", $item, $form);
31 31
 
32 32
 					// Item name.
33
-					if ( 'name' === $key ) {
33
+					if ('name' === $key) {
34 34
 
35 35
 
36 36
 						ob_start();
@@ -38,22 +38,22 @@  discard block
 block discarded – undo
38 38
 						// Add an optional description.
39 39
 						$description = $item->get_description();
40 40
 
41
-						if ( ! empty( $description ) ) {
42
-							echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post( $description ) . '</small>';
41
+						if (!empty($description)) {
42
+							echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post($description) . '</small>';
43 43
 						}
44 44
 
45 45
 						// Price help text.
46
-						$description = getpaid_item_recurring_price_help_text( $item, $currency );
47
-						if ( $description ) {
48
-							echo "<small class='getpaid-form-item-price-desc form-text text-muted font-italic pr-2 m-0'>" . wp_kses_post( $description ) . '</small>';
46
+						$description = getpaid_item_recurring_price_help_text($item, $currency);
47
+						if ($description) {
48
+							echo "<small class='getpaid-form-item-price-desc form-text text-muted font-italic pr-2 m-0'>" . wp_kses_post($description) . '</small>';
49 49
 						}
50 50
 
51
-						do_action( 'getpaid_payment_form_cart_item_description', $item, $form );
51
+						do_action('getpaid_payment_form_cart_item_description', $item, $form);
52 52
 
53
-						if ( wpinv_current_user_can_manage_invoicing() ) {
53
+						if (wpinv_current_user_can_manage_invoicing()) {
54 54
 
55 55
 							edit_post_link(
56
-								__( 'Edit this item.', 'invoicing' ),
56
+								__('Edit this item.', 'invoicing'),
57 57
 								'<small class="form-text text-muted">',
58 58
 								'</small>',
59 59
 								$item->get_id(),
@@ -65,30 +65,30 @@  discard block
 block discarded – undo
65 65
 						$description = ob_get_clean();
66 66
 
67 67
 						// Display the name.
68
-						$tootip = empty( $description ) ? '' : '&nbsp;<i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>';
68
+						$tootip = empty($description) ? '' : '&nbsp;<i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>';
69 69
 
70
-						$has_featured_image = has_post_thumbnail( $item->get_id() );
70
+						$has_featured_image = has_post_thumbnail($item->get_id());
71 71
 
72
-						if ( $has_featured_image ) {
72
+						if ($has_featured_image) {
73 73
 							echo '<div class="d-flex align-items-center getpaid-form-item-has-featured-image">';
74 74
 							echo '<div class="getpaid-form-item-image-container mr-2">';
75
-							echo get_the_post_thumbnail( $item->get_id(), 'thumbnail', array( 'class' => 'getpaid-form-item-image mb-0' ) );
75
+							echo get_the_post_thumbnail($item->get_id(), 'thumbnail', array('class' => 'getpaid-form-item-image mb-0'));
76 76
 							echo '</div>';
77 77
 							echo '<div class="getpaid-form-item-name-container">';
78 78
 						}
79 79
 
80
-						echo '<div class="mb-1 font-weight-bold">' . esc_html( $item->get_name() ) . wp_kses_post( $tootip ) . '</div>';
80
+						echo '<div class="mb-1 font-weight-bold">' . esc_html($item->get_name()) . wp_kses_post($tootip) . '</div>';
81 81
 
82
-						if ( ! empty( $description ) ) {
83
-							printf( '<span class="d-none d-sm-block getpaid-item-desc">%s</span>', wp_kses_post( $description ) );
82
+						if (!empty($description)) {
83
+							printf('<span class="d-none d-sm-block getpaid-item-desc">%s</span>', wp_kses_post($description));
84 84
 						}
85 85
 
86
-						if ( $item->allows_quantities() ) {
86
+						if ($item->allows_quantities()) {
87 87
 							printf(
88 88
 								'<small class="d-sm-none text-muted form-text">%s</small>',
89 89
 								sprintf(
90 90
 									// translators: %s is the item quantity.
91
-									esc_html__( 'Qty %s', 'invoicing' ),
91
+									esc_html__('Qty %s', 'invoicing'),
92 92
 									sprintf(
93 93
 										'<input
94 94
 												type="number"
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 												max="%s"
101 101
 												>',
102 102
 										(float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(),
103
-										floatval( null !== $max_qty ? $max_qty : 1000000000000 )
103
+										floatval(null !== $max_qty ? $max_qty : 1000000000000)
104 104
 									)
105 105
 								)
106 106
 							);
@@ -109,70 +109,70 @@  discard block
 block discarded – undo
109 109
 								'<small class="d-sm-none text-muted form-text">%s</small>',
110 110
 								sprintf(
111 111
 									// translators: %s is the item quantity.
112
-									esc_html__( 'Qty %s', 'invoicing' ),
112
+									esc_html__('Qty %s', 'invoicing'),
113 113
 									(float) $item->get_quantity()
114 114
 								)
115 115
 							);
116 116
 						}
117 117
 
118
-						if ( $has_featured_image ) {
118
+						if ($has_featured_image) {
119 119
 							echo '</div>';
120 120
 							echo '</div>';
121 121
 						}
122 122
 					}
123 123
 
124 124
 					// Item price.
125
-					if ( 'price' === $key ) {
125
+					if ('price' === $key) {
126 126
 
127 127
 					// Set the currency position.
128 128
 					$position = wpinv_currency_position();
129 129
 
130
-					if ( 'left_space' === $position ) {
130
+					if ('left_space' === $position) {
131 131
 						$position = 'left';
132 132
 					}
133 133
 
134
-					if ( 'right_space' === $position ) {
134
+					if ('right_space' === $position) {
135 135
 						$position = 'right';
136 136
 					}
137 137
 
138
-					if ( $item->user_can_set_their_price() ) {
139
-						$price            = max( (float) $item->get_price(), (float) $item->get_minimum_price() );
138
+					if ($item->user_can_set_their_price()) {
139
+						$price            = max((float) $item->get_price(), (float) $item->get_minimum_price());
140 140
 						$minimum          = (float) $item->get_minimum_price();
141 141
 						$validate_minimum = '';
142 142
 						$class            = '';
143 143
 						$data_minimum     = '';
144 144
 
145
-						if ( $minimum > 0 ) {
145
+						if ($minimum > 0) {
146 146
 							$validate_minimum = sprintf(
147 147
 								// translators: %s is the minimum price.
148
-								esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ),
149
-								wp_strip_all_tags( wpinv_price( $minimum, $currency ) )
148
+								esc_attr__('The minimum allowed amount is %s', 'invoicing'),
149
+								wp_strip_all_tags(wpinv_price($minimum, $currency))
150 150
 							);
151 151
 
152 152
 							$class = 'getpaid-validate-minimum-amount';
153 153
 
154
-							$data_minimum     = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'";
154
+							$data_minimum = "data-minimum-amount='" . esc_attr(getpaid_unstandardize_amount($minimum)) . "'";
155 155
 						}
156 156
 
157 157
 						?>
158 158
 								<div class="input-group input-group-sm">
159
-								<?php if ( 'left' === $position ) : ?>
159
+								<?php if ('left' === $position) : ?>
160 160
 										<div class="input-group-prepend">
161
-											<span class="input-group-text"><?php echo wp_kses_post( wpinv_currency_symbol( $currency ) ); ?></span>
161
+											<span class="input-group-text"><?php echo wp_kses_post(wpinv_currency_symbol($currency)); ?></span>
162 162
 										</div>
163 163
 									<?php endif; ?>
164 164
 
165
-									<input type="text" <?php echo wp_kses_post( $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 esc_attr( $class ); ?>" style="width: 64px; line-height: 1; min-height: 35px;">
165
+									<input type="text" <?php echo wp_kses_post($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 esc_attr($class); ?>" style="width: 64px; line-height: 1; min-height: 35px;">
166 166
 
167
-								<?php if ( ! empty( $validate_minimum ) ) : ?>
167
+								<?php if (!empty($validate_minimum)) : ?>
168 168
 										<div class="invalid-tooltip">
169
-											<?php echo wp_kses_post( $validate_minimum ); ?>
169
+											<?php echo wp_kses_post($validate_minimum); ?>
170 170
 										</div>
171 171
 									<?php endif; ?>
172 172
 
173
-								<?php if ( 'left' !== $position ) : ?>
173
+								<?php if ('left' !== $position) : ?>
174 174
 										<div class="input-group-append">
175
-											<span class="input-group-text"><?php echo wp_kses_post( wpinv_currency_symbol( $currency ) ); ?></span>
175
+											<span class="input-group-text"><?php echo wp_kses_post(wpinv_currency_symbol($currency)); ?></span>
176 176
 										</div>
177 177
 									<?php endif; ?>
178 178
 								</div>
@@ -180,24 +180,24 @@  discard block
 block discarded – undo
180 180
 							<?php
181 181
 
182 182
 						} else {
183
-						echo wp_kses_post( wpinv_price( $item->get_price(), $currency ) );
183
+						echo wp_kses_post(wpinv_price($item->get_price(), $currency));
184 184
 
185 185
 						?>
186
-								<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() ); ?>'>
186
+								<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()); ?>'>
187 187
 						<?php
188 188
 						}
189 189
 
190 190
 					printf(
191 191
                         '<small class="d-sm-none text-muted form-text getpaid-mobile-item-subtotal">%s</small>',
192 192
 						// translators: %s is the item subtotal.
193
-                        sprintf( esc_html__( 'Subtotal: %s', 'invoicing' ), wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ) )
193
+                        sprintf(esc_html__('Subtotal: %s', 'invoicing'), wp_kses_post(wpinv_price($item->get_sub_total(), $currency)))
194 194
                     );
195 195
 					}
196 196
 
197 197
 					// Item quantity.
198
-					if ( 'quantity' === $key ) {
198
+					if ('quantity' === $key) {
199 199
 
200
-					if ( $item->allows_quantities() ) {
200
+					if ($item->allows_quantities()) {
201 201
 						?>
202 202
 								<input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' type="number" step="any" 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() == 0 ? 1 : (float) $item->get_quantity(); ?>' min='1' <?php echo null !== $max_qty ? 'max="' . (float) $max_qty . '"' : ''; ?> required>
203 203
 							<?php
@@ -211,11 +211,11 @@  discard block
 block discarded – undo
211 211
 }
212 212
 
213 213
 					// Item sub total.
214
-					if ( 'subtotal' === $key ) {
215
-					echo wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) );
214
+					if ('subtotal' === $key) {
215
+					echo wp_kses_post(wpinv_price($item->get_sub_total(), $currency));
216 216
 					}
217 217
 
218
-					do_action( "getpaid_payment_form_cart_item_$key", $item, $form );
218
+					do_action("getpaid_payment_form_cart_item_$key", $item, $form);
219 219
 				?>
220 220
 
221 221
 			</div>
@@ -226,4 +226,4 @@  discard block
 block discarded – undo
226 226
 
227 227
 </div>
228 228
 <?php
229
-do_action( 'getpaid_payment_form_cart_item', $form, $item );
229
+do_action('getpaid_payment_form_cart_item', $form, $item);
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-payment-gateway.php 2 patches
Indentation   +613 added lines, -613 removed lines patch added patch discarded remove patch
@@ -13,462 +13,462 @@  discard block
 block discarded – undo
13 13
  */
14 14
 abstract class GetPaid_Payment_Gateway {
15 15
 
16
-	/**
17
-	 * Set if the place checkout button should be renamed on selection.
18
-	 *
19
-	 * @var string
20
-	 */
21
-	public $checkout_button_text;
22
-
23
-	/**
24
-	 * Boolean whether the method is enabled.
25
-	 *
26
-	 * @var bool
27
-	 */
28
-	public $enabled = true;
29
-
30
-	/**
31
-	 * Payment method id.
32
-	 *
33
-	 * @var string
34
-	 */
35
-	public $id;
36
-
37
-	/**
38
-	 * Payment method order.
39
-	 *
40
-	 * @var int
41
-	 */
42
-	public $order = 10;
43
-
44
-	/**
45
-	 * Payment method title for the frontend.
46
-	 *
47
-	 * @var string
48
-	 */
49
-	public $title;
50
-
51
-	/**
52
-	 * Payment method description for the frontend.
53
-	 *
54
-	 * @var string
55
-	 */
56
-	public $description;
57
-
58
-	/**
59
-	 * Gateway title.
60
-	 *
61
-	 * @var string
62
-	 */
63
-	public $method_title = '';
64
-
65
-	/**
66
-	 * Gateway description.
67
-	 *
68
-	 * @var string
69
-	 */
70
-	public $method_description = '';
71
-
72
-	/**
73
-	 * Countries this gateway is allowed for.
74
-	 *
75
-	 * @var array
76
-	 */
77
-	public $countries;
78
-
79
-	/**
80
-	 * Currencies this gateway is allowed for.
81
-	 *
82
-	 * @var array
83
-	 */
84
-	public $currencies;
85
-
86
-	/**
87
-	 * Currencies this gateway is not allowed for.
88
-	 *
89
-	 * @var array
90
-	 */
91
-	public $exclude_currencies;
92
-
93
-	/**
94
-	 * Maximum transaction amount, zero does not define a maximum.
95
-	 *
96
-	 * @var int
97
-	 */
98
-	public $max_amount = 0;
99
-
100
-	/**
101
-	 * Optional URL to view a transaction.
102
-	 *
103
-	 * @var string
104
-	 */
105
-	public $view_transaction_url = '';
106
-
107
-	/**
108
-	 * Optional URL to view a subscription.
109
-	 *
110
-	 * @var string
111
-	 */
112
-	public $view_subscription_url = '';
113
-
114
-	/**
115
-	 * Optional label to show for "new payment method" in the payment
116
-	 * method/token selection radio selection.
117
-	 *
118
-	 * @var string
119
-	 */
120
-	public $new_method_label = '';
121
-
122
-	/**
123
-	 * Contains a user's saved tokens for this gateway.
124
-	 *
125
-	 * @var array
126
-	 */
127
-	protected $tokens = array();
128
-
129
-	/**
130
-	 * An array of features that this gateway supports.
131
-	 *
132
-	 * @var array
133
-	 */
134
-	protected $supports = array();
135
-
136
-	/**
137
-	 * Class constructor.
138
-	 */
139
-	public function __construct() {
140
-
141
-		// Register gateway.
142
-		add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) );
143
-
144
-		$this->enabled = wpinv_is_gateway_active( $this->id );
145
-
146
-		// Add support for various features.
147
-		foreach ( $this->supports as $feature ) {
148
-			add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' );
149
-			add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' );
150
-			add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' );
151
-		}
152
-
153
-		// Invoice addons.
154
-		if ( $this->supports( 'addons' ) ) {
155
-			add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 );
156
-		}
157
-
158
-		// Gateway settings.
159
-		add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) );
160
-
161
-		// Gateway checkout fiellds.
162
-		add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 );
163
-
164
-		// Process payment.
165
-		add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 );
166
-
167
-		// Change the checkout button text.
168
-		if ( ! empty( $this->checkout_button_text ) ) {
169
-			add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) );
170
-		}
171
-
172
-		// Check if a gateway is valid for a given currency.
173
-		add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 );
174
-
175
-		// Generate the transaction url.
176
-		add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 );
177
-
178
-		// Generate the subscription url.
179
-		add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 );
180
-
181
-		// Confirm payments.
182
-		add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 );
183
-
184
-		// Verify IPNs.
185
-		add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) );
186
-
187
-	}
188
-
189
-	/**
190
-	 * Checks if this gateway is a given gateway.
191
-	 *
192
-	 * @since 1.0.19
193
-	 * @return bool
194
-	 */
195
-	public function is( $gateway ) {
196
-		return $gateway == $this->id;
197
-	}
198
-
199
-	/**
200
-	 * Returns a users saved tokens for this gateway.
201
-	 *
202
-	 * @since 1.0.19
203
-	 * @return array
204
-	 */
205
-	public function get_tokens( $sandbox = null ) {
206
-
207
-		if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) {
208
-			$tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true );
209
-
210
-			if ( is_array( $tokens ) ) {
211
-				$this->tokens = $tokens;
212
-			}
16
+    /**
17
+     * Set if the place checkout button should be renamed on selection.
18
+     *
19
+     * @var string
20
+     */
21
+    public $checkout_button_text;
22
+
23
+    /**
24
+     * Boolean whether the method is enabled.
25
+     *
26
+     * @var bool
27
+     */
28
+    public $enabled = true;
29
+
30
+    /**
31
+     * Payment method id.
32
+     *
33
+     * @var string
34
+     */
35
+    public $id;
36
+
37
+    /**
38
+     * Payment method order.
39
+     *
40
+     * @var int
41
+     */
42
+    public $order = 10;
43
+
44
+    /**
45
+     * Payment method title for the frontend.
46
+     *
47
+     * @var string
48
+     */
49
+    public $title;
50
+
51
+    /**
52
+     * Payment method description for the frontend.
53
+     *
54
+     * @var string
55
+     */
56
+    public $description;
57
+
58
+    /**
59
+     * Gateway title.
60
+     *
61
+     * @var string
62
+     */
63
+    public $method_title = '';
64
+
65
+    /**
66
+     * Gateway description.
67
+     *
68
+     * @var string
69
+     */
70
+    public $method_description = '';
71
+
72
+    /**
73
+     * Countries this gateway is allowed for.
74
+     *
75
+     * @var array
76
+     */
77
+    public $countries;
78
+
79
+    /**
80
+     * Currencies this gateway is allowed for.
81
+     *
82
+     * @var array
83
+     */
84
+    public $currencies;
85
+
86
+    /**
87
+     * Currencies this gateway is not allowed for.
88
+     *
89
+     * @var array
90
+     */
91
+    public $exclude_currencies;
92
+
93
+    /**
94
+     * Maximum transaction amount, zero does not define a maximum.
95
+     *
96
+     * @var int
97
+     */
98
+    public $max_amount = 0;
99
+
100
+    /**
101
+     * Optional URL to view a transaction.
102
+     *
103
+     * @var string
104
+     */
105
+    public $view_transaction_url = '';
106
+
107
+    /**
108
+     * Optional URL to view a subscription.
109
+     *
110
+     * @var string
111
+     */
112
+    public $view_subscription_url = '';
113
+
114
+    /**
115
+     * Optional label to show for "new payment method" in the payment
116
+     * method/token selection radio selection.
117
+     *
118
+     * @var string
119
+     */
120
+    public $new_method_label = '';
121
+
122
+    /**
123
+     * Contains a user's saved tokens for this gateway.
124
+     *
125
+     * @var array
126
+     */
127
+    protected $tokens = array();
128
+
129
+    /**
130
+     * An array of features that this gateway supports.
131
+     *
132
+     * @var array
133
+     */
134
+    protected $supports = array();
135
+
136
+    /**
137
+     * Class constructor.
138
+     */
139
+    public function __construct() {
140
+
141
+        // Register gateway.
142
+        add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) );
143
+
144
+        $this->enabled = wpinv_is_gateway_active( $this->id );
145
+
146
+        // Add support for various features.
147
+        foreach ( $this->supports as $feature ) {
148
+            add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' );
149
+            add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' );
150
+            add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' );
151
+        }
152
+
153
+        // Invoice addons.
154
+        if ( $this->supports( 'addons' ) ) {
155
+            add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 );
156
+        }
157
+
158
+        // Gateway settings.
159
+        add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) );
160
+
161
+        // Gateway checkout fiellds.
162
+        add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 );
163
+
164
+        // Process payment.
165
+        add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 );
166
+
167
+        // Change the checkout button text.
168
+        if ( ! empty( $this->checkout_button_text ) ) {
169
+            add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) );
170
+        }
171
+
172
+        // Check if a gateway is valid for a given currency.
173
+        add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 );
174
+
175
+        // Generate the transaction url.
176
+        add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 );
177
+
178
+        // Generate the subscription url.
179
+        add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 );
180
+
181
+        // Confirm payments.
182
+        add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 );
183
+
184
+        // Verify IPNs.
185
+        add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) );
186
+
187
+    }
188
+
189
+    /**
190
+     * Checks if this gateway is a given gateway.
191
+     *
192
+     * @since 1.0.19
193
+     * @return bool
194
+     */
195
+    public function is( $gateway ) {
196
+        return $gateway == $this->id;
197
+    }
198
+
199
+    /**
200
+     * Returns a users saved tokens for this gateway.
201
+     *
202
+     * @since 1.0.19
203
+     * @return array
204
+     */
205
+    public function get_tokens( $sandbox = null ) {
206
+
207
+        if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) {
208
+            $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true );
209
+
210
+            if ( is_array( $tokens ) ) {
211
+                $this->tokens = $tokens;
212
+            }
213 213
 }
214 214
 
215
-		if ( ! is_bool( $sandbox ) ) {
216
-			return $this->tokens;
217
-		}
218
-
219
-		// Filter tokens.
220
-		$args = array( 'type' => $sandbox ? 'sandbox' : 'live' );
221
-		return wp_list_filter( $this->tokens, $args );
222
-
223
-	}
224
-
225
-	/**
226
-	 * Saves a token for this gateway.
227
-	 *
228
-	 * @since 1.0.19
229
-	 */
230
-	public function save_token( $token ) {
231
-
232
-		$tokens   = $this->get_tokens();
233
-		$tokens[] = $token;
234
-
235
-		update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens );
236
-
237
-		$this->tokens = $tokens;
238
-
239
-	}
240
-
241
-	/**
242
-	 * Return the title for admin screens.
243
-	 *
244
-	 * @return string
245
-	 */
246
-	public function get_method_title() {
247
-		return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this );
248
-	}
249
-
250
-	/**
251
-	 * Return the description for admin screens.
252
-	 *
253
-	 * @return string
254
-	 */
255
-	public function get_method_description() {
256
-		return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this );
257
-	}
258
-
259
-	/**
260
-	 * Get the success url.
261
-	 *
262
-	 * @param WPInv_Invoice $invoice Invoice object.
263
-	 * @return string
264
-	 */
265
-	public function get_return_url( $invoice ) {
266
-
267
-		// Payment success url
268
-		$return_url = add_query_arg(
269
-			array(
270
-				'payment-confirm' => $this->id,
271
-				'invoice_key'     => $invoice->get_key(),
272
-				'utm_nooverride'  => 1,
273
-			),
274
-			wpinv_get_success_page_uri()
275
-		);
276
-
277
-		return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this );
278
-	}
279
-
280
-	/**
281
-	 * Confirms payments when rendering the success page.
282
-	 *
283
-	 * @param string $content Success page content.
284
-	 * @return string
285
-	 */
286
-	public function confirm_payment( $content ) {
287
-
288
-		// Retrieve the invoice.
289
-		$invoice_id = getpaid_get_current_invoice_id();
290
-		$invoice    = wpinv_get_invoice( $invoice_id );
291
-
292
-		// Ensure that it exists and that it is pending payment.
293
-		if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) {
294
-			return $content;
295
-		}
296
-
297
-		// Can the user view this invoice??
298
-		if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
299
-			return $content;
300
-		}
301
-
302
-		// Show payment processing indicator.
303
-		return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
304
-	}
305
-
306
-	/**
307
-	 * Processes ipns and marks payments as complete.
308
-	 *
309
-	 * @return void
310
-	 */
311
-	public function verify_ipn() {}
312
-
313
-	/**
314
-	 * Processes invoice addons.
315
-	 *
316
-	 * @param WPInv_Invoice $invoice
317
-	 * @param GetPaid_Form_Item[] $items
318
-	 * @return WPInv_Invoice
319
-	 */
320
-	public function process_addons( $invoice, $items ) {
321
-
322
-	}
323
-
324
-	/**
325
-	 * Get a link to the transaction on the 3rd party gateway site (if applicable).
326
-	 *
327
-	 * @param string $transaction_url transaction url.
328
-	 * @param WPInv_Invoice $invoice Invoice object.
329
-	 * @return string transaction URL, or empty string.
330
-	 */
331
-	public function filter_transaction_url( $transaction_url, $invoice ) {
332
-
333
-		$transaction_id  = $invoice->get_transaction_id();
334
-
335
-		if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
336
-			$transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
337
-			$replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
338
-			$transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
339
-		}
340
-
341
-		return $transaction_url;
342
-	}
343
-
344
-	/**
345
-	 * Get a link to the subscription on the 3rd party gateway site (if applicable).
346
-	 *
347
-	 * @param string $subscription_url transaction url.
348
-	 * @param WPInv_Subscription $subscription Subscription objectt.
349
-	 * @return string subscription URL, or empty string.
350
-	 */
351
-	public function generate_subscription_url( $subscription_url, $subscription ) {
352
-
353
-		$profile_id      = $subscription->get_profile_id();
354
-
355
-		if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
356
-
357
-			$subscription_url = sprintf( $this->view_subscription_url, $profile_id );
358
-			$replace          = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : '';
359
-			$subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
360
-
361
-		}
362
-
363
-		return $subscription_url;
364
-	}
365
-
366
-	/**
367
-	 * Check if the gateway is available for use.
368
-	 *
369
-	 * @return bool
370
-	 */
371
-	public function is_available() {
372
-		return ! empty( $this->enabled );
373
-	}
374
-
375
-	/**
376
-	 * Return the gateway's title.
377
-	 *
378
-	 * @return string
379
-	 */
380
-	public function get_title() {
381
-		return apply_filters( 'getpaid_gateway_title', $this->title, $this );
382
-	}
383
-
384
-	/**
385
-	 * Return the gateway's description.
386
-	 *
387
-	 * @return string
388
-	 */
389
-	public function get_description() {
390
-		return apply_filters( 'getpaid_gateway_description', $this->description, $this );
391
-	}
392
-
393
-	/**
394
-	 * Process Payment.
395
-	 *
396
-	 *
397
-	 * @param WPInv_Invoice $invoice Invoice.
398
-	 * @param array $submission_data Posted checkout fields.
399
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
400
-	 * @return void
401
-	 */
402
-	public function process_payment( $invoice, $submission_data, $submission ) {
403
-		// Process the payment then either redirect to the success page or the gateway.
404
-		do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission );
405
-	}
406
-
407
-	/**
408
-	 * Process refund.
409
-	 *
410
-	 * If the gateway declares 'refunds' support, this will allow it to refund.
411
-	 * a passed in amount.
412
-	 *
413
-	 * @param WPInv_Invoice $invoice Invoice.
414
-	 * @param  float  $amount Refund amount.
415
-	 * @param  string $reason Refund reason.
416
-	 * @return WP_Error|bool True or false based on success, or a WP_Error object.
417
-	 */
418
-	public function process_refund( $invoice, $amount = null, $reason = '' ) {
419
-		return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason );
420
-	}
421
-
422
-	/**
423
-	 * Displays the payment fields, credit cards etc.
424
-	 *
425
-	 * @param int $invoice_id 0 or invoice id.
426
-	 * @param GetPaid_Payment_Form $form Current payment form.
427
-	 */
428
-	public function payment_fields( $invoice_id, $form ) {
429
-		do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form );
430
-	}
431
-
432
-	/**
433
-	 * Filters the gateway settings.
434
-	 *
435
-	 * @param array $admin_settings
436
-	 */
437
-	public function admin_settings( $admin_settings ) {
438
-		return $admin_settings;
439
-	}
440
-
441
-	/**
442
-	 * Retrieves the value of a gateway setting.
443
-	 *
444
-	 * @param string $option
445
-	 */
446
-	public function get_option( $option, $default = false ) {
447
-		return wpinv_get_option( $this->id . '_' . $option, $default );
448
-	}
449
-
450
-	/**
451
-	 * Check if a gateway supports a given feature.
452
-	 *
453
-	 * Gateways should override this to declare support (or lack of support) for a feature.
454
-	 * For backward compatibility, gateways support 'products' by default, but nothing else.
455
-	 *
456
-	 * @param string $feature string The name of a feature to test support for.
457
-	 * @return bool True if the gateway supports the feature, false otherwise.
458
-	 * @since 1.0.19
459
-	 */
460
-	public function supports( $feature ) {
461
-		return getpaid_payment_gateway_supports( $this->id, $feature );
462
-	}
463
-
464
-	/**
465
-	 * Returns the credit card form html.
466
-	 *
467
-	 * @param bool $save whether or not to display the save button.
468
-	 */
215
+        if ( ! is_bool( $sandbox ) ) {
216
+            return $this->tokens;
217
+        }
218
+
219
+        // Filter tokens.
220
+        $args = array( 'type' => $sandbox ? 'sandbox' : 'live' );
221
+        return wp_list_filter( $this->tokens, $args );
222
+
223
+    }
224
+
225
+    /**
226
+     * Saves a token for this gateway.
227
+     *
228
+     * @since 1.0.19
229
+     */
230
+    public function save_token( $token ) {
231
+
232
+        $tokens   = $this->get_tokens();
233
+        $tokens[] = $token;
234
+
235
+        update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens );
236
+
237
+        $this->tokens = $tokens;
238
+
239
+    }
240
+
241
+    /**
242
+     * Return the title for admin screens.
243
+     *
244
+     * @return string
245
+     */
246
+    public function get_method_title() {
247
+        return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this );
248
+    }
249
+
250
+    /**
251
+     * Return the description for admin screens.
252
+     *
253
+     * @return string
254
+     */
255
+    public function get_method_description() {
256
+        return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this );
257
+    }
258
+
259
+    /**
260
+     * Get the success url.
261
+     *
262
+     * @param WPInv_Invoice $invoice Invoice object.
263
+     * @return string
264
+     */
265
+    public function get_return_url( $invoice ) {
266
+
267
+        // Payment success url
268
+        $return_url = add_query_arg(
269
+            array(
270
+                'payment-confirm' => $this->id,
271
+                'invoice_key'     => $invoice->get_key(),
272
+                'utm_nooverride'  => 1,
273
+            ),
274
+            wpinv_get_success_page_uri()
275
+        );
276
+
277
+        return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this );
278
+    }
279
+
280
+    /**
281
+     * Confirms payments when rendering the success page.
282
+     *
283
+     * @param string $content Success page content.
284
+     * @return string
285
+     */
286
+    public function confirm_payment( $content ) {
287
+
288
+        // Retrieve the invoice.
289
+        $invoice_id = getpaid_get_current_invoice_id();
290
+        $invoice    = wpinv_get_invoice( $invoice_id );
291
+
292
+        // Ensure that it exists and that it is pending payment.
293
+        if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) {
294
+            return $content;
295
+        }
296
+
297
+        // Can the user view this invoice??
298
+        if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
299
+            return $content;
300
+        }
301
+
302
+        // Show payment processing indicator.
303
+        return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
304
+    }
305
+
306
+    /**
307
+     * Processes ipns and marks payments as complete.
308
+     *
309
+     * @return void
310
+     */
311
+    public function verify_ipn() {}
312
+
313
+    /**
314
+     * Processes invoice addons.
315
+     *
316
+     * @param WPInv_Invoice $invoice
317
+     * @param GetPaid_Form_Item[] $items
318
+     * @return WPInv_Invoice
319
+     */
320
+    public function process_addons( $invoice, $items ) {
321
+
322
+    }
323
+
324
+    /**
325
+     * Get a link to the transaction on the 3rd party gateway site (if applicable).
326
+     *
327
+     * @param string $transaction_url transaction url.
328
+     * @param WPInv_Invoice $invoice Invoice object.
329
+     * @return string transaction URL, or empty string.
330
+     */
331
+    public function filter_transaction_url( $transaction_url, $invoice ) {
332
+
333
+        $transaction_id  = $invoice->get_transaction_id();
334
+
335
+        if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
336
+            $transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
337
+            $replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
338
+            $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
339
+        }
340
+
341
+        return $transaction_url;
342
+    }
343
+
344
+    /**
345
+     * Get a link to the subscription on the 3rd party gateway site (if applicable).
346
+     *
347
+     * @param string $subscription_url transaction url.
348
+     * @param WPInv_Subscription $subscription Subscription objectt.
349
+     * @return string subscription URL, or empty string.
350
+     */
351
+    public function generate_subscription_url( $subscription_url, $subscription ) {
352
+
353
+        $profile_id      = $subscription->get_profile_id();
354
+
355
+        if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
356
+
357
+            $subscription_url = sprintf( $this->view_subscription_url, $profile_id );
358
+            $replace          = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : '';
359
+            $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
360
+
361
+        }
362
+
363
+        return $subscription_url;
364
+    }
365
+
366
+    /**
367
+     * Check if the gateway is available for use.
368
+     *
369
+     * @return bool
370
+     */
371
+    public function is_available() {
372
+        return ! empty( $this->enabled );
373
+    }
374
+
375
+    /**
376
+     * Return the gateway's title.
377
+     *
378
+     * @return string
379
+     */
380
+    public function get_title() {
381
+        return apply_filters( 'getpaid_gateway_title', $this->title, $this );
382
+    }
383
+
384
+    /**
385
+     * Return the gateway's description.
386
+     *
387
+     * @return string
388
+     */
389
+    public function get_description() {
390
+        return apply_filters( 'getpaid_gateway_description', $this->description, $this );
391
+    }
392
+
393
+    /**
394
+     * Process Payment.
395
+     *
396
+     *
397
+     * @param WPInv_Invoice $invoice Invoice.
398
+     * @param array $submission_data Posted checkout fields.
399
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
400
+     * @return void
401
+     */
402
+    public function process_payment( $invoice, $submission_data, $submission ) {
403
+        // Process the payment then either redirect to the success page or the gateway.
404
+        do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission );
405
+    }
406
+
407
+    /**
408
+     * Process refund.
409
+     *
410
+     * If the gateway declares 'refunds' support, this will allow it to refund.
411
+     * a passed in amount.
412
+     *
413
+     * @param WPInv_Invoice $invoice Invoice.
414
+     * @param  float  $amount Refund amount.
415
+     * @param  string $reason Refund reason.
416
+     * @return WP_Error|bool True or false based on success, or a WP_Error object.
417
+     */
418
+    public function process_refund( $invoice, $amount = null, $reason = '' ) {
419
+        return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason );
420
+    }
421
+
422
+    /**
423
+     * Displays the payment fields, credit cards etc.
424
+     *
425
+     * @param int $invoice_id 0 or invoice id.
426
+     * @param GetPaid_Payment_Form $form Current payment form.
427
+     */
428
+    public function payment_fields( $invoice_id, $form ) {
429
+        do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form );
430
+    }
431
+
432
+    /**
433
+     * Filters the gateway settings.
434
+     *
435
+     * @param array $admin_settings
436
+     */
437
+    public function admin_settings( $admin_settings ) {
438
+        return $admin_settings;
439
+    }
440
+
441
+    /**
442
+     * Retrieves the value of a gateway setting.
443
+     *
444
+     * @param string $option
445
+     */
446
+    public function get_option( $option, $default = false ) {
447
+        return wpinv_get_option( $this->id . '_' . $option, $default );
448
+    }
449
+
450
+    /**
451
+     * Check if a gateway supports a given feature.
452
+     *
453
+     * Gateways should override this to declare support (or lack of support) for a feature.
454
+     * For backward compatibility, gateways support 'products' by default, but nothing else.
455
+     *
456
+     * @param string $feature string The name of a feature to test support for.
457
+     * @return bool True if the gateway supports the feature, false otherwise.
458
+     * @since 1.0.19
459
+     */
460
+    public function supports( $feature ) {
461
+        return getpaid_payment_gateway_supports( $this->id, $feature );
462
+    }
463
+
464
+    /**
465
+     * Returns the credit card form html.
466
+     *
467
+     * @param bool $save whether or not to display the save button.
468
+     */
469 469
     public function get_cc_form( $save = false ) {
470 470
 
471
-		ob_start();
471
+        ob_start();
472 472
 
473 473
         $id_prefix = esc_attr( uniqid( $this->id ) );
474 474
 
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
             '11' => __( 'November', 'invoicing' ),
487 487
             '12' => __( 'December', 'invoicing' ),
488 488
         );
489
-		$months = apply_filters( 'getpaid_cc_months', $months, $this );
489
+        $months = apply_filters( 'getpaid_cc_months', $months, $this );
490 490
 
491 491
         $year  = (int) current_time( 'Y' );
492 492
         $years = array();
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
             $years[ $year + $i ] = $year + $i;
496 496
         }
497 497
 
498
-		$years = apply_filters( 'getpaid_cc_years', $years, $this );
498
+        $years = apply_filters( 'getpaid_cc_years', $years, $this );
499 499
 
500 500
         ?>
501 501
             <div class="<?php echo esc_attr( $this->id ); ?>-cc-form getpaid-cc-form mt-1">
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
 
532 532
                                             <?php
533 533
                                                 foreach ( $months as $key => $month ) {
534
-												echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $month ) . '</option>';
534
+                                                echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $month ) . '</option>';
535 535
                                                 }
536 536
                                             ?>
537 537
 
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
 
545 545
                                             <?php
546 546
                                                 foreach ( $years as $key => $year ) {
547
-												echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $year ) . '</option>';
547
+                                                echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $year ) . '</option>';
548 548
                                                 }
549 549
                                             ?>
550 550
 
@@ -562,13 +562,13 @@  discard block
 block discarded – undo
562 562
                                         'name'             => $this->id . '[cc_cvv2]',
563 563
                                         'id'               => "$id_prefix-cc-cvv2",
564 564
                                         'label'            => __( 'CCV', 'invoicing' ),
565
-										'label_type'       => 'vertical',
566
-										'class'            => 'form-control-sm',
567
-										'extra_attributes' => array(
568
-											'autocomplete' => 'cc-csc',
569
-										),
565
+                                        'label_type'       => 'vertical',
566
+                                        'class'            => 'form-control-sm',
567
+                                        'extra_attributes' => array(
568
+                                            'autocomplete' => 'cc-csc',
569
+                                        ),
570 570
                                     ),
571
-									true
571
+                                    true
572 572
                                 );
573 573
                             ?>
574 574
                         </div>
@@ -577,192 +577,192 @@  discard block
 block discarded – undo
577 577
 
578 578
 					<?php
579 579
 
580
-						if ( $save ) {
581
-							$this->save_payment_method_checkbox();
582
-						}
580
+                        if ( $save ) {
581
+                            $this->save_payment_method_checkbox();
582
+                        }
583 583
 
584
-					?>
584
+                    ?>
585 585
                 </div>
586 586
 
587 587
             </div>
588 588
 		<?php
589 589
 
590
-		return ob_get_clean();
590
+        return ob_get_clean();
591
+
592
+    }
593
+
594
+    /**
595
+     * Displays a new payment method entry form.
596
+     *
597
+     * @since 1.0.19
598
+     */
599
+    public function new_payment_method_entry( $form ) {
600
+        echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses( $form, getpaid_allowed_html() ) . '</div>';
601
+    }
602
+
603
+    /**
604
+     * Grab and display our saved payment methods.
605
+     *
606
+     * @since 1.0.19
607
+     */
608
+    public function saved_payment_methods() {
609
+        echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">';
610
+
611
+        foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) {
612
+            $this->get_saved_payment_method_option_html( $token );
613
+        }
614
+
615
+        $this->get_new_payment_method_option_html();
616
+        echo '</ul>';
591 617
 
592 618
     }
593 619
 
594
-	/**
595
-	 * Displays a new payment method entry form.
596
-	 *
597
-	 * @since 1.0.19
598
-	 */
599
-	public function new_payment_method_entry( $form ) {
600
-		echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses( $form, getpaid_allowed_html() ) . '</div>';
601
-	}
602
-
603
-	/**
604
-	 * Grab and display our saved payment methods.
605
-	 *
606
-	 * @since 1.0.19
607
-	 */
608
-	public function saved_payment_methods() {
609
-		echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">';
610
-
611
-		foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) {
612
-			$this->get_saved_payment_method_option_html( $token );
613
-		}
614
-
615
-		$this->get_new_payment_method_option_html();
616
-		echo '</ul>';
617
-
618
-	}
619
-
620
-	/**
621
-	 * Gets saved payment method HTML from a token.
622
-	 *
623
-	 * @since 1.0.19
624
-	 * @param  array $token Payment Token.
625
-	 * @return string Generated payment method HTML
626
-	 */
627
-	public function get_saved_payment_method_option_html( $token ) {
628
-
629
-		printf(
630
-			'<li class="getpaid-payment-method form-group">
620
+    /**
621
+     * Gets saved payment method HTML from a token.
622
+     *
623
+     * @since 1.0.19
624
+     * @param  array $token Payment Token.
625
+     * @return string Generated payment method HTML
626
+     */
627
+    public function get_saved_payment_method_option_html( $token ) {
628
+
629
+        printf(
630
+            '<li class="getpaid-payment-method form-group">
631 631
 				<label>
632 632
 					<input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" data-currency="%5$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s />
633 633
 					<span>%3$s</span>
634 634
 				</label>
635 635
 			</li>',
636
-			esc_attr( $this->id ),
637
-			esc_attr( $token['id'] ),
638
-			esc_html( $token['name'] ),
639
-			checked( empty( $token['default'] ), false, false ),
640
-			empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] )
641
-		);
642
-
643
-	}
644
-
645
-	/**
646
-	 * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method.
647
-	 *
648
-	 * @since 1.0.19
649
-	 */
650
-	public function get_new_payment_method_option_html() {
651
-
652
-		$label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
653
-
654
-		printf(
655
-			'<li class="getpaid-new-payment-method">
636
+            esc_attr( $this->id ),
637
+            esc_attr( $token['id'] ),
638
+            esc_html( $token['name'] ),
639
+            checked( empty( $token['default'] ), false, false ),
640
+            empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] )
641
+        );
642
+
643
+    }
644
+
645
+    /**
646
+     * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method.
647
+     *
648
+     * @since 1.0.19
649
+     */
650
+    public function get_new_payment_method_option_html() {
651
+
652
+        $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
653
+
654
+        printf(
655
+            '<li class="getpaid-new-payment-method">
656 656
 				<label>
657 657
 					<input name="getpaid-%1$s-payment-method" type="radio" data-currency="none" value="new" style="width:auto;" />
658 658
 					<span>%2$s</span>
659 659
 				</label>
660 660
 			</li>',
661
-			esc_attr( $this->id ),
662
-			esc_html( $label )
663
-		);
664
-
665
-	}
666
-
667
-	/**
668
-	 * Outputs a checkbox for saving a new payment method to the database.
669
-	 *
670
-	 * @since 1.0.19
671
-	 */
672
-	public function save_payment_method_checkbox() {
673
-
674
-		aui()->input(
675
-			array(
676
-				'type'       => 'checkbox',
677
-				'name'       => esc_attr( "getpaid-$this->id-new-payment-method" ),
678
-				'id'         => esc_attr( uniqid( $this->id ) ),
679
-				'required'   => false,
680
-				'label'      => esc_html__( 'Save payment method', 'invoicing' ),
681
-				'value'      => 'true',
682
-				'checked'    => true,
683
-				'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1',
684
-			),
685
-			true
686
-		);
687
-
688
-	}
689
-
690
-	/**
691
-	 * Registers the gateway.
692
-	 *
693
-	 * @return array
694
-	 */
695
-	public function register_gateway( $gateways ) {
696
-
697
-		$gateways[ $this->id ] = array(
698
-
699
-			'admin_label'    => $this->method_title,
661
+            esc_attr( $this->id ),
662
+            esc_html( $label )
663
+        );
664
+
665
+    }
666
+
667
+    /**
668
+     * Outputs a checkbox for saving a new payment method to the database.
669
+     *
670
+     * @since 1.0.19
671
+     */
672
+    public function save_payment_method_checkbox() {
673
+
674
+        aui()->input(
675
+            array(
676
+                'type'       => 'checkbox',
677
+                'name'       => esc_attr( "getpaid-$this->id-new-payment-method" ),
678
+                'id'         => esc_attr( uniqid( $this->id ) ),
679
+                'required'   => false,
680
+                'label'      => esc_html__( 'Save payment method', 'invoicing' ),
681
+                'value'      => 'true',
682
+                'checked'    => true,
683
+                'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1',
684
+            ),
685
+            true
686
+        );
687
+
688
+    }
689
+
690
+    /**
691
+     * Registers the gateway.
692
+     *
693
+     * @return array
694
+     */
695
+    public function register_gateway( $gateways ) {
696
+
697
+        $gateways[ $this->id ] = array(
698
+
699
+            'admin_label'    => $this->method_title,
700 700
             'checkout_label' => $this->title,
701
-			'ordering'       => $this->order,
701
+            'ordering'       => $this->order,
702 702
 
703
-		);
703
+        );
704 704
 
705
-		return $gateways;
705
+        return $gateways;
706 706
 
707
-	}
707
+    }
708 708
 
709
-	/**
710
-	 * Checks whether or not this is a sandbox request.
711
-	 *
712
-	 * @param  WPInv_Invoice|null $invoice Invoice object or null.
713
-	 * @return bool
714
-	 */
715
-	public function is_sandbox( $invoice = null ) {
709
+    /**
710
+     * Checks whether or not this is a sandbox request.
711
+     *
712
+     * @param  WPInv_Invoice|null $invoice Invoice object or null.
713
+     * @return bool
714
+     */
715
+    public function is_sandbox( $invoice = null ) {
716 716
 
717
-		if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) {
718
-			return $invoice->get_mode() == 'test';
719
-		}
717
+        if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) {
718
+            return $invoice->get_mode() == 'test';
719
+        }
720 720
 
721
-		return wpinv_is_test_mode( $this->id );
721
+        return wpinv_is_test_mode( $this->id );
722 722
 
723
-	}
723
+    }
724 724
 
725
-	/**
726
-	 * Renames the checkout button
727
-	 *
728
-	 * @return string
729
-	 */
730
-	public function rename_checkout_button() {
731
-		return $this->checkout_button_text;
732
-	}
725
+    /**
726
+     * Renames the checkout button
727
+     *
728
+     * @return string
729
+     */
730
+    public function rename_checkout_button() {
731
+        return $this->checkout_button_text;
732
+    }
733 733
 
734
-	/**
735
-	 * Validate gateway currency
736
-	 *
737
-	 * @return bool
738
-	 */
739
-	public function validate_currency( $validation, $currency ) {
734
+    /**
735
+     * Validate gateway currency
736
+     *
737
+     * @return bool
738
+     */
739
+    public function validate_currency( $validation, $currency ) {
740 740
 
741
-		// Required currencies.
742
-		if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
743
-			return false;
744
-		}
741
+        // Required currencies.
742
+        if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
743
+            return false;
744
+        }
745 745
 
746
-		// Excluded currencies.
747
-		if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
748
-			return false;
749
-		}
746
+        // Excluded currencies.
747
+        if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
748
+            return false;
749
+        }
750 750
 
751
-		return $validation;
752
-	}
751
+        return $validation;
752
+    }
753 753
 
754
-	/**
755
-	 * Displays an error
756
-	 *
757
-	 */
758
-	public function show_error( $code, $message, $type ) {
754
+    /**
755
+     * Displays an error
756
+     *
757
+     */
758
+    public function show_error( $code, $message, $type ) {
759 759
 
760
-		if ( is_admin() ) {
761
-			getpaid_admin()->{"show_$type"}( $message );
762
-		}
760
+        if ( is_admin() ) {
761
+            getpaid_admin()->{"show_$type"}( $message );
762
+        }
763 763
 
764
-		wpinv_set_error( $code, $message, $type );
764
+        wpinv_set_error( $code, $message, $type );
765 765
 
766
-	}
766
+    }
767 767
 
768 768
 }
Please login to merge, or discard this patch.
Spacing   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Abstaract Payment Gateway class.
@@ -139,50 +139,50 @@  discard block
 block discarded – undo
139 139
 	public function __construct() {
140 140
 
141 141
 		// Register gateway.
142
-		add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) );
142
+		add_filter('wpinv_payment_gateways', array($this, 'register_gateway'));
143 143
 
144
-		$this->enabled = wpinv_is_gateway_active( $this->id );
144
+		$this->enabled = wpinv_is_gateway_active($this->id);
145 145
 
146 146
 		// Add support for various features.
147
-		foreach ( $this->supports as $feature ) {
148
-			add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' );
149
-			add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' );
150
-			add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' );
147
+		foreach ($this->supports as $feature) {
148
+			add_filter("wpinv_{$this->id}_support_{$feature}", '__return_true');
149
+			add_filter("getpaid_{$this->id}_support_{$feature}", '__return_true');
150
+			add_filter("getpaid_{$this->id}_supports_{$feature}", '__return_true');
151 151
 		}
152 152
 
153 153
 		// Invoice addons.
154
-		if ( $this->supports( 'addons' ) ) {
155
-			add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 );
154
+		if ($this->supports('addons')) {
155
+			add_action("getpaid_process_{$this->id}_invoice_addons", array($this, 'process_addons'), 10, 2);
156 156
 		}
157 157
 
158 158
 		// Gateway settings.
159
-		add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) );
159
+		add_filter("wpinv_gateway_settings_{$this->id}", array($this, 'admin_settings'));
160 160
 
161 161
 		// Gateway checkout fiellds.
162
-		add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 );
162
+		add_action("wpinv_{$this->id}_cc_form", array($this, 'payment_fields'), 10, 2);
163 163
 
164 164
 		// Process payment.
165
-		add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 );
165
+		add_action("getpaid_gateway_{$this->id}", array($this, 'process_payment'), 10, 3);
166 166
 
167 167
 		// Change the checkout button text.
168
-		if ( ! empty( $this->checkout_button_text ) ) {
169
-			add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) );
168
+		if (!empty($this->checkout_button_text)) {
169
+			add_filter("getpaid_gateway_{$this->id}_checkout_button_label", array($this, 'rename_checkout_button'));
170 170
 		}
171 171
 
172 172
 		// Check if a gateway is valid for a given currency.
173
-		add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 );
173
+		add_filter("getpaid_gateway_{$this->id}_is_valid_for_currency", array($this, 'validate_currency'), 10, 2);
174 174
 
175 175
 		// Generate the transaction url.
176
-		add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 );
176
+		add_filter("getpaid_gateway_{$this->id}_transaction_url", array($this, 'filter_transaction_url'), 10, 2);
177 177
 
178 178
 		// Generate the subscription url.
179
-		add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 );
179
+		add_filter('getpaid_remote_subscription_profile_url', array($this, 'generate_subscription_url'), 10, 2);
180 180
 
181 181
 		// Confirm payments.
182
-		add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 );
182
+		add_filter("wpinv_payment_confirm_{$this->id}", array($this, 'confirm_payment'), 10, 2);
183 183
 
184 184
 		// Verify IPNs.
185
-		add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) );
185
+		add_action("wpinv_verify_{$this->id}_ipn", array($this, 'verify_ipn'));
186 186
 
187 187
 	}
188 188
 
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 	 * @since 1.0.19
193 193
 	 * @return bool
194 194
 	 */
195
-	public function is( $gateway ) {
195
+	public function is($gateway) {
196 196
 		return $gateway == $this->id;
197 197
 	}
198 198
 
@@ -202,23 +202,23 @@  discard block
 block discarded – undo
202 202
 	 * @since 1.0.19
203 203
 	 * @return array
204 204
 	 */
205
-	public function get_tokens( $sandbox = null ) {
205
+	public function get_tokens($sandbox = null) {
206 206
 
207
-		if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) {
208
-			$tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true );
207
+		if (is_user_logged_in() && $this->supports('tokens') && 0 == count($this->tokens)) {
208
+			$tokens = get_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", true);
209 209
 
210
-			if ( is_array( $tokens ) ) {
210
+			if (is_array($tokens)) {
211 211
 				$this->tokens = $tokens;
212 212
 			}
213 213
 }
214 214
 
215
-		if ( ! is_bool( $sandbox ) ) {
215
+		if (!is_bool($sandbox)) {
216 216
 			return $this->tokens;
217 217
 		}
218 218
 
219 219
 		// Filter tokens.
220
-		$args = array( 'type' => $sandbox ? 'sandbox' : 'live' );
221
-		return wp_list_filter( $this->tokens, $args );
220
+		$args = array('type' => $sandbox ? 'sandbox' : 'live');
221
+		return wp_list_filter($this->tokens, $args);
222 222
 
223 223
 	}
224 224
 
@@ -227,12 +227,12 @@  discard block
 block discarded – undo
227 227
 	 *
228 228
 	 * @since 1.0.19
229 229
 	 */
230
-	public function save_token( $token ) {
230
+	public function save_token($token) {
231 231
 
232 232
 		$tokens   = $this->get_tokens();
233 233
 		$tokens[] = $token;
234 234
 
235
-		update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens );
235
+		update_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens);
236 236
 
237 237
 		$this->tokens = $tokens;
238 238
 
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 	 * @return string
245 245
 	 */
246 246
 	public function get_method_title() {
247
-		return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this );
247
+		return apply_filters('getpaid_gateway_method_title', $this->method_title, $this);
248 248
 	}
249 249
 
250 250
 	/**
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 	 * @return string
254 254
 	 */
255 255
 	public function get_method_description() {
256
-		return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this );
256
+		return apply_filters('getpaid_gateway_method_description', $this->method_description, $this);
257 257
 	}
258 258
 
259 259
 	/**
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 	 * @param WPInv_Invoice $invoice Invoice object.
263 263
 	 * @return string
264 264
 	 */
265
-	public function get_return_url( $invoice ) {
265
+	public function get_return_url($invoice) {
266 266
 
267 267
 		// Payment success url
268 268
 		$return_url = add_query_arg(
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 			wpinv_get_success_page_uri()
275 275
 		);
276 276
 
277
-		return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this );
277
+		return apply_filters('getpaid_gateway_success_url', $return_url, $invoice, $this);
278 278
 	}
279 279
 
280 280
 	/**
@@ -283,24 +283,24 @@  discard block
 block discarded – undo
283 283
 	 * @param string $content Success page content.
284 284
 	 * @return string
285 285
 	 */
286
-	public function confirm_payment( $content ) {
286
+	public function confirm_payment($content) {
287 287
 
288 288
 		// Retrieve the invoice.
289 289
 		$invoice_id = getpaid_get_current_invoice_id();
290
-		$invoice    = wpinv_get_invoice( $invoice_id );
290
+		$invoice    = wpinv_get_invoice($invoice_id);
291 291
 
292 292
 		// Ensure that it exists and that it is pending payment.
293
-		if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) {
293
+		if (empty($invoice_id) || !$invoice->needs_payment()) {
294 294
 			return $content;
295 295
 		}
296 296
 
297 297
 		// Can the user view this invoice??
298
-		if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
298
+		if (!wpinv_user_can_view_invoice($invoice)) {
299 299
 			return $content;
300 300
 		}
301 301
 
302 302
 		// Show payment processing indicator.
303
-		return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
303
+		return wpinv_get_template_html('wpinv-payment-processing.php', compact('invoice'));
304 304
 	}
305 305
 
306 306
 	/**
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 	 * @param GetPaid_Form_Item[] $items
318 318
 	 * @return WPInv_Invoice
319 319
 	 */
320
-	public function process_addons( $invoice, $items ) {
320
+	public function process_addons($invoice, $items) {
321 321
 
322 322
 	}
323 323
 
@@ -328,14 +328,14 @@  discard block
 block discarded – undo
328 328
 	 * @param WPInv_Invoice $invoice Invoice object.
329 329
 	 * @return string transaction URL, or empty string.
330 330
 	 */
331
-	public function filter_transaction_url( $transaction_url, $invoice ) {
331
+	public function filter_transaction_url($transaction_url, $invoice) {
332 332
 
333
-		$transaction_id  = $invoice->get_transaction_id();
333
+		$transaction_id = $invoice->get_transaction_id();
334 334
 
335
-		if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
336
-			$transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
337
-			$replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
338
-			$transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
335
+		if (!empty($this->view_transaction_url) && !empty($transaction_id)) {
336
+			$transaction_url = sprintf($this->view_transaction_url, $transaction_id);
337
+			$replace         = $this->is_sandbox($invoice) ? 'sandbox' : '';
338
+			$transaction_url = str_replace('{sandbox}', $replace, $transaction_url);
339 339
 		}
340 340
 
341 341
 		return $transaction_url;
@@ -348,15 +348,15 @@  discard block
 block discarded – undo
348 348
 	 * @param WPInv_Subscription $subscription Subscription objectt.
349 349
 	 * @return string subscription URL, or empty string.
350 350
 	 */
351
-	public function generate_subscription_url( $subscription_url, $subscription ) {
351
+	public function generate_subscription_url($subscription_url, $subscription) {
352 352
 
353
-		$profile_id      = $subscription->get_profile_id();
353
+		$profile_id = $subscription->get_profile_id();
354 354
 
355
-		if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
355
+		if ($this->id == $subscription->get_gateway() && !empty($this->view_subscription_url) && !empty($profile_id)) {
356 356
 
357
-			$subscription_url = sprintf( $this->view_subscription_url, $profile_id );
358
-			$replace          = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : '';
359
-			$subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
357
+			$subscription_url = sprintf($this->view_subscription_url, $profile_id);
358
+			$replace          = $this->is_sandbox($subscription->get_parent_invoice()) ? 'sandbox' : '';
359
+			$subscription_url = str_replace('{sandbox}', $replace, $subscription_url);
360 360
 
361 361
 		}
362 362
 
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
 	 * @return bool
370 370
 	 */
371 371
 	public function is_available() {
372
-		return ! empty( $this->enabled );
372
+		return !empty($this->enabled);
373 373
 	}
374 374
 
375 375
 	/**
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
 	 * @return string
379 379
 	 */
380 380
 	public function get_title() {
381
-		return apply_filters( 'getpaid_gateway_title', $this->title, $this );
381
+		return apply_filters('getpaid_gateway_title', $this->title, $this);
382 382
 	}
383 383
 
384 384
 	/**
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
 	 * @return string
388 388
 	 */
389 389
 	public function get_description() {
390
-		return apply_filters( 'getpaid_gateway_description', $this->description, $this );
390
+		return apply_filters('getpaid_gateway_description', $this->description, $this);
391 391
 	}
392 392
 
393 393
 	/**
@@ -399,9 +399,9 @@  discard block
 block discarded – undo
399 399
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
400 400
 	 * @return void
401 401
 	 */
402
-	public function process_payment( $invoice, $submission_data, $submission ) {
402
+	public function process_payment($invoice, $submission_data, $submission) {
403 403
 		// Process the payment then either redirect to the success page or the gateway.
404
-		do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission );
404
+		do_action('getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission);
405 405
 	}
406 406
 
407 407
 	/**
@@ -415,8 +415,8 @@  discard block
 block discarded – undo
415 415
 	 * @param  string $reason Refund reason.
416 416
 	 * @return WP_Error|bool True or false based on success, or a WP_Error object.
417 417
 	 */
418
-	public function process_refund( $invoice, $amount = null, $reason = '' ) {
419
-		return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason );
418
+	public function process_refund($invoice, $amount = null, $reason = '') {
419
+		return apply_filters('getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason);
420 420
 	}
421 421
 
422 422
 	/**
@@ -425,8 +425,8 @@  discard block
 block discarded – undo
425 425
 	 * @param int $invoice_id 0 or invoice id.
426 426
 	 * @param GetPaid_Payment_Form $form Current payment form.
427 427
 	 */
428
-	public function payment_fields( $invoice_id, $form ) {
429
-		do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form );
428
+	public function payment_fields($invoice_id, $form) {
429
+		do_action('getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form);
430 430
 	}
431 431
 
432 432
 	/**
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
 	 *
435 435
 	 * @param array $admin_settings
436 436
 	 */
437
-	public function admin_settings( $admin_settings ) {
437
+	public function admin_settings($admin_settings) {
438 438
 		return $admin_settings;
439 439
 	}
440 440
 
@@ -443,8 +443,8 @@  discard block
 block discarded – undo
443 443
 	 *
444 444
 	 * @param string $option
445 445
 	 */
446
-	public function get_option( $option, $default = false ) {
447
-		return wpinv_get_option( $this->id . '_' . $option, $default );
446
+	public function get_option($option, $default = false) {
447
+		return wpinv_get_option($this->id . '_' . $option, $default);
448 448
 	}
449 449
 
450 450
 	/**
@@ -457,8 +457,8 @@  discard block
 block discarded – undo
457 457
 	 * @return bool True if the gateway supports the feature, false otherwise.
458 458
 	 * @since 1.0.19
459 459
 	 */
460
-	public function supports( $feature ) {
461
-		return getpaid_payment_gateway_supports( $this->id, $feature );
460
+	public function supports($feature) {
461
+		return getpaid_payment_gateway_supports($this->id, $feature);
462 462
 	}
463 463
 
464 464
 	/**
@@ -466,39 +466,39 @@  discard block
 block discarded – undo
466 466
 	 *
467 467
 	 * @param bool $save whether or not to display the save button.
468 468
 	 */
469
-    public function get_cc_form( $save = false ) {
469
+    public function get_cc_form($save = false) {
470 470
 
471 471
 		ob_start();
472 472
 
473
-        $id_prefix = esc_attr( uniqid( $this->id ) );
473
+        $id_prefix = esc_attr(uniqid($this->id));
474 474
 
475 475
         $months = array(
476
-            '01' => __( 'January', 'invoicing' ),
477
-            '02' => __( 'February', 'invoicing' ),
478
-            '03' => __( 'March', 'invoicing' ),
479
-            '04' => __( 'April', 'invoicing' ),
480
-            '05' => __( 'May', 'invoicing' ),
481
-            '06' => __( 'June', 'invoicing' ),
482
-            '07' => __( 'July', 'invoicing' ),
483
-            '08' => __( 'August', 'invoicing' ),
484
-            '09' => __( 'September', 'invoicing' ),
485
-            '10' => __( 'October', 'invoicing' ),
486
-            '11' => __( 'November', 'invoicing' ),
487
-            '12' => __( 'December', 'invoicing' ),
476
+            '01' => __('January', 'invoicing'),
477
+            '02' => __('February', 'invoicing'),
478
+            '03' => __('March', 'invoicing'),
479
+            '04' => __('April', 'invoicing'),
480
+            '05' => __('May', 'invoicing'),
481
+            '06' => __('June', 'invoicing'),
482
+            '07' => __('July', 'invoicing'),
483
+            '08' => __('August', 'invoicing'),
484
+            '09' => __('September', 'invoicing'),
485
+            '10' => __('October', 'invoicing'),
486
+            '11' => __('November', 'invoicing'),
487
+            '12' => __('December', 'invoicing'),
488 488
         );
489
-		$months = apply_filters( 'getpaid_cc_months', $months, $this );
489
+		$months = apply_filters('getpaid_cc_months', $months, $this);
490 490
 
491
-        $year  = (int) current_time( 'Y' );
491
+        $year  = (int) current_time('Y');
492 492
         $years = array();
493 493
 
494
-        for ( $i = 0; $i <= 10; $i++ ) {
495
-            $years[ $year + $i ] = $year + $i;
494
+        for ($i = 0; $i <= 10; $i++) {
495
+            $years[$year + $i] = $year + $i;
496 496
         }
497 497
 
498
-		$years = apply_filters( 'getpaid_cc_years', $years, $this );
498
+		$years = apply_filters('getpaid_cc_years', $years, $this);
499 499
 
500 500
         ?>
501
-            <div class="<?php echo esc_attr( $this->id ); ?>-cc-form getpaid-cc-form mt-1">
501
+            <div class="<?php echo esc_attr($this->id); ?>-cc-form getpaid-cc-form mt-1">
502 502
 
503 503
 
504 504
                 <div class="getpaid-cc-card-inner">
@@ -507,14 +507,14 @@  discard block
 block discarded – undo
507 507
                         <div class="col-12">
508 508
 
509 509
 							<div class="form-group">
510
-								<label for="<?php echo esc_attr( "$id_prefix-cc-number" ); ?>"><?php esc_html_e( 'Card number', 'invoicing' ); ?></label>
510
+								<label for="<?php echo esc_attr("$id_prefix-cc-number"); ?>"><?php esc_html_e('Card number', 'invoicing'); ?></label>
511 511
 								<div class="input-group input-group-sm">
512 512
 									<div class="input-group-prepend ">
513 513
 										<span class="input-group-text">
514 514
 											<i class="fa fa-credit-card"></i>
515 515
 										</span>
516 516
 									</div>
517
-									<input type="text" name="<?php echo esc_attr( $this->id . '[cc_number]' ); ?>" id="<?php echo esc_attr( "$id_prefix-cc-number" ); ?>" class="form-control form-control-sm getpaid-format-card-number" autocomplete="cc-number">
517
+									<input type="text" name="<?php echo esc_attr($this->id . '[cc_number]'); ?>" id="<?php echo esc_attr("$id_prefix-cc-number"); ?>" class="form-control form-control-sm getpaid-format-card-number" autocomplete="cc-number">
518 518
 								</div>
519 519
 							</div>
520 520
 
@@ -522,16 +522,16 @@  discard block
 block discarded – undo
522 522
 
523 523
                         <div class="col-12">
524 524
                             <div class="form-group">
525
-                                <label><?php esc_html_e( 'Expiration', 'invoicing' ); ?></label>
525
+                                <label><?php esc_html_e('Expiration', 'invoicing'); ?></label>
526 526
                                 <div class="form-row">
527 527
 
528 528
                                     <div class="col">
529
-                                        <select class="form-control form-control-sm" autocomplete="cc-exp-month" name="<?php echo esc_attr( $this->id ); ?>[cc_expire_month]">
530
-                                            <option disabled selected="selected"><?php esc_html_e( 'MM', 'invoicing' ); ?></option>
529
+                                        <select class="form-control form-control-sm" autocomplete="cc-exp-month" name="<?php echo esc_attr($this->id); ?>[cc_expire_month]">
530
+                                            <option disabled selected="selected"><?php esc_html_e('MM', 'invoicing'); ?></option>
531 531
 
532 532
                                             <?php
533
-                                                foreach ( $months as $key => $month ) {
534
-												echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $month ) . '</option>';
533
+                                                foreach ($months as $key => $month) {
534
+												echo "<option value='" . esc_attr($key) . "'>" . esc_html($month) . '</option>';
535 535
                                                 }
536 536
                                             ?>
537 537
 
@@ -539,12 +539,12 @@  discard block
 block discarded – undo
539 539
                                     </div>
540 540
 
541 541
                                     <div class="col">
542
-                                        <select class="form-control form-control-sm" autocomplete="cc-exp-year" name="<?php echo esc_attr( $this->id ); ?>[cc_expire_year]">
543
-                                            <option disabled selected="selected"><?php esc_html_e( 'YY', 'invoicing' ); ?></option>
542
+                                        <select class="form-control form-control-sm" autocomplete="cc-exp-year" name="<?php echo esc_attr($this->id); ?>[cc_expire_year]">
543
+                                            <option disabled selected="selected"><?php esc_html_e('YY', 'invoicing'); ?></option>
544 544
 
545 545
                                             <?php
546
-                                                foreach ( $years as $key => $year ) {
547
-												echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $year ) . '</option>';
546
+                                                foreach ($years as $key => $year) {
547
+												echo "<option value='" . esc_attr($key) . "'>" . esc_html($year) . '</option>';
548 548
                                                 }
549 549
                                             ?>
550 550
 
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
                                     array(
562 562
                                         'name'             => $this->id . '[cc_cvv2]',
563 563
                                         'id'               => "$id_prefix-cc-cvv2",
564
-                                        'label'            => __( 'CCV', 'invoicing' ),
564
+                                        'label'            => __('CCV', 'invoicing'),
565 565
 										'label_type'       => 'vertical',
566 566
 										'class'            => 'form-control-sm',
567 567
 										'extra_attributes' => array(
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
 
578 578
 					<?php
579 579
 
580
-						if ( $save ) {
580
+						if ($save) {
581 581
 							$this->save_payment_method_checkbox();
582 582
 						}
583 583
 
@@ -596,8 +596,8 @@  discard block
 block discarded – undo
596 596
 	 *
597 597
 	 * @since 1.0.19
598 598
 	 */
599
-	public function new_payment_method_entry( $form ) {
600
-		echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses( $form, getpaid_allowed_html() ) . '</div>';
599
+	public function new_payment_method_entry($form) {
600
+		echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses($form, getpaid_allowed_html()) . '</div>';
601 601
 	}
602 602
 
603 603
 	/**
@@ -606,10 +606,10 @@  discard block
 block discarded – undo
606 606
 	 * @since 1.0.19
607 607
 	 */
608 608
 	public function saved_payment_methods() {
609
-		echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">';
609
+		echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr(count($this->get_tokens($this->is_sandbox()))) . '">';
610 610
 
611
-		foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) {
612
-			$this->get_saved_payment_method_option_html( $token );
611
+		foreach ($this->get_tokens($this->is_sandbox()) as $token) {
612
+			$this->get_saved_payment_method_option_html($token);
613 613
 		}
614 614
 
615 615
 		$this->get_new_payment_method_option_html();
@@ -624,7 +624,7 @@  discard block
 block discarded – undo
624 624
 	 * @param  array $token Payment Token.
625 625
 	 * @return string Generated payment method HTML
626 626
 	 */
627
-	public function get_saved_payment_method_option_html( $token ) {
627
+	public function get_saved_payment_method_option_html($token) {
628 628
 
629 629
 		printf(
630 630
 			'<li class="getpaid-payment-method form-group">
@@ -633,11 +633,11 @@  discard block
 block discarded – undo
633 633
 					<span>%3$s</span>
634 634
 				</label>
635 635
 			</li>',
636
-			esc_attr( $this->id ),
637
-			esc_attr( $token['id'] ),
638
-			esc_html( $token['name'] ),
639
-			checked( empty( $token['default'] ), false, false ),
640
-			empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] )
636
+			esc_attr($this->id),
637
+			esc_attr($token['id']),
638
+			esc_html($token['name']),
639
+			checked(empty($token['default']), false, false),
640
+			empty($token['currency']) ? 'none' : esc_attr($token['currency'])
641 641
 		);
642 642
 
643 643
 	}
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
 	 */
650 650
 	public function get_new_payment_method_option_html() {
651 651
 
652
-		$label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
652
+		$label = apply_filters('getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __('Use a new payment method', 'invoicing'), $this);
653 653
 
654 654
 		printf(
655 655
 			'<li class="getpaid-new-payment-method">
@@ -658,8 +658,8 @@  discard block
 block discarded – undo
658 658
 					<span>%2$s</span>
659 659
 				</label>
660 660
 			</li>',
661
-			esc_attr( $this->id ),
662
-			esc_html( $label )
661
+			esc_attr($this->id),
662
+			esc_html($label)
663 663
 		);
664 664
 
665 665
 	}
@@ -674,10 +674,10 @@  discard block
 block discarded – undo
674 674
 		aui()->input(
675 675
 			array(
676 676
 				'type'       => 'checkbox',
677
-				'name'       => esc_attr( "getpaid-$this->id-new-payment-method" ),
678
-				'id'         => esc_attr( uniqid( $this->id ) ),
677
+				'name'       => esc_attr("getpaid-$this->id-new-payment-method"),
678
+				'id'         => esc_attr(uniqid($this->id)),
679 679
 				'required'   => false,
680
-				'label'      => esc_html__( 'Save payment method', 'invoicing' ),
680
+				'label'      => esc_html__('Save payment method', 'invoicing'),
681 681
 				'value'      => 'true',
682 682
 				'checked'    => true,
683 683
 				'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1',
@@ -692,9 +692,9 @@  discard block
 block discarded – undo
692 692
 	 *
693 693
 	 * @return array
694 694
 	 */
695
-	public function register_gateway( $gateways ) {
695
+	public function register_gateway($gateways) {
696 696
 
697
-		$gateways[ $this->id ] = array(
697
+		$gateways[$this->id] = array(
698 698
 
699 699
 			'admin_label'    => $this->method_title,
700 700
             'checkout_label' => $this->title,
@@ -712,13 +712,13 @@  discard block
 block discarded – undo
712 712
 	 * @param  WPInv_Invoice|null $invoice Invoice object or null.
713 713
 	 * @return bool
714 714
 	 */
715
-	public function is_sandbox( $invoice = null ) {
715
+	public function is_sandbox($invoice = null) {
716 716
 
717
-		if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) {
717
+		if (!empty($invoice) && !$invoice->needs_payment()) {
718 718
 			return $invoice->get_mode() == 'test';
719 719
 		}
720 720
 
721
-		return wpinv_is_test_mode( $this->id );
721
+		return wpinv_is_test_mode($this->id);
722 722
 
723 723
 	}
724 724
 
@@ -736,15 +736,15 @@  discard block
 block discarded – undo
736 736
 	 *
737 737
 	 * @return bool
738 738
 	 */
739
-	public function validate_currency( $validation, $currency ) {
739
+	public function validate_currency($validation, $currency) {
740 740
 
741 741
 		// Required currencies.
742
-		if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
742
+		if (!empty($this->currencies) && !in_array($currency, $this->currencies)) {
743 743
 			return false;
744 744
 		}
745 745
 
746 746
 		// Excluded currencies.
747
-		if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
747
+		if (!empty($this->exclude_currencies) && in_array($currency, $this->exclude_currencies)) {
748 748
 			return false;
749 749
 		}
750 750
 
@@ -755,13 +755,13 @@  discard block
 block discarded – undo
755 755
 	 * Displays an error
756 756
 	 *
757 757
 	 */
758
-	public function show_error( $code, $message, $type ) {
758
+	public function show_error($code, $message, $type) {
759 759
 
760
-		if ( is_admin() ) {
761
-			getpaid_admin()->{"show_$type"}( $message );
760
+		if (is_admin()) {
761
+			getpaid_admin()->{"show_$type"}($message);
762 762
 		}
763 763
 
764
-		wpinv_set_error( $code, $message, $type );
764
+		wpinv_set_error($code, $message, $type);
765 765
 
766 766
 	}
767 767
 
Please login to merge, or discard this patch.
vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -7,40 +7,40 @@
 block discarded – undo
7 7
  * Bail if we are not in WP.
8 8
  */
9 9
 if ( ! defined( 'ABSPATH' ) ) {
10
-	exit;
10
+    exit;
11 11
 }
12 12
 
13 13
 /**
14 14
  * Set the version only if its the current newest while loading.
15 15
  */
16 16
 add_action('after_setup_theme', function () {
17
-	global $ayecode_ui_version,$ayecode_ui_file_key;
18
-	$this_version = "0.1.72";
19
-	if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){
20
-		$ayecode_ui_version = $this_version ;
21
-		$ayecode_ui_file_key = wp_hash( __FILE__ );
22
-	}
17
+    global $ayecode_ui_version,$ayecode_ui_file_key;
18
+    $this_version = "0.1.72";
19
+    if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){
20
+        $ayecode_ui_version = $this_version ;
21
+        $ayecode_ui_file_key = wp_hash( __FILE__ );
22
+    }
23 23
 },0);
24 24
 
25 25
 /**
26 26
  * Load this version of WP Bootstrap Settings only if the file hash is the current one.
27 27
  */
28 28
 add_action('after_setup_theme', function () {
29
-	global $ayecode_ui_file_key;
30
-	if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){
31
-		include_once( dirname( __FILE__ ) . '/includes/class-aui.php' );
32
-		include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' );
33
-	}
29
+    global $ayecode_ui_file_key;
30
+    if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){
31
+        include_once( dirname( __FILE__ ) . '/includes/class-aui.php' );
32
+        include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' );
33
+    }
34 34
 },1);
35 35
 
36 36
 /**
37 37
  * Add the function that calls the class.
38 38
  */
39 39
 if(!function_exists('aui')){
40
-	function aui(){
41
-		if(!class_exists("AUI",false)){
42
-			return false;
43
-		}
44
-		return AUI::instance();
45
-	}
40
+    function aui(){
41
+        if(!class_exists("AUI",false)){
42
+            return false;
43
+        }
44
+        return AUI::instance();
45
+    }
46 46
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -6,39 +6,39 @@
 block discarded – undo
6 6
 /**
7 7
  * Bail if we are not in WP.
8 8
  */
9
-if ( ! defined( 'ABSPATH' ) ) {
9
+if (!defined('ABSPATH')) {
10 10
 	exit;
11 11
 }
12 12
 
13 13
 /**
14 14
  * Set the version only if its the current newest while loading.
15 15
  */
16
-add_action('after_setup_theme', function () {
17
-	global $ayecode_ui_version,$ayecode_ui_file_key;
16
+add_action('after_setup_theme', function() {
17
+	global $ayecode_ui_version, $ayecode_ui_file_key;
18 18
 	$this_version = "0.1.72";
19
-	if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){
20
-		$ayecode_ui_version = $this_version ;
21
-		$ayecode_ui_file_key = wp_hash( __FILE__ );
19
+	if (empty($ayecode_ui_version) || version_compare($this_version, $ayecode_ui_version, '>')) {
20
+		$ayecode_ui_version = $this_version;
21
+		$ayecode_ui_file_key = wp_hash(__FILE__);
22 22
 	}
23 23
 },0);
24 24
 
25 25
 /**
26 26
  * Load this version of WP Bootstrap Settings only if the file hash is the current one.
27 27
  */
28
-add_action('after_setup_theme', function () {
28
+add_action('after_setup_theme', function() {
29 29
 	global $ayecode_ui_file_key;
30
-	if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){
31
-		include_once( dirname( __FILE__ ) . '/includes/class-aui.php' );
32
-		include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' );
30
+	if ($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash(__FILE__)) {
31
+		include_once(dirname(__FILE__) . '/includes/class-aui.php');
32
+		include_once(dirname(__FILE__) . '/includes/ayecode-ui-settings.php');
33 33
 	}
34 34
 },1);
35 35
 
36 36
 /**
37 37
  * Add the function that calls the class.
38 38
  */
39
-if(!function_exists('aui')){
40
-	function aui(){
41
-		if(!class_exists("AUI",false)){
39
+if (!function_exists('aui')) {
40
+	function aui() {
41
+		if (!class_exists("AUI", false)) {
42 42
 			return false;
43 43
 		}
44 44
 		return AUI::instance();
Please login to merge, or discard this patch.
ayecode/wp-ayecode-ui/includes/components/class-aui-component-input.php 3 patches
Indentation   +1216 added lines, -1216 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if ( ! defined( 'ABSPATH' ) ) {
4
-	exit; // Exit if accessed directly
4
+    exit; // Exit if accessed directly
5 5
 }
6 6
 
7 7
 /**
@@ -11,1240 +11,1240 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class AUI_Component_Input {
13 13
 
14
-	/**
15
-	 * Build the component.
16
-	 *
17
-	 * @param array $args
18
-	 *
19
-	 * @return string The rendered component.
20
-	 */
21
-	public static function input( $args = array() ) {
22
-		$defaults = array(
23
-			'type'                     => 'text',
24
-			'name'                     => '',
25
-			'class'                    => '',
26
-			'wrap_class'               => '',
27
-			'id'                       => '',
28
-			'placeholder'              => '',
29
-			'title'                    => '',
30
-			'value'                    => '',
31
-			'required'                 => false,
32
-			'size'                     => '', // sm, lg, small, large
33
-			'clear_icon'               => '', // true will show a clear icon, can't be used with input_group_right
34
-			'label'                    => '',
35
-			'label_after'              => false,
36
-			'label_class'              => '',
37
-			'label_col'                => '2',
38
-			'label_type'               => '', // top, horizontal, empty = hidden
39
-			'label_force_left'         => false, // used to force checkbox label left when using horizontal
40
-			// sets the label type, default: hidden. Options: hidden, top, horizontal, floating
41
-			'help_text'                => '',
42
-			'validation_text'          => '',
43
-			'validation_pattern'       => '',
44
-			'no_wrap'                  => false,
45
-			'input_group_right'        => '',
46
-			'input_group_left'         => '',
47
-			'input_group_right_inside' => false,
48
-			// forces the input group inside the input
49
-			'input_group_left_inside'  => false,
50
-			// forces the input group inside the input
51
-			'step'                     => '',
52
-			'switch'                   => false,
53
-			// to show checkbox as a switch
54
-			'checked'                  => false,
55
-			// set a checkbox or radio as selected
56
-			'password_toggle'          => true,
57
-			// toggle view/hide password
58
-			'element_require'          => '',
59
-			// [%element_id%] == "1"
60
-			'extra_attributes'         => array(),
61
-			// an array of extra attributes
62
-			'wrap_attributes'          => array()
63
-		);
64
-
65
-		/**
66
-		 * Parse incoming $args into an array and merge it with $defaults
67
-		 */
68
-		$args   = wp_parse_args( $args, $defaults );
69
-		$output = '';
70
-		if ( ! empty( $args['type'] ) ) {
71
-			// hidden label option needs to be empty
72
-			$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
73
-
74
-			$type = sanitize_html_class( $args['type'] );
75
-
76
-			$help_text   = '';
77
-			$label       = '';
78
-			$label_after = $args['label_after'];
79
-			$label_args  = array(
80
-				'title'      => $args['label'],
81
-				'for'        => $args['id'],
82
-				'class'      => $args['label_class'] . " ",
83
-				'label_type' => $args['label_type'],
84
-				'label_col'  => $args['label_col']
85
-			);
86
-
87
-			// floating labels need label after
88
-			if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) {
89
-				$label_after         = true;
90
-				$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
91
-			}
92
-
93
-			// size
94
-			$size = '';
95
-			if ( $args['size'] == 'lg' || $args['size'] == 'large' ) {
96
-				$size = 'lg';
97
-				$args['class'] .= ' form-control-lg';
98
-			}elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) {
99
-				$size = 'sm';
100
-				$args['class'] .= ' form-control-sm';
101
-			}
102
-
103
-			// clear function
104
-			$clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');';
105
-
106
-			// Some special sauce for files
107
-			if ( $type == 'file' ) {
108
-				$label_after = true; // if type file we need the label after
109
-				$args['class'] .= ' custom-file-input ';
110
-			} elseif ( $type == 'checkbox' ) {
111
-				$label_after = true; // if type file we need the label after
112
-				$args['class'] .= ' custom-control-input ';
113
-			} elseif ( $type == 'datepicker' || $type == 'timepicker' ) {
114
-				$type = 'text';
115
-				$args['class'] .= ' bg-initial '; // @todo not sure why we have this?
116
-
117
-				$args['extra_attributes']['data-aui-init'] = 'flatpickr';
118
-
119
-				// set a way to clear field if empty
120
-				if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) {
121
-					$args['input_group_right_inside'] = true;
122
-					$args['clear_icon'] = true;
123
-				}
124
-
125
-				// enqueue the script
126
-				$aui_settings = AyeCode_UI_Settings::instance();
127
-				$aui_settings->enqueue_flatpickr();
128
-			} elseif ( $type == 'iconpicker' ) {
129
-				$type = 'text';
130
-				//$args['class'] .= ' aui-flatpickr bg-initial ';
14
+    /**
15
+     * Build the component.
16
+     *
17
+     * @param array $args
18
+     *
19
+     * @return string The rendered component.
20
+     */
21
+    public static function input( $args = array() ) {
22
+        $defaults = array(
23
+            'type'                     => 'text',
24
+            'name'                     => '',
25
+            'class'                    => '',
26
+            'wrap_class'               => '',
27
+            'id'                       => '',
28
+            'placeholder'              => '',
29
+            'title'                    => '',
30
+            'value'                    => '',
31
+            'required'                 => false,
32
+            'size'                     => '', // sm, lg, small, large
33
+            'clear_icon'               => '', // true will show a clear icon, can't be used with input_group_right
34
+            'label'                    => '',
35
+            'label_after'              => false,
36
+            'label_class'              => '',
37
+            'label_col'                => '2',
38
+            'label_type'               => '', // top, horizontal, empty = hidden
39
+            'label_force_left'         => false, // used to force checkbox label left when using horizontal
40
+            // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
41
+            'help_text'                => '',
42
+            'validation_text'          => '',
43
+            'validation_pattern'       => '',
44
+            'no_wrap'                  => false,
45
+            'input_group_right'        => '',
46
+            'input_group_left'         => '',
47
+            'input_group_right_inside' => false,
48
+            // forces the input group inside the input
49
+            'input_group_left_inside'  => false,
50
+            // forces the input group inside the input
51
+            'step'                     => '',
52
+            'switch'                   => false,
53
+            // to show checkbox as a switch
54
+            'checked'                  => false,
55
+            // set a checkbox or radio as selected
56
+            'password_toggle'          => true,
57
+            // toggle view/hide password
58
+            'element_require'          => '',
59
+            // [%element_id%] == "1"
60
+            'extra_attributes'         => array(),
61
+            // an array of extra attributes
62
+            'wrap_attributes'          => array()
63
+        );
64
+
65
+        /**
66
+         * Parse incoming $args into an array and merge it with $defaults
67
+         */
68
+        $args   = wp_parse_args( $args, $defaults );
69
+        $output = '';
70
+        if ( ! empty( $args['type'] ) ) {
71
+            // hidden label option needs to be empty
72
+            $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
73
+
74
+            $type = sanitize_html_class( $args['type'] );
75
+
76
+            $help_text   = '';
77
+            $label       = '';
78
+            $label_after = $args['label_after'];
79
+            $label_args  = array(
80
+                'title'      => $args['label'],
81
+                'for'        => $args['id'],
82
+                'class'      => $args['label_class'] . " ",
83
+                'label_type' => $args['label_type'],
84
+                'label_col'  => $args['label_col']
85
+            );
86
+
87
+            // floating labels need label after
88
+            if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) {
89
+                $label_after         = true;
90
+                $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
91
+            }
92
+
93
+            // size
94
+            $size = '';
95
+            if ( $args['size'] == 'lg' || $args['size'] == 'large' ) {
96
+                $size = 'lg';
97
+                $args['class'] .= ' form-control-lg';
98
+            }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) {
99
+                $size = 'sm';
100
+                $args['class'] .= ' form-control-sm';
101
+            }
102
+
103
+            // clear function
104
+            $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');';
105
+
106
+            // Some special sauce for files
107
+            if ( $type == 'file' ) {
108
+                $label_after = true; // if type file we need the label after
109
+                $args['class'] .= ' custom-file-input ';
110
+            } elseif ( $type == 'checkbox' ) {
111
+                $label_after = true; // if type file we need the label after
112
+                $args['class'] .= ' custom-control-input ';
113
+            } elseif ( $type == 'datepicker' || $type == 'timepicker' ) {
114
+                $type = 'text';
115
+                $args['class'] .= ' bg-initial '; // @todo not sure why we have this?
116
+
117
+                $args['extra_attributes']['data-aui-init'] = 'flatpickr';
118
+
119
+                // set a way to clear field if empty
120
+                if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) {
121
+                    $args['input_group_right_inside'] = true;
122
+                    $args['clear_icon'] = true;
123
+                }
124
+
125
+                // enqueue the script
126
+                $aui_settings = AyeCode_UI_Settings::instance();
127
+                $aui_settings->enqueue_flatpickr();
128
+            } elseif ( $type == 'iconpicker' ) {
129
+                $type = 'text';
130
+                //$args['class'] .= ' aui-flatpickr bg-initial ';
131 131
 //				$args['class'] .= ' bg-initial ';
132 132
 
133
-				$args['extra_attributes']['data-aui-init'] = 'iconpicker';
134
-				$args['extra_attributes']['data-placement'] = 'bottomRight';
133
+                $args['extra_attributes']['data-aui-init'] = 'iconpicker';
134
+                $args['extra_attributes']['data-placement'] = 'bottomRight';
135 135
 
136
-				$args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>';
136
+                $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>';
137 137
 //				$args['input_group_right_inside'] = true;
138
-				// enqueue the script
139
-				$aui_settings = AyeCode_UI_Settings::instance();
140
-				$aui_settings->enqueue_iconpicker();
141
-			}
142
-
143
-			if ( $type == 'checkbox' && !empty($args['name'] ) && strpos($args['name'], '[') === false ) {
144
-				$output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />';
145
-			}
146
-
147
-			// allow clear icon
148
-			if ( $args['input_group_right'] === '' && $args['clear_icon'] ) {
149
-				$font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' );
150
-				$args['input_group_right_inside'] = true;
151
-				$args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none" onclick="' . $clear_function . '"><span style="font-size: '.$font_size.'rem" aria-hidden="true" class="close">&times;</span></span>';
152
-			}
153
-
154
-			// open/type
155
-			$output .= '<input type="' . $type . '" ';
156
-
157
-			// name
158
-			if ( ! empty( $args['name'] ) ) {
159
-				$output .= ' name="' . esc_attr( $args['name'] ) . '" ';
160
-			}
161
-
162
-			// id
163
-			if ( ! empty( $args['id'] ) ) {
164
-				$output .= ' id="' . sanitize_html_class( $args['id'] ) . '" ';
165
-			}
166
-
167
-			// placeholder
168
-			if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) {
169
-				$output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" ';
170
-			}
171
-
172
-			// title
173
-			if ( ! empty( $args['title'] ) ) {
174
-				$output .= ' title="' . esc_attr( $args['title'] ) . '" ';
175
-			}
176
-
177
-			// value
178
-			if ( ! empty( $args['value'] ) ) {
179
-				$output .= AUI_Component_Helper::value( $args['value'] );
180
-			}
181
-
182
-			// checked, for radio and checkboxes
183
-			if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) {
184
-				$output .= ' checked ';
185
-			}
186
-
187
-			// validation text
188
-			if ( ! empty( $args['validation_text'] ) ) {
189
-				$output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" ';
190
-				$output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
191
-			}
192
-
193
-			// validation_pattern
194
-			if ( ! empty( $args['validation_pattern'] ) ) {
195
-				$output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" ';
196
-			}
197
-
198
-			// step (for numbers)
199
-			if ( ! empty( $args['step'] ) ) {
200
-				$output .= ' step="' . $args['step'] . '" ';
201
-			}
202
-
203
-			// required
204
-			if ( ! empty( $args['required'] ) ) {
205
-				$output .= ' required ';
206
-			}
207
-
208
-			// class
209
-			$class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
210
-			$output .= ' class="form-control ' . $class . '" ';
211
-
212
-			// data-attributes
213
-			$output .= AUI_Component_Helper::data_attributes( $args );
214
-
215
-			// extra attributes
216
-			if ( ! empty( $args['extra_attributes'] ) ) {
217
-				$output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
218
-			}
219
-
220
-			// close
221
-			$output .= ' >';
222
-
223
-			// help text
224
-			if ( ! empty( $args['help_text'] ) ) {
225
-				$help_text = AUI_Component_Helper::help_text( $args['help_text'] );
226
-			}
227
-
228
-			// label
229
-			if ( ! empty( $args['label'] ) ) {
230
-				$label_base_class = '';
231
-				if ( $type == 'file' ) {
232
-					$label_base_class = ' custom-file-label';
233
-				} elseif ( $type == 'checkbox' ) {
234
-					if ( ! empty( $args['label_force_left'] ) ) {
235
-						$label_args['title'] = wp_kses_post( $args['help_text'] );
236
-						$help_text = '';
237
-						//$label_args['class'] .= ' d-inline ';
238
-						$args['wrap_class'] .= ' align-items-center ';
239
-					}else{
240
-
241
-					}
242
-
243
-					$label_base_class = ' custom-control-label';
244
-				}
245
-				$label_args['class'] .= $label_base_class;
246
-				$temp_label_args = $label_args;
247
-				if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";}
248
-				$label = self::label( $temp_label_args, $type );
249
-			}
250
-
251
-
252
-
253
-
254
-			// set help text in the correct position
255
-			if ( $label_after ) {
256
-				$output .= $label . $help_text;
257
-			}
258
-
259
-			// some input types need a separate wrap
260
-			if ( $type == 'file' ) {
261
-				$output = self::wrap( array(
262
-					'content' => $output,
263
-					'class'   => 'form-group custom-file'
264
-				) );
265
-			} elseif ( $type == 'checkbox' ) {
266
-
267
-				$label_args['title'] = $args['label'];
268
-				$label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' );
269
-				$label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>';
270
-				$switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : '';
271
-				$wrap_class = $args['switch'] ? 'custom-switch'.$switch_size_class : 'custom-checkbox';
272
-				if ( ! empty( $args['label_force_left'] ) ) {
273
-					$wrap_class .= ' d-flex align-content-center';
274
-					$label = str_replace("custom-control-label","", self::label( $label_args, 'cb' ) );
275
-				}
276
-				$output     = self::wrap( array(
277
-					'content' => $output,
278
-					'class'   => 'custom-control ' . $wrap_class
279
-				) );
280
-
281
-				if ( $args['label_type'] == 'horizontal' ) {
282
-					$input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
283
-					$output    = $label . '<div class="' . $input_col . '">' . $output . '</div>';
284
-				}
285
-			} elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) {
286
-
287
-
288
-				// allow password field to toggle view
289
-				$args['input_group_right'] = '<span class="input-group-text c-pointer px-3" 
138
+                // enqueue the script
139
+                $aui_settings = AyeCode_UI_Settings::instance();
140
+                $aui_settings->enqueue_iconpicker();
141
+            }
142
+
143
+            if ( $type == 'checkbox' && !empty($args['name'] ) && strpos($args['name'], '[') === false ) {
144
+                $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />';
145
+            }
146
+
147
+            // allow clear icon
148
+            if ( $args['input_group_right'] === '' && $args['clear_icon'] ) {
149
+                $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' );
150
+                $args['input_group_right_inside'] = true;
151
+                $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none" onclick="' . $clear_function . '"><span style="font-size: '.$font_size.'rem" aria-hidden="true" class="close">&times;</span></span>';
152
+            }
153
+
154
+            // open/type
155
+            $output .= '<input type="' . $type . '" ';
156
+
157
+            // name
158
+            if ( ! empty( $args['name'] ) ) {
159
+                $output .= ' name="' . esc_attr( $args['name'] ) . '" ';
160
+            }
161
+
162
+            // id
163
+            if ( ! empty( $args['id'] ) ) {
164
+                $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" ';
165
+            }
166
+
167
+            // placeholder
168
+            if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) {
169
+                $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" ';
170
+            }
171
+
172
+            // title
173
+            if ( ! empty( $args['title'] ) ) {
174
+                $output .= ' title="' . esc_attr( $args['title'] ) . '" ';
175
+            }
176
+
177
+            // value
178
+            if ( ! empty( $args['value'] ) ) {
179
+                $output .= AUI_Component_Helper::value( $args['value'] );
180
+            }
181
+
182
+            // checked, for radio and checkboxes
183
+            if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) {
184
+                $output .= ' checked ';
185
+            }
186
+
187
+            // validation text
188
+            if ( ! empty( $args['validation_text'] ) ) {
189
+                $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" ';
190
+                $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
191
+            }
192
+
193
+            // validation_pattern
194
+            if ( ! empty( $args['validation_pattern'] ) ) {
195
+                $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" ';
196
+            }
197
+
198
+            // step (for numbers)
199
+            if ( ! empty( $args['step'] ) ) {
200
+                $output .= ' step="' . $args['step'] . '" ';
201
+            }
202
+
203
+            // required
204
+            if ( ! empty( $args['required'] ) ) {
205
+                $output .= ' required ';
206
+            }
207
+
208
+            // class
209
+            $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
210
+            $output .= ' class="form-control ' . $class . '" ';
211
+
212
+            // data-attributes
213
+            $output .= AUI_Component_Helper::data_attributes( $args );
214
+
215
+            // extra attributes
216
+            if ( ! empty( $args['extra_attributes'] ) ) {
217
+                $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
218
+            }
219
+
220
+            // close
221
+            $output .= ' >';
222
+
223
+            // help text
224
+            if ( ! empty( $args['help_text'] ) ) {
225
+                $help_text = AUI_Component_Helper::help_text( $args['help_text'] );
226
+            }
227
+
228
+            // label
229
+            if ( ! empty( $args['label'] ) ) {
230
+                $label_base_class = '';
231
+                if ( $type == 'file' ) {
232
+                    $label_base_class = ' custom-file-label';
233
+                } elseif ( $type == 'checkbox' ) {
234
+                    if ( ! empty( $args['label_force_left'] ) ) {
235
+                        $label_args['title'] = wp_kses_post( $args['help_text'] );
236
+                        $help_text = '';
237
+                        //$label_args['class'] .= ' d-inline ';
238
+                        $args['wrap_class'] .= ' align-items-center ';
239
+                    }else{
240
+
241
+                    }
242
+
243
+                    $label_base_class = ' custom-control-label';
244
+                }
245
+                $label_args['class'] .= $label_base_class;
246
+                $temp_label_args = $label_args;
247
+                if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";}
248
+                $label = self::label( $temp_label_args, $type );
249
+            }
250
+
251
+
252
+
253
+
254
+            // set help text in the correct position
255
+            if ( $label_after ) {
256
+                $output .= $label . $help_text;
257
+            }
258
+
259
+            // some input types need a separate wrap
260
+            if ( $type == 'file' ) {
261
+                $output = self::wrap( array(
262
+                    'content' => $output,
263
+                    'class'   => 'form-group custom-file'
264
+                ) );
265
+            } elseif ( $type == 'checkbox' ) {
266
+
267
+                $label_args['title'] = $args['label'];
268
+                $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' );
269
+                $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>';
270
+                $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : '';
271
+                $wrap_class = $args['switch'] ? 'custom-switch'.$switch_size_class : 'custom-checkbox';
272
+                if ( ! empty( $args['label_force_left'] ) ) {
273
+                    $wrap_class .= ' d-flex align-content-center';
274
+                    $label = str_replace("custom-control-label","", self::label( $label_args, 'cb' ) );
275
+                }
276
+                $output     = self::wrap( array(
277
+                    'content' => $output,
278
+                    'class'   => 'custom-control ' . $wrap_class
279
+                ) );
280
+
281
+                if ( $args['label_type'] == 'horizontal' ) {
282
+                    $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
283
+                    $output    = $label . '<div class="' . $input_col . '">' . $output . '</div>';
284
+                }
285
+            } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) {
286
+
287
+
288
+                // allow password field to toggle view
289
+                $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" 
290 290
 onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\');
291 291
 var $eli = jQuery(this).parent().parent().find(\'input\');
292 292
 if($el.hasClass(\'fa-eye\'))
293 293
 {$eli.attr(\'type\',\'text\');}
294 294
 else{$eli.attr(\'type\',\'password\');}"
295 295
 ><i class="far fa-fw fa-eye-slash"></i></span>';
296
-			}
297
-
298
-			// input group wraps
299
-			if ( $args['input_group_left'] || $args['input_group_right'] ) {
300
-				$w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
301
-				$group_size = $size == 'lg' ? ' input-group-lg' : '';
302
-				$group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size;
303
-
304
-				if ( $args['input_group_left'] ) {
305
-					$output = self::wrap( array(
306
-						'content'                 => $output,
307
-						'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size,
308
-						'input_group_left'        => $args['input_group_left'],
309
-						'input_group_left_inside' => $args['input_group_left_inside']
310
-					) );
311
-				}
312
-				if ( $args['input_group_right'] ) {
313
-					$output = self::wrap( array(
314
-						'content'                  => $output,
315
-						'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size,
316
-						'input_group_right'        => $args['input_group_right'],
317
-						'input_group_right_inside' => $args['input_group_right_inside']
318
-					) );
319
-				}
320
-
321
-			}
322
-
323
-			if ( ! $label_after ) {
324
-				$output .= $help_text;
325
-			}
326
-
327
-
328
-			if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) {
329
-				$output = self::wrap( array(
330
-					'content' => $output,
331
-					'class'   => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' )
332
-				) );
333
-			}
334
-
335
-			if ( ! $label_after ) {
336
-				$output = $label . $output;
337
-			}
338
-
339
-			// wrap
340
-			if ( ! $args['no_wrap'] ) {
341
-				$form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group';
342
-				$wrap_class       = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class;
343
-				$wrap_class       = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
344
-				$output           = self::wrap( array(
345
-					'content'         => $output,
346
-					'class'           => $wrap_class,
347
-					'element_require' => $args['element_require'],
348
-					'argument_id'     => $args['id'],
349
-					'wrap_attributes' => $args['wrap_attributes'],
350
-				) );
351
-			}
352
-		}
353
-
354
-		return $output;
355
-	}
356
-
357
-	public static function label( $args = array(), $type = '' ) {
358
-		//<label for="exampleInputEmail1">Email address</label>
359
-		$defaults = array(
360
-			'title'      => 'div',
361
-			'for'        => '',
362
-			'class'      => '',
363
-			'label_type' => '', // empty = hidden, top, horizontal
364
-			'label_col'  => '',
365
-		);
366
-
367
-		/**
368
-		 * Parse incoming $args into an array and merge it with $defaults
369
-		 */
370
-		$args   = wp_parse_args( $args, $defaults );
371
-		$output = '';
372
-
373
-		if ( $args['title'] ) {
374
-
375
-			// maybe hide labels //@todo set a global option for visibility class
376
-			if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) {
377
-				$class = $args['class'];
378
-			} else {
379
-				$class = 'sr-only ' . $args['class'];
380
-			}
381
-
382
-			// maybe horizontal
383
-			if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) {
384
-				$class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label';
385
-			}
386
-
387
-			// open
388
-			$output .= '<label ';
389
-
390
-			// for
391
-			if ( ! empty( $args['for'] ) ) {
392
-				$output .= ' for="' . esc_attr( $args['for'] ) . '" ';
393
-			}
394
-
395
-			// class
396
-			$class = $class ? AUI_Component_Helper::esc_classes( $class ) : '';
397
-			$output .= ' class="' . $class . '" ';
398
-
399
-			// close
400
-			$output .= '>';
401
-
402
-
403
-			// title, don't escape fully as can contain html
404
-			if ( ! empty( $args['title'] ) ) {
405
-				$output .= wp_kses_post( $args['title'] );
406
-			}
407
-
408
-			// close wrap
409
-			$output .= '</label>';
410
-
411
-
412
-		}
413
-
414
-
415
-		return $output;
416
-	}
417
-
418
-	/**
419
-	 * Wrap some content in a HTML wrapper.
420
-	 *
421
-	 * @param array $args
422
-	 *
423
-	 * @return string
424
-	 */
425
-	public static function wrap( $args = array() ) {
426
-		$defaults = array(
427
-			'type'                     => 'div',
428
-			'class'                    => 'form-group',
429
-			'content'                  => '',
430
-			'input_group_left'         => '',
431
-			'input_group_right'        => '',
432
-			'input_group_left_inside'  => false,
433
-			'input_group_right_inside' => false,
434
-			'element_require'          => '',
435
-			'argument_id'              => '',
436
-			'wrap_attributes'          => array()
437
-		);
438
-
439
-		/**
440
-		 * Parse incoming $args into an array and merge it with $defaults
441
-		 */
442
-		$args   = wp_parse_args( $args, $defaults );
443
-		$output = '';
444
-		if ( $args['type'] ) {
445
-
446
-			// open
447
-			$output .= '<' . sanitize_html_class( $args['type'] );
448
-
449
-			// element require
450
-			if ( ! empty( $args['element_require'] ) ) {
451
-				$output .= AUI_Component_Helper::element_require( $args['element_require'] );
452
-				$args['class'] .= " aui-conditional-field";
453
-			}
454
-
455
-			// argument_id
456
-			if ( ! empty( $args['argument_id'] ) ) {
457
-				$output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"';
458
-			}
459
-
460
-			// class
461
-			$class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
462
-			$output .= ' class="' . $class . '" ';
463
-
464
-			// Attributes
465
-			if ( ! empty( $args['wrap_attributes'] ) ) {
466
-				$output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] );
467
-			}
468
-
469
-			// close wrap
470
-			$output .= ' >';
471
-
472
-
473
-			// Input group left
474
-			if ( ! empty( $args['input_group_left'] ) ) {
475
-				$position_class   = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : '';
476
-				$input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>';
477
-				$output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>';
478
-			}
479
-
480
-			// content
481
-			$output .= $args['content'];
482
-
483
-			// Input group right
484
-			if ( ! empty( $args['input_group_right'] ) ) {
485
-				$position_class    = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : '';
486
-				$input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>';
487
-				$output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>';
488
-			}
489
-
490
-
491
-			// close wrap
492
-			$output .= '</' . sanitize_html_class( $args['type'] ) . '>';
493
-
494
-
495
-		} else {
496
-			$output = $args['content'];
497
-		}
498
-
499
-		return $output;
500
-	}
501
-
502
-	/**
503
-	 * Build the component.
504
-	 *
505
-	 * @param array $args
506
-	 *
507
-	 * @return string The rendered component.
508
-	 */
509
-	public static function textarea( $args = array() ) {
510
-		$defaults = array(
511
-			'name'               => '',
512
-			'class'              => '',
513
-			'wrap_class'         => '',
514
-			'id'                 => '',
515
-			'placeholder'        => '',
516
-			'title'              => '',
517
-			'value'              => '',
518
-			'required'           => false,
519
-			'label'              => '',
520
-			'label_after'        => false,
521
-			'label_class'        => '',
522
-			'label_type'         => '',
523
-			'label_col'          => '',
524
-			// sets the label type, default: hidden. Options: hidden, top, horizontal, floating
525
-			'input_group_right'        => '',
526
-			'input_group_left'         => '',
527
-			'input_group_right_inside' => false,
528
-			'help_text'          => '',
529
-			'validation_text'    => '',
530
-			'validation_pattern' => '',
531
-			'no_wrap'            => false,
532
-			'rows'               => '',
533
-			'wysiwyg'            => false,
534
-			'allow_tags'         => false,
535
-			// Allow HTML tags
536
-			'element_require'    => '',
537
-			// [%element_id%] == "1"
538
-			'extra_attributes'   => array(),
539
-			// an array of extra attributes
540
-			'wrap_attributes'    => array(),
541
-		);
542
-
543
-		/**
544
-		 * Parse incoming $args into an array and merge it with $defaults
545
-		 */
546
-		$args   = wp_parse_args( $args, $defaults );
547
-		$output = '';
548
-
549
-		// hidden label option needs to be empty
550
-		$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
551
-
552
-		// floating labels don't work with wysiwyg so set it as top
553
-		if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) {
554
-			$args['label_type'] = 'top';
555
-		}
556
-
557
-		$label_after = $args['label_after'];
558
-
559
-		// floating labels need label after
560
-		if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) {
561
-			$label_after         = true;
562
-			$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
563
-		}
564
-
565
-		// label
566
-		if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
567
-		} elseif ( ! empty( $args['label'] ) && ! $label_after ) {
568
-			$label_args = array(
569
-				'title'      => $args['label'],
570
-				'for'        => $args['id'],
571
-				'class'      => $args['label_class'] . " ",
572
-				'label_type' => $args['label_type'],
573
-				'label_col'  => $args['label_col']
574
-			);
575
-			$output .= self::label( $label_args );
576
-		}
577
-
578
-		// maybe horizontal label
579
-		if ( $args['label_type'] == 'horizontal' ) {
580
-			$input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
581
-			$output .= '<div class="' . $input_col . '">';
582
-		}
583
-
584
-		if ( ! empty( $args['wysiwyg'] ) ) {
585
-			ob_start();
586
-			$content   = $args['value'];
587
-			$editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor';
588
-			$settings  = array(
589
-				'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4,
590
-				'quicktags'     => false,
591
-				'media_buttons' => false,
592
-				'editor_class'  => 'form-control',
593
-				'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ),
594
-				'teeny'         => true,
595
-			);
596
-
597
-			// maybe set settings if array
598
-			if ( is_array( $args['wysiwyg'] ) ) {
599
-				$settings = wp_parse_args( $args['wysiwyg'], $settings );
600
-			}
601
-
602
-			wp_editor( $content, $editor_id, $settings );
603
-			$output .= ob_get_clean();
604
-		} else {
605
-
606
-			// open
607
-			$output .= '<textarea ';
608
-
609
-			// name
610
-			if ( ! empty( $args['name'] ) ) {
611
-				$output .= ' name="' . esc_attr( $args['name'] ) . '" ';
612
-			}
613
-
614
-			// id
615
-			if ( ! empty( $args['id'] ) ) {
616
-				$output .= ' id="' . sanitize_html_class( $args['id'] ) . '" ';
617
-			}
618
-
619
-			// placeholder
620
-			if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) {
621
-				$output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" ';
622
-			}
623
-
624
-			// title
625
-			if ( ! empty( $args['title'] ) ) {
626
-				$output .= ' title="' . esc_attr( $args['title'] ) . '" ';
627
-			}
628
-
629
-			// validation text
630
-			if ( ! empty( $args['validation_text'] ) ) {
631
-				$output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" ';
632
-				$output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
633
-			}
634
-
635
-			// validation_pattern
636
-			if ( ! empty( $args['validation_pattern'] ) ) {
637
-				$output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" ';
638
-			}
639
-
640
-			// required
641
-			if ( ! empty( $args['required'] ) ) {
642
-				$output .= ' required ';
643
-			}
644
-
645
-			// rows
646
-			if ( ! empty( $args['rows'] ) ) {
647
-				$output .= ' rows="' . absint( $args['rows'] ) . '" ';
648
-			}
649
-
650
-
651
-			// class
652
-			$class = ! empty( $args['class'] ) ? $args['class'] : '';
653
-			$output .= ' class="form-control ' . $class . '" ';
654
-
655
-			// extra attributes
656
-			if ( ! empty( $args['extra_attributes'] ) ) {
657
-				$output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
658
-			}
659
-
660
-			// close tag
661
-			$output .= ' >';
662
-
663
-			// value
664
-			if ( ! empty( $args['value'] ) ) {
665
-				if ( ! empty( $args['allow_tags'] ) ) {
666
-					$output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML.
667
-				} else {
668
-					$output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] );
669
-				}
670
-			}
671
-
672
-			// closing tag
673
-			$output .= '</textarea>';
674
-
675
-
676
-			// input group wraps
677
-			if ( $args['input_group_left'] || $args['input_group_right'] ) {
678
-				$w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
679
-				if ( $args['input_group_left'] ) {
680
-					$output = self::wrap( array(
681
-						'content'                 => $output,
682
-						'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
683
-						'input_group_left'        => $args['input_group_left'],
684
-						'input_group_left_inside' => $args['input_group_left_inside']
685
-					) );
686
-				}
687
-				if ( $args['input_group_right'] ) {
688
-					$output = self::wrap( array(
689
-						'content'                  => $output,
690
-						'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
691
-						'input_group_right'        => $args['input_group_right'],
692
-						'input_group_right_inside' => $args['input_group_right_inside']
693
-					) );
694
-				}
695
-
696
-			}
697
-
698
-
699
-		}
700
-
701
-		if ( ! empty( $args['label'] ) && $label_after ) {
702
-			$label_args = array(
703
-				'title'      => $args['label'],
704
-				'for'        => $args['id'],
705
-				'class'      => $args['label_class'] . " ",
706
-				'label_type' => $args['label_type'],
707
-				'label_col'  => $args['label_col']
708
-			);
709
-			$output .= self::label( $label_args );
710
-		}
711
-
712
-		// help text
713
-		if ( ! empty( $args['help_text'] ) ) {
714
-			$output .= AUI_Component_Helper::help_text( $args['help_text'] );
715
-		}
716
-
717
-		// maybe horizontal label
718
-		if ( $args['label_type'] == 'horizontal' ) {
719
-			$output .= '</div>';
720
-		}
721
-
722
-
723
-		// wrap
724
-		if ( ! $args['no_wrap'] ) {
725
-			$form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : 'form-group';
726
-			$wrap_class       = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class;
727
-			$wrap_class       = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
728
-			$output           = self::wrap( array(
729
-				'content'         => $output,
730
-				'class'           => $wrap_class,
731
-				'element_require' => $args['element_require'],
732
-				'argument_id'     => $args['id'],
733
-				'wrap_attributes' => $args['wrap_attributes'],
734
-			) );
735
-		}
736
-
737
-
738
-		return $output;
739
-	}
740
-
741
-	/**
742
-	 * Build the component.
743
-	 *
744
-	 * @param array $args
745
-	 *
746
-	 * @return string The rendered component.
747
-	 */
748
-	public static function select( $args = array() ) {
749
-		$defaults = array(
750
-			'class'            => '',
751
-			'wrap_class'       => '',
752
-			'id'               => '',
753
-			'title'            => '',
754
-			'value'            => '',
755
-			// can be an array or a string
756
-			'required'         => false,
757
-			'label'            => '',
758
-			'label_after'      => false,
759
-			'label_type'       => '',
760
-			'label_col'        => '',
761
-			// sets the label type, default: hidden. Options: hidden, top, horizontal, floating
762
-			'label_class'      => '',
763
-			'help_text'        => '',
764
-			'placeholder'      => '',
765
-			'options'          => array(),
766
-			// array or string
767
-			'icon'             => '',
768
-			'multiple'         => false,
769
-			'select2'          => false,
770
-			'no_wrap'          => false,
771
-			'input_group_right' => '',
772
-			'input_group_left' => '',
773
-			'input_group_right_inside' => false, // forces the input group inside the input
774
-			'input_group_left_inside' => false, // forces the input group inside the input
775
-			'element_require'  => '',
776
-			// [%element_id%] == "1"
777
-			'extra_attributes' => array(),
778
-			// an array of extra attributes
779
-			'wrap_attributes'  => array(),
780
-		);
781
-
782
-		/**
783
-		 * Parse incoming $args into an array and merge it with $defaults
784
-		 */
785
-		$args   = wp_parse_args( $args, $defaults );
786
-		$output = '';
787
-
788
-		// for now lets hide floating labels
789
-		if ( $args['label_type'] == 'floating' ) {
790
-			$args['label_type'] = 'hidden';
791
-		}
792
-
793
-		// hidden label option needs to be empty
794
-		$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
795
-
796
-
797
-		$label_after = $args['label_after'];
798
-
799
-		// floating labels need label after
800
-		if ( $args['label_type'] == 'floating' ) {
801
-			$label_after         = true;
802
-			$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
803
-		}
804
-
805
-		// Maybe setup select2
806
-		$is_select2 = false;
807
-		if ( ! empty( $args['select2'] ) ) {
808
-			$args['class'] .= ' aui-select2';
809
-			$is_select2 = true;
810
-		} elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) {
811
-			$is_select2 = true;
812
-		}
813
-
814
-		// select2 tags
815
-		if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason
816
-			$args['data-tags']             = 'true';
817
-			$args['data-token-separators'] = "[',']";
818
-			$args['multiple']              = true;
819
-		}
820
-
821
-		// select2 placeholder
822
-		if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) {
823
-			$args['data-placeholder'] = esc_attr( $args['placeholder'] );
824
-			$args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true;
825
-		}
826
-
827
-
828
-
829
-		// maybe horizontal label
296
+            }
297
+
298
+            // input group wraps
299
+            if ( $args['input_group_left'] || $args['input_group_right'] ) {
300
+                $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
301
+                $group_size = $size == 'lg' ? ' input-group-lg' : '';
302
+                $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size;
303
+
304
+                if ( $args['input_group_left'] ) {
305
+                    $output = self::wrap( array(
306
+                        'content'                 => $output,
307
+                        'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size,
308
+                        'input_group_left'        => $args['input_group_left'],
309
+                        'input_group_left_inside' => $args['input_group_left_inside']
310
+                    ) );
311
+                }
312
+                if ( $args['input_group_right'] ) {
313
+                    $output = self::wrap( array(
314
+                        'content'                  => $output,
315
+                        'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size,
316
+                        'input_group_right'        => $args['input_group_right'],
317
+                        'input_group_right_inside' => $args['input_group_right_inside']
318
+                    ) );
319
+                }
320
+
321
+            }
322
+
323
+            if ( ! $label_after ) {
324
+                $output .= $help_text;
325
+            }
326
+
327
+
328
+            if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) {
329
+                $output = self::wrap( array(
330
+                    'content' => $output,
331
+                    'class'   => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' )
332
+                ) );
333
+            }
334
+
335
+            if ( ! $label_after ) {
336
+                $output = $label . $output;
337
+            }
338
+
339
+            // wrap
340
+            if ( ! $args['no_wrap'] ) {
341
+                $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group';
342
+                $wrap_class       = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class;
343
+                $wrap_class       = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
344
+                $output           = self::wrap( array(
345
+                    'content'         => $output,
346
+                    'class'           => $wrap_class,
347
+                    'element_require' => $args['element_require'],
348
+                    'argument_id'     => $args['id'],
349
+                    'wrap_attributes' => $args['wrap_attributes'],
350
+                ) );
351
+            }
352
+        }
353
+
354
+        return $output;
355
+    }
356
+
357
+    public static function label( $args = array(), $type = '' ) {
358
+        //<label for="exampleInputEmail1">Email address</label>
359
+        $defaults = array(
360
+            'title'      => 'div',
361
+            'for'        => '',
362
+            'class'      => '',
363
+            'label_type' => '', // empty = hidden, top, horizontal
364
+            'label_col'  => '',
365
+        );
366
+
367
+        /**
368
+         * Parse incoming $args into an array and merge it with $defaults
369
+         */
370
+        $args   = wp_parse_args( $args, $defaults );
371
+        $output = '';
372
+
373
+        if ( $args['title'] ) {
374
+
375
+            // maybe hide labels //@todo set a global option for visibility class
376
+            if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) {
377
+                $class = $args['class'];
378
+            } else {
379
+                $class = 'sr-only ' . $args['class'];
380
+            }
381
+
382
+            // maybe horizontal
383
+            if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) {
384
+                $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label';
385
+            }
386
+
387
+            // open
388
+            $output .= '<label ';
389
+
390
+            // for
391
+            if ( ! empty( $args['for'] ) ) {
392
+                $output .= ' for="' . esc_attr( $args['for'] ) . '" ';
393
+            }
394
+
395
+            // class
396
+            $class = $class ? AUI_Component_Helper::esc_classes( $class ) : '';
397
+            $output .= ' class="' . $class . '" ';
398
+
399
+            // close
400
+            $output .= '>';
401
+
402
+
403
+            // title, don't escape fully as can contain html
404
+            if ( ! empty( $args['title'] ) ) {
405
+                $output .= wp_kses_post( $args['title'] );
406
+            }
407
+
408
+            // close wrap
409
+            $output .= '</label>';
410
+
411
+
412
+        }
413
+
414
+
415
+        return $output;
416
+    }
417
+
418
+    /**
419
+     * Wrap some content in a HTML wrapper.
420
+     *
421
+     * @param array $args
422
+     *
423
+     * @return string
424
+     */
425
+    public static function wrap( $args = array() ) {
426
+        $defaults = array(
427
+            'type'                     => 'div',
428
+            'class'                    => 'form-group',
429
+            'content'                  => '',
430
+            'input_group_left'         => '',
431
+            'input_group_right'        => '',
432
+            'input_group_left_inside'  => false,
433
+            'input_group_right_inside' => false,
434
+            'element_require'          => '',
435
+            'argument_id'              => '',
436
+            'wrap_attributes'          => array()
437
+        );
438
+
439
+        /**
440
+         * Parse incoming $args into an array and merge it with $defaults
441
+         */
442
+        $args   = wp_parse_args( $args, $defaults );
443
+        $output = '';
444
+        if ( $args['type'] ) {
445
+
446
+            // open
447
+            $output .= '<' . sanitize_html_class( $args['type'] );
448
+
449
+            // element require
450
+            if ( ! empty( $args['element_require'] ) ) {
451
+                $output .= AUI_Component_Helper::element_require( $args['element_require'] );
452
+                $args['class'] .= " aui-conditional-field";
453
+            }
454
+
455
+            // argument_id
456
+            if ( ! empty( $args['argument_id'] ) ) {
457
+                $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"';
458
+            }
459
+
460
+            // class
461
+            $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
462
+            $output .= ' class="' . $class . '" ';
463
+
464
+            // Attributes
465
+            if ( ! empty( $args['wrap_attributes'] ) ) {
466
+                $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] );
467
+            }
468
+
469
+            // close wrap
470
+            $output .= ' >';
471
+
472
+
473
+            // Input group left
474
+            if ( ! empty( $args['input_group_left'] ) ) {
475
+                $position_class   = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : '';
476
+                $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>';
477
+                $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>';
478
+            }
479
+
480
+            // content
481
+            $output .= $args['content'];
482
+
483
+            // Input group right
484
+            if ( ! empty( $args['input_group_right'] ) ) {
485
+                $position_class    = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : '';
486
+                $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>';
487
+                $output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>';
488
+            }
489
+
490
+
491
+            // close wrap
492
+            $output .= '</' . sanitize_html_class( $args['type'] ) . '>';
493
+
494
+
495
+        } else {
496
+            $output = $args['content'];
497
+        }
498
+
499
+        return $output;
500
+    }
501
+
502
+    /**
503
+     * Build the component.
504
+     *
505
+     * @param array $args
506
+     *
507
+     * @return string The rendered component.
508
+     */
509
+    public static function textarea( $args = array() ) {
510
+        $defaults = array(
511
+            'name'               => '',
512
+            'class'              => '',
513
+            'wrap_class'         => '',
514
+            'id'                 => '',
515
+            'placeholder'        => '',
516
+            'title'              => '',
517
+            'value'              => '',
518
+            'required'           => false,
519
+            'label'              => '',
520
+            'label_after'        => false,
521
+            'label_class'        => '',
522
+            'label_type'         => '',
523
+            'label_col'          => '',
524
+            // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
525
+            'input_group_right'        => '',
526
+            'input_group_left'         => '',
527
+            'input_group_right_inside' => false,
528
+            'help_text'          => '',
529
+            'validation_text'    => '',
530
+            'validation_pattern' => '',
531
+            'no_wrap'            => false,
532
+            'rows'               => '',
533
+            'wysiwyg'            => false,
534
+            'allow_tags'         => false,
535
+            // Allow HTML tags
536
+            'element_require'    => '',
537
+            // [%element_id%] == "1"
538
+            'extra_attributes'   => array(),
539
+            // an array of extra attributes
540
+            'wrap_attributes'    => array(),
541
+        );
542
+
543
+        /**
544
+         * Parse incoming $args into an array and merge it with $defaults
545
+         */
546
+        $args   = wp_parse_args( $args, $defaults );
547
+        $output = '';
548
+
549
+        // hidden label option needs to be empty
550
+        $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
551
+
552
+        // floating labels don't work with wysiwyg so set it as top
553
+        if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) {
554
+            $args['label_type'] = 'top';
555
+        }
556
+
557
+        $label_after = $args['label_after'];
558
+
559
+        // floating labels need label after
560
+        if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) {
561
+            $label_after         = true;
562
+            $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
563
+        }
564
+
565
+        // label
566
+        if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
567
+        } elseif ( ! empty( $args['label'] ) && ! $label_after ) {
568
+            $label_args = array(
569
+                'title'      => $args['label'],
570
+                'for'        => $args['id'],
571
+                'class'      => $args['label_class'] . " ",
572
+                'label_type' => $args['label_type'],
573
+                'label_col'  => $args['label_col']
574
+            );
575
+            $output .= self::label( $label_args );
576
+        }
577
+
578
+        // maybe horizontal label
579
+        if ( $args['label_type'] == 'horizontal' ) {
580
+            $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
581
+            $output .= '<div class="' . $input_col . '">';
582
+        }
583
+
584
+        if ( ! empty( $args['wysiwyg'] ) ) {
585
+            ob_start();
586
+            $content   = $args['value'];
587
+            $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor';
588
+            $settings  = array(
589
+                'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4,
590
+                'quicktags'     => false,
591
+                'media_buttons' => false,
592
+                'editor_class'  => 'form-control',
593
+                'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ),
594
+                'teeny'         => true,
595
+            );
596
+
597
+            // maybe set settings if array
598
+            if ( is_array( $args['wysiwyg'] ) ) {
599
+                $settings = wp_parse_args( $args['wysiwyg'], $settings );
600
+            }
601
+
602
+            wp_editor( $content, $editor_id, $settings );
603
+            $output .= ob_get_clean();
604
+        } else {
605
+
606
+            // open
607
+            $output .= '<textarea ';
608
+
609
+            // name
610
+            if ( ! empty( $args['name'] ) ) {
611
+                $output .= ' name="' . esc_attr( $args['name'] ) . '" ';
612
+            }
613
+
614
+            // id
615
+            if ( ! empty( $args['id'] ) ) {
616
+                $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" ';
617
+            }
618
+
619
+            // placeholder
620
+            if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) {
621
+                $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" ';
622
+            }
623
+
624
+            // title
625
+            if ( ! empty( $args['title'] ) ) {
626
+                $output .= ' title="' . esc_attr( $args['title'] ) . '" ';
627
+            }
628
+
629
+            // validation text
630
+            if ( ! empty( $args['validation_text'] ) ) {
631
+                $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" ';
632
+                $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
633
+            }
634
+
635
+            // validation_pattern
636
+            if ( ! empty( $args['validation_pattern'] ) ) {
637
+                $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" ';
638
+            }
639
+
640
+            // required
641
+            if ( ! empty( $args['required'] ) ) {
642
+                $output .= ' required ';
643
+            }
644
+
645
+            // rows
646
+            if ( ! empty( $args['rows'] ) ) {
647
+                $output .= ' rows="' . absint( $args['rows'] ) . '" ';
648
+            }
649
+
650
+
651
+            // class
652
+            $class = ! empty( $args['class'] ) ? $args['class'] : '';
653
+            $output .= ' class="form-control ' . $class . '" ';
654
+
655
+            // extra attributes
656
+            if ( ! empty( $args['extra_attributes'] ) ) {
657
+                $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
658
+            }
659
+
660
+            // close tag
661
+            $output .= ' >';
662
+
663
+            // value
664
+            if ( ! empty( $args['value'] ) ) {
665
+                if ( ! empty( $args['allow_tags'] ) ) {
666
+                    $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML.
667
+                } else {
668
+                    $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] );
669
+                }
670
+            }
671
+
672
+            // closing tag
673
+            $output .= '</textarea>';
674
+
675
+
676
+            // input group wraps
677
+            if ( $args['input_group_left'] || $args['input_group_right'] ) {
678
+                $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
679
+                if ( $args['input_group_left'] ) {
680
+                    $output = self::wrap( array(
681
+                        'content'                 => $output,
682
+                        'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
683
+                        'input_group_left'        => $args['input_group_left'],
684
+                        'input_group_left_inside' => $args['input_group_left_inside']
685
+                    ) );
686
+                }
687
+                if ( $args['input_group_right'] ) {
688
+                    $output = self::wrap( array(
689
+                        'content'                  => $output,
690
+                        'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
691
+                        'input_group_right'        => $args['input_group_right'],
692
+                        'input_group_right_inside' => $args['input_group_right_inside']
693
+                    ) );
694
+                }
695
+
696
+            }
697
+
698
+
699
+        }
700
+
701
+        if ( ! empty( $args['label'] ) && $label_after ) {
702
+            $label_args = array(
703
+                'title'      => $args['label'],
704
+                'for'        => $args['id'],
705
+                'class'      => $args['label_class'] . " ",
706
+                'label_type' => $args['label_type'],
707
+                'label_col'  => $args['label_col']
708
+            );
709
+            $output .= self::label( $label_args );
710
+        }
711
+
712
+        // help text
713
+        if ( ! empty( $args['help_text'] ) ) {
714
+            $output .= AUI_Component_Helper::help_text( $args['help_text'] );
715
+        }
716
+
717
+        // maybe horizontal label
718
+        if ( $args['label_type'] == 'horizontal' ) {
719
+            $output .= '</div>';
720
+        }
721
+
722
+
723
+        // wrap
724
+        if ( ! $args['no_wrap'] ) {
725
+            $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : 'form-group';
726
+            $wrap_class       = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class;
727
+            $wrap_class       = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
728
+            $output           = self::wrap( array(
729
+                'content'         => $output,
730
+                'class'           => $wrap_class,
731
+                'element_require' => $args['element_require'],
732
+                'argument_id'     => $args['id'],
733
+                'wrap_attributes' => $args['wrap_attributes'],
734
+            ) );
735
+        }
736
+
737
+
738
+        return $output;
739
+    }
740
+
741
+    /**
742
+     * Build the component.
743
+     *
744
+     * @param array $args
745
+     *
746
+     * @return string The rendered component.
747
+     */
748
+    public static function select( $args = array() ) {
749
+        $defaults = array(
750
+            'class'            => '',
751
+            'wrap_class'       => '',
752
+            'id'               => '',
753
+            'title'            => '',
754
+            'value'            => '',
755
+            // can be an array or a string
756
+            'required'         => false,
757
+            'label'            => '',
758
+            'label_after'      => false,
759
+            'label_type'       => '',
760
+            'label_col'        => '',
761
+            // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
762
+            'label_class'      => '',
763
+            'help_text'        => '',
764
+            'placeholder'      => '',
765
+            'options'          => array(),
766
+            // array or string
767
+            'icon'             => '',
768
+            'multiple'         => false,
769
+            'select2'          => false,
770
+            'no_wrap'          => false,
771
+            'input_group_right' => '',
772
+            'input_group_left' => '',
773
+            'input_group_right_inside' => false, // forces the input group inside the input
774
+            'input_group_left_inside' => false, // forces the input group inside the input
775
+            'element_require'  => '',
776
+            // [%element_id%] == "1"
777
+            'extra_attributes' => array(),
778
+            // an array of extra attributes
779
+            'wrap_attributes'  => array(),
780
+        );
781
+
782
+        /**
783
+         * Parse incoming $args into an array and merge it with $defaults
784
+         */
785
+        $args   = wp_parse_args( $args, $defaults );
786
+        $output = '';
787
+
788
+        // for now lets hide floating labels
789
+        if ( $args['label_type'] == 'floating' ) {
790
+            $args['label_type'] = 'hidden';
791
+        }
792
+
793
+        // hidden label option needs to be empty
794
+        $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
795
+
796
+
797
+        $label_after = $args['label_after'];
798
+
799
+        // floating labels need label after
800
+        if ( $args['label_type'] == 'floating' ) {
801
+            $label_after         = true;
802
+            $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
803
+        }
804
+
805
+        // Maybe setup select2
806
+        $is_select2 = false;
807
+        if ( ! empty( $args['select2'] ) ) {
808
+            $args['class'] .= ' aui-select2';
809
+            $is_select2 = true;
810
+        } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) {
811
+            $is_select2 = true;
812
+        }
813
+
814
+        // select2 tags
815
+        if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason
816
+            $args['data-tags']             = 'true';
817
+            $args['data-token-separators'] = "[',']";
818
+            $args['multiple']              = true;
819
+        }
820
+
821
+        // select2 placeholder
822
+        if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) {
823
+            $args['data-placeholder'] = esc_attr( $args['placeholder'] );
824
+            $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true;
825
+        }
826
+
827
+
828
+
829
+        // maybe horizontal label
830 830
 //		if ( $args['label_type'] == 'horizontal' ) {
831 831
 //			$input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
832 832
 //			$output .= '<div class="' . $input_col . '">';
833 833
 //		}
834 834
 
835
-		// Set hidden input to save empty value for multiselect.
836
-		if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) {
837
-			$output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value=""/>';
838
-		}
839
-
840
-		// open/type
841
-		$output .= '<select ';
842
-
843
-		// style
844
-		if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) {
845
-			$output .= " style='width:100%;' ";
846
-		}
847
-
848
-		// element require
849
-		if ( ! empty( $args['element_require'] ) ) {
850
-			$output .= AUI_Component_Helper::element_require( $args['element_require'] );
851
-			$args['class'] .= " aui-conditional-field";
852
-		}
853
-
854
-		// class
855
-		$class = ! empty( $args['class'] ) ? $args['class'] : '';
856
-		$output .= AUI_Component_Helper::class_attr( 'custom-select ' . $class );
857
-
858
-		// name
859
-		if ( ! empty( $args['name'] ) ) {
860
-			$output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] );
861
-		}
862
-
863
-		// id
864
-		if ( ! empty( $args['id'] ) ) {
865
-			$output .= AUI_Component_Helper::id( $args['id'] );
866
-		}
867
-
868
-		// title
869
-		if ( ! empty( $args['title'] ) ) {
870
-			$output .= AUI_Component_Helper::title( $args['title'] );
871
-		}
872
-
873
-		// data-attributes
874
-		$output .= AUI_Component_Helper::data_attributes( $args );
875
-
876
-		// aria-attributes
877
-		$output .= AUI_Component_Helper::aria_attributes( $args );
878
-
879
-		// extra attributes
880
-		if ( ! empty( $args['extra_attributes'] ) ) {
881
-			$output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
882
-		}
883
-
884
-		// required
885
-		if ( ! empty( $args['required'] ) ) {
886
-			$output .= ' required ';
887
-		}
888
-
889
-		// multiple
890
-		if ( ! empty( $args['multiple'] ) ) {
891
-			$output .= ' multiple ';
892
-		}
893
-
894
-		// close opening tag
895
-		$output .= ' >';
896
-
897
-		// placeholder
898
-		if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) {
899
-			$output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>';
900
-		} elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) {
901
-			$output .= "<option></option>"; // select2 needs an empty select to fill the placeholder
902
-		}
903
-
904
-		// Options
905
-		if ( ! empty( $args['options'] ) ) {
906
-
907
-			if ( ! is_array( $args['options'] ) ) {
908
-				$output .= $args['options']; // not the preferred way but an option
909
-			} else {
910
-				foreach ( $args['options'] as $val => $name ) {
911
-					$selected = '';
912
-					if ( is_array( $name ) ) {
913
-						if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) {
914
-							$option_label = isset( $name['label'] ) ? $name['label'] : '';
915
-
916
-							$output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>';
917
-						} else {
918
-							$option_label = isset( $name['label'] ) ? $name['label'] : '';
919
-							$option_value = isset( $name['value'] ) ? $name['value'] : '';
920
-							$extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : '';
921
-							if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) {
922
-								$selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : "";
923
-							} elseif ( ! empty( $args['value'] ) ) {
924
-								$selected = selected( $option_value, stripslashes_deep( $args['value'] ), false );
925
-							} elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) {
926
-								$selected = selected( $option_value, $args['value'], false );
927
-							}
928
-
929
-							$output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>';
930
-						}
931
-					} else {
932
-						if ( ! empty( $args['value'] ) ) {
933
-							if ( is_array( $args['value'] ) ) {
934
-								$selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : '';
935
-							} elseif ( ! empty( $args['value'] ) ) {
936
-								$selected = selected( $args['value'], $val, false );
937
-							}
938
-						} elseif ( $args['value'] === $val ) {
939
-							$selected = selected( $args['value'], $val, false );
940
-						}
941
-						$output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>';
942
-					}
943
-				}
944
-			}
945
-
946
-		}
947
-
948
-		// closing tag
949
-		$output .= '</select>';
950
-
951
-		$label = '';
952
-		$help_text = '';
953
-		// label
954
-		if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
955
-		} elseif ( ! empty( $args['label'] ) && ! $label_after ) {
956
-			$label_args = array(
957
-				'title'      => $args['label'],
958
-				'for'        => $args['id'],
959
-				'class'      => $args['label_class'] . " ",
960
-				'label_type' => $args['label_type'],
961
-				'label_col'  => $args['label_col']
962
-			);
963
-			$label = self::label( $label_args );
964
-		}
965
-
966
-		// help text
967
-		if ( ! empty( $args['help_text'] ) ) {
968
-			$help_text = AUI_Component_Helper::help_text( $args['help_text'] );
969
-		}
970
-
971
-		// input group wraps
972
-		if ( $args['input_group_left'] || $args['input_group_right'] ) {
973
-			$w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
974
-			if ( $args['input_group_left'] ) {
975
-				$output = self::wrap( array(
976
-					'content'                 => $output,
977
-					'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
978
-					'input_group_left'        => $args['input_group_left'],
979
-					'input_group_left_inside' => $args['input_group_left_inside']
980
-				) );
981
-			}
982
-			if ( $args['input_group_right'] ) {
983
-				$output = self::wrap( array(
984
-					'content'                  => $output,
985
-					'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
986
-					'input_group_right'        => $args['input_group_right'],
987
-					'input_group_right_inside' => $args['input_group_right_inside']
988
-				) );
989
-			}
990
-
991
-		}
992
-
993
-		if ( ! $label_after ) {
994
-			$output .= $help_text;
995
-		}
996
-
997
-
998
-		if ( $args['label_type'] == 'horizontal' ) {
999
-			$output = self::wrap( array(
1000
-				'content' => $output,
1001
-				'class'   => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' )
1002
-			) );
1003
-		}
1004
-
1005
-		if ( ! $label_after ) {
1006
-			$output = $label . $output;
1007
-		}
1008
-
1009
-		// maybe horizontal label
835
+        // Set hidden input to save empty value for multiselect.
836
+        if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) {
837
+            $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value=""/>';
838
+        }
839
+
840
+        // open/type
841
+        $output .= '<select ';
842
+
843
+        // style
844
+        if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) {
845
+            $output .= " style='width:100%;' ";
846
+        }
847
+
848
+        // element require
849
+        if ( ! empty( $args['element_require'] ) ) {
850
+            $output .= AUI_Component_Helper::element_require( $args['element_require'] );
851
+            $args['class'] .= " aui-conditional-field";
852
+        }
853
+
854
+        // class
855
+        $class = ! empty( $args['class'] ) ? $args['class'] : '';
856
+        $output .= AUI_Component_Helper::class_attr( 'custom-select ' . $class );
857
+
858
+        // name
859
+        if ( ! empty( $args['name'] ) ) {
860
+            $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] );
861
+        }
862
+
863
+        // id
864
+        if ( ! empty( $args['id'] ) ) {
865
+            $output .= AUI_Component_Helper::id( $args['id'] );
866
+        }
867
+
868
+        // title
869
+        if ( ! empty( $args['title'] ) ) {
870
+            $output .= AUI_Component_Helper::title( $args['title'] );
871
+        }
872
+
873
+        // data-attributes
874
+        $output .= AUI_Component_Helper::data_attributes( $args );
875
+
876
+        // aria-attributes
877
+        $output .= AUI_Component_Helper::aria_attributes( $args );
878
+
879
+        // extra attributes
880
+        if ( ! empty( $args['extra_attributes'] ) ) {
881
+            $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
882
+        }
883
+
884
+        // required
885
+        if ( ! empty( $args['required'] ) ) {
886
+            $output .= ' required ';
887
+        }
888
+
889
+        // multiple
890
+        if ( ! empty( $args['multiple'] ) ) {
891
+            $output .= ' multiple ';
892
+        }
893
+
894
+        // close opening tag
895
+        $output .= ' >';
896
+
897
+        // placeholder
898
+        if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) {
899
+            $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>';
900
+        } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) {
901
+            $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder
902
+        }
903
+
904
+        // Options
905
+        if ( ! empty( $args['options'] ) ) {
906
+
907
+            if ( ! is_array( $args['options'] ) ) {
908
+                $output .= $args['options']; // not the preferred way but an option
909
+            } else {
910
+                foreach ( $args['options'] as $val => $name ) {
911
+                    $selected = '';
912
+                    if ( is_array( $name ) ) {
913
+                        if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) {
914
+                            $option_label = isset( $name['label'] ) ? $name['label'] : '';
915
+
916
+                            $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>';
917
+                        } else {
918
+                            $option_label = isset( $name['label'] ) ? $name['label'] : '';
919
+                            $option_value = isset( $name['value'] ) ? $name['value'] : '';
920
+                            $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : '';
921
+                            if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) {
922
+                                $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : "";
923
+                            } elseif ( ! empty( $args['value'] ) ) {
924
+                                $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false );
925
+                            } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) {
926
+                                $selected = selected( $option_value, $args['value'], false );
927
+                            }
928
+
929
+                            $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>';
930
+                        }
931
+                    } else {
932
+                        if ( ! empty( $args['value'] ) ) {
933
+                            if ( is_array( $args['value'] ) ) {
934
+                                $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : '';
935
+                            } elseif ( ! empty( $args['value'] ) ) {
936
+                                $selected = selected( $args['value'], $val, false );
937
+                            }
938
+                        } elseif ( $args['value'] === $val ) {
939
+                            $selected = selected( $args['value'], $val, false );
940
+                        }
941
+                        $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>';
942
+                    }
943
+                }
944
+            }
945
+
946
+        }
947
+
948
+        // closing tag
949
+        $output .= '</select>';
950
+
951
+        $label = '';
952
+        $help_text = '';
953
+        // label
954
+        if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
955
+        } elseif ( ! empty( $args['label'] ) && ! $label_after ) {
956
+            $label_args = array(
957
+                'title'      => $args['label'],
958
+                'for'        => $args['id'],
959
+                'class'      => $args['label_class'] . " ",
960
+                'label_type' => $args['label_type'],
961
+                'label_col'  => $args['label_col']
962
+            );
963
+            $label = self::label( $label_args );
964
+        }
965
+
966
+        // help text
967
+        if ( ! empty( $args['help_text'] ) ) {
968
+            $help_text = AUI_Component_Helper::help_text( $args['help_text'] );
969
+        }
970
+
971
+        // input group wraps
972
+        if ( $args['input_group_left'] || $args['input_group_right'] ) {
973
+            $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
974
+            if ( $args['input_group_left'] ) {
975
+                $output = self::wrap( array(
976
+                    'content'                 => $output,
977
+                    'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
978
+                    'input_group_left'        => $args['input_group_left'],
979
+                    'input_group_left_inside' => $args['input_group_left_inside']
980
+                ) );
981
+            }
982
+            if ( $args['input_group_right'] ) {
983
+                $output = self::wrap( array(
984
+                    'content'                  => $output,
985
+                    'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
986
+                    'input_group_right'        => $args['input_group_right'],
987
+                    'input_group_right_inside' => $args['input_group_right_inside']
988
+                ) );
989
+            }
990
+
991
+        }
992
+
993
+        if ( ! $label_after ) {
994
+            $output .= $help_text;
995
+        }
996
+
997
+
998
+        if ( $args['label_type'] == 'horizontal' ) {
999
+            $output = self::wrap( array(
1000
+                'content' => $output,
1001
+                'class'   => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' )
1002
+            ) );
1003
+        }
1004
+
1005
+        if ( ! $label_after ) {
1006
+            $output = $label . $output;
1007
+        }
1008
+
1009
+        // maybe horizontal label
1010 1010
 //		if ( $args['label_type'] == 'horizontal' ) {
1011 1011
 //			$output .= '</div>';
1012 1012
 //		}
1013 1013
 
1014 1014
 
1015
-		// wrap
1016
-		if ( ! $args['no_wrap'] ) {
1017
-			$wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group';
1018
-			$wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
1019
-			$output     = self::wrap( array(
1020
-				'content'         => $output,
1021
-				'class'           => $wrap_class,
1022
-				'element_require' => $args['element_require'],
1023
-				'argument_id'     => $args['id'],
1024
-				'wrap_attributes' => $args['wrap_attributes'],
1025
-			) );
1026
-		}
1027
-
1028
-
1029
-		return $output;
1030
-	}
1031
-
1032
-	/**
1033
-	 * Build the component.
1034
-	 *
1035
-	 * @param array $args
1036
-	 *
1037
-	 * @return string The rendered component.
1038
-	 */
1039
-	public static function radio( $args = array() ) {
1040
-		$defaults = array(
1041
-			'class'            => '',
1042
-			'wrap_class'       => '',
1043
-			'id'               => '',
1044
-			'title'            => '',
1045
-			'horizontal'       => false,
1046
-			// sets the lable horizontal
1047
-			'value'            => '',
1048
-			'label'            => '',
1049
-			'label_class'      => '',
1050
-			'label_type'       => '',
1051
-			'label_col'        => '',
1052
-			// sets the label type, default: hidden. Options: hidden, top, horizontal, floating
1053
-			'help_text'        => '',
1054
-			'inline'           => true,
1055
-			'required'         => false,
1056
-			'options'          => array(),
1057
-			'icon'             => '',
1058
-			'no_wrap'          => false,
1059
-			'element_require'  => '',
1060
-			// [%element_id%] == "1"
1061
-			'extra_attributes' => array(),
1062
-			// an array of extra attributes
1063
-			'wrap_attributes'  => array()
1064
-		);
1065
-
1066
-		/**
1067
-		 * Parse incoming $args into an array and merge it with $defaults
1068
-		 */
1069
-		$args = wp_parse_args( $args, $defaults );
1070
-
1071
-		// for now lets use horizontal for floating
1072
-		if ( $args['label_type'] == 'floating' ) {
1073
-			$args['label_type'] = 'horizontal';
1074
-		}
1075
-
1076
-		$label_args = array(
1077
-			'title'      => $args['label'],
1078
-			'class'      => $args['label_class'] . " pt-0 ",
1079
-			'label_type' => $args['label_type'],
1080
-			'label_col'  => $args['label_col']
1081
-		);
1082
-
1083
-		$output = '';
1084
-
1085
-
1086
-		// label before
1087
-		if ( ! empty( $args['label'] ) ) {
1088
-			$output .= self::label( $label_args, 'radio' );
1089
-		}
1090
-
1091
-		// maybe horizontal label
1092
-		if ( $args['label_type'] == 'horizontal' ) {
1093
-			$input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
1094
-			$output .= '<div class="' . $input_col . '">';
1095
-		}
1096
-
1097
-		if ( ! empty( $args['options'] ) ) {
1098
-			$count = 0;
1099
-			foreach ( $args['options'] as $value => $label ) {
1100
-				$option_args            = $args;
1101
-				$option_args['value']   = $value;
1102
-				$option_args['label']   = $label;
1103
-				$option_args['checked'] = $value == $args['value'] ? true : false;
1104
-				$output .= self::radio_option( $option_args, $count );
1105
-				$count ++;
1106
-			}
1107
-		}
1108
-
1109
-		// help text
1110
-		$help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : '';
1111
-		$output .= $help_text;
1112
-
1113
-		// maybe horizontal label
1114
-		if ( $args['label_type'] == 'horizontal' ) {
1115
-			$output .= '</div>';
1116
-		}
1117
-
1118
-		// wrap
1119
-		$wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group';
1120
-		$wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
1121
-		$output     = self::wrap( array(
1122
-			'content'         => $output,
1123
-			'class'           => $wrap_class,
1124
-			'element_require' => $args['element_require'],
1125
-			'argument_id'     => $args['id'],
1126
-			'wrap_attributes' => $args['wrap_attributes'],
1127
-		) );
1128
-
1129
-
1130
-		return $output;
1131
-	}
1132
-
1133
-	/**
1134
-	 * Build the component.
1135
-	 *
1136
-	 * @param array $args
1137
-	 *
1138
-	 * @return string The rendered component.
1139
-	 */
1140
-	public static function radio_option( $args = array(), $count = '' ) {
1141
-		$defaults = array(
1142
-			'class'            => '',
1143
-			'id'               => '',
1144
-			'title'            => '',
1145
-			'value'            => '',
1146
-			'required'         => false,
1147
-			'inline'           => true,
1148
-			'label'            => '',
1149
-			'options'          => array(),
1150
-			'icon'             => '',
1151
-			'no_wrap'          => false,
1152
-			'extra_attributes' => array() // an array of extra attributes
1153
-		);
1154
-
1155
-		/**
1156
-		 * Parse incoming $args into an array and merge it with $defaults
1157
-		 */
1158
-		$args = wp_parse_args( $args, $defaults );
1159
-
1160
-		$output = '';
1161
-
1162
-		// open/type
1163
-		$output .= '<input type="radio"';
1164
-
1165
-		// class
1166
-		$output .= ' class="form-check-input" ';
1167
-
1168
-		// name
1169
-		if ( ! empty( $args['name'] ) ) {
1170
-			$output .= AUI_Component_Helper::name( $args['name'] );
1171
-		}
1172
-
1173
-		// id
1174
-		if ( ! empty( $args['id'] ) ) {
1175
-			$output .= AUI_Component_Helper::id( $args['id'] . $count );
1176
-		}
1177
-
1178
-		// title
1179
-		if ( ! empty( $args['title'] ) ) {
1180
-			$output .= AUI_Component_Helper::title( $args['title'] );
1181
-		}
1182
-
1183
-		// value
1184
-		if ( isset( $args['value'] ) ) {
1185
-			$output .= AUI_Component_Helper::value( $args['value'] );
1186
-		}
1187
-
1188
-		// checked, for radio and checkboxes
1189
-		if ( $args['checked'] ) {
1190
-			$output .= ' checked ';
1191
-		}
1192
-
1193
-		// data-attributes
1194
-		$output .= AUI_Component_Helper::data_attributes( $args );
1195
-
1196
-		// aria-attributes
1197
-		$output .= AUI_Component_Helper::aria_attributes( $args );
1198
-
1199
-		// extra attributes
1200
-		if ( ! empty( $args['extra_attributes'] ) ) {
1201
-			$output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
1202
-		}
1203
-
1204
-		// required
1205
-		if ( ! empty( $args['required'] ) ) {
1206
-			$output .= ' required ';
1207
-		}
1208
-
1209
-		// close opening tag
1210
-		$output .= ' >';
1211
-
1212
-		// label
1213
-		if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
1214
-		} elseif ( ! empty( $args['label'] ) ) {
1215
-			$output .= self::label( array(
1216
-				'title' => $args['label'],
1217
-				'for'   => $args['id'] . $count,
1218
-				'class' => 'form-check-label'
1219
-			), 'radio' );
1220
-		}
1221
-
1222
-		// wrap
1223
-		if ( ! $args['no_wrap'] ) {
1224
-			$wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check';
1225
-
1226
-			// Unique wrap class
1227
-			$uniq_class = 'fwrap';
1228
-			if ( ! empty( $args['name'] ) ) {
1229
-				$uniq_class .= '-' . $args['name'];
1230
-			} else if ( ! empty( $args['id'] ) ) {
1231
-				$uniq_class .= '-' . $args['id'];
1232
-			}
1233
-
1234
-			if ( isset( $args['value'] ) || $args['value'] !== "" ) {
1235
-				$uniq_class .= '-' . $args['value'];
1236
-			} else {
1237
-				$uniq_class .= '-' . $count;
1238
-			}
1239
-			$wrap_class .= ' ' . sanitize_html_class( $uniq_class );
1240
-
1241
-			$output = self::wrap( array(
1242
-				'content' => $output,
1243
-				'class'   => $wrap_class
1244
-			) );
1245
-		}
1246
-
1247
-		return $output;
1248
-	}
1015
+        // wrap
1016
+        if ( ! $args['no_wrap'] ) {
1017
+            $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group';
1018
+            $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
1019
+            $output     = self::wrap( array(
1020
+                'content'         => $output,
1021
+                'class'           => $wrap_class,
1022
+                'element_require' => $args['element_require'],
1023
+                'argument_id'     => $args['id'],
1024
+                'wrap_attributes' => $args['wrap_attributes'],
1025
+            ) );
1026
+        }
1027
+
1028
+
1029
+        return $output;
1030
+    }
1031
+
1032
+    /**
1033
+     * Build the component.
1034
+     *
1035
+     * @param array $args
1036
+     *
1037
+     * @return string The rendered component.
1038
+     */
1039
+    public static function radio( $args = array() ) {
1040
+        $defaults = array(
1041
+            'class'            => '',
1042
+            'wrap_class'       => '',
1043
+            'id'               => '',
1044
+            'title'            => '',
1045
+            'horizontal'       => false,
1046
+            // sets the lable horizontal
1047
+            'value'            => '',
1048
+            'label'            => '',
1049
+            'label_class'      => '',
1050
+            'label_type'       => '',
1051
+            'label_col'        => '',
1052
+            // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
1053
+            'help_text'        => '',
1054
+            'inline'           => true,
1055
+            'required'         => false,
1056
+            'options'          => array(),
1057
+            'icon'             => '',
1058
+            'no_wrap'          => false,
1059
+            'element_require'  => '',
1060
+            // [%element_id%] == "1"
1061
+            'extra_attributes' => array(),
1062
+            // an array of extra attributes
1063
+            'wrap_attributes'  => array()
1064
+        );
1065
+
1066
+        /**
1067
+         * Parse incoming $args into an array and merge it with $defaults
1068
+         */
1069
+        $args = wp_parse_args( $args, $defaults );
1070
+
1071
+        // for now lets use horizontal for floating
1072
+        if ( $args['label_type'] == 'floating' ) {
1073
+            $args['label_type'] = 'horizontal';
1074
+        }
1075
+
1076
+        $label_args = array(
1077
+            'title'      => $args['label'],
1078
+            'class'      => $args['label_class'] . " pt-0 ",
1079
+            'label_type' => $args['label_type'],
1080
+            'label_col'  => $args['label_col']
1081
+        );
1082
+
1083
+        $output = '';
1084
+
1085
+
1086
+        // label before
1087
+        if ( ! empty( $args['label'] ) ) {
1088
+            $output .= self::label( $label_args, 'radio' );
1089
+        }
1090
+
1091
+        // maybe horizontal label
1092
+        if ( $args['label_type'] == 'horizontal' ) {
1093
+            $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
1094
+            $output .= '<div class="' . $input_col . '">';
1095
+        }
1096
+
1097
+        if ( ! empty( $args['options'] ) ) {
1098
+            $count = 0;
1099
+            foreach ( $args['options'] as $value => $label ) {
1100
+                $option_args            = $args;
1101
+                $option_args['value']   = $value;
1102
+                $option_args['label']   = $label;
1103
+                $option_args['checked'] = $value == $args['value'] ? true : false;
1104
+                $output .= self::radio_option( $option_args, $count );
1105
+                $count ++;
1106
+            }
1107
+        }
1108
+
1109
+        // help text
1110
+        $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : '';
1111
+        $output .= $help_text;
1112
+
1113
+        // maybe horizontal label
1114
+        if ( $args['label_type'] == 'horizontal' ) {
1115
+            $output .= '</div>';
1116
+        }
1117
+
1118
+        // wrap
1119
+        $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group';
1120
+        $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
1121
+        $output     = self::wrap( array(
1122
+            'content'         => $output,
1123
+            'class'           => $wrap_class,
1124
+            'element_require' => $args['element_require'],
1125
+            'argument_id'     => $args['id'],
1126
+            'wrap_attributes' => $args['wrap_attributes'],
1127
+        ) );
1128
+
1129
+
1130
+        return $output;
1131
+    }
1132
+
1133
+    /**
1134
+     * Build the component.
1135
+     *
1136
+     * @param array $args
1137
+     *
1138
+     * @return string The rendered component.
1139
+     */
1140
+    public static function radio_option( $args = array(), $count = '' ) {
1141
+        $defaults = array(
1142
+            'class'            => '',
1143
+            'id'               => '',
1144
+            'title'            => '',
1145
+            'value'            => '',
1146
+            'required'         => false,
1147
+            'inline'           => true,
1148
+            'label'            => '',
1149
+            'options'          => array(),
1150
+            'icon'             => '',
1151
+            'no_wrap'          => false,
1152
+            'extra_attributes' => array() // an array of extra attributes
1153
+        );
1154
+
1155
+        /**
1156
+         * Parse incoming $args into an array and merge it with $defaults
1157
+         */
1158
+        $args = wp_parse_args( $args, $defaults );
1159
+
1160
+        $output = '';
1161
+
1162
+        // open/type
1163
+        $output .= '<input type="radio"';
1164
+
1165
+        // class
1166
+        $output .= ' class="form-check-input" ';
1167
+
1168
+        // name
1169
+        if ( ! empty( $args['name'] ) ) {
1170
+            $output .= AUI_Component_Helper::name( $args['name'] );
1171
+        }
1172
+
1173
+        // id
1174
+        if ( ! empty( $args['id'] ) ) {
1175
+            $output .= AUI_Component_Helper::id( $args['id'] . $count );
1176
+        }
1177
+
1178
+        // title
1179
+        if ( ! empty( $args['title'] ) ) {
1180
+            $output .= AUI_Component_Helper::title( $args['title'] );
1181
+        }
1182
+
1183
+        // value
1184
+        if ( isset( $args['value'] ) ) {
1185
+            $output .= AUI_Component_Helper::value( $args['value'] );
1186
+        }
1187
+
1188
+        // checked, for radio and checkboxes
1189
+        if ( $args['checked'] ) {
1190
+            $output .= ' checked ';
1191
+        }
1192
+
1193
+        // data-attributes
1194
+        $output .= AUI_Component_Helper::data_attributes( $args );
1195
+
1196
+        // aria-attributes
1197
+        $output .= AUI_Component_Helper::aria_attributes( $args );
1198
+
1199
+        // extra attributes
1200
+        if ( ! empty( $args['extra_attributes'] ) ) {
1201
+            $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
1202
+        }
1203
+
1204
+        // required
1205
+        if ( ! empty( $args['required'] ) ) {
1206
+            $output .= ' required ';
1207
+        }
1208
+
1209
+        // close opening tag
1210
+        $output .= ' >';
1211
+
1212
+        // label
1213
+        if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
1214
+        } elseif ( ! empty( $args['label'] ) ) {
1215
+            $output .= self::label( array(
1216
+                'title' => $args['label'],
1217
+                'for'   => $args['id'] . $count,
1218
+                'class' => 'form-check-label'
1219
+            ), 'radio' );
1220
+        }
1221
+
1222
+        // wrap
1223
+        if ( ! $args['no_wrap'] ) {
1224
+            $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check';
1225
+
1226
+            // Unique wrap class
1227
+            $uniq_class = 'fwrap';
1228
+            if ( ! empty( $args['name'] ) ) {
1229
+                $uniq_class .= '-' . $args['name'];
1230
+            } else if ( ! empty( $args['id'] ) ) {
1231
+                $uniq_class .= '-' . $args['id'];
1232
+            }
1233
+
1234
+            if ( isset( $args['value'] ) || $args['value'] !== "" ) {
1235
+                $uniq_class .= '-' . $args['value'];
1236
+            } else {
1237
+                $uniq_class .= '-' . $count;
1238
+            }
1239
+            $wrap_class .= ' ' . sanitize_html_class( $uniq_class );
1240
+
1241
+            $output = self::wrap( array(
1242
+                'content' => $output,
1243
+                'class'   => $wrap_class
1244
+            ) );
1245
+        }
1246
+
1247
+        return $output;
1248
+    }
1249 1249
 
1250 1250
 }
1251 1251
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +290 added lines, -290 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) {
3
+if (!defined('ABSPATH')) {
4 4
 	exit; // Exit if accessed directly
5 5
 }
6 6
 
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 	 *
19 19
 	 * @return string The rendered component.
20 20
 	 */
21
-	public static function input( $args = array() ) {
21
+	public static function input($args = array()) {
22 22
 		$defaults = array(
23 23
 			'type'                     => 'text',
24 24
 			'name'                     => '',
@@ -65,13 +65,13 @@  discard block
 block discarded – undo
65 65
 		/**
66 66
 		 * Parse incoming $args into an array and merge it with $defaults
67 67
 		 */
68
-		$args   = wp_parse_args( $args, $defaults );
68
+		$args   = wp_parse_args($args, $defaults);
69 69
 		$output = '';
70
-		if ( ! empty( $args['type'] ) ) {
70
+		if (!empty($args['type'])) {
71 71
 			// hidden label option needs to be empty
72 72
 			$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
73 73
 
74
-			$type = sanitize_html_class( $args['type'] );
74
+			$type = sanitize_html_class($args['type']);
75 75
 
76 76
 			$help_text   = '';
77 77
 			$label       = '';
@@ -85,17 +85,17 @@  discard block
 block discarded – undo
85 85
 			);
86 86
 
87 87
 			// floating labels need label after
88
-			if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) {
88
+			if ($args['label_type'] == 'floating' && $type != 'checkbox') {
89 89
 				$label_after         = true;
90 90
 				$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
91 91
 			}
92 92
 
93 93
 			// size
94 94
 			$size = '';
95
-			if ( $args['size'] == 'lg' || $args['size'] == 'large' ) {
95
+			if ($args['size'] == 'lg' || $args['size'] == 'large') {
96 96
 				$size = 'lg';
97 97
 				$args['class'] .= ' form-control-lg';
98
-			}elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) {
98
+			}elseif ($args['size'] == 'sm' || $args['size'] == 'small') {
99 99
 				$size = 'sm';
100 100
 				$args['class'] .= ' form-control-sm';
101 101
 			}
@@ -104,20 +104,20 @@  discard block
 block discarded – undo
104 104
 			$clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');';
105 105
 
106 106
 			// Some special sauce for files
107
-			if ( $type == 'file' ) {
107
+			if ($type == 'file') {
108 108
 				$label_after = true; // if type file we need the label after
109 109
 				$args['class'] .= ' custom-file-input ';
110
-			} elseif ( $type == 'checkbox' ) {
110
+			} elseif ($type == 'checkbox') {
111 111
 				$label_after = true; // if type file we need the label after
112 112
 				$args['class'] .= ' custom-control-input ';
113
-			} elseif ( $type == 'datepicker' || $type == 'timepicker' ) {
113
+			} elseif ($type == 'datepicker' || $type == 'timepicker') {
114 114
 				$type = 'text';
115 115
 				$args['class'] .= ' bg-initial '; // @todo not sure why we have this?
116 116
 
117 117
 				$args['extra_attributes']['data-aui-init'] = 'flatpickr';
118 118
 
119 119
 				// set a way to clear field if empty
120
-				if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) {
120
+				if ($args['input_group_right'] === '' && $args['clear_icon'] !== false) {
121 121
 					$args['input_group_right_inside'] = true;
122 122
 					$args['clear_icon'] = true;
123 123
 				}
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 				// enqueue the script
126 126
 				$aui_settings = AyeCode_UI_Settings::instance();
127 127
 				$aui_settings->enqueue_flatpickr();
128
-			} elseif ( $type == 'iconpicker' ) {
128
+			} elseif ($type == 'iconpicker') {
129 129
 				$type = 'text';
130 130
 				//$args['class'] .= ' aui-flatpickr bg-initial ';
131 131
 //				$args['class'] .= ' bg-initial ';
@@ -140,103 +140,103 @@  discard block
 block discarded – undo
140 140
 				$aui_settings->enqueue_iconpicker();
141 141
 			}
142 142
 
143
-			if ( $type == 'checkbox' && !empty($args['name'] ) && strpos($args['name'], '[') === false ) {
144
-				$output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />';
143
+			if ($type == 'checkbox' && !empty($args['name']) && strpos($args['name'], '[') === false) {
144
+				$output .= '<input type="hidden" name="' . esc_attr($args['name']) . '" value="0" />';
145 145
 			}
146 146
 
147 147
 			// allow clear icon
148
-			if ( $args['input_group_right'] === '' && $args['clear_icon'] ) {
149
-				$font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' );
148
+			if ($args['input_group_right'] === '' && $args['clear_icon']) {
149
+				$font_size = $size == 'sm' ? '1.3' : ($size == 'lg' ? '1.65' : '1.5');
150 150
 				$args['input_group_right_inside'] = true;
151
-				$args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none" onclick="' . $clear_function . '"><span style="font-size: '.$font_size.'rem" aria-hidden="true" class="close">&times;</span></span>';
151
+				$args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none" onclick="' . $clear_function . '"><span style="font-size: ' . $font_size . 'rem" aria-hidden="true" class="close">&times;</span></span>';
152 152
 			}
153 153
 
154 154
 			// open/type
155 155
 			$output .= '<input type="' . $type . '" ';
156 156
 
157 157
 			// name
158
-			if ( ! empty( $args['name'] ) ) {
159
-				$output .= ' name="' . esc_attr( $args['name'] ) . '" ';
158
+			if (!empty($args['name'])) {
159
+				$output .= ' name="' . esc_attr($args['name']) . '" ';
160 160
 			}
161 161
 
162 162
 			// id
163
-			if ( ! empty( $args['id'] ) ) {
164
-				$output .= ' id="' . sanitize_html_class( $args['id'] ) . '" ';
163
+			if (!empty($args['id'])) {
164
+				$output .= ' id="' . sanitize_html_class($args['id']) . '" ';
165 165
 			}
166 166
 
167 167
 			// placeholder
168
-			if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) {
169
-				$output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" ';
168
+			if (isset($args['placeholder']) && '' != $args['placeholder']) {
169
+				$output .= ' placeholder="' . esc_attr($args['placeholder']) . '" ';
170 170
 			}
171 171
 
172 172
 			// title
173
-			if ( ! empty( $args['title'] ) ) {
174
-				$output .= ' title="' . esc_attr( $args['title'] ) . '" ';
173
+			if (!empty($args['title'])) {
174
+				$output .= ' title="' . esc_attr($args['title']) . '" ';
175 175
 			}
176 176
 
177 177
 			// value
178
-			if ( ! empty( $args['value'] ) ) {
179
-				$output .= AUI_Component_Helper::value( $args['value'] );
178
+			if (!empty($args['value'])) {
179
+				$output .= AUI_Component_Helper::value($args['value']);
180 180
 			}
181 181
 
182 182
 			// checked, for radio and checkboxes
183
-			if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) {
183
+			if (($type == 'checkbox' || $type == 'radio') && $args['checked']) {
184 184
 				$output .= ' checked ';
185 185
 			}
186 186
 
187 187
 			// validation text
188
-			if ( ! empty( $args['validation_text'] ) ) {
189
-				$output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" ';
188
+			if (!empty($args['validation_text'])) {
189
+				$output .= ' oninvalid="setCustomValidity(\'' . esc_attr($args['validation_text']) . '\')" ';
190 190
 				$output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
191 191
 			}
192 192
 
193 193
 			// validation_pattern
194
-			if ( ! empty( $args['validation_pattern'] ) ) {
195
-				$output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" ';
194
+			if (!empty($args['validation_pattern'])) {
195
+				$output .= ' pattern="' . esc_attr($args['validation_pattern']) . '" ';
196 196
 			}
197 197
 
198 198
 			// step (for numbers)
199
-			if ( ! empty( $args['step'] ) ) {
199
+			if (!empty($args['step'])) {
200 200
 				$output .= ' step="' . $args['step'] . '" ';
201 201
 			}
202 202
 
203 203
 			// required
204
-			if ( ! empty( $args['required'] ) ) {
204
+			if (!empty($args['required'])) {
205 205
 				$output .= ' required ';
206 206
 			}
207 207
 
208 208
 			// class
209
-			$class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
209
+			$class = !empty($args['class']) ? AUI_Component_Helper::esc_classes($args['class']) : '';
210 210
 			$output .= ' class="form-control ' . $class . '" ';
211 211
 
212 212
 			// data-attributes
213
-			$output .= AUI_Component_Helper::data_attributes( $args );
213
+			$output .= AUI_Component_Helper::data_attributes($args);
214 214
 
215 215
 			// extra attributes
216
-			if ( ! empty( $args['extra_attributes'] ) ) {
217
-				$output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
216
+			if (!empty($args['extra_attributes'])) {
217
+				$output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
218 218
 			}
219 219
 
220 220
 			// close
221 221
 			$output .= ' >';
222 222
 
223 223
 			// help text
224
-			if ( ! empty( $args['help_text'] ) ) {
225
-				$help_text = AUI_Component_Helper::help_text( $args['help_text'] );
224
+			if (!empty($args['help_text'])) {
225
+				$help_text = AUI_Component_Helper::help_text($args['help_text']);
226 226
 			}
227 227
 
228 228
 			// label
229
-			if ( ! empty( $args['label'] ) ) {
229
+			if (!empty($args['label'])) {
230 230
 				$label_base_class = '';
231
-				if ( $type == 'file' ) {
231
+				if ($type == 'file') {
232 232
 					$label_base_class = ' custom-file-label';
233
-				} elseif ( $type == 'checkbox' ) {
234
-					if ( ! empty( $args['label_force_left'] ) ) {
235
-						$label_args['title'] = wp_kses_post( $args['help_text'] );
233
+				} elseif ($type == 'checkbox') {
234
+					if (!empty($args['label_force_left'])) {
235
+						$label_args['title'] = wp_kses_post($args['help_text']);
236 236
 						$help_text = '';
237 237
 						//$label_args['class'] .= ' d-inline ';
238 238
 						$args['wrap_class'] .= ' align-items-center ';
239
-					}else{
239
+					} else {
240 240
 
241 241
 					}
242 242
 
@@ -244,45 +244,45 @@  discard block
 block discarded – undo
244 244
 				}
245 245
 				$label_args['class'] .= $label_base_class;
246 246
 				$temp_label_args = $label_args;
247
-				if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";}
248
-				$label = self::label( $temp_label_args, $type );
247
+				if (!empty($args['label_force_left'])) {$temp_label_args['class'] = $label_base_class . " text-muted"; }
248
+				$label = self::label($temp_label_args, $type);
249 249
 			}
250 250
 
251 251
 
252 252
 
253 253
 
254 254
 			// set help text in the correct position
255
-			if ( $label_after ) {
255
+			if ($label_after) {
256 256
 				$output .= $label . $help_text;
257 257
 			}
258 258
 
259 259
 			// some input types need a separate wrap
260
-			if ( $type == 'file' ) {
261
-				$output = self::wrap( array(
260
+			if ($type == 'file') {
261
+				$output = self::wrap(array(
262 262
 					'content' => $output,
263 263
 					'class'   => 'form-group custom-file'
264
-				) );
265
-			} elseif ( $type == 'checkbox' ) {
264
+				));
265
+			} elseif ($type == 'checkbox') {
266 266
 
267 267
 				$label_args['title'] = $args['label'];
268
-				$label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' );
269
-				$label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>';
270
-				$switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : '';
271
-				$wrap_class = $args['switch'] ? 'custom-switch'.$switch_size_class : 'custom-checkbox';
272
-				if ( ! empty( $args['label_force_left'] ) ) {
268
+				$label_col = AUI_Component_Helper::get_column_class($args['label_col'], 'label');
269
+				$label = !empty($args['label_force_left']) ? self::label($label_args, 'cb') : '<div class="' . $label_col . ' col-form-label"></div>';
270
+				$switch_size_class = $args['switch'] && !is_bool($args['switch']) ? ' custom-switch-' . esc_attr($args['switch']) : '';
271
+				$wrap_class = $args['switch'] ? 'custom-switch' . $switch_size_class : 'custom-checkbox';
272
+				if (!empty($args['label_force_left'])) {
273 273
 					$wrap_class .= ' d-flex align-content-center';
274
-					$label = str_replace("custom-control-label","", self::label( $label_args, 'cb' ) );
274
+					$label = str_replace("custom-control-label", "", self::label($label_args, 'cb'));
275 275
 				}
276
-				$output     = self::wrap( array(
276
+				$output = self::wrap(array(
277 277
 					'content' => $output,
278 278
 					'class'   => 'custom-control ' . $wrap_class
279
-				) );
279
+				));
280 280
 
281
-				if ( $args['label_type'] == 'horizontal' ) {
282
-					$input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
281
+				if ($args['label_type'] == 'horizontal') {
282
+					$input_col = AUI_Component_Helper::get_column_class($args['label_col'], 'input');
283 283
 					$output    = $label . '<div class="' . $input_col . '">' . $output . '</div>';
284 284
 				}
285
-			} elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) {
285
+			} elseif ($type == 'password' && $args['password_toggle'] && !$args['input_group_right']) {
286 286
 
287 287
 
288 288
 				// allow password field to toggle view
@@ -296,65 +296,65 @@  discard block
 block discarded – undo
296 296
 			}
297 297
 
298 298
 			// input group wraps
299
-			if ( $args['input_group_left'] || $args['input_group_right'] ) {
300
-				$w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
299
+			if ($args['input_group_left'] || $args['input_group_right']) {
300
+				$w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : '';
301 301
 				$group_size = $size == 'lg' ? ' input-group-lg' : '';
302 302
 				$group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size;
303 303
 
304
-				if ( $args['input_group_left'] ) {
305
-					$output = self::wrap( array(
304
+				if ($args['input_group_left']) {
305
+					$output = self::wrap(array(
306 306
 						'content'                 => $output,
307 307
 						'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size,
308 308
 						'input_group_left'        => $args['input_group_left'],
309 309
 						'input_group_left_inside' => $args['input_group_left_inside']
310
-					) );
310
+					));
311 311
 				}
312
-				if ( $args['input_group_right'] ) {
313
-					$output = self::wrap( array(
312
+				if ($args['input_group_right']) {
313
+					$output = self::wrap(array(
314 314
 						'content'                  => $output,
315 315
 						'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size,
316 316
 						'input_group_right'        => $args['input_group_right'],
317 317
 						'input_group_right_inside' => $args['input_group_right_inside']
318
-					) );
318
+					));
319 319
 				}
320 320
 
321 321
 			}
322 322
 
323
-			if ( ! $label_after ) {
323
+			if (!$label_after) {
324 324
 				$output .= $help_text;
325 325
 			}
326 326
 
327 327
 
328
-			if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) {
329
-				$output = self::wrap( array(
328
+			if ($args['label_type'] == 'horizontal' && $type != 'checkbox') {
329
+				$output = self::wrap(array(
330 330
 					'content' => $output,
331
-					'class'   => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' )
332
-				) );
331
+					'class'   => AUI_Component_Helper::get_column_class($args['label_col'], 'input')
332
+				));
333 333
 			}
334 334
 
335
-			if ( ! $label_after ) {
335
+			if (!$label_after) {
336 336
 				$output = $label . $output;
337 337
 			}
338 338
 
339 339
 			// wrap
340
-			if ( ! $args['no_wrap'] ) {
340
+			if (!$args['no_wrap']) {
341 341
 				$form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group';
342 342
 				$wrap_class       = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class;
343
-				$wrap_class       = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
344
-				$output           = self::wrap( array(
343
+				$wrap_class       = !empty($args['wrap_class']) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
344
+				$output           = self::wrap(array(
345 345
 					'content'         => $output,
346 346
 					'class'           => $wrap_class,
347 347
 					'element_require' => $args['element_require'],
348 348
 					'argument_id'     => $args['id'],
349 349
 					'wrap_attributes' => $args['wrap_attributes'],
350
-				) );
350
+				));
351 351
 			}
352 352
 		}
353 353
 
354 354
 		return $output;
355 355
 	}
356 356
 
357
-	public static function label( $args = array(), $type = '' ) {
357
+	public static function label($args = array(), $type = '') {
358 358
 		//<label for="exampleInputEmail1">Email address</label>
359 359
 		$defaults = array(
360 360
 			'title'      => 'div',
@@ -367,33 +367,33 @@  discard block
 block discarded – undo
367 367
 		/**
368 368
 		 * Parse incoming $args into an array and merge it with $defaults
369 369
 		 */
370
-		$args   = wp_parse_args( $args, $defaults );
370
+		$args   = wp_parse_args($args, $defaults);
371 371
 		$output = '';
372 372
 
373
-		if ( $args['title'] ) {
373
+		if ($args['title']) {
374 374
 
375 375
 			// maybe hide labels //@todo set a global option for visibility class
376
-			if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) {
376
+			if ($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type'])) {
377 377
 				$class = $args['class'];
378 378
 			} else {
379 379
 				$class = 'sr-only ' . $args['class'];
380 380
 			}
381 381
 
382 382
 			// maybe horizontal
383
-			if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) {
384
-				$class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label';
383
+			if ($args['label_type'] == 'horizontal' && $type != 'checkbox') {
384
+				$class .= ' ' . AUI_Component_Helper::get_column_class($args['label_col'], 'label') . ' col-form-label';
385 385
 			}
386 386
 
387 387
 			// open
388 388
 			$output .= '<label ';
389 389
 
390 390
 			// for
391
-			if ( ! empty( $args['for'] ) ) {
392
-				$output .= ' for="' . esc_attr( $args['for'] ) . '" ';
391
+			if (!empty($args['for'])) {
392
+				$output .= ' for="' . esc_attr($args['for']) . '" ';
393 393
 			}
394 394
 
395 395
 			// class
396
-			$class = $class ? AUI_Component_Helper::esc_classes( $class ) : '';
396
+			$class = $class ? AUI_Component_Helper::esc_classes($class) : '';
397 397
 			$output .= ' class="' . $class . '" ';
398 398
 
399 399
 			// close
@@ -401,8 +401,8 @@  discard block
 block discarded – undo
401 401
 
402 402
 
403 403
 			// title, don't escape fully as can contain html
404
-			if ( ! empty( $args['title'] ) ) {
405
-				$output .= wp_kses_post( $args['title'] );
404
+			if (!empty($args['title'])) {
405
+				$output .= wp_kses_post($args['title']);
406 406
 			}
407 407
 
408 408
 			// close wrap
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
 	 *
423 423
 	 * @return string
424 424
 	 */
425
-	public static function wrap( $args = array() ) {
425
+	public static function wrap($args = array()) {
426 426
 		$defaults = array(
427 427
 			'type'                     => 'div',
428 428
 			'class'                    => 'form-group',
@@ -439,31 +439,31 @@  discard block
 block discarded – undo
439 439
 		/**
440 440
 		 * Parse incoming $args into an array and merge it with $defaults
441 441
 		 */
442
-		$args   = wp_parse_args( $args, $defaults );
442
+		$args   = wp_parse_args($args, $defaults);
443 443
 		$output = '';
444
-		if ( $args['type'] ) {
444
+		if ($args['type']) {
445 445
 
446 446
 			// open
447
-			$output .= '<' . sanitize_html_class( $args['type'] );
447
+			$output .= '<' . sanitize_html_class($args['type']);
448 448
 
449 449
 			// element require
450
-			if ( ! empty( $args['element_require'] ) ) {
451
-				$output .= AUI_Component_Helper::element_require( $args['element_require'] );
450
+			if (!empty($args['element_require'])) {
451
+				$output .= AUI_Component_Helper::element_require($args['element_require']);
452 452
 				$args['class'] .= " aui-conditional-field";
453 453
 			}
454 454
 
455 455
 			// argument_id
456
-			if ( ! empty( $args['argument_id'] ) ) {
457
-				$output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"';
456
+			if (!empty($args['argument_id'])) {
457
+				$output .= ' data-argument="' . esc_attr($args['argument_id']) . '"';
458 458
 			}
459 459
 
460 460
 			// class
461
-			$class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
461
+			$class = !empty($args['class']) ? AUI_Component_Helper::esc_classes($args['class']) : '';
462 462
 			$output .= ' class="' . $class . '" ';
463 463
 
464 464
 			// Attributes
465
-			if ( ! empty( $args['wrap_attributes'] ) ) {
466
-				$output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] );
465
+			if (!empty($args['wrap_attributes'])) {
466
+				$output .= AUI_Component_Helper::extra_attributes($args['wrap_attributes']);
467 467
 			}
468 468
 
469 469
 			// close wrap
@@ -471,9 +471,9 @@  discard block
 block discarded – undo
471 471
 
472 472
 
473 473
 			// Input group left
474
-			if ( ! empty( $args['input_group_left'] ) ) {
475
-				$position_class   = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : '';
476
-				$input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>';
474
+			if (!empty($args['input_group_left'])) {
475
+				$position_class   = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : '';
476
+				$input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>';
477 477
 				$output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>';
478 478
 			}
479 479
 
@@ -481,15 +481,15 @@  discard block
 block discarded – undo
481 481
 			$output .= $args['content'];
482 482
 
483 483
 			// Input group right
484
-			if ( ! empty( $args['input_group_right'] ) ) {
485
-				$position_class    = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : '';
486
-				$input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>';
484
+			if (!empty($args['input_group_right'])) {
485
+				$position_class    = !empty($args['input_group_right_inside']) ? 'position-absolute h-100' : '';
486
+				$input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>';
487 487
 				$output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>';
488 488
 			}
489 489
 
490 490
 
491 491
 			// close wrap
492
-			$output .= '</' . sanitize_html_class( $args['type'] ) . '>';
492
+			$output .= '</' . sanitize_html_class($args['type']) . '>';
493 493
 
494 494
 
495 495
 		} else {
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
 	 *
507 507
 	 * @return string The rendered component.
508 508
 	 */
509
-	public static function textarea( $args = array() ) {
509
+	public static function textarea($args = array()) {
510 510
 		$defaults = array(
511 511
 			'name'               => '',
512 512
 			'class'              => '',
@@ -543,28 +543,28 @@  discard block
 block discarded – undo
543 543
 		/**
544 544
 		 * Parse incoming $args into an array and merge it with $defaults
545 545
 		 */
546
-		$args   = wp_parse_args( $args, $defaults );
546
+		$args   = wp_parse_args($args, $defaults);
547 547
 		$output = '';
548 548
 
549 549
 		// hidden label option needs to be empty
550 550
 		$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
551 551
 
552 552
 		// floating labels don't work with wysiwyg so set it as top
553
-		if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) {
553
+		if ($args['label_type'] == 'floating' && !empty($args['wysiwyg'])) {
554 554
 			$args['label_type'] = 'top';
555 555
 		}
556 556
 
557 557
 		$label_after = $args['label_after'];
558 558
 
559 559
 		// floating labels need label after
560
-		if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) {
560
+		if ($args['label_type'] == 'floating' && empty($args['wysiwyg'])) {
561 561
 			$label_after         = true;
562 562
 			$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
563 563
 		}
564 564
 
565 565
 		// label
566
-		if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
567
-		} elseif ( ! empty( $args['label'] ) && ! $label_after ) {
566
+		if (!empty($args['label']) && is_array($args['label'])) {
567
+		} elseif (!empty($args['label']) && !$label_after) {
568 568
 			$label_args = array(
569 569
 				'title'      => $args['label'],
570 570
 				'for'        => $args['id'],
@@ -572,34 +572,34 @@  discard block
 block discarded – undo
572 572
 				'label_type' => $args['label_type'],
573 573
 				'label_col'  => $args['label_col']
574 574
 			);
575
-			$output .= self::label( $label_args );
575
+			$output .= self::label($label_args);
576 576
 		}
577 577
 
578 578
 		// maybe horizontal label
579
-		if ( $args['label_type'] == 'horizontal' ) {
580
-			$input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
579
+		if ($args['label_type'] == 'horizontal') {
580
+			$input_col = AUI_Component_Helper::get_column_class($args['label_col'], 'input');
581 581
 			$output .= '<div class="' . $input_col . '">';
582 582
 		}
583 583
 
584
-		if ( ! empty( $args['wysiwyg'] ) ) {
584
+		if (!empty($args['wysiwyg'])) {
585 585
 			ob_start();
586 586
 			$content   = $args['value'];
587
-			$editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor';
587
+			$editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor';
588 588
 			$settings  = array(
589
-				'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4,
589
+				'textarea_rows' => !empty(absint($args['rows'])) ? absint($args['rows']) : 4,
590 590
 				'quicktags'     => false,
591 591
 				'media_buttons' => false,
592 592
 				'editor_class'  => 'form-control',
593
-				'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ),
593
+				'textarea_name' => !empty($args['name']) ? sanitize_html_class($args['name']) : sanitize_html_class($args['id']),
594 594
 				'teeny'         => true,
595 595
 			);
596 596
 
597 597
 			// maybe set settings if array
598
-			if ( is_array( $args['wysiwyg'] ) ) {
599
-				$settings = wp_parse_args( $args['wysiwyg'], $settings );
598
+			if (is_array($args['wysiwyg'])) {
599
+				$settings = wp_parse_args($args['wysiwyg'], $settings);
600 600
 			}
601 601
 
602
-			wp_editor( $content, $editor_id, $settings );
602
+			wp_editor($content, $editor_id, $settings);
603 603
 			$output .= ob_get_clean();
604 604
 		} else {
605 605
 
@@ -607,65 +607,65 @@  discard block
 block discarded – undo
607 607
 			$output .= '<textarea ';
608 608
 
609 609
 			// name
610
-			if ( ! empty( $args['name'] ) ) {
611
-				$output .= ' name="' . esc_attr( $args['name'] ) . '" ';
610
+			if (!empty($args['name'])) {
611
+				$output .= ' name="' . esc_attr($args['name']) . '" ';
612 612
 			}
613 613
 
614 614
 			// id
615
-			if ( ! empty( $args['id'] ) ) {
616
-				$output .= ' id="' . sanitize_html_class( $args['id'] ) . '" ';
615
+			if (!empty($args['id'])) {
616
+				$output .= ' id="' . sanitize_html_class($args['id']) . '" ';
617 617
 			}
618 618
 
619 619
 			// placeholder
620
-			if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) {
621
-				$output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" ';
620
+			if (isset($args['placeholder']) && '' != $args['placeholder']) {
621
+				$output .= ' placeholder="' . esc_attr($args['placeholder']) . '" ';
622 622
 			}
623 623
 
624 624
 			// title
625
-			if ( ! empty( $args['title'] ) ) {
626
-				$output .= ' title="' . esc_attr( $args['title'] ) . '" ';
625
+			if (!empty($args['title'])) {
626
+				$output .= ' title="' . esc_attr($args['title']) . '" ';
627 627
 			}
628 628
 
629 629
 			// validation text
630
-			if ( ! empty( $args['validation_text'] ) ) {
631
-				$output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" ';
630
+			if (!empty($args['validation_text'])) {
631
+				$output .= ' oninvalid="setCustomValidity(\'' . esc_attr($args['validation_text']) . '\')" ';
632 632
 				$output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
633 633
 			}
634 634
 
635 635
 			// validation_pattern
636
-			if ( ! empty( $args['validation_pattern'] ) ) {
637
-				$output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" ';
636
+			if (!empty($args['validation_pattern'])) {
637
+				$output .= ' pattern="' . esc_attr($args['validation_pattern']) . '" ';
638 638
 			}
639 639
 
640 640
 			// required
641
-			if ( ! empty( $args['required'] ) ) {
641
+			if (!empty($args['required'])) {
642 642
 				$output .= ' required ';
643 643
 			}
644 644
 
645 645
 			// rows
646
-			if ( ! empty( $args['rows'] ) ) {
647
-				$output .= ' rows="' . absint( $args['rows'] ) . '" ';
646
+			if (!empty($args['rows'])) {
647
+				$output .= ' rows="' . absint($args['rows']) . '" ';
648 648
 			}
649 649
 
650 650
 
651 651
 			// class
652
-			$class = ! empty( $args['class'] ) ? $args['class'] : '';
652
+			$class = !empty($args['class']) ? $args['class'] : '';
653 653
 			$output .= ' class="form-control ' . $class . '" ';
654 654
 
655 655
 			// extra attributes
656
-			if ( ! empty( $args['extra_attributes'] ) ) {
657
-				$output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
656
+			if (!empty($args['extra_attributes'])) {
657
+				$output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
658 658
 			}
659 659
 
660 660
 			// close tag
661 661
 			$output .= ' >';
662 662
 
663 663
 			// value
664
-			if ( ! empty( $args['value'] ) ) {
665
-				if ( ! empty( $args['allow_tags'] ) ) {
666
-					$output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML.
664
+			if (!empty($args['value'])) {
665
+				if (!empty($args['allow_tags'])) {
666
+					$output .= AUI_Component_Helper::sanitize_html_field($args['value'], $args); // Sanitize HTML.
667 667
 				} else {
668
-					$output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] );
668
+					$output .= AUI_Component_Helper::sanitize_textarea_field($args['value']);
669 669
 				}
670 670
 			}
671 671
 
@@ -674,23 +674,23 @@  discard block
 block discarded – undo
674 674
 
675 675
 
676 676
 			// input group wraps
677
-			if ( $args['input_group_left'] || $args['input_group_right'] ) {
678
-				$w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
679
-				if ( $args['input_group_left'] ) {
680
-					$output = self::wrap( array(
677
+			if ($args['input_group_left'] || $args['input_group_right']) {
678
+				$w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : '';
679
+				if ($args['input_group_left']) {
680
+					$output = self::wrap(array(
681 681
 						'content'                 => $output,
682 682
 						'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
683 683
 						'input_group_left'        => $args['input_group_left'],
684 684
 						'input_group_left_inside' => $args['input_group_left_inside']
685
-					) );
685
+					));
686 686
 				}
687
-				if ( $args['input_group_right'] ) {
688
-					$output = self::wrap( array(
687
+				if ($args['input_group_right']) {
688
+					$output = self::wrap(array(
689 689
 						'content'                  => $output,
690 690
 						'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
691 691
 						'input_group_right'        => $args['input_group_right'],
692 692
 						'input_group_right_inside' => $args['input_group_right_inside']
693
-					) );
693
+					));
694 694
 				}
695 695
 
696 696
 			}
@@ -698,7 +698,7 @@  discard block
 block discarded – undo
698 698
 
699 699
 		}
700 700
 
701
-		if ( ! empty( $args['label'] ) && $label_after ) {
701
+		if (!empty($args['label']) && $label_after) {
702 702
 			$label_args = array(
703 703
 				'title'      => $args['label'],
704 704
 				'for'        => $args['id'],
@@ -706,32 +706,32 @@  discard block
 block discarded – undo
706 706
 				'label_type' => $args['label_type'],
707 707
 				'label_col'  => $args['label_col']
708 708
 			);
709
-			$output .= self::label( $label_args );
709
+			$output .= self::label($label_args);
710 710
 		}
711 711
 
712 712
 		// help text
713
-		if ( ! empty( $args['help_text'] ) ) {
714
-			$output .= AUI_Component_Helper::help_text( $args['help_text'] );
713
+		if (!empty($args['help_text'])) {
714
+			$output .= AUI_Component_Helper::help_text($args['help_text']);
715 715
 		}
716 716
 
717 717
 		// maybe horizontal label
718
-		if ( $args['label_type'] == 'horizontal' ) {
718
+		if ($args['label_type'] == 'horizontal') {
719 719
 			$output .= '</div>';
720 720
 		}
721 721
 
722 722
 
723 723
 		// wrap
724
-		if ( ! $args['no_wrap'] ) {
724
+		if (!$args['no_wrap']) {
725 725
 			$form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : 'form-group';
726 726
 			$wrap_class       = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class;
727
-			$wrap_class       = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
728
-			$output           = self::wrap( array(
727
+			$wrap_class       = !empty($args['wrap_class']) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
728
+			$output           = self::wrap(array(
729 729
 				'content'         => $output,
730 730
 				'class'           => $wrap_class,
731 731
 				'element_require' => $args['element_require'],
732 732
 				'argument_id'     => $args['id'],
733 733
 				'wrap_attributes' => $args['wrap_attributes'],
734
-			) );
734
+			));
735 735
 		}
736 736
 
737 737
 
@@ -745,7 +745,7 @@  discard block
 block discarded – undo
745 745
 	 *
746 746
 	 * @return string The rendered component.
747 747
 	 */
748
-	public static function select( $args = array() ) {
748
+	public static function select($args = array()) {
749 749
 		$defaults = array(
750 750
 			'class'            => '',
751 751
 			'wrap_class'       => '',
@@ -782,11 +782,11 @@  discard block
 block discarded – undo
782 782
 		/**
783 783
 		 * Parse incoming $args into an array and merge it with $defaults
784 784
 		 */
785
-		$args   = wp_parse_args( $args, $defaults );
785
+		$args   = wp_parse_args($args, $defaults);
786 786
 		$output = '';
787 787
 
788 788
 		// for now lets hide floating labels
789
-		if ( $args['label_type'] == 'floating' ) {
789
+		if ($args['label_type'] == 'floating') {
790 790
 			$args['label_type'] = 'hidden';
791 791
 		}
792 792
 
@@ -797,31 +797,31 @@  discard block
 block discarded – undo
797 797
 		$label_after = $args['label_after'];
798 798
 
799 799
 		// floating labels need label after
800
-		if ( $args['label_type'] == 'floating' ) {
800
+		if ($args['label_type'] == 'floating') {
801 801
 			$label_after         = true;
802 802
 			$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
803 803
 		}
804 804
 
805 805
 		// Maybe setup select2
806 806
 		$is_select2 = false;
807
-		if ( ! empty( $args['select2'] ) ) {
807
+		if (!empty($args['select2'])) {
808 808
 			$args['class'] .= ' aui-select2';
809 809
 			$is_select2 = true;
810
-		} elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) {
810
+		} elseif (strpos($args['class'], 'aui-select2') !== false) {
811 811
 			$is_select2 = true;
812 812
 		}
813 813
 
814 814
 		// select2 tags
815
-		if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason
815
+		if (!empty($args['select2']) && $args['select2'] === 'tags') { // triple equals needed here for some reason
816 816
 			$args['data-tags']             = 'true';
817 817
 			$args['data-token-separators'] = "[',']";
818 818
 			$args['multiple']              = true;
819 819
 		}
820 820
 
821 821
 		// select2 placeholder
822
-		if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) {
823
-			$args['data-placeholder'] = esc_attr( $args['placeholder'] );
824
-			$args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true;
822
+		if ($is_select2 && isset($args['placeholder']) && '' != $args['placeholder'] && empty($args['data-placeholder'])) {
823
+			$args['data-placeholder'] = esc_attr($args['placeholder']);
824
+			$args['data-allow-clear'] = isset($args['data-allow-clear']) ? (bool) $args['data-allow-clear'] : true;
825 825
 		}
826 826
 
827 827
 
@@ -833,61 +833,61 @@  discard block
 block discarded – undo
833 833
 //		}
834 834
 
835 835
 		// Set hidden input to save empty value for multiselect.
836
-		if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) {
837
-			$output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value=""/>';
836
+		if (!empty($args['multiple']) && !empty($args['name'])) {
837
+			$output .= '<input type="hidden" ' . AUI_Component_Helper::name($args['name']) . ' value=""/>';
838 838
 		}
839 839
 
840 840
 		// open/type
841 841
 		$output .= '<select ';
842 842
 
843 843
 		// style
844
-		if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) {
844
+		if ($is_select2 && !($args['input_group_left'] || $args['input_group_right'])) {
845 845
 			$output .= " style='width:100%;' ";
846 846
 		}
847 847
 
848 848
 		// element require
849
-		if ( ! empty( $args['element_require'] ) ) {
850
-			$output .= AUI_Component_Helper::element_require( $args['element_require'] );
849
+		if (!empty($args['element_require'])) {
850
+			$output .= AUI_Component_Helper::element_require($args['element_require']);
851 851
 			$args['class'] .= " aui-conditional-field";
852 852
 		}
853 853
 
854 854
 		// class
855
-		$class = ! empty( $args['class'] ) ? $args['class'] : '';
856
-		$output .= AUI_Component_Helper::class_attr( 'custom-select ' . $class );
855
+		$class = !empty($args['class']) ? $args['class'] : '';
856
+		$output .= AUI_Component_Helper::class_attr('custom-select ' . $class);
857 857
 
858 858
 		// name
859
-		if ( ! empty( $args['name'] ) ) {
860
-			$output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] );
859
+		if (!empty($args['name'])) {
860
+			$output .= AUI_Component_Helper::name($args['name'], $args['multiple']);
861 861
 		}
862 862
 
863 863
 		// id
864
-		if ( ! empty( $args['id'] ) ) {
865
-			$output .= AUI_Component_Helper::id( $args['id'] );
864
+		if (!empty($args['id'])) {
865
+			$output .= AUI_Component_Helper::id($args['id']);
866 866
 		}
867 867
 
868 868
 		// title
869
-		if ( ! empty( $args['title'] ) ) {
870
-			$output .= AUI_Component_Helper::title( $args['title'] );
869
+		if (!empty($args['title'])) {
870
+			$output .= AUI_Component_Helper::title($args['title']);
871 871
 		}
872 872
 
873 873
 		// data-attributes
874
-		$output .= AUI_Component_Helper::data_attributes( $args );
874
+		$output .= AUI_Component_Helper::data_attributes($args);
875 875
 
876 876
 		// aria-attributes
877
-		$output .= AUI_Component_Helper::aria_attributes( $args );
877
+		$output .= AUI_Component_Helper::aria_attributes($args);
878 878
 
879 879
 		// extra attributes
880
-		if ( ! empty( $args['extra_attributes'] ) ) {
881
-			$output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
880
+		if (!empty($args['extra_attributes'])) {
881
+			$output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
882 882
 		}
883 883
 
884 884
 		// required
885
-		if ( ! empty( $args['required'] ) ) {
885
+		if (!empty($args['required'])) {
886 886
 			$output .= ' required ';
887 887
 		}
888 888
 
889 889
 		// multiple
890
-		if ( ! empty( $args['multiple'] ) ) {
890
+		if (!empty($args['multiple'])) {
891 891
 			$output .= ' multiple ';
892 892
 		}
893 893
 
@@ -895,50 +895,50 @@  discard block
 block discarded – undo
895 895
 		$output .= ' >';
896 896
 
897 897
 		// placeholder
898
-		if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) {
899
-			$output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>';
900
-		} elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) {
898
+		if (isset($args['placeholder']) && '' != $args['placeholder'] && !$is_select2) {
899
+			$output .= '<option value="" disabled selected hidden>' . esc_attr($args['placeholder']) . '</option>';
900
+		} elseif ($is_select2 && !empty($args['placeholder'])) {
901 901
 			$output .= "<option></option>"; // select2 needs an empty select to fill the placeholder
902 902
 		}
903 903
 
904 904
 		// Options
905
-		if ( ! empty( $args['options'] ) ) {
905
+		if (!empty($args['options'])) {
906 906
 
907
-			if ( ! is_array( $args['options'] ) ) {
907
+			if (!is_array($args['options'])) {
908 908
 				$output .= $args['options']; // not the preferred way but an option
909 909
 			} else {
910
-				foreach ( $args['options'] as $val => $name ) {
910
+				foreach ($args['options'] as $val => $name) {
911 911
 					$selected = '';
912
-					if ( is_array( $name ) ) {
913
-						if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) {
914
-							$option_label = isset( $name['label'] ) ? $name['label'] : '';
912
+					if (is_array($name)) {
913
+						if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) {
914
+							$option_label = isset($name['label']) ? $name['label'] : '';
915 915
 
916
-							$output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>';
916
+							$output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>';
917 917
 						} else {
918
-							$option_label = isset( $name['label'] ) ? $name['label'] : '';
919
-							$option_value = isset( $name['value'] ) ? $name['value'] : '';
920
-							$extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : '';
921
-							if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) {
922
-								$selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : "";
923
-							} elseif ( ! empty( $args['value'] ) ) {
924
-								$selected = selected( $option_value, stripslashes_deep( $args['value'] ), false );
925
-							} elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) {
926
-								$selected = selected( $option_value, $args['value'], false );
918
+							$option_label = isset($name['label']) ? $name['label'] : '';
919
+							$option_value = isset($name['value']) ? $name['value'] : '';
920
+							$extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes($name['extra_attributes']) : '';
921
+							if (!empty($args['multiple']) && !empty($args['value']) && is_array($args['value'])) {
922
+								$selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : "";
923
+							} elseif (!empty($args['value'])) {
924
+								$selected = selected($option_value, stripslashes_deep($args['value']), false);
925
+							} elseif (empty($args['value']) && $args['value'] === $option_value) {
926
+								$selected = selected($option_value, $args['value'], false);
927 927
 							}
928 928
 
929
-							$output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>';
929
+							$output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . ' ' . $extra_attributes . '>' . $option_label . '</option>';
930 930
 						}
931 931
 					} else {
932
-						if ( ! empty( $args['value'] ) ) {
933
-							if ( is_array( $args['value'] ) ) {
934
-								$selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : '';
935
-							} elseif ( ! empty( $args['value'] ) ) {
936
-								$selected = selected( $args['value'], $val, false );
932
+						if (!empty($args['value'])) {
933
+							if (is_array($args['value'])) {
934
+								$selected = in_array($val, $args['value']) ? 'selected="selected"' : '';
935
+							} elseif (!empty($args['value'])) {
936
+								$selected = selected($args['value'], $val, false);
937 937
 							}
938
-						} elseif ( $args['value'] === $val ) {
939
-							$selected = selected( $args['value'], $val, false );
938
+						} elseif ($args['value'] === $val) {
939
+							$selected = selected($args['value'], $val, false);
940 940
 						}
941
-						$output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>';
941
+						$output .= '<option value="' . esc_attr($val) . '" ' . $selected . '>' . esc_attr($name) . '</option>';
942 942
 					}
943 943
 				}
944 944
 			}
@@ -951,8 +951,8 @@  discard block
 block discarded – undo
951 951
 		$label = '';
952 952
 		$help_text = '';
953 953
 		// label
954
-		if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
955
-		} elseif ( ! empty( $args['label'] ) && ! $label_after ) {
954
+		if (!empty($args['label']) && is_array($args['label'])) {
955
+		} elseif (!empty($args['label']) && !$label_after) {
956 956
 			$label_args = array(
957 957
 				'title'      => $args['label'],
958 958
 				'for'        => $args['id'],
@@ -960,49 +960,49 @@  discard block
 block discarded – undo
960 960
 				'label_type' => $args['label_type'],
961 961
 				'label_col'  => $args['label_col']
962 962
 			);
963
-			$label = self::label( $label_args );
963
+			$label = self::label($label_args);
964 964
 		}
965 965
 
966 966
 		// help text
967
-		if ( ! empty( $args['help_text'] ) ) {
968
-			$help_text = AUI_Component_Helper::help_text( $args['help_text'] );
967
+		if (!empty($args['help_text'])) {
968
+			$help_text = AUI_Component_Helper::help_text($args['help_text']);
969 969
 		}
970 970
 
971 971
 		// input group wraps
972
-		if ( $args['input_group_left'] || $args['input_group_right'] ) {
973
-			$w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
974
-			if ( $args['input_group_left'] ) {
975
-				$output = self::wrap( array(
972
+		if ($args['input_group_left'] || $args['input_group_right']) {
973
+			$w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : '';
974
+			if ($args['input_group_left']) {
975
+				$output = self::wrap(array(
976 976
 					'content'                 => $output,
977 977
 					'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
978 978
 					'input_group_left'        => $args['input_group_left'],
979 979
 					'input_group_left_inside' => $args['input_group_left_inside']
980
-				) );
980
+				));
981 981
 			}
982
-			if ( $args['input_group_right'] ) {
983
-				$output = self::wrap( array(
982
+			if ($args['input_group_right']) {
983
+				$output = self::wrap(array(
984 984
 					'content'                  => $output,
985 985
 					'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
986 986
 					'input_group_right'        => $args['input_group_right'],
987 987
 					'input_group_right_inside' => $args['input_group_right_inside']
988
-				) );
988
+				));
989 989
 			}
990 990
 
991 991
 		}
992 992
 
993
-		if ( ! $label_after ) {
993
+		if (!$label_after) {
994 994
 			$output .= $help_text;
995 995
 		}
996 996
 
997 997
 
998
-		if ( $args['label_type'] == 'horizontal' ) {
999
-			$output = self::wrap( array(
998
+		if ($args['label_type'] == 'horizontal') {
999
+			$output = self::wrap(array(
1000 1000
 				'content' => $output,
1001
-				'class'   => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' )
1002
-			) );
1001
+				'class'   => AUI_Component_Helper::get_column_class($args['label_col'], 'input')
1002
+			));
1003 1003
 		}
1004 1004
 
1005
-		if ( ! $label_after ) {
1005
+		if (!$label_after) {
1006 1006
 			$output = $label . $output;
1007 1007
 		}
1008 1008
 
@@ -1013,16 +1013,16 @@  discard block
 block discarded – undo
1013 1013
 
1014 1014
 
1015 1015
 		// wrap
1016
-		if ( ! $args['no_wrap'] ) {
1016
+		if (!$args['no_wrap']) {
1017 1017
 			$wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group';
1018
-			$wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
1019
-			$output     = self::wrap( array(
1018
+			$wrap_class = !empty($args['wrap_class']) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
1019
+			$output     = self::wrap(array(
1020 1020
 				'content'         => $output,
1021 1021
 				'class'           => $wrap_class,
1022 1022
 				'element_require' => $args['element_require'],
1023 1023
 				'argument_id'     => $args['id'],
1024 1024
 				'wrap_attributes' => $args['wrap_attributes'],
1025
-			) );
1025
+			));
1026 1026
 		}
1027 1027
 
1028 1028
 
@@ -1036,7 +1036,7 @@  discard block
 block discarded – undo
1036 1036
 	 *
1037 1037
 	 * @return string The rendered component.
1038 1038
 	 */
1039
-	public static function radio( $args = array() ) {
1039
+	public static function radio($args = array()) {
1040 1040
 		$defaults = array(
1041 1041
 			'class'            => '',
1042 1042
 			'wrap_class'       => '',
@@ -1066,10 +1066,10 @@  discard block
 block discarded – undo
1066 1066
 		/**
1067 1067
 		 * Parse incoming $args into an array and merge it with $defaults
1068 1068
 		 */
1069
-		$args = wp_parse_args( $args, $defaults );
1069
+		$args = wp_parse_args($args, $defaults);
1070 1070
 
1071 1071
 		// for now lets use horizontal for floating
1072
-		if ( $args['label_type'] == 'floating' ) {
1072
+		if ($args['label_type'] == 'floating') {
1073 1073
 			$args['label_type'] = 'horizontal';
1074 1074
 		}
1075 1075
 
@@ -1084,47 +1084,47 @@  discard block
 block discarded – undo
1084 1084
 
1085 1085
 
1086 1086
 		// label before
1087
-		if ( ! empty( $args['label'] ) ) {
1088
-			$output .= self::label( $label_args, 'radio' );
1087
+		if (!empty($args['label'])) {
1088
+			$output .= self::label($label_args, 'radio');
1089 1089
 		}
1090 1090
 
1091 1091
 		// maybe horizontal label
1092
-		if ( $args['label_type'] == 'horizontal' ) {
1093
-			$input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
1092
+		if ($args['label_type'] == 'horizontal') {
1093
+			$input_col = AUI_Component_Helper::get_column_class($args['label_col'], 'input');
1094 1094
 			$output .= '<div class="' . $input_col . '">';
1095 1095
 		}
1096 1096
 
1097
-		if ( ! empty( $args['options'] ) ) {
1097
+		if (!empty($args['options'])) {
1098 1098
 			$count = 0;
1099
-			foreach ( $args['options'] as $value => $label ) {
1099
+			foreach ($args['options'] as $value => $label) {
1100 1100
 				$option_args            = $args;
1101 1101
 				$option_args['value']   = $value;
1102 1102
 				$option_args['label']   = $label;
1103 1103
 				$option_args['checked'] = $value == $args['value'] ? true : false;
1104
-				$output .= self::radio_option( $option_args, $count );
1105
-				$count ++;
1104
+				$output .= self::radio_option($option_args, $count);
1105
+				$count++;
1106 1106
 			}
1107 1107
 		}
1108 1108
 
1109 1109
 		// help text
1110
-		$help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : '';
1110
+		$help_text = !empty($args['help_text']) ? AUI_Component_Helper::help_text($args['help_text']) : '';
1111 1111
 		$output .= $help_text;
1112 1112
 
1113 1113
 		// maybe horizontal label
1114
-		if ( $args['label_type'] == 'horizontal' ) {
1114
+		if ($args['label_type'] == 'horizontal') {
1115 1115
 			$output .= '</div>';
1116 1116
 		}
1117 1117
 
1118 1118
 		// wrap
1119 1119
 		$wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group';
1120
-		$wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
1121
-		$output     = self::wrap( array(
1120
+		$wrap_class = !empty($args['wrap_class']) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
1121
+		$output     = self::wrap(array(
1122 1122
 			'content'         => $output,
1123 1123
 			'class'           => $wrap_class,
1124 1124
 			'element_require' => $args['element_require'],
1125 1125
 			'argument_id'     => $args['id'],
1126 1126
 			'wrap_attributes' => $args['wrap_attributes'],
1127
-		) );
1127
+		));
1128 1128
 
1129 1129
 
1130 1130
 		return $output;
@@ -1137,7 +1137,7 @@  discard block
 block discarded – undo
1137 1137
 	 *
1138 1138
 	 * @return string The rendered component.
1139 1139
 	 */
1140
-	public static function radio_option( $args = array(), $count = '' ) {
1140
+	public static function radio_option($args = array(), $count = '') {
1141 1141
 		$defaults = array(
1142 1142
 			'class'            => '',
1143 1143
 			'id'               => '',
@@ -1155,7 +1155,7 @@  discard block
 block discarded – undo
1155 1155
 		/**
1156 1156
 		 * Parse incoming $args into an array and merge it with $defaults
1157 1157
 		 */
1158
-		$args = wp_parse_args( $args, $defaults );
1158
+		$args = wp_parse_args($args, $defaults);
1159 1159
 
1160 1160
 		$output = '';
1161 1161
 
@@ -1166,43 +1166,43 @@  discard block
 block discarded – undo
1166 1166
 		$output .= ' class="form-check-input" ';
1167 1167
 
1168 1168
 		// name
1169
-		if ( ! empty( $args['name'] ) ) {
1170
-			$output .= AUI_Component_Helper::name( $args['name'] );
1169
+		if (!empty($args['name'])) {
1170
+			$output .= AUI_Component_Helper::name($args['name']);
1171 1171
 		}
1172 1172
 
1173 1173
 		// id
1174
-		if ( ! empty( $args['id'] ) ) {
1175
-			$output .= AUI_Component_Helper::id( $args['id'] . $count );
1174
+		if (!empty($args['id'])) {
1175
+			$output .= AUI_Component_Helper::id($args['id'] . $count);
1176 1176
 		}
1177 1177
 
1178 1178
 		// title
1179
-		if ( ! empty( $args['title'] ) ) {
1180
-			$output .= AUI_Component_Helper::title( $args['title'] );
1179
+		if (!empty($args['title'])) {
1180
+			$output .= AUI_Component_Helper::title($args['title']);
1181 1181
 		}
1182 1182
 
1183 1183
 		// value
1184
-		if ( isset( $args['value'] ) ) {
1185
-			$output .= AUI_Component_Helper::value( $args['value'] );
1184
+		if (isset($args['value'])) {
1185
+			$output .= AUI_Component_Helper::value($args['value']);
1186 1186
 		}
1187 1187
 
1188 1188
 		// checked, for radio and checkboxes
1189
-		if ( $args['checked'] ) {
1189
+		if ($args['checked']) {
1190 1190
 			$output .= ' checked ';
1191 1191
 		}
1192 1192
 
1193 1193
 		// data-attributes
1194
-		$output .= AUI_Component_Helper::data_attributes( $args );
1194
+		$output .= AUI_Component_Helper::data_attributes($args);
1195 1195
 
1196 1196
 		// aria-attributes
1197
-		$output .= AUI_Component_Helper::aria_attributes( $args );
1197
+		$output .= AUI_Component_Helper::aria_attributes($args);
1198 1198
 
1199 1199
 		// extra attributes
1200
-		if ( ! empty( $args['extra_attributes'] ) ) {
1201
-			$output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
1200
+		if (!empty($args['extra_attributes'])) {
1201
+			$output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
1202 1202
 		}
1203 1203
 
1204 1204
 		// required
1205
-		if ( ! empty( $args['required'] ) ) {
1205
+		if (!empty($args['required'])) {
1206 1206
 			$output .= ' required ';
1207 1207
 		}
1208 1208
 
@@ -1210,38 +1210,38 @@  discard block
 block discarded – undo
1210 1210
 		$output .= ' >';
1211 1211
 
1212 1212
 		// label
1213
-		if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
1214
-		} elseif ( ! empty( $args['label'] ) ) {
1215
-			$output .= self::label( array(
1213
+		if (!empty($args['label']) && is_array($args['label'])) {
1214
+		} elseif (!empty($args['label'])) {
1215
+			$output .= self::label(array(
1216 1216
 				'title' => $args['label'],
1217 1217
 				'for'   => $args['id'] . $count,
1218 1218
 				'class' => 'form-check-label'
1219
-			), 'radio' );
1219
+			), 'radio');
1220 1220
 		}
1221 1221
 
1222 1222
 		// wrap
1223
-		if ( ! $args['no_wrap'] ) {
1223
+		if (!$args['no_wrap']) {
1224 1224
 			$wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check';
1225 1225
 
1226 1226
 			// Unique wrap class
1227 1227
 			$uniq_class = 'fwrap';
1228
-			if ( ! empty( $args['name'] ) ) {
1228
+			if (!empty($args['name'])) {
1229 1229
 				$uniq_class .= '-' . $args['name'];
1230
-			} else if ( ! empty( $args['id'] ) ) {
1230
+			} else if (!empty($args['id'])) {
1231 1231
 				$uniq_class .= '-' . $args['id'];
1232 1232
 			}
1233 1233
 
1234
-			if ( isset( $args['value'] ) || $args['value'] !== "" ) {
1234
+			if (isset($args['value']) || $args['value'] !== "") {
1235 1235
 				$uniq_class .= '-' . $args['value'];
1236 1236
 			} else {
1237 1237
 				$uniq_class .= '-' . $count;
1238 1238
 			}
1239
-			$wrap_class .= ' ' . sanitize_html_class( $uniq_class );
1239
+			$wrap_class .= ' ' . sanitize_html_class($uniq_class);
1240 1240
 
1241
-			$output = self::wrap( array(
1241
+			$output = self::wrap(array(
1242 1242
 				'content' => $output,
1243 1243
 				'class'   => $wrap_class
1244
-			) );
1244
+			));
1245 1245
 		}
1246 1246
 
1247 1247
 		return $output;
Please login to merge, or discard this patch.
Braces   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 			if ( $args['size'] == 'lg' || $args['size'] == 'large' ) {
96 96
 				$size = 'lg';
97 97
 				$args['class'] .= ' form-control-lg';
98
-			}elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) {
98
+			} elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) {
99 99
 				$size = 'sm';
100 100
 				$args['class'] .= ' form-control-sm';
101 101
 			}
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
 						$help_text = '';
237 237
 						//$label_args['class'] .= ' d-inline ';
238 238
 						$args['wrap_class'] .= ' align-items-center ';
239
-					}else{
239
+					} else{
240 240
 
241 241
 					}
242 242
 
Please login to merge, or discard this patch.