Passed
Push — master ( 6086f2...9dee83 )
by Kiran
09:50 queued 20s
created
includes/payments/class-getpaid-payment-form-submission-taxes.php 1 patch
Indentation   +244 added lines, -244 removed lines patch added patch discarded remove patch
@@ -12,257 +12,257 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Taxes {
14 14
 
15
-	/**
16
-	 * Submission taxes.
17
-	 * @var array
18
-	 */
19
-	public $taxes = array();
20
-
21
-	/**
22
-	 * Whether or not we should skip the taxes.
23
-	 * @var bool
24
-	 */
25
-	protected $skip_taxes = false;
15
+    /**
16
+     * Submission taxes.
17
+     * @var array
18
+     */
19
+    public $taxes = array();
20
+
21
+    /**
22
+     * Whether or not we should skip the taxes.
23
+     * @var bool
24
+     */
25
+    protected $skip_taxes = false;
26
+
27
+    /**
28
+     * Class constructor
29
+     *
30
+     * @param GetPaid_Payment_Form_Submission $submission
31
+     */
32
+    public function __construct( $submission ) {
33
+        // Validate VAT number.
34
+        $this->validate_vat( $submission );
35
+
36
+        if ( $this->skip_taxes ) {
37
+            return;
38
+        }
39
+
40
+        foreach ( $submission->get_items() as $item ) {
41
+            $this->process_item_tax( $item, $submission );
42
+        }
43
+
44
+        // Process any existing invoice taxes.
45
+        if ( $submission->has_invoice() ) {
46
+            $invoice = $submission->get_invoice();
47
+            $invoice = $this->refresh_totals( $invoice, $submission );
48
+
49
+            $this->taxes = array_replace( $invoice->get_taxes(), $this->taxes );
50
+        }
51
+    }
52
+
53
+    /**
54
+     * Maybe process tax.
55
+     *
56
+     * @since 1.0.19
57
+     * @param GetPaid_Form_Item $item
58
+     * @param GetPaid_Payment_Form_Submission $submission
59
+     */
60
+    public function process_item_tax( $item, $submission ) {
61
+
62
+        $rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
63
+        $rates    = getpaid_filter_item_tax_rates( $item, $rates );
64
+        $taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
65
+        $r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
66
+
67
+        foreach ( $taxes as $name => $amount ) {
68
+            $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
69
+            $tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
70
+
71
+            $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] );
72
+
73
+            if ( ! isset( $this->taxes[ $name ] ) ) {
74
+                $this->taxes[ $name ] = $tax;
75
+                continue;
76
+            }
77
+
78
+            $this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
79
+            $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
80
+
81
+        }
82
+
83
+    }
26 84
 
27 85
     /**
28
-	 * Class constructor
29
-	 *
30
-	 * @param GetPaid_Payment_Form_Submission $submission
31
-	 */
32
-	public function __construct( $submission ) {
33
-		// Validate VAT number.
34
-		$this->validate_vat( $submission );
35
-
36
-		if ( $this->skip_taxes ) {
37
-			return;
38
-		}
39
-
40
-		foreach ( $submission->get_items() as $item ) {
41
-			$this->process_item_tax( $item, $submission );
42
-		}
43
-
44
-		// Process any existing invoice taxes.
45
-		if ( $submission->has_invoice() ) {
46
-			$invoice = $submission->get_invoice();
47
-			$invoice = $this->refresh_totals( $invoice, $submission );
48
-
49
-			$this->taxes = array_replace( $invoice->get_taxes(), $this->taxes );
50
-		}
51
-	}
52
-
53
-	/**
54
-	 * Maybe process tax.
55
-	 *
56
-	 * @since 1.0.19
57
-	 * @param GetPaid_Form_Item $item
58
-	 * @param GetPaid_Payment_Form_Submission $submission
59
-	 */
60
-	public function process_item_tax( $item, $submission ) {
61
-
62
-		$rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
63
-		$rates    = getpaid_filter_item_tax_rates( $item, $rates );
64
-		$taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
65
-		$r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
66
-
67
-		foreach ( $taxes as $name => $amount ) {
68
-			$recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
69
-			$tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
70
-
71
-			$item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] );
72
-
73
-			if ( ! isset( $this->taxes[ $name ] ) ) {
74
-				$this->taxes[ $name ] = $tax;
75
-				continue;
76
-			}
77
-
78
-			$this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
79
-			$this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
80
-
81
-		}
82
-
83
-	}
84
-
85
-	/**
86
-	 * Checks if the submission has a digital item.
87
-	 *
88
-	 * @param GetPaid_Payment_Form_Submission $submission
89
-	 * @since 1.0.19
90
-	 * @return bool
91
-	 */
92
-	public function has_digital_item( $submission ) {
93
-
94
-		foreach ( $submission->get_items() as $item ) {
95
-
96
-			if ( 'digital' == $item->get_vat_rule() ) {
97
-				return true;
98
-			}
86
+     * Checks if the submission has a digital item.
87
+     *
88
+     * @param GetPaid_Payment_Form_Submission $submission
89
+     * @since 1.0.19
90
+     * @return bool
91
+     */
92
+    public function has_digital_item( $submission ) {
93
+
94
+        foreach ( $submission->get_items() as $item ) {
95
+
96
+            if ( 'digital' == $item->get_vat_rule() ) {
97
+                return true;
98
+            }
99 99
 }
100 100
 
101
-		return false;
102
-	}
103
-
104
-	/**
105
-	 * Checks if this is an eu store.
106
-	 *
107
-	 * @since 1.0.19
108
-	 * @return bool
109
-	 */
110
-	public static function is_eu_store() {
111
-		return self::is_eu_country( wpinv_get_default_country() );
112
-	}
113
-
114
-	/**
115
-	 * Checks if this is an eu country.
116
-	 *
117
-	 * @param string $country
118
-	 * @since 1.0.19
119
-	 * @return bool
120
-	 */
121
-	public static function is_eu_country( $country ) {
122
-		return getpaid_is_eu_state( $country );
123
-	}
124
-
125
-	/**
126
-	 * Checks if this is an eu purchase.
127
-	 *
128
-	 * @param string $customer_country
129
-	 * @since 1.0.19
130
-	 * @return bool
131
-	 */
132
-	public static function is_eu_transaction( $customer_country ) {
133
-		return self::is_eu_country( $customer_country ) && self::is_eu_store();
134
-	}
135
-
136
-	/**
137
-	 * Retrieves the vat number.
138
-	 *
139
-	 * @param GetPaid_Payment_Form_Submission $submission
140
-	 * @since 1.0.19
141
-	 * @return string
142
-	 */
143
-	public function get_vat_number( $submission ) {
144
-
145
-		// Retrieve from the posted number.
146
-		$vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
147
-		if ( ! is_null( $vat_number ) ) {
148
-			return wpinv_clean( $vat_number );
149
-		}
150
-
151
-		return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
152
-	}
153
-
154
-	/**
155
-	 * Retrieves the company.
156
-	 *
157
-	 * @param GetPaid_Payment_Form_Submission $submission
158
-	 * @since 1.0.19
159
-	 * @return string
160
-	 */
161
-	public function get_company( $submission ) {
162
-
163
-		// Retrieve from the posted data.
164
-		$company = $submission->get_field( 'wpinv_company', 'billing' );
165
-		if ( ! empty( $company ) ) {
166
-			return wpinv_clean( $company );
167
-		}
168
-
169
-		// Retrieve from the invoice.
170
-		return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
171
-	}
172
-
173
-	/**
174
-	 * Checks if we require a VAT number.
175
-	 *
176
-	 * @param bool $ip_in_eu Whether the customer IP is from the EU
177
-	 * @param bool $country_in_eu Whether the customer country is from the EU
178
-	 * @since 1.0.19
179
-	 * @return string
180
-	 */
181
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
182
-
183
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
184
-		$prevent_b2c = ! empty( $prevent_b2c );
185
-		$is_eu       = $ip_in_eu || $country_in_eu;
186
-
187
-		return $prevent_b2c && $is_eu;
188
-	}
189
-
190
-	/**
191
-	 * Validate VAT data.
192
-	 *
193
-	 * @param GetPaid_Payment_Form_Submission $submission
194
-	 * @since 1.0.19
195
-	 */
196
-	public function validate_vat( $submission ) {
197
-
198
-		$in_eu = $this->is_eu_transaction( $submission->country );
199
-
200
-		// Abort if we are not validating vat numbers.
201
-		if ( ! $in_eu ) {
101
+        return false;
102
+    }
103
+
104
+    /**
105
+     * Checks if this is an eu store.
106
+     *
107
+     * @since 1.0.19
108
+     * @return bool
109
+     */
110
+    public static function is_eu_store() {
111
+        return self::is_eu_country( wpinv_get_default_country() );
112
+    }
113
+
114
+    /**
115
+     * Checks if this is an eu country.
116
+     *
117
+     * @param string $country
118
+     * @since 1.0.19
119
+     * @return bool
120
+     */
121
+    public static function is_eu_country( $country ) {
122
+        return getpaid_is_eu_state( $country );
123
+    }
124
+
125
+    /**
126
+     * Checks if this is an eu purchase.
127
+     *
128
+     * @param string $customer_country
129
+     * @since 1.0.19
130
+     * @return bool
131
+     */
132
+    public static function is_eu_transaction( $customer_country ) {
133
+        return self::is_eu_country( $customer_country ) && self::is_eu_store();
134
+    }
135
+
136
+    /**
137
+     * Retrieves the vat number.
138
+     *
139
+     * @param GetPaid_Payment_Form_Submission $submission
140
+     * @since 1.0.19
141
+     * @return string
142
+     */
143
+    public function get_vat_number( $submission ) {
144
+
145
+        // Retrieve from the posted number.
146
+        $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
147
+        if ( ! is_null( $vat_number ) ) {
148
+            return wpinv_clean( $vat_number );
149
+        }
150
+
151
+        return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
152
+    }
153
+
154
+    /**
155
+     * Retrieves the company.
156
+     *
157
+     * @param GetPaid_Payment_Form_Submission $submission
158
+     * @since 1.0.19
159
+     * @return string
160
+     */
161
+    public function get_company( $submission ) {
162
+
163
+        // Retrieve from the posted data.
164
+        $company = $submission->get_field( 'wpinv_company', 'billing' );
165
+        if ( ! empty( $company ) ) {
166
+            return wpinv_clean( $company );
167
+        }
168
+
169
+        // Retrieve from the invoice.
170
+        return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
171
+    }
172
+
173
+    /**
174
+     * Checks if we require a VAT number.
175
+     *
176
+     * @param bool $ip_in_eu Whether the customer IP is from the EU
177
+     * @param bool $country_in_eu Whether the customer country is from the EU
178
+     * @since 1.0.19
179
+     * @return string
180
+     */
181
+    public function requires_vat( $ip_in_eu, $country_in_eu ) {
182
+
183
+        $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
184
+        $prevent_b2c = ! empty( $prevent_b2c );
185
+        $is_eu       = $ip_in_eu || $country_in_eu;
186
+
187
+        return $prevent_b2c && $is_eu;
188
+    }
189
+
190
+    /**
191
+     * Validate VAT data.
192
+     *
193
+     * @param GetPaid_Payment_Form_Submission $submission
194
+     * @since 1.0.19
195
+     */
196
+    public function validate_vat( $submission ) {
197
+
198
+        $in_eu = $this->is_eu_transaction( $submission->country );
199
+
200
+        // Abort if we are not validating vat numbers.
201
+        if ( ! $in_eu ) {
202 202
             return;
203
-		}
203
+        }
204 204
 
205
-		// Prepare variables.
206
-		$vat_number  = $this->get_vat_number( $submission );
207
-		$ip_country  = getpaid_get_ip_country();
205
+        // Prepare variables.
206
+        $vat_number  = $this->get_vat_number( $submission );
207
+        $ip_country  = getpaid_get_ip_country();
208 208
         $is_eu       = $this->is_eu_country( $submission->country );
209 209
         $is_ip_eu    = $this->is_eu_country( $ip_country );
210 210
 
211
-		// Maybe abort early for initial fetches.
212
-		if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
213
-			return;
214
-		}
215
-
216
-		// If we're preventing business to consumer purchases,
217
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
218
-
219
-			// Ensure that a vat number has been specified.
220
-			throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) );
221
-
222
-		}
223
-
224
-		if ( empty( $vat_number ) ) {
225
-			return;
226
-		}
227
-
228
-		if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
229
-			throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) );
230
-		}
231
-
232
-		if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
233
-			return;
234
-		}
235
-
236
-		$this->skip_taxes = true;
237
-	}
238
-
239
-	 /**
240
-	 * Refresh totals if country or region changed in payment form.
241
-	 *
242
-	 * @since 2.8.8
243
-	 *
244
-	 * @param object $invoice Invoice object.
245
-	 * @param GetPaid_Payment_Form_Submission $submission Payment form submission object.
246
-	 * @return object Invoice object.
247
-	 */
248
-	public function refresh_totals( $invoice, $submission ) {
249
-		if ( ! ( ! empty( $_POST['action'] ) && ( $_POST['action'] == 'wpinv_payment_form_refresh_prices' || $_POST['action'] == 'wpinv_payment_form' ) && isset( $_POST['billing']['wpinv_country'] ) ) ) {
250
-			return $invoice;
251
-		}
252
-
253
-		if ( ! ( ! $invoice->is_paid() && ! $invoice->is_refunded() && ! $invoice->is_held() ) ) {
254
-			return $invoice;
255
-		}
256
-
257
-		// Maybe check the country, state.
258
-		if ( $submission->country != $invoice->get_country() || $submission->state != $invoice->get_state() ) {
259
-			$invoice->set_country( sanitize_text_field( $submission->country ) );
260
-			$invoice->set_state( sanitize_text_field( $submission->state ) );
261
-
262
-			// Recalculate totals.
263
-			$invoice->recalculate_total();
264
-		}
265
-
266
-		return $invoice;
267
-	}
211
+        // Maybe abort early for initial fetches.
212
+        if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
213
+            return;
214
+        }
215
+
216
+        // If we're preventing business to consumer purchases,
217
+        if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
218
+
219
+            // Ensure that a vat number has been specified.
220
+            throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) );
221
+
222
+        }
223
+
224
+        if ( empty( $vat_number ) ) {
225
+            return;
226
+        }
227
+
228
+        if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
229
+            throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) );
230
+        }
231
+
232
+        if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
233
+            return;
234
+        }
235
+
236
+        $this->skip_taxes = true;
237
+    }
238
+
239
+        /**
240
+         * Refresh totals if country or region changed in payment form.
241
+         *
242
+         * @since 2.8.8
243
+         *
244
+         * @param object $invoice Invoice object.
245
+         * @param GetPaid_Payment_Form_Submission $submission Payment form submission object.
246
+         * @return object Invoice object.
247
+         */
248
+    public function refresh_totals( $invoice, $submission ) {
249
+        if ( ! ( ! empty( $_POST['action'] ) && ( $_POST['action'] == 'wpinv_payment_form_refresh_prices' || $_POST['action'] == 'wpinv_payment_form' ) && isset( $_POST['billing']['wpinv_country'] ) ) ) {
250
+            return $invoice;
251
+        }
252
+
253
+        if ( ! ( ! $invoice->is_paid() && ! $invoice->is_refunded() && ! $invoice->is_held() ) ) {
254
+            return $invoice;
255
+        }
256
+
257
+        // Maybe check the country, state.
258
+        if ( $submission->country != $invoice->get_country() || $submission->state != $invoice->get_state() ) {
259
+            $invoice->set_country( sanitize_text_field( $submission->country ) );
260
+            $invoice->set_state( sanitize_text_field( $submission->state ) );
261
+
262
+            // Recalculate totals.
263
+            $invoice->recalculate_total();
264
+        }
265
+
266
+        return $invoice;
267
+    }
268 268
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-post-types-admin.php 1 patch
Indentation   +795 added lines, -795 removed lines patch added patch discarded remove patch
@@ -13,738 +13,738 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Post_Types_Admin {
14 14
 
15 15
     /**
16
-	 * Hook in methods.
17
-	 */
18
-	public static function init() {
19
-
20
-		// Init metaboxes.
21
-		GetPaid_Metaboxes::init();
22
-
23
-		// Filter the post updated messages.
24
-		add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
25
-
26
-		// Filter post actions.
27
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
28
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 );
29
-
30
-		// Invoice table columns.
31
-		add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
32
-		add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
33
-		add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) );
34
-		add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 );
35
-
36
-		// Items table columns.
37
-		add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
38
-		add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
39
-		add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
40
-		add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
41
-		add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
42
-		add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
43
-
44
-		// Payment forms columns.
45
-		add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
46
-		add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
47
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
48
-
49
-		// Discount table columns.
50
-		add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
51
-		add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 );
52
-
53
-		// Deleting posts.
54
-		add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
55
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
56
-
57
-		add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 );
58
-	}
59
-
60
-	/**
61
-	 * Post updated messages.
62
-	 */
63
-	public static function post_updated_messages( $messages ) {
64
-		global $post;
65
-
66
-		$messages['wpi_discount'] = array(
67
-			0  => '',
68
-			1  => __( 'Discount updated.', 'invoicing' ),
69
-			2  => __( 'Custom field updated.', 'invoicing' ),
70
-			3  => __( 'Custom field deleted.', 'invoicing' ),
71
-			4  => __( 'Discount updated.', 'invoicing' ),
72
-			5  => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
73
-			6  => __( 'Discount updated.', 'invoicing' ),
74
-			7  => __( 'Discount saved.', 'invoicing' ),
75
-			8  => __( 'Discount submitted.', 'invoicing' ),
76
-			9  => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
77
-			10 => __( 'Discount draft updated.', 'invoicing' ),
78
-		);
79
-
80
-		$messages['wpi_payment_form'] = array(
81
-			0  => '',
82
-			1  => __( 'Payment Form updated.', 'invoicing' ),
83
-			2  => __( 'Custom field updated.', 'invoicing' ),
84
-			3  => __( 'Custom field deleted.', 'invoicing' ),
85
-			4  => __( 'Payment Form updated.', 'invoicing' ),
86
-			5  => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
87
-			6  => __( 'Payment Form updated.', 'invoicing' ),
88
-			7  => __( 'Payment Form saved.', 'invoicing' ),
89
-			8  => __( 'Payment Form submitted.', 'invoicing' ),
90
-			9  => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
91
-			10 => __( 'Payment Form draft updated.', 'invoicing' ),
92
-		);
93
-
94
-		return $messages;
95
-
96
-	}
97
-
98
-	/**
99
-	 * Post row actions.
100
-	 */
101
-	public static function post_row_actions( $actions, $post ) {
102
-
103
-		$post = get_post( $post );
104
-
105
-		// We do not want to edit the default payment form.
106
-		if ( 'wpi_payment_form' == $post->post_type ) {
107
-
108
-			if ( wpinv_get_default_payment_form() === $post->ID ) {
109
-				unset( $actions['trash'] );
110
-				unset( $actions['inline hide-if-no-js'] );
111
-			}
112
-
113
-			$actions['duplicate'] = sprintf(
114
-				'<a href="%1$s">%2$s</a>',
115
-				esc_url(
116
-					wp_nonce_url(
117
-						add_query_arg(
118
-							array(
119
-								'getpaid-admin-action' => 'duplicate_form',
120
-								'form_id'              => $post->ID,
121
-							)
122
-						),
123
-						'getpaid-nonce',
124
-						'getpaid-nonce'
125
-					)
126
-				),
127
-				esc_html( __( 'Duplicate', 'invoicing' ) )
128
-			);
129
-
130
-			$actions['reset'] = sprintf(
131
-				'<a href="%1$s" style="color: #800">%2$s</a>',
132
-				esc_url(
133
-					wp_nonce_url(
134
-						add_query_arg(
135
-							array(
136
-								'getpaid-admin-action' => 'reset_form_stats',
137
-								'form_id'              => $post->ID,
138
-							)
139
-						),
140
-						'getpaid-nonce',
141
-						'getpaid-nonce'
142
-					)
143
-				),
144
-				esc_html( __( 'Reset Stats', 'invoicing' ) )
145
-			);
146
-		}
147
-
148
-		// Link to item payment form.
149
-		if ( 'wpi_item' == $post->post_type ) {
150
-			if ( getpaid_item_type_supports( get_post_meta( $post->ID, '_wpinv_type', true ), 'buy_now' ) ) {
151
-				$actions['buy'] = sprintf(
152
-					'<a href="%1$s">%2$s</a>',
153
-					esc_url( getpaid_embed_url( false, $post->ID . '|0' ) ),
154
-					esc_html( __( 'Buy', 'invoicing' ) )
155
-				);
156
-			}
157
-		}
158
-
159
-		return $actions;
160
-	}
161
-
162
-	/**
16
+     * Hook in methods.
17
+     */
18
+    public static function init() {
19
+
20
+        // Init metaboxes.
21
+        GetPaid_Metaboxes::init();
22
+
23
+        // Filter the post updated messages.
24
+        add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
25
+
26
+        // Filter post actions.
27
+        add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
28
+        add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 );
29
+
30
+        // Invoice table columns.
31
+        add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
32
+        add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
33
+        add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) );
34
+        add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 );
35
+
36
+        // Items table columns.
37
+        add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
38
+        add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
39
+        add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
40
+        add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
41
+        add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
42
+        add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
43
+
44
+        // Payment forms columns.
45
+        add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
46
+        add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
47
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
48
+
49
+        // Discount table columns.
50
+        add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
51
+        add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 );
52
+
53
+        // Deleting posts.
54
+        add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
55
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
56
+
57
+        add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 );
58
+    }
59
+
60
+    /**
61
+     * Post updated messages.
62
+     */
63
+    public static function post_updated_messages( $messages ) {
64
+        global $post;
65
+
66
+        $messages['wpi_discount'] = array(
67
+            0  => '',
68
+            1  => __( 'Discount updated.', 'invoicing' ),
69
+            2  => __( 'Custom field updated.', 'invoicing' ),
70
+            3  => __( 'Custom field deleted.', 'invoicing' ),
71
+            4  => __( 'Discount updated.', 'invoicing' ),
72
+            5  => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
73
+            6  => __( 'Discount updated.', 'invoicing' ),
74
+            7  => __( 'Discount saved.', 'invoicing' ),
75
+            8  => __( 'Discount submitted.', 'invoicing' ),
76
+            9  => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
77
+            10 => __( 'Discount draft updated.', 'invoicing' ),
78
+        );
79
+
80
+        $messages['wpi_payment_form'] = array(
81
+            0  => '',
82
+            1  => __( 'Payment Form updated.', 'invoicing' ),
83
+            2  => __( 'Custom field updated.', 'invoicing' ),
84
+            3  => __( 'Custom field deleted.', 'invoicing' ),
85
+            4  => __( 'Payment Form updated.', 'invoicing' ),
86
+            5  => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
87
+            6  => __( 'Payment Form updated.', 'invoicing' ),
88
+            7  => __( 'Payment Form saved.', 'invoicing' ),
89
+            8  => __( 'Payment Form submitted.', 'invoicing' ),
90
+            9  => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
91
+            10 => __( 'Payment Form draft updated.', 'invoicing' ),
92
+        );
93
+
94
+        return $messages;
95
+
96
+    }
97
+
98
+    /**
99
+     * Post row actions.
100
+     */
101
+    public static function post_row_actions( $actions, $post ) {
102
+
103
+        $post = get_post( $post );
104
+
105
+        // We do not want to edit the default payment form.
106
+        if ( 'wpi_payment_form' == $post->post_type ) {
107
+
108
+            if ( wpinv_get_default_payment_form() === $post->ID ) {
109
+                unset( $actions['trash'] );
110
+                unset( $actions['inline hide-if-no-js'] );
111
+            }
112
+
113
+            $actions['duplicate'] = sprintf(
114
+                '<a href="%1$s">%2$s</a>',
115
+                esc_url(
116
+                    wp_nonce_url(
117
+                        add_query_arg(
118
+                            array(
119
+                                'getpaid-admin-action' => 'duplicate_form',
120
+                                'form_id'              => $post->ID,
121
+                            )
122
+                        ),
123
+                        'getpaid-nonce',
124
+                        'getpaid-nonce'
125
+                    )
126
+                ),
127
+                esc_html( __( 'Duplicate', 'invoicing' ) )
128
+            );
129
+
130
+            $actions['reset'] = sprintf(
131
+                '<a href="%1$s" style="color: #800">%2$s</a>',
132
+                esc_url(
133
+                    wp_nonce_url(
134
+                        add_query_arg(
135
+                            array(
136
+                                'getpaid-admin-action' => 'reset_form_stats',
137
+                                'form_id'              => $post->ID,
138
+                            )
139
+                        ),
140
+                        'getpaid-nonce',
141
+                        'getpaid-nonce'
142
+                    )
143
+                ),
144
+                esc_html( __( 'Reset Stats', 'invoicing' ) )
145
+            );
146
+        }
147
+
148
+        // Link to item payment form.
149
+        if ( 'wpi_item' == $post->post_type ) {
150
+            if ( getpaid_item_type_supports( get_post_meta( $post->ID, '_wpinv_type', true ), 'buy_now' ) ) {
151
+                $actions['buy'] = sprintf(
152
+                    '<a href="%1$s">%2$s</a>',
153
+                    esc_url( getpaid_embed_url( false, $post->ID . '|0' ) ),
154
+                    esc_html( __( 'Buy', 'invoicing' ) )
155
+                );
156
+            }
157
+        }
158
+
159
+        return $actions;
160
+    }
161
+
162
+    /**
163 163
      * Remove bulk edit option from admin side quote listing
164 164
      *
165 165
      * @since    1.0.0
166 166
      * @param array $actions post actions
167
-	 * @param WP_Post $post
167
+     * @param WP_Post $post
168 168
      * @return array $actions actions without edit option
169 169
      */
170 170
     public static function filter_invoice_row_actions( $actions, $post ) {
171 171
 
172 172
         if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
173 173
 
174
-			$actions = array();
175
-			$invoice = new WPInv_Invoice( $post );
176
-
177
-			$actions['edit'] = sprintf(
178
-				'<a href="%1$s">%2$s</a>',
179
-				esc_url( get_edit_post_link( $invoice->get_id() ) ),
180
-				esc_html( __( 'Edit', 'invoicing' ) )
181
-			);
182
-
183
-			if ( ! $invoice->is_draft() ) {
184
-
185
-				$actions['view'] = sprintf(
186
-					'<a href="%1$s">%2$s</a>',
187
-					esc_url( $invoice->get_view_url() ),
188
-					sprintf(
189
-						// translators: %s is the invoice type
190
-						esc_html__( 'View %s', 'invoicing' ),
191
-						getpaid_get_post_type_label( $invoice->get_post_type(), false )
192
-					)
193
-				);
194
-
195
-				$actions['send'] = sprintf(
196
-					'<a href="%1$s">%2$s</a>',
197
-					esc_url(
198
-						wp_nonce_url(
199
-							add_query_arg(
200
-								array(
201
-									'getpaid-admin-action' => 'send_invoice',
202
-									'invoice_id'           => $invoice->get_id(),
203
-								)
204
-							),
205
-							'getpaid-nonce',
206
-							'getpaid-nonce'
207
-						)
208
-					),
209
-					esc_html( __( 'Send to Customer', 'invoicing' ) )
210
-				);
211
-
212
-			}
213
-
214
-			$actions['duplicate'] = sprintf(
215
-				'<a href="%1$s">%2$s</a>',
216
-				esc_url(
217
-					wp_nonce_url(
218
-						add_query_arg(
219
-							array(
220
-								'getpaid-admin-action' => 'duplicate_invoice',
221
-								'invoice_id'           => $post->ID,
222
-							)
223
-						),
224
-						'getpaid-nonce',
225
-						'getpaid-nonce'
226
-					)
227
-				),
228
-				esc_html( __( 'Duplicate', 'invoicing' ) )
229
-			);
174
+            $actions = array();
175
+            $invoice = new WPInv_Invoice( $post );
176
+
177
+            $actions['edit'] = sprintf(
178
+                '<a href="%1$s">%2$s</a>',
179
+                esc_url( get_edit_post_link( $invoice->get_id() ) ),
180
+                esc_html( __( 'Edit', 'invoicing' ) )
181
+            );
182
+
183
+            if ( ! $invoice->is_draft() ) {
184
+
185
+                $actions['view'] = sprintf(
186
+                    '<a href="%1$s">%2$s</a>',
187
+                    esc_url( $invoice->get_view_url() ),
188
+                    sprintf(
189
+                        // translators: %s is the invoice type
190
+                        esc_html__( 'View %s', 'invoicing' ),
191
+                        getpaid_get_post_type_label( $invoice->get_post_type(), false )
192
+                    )
193
+                );
194
+
195
+                $actions['send'] = sprintf(
196
+                    '<a href="%1$s">%2$s</a>',
197
+                    esc_url(
198
+                        wp_nonce_url(
199
+                            add_query_arg(
200
+                                array(
201
+                                    'getpaid-admin-action' => 'send_invoice',
202
+                                    'invoice_id'           => $invoice->get_id(),
203
+                                )
204
+                            ),
205
+                            'getpaid-nonce',
206
+                            'getpaid-nonce'
207
+                        )
208
+                    ),
209
+                    esc_html( __( 'Send to Customer', 'invoicing' ) )
210
+                );
211
+
212
+            }
213
+
214
+            $actions['duplicate'] = sprintf(
215
+                '<a href="%1$s">%2$s</a>',
216
+                esc_url(
217
+                    wp_nonce_url(
218
+                        add_query_arg(
219
+                            array(
220
+                                'getpaid-admin-action' => 'duplicate_invoice',
221
+                                'invoice_id'           => $post->ID,
222
+                            )
223
+                        ),
224
+                        'getpaid-nonce',
225
+                        'getpaid-nonce'
226
+                    )
227
+                ),
228
+                esc_html( __( 'Duplicate', 'invoicing' ) )
229
+            );
230 230
 
231 231
         }
232 232
 
233 233
         return $actions;
234
-	}
235
-
236
-	/**
237
-	 * Returns an array of invoice table columns.
238
-	 */
239
-	public static function invoice_columns( $columns ) {
240
-
241
-		$columns = array(
242
-			'cb'           => $columns['cb'],
243
-			'number'       => __( 'Invoice', 'invoicing' ),
244
-			'customer'     => __( 'Customer', 'invoicing' ),
245
-			'invoice_date' => __( 'Created', 'invoicing' ),
246
-			'payment_date' => __( 'Completed', 'invoicing' ),
247
-			'amount'       => __( 'Amount', 'invoicing' ),
248
-			'recurring'    => __( 'Recurring', 'invoicing' ),
249
-			'status'       => __( 'Status', 'invoicing' ),
250
-		);
251
-
252
-		return apply_filters( 'wpi_invoice_table_columns', $columns );
253
-	}
254
-
255
-	/**
256
-	 * Displays invoice table columns.
257
-	 */
258
-	public static function display_invoice_columns( $column_name, $post_id ) {
259
-
260
-		$invoice = new WPInv_Invoice( $post_id );
261
-
262
-		switch ( $column_name ) {
263
-
264
-			case 'invoice_date':
265
-				$date_time = esc_attr( $invoice->get_created_date() );
266
-				$date      = esc_html( getpaid_format_date_value( $date_time, '&mdash;', true ) );
267
-				echo wp_kses_post( "<span title='$date_time'>$date</span>" );
268
-				break;
269
-
270
-			case 'payment_date':
271
-				if ( $invoice->is_paid() ) {
272
-					$date_time = esc_attr( $invoice->get_completed_date() );
273
-					$date      = esc_html( getpaid_format_date_value( $date_time, '&mdash;', true ) );
274
-					echo wp_kses_post( "<span title='$date_time'>$date</span>" );
275
-				} else {
276
-					echo '&mdash;';
277
-				}
278
-
279
-				break;
280
-
281
-			case 'amount':
282
-				$amount = $invoice->get_total();
283
-				$formated_amount = wp_kses_post( wpinv_price( $amount, $invoice->get_currency() ) );
284
-
285
-				if ( $invoice->is_refunded() ) {
286
-					$refunded_amount = wpinv_price( 0, $invoice->get_currency() );
287
-					echo wp_kses_post( "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>" );
288
-				} else {
289
-
290
-					$discount = $invoice->get_total_discount();
291
-
292
-					if ( ! empty( $discount ) ) {
293
-						$new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() );
294
-						echo wp_kses_post( "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>" );
295
-					} else {
296
-						echo wp_kses_post( $formated_amount );
297
-					}
298
-				}
299
-
300
-				break;
301
-
302
-			case 'status':
303
-				$status       = esc_html( $invoice->get_status() );
304
-				$status_label = esc_html( $invoice->get_status_nicename() );
305
-
306
-				// If it is paid, show the gateway title.
307
-				if ( $invoice->is_paid() ) {
308
-					$gateway = esc_html( $invoice->get_gateway_title() );
309
-					$gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), esc_html( $gateway ) );
310
-
311
-					echo wp_kses_post( "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>" );
312
-				} else {
313
-					echo wp_kses_post( "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>" );
314
-				}
315
-
316
-				// If it is not paid, display the overdue and view status.
317
-				if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
318
-
319
-					// Invoice view status.
320
-					if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
321
-						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="' . esc_attr__( 'Viewed by Customer', 'invoicing' ) . '"></i>';
322
-					} else {
323
-						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__( 'Not Viewed by Customer', 'invoicing' ) . '"></i>';
324
-					}
325
-
326
-					// Display the overview status.
327
-					if ( wpinv_get_option( 'overdue_active' ) ) {
328
-						$due_date = $invoice->get_due_date();
329
-						$fomatted = getpaid_format_date( $due_date );
330
-
331
-						if ( ! empty( $fomatted ) ) {
332
-							$date = wp_sprintf(
333
-								// translators: %s is the due date.
334
-								__( 'Due %s', 'invoicing' ),
335
-								$fomatted
336
-							);
337
-							echo wp_kses_post( "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>" );
338
-						}
339
-					}
340
-				}
341
-
342
-				break;
343
-
344
-			case 'recurring':
345
-				if ( $invoice->is_recurring() ) {
346
-					echo '<i class="fa fa-check" style="color:#43850a;"></i>';
347
-				} else {
348
-					echo '<i class="fa fa-times" style="color:#616161;"></i>';
349
-				}
350
-				break;
351
-
352
-			case 'number':
353
-				$edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
354
-				$invoice_number  = esc_html( $invoice->get_number() );
355
-				$invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
356
-
357
-				echo wp_kses_post( "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>" );
358
-
359
-				do_action( 'getpaid_admin_table_invoice_number_column', $invoice );
360
-				break;
361
-
362
-			case 'customer':
363
-				$customer_name = $invoice->get_user_full_name();
364
-
365
-				if ( empty( $customer_name ) ) {
366
-					$customer_name = $invoice->get_email();
367
-				}
368
-
369
-				if ( ! empty( $customer_name ) ) {
370
-					$customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
371
-					$view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
372
-					echo wp_kses_post( "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>" );
373
-				} else {
374
-					echo '<div>&mdash;</div>';
375
-				}
376
-
377
-				break;
378
-
379
-		}
380
-
381
-	}
382
-
383
-	/**
384
-	 * Displays invoice bulk actions.
385
-	 */
386
-	public static function invoice_bulk_actions( $actions ) {
387
-		$actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' );
388
-		return $actions;
389
-	}
390
-
391
-	/**
392
-	 * Processes invoice bulk actions.
393
-	 */
394
-	public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) {
395
-
396
-		if ( 'resend-invoice' === $action ) {
397
-			foreach ( $post_ids as $post_id ) {
398
-				getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true );
399
-			}
400
-		}
401
-
402
-		return $redirect_url;
403
-
404
-	}
405
-
406
-	/**
407
-	 * Returns an array of payment forms table columns.
408
-	 */
409
-	public static function payment_form_columns( $columns ) {
410
-
411
-		$columns = array(
412
-			'cb'        => $columns['cb'],
413
-			'title'     => __( 'Name', 'invoicing' ),
414
-			'shortcode' => __( 'Shortcode', 'invoicing' ),
415
-			'earnings'  => __( 'Revenue', 'invoicing' ),
416
-			'refunds'   => __( 'Refunded', 'invoicing' ),
417
-			'items'     => __( 'Items', 'invoicing' ),
418
-			'date'      => __( 'Date', 'invoicing' ),
419
-		);
420
-
421
-		return apply_filters( 'wpi_payment_form_table_columns', $columns );
422
-
423
-	}
424
-
425
-	/**
426
-	 * Displays payment form table columns.
427
-	 */
428
-	public static function display_payment_form_columns( $column_name, $post_id ) {
429
-
430
-		// Retrieve the payment form.
431
-		$form = new GetPaid_Payment_Form( $post_id );
432
-
433
-		switch ( $column_name ) {
434
-
435
-			case 'earnings':
436
-				echo wp_kses_post( wpinv_price( $form->get_earned() ) );
437
-				break;
438
-
439
-			case 'refunds':
440
-				echo wp_kses_post( wpinv_price( $form->get_refunded() ) );
441
-				break;
442
-
443
-			case 'refunds':
444
-				echo wp_kses_post( wpinv_price( $form->get_refunded() ) );
445
-				break;
446
-
447
-			case 'shortcode':
448
-				if ( $form->is_default() ) {
449
-					echo '&mdash;';
450
-				} else {
451
-					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
452
-				}
453
-
454
-				break;
234
+    }
235
+
236
+    /**
237
+     * Returns an array of invoice table columns.
238
+     */
239
+    public static function invoice_columns( $columns ) {
240
+
241
+        $columns = array(
242
+            'cb'           => $columns['cb'],
243
+            'number'       => __( 'Invoice', 'invoicing' ),
244
+            'customer'     => __( 'Customer', 'invoicing' ),
245
+            'invoice_date' => __( 'Created', 'invoicing' ),
246
+            'payment_date' => __( 'Completed', 'invoicing' ),
247
+            'amount'       => __( 'Amount', 'invoicing' ),
248
+            'recurring'    => __( 'Recurring', 'invoicing' ),
249
+            'status'       => __( 'Status', 'invoicing' ),
250
+        );
251
+
252
+        return apply_filters( 'wpi_invoice_table_columns', $columns );
253
+    }
254
+
255
+    /**
256
+     * Displays invoice table columns.
257
+     */
258
+    public static function display_invoice_columns( $column_name, $post_id ) {
259
+
260
+        $invoice = new WPInv_Invoice( $post_id );
261
+
262
+        switch ( $column_name ) {
263
+
264
+            case 'invoice_date':
265
+                $date_time = esc_attr( $invoice->get_created_date() );
266
+                $date      = esc_html( getpaid_format_date_value( $date_time, '&mdash;', true ) );
267
+                echo wp_kses_post( "<span title='$date_time'>$date</span>" );
268
+                break;
269
+
270
+            case 'payment_date':
271
+                if ( $invoice->is_paid() ) {
272
+                    $date_time = esc_attr( $invoice->get_completed_date() );
273
+                    $date      = esc_html( getpaid_format_date_value( $date_time, '&mdash;', true ) );
274
+                    echo wp_kses_post( "<span title='$date_time'>$date</span>" );
275
+                } else {
276
+                    echo '&mdash;';
277
+                }
278
+
279
+                break;
280
+
281
+            case 'amount':
282
+                $amount = $invoice->get_total();
283
+                $formated_amount = wp_kses_post( wpinv_price( $amount, $invoice->get_currency() ) );
284
+
285
+                if ( $invoice->is_refunded() ) {
286
+                    $refunded_amount = wpinv_price( 0, $invoice->get_currency() );
287
+                    echo wp_kses_post( "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>" );
288
+                } else {
289
+
290
+                    $discount = $invoice->get_total_discount();
291
+
292
+                    if ( ! empty( $discount ) ) {
293
+                        $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() );
294
+                        echo wp_kses_post( "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>" );
295
+                    } else {
296
+                        echo wp_kses_post( $formated_amount );
297
+                    }
298
+                }
299
+
300
+                break;
301
+
302
+            case 'status':
303
+                $status       = esc_html( $invoice->get_status() );
304
+                $status_label = esc_html( $invoice->get_status_nicename() );
305
+
306
+                // If it is paid, show the gateway title.
307
+                if ( $invoice->is_paid() ) {
308
+                    $gateway = esc_html( $invoice->get_gateway_title() );
309
+                    $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), esc_html( $gateway ) );
310
+
311
+                    echo wp_kses_post( "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>" );
312
+                } else {
313
+                    echo wp_kses_post( "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>" );
314
+                }
315
+
316
+                // If it is not paid, display the overdue and view status.
317
+                if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
318
+
319
+                    // Invoice view status.
320
+                    if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
321
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="' . esc_attr__( 'Viewed by Customer', 'invoicing' ) . '"></i>';
322
+                    } else {
323
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__( 'Not Viewed by Customer', 'invoicing' ) . '"></i>';
324
+                    }
325
+
326
+                    // Display the overview status.
327
+                    if ( wpinv_get_option( 'overdue_active' ) ) {
328
+                        $due_date = $invoice->get_due_date();
329
+                        $fomatted = getpaid_format_date( $due_date );
330
+
331
+                        if ( ! empty( $fomatted ) ) {
332
+                            $date = wp_sprintf(
333
+                                // translators: %s is the due date.
334
+                                __( 'Due %s', 'invoicing' ),
335
+                                $fomatted
336
+                            );
337
+                            echo wp_kses_post( "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>" );
338
+                        }
339
+                    }
340
+                }
341
+
342
+                break;
343
+
344
+            case 'recurring':
345
+                if ( $invoice->is_recurring() ) {
346
+                    echo '<i class="fa fa-check" style="color:#43850a;"></i>';
347
+                } else {
348
+                    echo '<i class="fa fa-times" style="color:#616161;"></i>';
349
+                }
350
+                break;
351
+
352
+            case 'number':
353
+                $edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
354
+                $invoice_number  = esc_html( $invoice->get_number() );
355
+                $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
356
+
357
+                echo wp_kses_post( "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>" );
358
+
359
+                do_action( 'getpaid_admin_table_invoice_number_column', $invoice );
360
+                break;
361
+
362
+            case 'customer':
363
+                $customer_name = $invoice->get_user_full_name();
364
+
365
+                if ( empty( $customer_name ) ) {
366
+                    $customer_name = $invoice->get_email();
367
+                }
368
+
369
+                if ( ! empty( $customer_name ) ) {
370
+                    $customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
371
+                    $view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
372
+                    echo wp_kses_post( "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>" );
373
+                } else {
374
+                    echo '<div>&mdash;</div>';
375
+                }
376
+
377
+                break;
455 378
 
456
-			case 'items':
457
-				$items = $form->get_items();
458
-
459
-				if ( $form->is_default() || empty( $items ) ) {
460
-					echo '&mdash;';
461
-					return;
462
-				}
463
-
464
-				$_items = array();
465
-
466
-				foreach ( $items as $item ) {
467
-					$url = $item->get_edit_url();
468
-
469
-					if ( empty( $url ) ) {
470
-						$_items[] = esc_html( $item->get_name() );
471
-					} else {
472
-						$_items[] = sprintf(
473
-							'<a href="%s">%s</a>',
474
-							esc_url( $url ),
475
-							esc_html( $item->get_name() )
476
-						);
477
-					}
379
+        }
380
+
381
+    }
382
+
383
+    /**
384
+     * Displays invoice bulk actions.
385
+     */
386
+    public static function invoice_bulk_actions( $actions ) {
387
+        $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' );
388
+        return $actions;
389
+    }
390
+
391
+    /**
392
+     * Processes invoice bulk actions.
393
+     */
394
+    public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) {
395
+
396
+        if ( 'resend-invoice' === $action ) {
397
+            foreach ( $post_ids as $post_id ) {
398
+                getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true );
399
+            }
400
+        }
401
+
402
+        return $redirect_url;
403
+
404
+    }
405
+
406
+    /**
407
+     * Returns an array of payment forms table columns.
408
+     */
409
+    public static function payment_form_columns( $columns ) {
410
+
411
+        $columns = array(
412
+            'cb'        => $columns['cb'],
413
+            'title'     => __( 'Name', 'invoicing' ),
414
+            'shortcode' => __( 'Shortcode', 'invoicing' ),
415
+            'earnings'  => __( 'Revenue', 'invoicing' ),
416
+            'refunds'   => __( 'Refunded', 'invoicing' ),
417
+            'items'     => __( 'Items', 'invoicing' ),
418
+            'date'      => __( 'Date', 'invoicing' ),
419
+        );
420
+
421
+        return apply_filters( 'wpi_payment_form_table_columns', $columns );
422
+
423
+    }
424
+
425
+    /**
426
+     * Displays payment form table columns.
427
+     */
428
+    public static function display_payment_form_columns( $column_name, $post_id ) {
429
+
430
+        // Retrieve the payment form.
431
+        $form = new GetPaid_Payment_Form( $post_id );
432
+
433
+        switch ( $column_name ) {
434
+
435
+            case 'earnings':
436
+                echo wp_kses_post( wpinv_price( $form->get_earned() ) );
437
+                break;
438
+
439
+            case 'refunds':
440
+                echo wp_kses_post( wpinv_price( $form->get_refunded() ) );
441
+                break;
442
+
443
+            case 'refunds':
444
+                echo wp_kses_post( wpinv_price( $form->get_refunded() ) );
445
+                break;
446
+
447
+            case 'shortcode':
448
+                if ( $form->is_default() ) {
449
+                    echo '&mdash;';
450
+                } else {
451
+                    echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
452
+                }
453
+
454
+                break;
455
+
456
+            case 'items':
457
+                $items = $form->get_items();
458
+
459
+                if ( $form->is_default() || empty( $items ) ) {
460
+                    echo '&mdash;';
461
+                    return;
462
+                }
463
+
464
+                $_items = array();
465
+
466
+                foreach ( $items as $item ) {
467
+                    $url = $item->get_edit_url();
468
+
469
+                    if ( empty( $url ) ) {
470
+                        $_items[] = esc_html( $item->get_name() );
471
+                    } else {
472
+                        $_items[] = sprintf(
473
+                            '<a href="%s">%s</a>',
474
+                            esc_url( $url ),
475
+                            esc_html( $item->get_name() )
476
+                        );
477
+                    }
478 478
 }
479 479
 
480
-				echo wp_kses_post( implode( '<br>', $_items ) );
480
+                echo wp_kses_post( implode( '<br>', $_items ) );
481
+
482
+                break;
483
+
484
+        }
485
+
486
+    }
487
+
488
+    /**
489
+     * Filters post states.
490
+     */
491
+    public static function filter_payment_form_state( $post_states, $post ) {
492
+
493
+        if ( 'wpi_payment_form' === $post->post_type && wpinv_get_default_payment_form() === $post->ID ) {
494
+            $post_states['default_form'] = __( 'Default Payment Form', 'invoicing' );
495
+        }
496
+
497
+        return $post_states;
498
+
499
+    }
500
+
501
+    /**
502
+     * Returns an array of coupon table columns.
503
+     */
504
+    public static function discount_columns( $columns ) {
505
+
506
+        $columns = array(
507
+            'cb'          => $columns['cb'],
508
+            'title'       => __( 'Name', 'invoicing' ),
509
+            'code'        => __( 'Code', 'invoicing' ),
510
+            'amount'      => __( 'Amount', 'invoicing' ),
511
+            'usage'       => __( 'Usage / Limit', 'invoicing' ),
512
+            'start_date'  => __( 'Start Date', 'invoicing' ),
513
+            'expiry_date' => __( 'Expiry Date', 'invoicing' ),
514
+        );
515
+
516
+        return apply_filters( 'wpi_discount_table_columns', $columns );
517
+    }
481 518
 
482
-				break;
519
+    /**
520
+     * Filters post states.
521
+     */
522
+    public static function filter_discount_state( $post_states, $post ) {
483 523
 
484
-		}
524
+        if ( 'wpi_discount' === $post->post_type ) {
485 525
 
486
-	}
526
+            $discount = new WPInv_Discount( $post );
487 527
 
488
-	/**
489
-	 * Filters post states.
490
-	 */
491
-	public static function filter_payment_form_state( $post_states, $post ) {
528
+            $status = $discount->is_expired() ? 'expired' : $discount->get_status();
492 529
 
493
-		if ( 'wpi_payment_form' === $post->post_type && wpinv_get_default_payment_form() === $post->ID ) {
494
-			$post_states['default_form'] = __( 'Default Payment Form', 'invoicing' );
495
-		}
530
+            if ( 'publish' !== $status ) {
531
+                return array(
532
+                    'discount_status' => wpinv_discount_status( $status ),
533
+                );
534
+            }
535
+
536
+            return array();
537
+
538
+        }
539
+
540
+        return $post_states;
496 541
 
497
-		return $post_states;
542
+    }
498 543
 
499
-	}
544
+    /**
545
+     * Returns an array of items table columns.
546
+     */
547
+    public static function item_columns( $columns ) {
548
+
549
+        $columns = array(
550
+            'cb'        => $columns['cb'],
551
+            'title'     => __( 'Name', 'invoicing' ),
552
+            'price'     => __( 'Price', 'invoicing' ),
553
+            'vat_rule'  => __( 'Tax Rule', 'invoicing' ),
554
+            'vat_class' => __( 'Tax Class', 'invoicing' ),
555
+            'type'      => __( 'Type', 'invoicing' ),
556
+            'shortcode' => __( 'Shortcode', 'invoicing' ),
557
+        );
558
+
559
+        if ( ! wpinv_use_taxes() ) {
560
+            unset( $columns['vat_rule'] );
561
+            unset( $columns['vat_class'] );
562
+        }
500 563
 
501
-	/**
502
-	 * Returns an array of coupon table columns.
503
-	 */
504
-	public static function discount_columns( $columns ) {
564
+        return apply_filters( 'wpi_item_table_columns', $columns );
565
+    }
505 566
 
506
-		$columns = array(
507
-			'cb'          => $columns['cb'],
508
-			'title'       => __( 'Name', 'invoicing' ),
509
-			'code'        => __( 'Code', 'invoicing' ),
510
-			'amount'      => __( 'Amount', 'invoicing' ),
511
-			'usage'       => __( 'Usage / Limit', 'invoicing' ),
512
-			'start_date'  => __( 'Start Date', 'invoicing' ),
513
-			'expiry_date' => __( 'Expiry Date', 'invoicing' ),
514
-		);
567
+    /**
568
+     * Returns an array of sortable items table columns.
569
+     */
570
+    public static function sortable_item_columns( $columns ) {
571
+
572
+        return array_merge(
573
+            $columns,
574
+            array(
575
+                'price'     => 'price',
576
+                'vat_rule'  => 'vat_rule',
577
+                'vat_class' => 'vat_class',
578
+                'type'      => 'type',
579
+            )
580
+        );
515 581
 
516
-		return apply_filters( 'wpi_discount_table_columns', $columns );
517
-	}
582
+    }
518 583
 
519
-	/**
520
-	 * Filters post states.
521
-	 */
522
-	public static function filter_discount_state( $post_states, $post ) {
584
+    /**
585
+     * Displays items table columns.
586
+     */
587
+    public static function display_item_columns( $column_name, $post_id ) {
523 588
 
524
-		if ( 'wpi_discount' === $post->post_type ) {
589
+        $item = new WPInv_Item( $post_id );
525 590
 
526
-			$discount = new WPInv_Discount( $post );
591
+        switch ( $column_name ) {
527 592
 
528
-			$status = $discount->is_expired() ? 'expired' : $discount->get_status();
593
+            case 'price':
594
+                if ( ! $item->is_recurring() ) {
595
+                    echo wp_kses_post( $item->get_the_price() );
596
+                    break;
597
+                }
529 598
 
530
-			if ( 'publish' !== $status ) {
531
-				return array(
532
-					'discount_status' => wpinv_discount_status( $status ),
533
-				);
534
-			}
599
+                $price = wp_sprintf(
600
+                    __( '%1$s / %2$s', 'invoicing' ),
601
+                    $item->get_the_price(),
602
+                    getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
603
+                );
535 604
 
536
-			return array();
605
+                if ( $item->get_the_price() == $item->get_the_initial_price() ) {
606
+                    echo wp_kses_post( $price );
607
+                    break;
608
+                }
537 609
 
538
-		}
610
+                echo wp_kses_post( $item->get_the_initial_price() );
539 611
 
540
-		return $post_states;
612
+                echo '<span class="meta">' . wp_sprintf( esc_html__( 'then %s', 'invoicing' ), wp_kses_post( $price ) ) . '</span>';
613
+                break;
541 614
 
542
-	}
615
+            case 'vat_rule':
616
+                echo wp_kses_post( getpaid_get_tax_rule_label( $item->get_vat_rule() ) );
617
+                break;
543 618
 
544
-	/**
545
-	 * Returns an array of items table columns.
546
-	 */
547
-	public static function item_columns( $columns ) {
619
+            case 'vat_class':
620
+                echo wp_kses_post( getpaid_get_tax_class_label( $item->get_vat_class() ) );
621
+                break;
548 622
 
549
-		$columns = array(
550
-			'cb'        => $columns['cb'],
551
-			'title'     => __( 'Name', 'invoicing' ),
552
-			'price'     => __( 'Price', 'invoicing' ),
553
-			'vat_rule'  => __( 'Tax Rule', 'invoicing' ),
554
-			'vat_class' => __( 'Tax Class', 'invoicing' ),
555
-			'type'      => __( 'Type', 'invoicing' ),
556
-			'shortcode' => __( 'Shortcode', 'invoicing' ),
557
-		);
623
+            case 'shortcode':
624
+                if ( $item->is_type( array( '', 'fee', 'custom' ) ) ) {
625
+                    echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
626
+                } else {
627
+                    echo '&mdash;';
628
+                }
558 629
 
559
-		if ( ! wpinv_use_taxes() ) {
560
-			unset( $columns['vat_rule'] );
561
-			unset( $columns['vat_class'] );
562
-		}
630
+                break;
563 631
 
564
-		return apply_filters( 'wpi_item_table_columns', $columns );
565
-	}
632
+            case 'type':
633
+                echo wp_kses_post( wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>' );
634
+                break;
566 635
 
567
-	/**
568
-	 * Returns an array of sortable items table columns.
569
-	 */
570
-	public static function sortable_item_columns( $columns ) {
571
-
572
-		return array_merge(
573
-			$columns,
574
-			array(
575
-				'price'     => 'price',
576
-				'vat_rule'  => 'vat_rule',
577
-				'vat_class' => 'vat_class',
578
-				'type'      => 'type',
579
-			)
580
-		);
581
-
582
-	}
583
-
584
-	/**
585
-	 * Displays items table columns.
586
-	 */
587
-	public static function display_item_columns( $column_name, $post_id ) {
588
-
589
-		$item = new WPInv_Item( $post_id );
590
-
591
-		switch ( $column_name ) {
592
-
593
-			case 'price':
594
-				if ( ! $item->is_recurring() ) {
595
-					echo wp_kses_post( $item->get_the_price() );
596
-					break;
597
-				}
598
-
599
-				$price = wp_sprintf(
600
-					__( '%1$s / %2$s', 'invoicing' ),
601
-					$item->get_the_price(),
602
-					getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
603
-				);
604
-
605
-				if ( $item->get_the_price() == $item->get_the_initial_price() ) {
606
-					echo wp_kses_post( $price );
607
-					break;
608
-				}
609
-
610
-				echo wp_kses_post( $item->get_the_initial_price() );
611
-
612
-				echo '<span class="meta">' . wp_sprintf( esc_html__( 'then %s', 'invoicing' ), wp_kses_post( $price ) ) . '</span>';
613
-				break;
614
-
615
-			case 'vat_rule':
616
-				echo wp_kses_post( getpaid_get_tax_rule_label( $item->get_vat_rule() ) );
617
-				break;
618
-
619
-			case 'vat_class':
620
-				echo wp_kses_post( getpaid_get_tax_class_label( $item->get_vat_class() ) );
621
-				break;
622
-
623
-			case 'shortcode':
624
-				if ( $item->is_type( array( '', 'fee', 'custom' ) ) ) {
625
-					echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
626
-				} else {
627
-					echo '&mdash;';
628
-				}
629
-
630
-				break;
631
-
632
-			case 'type':
633
-				echo wp_kses_post( wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>' );
634
-				break;
635
-
636
-		}
637
-
638
-	}
639
-
640
-	/**
641
-	 * Lets users filter items using taxes.
642
-	 */
643
-	public static function add_item_filters( $post_type ) {
644
-
645
-		// Abort if we're not dealing with items.
646
-		if ( 'wpi_item' !== $post_type ) {
647
-			return;
648
-		}
649
-
650
-		// Filter by vat rules.
651
-		if ( wpinv_use_taxes() ) {
652
-
653
-			// Sanitize selected vat rule.
654
-			$vat_rule   = '';
655
-			$vat_rules  = getpaid_get_tax_rules();
656
-			if ( isset( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
657
-				$vat_rule   = sanitize_text_field( $_GET['vat_rule'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
658
-			}
659
-
660
-			// Filter by VAT rule.
661
-			wpinv_html_select(
662
-				array(
663
-					'options'          => array_merge(
664
-						array(
665
-							'' => __( 'All Tax Rules', 'invoicing' ),
666
-						),
667
-						$vat_rules
668
-					),
669
-					'name'             => 'vat_rule',
670
-					'id'               => 'vat_rule',
671
-					'selected'         => in_array( $vat_rule, array_keys( $vat_rules ), true ) ? $vat_rule : '',
672
-					'show_option_all'  => false,
673
-					'show_option_none' => false,
674
-				)
675
-			);
676
-
677
-			// Filter by VAT class.
678
-
679
-			// Sanitize selected vat rule.
680
-			$vat_class   = '';
681
-			$vat_classes = getpaid_get_tax_classes();
682
-			if ( isset( $_GET['vat_class'] ) ) {  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
683
-				$vat_class   = sanitize_text_field( $_GET['vat_class'] );  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
684
-			}
685
-
686
-			wpinv_html_select(
687
-				array(
688
-					'options'          => array_merge(
689
-						array(
690
-							'' => __( 'All Tax Classes', 'invoicing' ),
691
-						),
692
-						$vat_classes
693
-					),
694
-					'name'             => 'vat_class',
695
-					'id'               => 'vat_class',
696
-					'selected'         => in_array( $vat_class, array_keys( $vat_classes ), true ) ? $vat_class : '',
697
-					'show_option_all'  => false,
698
-					'show_option_none' => false,
699
-				)
700
-			);
701
-
702
-		}
703
-
704
-		// Filter by item type.
705
-		$type   = '';
706
-		if ( isset( $_GET['type'] ) ) {  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
707
-			$type   = sanitize_text_field( $_GET['type'] );  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
708
-		}
709
-
710
-		wpinv_html_select(
711
-			array(
712
-				'options'          => array_merge(
713
-					array(
714
-						'' => __( 'All item types', 'invoicing' ),
715
-					),
716
-					wpinv_get_item_types()
717
-				),
718
-				'name'             => 'type',
719
-				'id'               => 'type',
720
-				'selected'         => in_array( $type, wpinv_item_types(), true ) ? $type : '',
721
-				'show_option_all'  => false,
722
-				'show_option_none' => false,
723
-			)
724
-		);
725
-
726
-	}
727
-
728
-	/**
729
-	 * Filters the item query.
730
-	 */
731
-	public static function filter_item_query( $query ) {
732
-
733
-		// modify the query only if it admin and main query.
734
-		if ( ! ( is_admin() && $query->is_main_query() ) ) {
735
-			return $query;
736
-		}
737
-
738
-		// we want to modify the query for our items.
739
-		if ( empty( $query->query['post_type'] ) || 'wpi_item' !== $query->query['post_type'] ) {
740
-			return $query;
741
-		}
742
-
743
-		if ( empty( $query->query_vars['meta_query'] ) ) {
744
-			$query->query_vars['meta_query'] = array();
745
-		}
746
-
747
-		// Filter vat rule type
636
+        }
637
+
638
+    }
639
+
640
+    /**
641
+     * Lets users filter items using taxes.
642
+     */
643
+    public static function add_item_filters( $post_type ) {
644
+
645
+        // Abort if we're not dealing with items.
646
+        if ( 'wpi_item' !== $post_type ) {
647
+            return;
648
+        }
649
+
650
+        // Filter by vat rules.
651
+        if ( wpinv_use_taxes() ) {
652
+
653
+            // Sanitize selected vat rule.
654
+            $vat_rule   = '';
655
+            $vat_rules  = getpaid_get_tax_rules();
656
+            if ( isset( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
657
+                $vat_rule   = sanitize_text_field( $_GET['vat_rule'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
658
+            }
659
+
660
+            // Filter by VAT rule.
661
+            wpinv_html_select(
662
+                array(
663
+                    'options'          => array_merge(
664
+                        array(
665
+                            '' => __( 'All Tax Rules', 'invoicing' ),
666
+                        ),
667
+                        $vat_rules
668
+                    ),
669
+                    'name'             => 'vat_rule',
670
+                    'id'               => 'vat_rule',
671
+                    'selected'         => in_array( $vat_rule, array_keys( $vat_rules ), true ) ? $vat_rule : '',
672
+                    'show_option_all'  => false,
673
+                    'show_option_none' => false,
674
+                )
675
+            );
676
+
677
+            // Filter by VAT class.
678
+
679
+            // Sanitize selected vat rule.
680
+            $vat_class   = '';
681
+            $vat_classes = getpaid_get_tax_classes();
682
+            if ( isset( $_GET['vat_class'] ) ) {  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
683
+                $vat_class   = sanitize_text_field( $_GET['vat_class'] );  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
684
+            }
685
+
686
+            wpinv_html_select(
687
+                array(
688
+                    'options'          => array_merge(
689
+                        array(
690
+                            '' => __( 'All Tax Classes', 'invoicing' ),
691
+                        ),
692
+                        $vat_classes
693
+                    ),
694
+                    'name'             => 'vat_class',
695
+                    'id'               => 'vat_class',
696
+                    'selected'         => in_array( $vat_class, array_keys( $vat_classes ), true ) ? $vat_class : '',
697
+                    'show_option_all'  => false,
698
+                    'show_option_none' => false,
699
+                )
700
+            );
701
+
702
+        }
703
+
704
+        // Filter by item type.
705
+        $type   = '';
706
+        if ( isset( $_GET['type'] ) ) {  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
707
+            $type   = sanitize_text_field( $_GET['type'] );  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
708
+        }
709
+
710
+        wpinv_html_select(
711
+            array(
712
+                'options'          => array_merge(
713
+                    array(
714
+                        '' => __( 'All item types', 'invoicing' ),
715
+                    ),
716
+                    wpinv_get_item_types()
717
+                ),
718
+                'name'             => 'type',
719
+                'id'               => 'type',
720
+                'selected'         => in_array( $type, wpinv_item_types(), true ) ? $type : '',
721
+                'show_option_all'  => false,
722
+                'show_option_none' => false,
723
+            )
724
+        );
725
+
726
+    }
727
+
728
+    /**
729
+     * Filters the item query.
730
+     */
731
+    public static function filter_item_query( $query ) {
732
+
733
+        // modify the query only if it admin and main query.
734
+        if ( ! ( is_admin() && $query->is_main_query() ) ) {
735
+            return $query;
736
+        }
737
+
738
+        // we want to modify the query for our items.
739
+        if ( empty( $query->query['post_type'] ) || 'wpi_item' !== $query->query['post_type'] ) {
740
+            return $query;
741
+        }
742
+
743
+        if ( empty( $query->query_vars['meta_query'] ) ) {
744
+            $query->query_vars['meta_query'] = array();
745
+        }
746
+
747
+        // Filter vat rule type
748 748
         if ( ! empty( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
749 749
             $query->query_vars['meta_query'][] = array(
750 750
                 'key'     => '_wpinv_vat_rule',
@@ -769,101 +769,101 @@  discard block
 block discarded – undo
769 769
                 'value'   => sanitize_text_field( $_GET['type'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended
770 770
                 'compare' => '=',
771 771
             );
772
-		}
773
-
774
-		$query->query_vars['meta_query'][] = array(
775
-			'key'     => '_wpinv_one_time',
776
-			'compare' => 'NOT EXISTS',
777
-		);
778
-	}
779
-
780
-	/**
781
-	 * Reorders items.
782
-	 */
783
-	public static function reorder_items( $vars ) {
784
-		global $typenow;
785
-
786
-		if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
787
-			return $vars;
788
-		}
789
-
790
-		// By item type.
791
-		if ( 'type' === $vars['orderby'] ) {
792
-			return array_merge(
793
-				$vars,
794
-				array(
795
-					'meta_key' => '_wpinv_type',
796
-					'orderby'  => 'meta_value',
797
-				)
798
-			);
799
-		}
800
-
801
-		// By vat class.
802
-		if ( 'vat_class' === $vars['orderby'] ) {
803
-			return array_merge(
804
-				$vars,
805
-				array(
806
-					'meta_key' => '_wpinv_vat_class',
807
-					'orderby'  => 'meta_value',
808
-				)
809
-			);
810
-		}
811
-
812
-		// By vat rule.
813
-		if ( 'vat_rule' === $vars['orderby'] ) {
814
-			return array_merge(
815
-				$vars,
816
-				array(
817
-					'meta_key' => '_wpinv_vat_rule',
818
-					'orderby'  => 'meta_value',
819
-				)
820
-			);
821
-		}
822
-
823
-		// By price.
824
-		if ( 'price' === $vars['orderby'] ) {
825
-			return array_merge(
826
-				$vars,
827
-				array(
828
-					'meta_key' => '_wpinv_price',
829
-					'orderby'  => 'meta_value_num',
830
-				)
831
-			);
832
-		}
833
-
834
-		return $vars;
835
-
836
-	}
837
-
838
-	/**
839
-	 * Fired when deleting a post.
840
-	 */
841
-	public static function delete_post( $post_id ) {
842
-
843
-		switch ( get_post_type( $post_id ) ) {
844
-
845
-			case 'wpi_item':
846
-				do_action( 'getpaid_before_delete_item', new WPInv_Item( $post_id ) );
847
-				break;
848
-
849
-			case 'wpi_payment_form':
850
-				do_action( 'getpaid_before_delete_payment_form', new GetPaid_Payment_Form( $post_id ) );
851
-				break;
852
-
853
-			case 'wpi_discount':
854
-				do_action( 'getpaid_before_delete_discount', new WPInv_Discount( $post_id ) );
855
-				break;
856
-
857
-			case 'wpi_invoice':
858
-				$invoice = new WPInv_Invoice( $post_id );
859
-				do_action( 'getpaid_before_delete_invoice', $invoice );
860
-				$invoice->get_data_store()->delete_items( $invoice );
861
-				$invoice->get_data_store()->delete_special_fields( $invoice );
862
-				break;
863
-		}
864
-	}
865
-
866
-	/**
772
+        }
773
+
774
+        $query->query_vars['meta_query'][] = array(
775
+            'key'     => '_wpinv_one_time',
776
+            'compare' => 'NOT EXISTS',
777
+        );
778
+    }
779
+
780
+    /**
781
+     * Reorders items.
782
+     */
783
+    public static function reorder_items( $vars ) {
784
+        global $typenow;
785
+
786
+        if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
787
+            return $vars;
788
+        }
789
+
790
+        // By item type.
791
+        if ( 'type' === $vars['orderby'] ) {
792
+            return array_merge(
793
+                $vars,
794
+                array(
795
+                    'meta_key' => '_wpinv_type',
796
+                    'orderby'  => 'meta_value',
797
+                )
798
+            );
799
+        }
800
+
801
+        // By vat class.
802
+        if ( 'vat_class' === $vars['orderby'] ) {
803
+            return array_merge(
804
+                $vars,
805
+                array(
806
+                    'meta_key' => '_wpinv_vat_class',
807
+                    'orderby'  => 'meta_value',
808
+                )
809
+            );
810
+        }
811
+
812
+        // By vat rule.
813
+        if ( 'vat_rule' === $vars['orderby'] ) {
814
+            return array_merge(
815
+                $vars,
816
+                array(
817
+                    'meta_key' => '_wpinv_vat_rule',
818
+                    'orderby'  => 'meta_value',
819
+                )
820
+            );
821
+        }
822
+
823
+        // By price.
824
+        if ( 'price' === $vars['orderby'] ) {
825
+            return array_merge(
826
+                $vars,
827
+                array(
828
+                    'meta_key' => '_wpinv_price',
829
+                    'orderby'  => 'meta_value_num',
830
+                )
831
+            );
832
+        }
833
+
834
+        return $vars;
835
+
836
+    }
837
+
838
+    /**
839
+     * Fired when deleting a post.
840
+     */
841
+    public static function delete_post( $post_id ) {
842
+
843
+        switch ( get_post_type( $post_id ) ) {
844
+
845
+            case 'wpi_item':
846
+                do_action( 'getpaid_before_delete_item', new WPInv_Item( $post_id ) );
847
+                break;
848
+
849
+            case 'wpi_payment_form':
850
+                do_action( 'getpaid_before_delete_payment_form', new GetPaid_Payment_Form( $post_id ) );
851
+                break;
852
+
853
+            case 'wpi_discount':
854
+                do_action( 'getpaid_before_delete_discount', new WPInv_Discount( $post_id ) );
855
+                break;
856
+
857
+            case 'wpi_invoice':
858
+                $invoice = new WPInv_Invoice( $post_id );
859
+                do_action( 'getpaid_before_delete_invoice', $invoice );
860
+                $invoice->get_data_store()->delete_items( $invoice );
861
+                $invoice->get_data_store()->delete_special_fields( $invoice );
862
+                break;
863
+        }
864
+    }
865
+
866
+    /**
867 867
      * Add a post display state for special GetPaid pages in the page list table.
868 868
      *
869 869
      * @param array   $post_states An array of post display states.
@@ -877,21 +877,21 @@  discard block
 block discarded – undo
877 877
             $post_states['getpaid_success_page'] = __( 'GetPaid Receipt Page', 'invoicing' );
878 878
         }
879 879
 
880
-		foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) {
880
+        foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) {
881 881
 
882
-			if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) {
883
-				$post_states[ "getpaid_{$post_type}_history_page" ] = sprintf(
884
-					__( 'GetPaid %s History Page', 'invoicing' ),
885
-					$label
886
-				);
887
-			}
882
+            if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) {
883
+                $post_states[ "getpaid_{$post_type}_history_page" ] = sprintf(
884
+                    __( 'GetPaid %s History Page', 'invoicing' ),
885
+                    $label
886
+                );
887
+            }
888 888
 }
889 889
 
890
-		if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) {
890
+        if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) {
891 891
             $post_states['getpaid_invoice_subscription_page'] = __( 'GetPaid Subscription Page', 'invoicing' );
892 892
         }
893 893
 
894
-		if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) {
894
+        if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) {
895 895
             $post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' );
896 896
         }
897 897
 
Please login to merge, or discard this patch.
includes/wpinv-item-functions.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -57,21 +57,21 @@  discard block
 block discarded – undo
57 57
     $args = wp_parse_args(
58 58
         $args,
59 59
         array(
60
-			'status'     => array( 'publish' ),
61
-			'limit'      => get_option( 'posts_per_page' ),
62
-			'page'       => 1,
63
-			'exclude'    => array(),
64
-			'orderby'    => 'date',
65
-			'order'      => 'DESC',
66
-			'type'       => wpinv_item_types(),
67
-			'meta_query' => array(
60
+            'status'     => array( 'publish' ),
61
+            'limit'      => get_option( 'posts_per_page' ),
62
+            'page'       => 1,
63
+            'exclude'    => array(),
64
+            'orderby'    => 'date',
65
+            'order'      => 'DESC',
66
+            'type'       => wpinv_item_types(),
67
+            'meta_query' => array(
68 68
                 array(
69 69
                     'key'     => '_wpinv_one_time',
70 70
                     'compare' => 'NOT EXISTS',
71 71
                 ),
72 72
             ),
73
-			'return'     => 'objects',
74
-			'paginate'   => false,
73
+            'return'     => 'objects',
74
+            'paginate'   => false,
75 75
         )
76 76
     );
77 77
 
@@ -211,9 +211,9 @@  discard block
 block discarded – undo
211 211
 
212 212
 function wpinv_get_item_types() {
213 213
     $item_types = array(
214
-		'custom' => __( 'Standard', 'invoicing' ),
215
-		'fee'    => __( 'Fee', 'invoicing' ),
216
-	);
214
+        'custom' => __( 'Standard', 'invoicing' ),
215
+        'fee'    => __( 'Fee', 'invoicing' ),
216
+    );
217 217
     return apply_filters( 'wpinv_get_item_types', $item_types );
218 218
 }
219 219
 
@@ -255,16 +255,16 @@  discard block
 block discarded – undo
255 255
     $args = array();
256 256
     if ( $post_ids ) {
257 257
         $args = array(
258
-			'fields' => 'ids',
259
-		);
258
+            'fields' => 'ids',
259
+        );
260 260
     }
261 261
 
262 262
     $args = array_merge(
263 263
         $args,
264 264
         array(
265 265
             'post_type'  => 'wpi_item',
266
-			'orderby'    => 'rand',
267
-			'post_count' => $num,
266
+            'orderby'    => 'rand',
267
+            'post_count' => $num,
268 268
             'meta_query' => array(
269 269
                 array(
270 270
                     'key'     => '_wpinv_one_time',
@@ -439,10 +439,10 @@  discard block
 block discarded – undo
439 439
     $bill_times_less = $bill_times - 1;
440 440
 
441 441
     if ( ! empty( $bill_times ) ) {
442
-		$bill_times = $item->get_recurring_interval() * $bill_times;
442
+        $bill_times = $item->get_recurring_interval() * $bill_times;
443 443
         $bill_times_less = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times - $item->get_recurring_interval() );
444
-		$bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times );
445
-	}
444
+        $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times );
445
+    }
446 446
 
447 447
     if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) {
448 448
         $initial_price   = wpinv_price( $item->get_sub_total(), $currency );
@@ -587,19 +587,19 @@  discard block
 block discarded – undo
587 587
  * @return bool Whether the item type supports the given feature.
588 588
  */
589 589
 function getpaid_item_type_supports( $item_type, $feature, $item_ID = 0 ) {
590
-	$supports = false;
590
+    $supports = false;
591 591
 
592
-	if ( ! is_scalar( $item_type ) ) {
593
-		return $supports;
594
-	}
592
+    if ( ! is_scalar( $item_type ) ) {
593
+        return $supports;
594
+    }
595 595
 
596
-	switch ( $feature ) {
597
-		case 'buy_now':
598
-			if ( '' === $item_type || 'fee' === $item_type || 'custom' === $item_type ) {
599
-				$supports = true;
600
-			}
601
-			break;
602
-	}
596
+    switch ( $feature ) {
597
+        case 'buy_now':
598
+            if ( '' === $item_type || 'fee' === $item_type || 'custom' === $item_type ) {
599
+                $supports = true;
600
+            }
601
+            break;
602
+    }
603 603
 
604
-	return apply_filters( 'getpaid_item_type_supports', $supports, $item_type, $feature, $item_ID );
604
+    return apply_filters( 'getpaid_item_type_supports', $supports, $item_type, $feature, $item_ID );
605 605
 }
606 606
\ No newline at end of file
Please login to merge, or discard this patch.
ayecode/wp-ayecode-ui/includes/components/class-aui-component-input.php 1 patch
Indentation   +1268 added lines, -1268 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,1291 +11,1291 @@  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
-		global $aui_bs5;
23
-
24
-		$defaults = array(
25
-			'type'                     => 'text',
26
-			'name'                     => '',
27
-			'class'                    => '',
28
-			'wrap_class'               => '',
29
-			'id'                       => '',
30
-			'placeholder'              => '',
31
-			'title'                    => '',
32
-			'value'                    => '',
33
-			'required'                 => false,
34
-			'size'                     => '', // sm, lg, small, large
35
-			'clear_icon'               => '', // true will show a clear icon, can't be used with input_group_right
36
-			'with_hidden'              => false, // Append hidden field for single checkbox.
37
-			'label'                    => '',
38
-			'label_after'              => false,
39
-			'label_class'              => '',
40
-			'label_col'                => '2',
41
-			'label_type'               => '', // top, horizontal, empty = hidden
42
-			'label_force_left'         => false, // used to force checkbox label left when using horizontal
43
-			// sets the label type, default: hidden. Options: hidden, top, horizontal, floating
44
-			'help_text'                => '',
45
-			'validation_text'          => '',
46
-			'validation_pattern'       => '',
47
-			'no_wrap'                  => false,
48
-			'input_group_right'        => '',
49
-			'input_group_left'         => '',
50
-			'input_group_right_inside' => false,
51
-			// forces the input group inside the input
52
-			'input_group_left_inside'  => false,
53
-			// forces the input group inside the input
54
-			'form_group_class'         => '',
55
-			'step'                     => '',
56
-			'switch'                   => false,
57
-			// to show checkbox as a switch
58
-			'checked'                  => false,
59
-			// set a checkbox or radio as selected
60
-			'password_toggle'          => true,
61
-			// toggle view/hide password
62
-			'element_require'          => '',
63
-			// [%element_id%] == "1"
64
-			'extra_attributes'         => array(),
65
-			// an array of extra attributes
66
-			'wrap_attributes'          => array()
67
-		);
68
-
69
-		/**
70
-		 * Parse incoming $args into an array and merge it with $defaults
71
-		 */
72
-		$args   = wp_parse_args( $args, $defaults );
73
-		$output = '';
74
-		if ( ! empty( $args['type'] ) ) {
75
-			// hidden label option needs to be empty
76
-			$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
77
-
78
-			$type = sanitize_html_class( $args['type'] );
79
-
80
-			$help_text   = '';
81
-			$label       = '';
82
-			$label_after = $args['label_after'];
83
-			$label_args  = array(
84
-				'title'      => $args['label'],
85
-				'for'        => $args['id'],
86
-				'class'      => $args['label_class'] . " ",
87
-				'label_type' => $args['label_type'],
88
-				'label_col'  => $args['label_col']
89
-			);
90
-
91
-			// floating labels need label after
92
-			if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) {
93
-				$label_after         = true;
94
-				$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
95
-			}
96
-
97
-			// size
98
-			$size = '';
99
-			if ( $args['size'] == 'lg' || $args['size'] == 'large' ) {
100
-				$size = 'lg';
101
-				$args['class'] .= ' form-control-lg';
102
-			}elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) {
103
-				$size = 'sm';
104
-				$args['class'] .= ' form-control-sm';
105
-			}
106
-
107
-			// clear function
108
-			$clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');';
109
-
110
-			// Some special sauce for files
111
-			if ( $type == 'file' ) {
112
-				$label_after = true; // if type file we need the label after
113
-				$args['class'] .= ' custom-file-input ';
114
-			} elseif ( $type == 'checkbox' ) {
115
-				$label_after = true; // if type file we need the label after
116
-				$args['class'] .= $aui_bs5 ? ' form-check-input c-pointer ' : ' custom-control-input c-pointer ';
117
-			} elseif ( $type == 'datepicker' || $type == 'timepicker' ) {
118
-				$orig_type = $type;
119
-				$type = 'text';
120
-				$args['class'] .= ' bg-initial '; // @todo not sure why we have this?
121
-				$clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');";
122
-
123
-				$args['extra_attributes']['data-aui-init'] = 'flatpickr';
124
-
125
-				// Disable native datetime inputs.
126
-				$disable_mobile_attr = isset( $args['extra_attributes']['data-disable-mobile'] ) ? $args['extra_attributes']['data-disable-mobile'] : 'true';
127
-				$disable_mobile_attr = apply_filters( 'aui_flatpickr_disable_disable_mobile_attr', $disable_mobile_attr, $args );
128
-
129
-				$args['extra_attributes']['data-disable-mobile'] = $disable_mobile_attr;
130
-
131
-				// set a way to clear field if empty
132
-				if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) {
133
-					$args['input_group_right_inside'] = true;
134
-					$args['clear_icon'] = true;
135
-				}
136
-
137
-				// enqueue the script
138
-				$aui_settings = AyeCode_UI_Settings::instance();
139
-				$aui_settings->enqueue_flatpickr();
140
-			} elseif ( $type == 'iconpicker' ) {
141
-				$type = 'text';
142
-				//$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
+        global $aui_bs5;
23
+
24
+        $defaults = array(
25
+            'type'                     => 'text',
26
+            'name'                     => '',
27
+            'class'                    => '',
28
+            'wrap_class'               => '',
29
+            'id'                       => '',
30
+            'placeholder'              => '',
31
+            'title'                    => '',
32
+            'value'                    => '',
33
+            'required'                 => false,
34
+            'size'                     => '', // sm, lg, small, large
35
+            'clear_icon'               => '', // true will show a clear icon, can't be used with input_group_right
36
+            'with_hidden'              => false, // Append hidden field for single checkbox.
37
+            'label'                    => '',
38
+            'label_after'              => false,
39
+            'label_class'              => '',
40
+            'label_col'                => '2',
41
+            'label_type'               => '', // top, horizontal, empty = hidden
42
+            'label_force_left'         => false, // used to force checkbox label left when using horizontal
43
+            // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
44
+            'help_text'                => '',
45
+            'validation_text'          => '',
46
+            'validation_pattern'       => '',
47
+            'no_wrap'                  => false,
48
+            'input_group_right'        => '',
49
+            'input_group_left'         => '',
50
+            'input_group_right_inside' => false,
51
+            // forces the input group inside the input
52
+            'input_group_left_inside'  => false,
53
+            // forces the input group inside the input
54
+            'form_group_class'         => '',
55
+            'step'                     => '',
56
+            'switch'                   => false,
57
+            // to show checkbox as a switch
58
+            'checked'                  => false,
59
+            // set a checkbox or radio as selected
60
+            'password_toggle'          => true,
61
+            // toggle view/hide password
62
+            'element_require'          => '',
63
+            // [%element_id%] == "1"
64
+            'extra_attributes'         => array(),
65
+            // an array of extra attributes
66
+            'wrap_attributes'          => array()
67
+        );
68
+
69
+        /**
70
+         * Parse incoming $args into an array and merge it with $defaults
71
+         */
72
+        $args   = wp_parse_args( $args, $defaults );
73
+        $output = '';
74
+        if ( ! empty( $args['type'] ) ) {
75
+            // hidden label option needs to be empty
76
+            $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
77
+
78
+            $type = sanitize_html_class( $args['type'] );
79
+
80
+            $help_text   = '';
81
+            $label       = '';
82
+            $label_after = $args['label_after'];
83
+            $label_args  = array(
84
+                'title'      => $args['label'],
85
+                'for'        => $args['id'],
86
+                'class'      => $args['label_class'] . " ",
87
+                'label_type' => $args['label_type'],
88
+                'label_col'  => $args['label_col']
89
+            );
90
+
91
+            // floating labels need label after
92
+            if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) {
93
+                $label_after         = true;
94
+                $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
95
+            }
96
+
97
+            // size
98
+            $size = '';
99
+            if ( $args['size'] == 'lg' || $args['size'] == 'large' ) {
100
+                $size = 'lg';
101
+                $args['class'] .= ' form-control-lg';
102
+            }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) {
103
+                $size = 'sm';
104
+                $args['class'] .= ' form-control-sm';
105
+            }
106
+
107
+            // clear function
108
+            $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');';
109
+
110
+            // Some special sauce for files
111
+            if ( $type == 'file' ) {
112
+                $label_after = true; // if type file we need the label after
113
+                $args['class'] .= ' custom-file-input ';
114
+            } elseif ( $type == 'checkbox' ) {
115
+                $label_after = true; // if type file we need the label after
116
+                $args['class'] .= $aui_bs5 ? ' form-check-input c-pointer ' : ' custom-control-input c-pointer ';
117
+            } elseif ( $type == 'datepicker' || $type == 'timepicker' ) {
118
+                $orig_type = $type;
119
+                $type = 'text';
120
+                $args['class'] .= ' bg-initial '; // @todo not sure why we have this?
121
+                $clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');";
122
+
123
+                $args['extra_attributes']['data-aui-init'] = 'flatpickr';
124
+
125
+                // Disable native datetime inputs.
126
+                $disable_mobile_attr = isset( $args['extra_attributes']['data-disable-mobile'] ) ? $args['extra_attributes']['data-disable-mobile'] : 'true';
127
+                $disable_mobile_attr = apply_filters( 'aui_flatpickr_disable_disable_mobile_attr', $disable_mobile_attr, $args );
128
+
129
+                $args['extra_attributes']['data-disable-mobile'] = $disable_mobile_attr;
130
+
131
+                // set a way to clear field if empty
132
+                if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) {
133
+                    $args['input_group_right_inside'] = true;
134
+                    $args['clear_icon'] = true;
135
+                }
136
+
137
+                // enqueue the script
138
+                $aui_settings = AyeCode_UI_Settings::instance();
139
+                $aui_settings->enqueue_flatpickr();
140
+            } elseif ( $type == 'iconpicker' ) {
141
+                $type = 'text';
142
+                //$args['class'] .= ' aui-flatpickr bg-initial ';
143 143
 //				$args['class'] .= ' bg-initial ';
144 144
 
145
-				$args['extra_attributes']['data-aui-init'] = 'iconpicker';
146
-				$args['extra_attributes']['data-placement'] = 'bottomRight';
145
+                $args['extra_attributes']['data-aui-init'] = 'iconpicker';
146
+                $args['extra_attributes']['data-placement'] = 'bottomRight';
147 147
 
148
-				$args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>';
148
+                $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>';
149 149
 //				$args['input_group_right_inside'] = true;
150
-				// enqueue the script
151
-				$aui_settings = AyeCode_UI_Settings::instance();
152
-				$aui_settings->enqueue_iconpicker();
153
-			}
154
-
155
-			if ( $type == 'checkbox' && ( ( ! empty( $args['name'] ) && strpos( $args['name'], '[' ) === false ) || ! empty( $args['with_hidden'] ) ) ) {
156
-				$output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />';
157
-			}
158
-
159
-			// allow clear icon
160
-			if ( $args['input_group_right'] === '' && $args['clear_icon'] ) {
161
-				$font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' );
162
-				$args['input_group_right_inside'] = true;
163
-				$align_class = $aui_bs5 ? ' h-100 py-0' : '';
164
-				$args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none ' . $align_class . '" onclick="' . $clear_function . '"><span style="font-size: ' . $font_size . 'rem" aria-hidden="true" class="' . ( $aui_bs5 ? 'btn-close' : 'close' ) . '">' . ( $aui_bs5 ? '' : '&times;' ) . '</span></span>';
165
-			}
166
-
167
-			// open/type
168
-			$output .= '<input type="' . $type . '" ';
169
-
170
-			// name
171
-			if ( ! empty( $args['name'] ) ) {
172
-				$output .= ' name="' . esc_attr( $args['name'] ) . '" ';
173
-			}
174
-
175
-			// id
176
-			if ( ! empty( $args['id'] ) ) {
177
-				$output .= ' id="' . sanitize_html_class( $args['id'] ) . '" ';
178
-			}
179
-
180
-			// placeholder
181
-			if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) {
182
-				$output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" ';
183
-			}
184
-
185
-			// title
186
-			if ( ! empty( $args['title'] ) ) {
187
-				$output .= ' title="' . esc_attr( $args['title'] ) . '" ';
188
-			}
189
-
190
-			// value
191
-			if ( ! empty( $args['value'] ) ) {
192
-				$output .= AUI_Component_Helper::value( $args['value'] );
193
-			}
194
-
195
-			// checked, for radio and checkboxes
196
-			if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) {
197
-				$output .= ' checked ';
198
-			}
199
-
200
-			// validation text
201
-			if ( ! empty( $args['validation_text'] ) ) {
202
-				$output .= ' oninvalid="setCustomValidity(\'' . esc_attr( addslashes( $args['validation_text'] ) ) . '\')" ';
203
-				$output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
204
-			}
205
-
206
-			// validation_pattern
207
-			if ( ! empty( $args['validation_pattern'] ) ) {
208
-				$output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" ';
209
-			}
210
-
211
-			// step (for numbers)
212
-			if ( ! empty( $args['step'] ) ) {
213
-				$output .= ' step="' . $args['step'] . '" ';
214
-			}
215
-
216
-			// required
217
-			if ( ! empty( $args['required'] ) ) {
218
-				$output .= ' required ';
219
-			}
220
-
221
-			// class
222
-			$class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
223
-			$output .= $aui_bs5 &&  $type == 'checkbox' ? ' class="' . $class . '" ' : ' class="form-control ' . $class . '" ';
224
-
225
-			// data-attributes
226
-			$output .= AUI_Component_Helper::data_attributes( $args );
227
-
228
-			// extra attributes
229
-			if ( ! empty( $args['extra_attributes'] ) ) {
230
-				$output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
231
-			}
232
-
233
-			// close
234
-			$output .= ' >';
235
-
236
-			// help text
237
-			if ( ! empty( $args['help_text'] ) ) {
238
-				$help_text = AUI_Component_Helper::help_text( $args['help_text'] );
239
-			}
240
-
241
-			// label
242
-			if ( ! empty( $args['label'] ) ) {
243
-				$label_base_class = '';
244
-				if ( $type == 'file' ) {
245
-					$label_base_class = ' custom-file-label';
246
-				} elseif ( $type == 'checkbox' ) {
247
-					if ( ! empty( $args['label_force_left'] ) ) {
248
-						$label_args['title'] = wp_kses_post( $args['help_text'] );
249
-						$help_text = '';
250
-						//$label_args['class'] .= ' d-inline ';
251
-						$args['wrap_class'] .= ' align-items-center ';
252
-					}else{
253
-
254
-					}
255
-
256
-					$label_base_class = $aui_bs5 ? ' form-check-label' : ' custom-control-label';
257
-				}
258
-				$label_args['class'] .= $label_base_class;
259
-				$temp_label_args = $label_args;
260
-				if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";}
261
-				$label = self::label( $temp_label_args, $type );
262
-			}
263
-
264
-
265
-
266
-
267
-			// set help text in the correct position
268
-			if ( $label_after ) {
269
-				$output .= $label . $help_text;
270
-			}
271
-
272
-			// some input types need a separate wrap
273
-			if ( $type == 'file' ) {
274
-				$output = self::wrap( array(
275
-					'content' => $output,
276
-					'class'   => $aui_bs5 ? 'mb-3 custom-file' : 'form-group custom-file'
277
-				) );
278
-			} elseif ( $type == 'checkbox' ) {
279
-
280
-				$label_args['title'] = $args['label'];
281
-				$label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' );
282
-				$label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>';
283
-				$switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : '';
284
-				if ( $aui_bs5 ) {
285
-					$wrap_class = $args['switch'] ? 'form-check form-switch' . $switch_size_class : 'form-check';
286
-				}else{
287
-					$wrap_class = $args['switch'] ? 'custom-switch' . $switch_size_class :  'custom-checkbox' ;
288
-				}
289
-				if ( ! empty( $args['label_force_left'] ) ) {
290
-					$wrap_class .= $aui_bs5 ? '' : ' d-flex align-content-center';
291
-					$label = str_replace(array("form-check-label","custom-control-label"),"", self::label( $label_args, 'cb' ) );
292
-				}
293
-				$output     = self::wrap( array(
294
-					'content' => $output,
295
-					'class'   => $aui_bs5 ? $wrap_class : 'custom-control ' . $wrap_class
296
-				) );
297
-
298
-				if ( $args['label_type'] == 'horizontal' ) {
299
-					$input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
300
-					$output    = $label . '<div class="' . $input_col . '">' . $output . '</div>';
301
-				}
302
-			} elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) {
303
-
304
-
305
-				// allow password field to toggle view
306
-				$args['input_group_right'] = '<span class="input-group-text c-pointer px-3" 
150
+                // enqueue the script
151
+                $aui_settings = AyeCode_UI_Settings::instance();
152
+                $aui_settings->enqueue_iconpicker();
153
+            }
154
+
155
+            if ( $type == 'checkbox' && ( ( ! empty( $args['name'] ) && strpos( $args['name'], '[' ) === false ) || ! empty( $args['with_hidden'] ) ) ) {
156
+                $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />';
157
+            }
158
+
159
+            // allow clear icon
160
+            if ( $args['input_group_right'] === '' && $args['clear_icon'] ) {
161
+                $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' );
162
+                $args['input_group_right_inside'] = true;
163
+                $align_class = $aui_bs5 ? ' h-100 py-0' : '';
164
+                $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none ' . $align_class . '" onclick="' . $clear_function . '"><span style="font-size: ' . $font_size . 'rem" aria-hidden="true" class="' . ( $aui_bs5 ? 'btn-close' : 'close' ) . '">' . ( $aui_bs5 ? '' : '&times;' ) . '</span></span>';
165
+            }
166
+
167
+            // open/type
168
+            $output .= '<input type="' . $type . '" ';
169
+
170
+            // name
171
+            if ( ! empty( $args['name'] ) ) {
172
+                $output .= ' name="' . esc_attr( $args['name'] ) . '" ';
173
+            }
174
+
175
+            // id
176
+            if ( ! empty( $args['id'] ) ) {
177
+                $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" ';
178
+            }
179
+
180
+            // placeholder
181
+            if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) {
182
+                $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" ';
183
+            }
184
+
185
+            // title
186
+            if ( ! empty( $args['title'] ) ) {
187
+                $output .= ' title="' . esc_attr( $args['title'] ) . '" ';
188
+            }
189
+
190
+            // value
191
+            if ( ! empty( $args['value'] ) ) {
192
+                $output .= AUI_Component_Helper::value( $args['value'] );
193
+            }
194
+
195
+            // checked, for radio and checkboxes
196
+            if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) {
197
+                $output .= ' checked ';
198
+            }
199
+
200
+            // validation text
201
+            if ( ! empty( $args['validation_text'] ) ) {
202
+                $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( addslashes( $args['validation_text'] ) ) . '\')" ';
203
+                $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
204
+            }
205
+
206
+            // validation_pattern
207
+            if ( ! empty( $args['validation_pattern'] ) ) {
208
+                $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" ';
209
+            }
210
+
211
+            // step (for numbers)
212
+            if ( ! empty( $args['step'] ) ) {
213
+                $output .= ' step="' . $args['step'] . '" ';
214
+            }
215
+
216
+            // required
217
+            if ( ! empty( $args['required'] ) ) {
218
+                $output .= ' required ';
219
+            }
220
+
221
+            // class
222
+            $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
223
+            $output .= $aui_bs5 &&  $type == 'checkbox' ? ' class="' . $class . '" ' : ' class="form-control ' . $class . '" ';
224
+
225
+            // data-attributes
226
+            $output .= AUI_Component_Helper::data_attributes( $args );
227
+
228
+            // extra attributes
229
+            if ( ! empty( $args['extra_attributes'] ) ) {
230
+                $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
231
+            }
232
+
233
+            // close
234
+            $output .= ' >';
235
+
236
+            // help text
237
+            if ( ! empty( $args['help_text'] ) ) {
238
+                $help_text = AUI_Component_Helper::help_text( $args['help_text'] );
239
+            }
240
+
241
+            // label
242
+            if ( ! empty( $args['label'] ) ) {
243
+                $label_base_class = '';
244
+                if ( $type == 'file' ) {
245
+                    $label_base_class = ' custom-file-label';
246
+                } elseif ( $type == 'checkbox' ) {
247
+                    if ( ! empty( $args['label_force_left'] ) ) {
248
+                        $label_args['title'] = wp_kses_post( $args['help_text'] );
249
+                        $help_text = '';
250
+                        //$label_args['class'] .= ' d-inline ';
251
+                        $args['wrap_class'] .= ' align-items-center ';
252
+                    }else{
253
+
254
+                    }
255
+
256
+                    $label_base_class = $aui_bs5 ? ' form-check-label' : ' custom-control-label';
257
+                }
258
+                $label_args['class'] .= $label_base_class;
259
+                $temp_label_args = $label_args;
260
+                if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";}
261
+                $label = self::label( $temp_label_args, $type );
262
+            }
263
+
264
+
265
+
266
+
267
+            // set help text in the correct position
268
+            if ( $label_after ) {
269
+                $output .= $label . $help_text;
270
+            }
271
+
272
+            // some input types need a separate wrap
273
+            if ( $type == 'file' ) {
274
+                $output = self::wrap( array(
275
+                    'content' => $output,
276
+                    'class'   => $aui_bs5 ? 'mb-3 custom-file' : 'form-group custom-file'
277
+                ) );
278
+            } elseif ( $type == 'checkbox' ) {
279
+
280
+                $label_args['title'] = $args['label'];
281
+                $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' );
282
+                $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>';
283
+                $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : '';
284
+                if ( $aui_bs5 ) {
285
+                    $wrap_class = $args['switch'] ? 'form-check form-switch' . $switch_size_class : 'form-check';
286
+                }else{
287
+                    $wrap_class = $args['switch'] ? 'custom-switch' . $switch_size_class :  'custom-checkbox' ;
288
+                }
289
+                if ( ! empty( $args['label_force_left'] ) ) {
290
+                    $wrap_class .= $aui_bs5 ? '' : ' d-flex align-content-center';
291
+                    $label = str_replace(array("form-check-label","custom-control-label"),"", self::label( $label_args, 'cb' ) );
292
+                }
293
+                $output     = self::wrap( array(
294
+                    'content' => $output,
295
+                    'class'   => $aui_bs5 ? $wrap_class : 'custom-control ' . $wrap_class
296
+                ) );
297
+
298
+                if ( $args['label_type'] == 'horizontal' ) {
299
+                    $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
300
+                    $output    = $label . '<div class="' . $input_col . '">' . $output . '</div>';
301
+                }
302
+            } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) {
303
+
304
+
305
+                // allow password field to toggle view
306
+                $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" 
307 307
 onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\');
308 308
 var $eli = jQuery(this).parent().parent().find(\'input\');
309 309
 if($el.hasClass(\'fa-eye\'))
310 310
 {$eli.attr(\'type\',\'text\');}
311 311
 else{$eli.attr(\'type\',\'password\');}"
312 312
 ><i class="far fa-fw fa-eye-slash"></i></span>';
313
-			}
314
-
315
-			// input group wraps
316
-			if ( $args['input_group_left'] || $args['input_group_right'] ) {
317
-				$w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
318
-				$group_size = $size == 'lg' ? ' input-group-lg' : '';
319
-				$group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size;
320
-
321
-				if ( $args['input_group_left'] ) {
322
-					$output = self::wrap( array(
323
-						'content'                 => $output,
324
-						'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size,
325
-						'input_group_left'        => $args['input_group_left'],
326
-						'input_group_left_inside' => $args['input_group_left_inside']
327
-					) );
328
-				}
329
-				if ( $args['input_group_right'] ) {
330
-					$output = self::wrap( array(
331
-						'content'                  => $output,
332
-						'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size,
333
-						'input_group_right'        => $args['input_group_right'],
334
-						'input_group_right_inside' => $args['input_group_right_inside']
335
-					) );
336
-				}
337
-
338
-			}
339
-
340
-			if ( ! $label_after ) {
341
-				$output .= $help_text;
342
-			}
343
-
344
-
345
-			if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) {
346
-				$output = self::wrap( array(
347
-					'content' => $output,
348
-					'class'   => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' )
349
-				) );
350
-			}
351
-
352
-			if ( ! $label_after ) {
353
-				$output = $label . $output;
354
-			}
355
-
356
-			// wrap
357
-			if ( ! $args['no_wrap'] ) {
358
-				if ( ! empty( $args['form_group_class'] ) ) {
359
-					$fg_class = esc_attr( $args['form_group_class'] );
360
-				}else{
361
-					$fg_class = $aui_bs5 ? 'mb-3' : 'form-group';
362
-				}
363
-				$form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : $fg_class;
364
-				$wrap_class       = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class;
365
-				$wrap_class       = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
366
-				$output           = self::wrap( array(
367
-					'content'         => $output,
368
-					'class'           => $wrap_class,
369
-					'element_require' => $args['element_require'],
370
-					'argument_id'     => $args['id'],
371
-					'wrap_attributes' => $args['wrap_attributes'],
372
-				) );
373
-			}
374
-		}
375
-
376
-		return $output;
377
-	}
378
-
379
-	public static function label( $args = array(), $type = '' ) {
380
-		global $aui_bs5;
381
-		//<label for="exampleInputEmail1">Email address</label>
382
-		$defaults = array(
383
-			'title'      => 'div',
384
-			'for'        => '',
385
-			'class'      => '',
386
-			'label_type' => '', // empty = hidden, top, horizontal
387
-			'label_col'  => '',
388
-		);
389
-
390
-		/**
391
-		 * Parse incoming $args into an array and merge it with $defaults
392
-		 */
393
-		$args   = wp_parse_args( $args, $defaults );
394
-		$output = '';
395
-
396
-		if ( $args['title'] ) {
397
-
398
-			// maybe hide labels //@todo set a global option for visibility class
399
-			if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) {
400
-				$class = $args['class'];
401
-			} else {
402
-				$class = 'sr-only ' . $args['class'];
403
-			}
404
-
405
-			// maybe horizontal
406
-			if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) {
407
-				$class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label '.$type;
408
-			}
409
-
410
-			if( $aui_bs5 ){ $class .= ' form-label'; }
411
-
412
-			// open
413
-			$output .= '<label ';
414
-
415
-			// for
416
-			if ( ! empty( $args['for'] ) ) {
417
-				$output .= ' for="' . esc_attr( $args['for'] ) . '" ';
418
-			}
419
-
420
-			// class
421
-			$class = $class ? AUI_Component_Helper::esc_classes( $class ) : '';
422
-			$output .= ' class="' . $class . '" ';
423
-
424
-			// close
425
-			$output .= '>';
426
-
427
-
428
-			// title, don't escape fully as can contain html
429
-			if ( ! empty( $args['title'] ) ) {
430
-				$output .= wp_kses_post( $args['title'] );
431
-			}
432
-
433
-			// close wrap
434
-			$output .= '</label>';
435
-
436
-
437
-		}
438
-
439
-
440
-		return $output;
441
-	}
442
-
443
-	/**
444
-	 * Wrap some content in a HTML wrapper.
445
-	 *
446
-	 * @param array $args
447
-	 *
448
-	 * @return string
449
-	 */
450
-	public static function wrap( $args = array() ) {
451
-		global $aui_bs5;
452
-		$defaults = array(
453
-			'type'                     => 'div',
454
-			'class'                    => $aui_bs5 ? 'mb-3' : 'form-group',
455
-			'content'                  => '',
456
-			'input_group_left'         => '',
457
-			'input_group_right'        => '',
458
-			'input_group_left_inside'  => false,
459
-			'input_group_right_inside' => false,
460
-			'element_require'          => '',
461
-			'argument_id'              => '',
462
-			'wrap_attributes'          => array()
463
-		);
464
-
465
-		/**
466
-		 * Parse incoming $args into an array and merge it with $defaults
467
-		 */
468
-		$args   = wp_parse_args( $args, $defaults );
469
-		$output = '';
470
-		if ( $args['type'] ) {
471
-
472
-			// open
473
-			$output .= '<' . sanitize_html_class( $args['type'] );
474
-
475
-			// element require
476
-			if ( ! empty( $args['element_require'] ) ) {
477
-				$output .= AUI_Component_Helper::element_require( $args['element_require'] );
478
-				$args['class'] .= " aui-conditional-field";
479
-			}
480
-
481
-			// argument_id
482
-			if ( ! empty( $args['argument_id'] ) ) {
483
-				$output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"';
484
-			}
485
-
486
-			// class
487
-			$class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
488
-			$output .= ' class="' . $class . '" ';
489
-
490
-			// Attributes
491
-			if ( ! empty( $args['wrap_attributes'] ) ) {
492
-				$output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] );
493
-			}
494
-
495
-			// close wrap
496
-			$output .= ' >';
497
-
498
-
499
-			// Input group left
500
-			if ( ! empty( $args['input_group_left'] ) ) {
501
-				$position_class   = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : '';
502
-				$input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>';
503
-				$output .= $aui_bs5 ? $input_group_left : '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>';
313
+            }
314
+
315
+            // input group wraps
316
+            if ( $args['input_group_left'] || $args['input_group_right'] ) {
317
+                $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
318
+                $group_size = $size == 'lg' ? ' input-group-lg' : '';
319
+                $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size;
320
+
321
+                if ( $args['input_group_left'] ) {
322
+                    $output = self::wrap( array(
323
+                        'content'                 => $output,
324
+                        'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size,
325
+                        'input_group_left'        => $args['input_group_left'],
326
+                        'input_group_left_inside' => $args['input_group_left_inside']
327
+                    ) );
328
+                }
329
+                if ( $args['input_group_right'] ) {
330
+                    $output = self::wrap( array(
331
+                        'content'                  => $output,
332
+                        'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size,
333
+                        'input_group_right'        => $args['input_group_right'],
334
+                        'input_group_right_inside' => $args['input_group_right_inside']
335
+                    ) );
336
+                }
337
+
338
+            }
339
+
340
+            if ( ! $label_after ) {
341
+                $output .= $help_text;
342
+            }
343
+
344
+
345
+            if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) {
346
+                $output = self::wrap( array(
347
+                    'content' => $output,
348
+                    'class'   => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' )
349
+                ) );
350
+            }
351
+
352
+            if ( ! $label_after ) {
353
+                $output = $label . $output;
354
+            }
355
+
356
+            // wrap
357
+            if ( ! $args['no_wrap'] ) {
358
+                if ( ! empty( $args['form_group_class'] ) ) {
359
+                    $fg_class = esc_attr( $args['form_group_class'] );
360
+                }else{
361
+                    $fg_class = $aui_bs5 ? 'mb-3' : 'form-group';
362
+                }
363
+                $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : $fg_class;
364
+                $wrap_class       = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class;
365
+                $wrap_class       = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
366
+                $output           = self::wrap( array(
367
+                    'content'         => $output,
368
+                    'class'           => $wrap_class,
369
+                    'element_require' => $args['element_require'],
370
+                    'argument_id'     => $args['id'],
371
+                    'wrap_attributes' => $args['wrap_attributes'],
372
+                ) );
373
+            }
374
+        }
375
+
376
+        return $output;
377
+    }
378
+
379
+    public static function label( $args = array(), $type = '' ) {
380
+        global $aui_bs5;
381
+        //<label for="exampleInputEmail1">Email address</label>
382
+        $defaults = array(
383
+            'title'      => 'div',
384
+            'for'        => '',
385
+            'class'      => '',
386
+            'label_type' => '', // empty = hidden, top, horizontal
387
+            'label_col'  => '',
388
+        );
389
+
390
+        /**
391
+         * Parse incoming $args into an array and merge it with $defaults
392
+         */
393
+        $args   = wp_parse_args( $args, $defaults );
394
+        $output = '';
395
+
396
+        if ( $args['title'] ) {
397
+
398
+            // maybe hide labels //@todo set a global option for visibility class
399
+            if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) {
400
+                $class = $args['class'];
401
+            } else {
402
+                $class = 'sr-only ' . $args['class'];
403
+            }
404
+
405
+            // maybe horizontal
406
+            if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) {
407
+                $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label '.$type;
408
+            }
409
+
410
+            if( $aui_bs5 ){ $class .= ' form-label'; }
411
+
412
+            // open
413
+            $output .= '<label ';
414
+
415
+            // for
416
+            if ( ! empty( $args['for'] ) ) {
417
+                $output .= ' for="' . esc_attr( $args['for'] ) . '" ';
418
+            }
419
+
420
+            // class
421
+            $class = $class ? AUI_Component_Helper::esc_classes( $class ) : '';
422
+            $output .= ' class="' . $class . '" ';
423
+
424
+            // close
425
+            $output .= '>';
426
+
427
+
428
+            // title, don't escape fully as can contain html
429
+            if ( ! empty( $args['title'] ) ) {
430
+                $output .= wp_kses_post( $args['title'] );
431
+            }
432
+
433
+            // close wrap
434
+            $output .= '</label>';
435
+
436
+
437
+        }
438
+
439
+
440
+        return $output;
441
+    }
442
+
443
+    /**
444
+     * Wrap some content in a HTML wrapper.
445
+     *
446
+     * @param array $args
447
+     *
448
+     * @return string
449
+     */
450
+    public static function wrap( $args = array() ) {
451
+        global $aui_bs5;
452
+        $defaults = array(
453
+            'type'                     => 'div',
454
+            'class'                    => $aui_bs5 ? 'mb-3' : 'form-group',
455
+            'content'                  => '',
456
+            'input_group_left'         => '',
457
+            'input_group_right'        => '',
458
+            'input_group_left_inside'  => false,
459
+            'input_group_right_inside' => false,
460
+            'element_require'          => '',
461
+            'argument_id'              => '',
462
+            'wrap_attributes'          => array()
463
+        );
464
+
465
+        /**
466
+         * Parse incoming $args into an array and merge it with $defaults
467
+         */
468
+        $args   = wp_parse_args( $args, $defaults );
469
+        $output = '';
470
+        if ( $args['type'] ) {
471
+
472
+            // open
473
+            $output .= '<' . sanitize_html_class( $args['type'] );
474
+
475
+            // element require
476
+            if ( ! empty( $args['element_require'] ) ) {
477
+                $output .= AUI_Component_Helper::element_require( $args['element_require'] );
478
+                $args['class'] .= " aui-conditional-field";
479
+            }
480
+
481
+            // argument_id
482
+            if ( ! empty( $args['argument_id'] ) ) {
483
+                $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"';
484
+            }
485
+
486
+            // class
487
+            $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
488
+            $output .= ' class="' . $class . '" ';
489
+
490
+            // Attributes
491
+            if ( ! empty( $args['wrap_attributes'] ) ) {
492
+                $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] );
493
+            }
494
+
495
+            // close wrap
496
+            $output .= ' >';
497
+
498
+
499
+            // Input group left
500
+            if ( ! empty( $args['input_group_left'] ) ) {
501
+                $position_class   = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : '';
502
+                $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>';
503
+                $output .= $aui_bs5 ? $input_group_left : '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>';
504 504
 //				$output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>';
505
-			}
505
+            }
506 506
 
507
-			// content
508
-			$output .= $args['content'];
507
+            // content
508
+            $output .= $args['content'];
509 509
 
510
-			// Input group right
511
-			if ( ! empty( $args['input_group_right'] ) ) {
512
-				$position_class    = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : '';
513
-				$input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>';
514
-				$output .= $aui_bs5 ? str_replace( 'input-group-text','input-group-text top-0 end-0', $input_group_right ) : '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>';
510
+            // Input group right
511
+            if ( ! empty( $args['input_group_right'] ) ) {
512
+                $position_class    = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : '';
513
+                $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>';
514
+                $output .= $aui_bs5 ? str_replace( 'input-group-text','input-group-text top-0 end-0', $input_group_right ) : '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>';
515 515
 //				$output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>';
516
-			}
517
-
518
-
519
-			// close wrap
520
-			$output .= '</' . sanitize_html_class( $args['type'] ) . '>';
521
-
522
-
523
-		} else {
524
-			$output = $args['content'];
525
-		}
526
-
527
-		return $output;
528
-	}
529
-
530
-	/**
531
-	 * Build the component.
532
-	 *
533
-	 * @param array $args
534
-	 *
535
-	 * @return string The rendered component.
536
-	 */
537
-	public static function textarea( $args = array() ) {
538
-		global $aui_bs5;
539
-
540
-		$defaults = array(
541
-			'name'               => '',
542
-			'class'              => '',
543
-			'wrap_class'         => '',
544
-			'id'                 => '',
545
-			'placeholder'        => '',
546
-			'title'              => '',
547
-			'value'              => '',
548
-			'required'           => false,
549
-			'label'              => '',
550
-			'label_after'        => false,
551
-			'label_class'        => '',
552
-			'label_type'         => '',
553
-			'label_col'          => '',
554
-			// sets the label type, default: hidden. Options: hidden, top, horizontal, floating
555
-			'input_group_right'        => '',
556
-			'input_group_left'         => '',
557
-			'input_group_right_inside' => false,
558
-			'form_group_class'      => '',
559
-			'help_text'          => '',
560
-			'validation_text'    => '',
561
-			'validation_pattern' => '',
562
-			'no_wrap'            => false,
563
-			'rows'               => '',
564
-			'wysiwyg'            => false,
565
-			'allow_tags'         => false,
566
-			// Allow HTML tags
567
-			'element_require'    => '',
568
-			// [%element_id%] == "1"
569
-			'extra_attributes'   => array(),
570
-			// an array of extra attributes
571
-			'wrap_attributes'    => array(),
572
-		);
573
-
574
-		/**
575
-		 * Parse incoming $args into an array and merge it with $defaults
576
-		 */
577
-		$args   = wp_parse_args( $args, $defaults );
578
-		$output = '';
579
-		$label = '';
580
-
581
-		// hidden label option needs to be empty
582
-		$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
583
-
584
-		// floating labels don't work with wysiwyg so set it as top
585
-		if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) {
586
-			$args['label_type'] = 'top';
587
-		}
588
-
589
-		$label_after = $args['label_after'];
590
-
591
-		// floating labels need label after
592
-		if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) {
593
-			$label_after         = true;
594
-			$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
595
-		}
596
-
597
-		// label
598
-		if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
599
-		} elseif ( ! empty( $args['label'] ) && ! $label_after ) {
600
-			$label_args = array(
601
-				'title'      => $args['label'],
602
-				'for'        => $args['id'],
603
-				'class'      => $args['label_class'] . " ",
604
-				'label_type' => $args['label_type'],
605
-				'label_col'  => $args['label_col']
606
-			);
607
-			$label .= self::label( $label_args );
608
-		}
609
-
610
-		// maybe horizontal label
611
-		if ( $args['label_type'] == 'horizontal' ) {
612
-			$input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
613
-			$label .= '<div class="' . $input_col . '">';
614
-		}
615
-
616
-		if ( ! empty( $args['wysiwyg'] ) ) {
617
-			ob_start();
618
-			$content   = $args['value'];
619
-			$editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor';
620
-			$settings  = array(
621
-				'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4,
622
-				'quicktags'     => false,
623
-				'media_buttons' => false,
624
-				'editor_class'  => 'form-control',
625
-				'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ),
626
-				'teeny'         => true,
627
-			);
628
-
629
-			// maybe set settings if array
630
-			if ( is_array( $args['wysiwyg'] ) ) {
631
-				$settings = wp_parse_args( $args['wysiwyg'], $settings );
632
-			}
633
-
634
-			wp_editor( $content, $editor_id, $settings );
635
-			$output .= ob_get_clean();
636
-		} else {
637
-
638
-			// open
639
-			$output .= '<textarea ';
640
-
641
-			// name
642
-			if ( ! empty( $args['name'] ) ) {
643
-				$output .= ' name="' . esc_attr( $args['name'] ) . '" ';
644
-			}
645
-
646
-			// id
647
-			if ( ! empty( $args['id'] ) ) {
648
-				$output .= ' id="' . sanitize_html_class( $args['id'] ) . '" ';
649
-			}
650
-
651
-			// placeholder
652
-			if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) {
653
-				$output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" ';
654
-			}
655
-
656
-			// title
657
-			if ( ! empty( $args['title'] ) ) {
658
-				$output .= ' title="' . esc_attr( $args['title'] ) . '" ';
659
-			}
660
-
661
-			// validation text
662
-			if ( ! empty( $args['validation_text'] ) ) {
663
-				$output .= ' oninvalid="setCustomValidity(\'' . esc_attr( addslashes( $args['validation_text'] ) ) . '\')" ';
664
-				$output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
665
-			}
666
-
667
-			// validation_pattern
668
-			if ( ! empty( $args['validation_pattern'] ) ) {
669
-				$output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" ';
670
-			}
671
-
672
-			// required
673
-			if ( ! empty( $args['required'] ) ) {
674
-				$output .= ' required ';
675
-			}
676
-
677
-			// rows
678
-			if ( ! empty( $args['rows'] ) ) {
679
-				$output .= ' rows="' . absint( $args['rows'] ) . '" ';
680
-			}
681
-
682
-
683
-			// class
684
-			$class = ! empty( $args['class'] ) ? $args['class'] : '';
685
-			$output .= ' class="form-control ' . $class . '" ';
686
-
687
-			// extra attributes
688
-			if ( ! empty( $args['extra_attributes'] ) ) {
689
-				$output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
690
-			}
691
-
692
-			// close tag
693
-			$output .= ' >';
694
-
695
-			// value
696
-			if ( ! empty( $args['value'] ) ) {
697
-				if ( ! empty( $args['allow_tags'] ) ) {
698
-					$output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML.
699
-				} else {
700
-					$output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] );
701
-				}
702
-			}
703
-
704
-			// closing tag
705
-			$output .= '</textarea>';
706
-
707
-
708
-			// input group wraps
709
-			if ( $args['input_group_left'] || $args['input_group_right'] ) {
710
-				$w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
711
-				if ( $args['input_group_left'] ) {
712
-					$output = self::wrap( array(
713
-						'content'                 => $output,
714
-						'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
715
-						'input_group_left'        => $args['input_group_left'],
716
-						'input_group_left_inside' => $args['input_group_left_inside']
717
-					) );
718
-				}
719
-				if ( $args['input_group_right'] ) {
720
-					$output = self::wrap( array(
721
-						'content'                  => $output,
722
-						'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
723
-						'input_group_right'        => $args['input_group_right'],
724
-						'input_group_right_inside' => $args['input_group_right_inside']
725
-					) );
726
-				}
727
-
728
-			}
729
-
730
-
731
-		}
732
-
733
-		if ( ! empty( $args['label'] ) && $label_after ) {
734
-			$label_args = array(
735
-				'title'      => $args['label'],
736
-				'for'        => $args['id'],
737
-				'class'      => $args['label_class'] . " ",
738
-				'label_type' => $args['label_type'],
739
-				'label_col'  => $args['label_col']
740
-			);
741
-			$output .= self::label( $label_args );
742
-		}
743
-
744
-		// help text
745
-		if ( ! empty( $args['help_text'] ) ) {
746
-			$output .= AUI_Component_Helper::help_text( $args['help_text'] );
747
-		}
748
-
749
-		if ( ! $label_after ) {
750
-			$output = $label . $output;
751
-		}
752
-
753
-		// maybe horizontal label
754
-		if ( $args['label_type'] == 'horizontal' ) {
755
-			$output .= '</div>';
756
-		}
757
-
758
-
759
-		// wrap
760
-		if ( ! $args['no_wrap'] ) {
761
-			if ( ! empty( $args['form_group_class'] ) ) {
762
-				$fg_class = esc_attr( $args['form_group_class'] );
763
-			}else{
764
-				$fg_class = $aui_bs5 ? 'mb-3' : 'form-group';
765
-			}
766
-			$form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : $fg_class;
767
-			$wrap_class       = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class;
768
-			$wrap_class       = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
769
-			$output           = self::wrap( array(
770
-				'content'         => $output,
771
-				'class'           => $wrap_class,
772
-				'element_require' => $args['element_require'],
773
-				'argument_id'     => $args['id'],
774
-				'wrap_attributes' => $args['wrap_attributes'],
775
-			) );
776
-		}
777
-
778
-
779
-		return $output;
780
-	}
781
-
782
-	/**
783
-	 * Build the component.
784
-	 *
785
-	 * @param array $args
786
-	 *
787
-	 * @return string The rendered component.
788
-	 */
789
-	public static function select( $args = array() ) {
790
-		global $aui_bs5;
791
-		$defaults = array(
792
-			'class'            => '',
793
-			'wrap_class'       => '',
794
-			'id'               => '',
795
-			'title'            => '',
796
-			'value'            => '',
797
-			// can be an array or a string
798
-			'required'         => false,
799
-			'label'            => '',
800
-			'label_after'      => false,
801
-			'label_type'       => '',
802
-			'label_col'        => '',
803
-			// sets the label type, default: hidden. Options: hidden, top, horizontal, floating
804
-			'label_class'      => '',
805
-			'help_text'        => '',
806
-			'placeholder'      => '',
807
-			'options'          => array(),
808
-			// array or string
809
-			'icon'             => '',
810
-			'multiple'         => false,
811
-			'select2'          => false,
812
-			'no_wrap'          => false,
813
-			'input_group_right' => '',
814
-			'input_group_left' => '',
815
-			'input_group_right_inside' => false, // forces the input group inside the input
816
-			'input_group_left_inside' => false, // forces the input group inside the input
817
-			'form_group_class'  => '',
818
-			'element_require'  => '',
819
-			// [%element_id%] == "1"
820
-			'extra_attributes' => array(),
821
-			// an array of extra attributes
822
-			'wrap_attributes'  => array(),
823
-		);
824
-
825
-		/**
826
-		 * Parse incoming $args into an array and merge it with $defaults
827
-		 */
828
-		$args   = wp_parse_args( $args, $defaults );
829
-		$output = '';
830
-
831
-		// for now lets hide floating labels
832
-		if ( $args['label_type'] == 'floating' ) {
833
-			$args['label_type'] = 'hidden';
834
-		}
835
-
836
-		// hidden label option needs to be empty
837
-		$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
838
-
839
-
840
-		$label_after = $args['label_after'];
841
-
842
-		// floating labels need label after
843
-		if ( $args['label_type'] == 'floating' ) {
844
-			$label_after         = true;
845
-			$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
846
-		}
847
-
848
-		// Maybe setup select2
849
-		$is_select2 = false;
850
-		if ( ! empty( $args['select2'] ) ) {
851
-			$args['class'] .= ' aui-select2';
852
-			$is_select2 = true;
853
-		} elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) {
854
-			$is_select2 = true;
855
-		}
856
-
857
-		// select2 tags
858
-		if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason
859
-			$args['data-tags']             = 'true';
860
-			$args['data-token-separators'] = "[',']";
861
-			$args['multiple']              = true;
862
-		}
863
-
864
-		// select2 placeholder
865
-		if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) {
866
-			$args['data-placeholder'] = esc_attr( $args['placeholder'] );
867
-			$args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true;
868
-		}
869
-
870
-		// Set hidden input to save empty value for multiselect.
871
-		if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) {
872
-			$output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>';
873
-		}
874
-
875
-		// open/type
876
-		$output .= '<select ';
877
-
878
-		// style
879
-		if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) {
880
-			$output .= " style='width:100%;' ";
881
-		}
882
-
883
-		// element require
884
-		if ( ! empty( $args['element_require'] ) ) {
885
-			$output .= AUI_Component_Helper::element_require( $args['element_require'] );
886
-			$args['class'] .= " aui-conditional-field";
887
-		}
888
-
889
-		// class
890
-		$class = ! empty( $args['class'] ) ? $args['class'] : '';
891
-		$select_class = $aui_bs5 ? 'form-select ' : 'custom-select ';
892
-		$output .= AUI_Component_Helper::class_attr( $select_class . $class );
893
-
894
-		// name
895
-		if ( ! empty( $args['name'] ) ) {
896
-			$output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] );
897
-		}
898
-
899
-		// id
900
-		if ( ! empty( $args['id'] ) ) {
901
-			$output .= AUI_Component_Helper::id( $args['id'] );
902
-		}
903
-
904
-		// title
905
-		if ( ! empty( $args['title'] ) ) {
906
-			$output .= AUI_Component_Helper::title( $args['title'] );
907
-		}
908
-
909
-		// data-attributes
910
-		$output .= AUI_Component_Helper::data_attributes( $args );
911
-
912
-		// aria-attributes
913
-		$output .= AUI_Component_Helper::aria_attributes( $args );
914
-
915
-		// extra attributes
916
-		if ( ! empty( $args['extra_attributes'] ) ) {
917
-			$output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
918
-		}
919
-
920
-		// required
921
-		if ( ! empty( $args['required'] ) ) {
922
-			$output .= ' required ';
923
-		}
924
-
925
-		// multiple
926
-		if ( ! empty( $args['multiple'] ) ) {
927
-			$output .= ' multiple ';
928
-		}
929
-
930
-		// close opening tag
931
-		$output .= ' >';
932
-
933
-		// placeholder
934
-		if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) {
935
-			$output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>';
936
-		} elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) {
937
-			$output .= "<option></option>"; // select2 needs an empty select to fill the placeholder
938
-		}
939
-
940
-		// Options
941
-		if ( ! empty( $args['options'] ) ) {
942
-
943
-			if ( ! is_array( $args['options'] ) ) {
944
-				$output .= $args['options']; // not the preferred way but an option
945
-			} else {
946
-				foreach ( $args['options'] as $val => $name ) {
947
-					$selected = '';
948
-					if ( is_array( $name ) ) {
949
-						if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) {
950
-							$option_label = isset( $name['label'] ) ? $name['label'] : '';
951
-
952
-							$output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>';
953
-						} else {
954
-							$option_label = isset( $name['label'] ) ? $name['label'] : '';
955
-							$option_value = isset( $name['value'] ) ? $name['value'] : '';
956
-							$extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : '';
957
-							if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) {
958
-								$selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : "";
959
-							} elseif ( ! empty( $args['value'] ) ) {
960
-								$selected = selected( $option_value, stripslashes_deep( $args['value'] ), false );
961
-							} elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) {
962
-								$selected = selected( $option_value, $args['value'], false );
963
-							}
964
-
965
-							$output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>';
966
-						}
967
-					} else {
968
-						if ( ! empty( $args['value'] ) ) {
969
-							if ( is_array( $args['value'] ) ) {
970
-								$selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : '';
971
-							} elseif ( ! empty( $args['value'] ) ) {
972
-								$selected = selected( $args['value'], $val, false );
973
-							}
974
-						} elseif ( $args['value'] === $val ) {
975
-							$selected = selected( $args['value'], $val, false );
976
-						}
977
-						$output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>';
978
-					}
979
-				}
980
-			}
981
-
982
-		}
983
-
984
-		// closing tag
985
-		$output .= '</select>';
986
-
987
-		$label = '';
988
-		$help_text = '';
989
-		// label
990
-		if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
991
-		} elseif ( ! empty( $args['label'] ) && ! $label_after ) {
992
-			$label_args = array(
993
-				'title'      => $args['label'],
994
-				'for'        => $args['id'],
995
-				'class'      => $args['label_class'] . " ",
996
-				'label_type' => $args['label_type'],
997
-				'label_col'  => $args['label_col']
998
-			);
999
-			$label = self::label( $label_args );
1000
-		}
1001
-
1002
-		// help text
1003
-		if ( ! empty( $args['help_text'] ) ) {
1004
-			$help_text = AUI_Component_Helper::help_text( $args['help_text'] );
1005
-		}
1006
-
1007
-		// input group wraps
1008
-		if ( $args['input_group_left'] || $args['input_group_right'] ) {
1009
-			$w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
1010
-			if ( $args['input_group_left'] ) {
1011
-				$output = self::wrap( array(
1012
-					'content'                 => $output,
1013
-					'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
1014
-					'input_group_left'        => $args['input_group_left'],
1015
-					'input_group_left_inside' => $args['input_group_left_inside']
1016
-				) );
1017
-			}
1018
-			if ( $args['input_group_right'] ) {
1019
-				$output = self::wrap( array(
1020
-					'content'                  => $output,
1021
-					'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
1022
-					'input_group_right'        => $args['input_group_right'],
1023
-					'input_group_right_inside' => $args['input_group_right_inside']
1024
-				) );
1025
-			}
1026
-
1027
-		}
1028
-
1029
-		if ( ! $label_after ) {
1030
-			$output .= $help_text;
1031
-		}
1032
-
1033
-
1034
-		if ( $args['label_type'] == 'horizontal' ) {
1035
-			$output = self::wrap( array(
1036
-				'content' => $output,
1037
-				'class'   => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' )
1038
-			) );
1039
-		}
1040
-
1041
-		if ( ! $label_after ) {
1042
-			$output = $label . $output;
1043
-		}
1044
-
1045
-		// maybe horizontal label
516
+            }
517
+
518
+
519
+            // close wrap
520
+            $output .= '</' . sanitize_html_class( $args['type'] ) . '>';
521
+
522
+
523
+        } else {
524
+            $output = $args['content'];
525
+        }
526
+
527
+        return $output;
528
+    }
529
+
530
+    /**
531
+     * Build the component.
532
+     *
533
+     * @param array $args
534
+     *
535
+     * @return string The rendered component.
536
+     */
537
+    public static function textarea( $args = array() ) {
538
+        global $aui_bs5;
539
+
540
+        $defaults = array(
541
+            'name'               => '',
542
+            'class'              => '',
543
+            'wrap_class'         => '',
544
+            'id'                 => '',
545
+            'placeholder'        => '',
546
+            'title'              => '',
547
+            'value'              => '',
548
+            'required'           => false,
549
+            'label'              => '',
550
+            'label_after'        => false,
551
+            'label_class'        => '',
552
+            'label_type'         => '',
553
+            'label_col'          => '',
554
+            // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
555
+            'input_group_right'        => '',
556
+            'input_group_left'         => '',
557
+            'input_group_right_inside' => false,
558
+            'form_group_class'      => '',
559
+            'help_text'          => '',
560
+            'validation_text'    => '',
561
+            'validation_pattern' => '',
562
+            'no_wrap'            => false,
563
+            'rows'               => '',
564
+            'wysiwyg'            => false,
565
+            'allow_tags'         => false,
566
+            // Allow HTML tags
567
+            'element_require'    => '',
568
+            // [%element_id%] == "1"
569
+            'extra_attributes'   => array(),
570
+            // an array of extra attributes
571
+            'wrap_attributes'    => array(),
572
+        );
573
+
574
+        /**
575
+         * Parse incoming $args into an array and merge it with $defaults
576
+         */
577
+        $args   = wp_parse_args( $args, $defaults );
578
+        $output = '';
579
+        $label = '';
580
+
581
+        // hidden label option needs to be empty
582
+        $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
583
+
584
+        // floating labels don't work with wysiwyg so set it as top
585
+        if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) {
586
+            $args['label_type'] = 'top';
587
+        }
588
+
589
+        $label_after = $args['label_after'];
590
+
591
+        // floating labels need label after
592
+        if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) {
593
+            $label_after         = true;
594
+            $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
595
+        }
596
+
597
+        // label
598
+        if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
599
+        } elseif ( ! empty( $args['label'] ) && ! $label_after ) {
600
+            $label_args = array(
601
+                'title'      => $args['label'],
602
+                'for'        => $args['id'],
603
+                'class'      => $args['label_class'] . " ",
604
+                'label_type' => $args['label_type'],
605
+                'label_col'  => $args['label_col']
606
+            );
607
+            $label .= self::label( $label_args );
608
+        }
609
+
610
+        // maybe horizontal label
611
+        if ( $args['label_type'] == 'horizontal' ) {
612
+            $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
613
+            $label .= '<div class="' . $input_col . '">';
614
+        }
615
+
616
+        if ( ! empty( $args['wysiwyg'] ) ) {
617
+            ob_start();
618
+            $content   = $args['value'];
619
+            $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor';
620
+            $settings  = array(
621
+                'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4,
622
+                'quicktags'     => false,
623
+                'media_buttons' => false,
624
+                'editor_class'  => 'form-control',
625
+                'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ),
626
+                'teeny'         => true,
627
+            );
628
+
629
+            // maybe set settings if array
630
+            if ( is_array( $args['wysiwyg'] ) ) {
631
+                $settings = wp_parse_args( $args['wysiwyg'], $settings );
632
+            }
633
+
634
+            wp_editor( $content, $editor_id, $settings );
635
+            $output .= ob_get_clean();
636
+        } else {
637
+
638
+            // open
639
+            $output .= '<textarea ';
640
+
641
+            // name
642
+            if ( ! empty( $args['name'] ) ) {
643
+                $output .= ' name="' . esc_attr( $args['name'] ) . '" ';
644
+            }
645
+
646
+            // id
647
+            if ( ! empty( $args['id'] ) ) {
648
+                $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" ';
649
+            }
650
+
651
+            // placeholder
652
+            if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) {
653
+                $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" ';
654
+            }
655
+
656
+            // title
657
+            if ( ! empty( $args['title'] ) ) {
658
+                $output .= ' title="' . esc_attr( $args['title'] ) . '" ';
659
+            }
660
+
661
+            // validation text
662
+            if ( ! empty( $args['validation_text'] ) ) {
663
+                $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( addslashes( $args['validation_text'] ) ) . '\')" ';
664
+                $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
665
+            }
666
+
667
+            // validation_pattern
668
+            if ( ! empty( $args['validation_pattern'] ) ) {
669
+                $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" ';
670
+            }
671
+
672
+            // required
673
+            if ( ! empty( $args['required'] ) ) {
674
+                $output .= ' required ';
675
+            }
676
+
677
+            // rows
678
+            if ( ! empty( $args['rows'] ) ) {
679
+                $output .= ' rows="' . absint( $args['rows'] ) . '" ';
680
+            }
681
+
682
+
683
+            // class
684
+            $class = ! empty( $args['class'] ) ? $args['class'] : '';
685
+            $output .= ' class="form-control ' . $class . '" ';
686
+
687
+            // extra attributes
688
+            if ( ! empty( $args['extra_attributes'] ) ) {
689
+                $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
690
+            }
691
+
692
+            // close tag
693
+            $output .= ' >';
694
+
695
+            // value
696
+            if ( ! empty( $args['value'] ) ) {
697
+                if ( ! empty( $args['allow_tags'] ) ) {
698
+                    $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML.
699
+                } else {
700
+                    $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] );
701
+                }
702
+            }
703
+
704
+            // closing tag
705
+            $output .= '</textarea>';
706
+
707
+
708
+            // input group wraps
709
+            if ( $args['input_group_left'] || $args['input_group_right'] ) {
710
+                $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
711
+                if ( $args['input_group_left'] ) {
712
+                    $output = self::wrap( array(
713
+                        'content'                 => $output,
714
+                        'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
715
+                        'input_group_left'        => $args['input_group_left'],
716
+                        'input_group_left_inside' => $args['input_group_left_inside']
717
+                    ) );
718
+                }
719
+                if ( $args['input_group_right'] ) {
720
+                    $output = self::wrap( array(
721
+                        'content'                  => $output,
722
+                        'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
723
+                        'input_group_right'        => $args['input_group_right'],
724
+                        'input_group_right_inside' => $args['input_group_right_inside']
725
+                    ) );
726
+                }
727
+
728
+            }
729
+
730
+
731
+        }
732
+
733
+        if ( ! empty( $args['label'] ) && $label_after ) {
734
+            $label_args = array(
735
+                'title'      => $args['label'],
736
+                'for'        => $args['id'],
737
+                'class'      => $args['label_class'] . " ",
738
+                'label_type' => $args['label_type'],
739
+                'label_col'  => $args['label_col']
740
+            );
741
+            $output .= self::label( $label_args );
742
+        }
743
+
744
+        // help text
745
+        if ( ! empty( $args['help_text'] ) ) {
746
+            $output .= AUI_Component_Helper::help_text( $args['help_text'] );
747
+        }
748
+
749
+        if ( ! $label_after ) {
750
+            $output = $label . $output;
751
+        }
752
+
753
+        // maybe horizontal label
754
+        if ( $args['label_type'] == 'horizontal' ) {
755
+            $output .= '</div>';
756
+        }
757
+
758
+
759
+        // wrap
760
+        if ( ! $args['no_wrap'] ) {
761
+            if ( ! empty( $args['form_group_class'] ) ) {
762
+                $fg_class = esc_attr( $args['form_group_class'] );
763
+            }else{
764
+                $fg_class = $aui_bs5 ? 'mb-3' : 'form-group';
765
+            }
766
+            $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : $fg_class;
767
+            $wrap_class       = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class;
768
+            $wrap_class       = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
769
+            $output           = self::wrap( array(
770
+                'content'         => $output,
771
+                'class'           => $wrap_class,
772
+                'element_require' => $args['element_require'],
773
+                'argument_id'     => $args['id'],
774
+                'wrap_attributes' => $args['wrap_attributes'],
775
+            ) );
776
+        }
777
+
778
+
779
+        return $output;
780
+    }
781
+
782
+    /**
783
+     * Build the component.
784
+     *
785
+     * @param array $args
786
+     *
787
+     * @return string The rendered component.
788
+     */
789
+    public static function select( $args = array() ) {
790
+        global $aui_bs5;
791
+        $defaults = array(
792
+            'class'            => '',
793
+            'wrap_class'       => '',
794
+            'id'               => '',
795
+            'title'            => '',
796
+            'value'            => '',
797
+            // can be an array or a string
798
+            'required'         => false,
799
+            'label'            => '',
800
+            'label_after'      => false,
801
+            'label_type'       => '',
802
+            'label_col'        => '',
803
+            // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
804
+            'label_class'      => '',
805
+            'help_text'        => '',
806
+            'placeholder'      => '',
807
+            'options'          => array(),
808
+            // array or string
809
+            'icon'             => '',
810
+            'multiple'         => false,
811
+            'select2'          => false,
812
+            'no_wrap'          => false,
813
+            'input_group_right' => '',
814
+            'input_group_left' => '',
815
+            'input_group_right_inside' => false, // forces the input group inside the input
816
+            'input_group_left_inside' => false, // forces the input group inside the input
817
+            'form_group_class'  => '',
818
+            'element_require'  => '',
819
+            // [%element_id%] == "1"
820
+            'extra_attributes' => array(),
821
+            // an array of extra attributes
822
+            'wrap_attributes'  => array(),
823
+        );
824
+
825
+        /**
826
+         * Parse incoming $args into an array and merge it with $defaults
827
+         */
828
+        $args   = wp_parse_args( $args, $defaults );
829
+        $output = '';
830
+
831
+        // for now lets hide floating labels
832
+        if ( $args['label_type'] == 'floating' ) {
833
+            $args['label_type'] = 'hidden';
834
+        }
835
+
836
+        // hidden label option needs to be empty
837
+        $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
838
+
839
+
840
+        $label_after = $args['label_after'];
841
+
842
+        // floating labels need label after
843
+        if ( $args['label_type'] == 'floating' ) {
844
+            $label_after         = true;
845
+            $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
846
+        }
847
+
848
+        // Maybe setup select2
849
+        $is_select2 = false;
850
+        if ( ! empty( $args['select2'] ) ) {
851
+            $args['class'] .= ' aui-select2';
852
+            $is_select2 = true;
853
+        } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) {
854
+            $is_select2 = true;
855
+        }
856
+
857
+        // select2 tags
858
+        if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason
859
+            $args['data-tags']             = 'true';
860
+            $args['data-token-separators'] = "[',']";
861
+            $args['multiple']              = true;
862
+        }
863
+
864
+        // select2 placeholder
865
+        if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) {
866
+            $args['data-placeholder'] = esc_attr( $args['placeholder'] );
867
+            $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true;
868
+        }
869
+
870
+        // Set hidden input to save empty value for multiselect.
871
+        if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) {
872
+            $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>';
873
+        }
874
+
875
+        // open/type
876
+        $output .= '<select ';
877
+
878
+        // style
879
+        if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) {
880
+            $output .= " style='width:100%;' ";
881
+        }
882
+
883
+        // element require
884
+        if ( ! empty( $args['element_require'] ) ) {
885
+            $output .= AUI_Component_Helper::element_require( $args['element_require'] );
886
+            $args['class'] .= " aui-conditional-field";
887
+        }
888
+
889
+        // class
890
+        $class = ! empty( $args['class'] ) ? $args['class'] : '';
891
+        $select_class = $aui_bs5 ? 'form-select ' : 'custom-select ';
892
+        $output .= AUI_Component_Helper::class_attr( $select_class . $class );
893
+
894
+        // name
895
+        if ( ! empty( $args['name'] ) ) {
896
+            $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] );
897
+        }
898
+
899
+        // id
900
+        if ( ! empty( $args['id'] ) ) {
901
+            $output .= AUI_Component_Helper::id( $args['id'] );
902
+        }
903
+
904
+        // title
905
+        if ( ! empty( $args['title'] ) ) {
906
+            $output .= AUI_Component_Helper::title( $args['title'] );
907
+        }
908
+
909
+        // data-attributes
910
+        $output .= AUI_Component_Helper::data_attributes( $args );
911
+
912
+        // aria-attributes
913
+        $output .= AUI_Component_Helper::aria_attributes( $args );
914
+
915
+        // extra attributes
916
+        if ( ! empty( $args['extra_attributes'] ) ) {
917
+            $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
918
+        }
919
+
920
+        // required
921
+        if ( ! empty( $args['required'] ) ) {
922
+            $output .= ' required ';
923
+        }
924
+
925
+        // multiple
926
+        if ( ! empty( $args['multiple'] ) ) {
927
+            $output .= ' multiple ';
928
+        }
929
+
930
+        // close opening tag
931
+        $output .= ' >';
932
+
933
+        // placeholder
934
+        if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) {
935
+            $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>';
936
+        } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) {
937
+            $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder
938
+        }
939
+
940
+        // Options
941
+        if ( ! empty( $args['options'] ) ) {
942
+
943
+            if ( ! is_array( $args['options'] ) ) {
944
+                $output .= $args['options']; // not the preferred way but an option
945
+            } else {
946
+                foreach ( $args['options'] as $val => $name ) {
947
+                    $selected = '';
948
+                    if ( is_array( $name ) ) {
949
+                        if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) {
950
+                            $option_label = isset( $name['label'] ) ? $name['label'] : '';
951
+
952
+                            $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>';
953
+                        } else {
954
+                            $option_label = isset( $name['label'] ) ? $name['label'] : '';
955
+                            $option_value = isset( $name['value'] ) ? $name['value'] : '';
956
+                            $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : '';
957
+                            if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) {
958
+                                $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : "";
959
+                            } elseif ( ! empty( $args['value'] ) ) {
960
+                                $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false );
961
+                            } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) {
962
+                                $selected = selected( $option_value, $args['value'], false );
963
+                            }
964
+
965
+                            $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>';
966
+                        }
967
+                    } else {
968
+                        if ( ! empty( $args['value'] ) ) {
969
+                            if ( is_array( $args['value'] ) ) {
970
+                                $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : '';
971
+                            } elseif ( ! empty( $args['value'] ) ) {
972
+                                $selected = selected( $args['value'], $val, false );
973
+                            }
974
+                        } elseif ( $args['value'] === $val ) {
975
+                            $selected = selected( $args['value'], $val, false );
976
+                        }
977
+                        $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>';
978
+                    }
979
+                }
980
+            }
981
+
982
+        }
983
+
984
+        // closing tag
985
+        $output .= '</select>';
986
+
987
+        $label = '';
988
+        $help_text = '';
989
+        // label
990
+        if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
991
+        } elseif ( ! empty( $args['label'] ) && ! $label_after ) {
992
+            $label_args = array(
993
+                'title'      => $args['label'],
994
+                'for'        => $args['id'],
995
+                'class'      => $args['label_class'] . " ",
996
+                'label_type' => $args['label_type'],
997
+                'label_col'  => $args['label_col']
998
+            );
999
+            $label = self::label( $label_args );
1000
+        }
1001
+
1002
+        // help text
1003
+        if ( ! empty( $args['help_text'] ) ) {
1004
+            $help_text = AUI_Component_Helper::help_text( $args['help_text'] );
1005
+        }
1006
+
1007
+        // input group wraps
1008
+        if ( $args['input_group_left'] || $args['input_group_right'] ) {
1009
+            $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
1010
+            if ( $args['input_group_left'] ) {
1011
+                $output = self::wrap( array(
1012
+                    'content'                 => $output,
1013
+                    'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
1014
+                    'input_group_left'        => $args['input_group_left'],
1015
+                    'input_group_left_inside' => $args['input_group_left_inside']
1016
+                ) );
1017
+            }
1018
+            if ( $args['input_group_right'] ) {
1019
+                $output = self::wrap( array(
1020
+                    'content'                  => $output,
1021
+                    'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
1022
+                    'input_group_right'        => $args['input_group_right'],
1023
+                    'input_group_right_inside' => $args['input_group_right_inside']
1024
+                ) );
1025
+            }
1026
+
1027
+        }
1028
+
1029
+        if ( ! $label_after ) {
1030
+            $output .= $help_text;
1031
+        }
1032
+
1033
+
1034
+        if ( $args['label_type'] == 'horizontal' ) {
1035
+            $output = self::wrap( array(
1036
+                'content' => $output,
1037
+                'class'   => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' )
1038
+            ) );
1039
+        }
1040
+
1041
+        if ( ! $label_after ) {
1042
+            $output = $label . $output;
1043
+        }
1044
+
1045
+        // maybe horizontal label
1046 1046
 //		if ( $args['label_type'] == 'horizontal' ) {
1047 1047
 //			$output .= '</div>';
1048 1048
 //		}
1049 1049
 
1050 1050
 
1051
-		// wrap
1052
-		if ( ! $args['no_wrap'] ) {
1053
-			if ( ! empty( $args['form_group_class'] ) ) {
1054
-				$fg_class = esc_attr( $args['form_group_class'] );
1055
-			}else{
1056
-				$fg_class = $aui_bs5 ? 'mb-3' : 'form-group';
1057
-			}
1058
-			$wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class;
1059
-			$wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
1060
-			$output     = self::wrap( array(
1061
-				'content'         => $output,
1062
-				'class'           => $wrap_class,
1063
-				'element_require' => $args['element_require'],
1064
-				'argument_id'     => $args['id'],
1065
-				'wrap_attributes' => $args['wrap_attributes'],
1066
-			) );
1067
-		}
1068
-
1069
-
1070
-		return $output;
1071
-	}
1072
-
1073
-	/**
1074
-	 * Build the component.
1075
-	 *
1076
-	 * @param array $args
1077
-	 *
1078
-	 * @return string The rendered component.
1079
-	 */
1080
-	public static function radio( $args = array() ) {
1081
-		global $aui_bs5;
1082
-
1083
-		$defaults = array(
1084
-			'class'            => '',
1085
-			'wrap_class'       => '',
1086
-			'id'               => '',
1087
-			'title'            => '',
1088
-			'horizontal'       => false,
1089
-			// sets the lable horizontal
1090
-			'value'            => '',
1091
-			'label'            => '',
1092
-			'label_class'      => '',
1093
-			'label_type'       => '',
1094
-			'label_col'        => '',
1095
-			// sets the label type, default: hidden. Options: hidden, top, horizontal, floating
1096
-			'help_text'        => '',
1097
-			'inline'           => true,
1098
-			'required'         => false,
1099
-			'options'          => array(),
1100
-			'icon'             => '',
1101
-			'no_wrap'          => false,
1102
-			'element_require'  => '',
1103
-			// [%element_id%] == "1"
1104
-			'extra_attributes' => array(),
1105
-			// an array of extra attributes
1106
-			'wrap_attributes'  => array()
1107
-		);
1108
-
1109
-		/**
1110
-		 * Parse incoming $args into an array and merge it with $defaults
1111
-		 */
1112
-		$args = wp_parse_args( $args, $defaults );
1113
-
1114
-		// for now lets use horizontal for floating
1115
-		if ( $args['label_type'] == 'floating' ) {
1116
-			$args['label_type'] = 'horizontal';
1117
-		}
1118
-
1119
-		$label_args = array(
1120
-			'title'      => $args['label'],
1121
-			'class'      => $args['label_class'] . " pt-0 ",
1122
-			'label_type' => $args['label_type'],
1123
-			'label_col'  => $args['label_col']
1124
-		);
1125
-
1126
-		if ( $args['label_type'] == 'top' || $args['label_type'] == 'hidden' ) {
1127
-			$label_args['class'] .= 'd-block ';
1128
-
1129
-			if ( $args['label_type'] == 'hidden' ) {
1130
-				$label_args['class'] .= 'sr-only ';
1131
-			}
1132
-		}
1133
-
1134
-		$output = '';
1135
-
1136
-		// label before
1137
-		if ( ! empty( $args['label'] ) ) {
1138
-			$output .= self::label( $label_args, 'radio' );
1139
-		}
1140
-
1141
-		// maybe horizontal label
1142
-		if ( $args['label_type'] == 'horizontal' ) {
1143
-			$input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
1144
-			$output .= '<div class="' . $input_col . '">';
1145
-		}
1146
-
1147
-		if ( ! empty( $args['options'] ) ) {
1148
-			$count = 0;
1149
-			foreach ( $args['options'] as $value => $label ) {
1150
-				$option_args            = $args;
1151
-				$option_args['value']   = $value;
1152
-				$option_args['label']   = $label;
1153
-				$option_args['checked'] = $value == $args['value'] ? true : false;
1154
-				$output .= self::radio_option( $option_args, $count );
1155
-				$count ++;
1156
-			}
1157
-		}
1158
-
1159
-		// help text
1160
-		$help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : '';
1161
-		$output .= $help_text;
1162
-
1163
-		// maybe horizontal label
1164
-		if ( $args['label_type'] == 'horizontal' ) {
1165
-			$output .= '</div>';
1166
-		}
1167
-
1168
-		// wrap
1169
-		$fg_class = $aui_bs5 ? 'mb-3' : 'form-group';
1170
-		$wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class;
1171
-		$wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
1172
-		$output     = self::wrap( array(
1173
-			'content'         => $output,
1174
-			'class'           => $wrap_class,
1175
-			'element_require' => $args['element_require'],
1176
-			'argument_id'     => $args['id'],
1177
-			'wrap_attributes' => $args['wrap_attributes'],
1178
-		) );
1179
-
1180
-
1181
-		return $output;
1182
-	}
1183
-
1184
-	/**
1185
-	 * Build the component.
1186
-	 *
1187
-	 * @param array $args
1188
-	 *
1189
-	 * @return string The rendered component.
1190
-	 */
1191
-	public static function radio_option( $args = array(), $count = '' ) {
1192
-		$defaults = array(
1193
-			'class'            => '',
1194
-			'id'               => '',
1195
-			'title'            => '',
1196
-			'value'            => '',
1197
-			'required'         => false,
1198
-			'inline'           => true,
1199
-			'label'            => '',
1200
-			'options'          => array(),
1201
-			'icon'             => '',
1202
-			'no_wrap'          => false,
1203
-			'extra_attributes' => array() // an array of extra attributes
1204
-		);
1205
-
1206
-		/**
1207
-		 * Parse incoming $args into an array and merge it with $defaults
1208
-		 */
1209
-		$args = wp_parse_args( $args, $defaults );
1210
-
1211
-		$output = '';
1212
-
1213
-		// open/type
1214
-		$output .= '<input type="radio"';
1215
-
1216
-		// class
1217
-		$output .= ' class="form-check-input" ';
1218
-
1219
-		// name
1220
-		if ( ! empty( $args['name'] ) ) {
1221
-			$output .= AUI_Component_Helper::name( $args['name'] );
1222
-		}
1223
-
1224
-		// id
1225
-		if ( ! empty( $args['id'] ) ) {
1226
-			$output .= AUI_Component_Helper::id( $args['id'] . $count );
1227
-		}
1228
-
1229
-		// title
1230
-		if ( ! empty( $args['title'] ) ) {
1231
-			$output .= AUI_Component_Helper::title( $args['title'] );
1232
-		}
1233
-
1234
-		// value
1235
-		if ( isset( $args['value'] ) ) {
1236
-			$output .= AUI_Component_Helper::value( $args['value'] );
1237
-		}
1238
-
1239
-		// checked, for radio and checkboxes
1240
-		if ( $args['checked'] ) {
1241
-			$output .= ' checked ';
1242
-		}
1243
-
1244
-		// data-attributes
1245
-		$output .= AUI_Component_Helper::data_attributes( $args );
1246
-
1247
-		// aria-attributes
1248
-		$output .= AUI_Component_Helper::aria_attributes( $args );
1249
-
1250
-		// extra attributes
1251
-		if ( ! empty( $args['extra_attributes'] ) ) {
1252
-			$output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
1253
-		}
1254
-
1255
-		// required
1256
-		if ( ! empty( $args['required'] ) ) {
1257
-			$output .= ' required ';
1258
-		}
1259
-
1260
-		// close opening tag
1261
-		$output .= ' >';
1262
-
1263
-		// label
1264
-		if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
1265
-		} elseif ( ! empty( $args['label'] ) ) {
1266
-			$output .= self::label( array(
1267
-				'title' => $args['label'],
1268
-				'for'   => $args['id'] . $count,
1269
-				'class' => 'form-check-label'
1270
-			), 'radio' );
1271
-		}
1272
-
1273
-		// wrap
1274
-		if ( ! $args['no_wrap'] ) {
1275
-			$wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check';
1276
-
1277
-			// Unique wrap class
1278
-			$uniq_class = 'fwrap';
1279
-			if ( ! empty( $args['name'] ) ) {
1280
-				$uniq_class .= '-' . $args['name'];
1281
-			} else if ( ! empty( $args['id'] ) ) {
1282
-				$uniq_class .= '-' . $args['id'];
1283
-			}
1284
-
1285
-			if ( isset( $args['value'] ) || $args['value'] !== "" ) {
1286
-				$uniq_class .= '-' . $args['value'];
1287
-			} else {
1288
-				$uniq_class .= '-' . $count;
1289
-			}
1290
-			$wrap_class .= ' ' . sanitize_html_class( $uniq_class );
1291
-
1292
-			$output = self::wrap( array(
1293
-				'content' => $output,
1294
-				'class'   => $wrap_class
1295
-			) );
1296
-		}
1297
-
1298
-		return $output;
1299
-	}
1051
+        // wrap
1052
+        if ( ! $args['no_wrap'] ) {
1053
+            if ( ! empty( $args['form_group_class'] ) ) {
1054
+                $fg_class = esc_attr( $args['form_group_class'] );
1055
+            }else{
1056
+                $fg_class = $aui_bs5 ? 'mb-3' : 'form-group';
1057
+            }
1058
+            $wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class;
1059
+            $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
1060
+            $output     = self::wrap( array(
1061
+                'content'         => $output,
1062
+                'class'           => $wrap_class,
1063
+                'element_require' => $args['element_require'],
1064
+                'argument_id'     => $args['id'],
1065
+                'wrap_attributes' => $args['wrap_attributes'],
1066
+            ) );
1067
+        }
1068
+
1069
+
1070
+        return $output;
1071
+    }
1072
+
1073
+    /**
1074
+     * Build the component.
1075
+     *
1076
+     * @param array $args
1077
+     *
1078
+     * @return string The rendered component.
1079
+     */
1080
+    public static function radio( $args = array() ) {
1081
+        global $aui_bs5;
1082
+
1083
+        $defaults = array(
1084
+            'class'            => '',
1085
+            'wrap_class'       => '',
1086
+            'id'               => '',
1087
+            'title'            => '',
1088
+            'horizontal'       => false,
1089
+            // sets the lable horizontal
1090
+            'value'            => '',
1091
+            'label'            => '',
1092
+            'label_class'      => '',
1093
+            'label_type'       => '',
1094
+            'label_col'        => '',
1095
+            // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
1096
+            'help_text'        => '',
1097
+            'inline'           => true,
1098
+            'required'         => false,
1099
+            'options'          => array(),
1100
+            'icon'             => '',
1101
+            'no_wrap'          => false,
1102
+            'element_require'  => '',
1103
+            // [%element_id%] == "1"
1104
+            'extra_attributes' => array(),
1105
+            // an array of extra attributes
1106
+            'wrap_attributes'  => array()
1107
+        );
1108
+
1109
+        /**
1110
+         * Parse incoming $args into an array and merge it with $defaults
1111
+         */
1112
+        $args = wp_parse_args( $args, $defaults );
1113
+
1114
+        // for now lets use horizontal for floating
1115
+        if ( $args['label_type'] == 'floating' ) {
1116
+            $args['label_type'] = 'horizontal';
1117
+        }
1118
+
1119
+        $label_args = array(
1120
+            'title'      => $args['label'],
1121
+            'class'      => $args['label_class'] . " pt-0 ",
1122
+            'label_type' => $args['label_type'],
1123
+            'label_col'  => $args['label_col']
1124
+        );
1125
+
1126
+        if ( $args['label_type'] == 'top' || $args['label_type'] == 'hidden' ) {
1127
+            $label_args['class'] .= 'd-block ';
1128
+
1129
+            if ( $args['label_type'] == 'hidden' ) {
1130
+                $label_args['class'] .= 'sr-only ';
1131
+            }
1132
+        }
1133
+
1134
+        $output = '';
1135
+
1136
+        // label before
1137
+        if ( ! empty( $args['label'] ) ) {
1138
+            $output .= self::label( $label_args, 'radio' );
1139
+        }
1140
+
1141
+        // maybe horizontal label
1142
+        if ( $args['label_type'] == 'horizontal' ) {
1143
+            $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
1144
+            $output .= '<div class="' . $input_col . '">';
1145
+        }
1146
+
1147
+        if ( ! empty( $args['options'] ) ) {
1148
+            $count = 0;
1149
+            foreach ( $args['options'] as $value => $label ) {
1150
+                $option_args            = $args;
1151
+                $option_args['value']   = $value;
1152
+                $option_args['label']   = $label;
1153
+                $option_args['checked'] = $value == $args['value'] ? true : false;
1154
+                $output .= self::radio_option( $option_args, $count );
1155
+                $count ++;
1156
+            }
1157
+        }
1158
+
1159
+        // help text
1160
+        $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : '';
1161
+        $output .= $help_text;
1162
+
1163
+        // maybe horizontal label
1164
+        if ( $args['label_type'] == 'horizontal' ) {
1165
+            $output .= '</div>';
1166
+        }
1167
+
1168
+        // wrap
1169
+        $fg_class = $aui_bs5 ? 'mb-3' : 'form-group';
1170
+        $wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class;
1171
+        $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
1172
+        $output     = self::wrap( array(
1173
+            'content'         => $output,
1174
+            'class'           => $wrap_class,
1175
+            'element_require' => $args['element_require'],
1176
+            'argument_id'     => $args['id'],
1177
+            'wrap_attributes' => $args['wrap_attributes'],
1178
+        ) );
1179
+
1180
+
1181
+        return $output;
1182
+    }
1183
+
1184
+    /**
1185
+     * Build the component.
1186
+     *
1187
+     * @param array $args
1188
+     *
1189
+     * @return string The rendered component.
1190
+     */
1191
+    public static function radio_option( $args = array(), $count = '' ) {
1192
+        $defaults = array(
1193
+            'class'            => '',
1194
+            'id'               => '',
1195
+            'title'            => '',
1196
+            'value'            => '',
1197
+            'required'         => false,
1198
+            'inline'           => true,
1199
+            'label'            => '',
1200
+            'options'          => array(),
1201
+            'icon'             => '',
1202
+            'no_wrap'          => false,
1203
+            'extra_attributes' => array() // an array of extra attributes
1204
+        );
1205
+
1206
+        /**
1207
+         * Parse incoming $args into an array and merge it with $defaults
1208
+         */
1209
+        $args = wp_parse_args( $args, $defaults );
1210
+
1211
+        $output = '';
1212
+
1213
+        // open/type
1214
+        $output .= '<input type="radio"';
1215
+
1216
+        // class
1217
+        $output .= ' class="form-check-input" ';
1218
+
1219
+        // name
1220
+        if ( ! empty( $args['name'] ) ) {
1221
+            $output .= AUI_Component_Helper::name( $args['name'] );
1222
+        }
1223
+
1224
+        // id
1225
+        if ( ! empty( $args['id'] ) ) {
1226
+            $output .= AUI_Component_Helper::id( $args['id'] . $count );
1227
+        }
1228
+
1229
+        // title
1230
+        if ( ! empty( $args['title'] ) ) {
1231
+            $output .= AUI_Component_Helper::title( $args['title'] );
1232
+        }
1233
+
1234
+        // value
1235
+        if ( isset( $args['value'] ) ) {
1236
+            $output .= AUI_Component_Helper::value( $args['value'] );
1237
+        }
1238
+
1239
+        // checked, for radio and checkboxes
1240
+        if ( $args['checked'] ) {
1241
+            $output .= ' checked ';
1242
+        }
1243
+
1244
+        // data-attributes
1245
+        $output .= AUI_Component_Helper::data_attributes( $args );
1246
+
1247
+        // aria-attributes
1248
+        $output .= AUI_Component_Helper::aria_attributes( $args );
1249
+
1250
+        // extra attributes
1251
+        if ( ! empty( $args['extra_attributes'] ) ) {
1252
+            $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
1253
+        }
1254
+
1255
+        // required
1256
+        if ( ! empty( $args['required'] ) ) {
1257
+            $output .= ' required ';
1258
+        }
1259
+
1260
+        // close opening tag
1261
+        $output .= ' >';
1262
+
1263
+        // label
1264
+        if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
1265
+        } elseif ( ! empty( $args['label'] ) ) {
1266
+            $output .= self::label( array(
1267
+                'title' => $args['label'],
1268
+                'for'   => $args['id'] . $count,
1269
+                'class' => 'form-check-label'
1270
+            ), 'radio' );
1271
+        }
1272
+
1273
+        // wrap
1274
+        if ( ! $args['no_wrap'] ) {
1275
+            $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check';
1276
+
1277
+            // Unique wrap class
1278
+            $uniq_class = 'fwrap';
1279
+            if ( ! empty( $args['name'] ) ) {
1280
+                $uniq_class .= '-' . $args['name'];
1281
+            } else if ( ! empty( $args['id'] ) ) {
1282
+                $uniq_class .= '-' . $args['id'];
1283
+            }
1284
+
1285
+            if ( isset( $args['value'] ) || $args['value'] !== "" ) {
1286
+                $uniq_class .= '-' . $args['value'];
1287
+            } else {
1288
+                $uniq_class .= '-' . $count;
1289
+            }
1290
+            $wrap_class .= ' ' . sanitize_html_class( $uniq_class );
1291
+
1292
+            $output = self::wrap( array(
1293
+                'content' => $output,
1294
+                'class'   => $wrap_class
1295
+            ) );
1296
+        }
1297
+
1298
+        return $output;
1299
+    }
1300 1300
 
1301 1301
 }
1302 1302
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/class-getpaid-admin-profile.php 1 patch
Indentation   +185 added lines, -185 removed lines patch added patch discarded remove patch
@@ -5,129 +5,129 @@  discard block
 block discarded – undo
5 5
  */
6 6
 
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit; // Exit if accessed directly
8
+    exit; // Exit if accessed directly
9 9
 }
10 10
 
11 11
 if ( ! class_exists( 'GetPaid_Admin_Profile', false ) ) :
12 12
 
13
-	/**
14
-	 * GetPaid_Admin_Profile Class.
15
-	 */
16
-	class GetPaid_Admin_Profile {
17
-
18
-		/**
19
-		 * Hook in tabs.
20
-		 */
21
-		public function __construct() {
22
-			add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 );
23
-			add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 );
24
-
25
-			add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) );
26
-			add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) );
27
-		}
28
-
29
-		/**
30
-		 * Get Address Fields for the edit user pages.
31
-		 *
32
-		 * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned
33
-		 */
34
-		public function get_customer_meta_fields() {
35
-
36
-			$show_fields = apply_filters(
37
-				'getpaid_customer_meta_fields',
38
-				array(
39
-					'billing' => array(
40
-						'title'  => __( 'Billing Details (GetPaid)', 'invoicing' ),
41
-						'fields' => array(
42
-							'_wpinv_first_name' => array(
43
-								'label'       => __( 'First name', 'invoicing' ),
44
-								'description' => '',
45
-							),
46
-							'_wpinv_last_name'  => array(
47
-								'label'       => __( 'Last name', 'invoicing' ),
48
-								'description' => '',
49
-							),
50
-							'_wpinv_company'    => array(
51
-								'label'       => __( 'Company', 'invoicing' ),
52
-								'description' => '',
53
-							),
54
-							'_wpinv_company_id' => array(
55
-								'label'       => __( 'Company ID', 'invoicing' ),
56
-								'description' => '',
57
-							),
58
-							'_wpinv_address'    => array(
59
-								'label'       => __( 'Address', 'invoicing' ),
60
-								'description' => '',
61
-							),
62
-							'_wpinv_city'       => array(
63
-								'label'       => __( 'City', 'invoicing' ),
64
-								'description' => '',
65
-							),
66
-							'_wpinv_zip'        => array(
67
-								'label'       => __( 'Postcode / ZIP', 'invoicing' ),
68
-								'description' => '',
69
-							),
70
-							'_wpinv_country'    => array(
71
-								'label'       => __( 'Country / Region', 'invoicing' ),
72
-								'description' => '',
73
-								'class'       => 'getpaid_js_field-country',
74
-								'type'        => 'select',
75
-								'options'     => array( '' => __( 'Select a country / region&hellip;', 'invoicing' ) ) + wpinv_get_country_list(),
76
-							),
77
-							'_wpinv_state'      => array(
78
-								'label'       => __( 'State / County', 'invoicing' ),
79
-								'description' => __( 'State / County or state code', 'invoicing' ),
80
-								'class'       => 'getpaid_js_field-state regular-text',
81
-							),
82
-							'_wpinv_phone'      => array(
83
-								'label'       => __( 'Phone', 'invoicing' ),
84
-								'description' => '',
85
-							),
86
-							'_wpinv_vat_number' => array(
87
-								'label'       => __( 'VAT Number', 'invoicing' ),
88
-								'description' => '',
89
-							),
90
-						),
91
-					),
92
-				)
93
-			);
94
-			return $show_fields;
95
-		}
96
-
97
-		/**
98
-		 * Show Address Fields on edit user pages.
99
-		 *
100
-		 * @param WP_User $user
101
-		 */
102
-		public function add_customer_meta_fields( $user ) {
103
-			if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) {
104
-				return;
105
-			}
106
-
107
-			$show_fields = $this->get_customer_meta_fields();
108
-
109
-			$customer = getpaid_get_customer_by_user_id( (int) $user->ID );
110
-
111
-			foreach ( $show_fields as $fieldset_key => $fieldset ) :
112
-				if ( ! wpinv_use_taxes() && isset( $fieldset['fields']['_wpinv_vat_number'] ) ) {
113
-					unset( $fieldset['fields']['_wpinv_vat_number'] );
114
-				}
115
-				?>
13
+    /**
14
+     * GetPaid_Admin_Profile Class.
15
+     */
16
+    class GetPaid_Admin_Profile {
17
+
18
+        /**
19
+         * Hook in tabs.
20
+         */
21
+        public function __construct() {
22
+            add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 );
23
+            add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 );
24
+
25
+            add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) );
26
+            add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) );
27
+        }
28
+
29
+        /**
30
+         * Get Address Fields for the edit user pages.
31
+         *
32
+         * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned
33
+         */
34
+        public function get_customer_meta_fields() {
35
+
36
+            $show_fields = apply_filters(
37
+                'getpaid_customer_meta_fields',
38
+                array(
39
+                    'billing' => array(
40
+                        'title'  => __( 'Billing Details (GetPaid)', 'invoicing' ),
41
+                        'fields' => array(
42
+                            '_wpinv_first_name' => array(
43
+                                'label'       => __( 'First name', 'invoicing' ),
44
+                                'description' => '',
45
+                            ),
46
+                            '_wpinv_last_name'  => array(
47
+                                'label'       => __( 'Last name', 'invoicing' ),
48
+                                'description' => '',
49
+                            ),
50
+                            '_wpinv_company'    => array(
51
+                                'label'       => __( 'Company', 'invoicing' ),
52
+                                'description' => '',
53
+                            ),
54
+                            '_wpinv_company_id' => array(
55
+                                'label'       => __( 'Company ID', 'invoicing' ),
56
+                                'description' => '',
57
+                            ),
58
+                            '_wpinv_address'    => array(
59
+                                'label'       => __( 'Address', 'invoicing' ),
60
+                                'description' => '',
61
+                            ),
62
+                            '_wpinv_city'       => array(
63
+                                'label'       => __( 'City', 'invoicing' ),
64
+                                'description' => '',
65
+                            ),
66
+                            '_wpinv_zip'        => array(
67
+                                'label'       => __( 'Postcode / ZIP', 'invoicing' ),
68
+                                'description' => '',
69
+                            ),
70
+                            '_wpinv_country'    => array(
71
+                                'label'       => __( 'Country / Region', 'invoicing' ),
72
+                                'description' => '',
73
+                                'class'       => 'getpaid_js_field-country',
74
+                                'type'        => 'select',
75
+                                'options'     => array( '' => __( 'Select a country / region&hellip;', 'invoicing' ) ) + wpinv_get_country_list(),
76
+                            ),
77
+                            '_wpinv_state'      => array(
78
+                                'label'       => __( 'State / County', 'invoicing' ),
79
+                                'description' => __( 'State / County or state code', 'invoicing' ),
80
+                                'class'       => 'getpaid_js_field-state regular-text',
81
+                            ),
82
+                            '_wpinv_phone'      => array(
83
+                                'label'       => __( 'Phone', 'invoicing' ),
84
+                                'description' => '',
85
+                            ),
86
+                            '_wpinv_vat_number' => array(
87
+                                'label'       => __( 'VAT Number', 'invoicing' ),
88
+                                'description' => '',
89
+                            ),
90
+                        ),
91
+                    ),
92
+                )
93
+            );
94
+            return $show_fields;
95
+        }
96
+
97
+        /**
98
+         * Show Address Fields on edit user pages.
99
+         *
100
+         * @param WP_User $user
101
+         */
102
+        public function add_customer_meta_fields( $user ) {
103
+            if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) {
104
+                return;
105
+            }
106
+
107
+            $show_fields = $this->get_customer_meta_fields();
108
+
109
+            $customer = getpaid_get_customer_by_user_id( (int) $user->ID );
110
+
111
+            foreach ( $show_fields as $fieldset_key => $fieldset ) :
112
+                if ( ! wpinv_use_taxes() && isset( $fieldset['fields']['_wpinv_vat_number'] ) ) {
113
+                    unset( $fieldset['fields']['_wpinv_vat_number'] );
114
+                }
115
+                ?>
116 116
 				<h2><?php echo esc_html( $fieldset['title'] ); ?></h2>
117 117
 				<table class="form-table" id="<?php echo esc_attr( 'getpaid-fieldset-' . $fieldset_key ); ?>">
118 118
 					<?php foreach ( $fieldset['fields'] as $key => $field ) :
119
-						if ( ! empty( $customer ) ) {
120
-							if ( strpos( $key, '_wpinv_' ) === 0 ) {
121
-								$save_key = substr( $key , 7 );
122
-							} else {
123
-								$save_key = $key;
124
-							}
125
-
126
-							$value = $customer->get( $save_key );
127
-						} else {
128
-							$value = $this->get_user_meta( $user->ID, $key );
129
-						}
130
-						?>
119
+                        if ( ! empty( $customer ) ) {
120
+                            if ( strpos( $key, '_wpinv_' ) === 0 ) {
121
+                                $save_key = substr( $key , 7 );
122
+                            } else {
123
+                                $save_key = $key;
124
+                            }
125
+
126
+                            $value = $customer->get( $save_key );
127
+                        } else {
128
+                            $value = $this->get_user_meta( $user->ID, $key );
129
+                        }
130
+                        ?>
131 131
 						<tr>
132 132
 							<th>
133 133
 								<label for="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $field['label'] ); ?></label>
@@ -150,75 +150,75 @@  discard block
 block discarded – undo
150 150
 					<?php endforeach; ?>
151 151
 				</table>
152 152
 				<?php
153
-			endforeach;
154
-		}
155
-
156
-		/**
157
-		 * Save Address Fields on edit user pages.
158
-		 *
159
-		 * @param int $user_id User ID of the user being saved
160
-		 */
161
-		public function save_customer_meta_fields( $user_id ) {
162
-			if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) {
163
-				return;
164
-			}
165
-
166
-			$save_fields = $this->get_customer_meta_fields();
167
-			$save_data = array();
168
-
169
-			foreach ( $save_fields as $fieldset ) {
170
-				foreach ( $fieldset['fields'] as $key => $field ) {
171
-					if ( strpos( $key, '_wpinv_' ) === 0 ) {
172
-						$save_key = substr( $key , 7 );
173
-					} else {
174
-						$save_key = $key;
175
-					}
176
-
177
-					if ( $save_key && isset( $field['type'] ) && 'checkbox' === $field['type'] ) {
178
-						$save_data[ $save_key ] = ! empty( $_POST[ $key ] ) ? true : false;
179
-					} else if ( $save_key && isset( $_POST[ $key ] ) ) {
180
-						$save_data[ $save_key ] = wpinv_clean( $_POST[ $key ] );
181
-					}
182
-				}
183
-			}
184
-
185
-			if ( empty( $save_data ) ) {
186
-				return;
187
-			}
188
-
189
-			$customer = getpaid_get_customer_by_user_id( (int) $user_id );
190
-
191
-			if ( empty( $customer ) ) {
192
-				$customer = new GetPaid_Customer( 0 );
193
-				$customer->clone_user( (int) $user_id );
194
-			}
195
-
196
-			foreach ( $save_data as $key => $value ) {
197
-				$customer->set( $key, $value );
198
-			}
199
-
200
-			$customer->save();
201
-		}
202
-
203
-		/**
204
-		 * Get user meta for a given key, with fallbacks to core user info for pre-existing fields.
205
-		 *
206
-		 * @since 3.1.0
207
-		 * @param int    $user_id User ID of the user being edited
208
-		 * @param string $key     Key for user meta field
209
-		 * @return string
210
-		 */
211
-		protected function get_user_meta( $user_id, $key ) {
212
-			$value           = get_user_meta( $user_id, $key, true );
213
-			$existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' );
214
-
215
-			if ( ! $value && in_array( $key, $existing_fields ) ) {
216
-				$value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true );
217
-			}
218
-
219
-			return $value;
220
-		}
221
-	}
153
+            endforeach;
154
+        }
155
+
156
+        /**
157
+         * Save Address Fields on edit user pages.
158
+         *
159
+         * @param int $user_id User ID of the user being saved
160
+         */
161
+        public function save_customer_meta_fields( $user_id ) {
162
+            if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) {
163
+                return;
164
+            }
165
+
166
+            $save_fields = $this->get_customer_meta_fields();
167
+            $save_data = array();
168
+
169
+            foreach ( $save_fields as $fieldset ) {
170
+                foreach ( $fieldset['fields'] as $key => $field ) {
171
+                    if ( strpos( $key, '_wpinv_' ) === 0 ) {
172
+                        $save_key = substr( $key , 7 );
173
+                    } else {
174
+                        $save_key = $key;
175
+                    }
176
+
177
+                    if ( $save_key && isset( $field['type'] ) && 'checkbox' === $field['type'] ) {
178
+                        $save_data[ $save_key ] = ! empty( $_POST[ $key ] ) ? true : false;
179
+                    } else if ( $save_key && isset( $_POST[ $key ] ) ) {
180
+                        $save_data[ $save_key ] = wpinv_clean( $_POST[ $key ] );
181
+                    }
182
+                }
183
+            }
184
+
185
+            if ( empty( $save_data ) ) {
186
+                return;
187
+            }
188
+
189
+            $customer = getpaid_get_customer_by_user_id( (int) $user_id );
190
+
191
+            if ( empty( $customer ) ) {
192
+                $customer = new GetPaid_Customer( 0 );
193
+                $customer->clone_user( (int) $user_id );
194
+            }
195
+
196
+            foreach ( $save_data as $key => $value ) {
197
+                $customer->set( $key, $value );
198
+            }
199
+
200
+            $customer->save();
201
+        }
202
+
203
+        /**
204
+         * Get user meta for a given key, with fallbacks to core user info for pre-existing fields.
205
+         *
206
+         * @since 3.1.0
207
+         * @param int    $user_id User ID of the user being edited
208
+         * @param string $key     Key for user meta field
209
+         * @return string
210
+         */
211
+        protected function get_user_meta( $user_id, $key ) {
212
+            $value           = get_user_meta( $user_id, $key, true );
213
+            $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' );
214
+
215
+            if ( ! $value && in_array( $key, $existing_fields ) ) {
216
+                $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true );
217
+            }
218
+
219
+            return $value;
220
+        }
221
+    }
222 222
 
223 223
 endif;
224 224
 
Please login to merge, or discard this patch.
vendor/ayecode/wp-ayecode-ui/includes/inc/bs-conversion.php 1 patch
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -14,76 +14,76 @@
 block discarded – undo
14 14
  * @return array|mixed|string|string[]
15 15
  */
16 16
 function aui_bs_convert_sd_output( $output, $instance = '', $args = '', $sd = '' ) {
17
-	global $aui_bs5;
17
+    global $aui_bs5;
18 18
 
19
-	if ( $aui_bs5 ) {
20
-		$convert = array(
21
-			'"ml-' => '"ms-',
22
-			'"mr-' => '"me-',
23
-			'"pl-' => '"ps-',
24
-			'"pr-' => '"pe-',
25
-			"'ml-" => "'ms-",
26
-			"'mr-" => "'me-",
27
-			"'pl-" => "'ps-",
28
-			"'pr-" => "'pe-",
29
-			' ml-' => ' ms-',
30
-			' mr-' => ' me-',
31
-			' pl-' => ' ps-',
32
-			' pr-' => ' pe-',
33
-			'.ml-' => '.ms-',
34
-			'.mr-' => '.me-',
35
-			'.pl-' => '.ps-',
36
-			'.pr-' => '.pe-',
37
-			' form-row' => ' row',
38
-			' embed-responsive-item' => '',
39
-			' embed-responsive' => ' ratio',
40
-			'-1by1'    => '-1x1',
41
-			'-4by3'    => '-4x3',
42
-			'-16by9'    => '-16x9',
43
-			'-21by9'    => '-21x9',
44
-			'geodir-lightbox-image' => 'aui-lightbox-image',
45
-			'geodir-lightbox-iframe' => 'aui-lightbox-iframe',
46
-			' badge-'   => ' text-bg-',
47
-			'form-group'   => 'mb-3',
48
-			'custom-select'   => 'form-select',
49
-			'float-left'   => 'float-start',
50
-			'float-right'   => 'float-end',
51
-			'text-left'    => 'text-start',
52
-			'text-sm-left'    => 'text-sm-start',
53
-			'text-md-left'    => 'text-md-start',
54
-			'text-lg-left'    => 'text-lg-start',
55
-			'text-right'    => 'text-end',
56
-			'text-sm-right'    => 'text-sm-end',
57
-			'text-md-right'    => 'text-md-end',
58
-			'text-lg-right'    => 'text-lg-end',
59
-			'border-right'    => 'border-end',
60
-			'border-left'    => 'border-start',
61
-			'font-weight-'  => 'fw-',
62
-			'btn-block'     => 'w-100',
63
-			'rounded-left'  => 'rounded-start',
64
-			'rounded-right'  => 'rounded-end',
65
-			'font-italic' => 'fst-italic',
19
+    if ( $aui_bs5 ) {
20
+        $convert = array(
21
+            '"ml-' => '"ms-',
22
+            '"mr-' => '"me-',
23
+            '"pl-' => '"ps-',
24
+            '"pr-' => '"pe-',
25
+            "'ml-" => "'ms-",
26
+            "'mr-" => "'me-",
27
+            "'pl-" => "'ps-",
28
+            "'pr-" => "'pe-",
29
+            ' ml-' => ' ms-',
30
+            ' mr-' => ' me-',
31
+            ' pl-' => ' ps-',
32
+            ' pr-' => ' pe-',
33
+            '.ml-' => '.ms-',
34
+            '.mr-' => '.me-',
35
+            '.pl-' => '.ps-',
36
+            '.pr-' => '.pe-',
37
+            ' form-row' => ' row',
38
+            ' embed-responsive-item' => '',
39
+            ' embed-responsive' => ' ratio',
40
+            '-1by1'    => '-1x1',
41
+            '-4by3'    => '-4x3',
42
+            '-16by9'    => '-16x9',
43
+            '-21by9'    => '-21x9',
44
+            'geodir-lightbox-image' => 'aui-lightbox-image',
45
+            'geodir-lightbox-iframe' => 'aui-lightbox-iframe',
46
+            ' badge-'   => ' text-bg-',
47
+            'form-group'   => 'mb-3',
48
+            'custom-select'   => 'form-select',
49
+            'float-left'   => 'float-start',
50
+            'float-right'   => 'float-end',
51
+            'text-left'    => 'text-start',
52
+            'text-sm-left'    => 'text-sm-start',
53
+            'text-md-left'    => 'text-md-start',
54
+            'text-lg-left'    => 'text-lg-start',
55
+            'text-right'    => 'text-end',
56
+            'text-sm-right'    => 'text-sm-end',
57
+            'text-md-right'    => 'text-md-end',
58
+            'text-lg-right'    => 'text-lg-end',
59
+            'border-right'    => 'border-end',
60
+            'border-left'    => 'border-start',
61
+            'font-weight-'  => 'fw-',
62
+            'btn-block'     => 'w-100',
63
+            'rounded-left'  => 'rounded-start',
64
+            'rounded-right'  => 'rounded-end',
65
+            'font-italic' => 'fst-italic',
66 66
 
67 67
 //			'custom-control custom-checkbox'    => 'form-check',
68
-			// data
69
-			' data-toggle=' => ' data-bs-toggle=',
70
-			'data-ride=' => 'data-bs-ride=',
71
-			'data-controlnav=' => 'data-bs-controlnav=',
72
-			'data-slide='   => 'data-bs-slide=',
73
-			'data-slide-to=' => 'data-bs-slide-to=',
74
-			'data-target='  => 'data-bs-target=',
75
-			'data-dismiss="modal"'  => 'data-bs-dismiss="modal"',
76
-			'class="close"' => 'class="btn-close"',
77
-			'<span aria-hidden="true">&times;</span>' => '',
78
-		);
79
-		$output  = str_replace(
80
-			array_keys( $convert ),
81
-			array_values( $convert ),
82
-			$output
83
-		);
84
-	}
68
+            // data
69
+            ' data-toggle=' => ' data-bs-toggle=',
70
+            'data-ride=' => 'data-bs-ride=',
71
+            'data-controlnav=' => 'data-bs-controlnav=',
72
+            'data-slide='   => 'data-bs-slide=',
73
+            'data-slide-to=' => 'data-bs-slide-to=',
74
+            'data-target='  => 'data-bs-target=',
75
+            'data-dismiss="modal"'  => 'data-bs-dismiss="modal"',
76
+            'class="close"' => 'class="btn-close"',
77
+            '<span aria-hidden="true">&times;</span>' => '',
78
+        );
79
+        $output  = str_replace(
80
+            array_keys( $convert ),
81
+            array_values( $convert ),
82
+            $output
83
+        );
84
+    }
85 85
 
86
-	return $output;
86
+    return $output;
87 87
 }
88 88
 
89 89
 add_filter( 'wp_super_duper_widget_output', 'aui_bs_convert_sd_output', 10, 4 ); //$output, $instance, $args, $this
Please login to merge, or discard this patch.
vendor/ayecode/wp-super-duper/sd-plugin.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -15,12 +15,12 @@  discard block
 block discarded – undo
15 15
  */
16 16
 
17 17
 if ( ! defined( 'ABSPATH' ) ) {
18
-	exit;
18
+    exit;
19 19
 }
20 20
 
21 21
 if ( ! class_exists( 'WP_Super_Duper' ) ) {
22
-	// include the class if needed
23
-	include_once( dirname( __FILE__ ) . "/wp-super-duper.php" );
22
+    // include the class if needed
23
+    include_once( dirname( __FILE__ ) . "/wp-super-duper.php" );
24 24
 }
25 25
 
26 26
 /*
@@ -35,5 +35,5 @@  discard block
 block discarded – undo
35 35
 
36 36
 
37 37
 if ( ! function_exists( 'sd_get_class_build_keys' ) ) {
38
-	include_once( dirname( __FILE__ ) . "/sd-functions.php" );
38
+    include_once( dirname( __FILE__ ) . "/sd-functions.php" );
39 39
 }
40 40
\ No newline at end of file
Please login to merge, or discard this patch.
vendor/ayecode/wp-super-duper/hello-world.php 1 patch
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -3,114 +3,114 @@  discard block
 block discarded – undo
3 3
 class SD_Hello_World extends WP_Super_Duper {
4 4
 
5 5
 
6
-	public $arguments;
7
-
8
-	/**
9
-	 * Sets up the widgets name etc
10
-	 */
11
-	public function __construct() {
12
-
13
-		$options = array(
14
-			'textdomain'     => 'super-duper',
15
-			// textdomain of the plugin/theme (used to prefix the Gutenberg block)
16
-			'block-icon'     => 'fas fa-globe-americas',
17
-			// Dash icon name for the block: https://developer.wordpress.org/resource/dashicons/#arrow-right
18
-			// OR font-awesome 5 class name: fas fa-globe-americas
19
-			'block-category' => 'widgets',
20
-			// the category for the block, 'common', 'formatting', 'layout', 'widgets', 'embed'.
21
-			'block-keywords' => "['hello','world']",
22
-			// used in the block search, MAX 3
23
-			'block-output'   => array( // the block visual output elements as an array
6
+    public $arguments;
7
+
8
+    /**
9
+     * Sets up the widgets name etc
10
+     */
11
+    public function __construct() {
12
+
13
+        $options = array(
14
+            'textdomain'     => 'super-duper',
15
+            // textdomain of the plugin/theme (used to prefix the Gutenberg block)
16
+            'block-icon'     => 'fas fa-globe-americas',
17
+            // Dash icon name for the block: https://developer.wordpress.org/resource/dashicons/#arrow-right
18
+            // OR font-awesome 5 class name: fas fa-globe-americas
19
+            'block-category' => 'widgets',
20
+            // the category for the block, 'common', 'formatting', 'layout', 'widgets', 'embed'.
21
+            'block-keywords' => "['hello','world']",
22
+            // used in the block search, MAX 3
23
+            'block-output'   => array( // the block visual output elements as an array
24 24
 //				array(
25 25
 //					'element' => 'p',
26 26
 //					'title'   => __( 'Placeholder', 'ayecode-connect' ),
27 27
 //					'class'   => '[%className%]',
28 28
 //					'content' => 'Hello: [%after_text%]' // block properties can be added by wrapping them in [%name%]
29 29
 //				)
30
-				array(
31
-					'element'       => 'BlocksProps',
32
-					'inner_element' => 'p',
33
-					'blockProps'    => array(
34
-						'className'               => '[%WrapClass%]',
30
+                array(
31
+                    'element'       => 'BlocksProps',
32
+                    'inner_element' => 'p',
33
+                    'blockProps'    => array(
34
+                        'className'               => '[%WrapClass%]',
35 35
 //						'content' => 'Hello: [%after_text%]'
36 36
 //						'if_dangerouslySetInnerHTML' => '{__html: blockstrap_build_shape(props.attributes) }',
37
-					),
38
-					'content' => 'Hello: [%after_text%]' // block properties can be added by wrapping them in [%name%]
39
-
40
-
41
-				),
42
-			),
43
-			'block-wrap'    => '', // You can specify the type of element to wrap the block `div` or `span` etc.. Or blank for no wrap at all.
44
-			'class_name'     => __CLASS__,
45
-			// The calling class name
46
-			'base_id'        => 'hello_world',
47
-			// this is used as the widget id and the shortcode id.
48
-			'name'           => __( 'Hello World', 'ayecode-connect' ),
49
-			// the name of the widget/block
50
-			'widget_ops'     => array(
51
-				'classname'   => 'hello-world-class',
52
-				// widget class
53
-				'description' => esc_html__( 'This is an example that will take a text parameter and output it after `Hello:`.', 'ayecode-connect' ),
54
-				// widget description
55
-			),
56
-			'no_wrap'       => true, // This will prevent the widget being wrapped in the containing widget class div.
57
-			'arguments'      => array( // these are the arguments that will be used in the widget, shortcode and block settings.
58
-				'after_text' => array( // this is the input name=''
59
-					'title'       => __( 'Text after hello:', 'ayecode-connect' ),
60
-					// input title
61
-					'desc'        => __( 'This is the text that will appear after `Hello:`.', 'ayecode-connect' ),
62
-					// input description
63
-					'type'        => 'text',
64
-					// the type of input, test, select, checkbox etc.
65
-					'placeholder' => 'World',
66
-					// the input placeholder text.
67
-					'desc_tip'    => true,
68
-					// if the input should show the widget description text as a tooltip.
69
-					'default'     => 'World',
70
-					// the input default value.
71
-					'advanced'    => false
72
-					// not yet implemented
73
-				),
74
-			)
75
-		);
76
-
77
-		parent::__construct( $options );
78
-	}
79
-
80
-
81
-	/**
82
-	 * This is the output function for the widget, shortcode and block (front end).
83
-	 *
84
-	 * @param array $args The arguments values.
85
-	 * @param array $widget_args The widget arguments when used.
86
-	 * @param string $content The shortcode content argument
87
-	 *
88
-	 * @return string
89
-	 */
90
-	public function output( $args = array(), $widget_args = array(), $content = '' ) {
91
-
92
-		/**
93
-		 * @var string $after_text
94
-		 * @var string $another_input This is added by filter below.
95
-		 */
96
-		extract( $args, EXTR_SKIP );
97
-
98
-		/*
37
+                    ),
38
+                    'content' => 'Hello: [%after_text%]' // block properties can be added by wrapping them in [%name%]
39
+
40
+
41
+                ),
42
+            ),
43
+            'block-wrap'    => '', // You can specify the type of element to wrap the block `div` or `span` etc.. Or blank for no wrap at all.
44
+            'class_name'     => __CLASS__,
45
+            // The calling class name
46
+            'base_id'        => 'hello_world',
47
+            // this is used as the widget id and the shortcode id.
48
+            'name'           => __( 'Hello World', 'ayecode-connect' ),
49
+            // the name of the widget/block
50
+            'widget_ops'     => array(
51
+                'classname'   => 'hello-world-class',
52
+                // widget class
53
+                'description' => esc_html__( 'This is an example that will take a text parameter and output it after `Hello:`.', 'ayecode-connect' ),
54
+                // widget description
55
+            ),
56
+            'no_wrap'       => true, // This will prevent the widget being wrapped in the containing widget class div.
57
+            'arguments'      => array( // these are the arguments that will be used in the widget, shortcode and block settings.
58
+                'after_text' => array( // this is the input name=''
59
+                    'title'       => __( 'Text after hello:', 'ayecode-connect' ),
60
+                    // input title
61
+                    'desc'        => __( 'This is the text that will appear after `Hello:`.', 'ayecode-connect' ),
62
+                    // input description
63
+                    'type'        => 'text',
64
+                    // the type of input, test, select, checkbox etc.
65
+                    'placeholder' => 'World',
66
+                    // the input placeholder text.
67
+                    'desc_tip'    => true,
68
+                    // if the input should show the widget description text as a tooltip.
69
+                    'default'     => 'World',
70
+                    // the input default value.
71
+                    'advanced'    => false
72
+                    // not yet implemented
73
+                ),
74
+            )
75
+        );
76
+
77
+        parent::__construct( $options );
78
+    }
79
+
80
+
81
+    /**
82
+     * This is the output function for the widget, shortcode and block (front end).
83
+     *
84
+     * @param array $args The arguments values.
85
+     * @param array $widget_args The widget arguments when used.
86
+     * @param string $content The shortcode content argument
87
+     *
88
+     * @return string
89
+     */
90
+    public function output( $args = array(), $widget_args = array(), $content = '' ) {
91
+
92
+        /**
93
+         * @var string $after_text
94
+         * @var string $another_input This is added by filter below.
95
+         */
96
+        extract( $args, EXTR_SKIP );
97
+
98
+        /*
99 99
 		 * This value is added by filter so might not exist if filter is removed so we check.
100 100
 		 */
101
-		if ( ! isset( $another_input ) ) {
102
-			$another_input = '';
103
-		}
101
+        if ( ! isset( $another_input ) ) {
102
+            $another_input = '';
103
+        }
104 104
 
105
-		return "Helllo: " . $after_text . "" . $another_input;
105
+        return "Helllo: " . $after_text . "" . $another_input;
106 106
 
107
-	}
107
+    }
108 108
 
109 109
 }
110 110
 
111 111
 // register it.
112 112
 add_action( 'widgets_init', function () {
113
-	register_widget( 'SD_Hello_World' );
113
+    register_widget( 'SD_Hello_World' );
114 114
 } );
115 115
 
116 116
 
@@ -123,26 +123,26 @@  discard block
 block discarded – undo
123 123
  */
124 124
 function _my_extra_arguments( $options ) {
125 125
 
126
-	/*
126
+    /*
127 127
 	 * Add a new input option.
128 128
 	 */
129
-	$options['arguments']['another_input'] = array(
130
-		'name'        => 'another_input', // this is the input name=''
131
-		'title'       => __( 'Another input:', 'ayecode-connect' ), // input title
132
-		'desc'        => __( 'This is an input added via filter.', 'ayecode-connect' ), // input description
133
-		'type'        => 'text', // the type of input, test, select, checkbox etc.
134
-		'placeholder' => 'Placeholder text', // the input placeholder text.
135
-		'desc_tip'    => true, // if the input should show the widget description text as a tooltip.
136
-		'default'     => '', // the input default value.
137
-		'advanced'    => false // not yet implemented
138
-	);
139
-
140
-	/*
129
+    $options['arguments']['another_input'] = array(
130
+        'name'        => 'another_input', // this is the input name=''
131
+        'title'       => __( 'Another input:', 'ayecode-connect' ), // input title
132
+        'desc'        => __( 'This is an input added via filter.', 'ayecode-connect' ), // input description
133
+        'type'        => 'text', // the type of input, test, select, checkbox etc.
134
+        'placeholder' => 'Placeholder text', // the input placeholder text.
135
+        'desc_tip'    => true, // if the input should show the widget description text as a tooltip.
136
+        'default'     => '', // the input default value.
137
+        'advanced'    => false // not yet implemented
138
+    );
139
+
140
+    /*
141 141
 	 * Output the new option in the block output also.
142 142
 	 */
143
-	$options['block-output']['element::p']['content'] = $options['block-output']['element::p']['content'] . " [%another_input%]";;
143
+    $options['block-output']['element::p']['content'] = $options['block-output']['element::p']['content'] . " [%another_input%]";;
144 144
 
145
-	return $options;
145
+    return $options;
146 146
 }
147 147
 
148 148
 //add_filter( 'wp_super_duper_options_hello_world', '_my_extra_arguments' );
149 149
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv.php 1 patch
Indentation   +616 added lines, -616 removed lines patch added patch discarded remove patch
@@ -14,620 +14,620 @@
 block discarded – undo
14 14
  */
15 15
 class WPInv_Plugin {
16 16
 
17
-	/**
18
-	 * GetPaid version.
19
-	 *
20
-	 * @var string
21
-	 */
22
-	public $version;
23
-
24
-	/**
25
-	 * Data container.
26
-	 *
27
-	 * @var array
28
-	 */
29
-	protected $data = array();
30
-
31
-	/**
32
-	 * Form elements instance.
33
-	 *
34
-	 * @var WPInv_Payment_Form_Elements
35
-	 */
36
-	public $form_elements;
37
-
38
-	/**
39
-	 * @var array An array of payment gateways.
40
-	 */
41
-	public $gateways;
42
-
43
-	/**
44
-	 * Class constructor.
45
-	 */
46
-	public function __construct() {
47
-		$this->define_constants();
48
-		$this->includes();
49
-		$this->init_hooks();
50
-		$this->set_properties();
51
-	}
52
-
53
-	/**
54
-	 * Sets a custom data property.
55
-	 *
56
-	 * @param string $prop The prop to set.
57
-	 * @param mixed $value The value to retrieve.
58
-	 */
59
-	public function set( $prop, $value ) {
60
-		$this->data[ $prop ] = $value;
61
-	}
62
-
63
-	/**
64
-	 * Gets a custom data property.
65
-	 *
66
-	 * @param string $prop The prop to set.
67
-	 * @return mixed The value.
68
-	 */
69
-	public function get( $prop ) {
70
-		if ( isset( $this->data[ $prop ] ) ) {
71
-			return $this->data[ $prop ];
72
-		}
73
-
74
-		return null;
75
-	}
76
-
77
-	/**
78
-	 * Define class properties.
79
-	 */
80
-	public function set_properties() {
81
-		// Sessions.
82
-		$this->set( 'session', new WPInv_Session_Handler() );
83
-		$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
84
-		$GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
85
-
86
-		// Init other objects.
87
-		$this->set( 'notes', new WPInv_Notes() );
88
-		$this->set( 'api', new WPInv_API() );
89
-		$this->set( 'post_types', new GetPaid_Post_Types() );
90
-		$this->set( 'template', new GetPaid_Template() );
91
-		$this->set( 'admin', new GetPaid_Admin() );
92
-		$this->set( 'subscriptions', new WPInv_Subscriptions() );
93
-		$this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
94
-		$this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
95
-		$this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
96
-		$this->set( 'payment_forms', new GetPaid_Payment_Forms() );
97
-		$this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
98
-	}
99
-
100
-	 /**
101
-	 * Define plugin constants.
102
-	 */
103
-	public function define_constants() {
104
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
105
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
106
-		$this->version = WPINV_VERSION;
107
-	}
108
-
109
-	/**
110
-	 * Hook into actions and filters.
111
-	 *
112
-	 * @since 1.0.19
113
-	 */
114
-	protected function init_hooks() {
115
-		/* Internationalize the text strings used. */
116
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
117
-
118
-		// Init the plugin after WordPress inits.
119
-		add_action( 'init', array( $this, 'init' ), 1 );
120
-		add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
121
-		add_action( 'init', array( $this, 'wpinv_actions' ) );
122
-		add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
123
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
124
-		add_action( 'wp_footer', array( $this, 'wp_footer' ) );
125
-		add_action( 'wp_head', array( $this, 'wp_head' ) );
126
-		add_action( 'widgets_init', array( $this, 'register_widgets' ) );
127
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
128
-		add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) );
129
-		add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
130
-
131
-		add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
132
-		add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 );
133
-		add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
134
-
135
-		// Fires after registering actions.
136
-		do_action( 'wpinv_actions', $this );
137
-		do_action( 'getpaid_actions', $this );
138
-	}
139
-
140
-	public function plugins_loaded() {
141
-		/* Internationalize the text strings used. */
142
-		$this->load_textdomain();
143
-
144
-		do_action( 'wpinv_loaded' );
145
-
146
-		// Fix oxygen page builder conflict
147
-		if ( function_exists( 'ct_css_output' ) ) {
148
-			wpinv_oxygen_fix_conflict();
149
-		}
150
-	}
151
-
152
-	/**
153
-	 * Load Localisation files.
154
-	 *
155
-	 * Note: the first-loaded translation file overrides any following ones if the same translation is present.
156
-	 *
157
-	 * Locales found in:
158
-	 *      - WP_LANG_DIR/plugins/invoicing-LOCALE.mo
159
-	 *      - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo
160
-	 *
161
-	 * @since 1.0.0
162
-	 */
163
-	public function load_textdomain() {
164
-		// Determines the current locale.
165
-		if ( function_exists( 'determine_locale' ) ) {
166
-			$locale = determine_locale();
167
-		} else if ( function_exists( 'get_user_locale' ) ) {
168
-			$locale = get_user_locale();
169
-		} else {
170
-			$locale = get_locale();
171
-		}
172
-
173
-		/**
174
-		 * Filter the locale to use for translations.
175
-		 */
176
-		$locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
177
-
178
-		unload_textdomain( 'invoicing' );
179
-		load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
180
-		load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' );
181
-	}
182
-
183
-	/**
184
-	 * Include required core files used in admin and on the frontend.
185
-	 */
186
-	public function includes() {
187
-		// Start with the settings.
188
-		require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php';
189
-
190
-		// Packages/libraries.
191
-		require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php';
192
-		require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php';
193
-
194
-		// Load functions.
195
-		require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php';
196
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php';
197
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php';
198
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php';
199
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php';
200
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php';
201
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php';
202
-		require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php';
203
-		require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php';
204
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php';
205
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php';
206
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php';
207
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php';
208
-		require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php';
209
-		require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php';
210
-
211
-		// Register autoloader.
212
-		try {
213
-			spl_autoload_register( array( $this, 'autoload' ), true );
214
-		} catch ( Exception $e ) {
215
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
216
-		}
217
-
218
-		require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php';
219
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php';
220
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php';
221
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php';
222
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php';
223
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php';
224
-		require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php';
225
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php';
226
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php';
227
-		require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php';
228
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php';
229
-		require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php';
230
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php';
231
-		require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php';
232
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php';
233
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php';
234
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php';
235
-		require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php';
236
-		require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php';
237
-		require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php';
238
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php';
239
-		require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php';
240
-
241
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
242
-			GetPaid_Post_Types_Admin::init();
243
-
244
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php';
245
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php';
246
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php';
247
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php';
248
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php';
249
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php';
250
-			// load the user class only on the users.php page
251
-			global $pagenow;
252
-			if ( $pagenow == 'users.php' ) {
253
-				new WPInv_Admin_Users();
254
-			}
255
-		}
256
-
257
-		// Register cli commands
258
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
259
-			require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php';
260
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
261
-		}
262
-	}
263
-
264
-	/**
265
-	 * Class autoloader
266
-	 *
267
-	 * @param       string $class_name The name of the class to load.
268
-	 * @access      public
269
-	 * @since       1.0.19
270
-	 * @return      void
271
-	 */
272
-	public function autoload( $class_name ) {
273
-		// Normalize the class name...
274
-		$class_name  = strtolower( $class_name );
275
-
276
-		// ... and make sure it is our class.
277
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
278
-			return;
279
-		}
280
-
281
-		// Next, prepare the file name from the class.
282
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
283
-
284
-		// Base path of the classes.
285
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
286
-
287
-		// And an array of possible locations in order of importance.
288
-		$locations = array(
289
-			"$plugin_path/includes",
290
-			"$plugin_path/includes/data-stores",
291
-			"$plugin_path/includes/gateways",
292
-			"$plugin_path/includes/payments",
293
-			"$plugin_path/includes/geolocation",
294
-			"$plugin_path/includes/reports",
295
-			"$plugin_path/includes/api",
296
-			"$plugin_path/includes/admin",
297
-			"$plugin_path/includes/admin/meta-boxes",
298
-		);
299
-
300
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
301
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
302
-				include trailingslashit( $location ) . $file_name;
303
-				break;
304
-			}
305
-		}
306
-	}
307
-
308
-	/**
309
-	 * Inits hooks etc.
310
-	 */
311
-	public function init() {
312
-		// Fires before getpaid inits.
313
-		do_action( 'before_getpaid_init', $this );
314
-
315
-		// Maybe upgrade.
316
-		$this->maybe_upgrade_database();
317
-
318
-		// Load default gateways.
319
-		$gateways = apply_filters(
320
-			'getpaid_default_gateways',
321
-			array(
322
-				'manual'        => 'GetPaid_Manual_Gateway',
323
-				'paypal'        => 'GetPaid_Paypal_Gateway',
324
-				'worldpay'      => 'GetPaid_Worldpay_Gateway',
325
-				'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
326
-				'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
327
-			)
328
-		);
329
-
330
-		foreach ( $gateways as $id => $class ) {
331
-			$this->gateways[ $id ] = new $class();
332
-		}
333
-
334
-		if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
335
-			GetPaid_Installer::rename_gateways_label();
336
-			update_option( 'wpinv_renamed_gateways', 'yes' );
337
-		}
338
-
339
-		// Fires after getpaid inits.
340
-		do_action( 'getpaid_init', $this );
341
-	}
342
-
343
-	/**
344
-	 * Checks if this is an IPN request and processes it.
345
-	 */
346
-	public function maybe_process_ipn() {
347
-		// Ensure that this is an IPN request.
348
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
349
-			return;
350
-		}
351
-
352
-		$gateway = sanitize_text_field( $_GET['wpi-gateway'] );
353
-
354
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
355
-		do_action( "wpinv_verify_{$gateway}_ipn" );
356
-		exit;
357
-	}
358
-
359
-	public function enqueue_scripts() {
360
-		// Fires before adding scripts.
361
-		do_action( 'getpaid_enqueue_scripts' );
362
-
363
-		$localize                         = array();
364
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
365
-		$localize['thousands']            = wpinv_thousands_separator();
366
-		$localize['decimals']             = wpinv_decimal_separator();
367
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
368
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
369
-		$localize['UseTaxes']             = wpinv_use_taxes();
370
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
371
-		$localize['loading']              = __( 'Loading...', 'invoicing' );
372
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
373
-		$localize['recaptchaSettings']    = getpaid_get_recaptcha_settings();
374
-
375
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
376
-
377
-		// reCaptcha.
378
-		if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) {
379
-			wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
380
-		}
381
-
382
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
383
-		wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true );
384
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
385
-	}
386
-
387
-	public function wpinv_actions() {
388
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
389
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
390
-		}
391
-
392
-		if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) {
393
-			include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php';
394
-		}
395
-	}
396
-
397
-	/**
398
-	 * Fires an action after verifying that a user can fire them.
399
-	 *
400
-	 * Note: If the action is on an invoice, subscription etc, esure that the
401
-	 * current user owns the invoice/subscription.
402
-	 */
403
-	public function maybe_do_authenticated_action() {
404
-		if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
405
-			$key  = sanitize_key( $_REQUEST['getpaid-action'] );
406
-			$data = wp_unslash( $_REQUEST );
407
-
408
-			if ( is_user_logged_in() ) {
409
-				do_action( "getpaid_authenticated_action_$key", $data );
410
-			}
411
-
412
-			do_action( "getpaid_unauthenticated_action_$key", $data );
413
-		}
414
-	}
415
-
416
-	public function pre_get_posts( $wp_query ) {
417
-		if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
418
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
419
-		}
420
-
421
-		return $wp_query;
422
-	}
423
-
424
-	/**
425
-	 * Register widgets
426
-	 *
427
-	 */
428
-	public function register_widgets() {
429
-		global $pagenow;
430
-
431
-		// Currently, UX Builder does not work particulaly well with SuperDuper.
432
-		// So we disable our widgets when editing a page with UX Builder.
433
-		if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
434
-			return;
435
-		}
436
-
437
-		$block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array();
438
-
439
-		if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) {
440
-			// don't initiate in these conditions.
441
-		} else {
442
-			// Only load allowed widgets.
443
-			$exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array();
444
-			$widgets = apply_filters(
445
-				'getpaid_widget_classes',
446
-				array(
447
-					'WPInv_Checkout_Widget',
448
-					'WPInv_History_Widget',
449
-					'WPInv_Receipt_Widget',
450
-					'WPInv_Subscriptions_Widget',
451
-					'WPInv_Buy_Item_Widget',
452
-					'WPInv_Messages_Widget',
453
-					'WPInv_GetPaid_Widget',
454
-					'WPInv_Invoice_Widget',
455
-				)
456
-			);
457
-
458
-			// For each widget...
459
-			foreach ( $widgets as $widget ) {
460
-				// Abort early if it is excluded for this page.
461
-				if ( in_array( $widget, $exclude ) ) {
462
-					continue;
463
-				}
464
-
465
-				// SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it.
466
-				if ( is_subclass_of( $widget, 'WP_Widget' ) ) {
467
-					register_widget( $widget );
468
-				} else {
469
-					new $widget();
470
-				}
471
-			}
472
-		}
473
-	}
474
-
475
-	/**
476
-	 * Upgrades the database.
477
-	 *
478
-	 * @since 2.0.2
479
-	 */
480
-	public function maybe_upgrade_database() {
481
-		// Ensure the database tables are up to date.
482
-		GetPaid_Installer::maybe_create_db_tables();
483
-
484
-		$wpi_version = get_option( 'wpinv_version', 0 );
485
-
486
-		if ( $wpi_version == WPINV_VERSION ) {
487
-			return;
488
-		}
489
-
490
-		$installer = new GetPaid_Installer();
491
-
492
-		if ( empty( $wpi_version ) ) {
493
-			return $installer->upgrade_db( 0 );
494
-		}
495
-
496
-		$upgrades  = array(
497
-			'0.0.5' => '004',
498
-			'1.0.3' => '102',
499
-			'2.0.0' => '118',
500
-			'2.8.0' => '279',
501
-		);
502
-
503
-		foreach ( $upgrades as $key => $method ) {
504
-			if ( version_compare( $wpi_version, $key, '<' ) ) {
505
-				return $installer->upgrade_db( $method );
506
-			}
507
-		}
508
-	}
509
-
510
-	/**
511
-	 * Flushes the permalinks if needed.
512
-	 *
513
-	 * @since 2.0.8
514
-	 */
515
-	public function maybe_flush_permalinks() {
516
-		$flush = get_option( 'wpinv_flush_permalinks', 0 );
517
-
518
-		if ( ! empty( $flush ) ) {
519
-			flush_rewrite_rules();
520
-			delete_option( 'wpinv_flush_permalinks' );
521
-		}
522
-	}
523
-
524
-	/**
525
-	 * Remove our pages from yoast sitemaps.
526
-	 *
527
-	 * @since 1.0.19
528
-	 * @param int[] $excluded_posts_ids
529
-	 */
530
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) {
531
-		// Ensure that we have an array.
532
-		if ( ! is_array( $excluded_posts_ids ) ) {
533
-			$excluded_posts_ids = array();
534
-		}
535
-
536
-		// Prepare our pages.
537
-		$our_pages = array();
538
-
539
-		// Checkout page.
540
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
541
-
542
-		// Success page.
543
-		$our_pages[] = wpinv_get_option( 'success_page', false );
544
-
545
-		// Failure page.
546
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
547
-
548
-		// History page.
549
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
550
-
551
-		// Subscriptions page.
552
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
553
-
554
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
555
-
556
-		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
557
-
558
-		return array_unique( $excluded_posts_ids );
559
-	}
560
-
561
-	/**
562
-	 * Remove our pages from yoast sitemaps.
563
-	 *
564
-	 * @since 1.0.19
565
-	 * @param string[] $post_types
566
-	 */
567
-	public function exclude_invoicing_post_types( $post_types ) {
568
-		// Ensure that we have an array.
569
-		if ( ! is_array( $post_types ) ) {
570
-			$post_types = array();
571
-		}
572
-
573
-		// Remove our post types.
574
-		return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) );
575
-	}
576
-
577
-	/**
578
-	 * Displays additional footer code.
579
-	 *
580
-	 * @since 2.0.0
581
-	 */
582
-	public function wp_footer() {
583
-		wpinv_get_template( 'frontend-footer.php' );
584
-	}
585
-
586
-	/**
587
-	 * Displays additional header code.
588
-	 *
589
-	 * @since 2.0.0
590
-	 */
591
-	public function wp_head() {
592
-		wpinv_get_template( 'frontend-head.php' );
593
-	}
594
-
595
-	/**
596
-	 * Custom query vars.
597
-	 *
598
-	 */
599
-	public function custom_query_vars( $vars ) {
600
-		$vars[] = 'getpaid-ipn';
601
-		return $vars;
602
-	}
603
-
604
-	/**
605
-	 * Add rewrite tags and rules.
606
-	 *
607
-	 */
608
-	public function add_rewrite_rule() {
609
-		$tag = 'getpaid-ipn';
610
-		add_rewrite_tag( "%$tag%", '([^&]+)' );
611
-		add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' );
612
-	}
613
-
614
-	/**
615
-	 * Processes non-query string ipns.
616
-	 *
617
-	 */
618
-	public function maybe_process_new_ipn( $query ) {
619
-		if ( is_admin() || ! $query->is_main_query() ) {
620
-			return;
621
-		}
622
-
623
-		$gateway = get_query_var( 'getpaid-ipn' );
624
-
625
-		if ( ! empty( $gateway ) ) {
626
-			$gateway = sanitize_text_field( $gateway );
627
-			nocache_headers();
628
-			do_action( 'wpinv_verify_payment_ipn', $gateway );
629
-			do_action( "wpinv_verify_{$gateway}_ipn" );
630
-			exit;
631
-		}
632
-	}
17
+    /**
18
+     * GetPaid version.
19
+     *
20
+     * @var string
21
+     */
22
+    public $version;
23
+
24
+    /**
25
+     * Data container.
26
+     *
27
+     * @var array
28
+     */
29
+    protected $data = array();
30
+
31
+    /**
32
+     * Form elements instance.
33
+     *
34
+     * @var WPInv_Payment_Form_Elements
35
+     */
36
+    public $form_elements;
37
+
38
+    /**
39
+     * @var array An array of payment gateways.
40
+     */
41
+    public $gateways;
42
+
43
+    /**
44
+     * Class constructor.
45
+     */
46
+    public function __construct() {
47
+        $this->define_constants();
48
+        $this->includes();
49
+        $this->init_hooks();
50
+        $this->set_properties();
51
+    }
52
+
53
+    /**
54
+     * Sets a custom data property.
55
+     *
56
+     * @param string $prop The prop to set.
57
+     * @param mixed $value The value to retrieve.
58
+     */
59
+    public function set( $prop, $value ) {
60
+        $this->data[ $prop ] = $value;
61
+    }
62
+
63
+    /**
64
+     * Gets a custom data property.
65
+     *
66
+     * @param string $prop The prop to set.
67
+     * @return mixed The value.
68
+     */
69
+    public function get( $prop ) {
70
+        if ( isset( $this->data[ $prop ] ) ) {
71
+            return $this->data[ $prop ];
72
+        }
73
+
74
+        return null;
75
+    }
76
+
77
+    /**
78
+     * Define class properties.
79
+     */
80
+    public function set_properties() {
81
+        // Sessions.
82
+        $this->set( 'session', new WPInv_Session_Handler() );
83
+        $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
84
+        $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
85
+
86
+        // Init other objects.
87
+        $this->set( 'notes', new WPInv_Notes() );
88
+        $this->set( 'api', new WPInv_API() );
89
+        $this->set( 'post_types', new GetPaid_Post_Types() );
90
+        $this->set( 'template', new GetPaid_Template() );
91
+        $this->set( 'admin', new GetPaid_Admin() );
92
+        $this->set( 'subscriptions', new WPInv_Subscriptions() );
93
+        $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
94
+        $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
95
+        $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
96
+        $this->set( 'payment_forms', new GetPaid_Payment_Forms() );
97
+        $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
98
+    }
99
+
100
+        /**
101
+         * Define plugin constants.
102
+         */
103
+    public function define_constants() {
104
+        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
105
+        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
106
+        $this->version = WPINV_VERSION;
107
+    }
108
+
109
+    /**
110
+     * Hook into actions and filters.
111
+     *
112
+     * @since 1.0.19
113
+     */
114
+    protected function init_hooks() {
115
+        /* Internationalize the text strings used. */
116
+        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
117
+
118
+        // Init the plugin after WordPress inits.
119
+        add_action( 'init', array( $this, 'init' ), 1 );
120
+        add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
121
+        add_action( 'init', array( $this, 'wpinv_actions' ) );
122
+        add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
123
+        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
124
+        add_action( 'wp_footer', array( $this, 'wp_footer' ) );
125
+        add_action( 'wp_head', array( $this, 'wp_head' ) );
126
+        add_action( 'widgets_init', array( $this, 'register_widgets' ) );
127
+        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
128
+        add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) );
129
+        add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
130
+
131
+        add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
132
+        add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 );
133
+        add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
134
+
135
+        // Fires after registering actions.
136
+        do_action( 'wpinv_actions', $this );
137
+        do_action( 'getpaid_actions', $this );
138
+    }
139
+
140
+    public function plugins_loaded() {
141
+        /* Internationalize the text strings used. */
142
+        $this->load_textdomain();
143
+
144
+        do_action( 'wpinv_loaded' );
145
+
146
+        // Fix oxygen page builder conflict
147
+        if ( function_exists( 'ct_css_output' ) ) {
148
+            wpinv_oxygen_fix_conflict();
149
+        }
150
+    }
151
+
152
+    /**
153
+     * Load Localisation files.
154
+     *
155
+     * Note: the first-loaded translation file overrides any following ones if the same translation is present.
156
+     *
157
+     * Locales found in:
158
+     *      - WP_LANG_DIR/plugins/invoicing-LOCALE.mo
159
+     *      - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo
160
+     *
161
+     * @since 1.0.0
162
+     */
163
+    public function load_textdomain() {
164
+        // Determines the current locale.
165
+        if ( function_exists( 'determine_locale' ) ) {
166
+            $locale = determine_locale();
167
+        } else if ( function_exists( 'get_user_locale' ) ) {
168
+            $locale = get_user_locale();
169
+        } else {
170
+            $locale = get_locale();
171
+        }
172
+
173
+        /**
174
+         * Filter the locale to use for translations.
175
+         */
176
+        $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
177
+
178
+        unload_textdomain( 'invoicing' );
179
+        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
180
+        load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' );
181
+    }
182
+
183
+    /**
184
+     * Include required core files used in admin and on the frontend.
185
+     */
186
+    public function includes() {
187
+        // Start with the settings.
188
+        require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php';
189
+
190
+        // Packages/libraries.
191
+        require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php';
192
+        require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php';
193
+
194
+        // Load functions.
195
+        require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php';
196
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php';
197
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php';
198
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php';
199
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php';
200
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php';
201
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php';
202
+        require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php';
203
+        require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php';
204
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php';
205
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php';
206
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php';
207
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php';
208
+        require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php';
209
+        require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php';
210
+
211
+        // Register autoloader.
212
+        try {
213
+            spl_autoload_register( array( $this, 'autoload' ), true );
214
+        } catch ( Exception $e ) {
215
+            wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
216
+        }
217
+
218
+        require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php';
219
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php';
220
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php';
221
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php';
222
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php';
223
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php';
224
+        require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php';
225
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php';
226
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php';
227
+        require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php';
228
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php';
229
+        require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php';
230
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php';
231
+        require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php';
232
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php';
233
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php';
234
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php';
235
+        require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php';
236
+        require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php';
237
+        require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php';
238
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php';
239
+        require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php';
240
+
241
+        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
242
+            GetPaid_Post_Types_Admin::init();
243
+
244
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php';
245
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php';
246
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php';
247
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php';
248
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php';
249
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php';
250
+            // load the user class only on the users.php page
251
+            global $pagenow;
252
+            if ( $pagenow == 'users.php' ) {
253
+                new WPInv_Admin_Users();
254
+            }
255
+        }
256
+
257
+        // Register cli commands
258
+        if ( defined( 'WP_CLI' ) && WP_CLI ) {
259
+            require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php';
260
+            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
261
+        }
262
+    }
263
+
264
+    /**
265
+     * Class autoloader
266
+     *
267
+     * @param       string $class_name The name of the class to load.
268
+     * @access      public
269
+     * @since       1.0.19
270
+     * @return      void
271
+     */
272
+    public function autoload( $class_name ) {
273
+        // Normalize the class name...
274
+        $class_name  = strtolower( $class_name );
275
+
276
+        // ... and make sure it is our class.
277
+        if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
278
+            return;
279
+        }
280
+
281
+        // Next, prepare the file name from the class.
282
+        $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
283
+
284
+        // Base path of the classes.
285
+        $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
286
+
287
+        // And an array of possible locations in order of importance.
288
+        $locations = array(
289
+            "$plugin_path/includes",
290
+            "$plugin_path/includes/data-stores",
291
+            "$plugin_path/includes/gateways",
292
+            "$plugin_path/includes/payments",
293
+            "$plugin_path/includes/geolocation",
294
+            "$plugin_path/includes/reports",
295
+            "$plugin_path/includes/api",
296
+            "$plugin_path/includes/admin",
297
+            "$plugin_path/includes/admin/meta-boxes",
298
+        );
299
+
300
+        foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
301
+            if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
302
+                include trailingslashit( $location ) . $file_name;
303
+                break;
304
+            }
305
+        }
306
+    }
307
+
308
+    /**
309
+     * Inits hooks etc.
310
+     */
311
+    public function init() {
312
+        // Fires before getpaid inits.
313
+        do_action( 'before_getpaid_init', $this );
314
+
315
+        // Maybe upgrade.
316
+        $this->maybe_upgrade_database();
317
+
318
+        // Load default gateways.
319
+        $gateways = apply_filters(
320
+            'getpaid_default_gateways',
321
+            array(
322
+                'manual'        => 'GetPaid_Manual_Gateway',
323
+                'paypal'        => 'GetPaid_Paypal_Gateway',
324
+                'worldpay'      => 'GetPaid_Worldpay_Gateway',
325
+                'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
326
+                'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
327
+            )
328
+        );
329
+
330
+        foreach ( $gateways as $id => $class ) {
331
+            $this->gateways[ $id ] = new $class();
332
+        }
333
+
334
+        if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
335
+            GetPaid_Installer::rename_gateways_label();
336
+            update_option( 'wpinv_renamed_gateways', 'yes' );
337
+        }
338
+
339
+        // Fires after getpaid inits.
340
+        do_action( 'getpaid_init', $this );
341
+    }
342
+
343
+    /**
344
+     * Checks if this is an IPN request and processes it.
345
+     */
346
+    public function maybe_process_ipn() {
347
+        // Ensure that this is an IPN request.
348
+        if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
349
+            return;
350
+        }
351
+
352
+        $gateway = sanitize_text_field( $_GET['wpi-gateway'] );
353
+
354
+        do_action( 'wpinv_verify_payment_ipn', $gateway );
355
+        do_action( "wpinv_verify_{$gateway}_ipn" );
356
+        exit;
357
+    }
358
+
359
+    public function enqueue_scripts() {
360
+        // Fires before adding scripts.
361
+        do_action( 'getpaid_enqueue_scripts' );
362
+
363
+        $localize                         = array();
364
+        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
365
+        $localize['thousands']            = wpinv_thousands_separator();
366
+        $localize['decimals']             = wpinv_decimal_separator();
367
+        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
368
+        $localize['txtComplete']          = __( 'Continue', 'invoicing' );
369
+        $localize['UseTaxes']             = wpinv_use_taxes();
370
+        $localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
371
+        $localize['loading']              = __( 'Loading...', 'invoicing' );
372
+        $localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
373
+        $localize['recaptchaSettings']    = getpaid_get_recaptcha_settings();
374
+
375
+        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
376
+
377
+        // reCaptcha.
378
+        if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) {
379
+            wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
380
+        }
381
+
382
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
383
+        wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true );
384
+        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
385
+    }
386
+
387
+    public function wpinv_actions() {
388
+        if ( isset( $_REQUEST['wpi_action'] ) ) {
389
+            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
390
+        }
391
+
392
+        if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) {
393
+            include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php';
394
+        }
395
+    }
396
+
397
+    /**
398
+     * Fires an action after verifying that a user can fire them.
399
+     *
400
+     * Note: If the action is on an invoice, subscription etc, esure that the
401
+     * current user owns the invoice/subscription.
402
+     */
403
+    public function maybe_do_authenticated_action() {
404
+        if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
405
+            $key  = sanitize_key( $_REQUEST['getpaid-action'] );
406
+            $data = wp_unslash( $_REQUEST );
407
+
408
+            if ( is_user_logged_in() ) {
409
+                do_action( "getpaid_authenticated_action_$key", $data );
410
+            }
411
+
412
+            do_action( "getpaid_unauthenticated_action_$key", $data );
413
+        }
414
+    }
415
+
416
+    public function pre_get_posts( $wp_query ) {
417
+        if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
418
+            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
419
+        }
420
+
421
+        return $wp_query;
422
+    }
423
+
424
+    /**
425
+     * Register widgets
426
+     *
427
+     */
428
+    public function register_widgets() {
429
+        global $pagenow;
430
+
431
+        // Currently, UX Builder does not work particulaly well with SuperDuper.
432
+        // So we disable our widgets when editing a page with UX Builder.
433
+        if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
434
+            return;
435
+        }
436
+
437
+        $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array();
438
+
439
+        if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) {
440
+            // don't initiate in these conditions.
441
+        } else {
442
+            // Only load allowed widgets.
443
+            $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array();
444
+            $widgets = apply_filters(
445
+                'getpaid_widget_classes',
446
+                array(
447
+                    'WPInv_Checkout_Widget',
448
+                    'WPInv_History_Widget',
449
+                    'WPInv_Receipt_Widget',
450
+                    'WPInv_Subscriptions_Widget',
451
+                    'WPInv_Buy_Item_Widget',
452
+                    'WPInv_Messages_Widget',
453
+                    'WPInv_GetPaid_Widget',
454
+                    'WPInv_Invoice_Widget',
455
+                )
456
+            );
457
+
458
+            // For each widget...
459
+            foreach ( $widgets as $widget ) {
460
+                // Abort early if it is excluded for this page.
461
+                if ( in_array( $widget, $exclude ) ) {
462
+                    continue;
463
+                }
464
+
465
+                // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it.
466
+                if ( is_subclass_of( $widget, 'WP_Widget' ) ) {
467
+                    register_widget( $widget );
468
+                } else {
469
+                    new $widget();
470
+                }
471
+            }
472
+        }
473
+    }
474
+
475
+    /**
476
+     * Upgrades the database.
477
+     *
478
+     * @since 2.0.2
479
+     */
480
+    public function maybe_upgrade_database() {
481
+        // Ensure the database tables are up to date.
482
+        GetPaid_Installer::maybe_create_db_tables();
483
+
484
+        $wpi_version = get_option( 'wpinv_version', 0 );
485
+
486
+        if ( $wpi_version == WPINV_VERSION ) {
487
+            return;
488
+        }
489
+
490
+        $installer = new GetPaid_Installer();
491
+
492
+        if ( empty( $wpi_version ) ) {
493
+            return $installer->upgrade_db( 0 );
494
+        }
495
+
496
+        $upgrades  = array(
497
+            '0.0.5' => '004',
498
+            '1.0.3' => '102',
499
+            '2.0.0' => '118',
500
+            '2.8.0' => '279',
501
+        );
502
+
503
+        foreach ( $upgrades as $key => $method ) {
504
+            if ( version_compare( $wpi_version, $key, '<' ) ) {
505
+                return $installer->upgrade_db( $method );
506
+            }
507
+        }
508
+    }
509
+
510
+    /**
511
+     * Flushes the permalinks if needed.
512
+     *
513
+     * @since 2.0.8
514
+     */
515
+    public function maybe_flush_permalinks() {
516
+        $flush = get_option( 'wpinv_flush_permalinks', 0 );
517
+
518
+        if ( ! empty( $flush ) ) {
519
+            flush_rewrite_rules();
520
+            delete_option( 'wpinv_flush_permalinks' );
521
+        }
522
+    }
523
+
524
+    /**
525
+     * Remove our pages from yoast sitemaps.
526
+     *
527
+     * @since 1.0.19
528
+     * @param int[] $excluded_posts_ids
529
+     */
530
+    public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) {
531
+        // Ensure that we have an array.
532
+        if ( ! is_array( $excluded_posts_ids ) ) {
533
+            $excluded_posts_ids = array();
534
+        }
535
+
536
+        // Prepare our pages.
537
+        $our_pages = array();
538
+
539
+        // Checkout page.
540
+        $our_pages[] = wpinv_get_option( 'checkout_page', false );
541
+
542
+        // Success page.
543
+        $our_pages[] = wpinv_get_option( 'success_page', false );
544
+
545
+        // Failure page.
546
+        $our_pages[] = wpinv_get_option( 'failure_page', false );
547
+
548
+        // History page.
549
+        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
550
+
551
+        // Subscriptions page.
552
+        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
553
+
554
+        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
555
+
556
+        $excluded_posts_ids = $excluded_posts_ids + $our_pages;
557
+
558
+        return array_unique( $excluded_posts_ids );
559
+    }
560
+
561
+    /**
562
+     * Remove our pages from yoast sitemaps.
563
+     *
564
+     * @since 1.0.19
565
+     * @param string[] $post_types
566
+     */
567
+    public function exclude_invoicing_post_types( $post_types ) {
568
+        // Ensure that we have an array.
569
+        if ( ! is_array( $post_types ) ) {
570
+            $post_types = array();
571
+        }
572
+
573
+        // Remove our post types.
574
+        return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) );
575
+    }
576
+
577
+    /**
578
+     * Displays additional footer code.
579
+     *
580
+     * @since 2.0.0
581
+     */
582
+    public function wp_footer() {
583
+        wpinv_get_template( 'frontend-footer.php' );
584
+    }
585
+
586
+    /**
587
+     * Displays additional header code.
588
+     *
589
+     * @since 2.0.0
590
+     */
591
+    public function wp_head() {
592
+        wpinv_get_template( 'frontend-head.php' );
593
+    }
594
+
595
+    /**
596
+     * Custom query vars.
597
+     *
598
+     */
599
+    public function custom_query_vars( $vars ) {
600
+        $vars[] = 'getpaid-ipn';
601
+        return $vars;
602
+    }
603
+
604
+    /**
605
+     * Add rewrite tags and rules.
606
+     *
607
+     */
608
+    public function add_rewrite_rule() {
609
+        $tag = 'getpaid-ipn';
610
+        add_rewrite_tag( "%$tag%", '([^&]+)' );
611
+        add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' );
612
+    }
613
+
614
+    /**
615
+     * Processes non-query string ipns.
616
+     *
617
+     */
618
+    public function maybe_process_new_ipn( $query ) {
619
+        if ( is_admin() || ! $query->is_main_query() ) {
620
+            return;
621
+        }
622
+
623
+        $gateway = get_query_var( 'getpaid-ipn' );
624
+
625
+        if ( ! empty( $gateway ) ) {
626
+            $gateway = sanitize_text_field( $gateway );
627
+            nocache_headers();
628
+            do_action( 'wpinv_verify_payment_ipn', $gateway );
629
+            do_action( "wpinv_verify_{$gateway}_ipn" );
630
+            exit;
631
+        }
632
+    }
633 633
 }
Please login to merge, or discard this patch.