Passed
Push — master ( ee569f...d98642 )
by Brian
05:03
created
includes/payments/class-getpaid-checkout.php 1 patch
Indentation   +304 added lines, -304 removed lines patch added patch discarded remove patch
@@ -12,184 +12,184 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Checkout {
14 14
 
15
-	/**
16
-	 * @var GetPaid_Payment_Form_Submission
17
-	 */
18
-	protected $payment_form_submission;
19
-
20
-	/**
21
-	 * Class constructor.
22
-	 *
23
-	 * @param GetPaid_Payment_Form_Submission $submission
24
-	 */
25
-	public function __construct( $submission ) {
26
-		$this->payment_form_submission = $submission;
27
-	}
28
-
29
-	/**
30
-	 * Processes the checkout.
31
-	 *
32
-	 */
33
-	public function process_checkout() {
34
-
35
-		// Validate the submission.
36
-		$this->validate_submission();
37
-
38
-		// Prepare the invoice.
39
-		$items      = $this->get_submission_items();
40
-		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared   = $this->prepare_submission_data_for_saving();
43
-
44
-		$this->prepare_billing_info( $invoice );
45
-
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
47
-
48
-		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
50
-		$invoice->recalculate_total();
15
+    /**
16
+     * @var GetPaid_Payment_Form_Submission
17
+     */
18
+    protected $payment_form_submission;
19
+
20
+    /**
21
+     * Class constructor.
22
+     *
23
+     * @param GetPaid_Payment_Form_Submission $submission
24
+     */
25
+    public function __construct( $submission ) {
26
+        $this->payment_form_submission = $submission;
27
+    }
28
+
29
+    /**
30
+     * Processes the checkout.
31
+     *
32
+     */
33
+    public function process_checkout() {
34
+
35
+        // Validate the submission.
36
+        $this->validate_submission();
37
+
38
+        // Prepare the invoice.
39
+        $items      = $this->get_submission_items();
40
+        $invoice    = $this->get_submission_invoice();
41
+        $invoice    = $this->process_submission_invoice( $invoice, $items );
42
+        $prepared   = $this->prepare_submission_data_for_saving();
43
+
44
+        $this->prepare_billing_info( $invoice );
45
+
46
+        $shipping   = $this->prepare_shipping_info( $invoice );
47
+
48
+        // Save the invoice.
49
+        $invoice->set_is_viewed( true );
50
+        $invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+        do_action( 'getpaid_checkout_invoice_updated', $invoice );
54 54
 
55
-		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
57
-	}
55
+        // Send to the gateway.
56
+        $this->post_process_submission( $invoice, $prepared, $shipping );
57
+    }
58 58
 
59
-	/**
60
-	 * Validates the submission.
61
-	 *
62
-	 */
63
-	protected function validate_submission() {
59
+    /**
60
+     * Validates the submission.
61
+     *
62
+     */
63
+    protected function validate_submission() {
64 64
 
65
-		$submission = $this->payment_form_submission;
66
-		$data       = $submission->get_data();
65
+        $submission = $this->payment_form_submission;
66
+        $data       = $submission->get_data();
67 67
 
68
-		// Do we have an error?
68
+        // Do we have an error?
69 69
         if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
70
+            wp_send_json_error( $submission->last_error );
71 71
         }
72 72
 
73
-		// We need a billing email.
73
+        // We need a billing email.
74 74
         if ( ! $submission->has_billing_email() ) {
75 75
             wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
76
-		}
76
+        }
77 77
 
78
-		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
-		}
78
+        // Non-recurring gateways should not be allowed to process recurring invoices.
79
+        if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
+            wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
+        }
82 82
 
83
-		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
86
-		}
83
+        // Ensure the gateway is active.
84
+        if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
+            wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
86
+        }
87 87
 
88
-		// Clear any existing errors.
89
-		wpinv_clear_errors();
88
+        // Clear any existing errors.
89
+        wpinv_clear_errors();
90 90
 
91
-		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
91
+        // Allow themes and plugins to hook to errors
92
+        do_action( 'getpaid_checkout_error_checks', $submission );
93 93
 
94
-		// Do we have any errors?
94
+        // Do we have any errors?
95 95
         if ( wpinv_get_errors() ) {
96 96
             wp_send_json_error( getpaid_get_errors_html() );
97
-		}
97
+        }
98 98
 
99
-	}
99
+    }
100 100
 
101
-	/**
102
-	 * Retrieves submission items.
103
-	 *
104
-	 * @return GetPaid_Form_Item[]
105
-	 */
106
-	protected function get_submission_items() {
101
+    /**
102
+     * Retrieves submission items.
103
+     *
104
+     * @return GetPaid_Form_Item[]
105
+     */
106
+    protected function get_submission_items() {
107 107
 
108
-		$items = $this->payment_form_submission->get_items();
108
+        $items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111 111
         if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112 112
             wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
113
-		}
114
-
115
-		return $items;
116
-	}
117
-
118
-	/**
119
-	 * Retrieves submission invoice.
120
-	 *
121
-	 * @return WPInv_Invoice
122
-	 */
123
-	protected function get_submission_invoice() {
124
-		$submission = $this->payment_form_submission;
125
-
126
-		if ( ! $submission->has_invoice() ) {
127
-			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
129
-			return $invoice;
130 113
         }
131 114
 
132
-		$invoice = $submission->get_invoice();
115
+        return $items;
116
+    }
133 117
 
134
-		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
-		}
118
+    /**
119
+     * Retrieves submission invoice.
120
+     *
121
+     * @return WPInv_Invoice
122
+     */
123
+    protected function get_submission_invoice() {
124
+        $submission = $this->payment_form_submission;
138 125
 
139
-		return $invoice;
140
-	}
126
+        if ( ! $submission->has_invoice() ) {
127
+            $invoice = new WPInv_Invoice();
128
+            $invoice->set_created_via( 'payment_form' );
129
+            return $invoice;
130
+        }
141 131
 
142
-	/**
143
-	 * Processes the submission invoice.
144
-	 *
145
-	 * @param WPInv_Invoice $invoice
146
-	 * @param GetPaid_Form_Item[] $items
147
-	 * @return WPInv_Invoice
148
-	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
132
+        $invoice = $submission->get_invoice();
150 133
 
151
-		$submission = $this->payment_form_submission;
134
+        // Make sure that it is neither paid or refunded.
135
+        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
+            wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
+        }
152 138
 
153
-		// Set-up the invoice details.
154
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
-		$invoice->set_user_id( $this->get_submission_customer() );
156
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
139
+        return $invoice;
140
+    }
141
+
142
+    /**
143
+     * Processes the submission invoice.
144
+     *
145
+     * @param WPInv_Invoice $invoice
146
+     * @param GetPaid_Form_Item[] $items
147
+     * @return WPInv_Invoice
148
+     */
149
+    protected function process_submission_invoice( $invoice, $items ) {
150
+
151
+        $submission = $this->payment_form_submission;
152
+
153
+        // Set-up the invoice details.
154
+        $invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
+        $invoice->set_user_id( $this->get_submission_customer() );
156
+        $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
157 157
         $invoice->set_items( $items );
158 158
         $invoice->set_fees( $submission->get_fees() );
159 159
         $invoice->set_taxes( $submission->get_taxes() );
160
-		$invoice->set_discounts( $submission->get_discounts() );
161
-		$invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
162
-		$invoice->set_currency( $submission->get_currency() );
160
+        $invoice->set_discounts( $submission->get_discounts() );
161
+        $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
162
+        $invoice->set_currency( $submission->get_currency() );
163 163
 
164
-		if ( $submission->has_shipping() ) {
165
-			$invoice->set_shipping( $submission->get_shipping() );
166
-		}
164
+        if ( $submission->has_shipping() ) {
165
+            $invoice->set_shipping( $submission->get_shipping() );
166
+        }
167 167
 
168
-		$address_confirmed = $submission->get_field( 'confirm-address' );
169
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
168
+        $address_confirmed = $submission->get_field( 'confirm-address' );
169
+        $invoice->set_address_confirmed( ! empty( $address_confirmed ) );
170 170
 
171
-		if ( $submission->has_discount_code() ) {
171
+        if ( $submission->has_discount_code() ) {
172 172
             $invoice->set_discount_code( $submission->get_discount_code() );
173
-		}
174
-
175
-		getpaid_maybe_add_default_address( $invoice );
176
-		return $invoice;
177
-	}
178
-
179
-	/**
180
-	 * Retrieves the submission's customer.
181
-	 *
182
-	 * @return int The customer id.
183
-	 */
184
-	protected function get_submission_customer() {
185
-		$submission = $this->payment_form_submission;
186
-
187
-		// If this is an existing invoice...
188
-		if ( $submission->has_invoice() ) {
189
-			return $submission->get_invoice()->get_user_id();
190
-		}
191
-
192
-		// (Maybe) create the user.
173
+        }
174
+
175
+        getpaid_maybe_add_default_address( $invoice );
176
+        return $invoice;
177
+    }
178
+
179
+    /**
180
+     * Retrieves the submission's customer.
181
+     *
182
+     * @return int The customer id.
183
+     */
184
+    protected function get_submission_customer() {
185
+        $submission = $this->payment_form_submission;
186
+
187
+        // If this is an existing invoice...
188
+        if ( $submission->has_invoice() ) {
189
+            return $submission->get_invoice()->get_user_id();
190
+        }
191
+
192
+        // (Maybe) create the user.
193 193
         $user = get_current_user_id();
194 194
 
195 195
         if ( empty( $user ) ) {
@@ -197,16 +197,16 @@  discard block
 block discarded – undo
197 197
         }
198 198
 
199 199
         if ( empty( $user ) ) {
200
-			$name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) );
201
-			$name = implode( '', array_filter( $name ) );
200
+            $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) );
201
+            $name = implode( '', array_filter( $name ) );
202 202
             $user = wpinv_create_user( $submission->get_billing_email(), $name );
203 203
 
204
-			// (Maybe) send new user notification.
205
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
206
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
207
-				wp_send_new_user_notifications( $user, 'user' );
208
-			}
209
-		}
204
+            // (Maybe) send new user notification.
205
+            $should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
206
+            if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
207
+                wp_send_new_user_notifications( $user, 'user' );
208
+            }
209
+        }
210 210
 
211 211
         if ( is_wp_error( $user ) ) {
212 212
             wp_send_json_error( $user->get_error_message() );
@@ -214,49 +214,49 @@  discard block
 block discarded – undo
214 214
 
215 215
         if ( is_numeric( $user ) ) {
216 216
             return $user;
217
-		}
217
+        }
218 218
 
219
-		return $user->ID;
219
+        return $user->ID;
220 220
 
221
-	}
221
+    }
222 222
 
223
-	/**
223
+    /**
224 224
      * Prepares submission data for saving to the database.
225 225
      *
226
-	 * @return array
226
+     * @return array
227 227
      */
228 228
     public function prepare_submission_data_for_saving() {
229 229
 
230
-		$submission = $this->payment_form_submission;
230
+        $submission = $this->payment_form_submission;
231 231
 
232
-		// Prepared submission details.
232
+        // Prepared submission details.
233 233
         $prepared = array(
234
-			'all'  => array(),
235
-			'meta' => array(),
236
-		);
234
+            'all'  => array(),
235
+            'meta' => array(),
236
+        );
237 237
 
238 238
         // Raw submission details.
239
-		$data     = $submission->get_data();
239
+        $data     = $submission->get_data();
240 240
 
241
-		// Loop through the submitted details.
241
+        // Loop through the submitted details.
242 242
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
243 243
 
244
-			// Skip premade fields.
244
+            // Skip premade fields.
245 245
             if ( ! empty( $field['premade'] ) ) {
246 246
                 continue;
247 247
             }
248 248
 
249
-			// Ensure address is provided.
250
-			if ( $field['type'] == 'address' ) {
249
+            // Ensure address is provided.
250
+            if ( $field['type'] == 'address' ) {
251 251
                 $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
252 252
 
253
-				foreach ( $field['fields'] as $address_field ) {
253
+                foreach ( $field['fields'] as $address_field ) {
254 254
 
255
-					if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) {
256
-						wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
257
-					}
258
-			}
259
-		}
255
+                    if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) {
256
+                        wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
257
+                    }
258
+            }
259
+        }
260 260
 
261 261
             // If it is required and not set, abort.
262 262
             if ( ! $submission->is_required_field_set( $field ) ) {
@@ -266,31 +266,31 @@  discard block
 block discarded – undo
266 266
             // Handle misc fields.
267 267
             if ( isset( $data[ $field['id'] ] ) ) {
268 268
 
269
-				// Uploads.
270
-				if ( $field['type'] === 'file_upload' ) {
271
-					$max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
269
+                // Uploads.
270
+                if ( $field['type'] === 'file_upload' ) {
271
+                    $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
272 272
 
273
-					if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
274
-						wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
275
-					}
273
+                    if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
274
+                        wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
275
+                    }
276 276
 
277
-					$value = array();
277
+                    $value = array();
278 278
 
279
-					foreach ( $data[ $field['id'] ] as $url => $name ) {
280
-						$value[] = sprintf(
281
-							'<a href="%s" target="_blank">%s</a>',
282
-							esc_url_raw( $url ),
283
-							esc_html( $name )
284
-						);
285
-					}
279
+                    foreach ( $data[ $field['id'] ] as $url => $name ) {
280
+                        $value[] = sprintf(
281
+                            '<a href="%s" target="_blank">%s</a>',
282
+                            esc_url_raw( $url ),
283
+                            esc_html( $name )
284
+                        );
285
+                    }
286 286
 
287
-					$value = implode( ' | ', $value );
287
+                    $value = implode( ' | ', $value );
288 288
 
289
-				} elseif ( $field['type'] === 'checkbox' ) {
290
-					$value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
291
-				} else {
292
-					$value = wp_kses_post( $data[ $field['id'] ] );
293
-				}
289
+                } elseif ( $field['type'] === 'checkbox' ) {
290
+                    $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
291
+                } else {
292
+                    $value = wp_kses_post( $data[ $field['id'] ] );
293
+                }
294 294
 
295 295
                 $label = $field['id'];
296 296
 
@@ -298,188 +298,188 @@  discard block
 block discarded – undo
298 298
                     $label = $field['label'];
299 299
                 }
300 300
 
301
-				if ( ! empty( $field['add_meta'] ) ) {
302
-					$prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
303
-				}
304
-				$prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
301
+                if ( ! empty( $field['add_meta'] ) ) {
302
+                    $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
303
+                }
304
+                $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
305 305
 
306 306
             }
307
-		}
307
+        }
308 308
 
309
-		return $prepared;
309
+        return $prepared;
310 310
 
311
-	}
311
+    }
312 312
 
313
-	/**
313
+    /**
314 314
      * Retrieves address details.
315 315
      *
316
-	 * @return array
317
-	 * @param WPInv_Invoice $invoice
318
-	 * @param string $type
316
+     * @return array
317
+     * @param WPInv_Invoice $invoice
318
+     * @param string $type
319 319
      */
320 320
     public function prepare_address_details( $invoice, $type = 'billing' ) {
321 321
 
322
-		$data     = $this->payment_form_submission->get_data();
323
-		$type     = sanitize_key( $type );
324
-		$address  = array();
325
-		$prepared = array();
322
+        $data     = $this->payment_form_submission->get_data();
323
+        $type     = sanitize_key( $type );
324
+        $address  = array();
325
+        $prepared = array();
326 326
 
327
-		if ( ! empty( $data[ $type ] ) ) {
328
-			$address = $data[ $type ];
329
-		}
327
+        if ( ! empty( $data[ $type ] ) ) {
328
+            $address = $data[ $type ];
329
+        }
330 330
 
331
-		// Clean address details.
332
-		foreach ( $address as $key => $value ) {
333
-			$key             = sanitize_key( $key );
334
-			$key             = str_replace( 'wpinv_', '', $key );
335
-			$value           = wpinv_clean( $value );
336
-			$prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
337
-		}
331
+        // Clean address details.
332
+        foreach ( $address as $key => $value ) {
333
+            $key             = sanitize_key( $key );
334
+            $key             = str_replace( 'wpinv_', '', $key );
335
+            $value           = wpinv_clean( $value );
336
+            $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
337
+        }
338 338
 
339
-		// Filter address details.
340
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
339
+        // Filter address details.
340
+        $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
341 341
 
342
-		// Remove non-whitelisted values.
343
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
342
+        // Remove non-whitelisted values.
343
+        return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
344 344
 
345
-	}
345
+    }
346 346
 
347
-	/**
347
+    /**
348 348
      * Prepares the billing details.
349 349
      *
350
-	 * @return array
351
-	 * @param WPInv_Invoice $invoice
350
+     * @return array
351
+     * @param WPInv_Invoice $invoice
352 352
      */
353 353
     protected function prepare_billing_info( &$invoice ) {
354 354
 
355
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
355
+        $billing_address = $this->prepare_address_details( $invoice, 'billing' );
356 356
 
357
-		// Update the invoice with the billing details.
358
-		$invoice->set_props( $billing_address );
357
+        // Update the invoice with the billing details.
358
+        $invoice->set_props( $billing_address );
359 359
 
360
-	}
360
+    }
361 361
 
362
-	/**
362
+    /**
363 363
      * Prepares the shipping details.
364 364
      *
365
-	 * @return array
366
-	 * @param WPInv_Invoice $invoice
365
+     * @return array
366
+     * @param WPInv_Invoice $invoice
367 367
      */
368 368
     protected function prepare_shipping_info( $invoice ) {
369 369
 
370
-		$data = $this->payment_form_submission->get_data();
370
+        $data = $this->payment_form_submission->get_data();
371 371
 
372
-		if ( empty( $data['same-shipping-address'] ) ) {
373
-			return $this->prepare_address_details( $invoice, 'shipping' );
374
-		}
372
+        if ( empty( $data['same-shipping-address'] ) ) {
373
+            return $this->prepare_address_details( $invoice, 'shipping' );
374
+        }
375 375
 
376
-		return $this->prepare_address_details( $invoice, 'billing' );
376
+        return $this->prepare_address_details( $invoice, 'billing' );
377 377
 
378
-	}
378
+    }
379 379
 
380
-	/**
381
-	 * Confirms the submission is valid and send users to the gateway.
382
-	 *
383
-	 * @param WPInv_Invoice $invoice
384
-	 * @param array $prepared_payment_form_data
385
-	 * @param array $shipping
386
-	 */
387
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
380
+    /**
381
+     * Confirms the submission is valid and send users to the gateway.
382
+     *
383
+     * @param WPInv_Invoice $invoice
384
+     * @param array $prepared_payment_form_data
385
+     * @param array $shipping
386
+     */
387
+    protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
388 388
 
389
-		// Ensure the invoice exists.
389
+        // Ensure the invoice exists.
390 390
         if ( ! $invoice->exists() ) {
391 391
             wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
392 392
         }
393 393
 
394
-		// Save payment form data.
395
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
394
+        // Save payment form data.
395
+        $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
396 396
         delete_post_meta( $invoice->get_id(), 'payment_form_data' );
397
-		delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
398
-		if ( ! empty( $prepared_payment_form_data ) ) {
397
+        delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
398
+        if ( ! empty( $prepared_payment_form_data ) ) {
399 399
 
400
-			if ( ! empty( $prepared_payment_form_data['all'] ) ) {
401
-				update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
402
-			}
400
+            if ( ! empty( $prepared_payment_form_data['all'] ) ) {
401
+                update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
402
+            }
403 403
 
404
-			if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
405
-				update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
406
-			}
404
+            if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
405
+                update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
406
+            }
407 407
 }
408 408
 
409
-		// Save payment form data.
410
-		$shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
409
+        // Save payment form data.
410
+        $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
411 411
         if ( ! empty( $shipping ) ) {
412 412
             update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
413
-		}
413
+        }
414 414
 
415
-		// Backwards compatibility.
415
+        // Backwards compatibility.
416 416
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
417 417
 
418
-		$this->process_payment( $invoice );
418
+        $this->process_payment( $invoice );
419 419
 
420 420
         // If we are here, there was an error.
421
-		wpinv_send_back_to_checkout( $invoice );
421
+        wpinv_send_back_to_checkout( $invoice );
422 422
 
423
-	}
423
+    }
424 424
 
425
-	/**
426
-	 * Processes the actual payment.
427
-	 *
428
-	 * @param WPInv_Invoice $invoice
429
-	 */
430
-	protected function process_payment( $invoice ) {
425
+    /**
426
+     * Processes the actual payment.
427
+     *
428
+     * @param WPInv_Invoice $invoice
429
+     */
430
+    protected function process_payment( $invoice ) {
431 431
 
432
-		// Clear any checkout errors.
433
-		wpinv_clear_errors();
432
+        // Clear any checkout errors.
433
+        wpinv_clear_errors();
434 434
 
435
-		// No need to send free invoices to the gateway.
436
-		if ( $invoice->is_free() ) {
437
-			$this->process_free_payment( $invoice );
438
-		}
435
+        // No need to send free invoices to the gateway.
436
+        if ( $invoice->is_free() ) {
437
+            $this->process_free_payment( $invoice );
438
+        }
439 439
 
440
-		$submission = $this->payment_form_submission;
440
+        $submission = $this->payment_form_submission;
441 441
 
442
-		// Fires before sending to the gateway.
443
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
442
+        // Fires before sending to the gateway.
443
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
444 444
 
445
-		// Allow the sumission data to be modified before it is sent to the gateway.
446
-		$submission_data    = $submission->get_data();
447
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
448
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
445
+        // Allow the sumission data to be modified before it is sent to the gateway.
446
+        $submission_data    = $submission->get_data();
447
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
448
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
449 449
 
450
-		// Validate the currency.
451
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
452
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
453
-		}
450
+        // Validate the currency.
451
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
452
+            wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
453
+        }
454 454
 
455
-		// Check to see if we have any errors.
456
-		if ( wpinv_get_errors() ) {
457
-			wpinv_send_back_to_checkout( $invoice );
458
-		}
455
+        // Check to see if we have any errors.
456
+        if ( wpinv_get_errors() ) {
457
+            wpinv_send_back_to_checkout( $invoice );
458
+        }
459 459
 
460
-		// Send info to the gateway for payment processing
461
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
460
+        // Send info to the gateway for payment processing
461
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
462 462
 
463
-		// Backwards compatibility.
464
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
463
+        // Backwards compatibility.
464
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
465 465
 
466
-	}
466
+    }
467 467
 
468
-	/**
469
-	 * Marks the invoice as paid in case the checkout is free.
470
-	 *
471
-	 * @param WPInv_Invoice $invoice
472
-	 */
473
-	protected function process_free_payment( $invoice ) {
468
+    /**
469
+     * Marks the invoice as paid in case the checkout is free.
470
+     *
471
+     * @param WPInv_Invoice $invoice
472
+     */
473
+    protected function process_free_payment( $invoice ) {
474 474
 
475
-		$invoice->set_gateway( 'none' );
476
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
477
-		$invoice->mark_paid();
478
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
475
+        $invoice->set_gateway( 'none' );
476
+        $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
477
+        $invoice->mark_paid();
478
+        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
479 479
 
480
-	}
480
+    }
481 481
 
482
-	/**
482
+    /**
483 483
      * Sends a redrect response to payment details.
484 484
      *
485 485
      */
Please login to merge, or discard this patch.
includes/class-wpinv.php 1 patch
Indentation   +591 added lines, -591 removed lines patch added patch discarded remove patch
@@ -14,636 +14,636 @@
 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
-
71
-		if ( isset( $this->data[ $prop ] ) ) {
72
-			return $this->data[ $prop ];
73
-		}
74
-
75
-		return null;
76
-	}
77
-
78
-	/**
79
-	 * Define class properties.
80
-	 */
81
-	public function set_properties() {
82
-
83
-		// Sessions.
84
-		$this->set( 'session', new WPInv_Session_Handler() );
85
-		$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
86
-		$GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
87
-
88
-		// Init other objects.
89
-		$this->set( 'session', new WPInv_Session_Handler() );
90
-		$this->set( 'notes', new WPInv_Notes() );
91
-		$this->set( 'api', new WPInv_API() );
92
-		$this->set( 'post_types', new GetPaid_Post_Types() );
93
-		$this->set( 'template', new GetPaid_Template() );
94
-		$this->set( 'admin', new GetPaid_Admin() );
95
-		$this->set( 'subscriptions', new WPInv_Subscriptions() );
96
-		$this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
97
-		$this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
98
-		$this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
99
-		$this->set( 'payment_forms', new GetPaid_Payment_Forms() );
100
-		$this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
101
-
102
-	}
103
-
104
-	 /**
105
-	 * Define plugin constants.
106
-	 */
107
-	public function define_constants() {
108
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
109
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
110
-		$this->version = WPINV_VERSION;
111
-	}
112
-
113
-	/**
114
-	 * Hook into actions and filters.
115
-	 *
116
-	 * @since 1.0.19
117
-	 */
118
-	protected function init_hooks() {
119
-		/* Internationalize the text strings used. */
120
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
121
-
122
-		// Init the plugin after WordPress inits.
123
-		add_action( 'init', array( $this, 'init' ), 1 );
124
-		add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
125
-		add_action( 'init', array( $this, 'wpinv_actions' ) );
126
-		add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
127
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
128
-		add_action( 'wp_footer', array( $this, 'wp_footer' ) );
129
-		add_action( 'wp_head', array( $this, 'wp_head' ) );
130
-		add_action( 'widgets_init', array( $this, 'register_widgets' ) );
131
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
132
-		add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) );
133
-		add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
134
-
135
-		add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
17
+    /**
18
+     * GetPaid version.
19
+     *
20
+     * @var string
21
+     */
22
+    public $version;
23
+
24
+    /**
25
+     * Data container.
26
+     *
27
+     * @var array
28
+     */
29
+    protected $data = array();
30
+
31
+    /**
32
+     * Form elements instance.
33
+     *
34
+     * @var WPInv_Payment_Form_Elements
35
+     */
36
+    public $form_elements;
37
+
38
+    /**
39
+     * @var array An array of payment gateways.
40
+     */
41
+    public $gateways;
42
+
43
+    /**
44
+     * Class constructor.
45
+     */
46
+    public function __construct() {
47
+        $this->define_constants();
48
+        $this->includes();
49
+        $this->init_hooks();
50
+        $this->set_properties();
51
+    }
52
+
53
+    /**
54
+     * Sets a custom data property.
55
+     *
56
+     * @param string $prop The prop to set.
57
+     * @param mixed $value The value to retrieve.
58
+     */
59
+    public function set( $prop, $value ) {
60
+        $this->data[ $prop ] = $value;
61
+    }
62
+
63
+    /**
64
+     * Gets a custom data property.
65
+     *
66
+     * @param string $prop The prop to set.
67
+     * @return mixed The value.
68
+     */
69
+    public function get( $prop ) {
70
+
71
+        if ( isset( $this->data[ $prop ] ) ) {
72
+            return $this->data[ $prop ];
73
+        }
74
+
75
+        return null;
76
+    }
77
+
78
+    /**
79
+     * Define class properties.
80
+     */
81
+    public function set_properties() {
82
+
83
+        // Sessions.
84
+        $this->set( 'session', new WPInv_Session_Handler() );
85
+        $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
86
+        $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
87
+
88
+        // Init other objects.
89
+        $this->set( 'session', new WPInv_Session_Handler() );
90
+        $this->set( 'notes', new WPInv_Notes() );
91
+        $this->set( 'api', new WPInv_API() );
92
+        $this->set( 'post_types', new GetPaid_Post_Types() );
93
+        $this->set( 'template', new GetPaid_Template() );
94
+        $this->set( 'admin', new GetPaid_Admin() );
95
+        $this->set( 'subscriptions', new WPInv_Subscriptions() );
96
+        $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
97
+        $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
98
+        $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
99
+        $this->set( 'payment_forms', new GetPaid_Payment_Forms() );
100
+        $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
101
+
102
+    }
103
+
104
+        /**
105
+         * Define plugin constants.
106
+         */
107
+    public function define_constants() {
108
+        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
109
+        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
110
+        $this->version = WPINV_VERSION;
111
+    }
112
+
113
+    /**
114
+     * Hook into actions and filters.
115
+     *
116
+     * @since 1.0.19
117
+     */
118
+    protected function init_hooks() {
119
+        /* Internationalize the text strings used. */
120
+        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
121
+
122
+        // Init the plugin after WordPress inits.
123
+        add_action( 'init', array( $this, 'init' ), 1 );
124
+        add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
125
+        add_action( 'init', array( $this, 'wpinv_actions' ) );
126
+        add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
127
+        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
128
+        add_action( 'wp_footer', array( $this, 'wp_footer' ) );
129
+        add_action( 'wp_head', array( $this, 'wp_head' ) );
130
+        add_action( 'widgets_init', array( $this, 'register_widgets' ) );
131
+        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
132
+        add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) );
133
+        add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
134
+
135
+        add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
136 136
         add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 );
137
-		add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
138
-
139
-		// Fires after registering actions.
140
-		do_action( 'wpinv_actions', $this );
141
-		do_action( 'getpaid_actions', $this );
142
-
143
-	}
144
-
145
-	public function plugins_loaded() {
146
-		/* Internationalize the text strings used. */
147
-		$this->load_textdomain();
148
-
149
-		do_action( 'wpinv_loaded' );
150
-
151
-		// Fix oxygen page builder conflict
152
-		if ( function_exists( 'ct_css_output' ) ) {
153
-			wpinv_oxygen_fix_conflict();
154
-		}
155
-	}
156
-
157
-	/**
158
-	 * Load Localisation files.
159
-	 *
160
-	 * Note: the first-loaded translation file overrides any following ones if the same translation is present.
161
-	 *
162
-	 * Locales found in:
163
-	 *      - WP_LANG_DIR/plugins/invoicing-LOCALE.mo
164
-	 *      - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo
165
-	 *
166
-	 * @since 1.0.0
167
-	 */
168
-	public function load_textdomain() {
169
-
170
-		load_plugin_textdomain(
171
-			'invoicing',
172
-			false,
173
-			plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/'
174
-		);
175
-
176
-	}
177
-
178
-	/**
179
-	 * Include required core files used in admin and on the frontend.
180
-	 */
181
-	public function includes() {
182
-
183
-		// Start with the settings.
184
-		require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php';
185
-
186
-		// Packages/libraries.
187
-		require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php';
188
-		require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php';
189
-
190
-		// Load functions.
191
-		require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php';
192
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php';
193
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php';
194
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php';
195
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php';
196
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php';
197
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php';
198
-		require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php';
199
-		require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php';
200
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php';
201
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php';
202
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php';
203
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php';
204
-		require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php';
205
-		require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php';
206
-
207
-		// Register autoloader.
208
-		try {
209
-			spl_autoload_register( array( $this, 'autoload' ), true );
210
-		} catch ( Exception $e ) {
211
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
212
-		}
213
-
214
-		require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php';
215
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php';
216
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php';
217
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php';
218
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php';
219
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php';
220
-		require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php';
221
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php';
222
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php';
223
-		require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php';
224
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php';
225
-		require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php';
226
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php';
227
-		require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php';
228
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php';
229
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php';
230
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php';
231
-		require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php';
232
-		require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php';
233
-		require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php';
234
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php';
235
-		require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php';
236
-
237
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
238
-			GetPaid_Post_Types_Admin::init();
239
-
240
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php';
241
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php';
242
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php';
243
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php';
244
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php';
245
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php';
246
-			// load the user class only on the users.php page
247
-			global $pagenow;
248
-			if ( $pagenow == 'users.php' ) {
249
-				new WPInv_Admin_Users();
250
-			}
251
-		}
252
-
253
-		// Register cli commands
254
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
255
-			require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php';
256
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
257
-		}
258
-
259
-	}
260
-
261
-	/**
262
-	 * Class autoloader
263
-	 *
264
-	 * @param       string $class_name The name of the class to load.
265
-	 * @access      public
266
-	 * @since       1.0.19
267
-	 * @return      void
268
-	 */
269
-	public function autoload( $class_name ) {
270
-
271
-		// Normalize the class name...
272
-		$class_name  = strtolower( $class_name );
273
-
274
-		// ... and make sure it is our class.
275
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
276
-			return;
277
-		}
278
-
279
-		// Next, prepare the file name from the class.
280
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
281
-
282
-		// Base path of the classes.
283
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
284
-
285
-		// And an array of possible locations in order of importance.
286
-		$locations = array(
287
-			"$plugin_path/includes",
288
-			"$plugin_path/includes/data-stores",
289
-			"$plugin_path/includes/gateways",
290
-			"$plugin_path/includes/payments",
291
-			"$plugin_path/includes/geolocation",
292
-			"$plugin_path/includes/reports",
293
-			"$plugin_path/includes/api",
294
-			"$plugin_path/includes/admin",
295
-			"$plugin_path/includes/admin/meta-boxes",
296
-		);
297
-
298
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
299
-
300
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
301
-				include trailingslashit( $location ) . $file_name;
302
-				break;
303
-			}
137
+        add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
138
+
139
+        // Fires after registering actions.
140
+        do_action( 'wpinv_actions', $this );
141
+        do_action( 'getpaid_actions', $this );
142
+
143
+    }
144
+
145
+    public function plugins_loaded() {
146
+        /* Internationalize the text strings used. */
147
+        $this->load_textdomain();
148
+
149
+        do_action( 'wpinv_loaded' );
150
+
151
+        // Fix oxygen page builder conflict
152
+        if ( function_exists( 'ct_css_output' ) ) {
153
+            wpinv_oxygen_fix_conflict();
154
+        }
155
+    }
156
+
157
+    /**
158
+     * Load Localisation files.
159
+     *
160
+     * Note: the first-loaded translation file overrides any following ones if the same translation is present.
161
+     *
162
+     * Locales found in:
163
+     *      - WP_LANG_DIR/plugins/invoicing-LOCALE.mo
164
+     *      - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo
165
+     *
166
+     * @since 1.0.0
167
+     */
168
+    public function load_textdomain() {
169
+
170
+        load_plugin_textdomain(
171
+            'invoicing',
172
+            false,
173
+            plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/'
174
+        );
175
+
176
+    }
177
+
178
+    /**
179
+     * Include required core files used in admin and on the frontend.
180
+     */
181
+    public function includes() {
182
+
183
+        // Start with the settings.
184
+        require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php';
185
+
186
+        // Packages/libraries.
187
+        require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php';
188
+        require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php';
189
+
190
+        // Load functions.
191
+        require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php';
192
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php';
193
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php';
194
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php';
195
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php';
196
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php';
197
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php';
198
+        require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php';
199
+        require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php';
200
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php';
201
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php';
202
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php';
203
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php';
204
+        require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php';
205
+        require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php';
206
+
207
+        // Register autoloader.
208
+        try {
209
+            spl_autoload_register( array( $this, 'autoload' ), true );
210
+        } catch ( Exception $e ) {
211
+            wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
212
+        }
213
+
214
+        require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php';
215
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php';
216
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php';
217
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php';
218
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php';
219
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php';
220
+        require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php';
221
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php';
222
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php';
223
+        require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php';
224
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php';
225
+        require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php';
226
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php';
227
+        require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php';
228
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php';
229
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php';
230
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php';
231
+        require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php';
232
+        require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php';
233
+        require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php';
234
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php';
235
+        require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php';
236
+
237
+        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
238
+            GetPaid_Post_Types_Admin::init();
239
+
240
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php';
241
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php';
242
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php';
243
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php';
244
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php';
245
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php';
246
+            // load the user class only on the users.php page
247
+            global $pagenow;
248
+            if ( $pagenow == 'users.php' ) {
249
+                new WPInv_Admin_Users();
250
+            }
251
+        }
252
+
253
+        // Register cli commands
254
+        if ( defined( 'WP_CLI' ) && WP_CLI ) {
255
+            require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php';
256
+            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
257
+        }
258
+
259
+    }
260
+
261
+    /**
262
+     * Class autoloader
263
+     *
264
+     * @param       string $class_name The name of the class to load.
265
+     * @access      public
266
+     * @since       1.0.19
267
+     * @return      void
268
+     */
269
+    public function autoload( $class_name ) {
270
+
271
+        // Normalize the class name...
272
+        $class_name  = strtolower( $class_name );
273
+
274
+        // ... and make sure it is our class.
275
+        if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
276
+            return;
277
+        }
278
+
279
+        // Next, prepare the file name from the class.
280
+        $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
281
+
282
+        // Base path of the classes.
283
+        $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
284
+
285
+        // And an array of possible locations in order of importance.
286
+        $locations = array(
287
+            "$plugin_path/includes",
288
+            "$plugin_path/includes/data-stores",
289
+            "$plugin_path/includes/gateways",
290
+            "$plugin_path/includes/payments",
291
+            "$plugin_path/includes/geolocation",
292
+            "$plugin_path/includes/reports",
293
+            "$plugin_path/includes/api",
294
+            "$plugin_path/includes/admin",
295
+            "$plugin_path/includes/admin/meta-boxes",
296
+        );
297
+
298
+        foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
299
+
300
+            if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
301
+                include trailingslashit( $location ) . $file_name;
302
+                break;
303
+            }
304 304
 }
305 305
 
306
-	}
307
-
308
-	/**
309
-	 * Inits hooks etc.
310
-	 */
311
-	public function init() {
312
-
313
-		// Fires before getpaid inits.
314
-		do_action( 'before_getpaid_init', $this );
315
-
316
-		// Maybe upgrade.
317
-		$this->maybe_upgrade_database();
318
-
319
-		// Load default gateways.
320
-		$gateways = apply_filters(
321
-			'getpaid_default_gateways',
322
-			array(
323
-				'manual'        => 'GetPaid_Manual_Gateway',
324
-				'paypal'        => 'GetPaid_Paypal_Gateway',
325
-				'worldpay'      => 'GetPaid_Worldpay_Gateway',
326
-				'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
327
-				'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
328
-			)
329
-		);
330
-
331
-		foreach ( $gateways as $id => $class ) {
332
-			$this->gateways[ $id ] = new $class();
333
-		}
334
-
335
-		if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
336
-			GetPaid_Installer::rename_gateways_label();
337
-			update_option( 'wpinv_renamed_gateways', 'yes' );
338
-		}
339
-
340
-		// Fires after getpaid inits.
341
-		do_action( 'getpaid_init', $this );
342
-
343
-	}
344
-
345
-	/**
346
-	 * Checks if this is an IPN request and processes it.
347
-	 */
348
-	public function maybe_process_ipn() {
349
-
350
-		// Ensure that this is an IPN request.
351
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
352
-			return;
353
-		}
354
-
355
-		$gateway = sanitize_text_field( $_GET['wpi-gateway'] );
356
-
357
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
358
-		do_action( "wpinv_verify_{$gateway}_ipn" );
359
-		exit;
360
-
361
-	}
362
-
363
-	public function enqueue_scripts() {
364
-
365
-		// Fires before adding scripts.
366
-		do_action( 'getpaid_enqueue_scripts' );
367
-
368
-		$localize                         = array();
369
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
370
-		$localize['thousands']            = wpinv_thousands_separator();
371
-		$localize['decimals']             = wpinv_decimal_separator();
372
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
373
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
374
-		$localize['UseTaxes']             = wpinv_use_taxes();
375
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
376
-		$localize['loading']              = __( 'Loading...', 'invoicing' );
377
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
378
-
379
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
380
-
381
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
382
-		wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true );
383
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
384
-	}
385
-
386
-	public function wpinv_actions() {
387
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
388
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
389
-		}
390
-
391
-		if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) {
392
-			include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php';
393
-		}
394
-	}
395
-
396
-	/**
306
+    }
307
+
308
+    /**
309
+     * Inits hooks etc.
310
+     */
311
+    public function init() {
312
+
313
+        // Fires before getpaid inits.
314
+        do_action( 'before_getpaid_init', $this );
315
+
316
+        // Maybe upgrade.
317
+        $this->maybe_upgrade_database();
318
+
319
+        // Load default gateways.
320
+        $gateways = apply_filters(
321
+            'getpaid_default_gateways',
322
+            array(
323
+                'manual'        => 'GetPaid_Manual_Gateway',
324
+                'paypal'        => 'GetPaid_Paypal_Gateway',
325
+                'worldpay'      => 'GetPaid_Worldpay_Gateway',
326
+                'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
327
+                'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
328
+            )
329
+        );
330
+
331
+        foreach ( $gateways as $id => $class ) {
332
+            $this->gateways[ $id ] = new $class();
333
+        }
334
+
335
+        if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
336
+            GetPaid_Installer::rename_gateways_label();
337
+            update_option( 'wpinv_renamed_gateways', 'yes' );
338
+        }
339
+
340
+        // Fires after getpaid inits.
341
+        do_action( 'getpaid_init', $this );
342
+
343
+    }
344
+
345
+    /**
346
+     * Checks if this is an IPN request and processes it.
347
+     */
348
+    public function maybe_process_ipn() {
349
+
350
+        // Ensure that this is an IPN request.
351
+        if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
352
+            return;
353
+        }
354
+
355
+        $gateway = sanitize_text_field( $_GET['wpi-gateway'] );
356
+
357
+        do_action( 'wpinv_verify_payment_ipn', $gateway );
358
+        do_action( "wpinv_verify_{$gateway}_ipn" );
359
+        exit;
360
+
361
+    }
362
+
363
+    public function enqueue_scripts() {
364
+
365
+        // Fires before adding scripts.
366
+        do_action( 'getpaid_enqueue_scripts' );
367
+
368
+        $localize                         = array();
369
+        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
370
+        $localize['thousands']            = wpinv_thousands_separator();
371
+        $localize['decimals']             = wpinv_decimal_separator();
372
+        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
373
+        $localize['txtComplete']          = __( 'Continue', 'invoicing' );
374
+        $localize['UseTaxes']             = wpinv_use_taxes();
375
+        $localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
376
+        $localize['loading']              = __( 'Loading...', 'invoicing' );
377
+        $localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
378
+
379
+        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
380
+
381
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
382
+        wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true );
383
+        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
384
+    }
385
+
386
+    public function wpinv_actions() {
387
+        if ( isset( $_REQUEST['wpi_action'] ) ) {
388
+            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
389
+        }
390
+
391
+        if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) {
392
+            include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php';
393
+        }
394
+    }
395
+
396
+    /**
397 397
      * Fires an action after verifying that a user can fire them.
398
-	 *
399
-	 * Note: If the action is on an invoice, subscription etc, esure that the
400
-	 * current user owns the invoice/subscription.
398
+     *
399
+     * Note: If the action is on an invoice, subscription etc, esure that the
400
+     * current user owns the invoice/subscription.
401 401
      */
402 402
     public function maybe_do_authenticated_action() {
403 403
 
404
-		if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
404
+        if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
405 405
 
406
-			$key  = sanitize_key( $_REQUEST['getpaid-action'] );
407
-			$data = wp_unslash( $_REQUEST );
408
-			if ( is_user_logged_in() ) {
409
-				do_action( "getpaid_authenticated_action_$key", $data );
410
-			}
406
+            $key  = sanitize_key( $_REQUEST['getpaid-action'] );
407
+            $data = wp_unslash( $_REQUEST );
408
+            if ( is_user_logged_in() ) {
409
+                do_action( "getpaid_authenticated_action_$key", $data );
410
+            }
411 411
 
412
-			do_action( "getpaid_unauthenticated_action_$key", $data );
412
+            do_action( "getpaid_unauthenticated_action_$key", $data );
413 413
 
414
-		}
414
+        }
415 415
 
416 416
     }
417 417
 
418
-	public function pre_get_posts( $wp_query ) {
419
-
420
-		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() ) {
421
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
422
-		}
423
-
424
-		return $wp_query;
425
-	}
426
-
427
-	/**
428
-	 * Register widgets
429
-	 *
430
-	 */
431
-	public function register_widgets() {
432
-		global $pagenow;
433
-
434
-		// Currently, UX Builder does not work particulaly well with SuperDuper.
435
-		// So we disable our widgets when editing a page with UX Builder.
436
-		if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
437
-			return;
438
-		}
439
-
440
-		$block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array();
441
-
442
-		if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) {
443
-			// don't initiate in these conditions.
444
-		} else {
445
-
446
-			// Only load allowed widgets.
447
-			$exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array();
448
-			$widgets = apply_filters(
449
-				'getpaid_widget_classes',
450
-				array(
451
-					'WPInv_Checkout_Widget',
452
-					'WPInv_History_Widget',
453
-					'WPInv_Receipt_Widget',
454
-					'WPInv_Subscriptions_Widget',
455
-					'WPInv_Buy_Item_Widget',
456
-					'WPInv_Messages_Widget',
457
-					'WPInv_GetPaid_Widget',
458
-					'WPInv_Invoice_Widget',
459
-				)
460
-			);
461
-
462
-			// For each widget...
463
-			foreach ( $widgets as $widget ) {
464
-
465
-				// Abort early if it is excluded for this page.
466
-				if ( in_array( $widget, $exclude ) ) {
467
-					continue;
468
-				}
469
-
470
-				// SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it.
471
-				if ( is_subclass_of( $widget, 'WP_Widget' ) ) {
472
-					register_widget( $widget );
473
-				} else {
474
-					new $widget();
475
-				}
418
+    public function pre_get_posts( $wp_query ) {
419
+
420
+        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() ) {
421
+            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
422
+        }
423
+
424
+        return $wp_query;
425
+    }
426
+
427
+    /**
428
+     * Register widgets
429
+     *
430
+     */
431
+    public function register_widgets() {
432
+        global $pagenow;
433
+
434
+        // Currently, UX Builder does not work particulaly well with SuperDuper.
435
+        // So we disable our widgets when editing a page with UX Builder.
436
+        if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
437
+            return;
438
+        }
439
+
440
+        $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array();
441
+
442
+        if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) {
443
+            // don't initiate in these conditions.
444
+        } else {
445
+
446
+            // Only load allowed widgets.
447
+            $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array();
448
+            $widgets = apply_filters(
449
+                'getpaid_widget_classes',
450
+                array(
451
+                    'WPInv_Checkout_Widget',
452
+                    'WPInv_History_Widget',
453
+                    'WPInv_Receipt_Widget',
454
+                    'WPInv_Subscriptions_Widget',
455
+                    'WPInv_Buy_Item_Widget',
456
+                    'WPInv_Messages_Widget',
457
+                    'WPInv_GetPaid_Widget',
458
+                    'WPInv_Invoice_Widget',
459
+                )
460
+            );
461
+
462
+            // For each widget...
463
+            foreach ( $widgets as $widget ) {
464
+
465
+                // Abort early if it is excluded for this page.
466
+                if ( in_array( $widget, $exclude ) ) {
467
+                    continue;
468
+                }
469
+
470
+                // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it.
471
+                if ( is_subclass_of( $widget, 'WP_Widget' ) ) {
472
+                    register_widget( $widget );
473
+                } else {
474
+                    new $widget();
475
+                }
476 476
 }
477 477
 }
478 478
 
479
-	}
479
+    }
480
+
481
+    /**
482
+     * Upgrades the database.
483
+     *
484
+     * @since 2.0.2
485
+     */
486
+    public function maybe_upgrade_database() {
487
+
488
+        $wpi_version = get_option( 'wpinv_version', 0 );
489
+
490
+        if ( $wpi_version == WPINV_VERSION ) {
491
+            return;
492
+        }
480 493
 
481
-	/**
482
-	 * Upgrades the database.
483
-	 *
484
-	 * @since 2.0.2
485
-	 */
486
-	public function maybe_upgrade_database() {
494
+        $installer = new GetPaid_Installer();
487 495
 
488
-		$wpi_version = get_option( 'wpinv_version', 0 );
496
+        if ( empty( $wpi_version ) ) {
497
+            return $installer->upgrade_db( 0 );
498
+        }
489 499
 
490
-		if ( $wpi_version == WPINV_VERSION ) {
491
-			return;
492
-		}
500
+        $upgrades  = array(
501
+            '0.0.5'  => '004',
502
+            '1.0.3'  => '102',
503
+            '2.0.0'  => '118',
504
+            '2.0.8'  => '207',
505
+            '2.6.16' => '2615',
506
+        );
493 507
 
494
-		$installer = new GetPaid_Installer();
508
+        foreach ( $upgrades as $key => $method ) {
509
+
510
+            if ( version_compare( $wpi_version, $key, '<' ) ) {
511
+                return $installer->upgrade_db( $method );
512
+            }
513
+        }
514
+
515
+    }
516
+
517
+    /**
518
+     * Flushes the permalinks if needed.
519
+     *
520
+     * @since 2.0.8
521
+     */
522
+    public function maybe_flush_permalinks() {
495 523
 
496
-		if ( empty( $wpi_version ) ) {
497
-			return $installer->upgrade_db( 0 );
498
-		}
524
+        $flush = get_option( 'wpinv_flush_permalinks', 0 );
499 525
 
500
-		$upgrades  = array(
501
-			'0.0.5'  => '004',
502
-			'1.0.3'  => '102',
503
-			'2.0.0'  => '118',
504
-			'2.0.8'  => '207',
505
-			'2.6.16' => '2615',
506
-		);
507
-
508
-		foreach ( $upgrades as $key => $method ) {
509
-
510
-			if ( version_compare( $wpi_version, $key, '<' ) ) {
511
-				return $installer->upgrade_db( $method );
512
-			}
513
-		}
514
-
515
-	}
516
-
517
-	/**
518
-	 * Flushes the permalinks if needed.
519
-	 *
520
-	 * @since 2.0.8
521
-	 */
522
-	public function maybe_flush_permalinks() {
523
-
524
-		$flush = get_option( 'wpinv_flush_permalinks', 0 );
525
-
526
-		if ( ! empty( $flush ) ) {
527
-			flush_rewrite_rules();
528
-			delete_option( 'wpinv_flush_permalinks' );
529
-		}
530
-
531
-	}
532
-
533
-	/**
534
-	 * Remove our pages from yoast sitemaps.
535
-	 *
536
-	 * @since 1.0.19
537
-	 * @param int[] $excluded_posts_ids
538
-	 */
539
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) {
540
-
541
-		// Ensure that we have an array.
542
-		if ( ! is_array( $excluded_posts_ids ) ) {
543
-			$excluded_posts_ids = array();
544
-		}
545
-
546
-		// Prepare our pages.
547
-		$our_pages = array();
548
-
549
-		// Checkout page.
550
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
551
-
552
-		// Success page.
553
-		$our_pages[] = wpinv_get_option( 'success_page', false );
554
-
555
-		// Failure page.
556
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
557
-
558
-		// History page.
559
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
560
-
561
-		// Subscriptions page.
562
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
563
-
564
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
565
-
566
-		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
567
-		return array_unique( $excluded_posts_ids );
568
-
569
-	}
570
-
571
-	/**
572
-	 * Remove our pages from yoast sitemaps.
573
-	 *
574
-	 * @since 1.0.19
575
-	 * @param string[] $post_types
576
-	 */
577
-	public function exclude_invoicing_post_types( $post_types ) {
578
-
579
-		// Ensure that we have an array.
580
-		if ( ! is_array( $post_types ) ) {
581
-			$post_types = array();
582
-		}
583
-
584
-		// Remove our post types.
585
-		return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) );
586
-	}
587
-
588
-	/**
589
-	 * Displays additional footer code.
590
-	 *
591
-	 * @since 2.0.0
592
-	 */
593
-	public function wp_footer() {
594
-		wpinv_get_template( 'frontend-footer.php' );
595
-	}
596
-
597
-	/**
598
-	 * Displays additional header code.
599
-	 *
600
-	 * @since 2.0.0
601
-	 */
602
-	public function wp_head() {
603
-		wpinv_get_template( 'frontend-head.php' );
604
-	}
605
-
606
-	/**
607
-	 * Custom query vars.
608
-	 *
609
-	 */
610
-	public function custom_query_vars( $vars ) {
526
+        if ( ! empty( $flush ) ) {
527
+            flush_rewrite_rules();
528
+            delete_option( 'wpinv_flush_permalinks' );
529
+        }
530
+
531
+    }
532
+
533
+    /**
534
+     * Remove our pages from yoast sitemaps.
535
+     *
536
+     * @since 1.0.19
537
+     * @param int[] $excluded_posts_ids
538
+     */
539
+    public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) {
540
+
541
+        // Ensure that we have an array.
542
+        if ( ! is_array( $excluded_posts_ids ) ) {
543
+            $excluded_posts_ids = array();
544
+        }
545
+
546
+        // Prepare our pages.
547
+        $our_pages = array();
548
+
549
+        // Checkout page.
550
+        $our_pages[] = wpinv_get_option( 'checkout_page', false );
551
+
552
+        // Success page.
553
+        $our_pages[] = wpinv_get_option( 'success_page', false );
554
+
555
+        // Failure page.
556
+        $our_pages[] = wpinv_get_option( 'failure_page', false );
557
+
558
+        // History page.
559
+        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
560
+
561
+        // Subscriptions page.
562
+        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
563
+
564
+        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
565
+
566
+        $excluded_posts_ids = $excluded_posts_ids + $our_pages;
567
+        return array_unique( $excluded_posts_ids );
568
+
569
+    }
570
+
571
+    /**
572
+     * Remove our pages from yoast sitemaps.
573
+     *
574
+     * @since 1.0.19
575
+     * @param string[] $post_types
576
+     */
577
+    public function exclude_invoicing_post_types( $post_types ) {
578
+
579
+        // Ensure that we have an array.
580
+        if ( ! is_array( $post_types ) ) {
581
+            $post_types = array();
582
+        }
583
+
584
+        // Remove our post types.
585
+        return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) );
586
+    }
587
+
588
+    /**
589
+     * Displays additional footer code.
590
+     *
591
+     * @since 2.0.0
592
+     */
593
+    public function wp_footer() {
594
+        wpinv_get_template( 'frontend-footer.php' );
595
+    }
596
+
597
+    /**
598
+     * Displays additional header code.
599
+     *
600
+     * @since 2.0.0
601
+     */
602
+    public function wp_head() {
603
+        wpinv_get_template( 'frontend-head.php' );
604
+    }
605
+
606
+    /**
607
+     * Custom query vars.
608
+     *
609
+     */
610
+    public function custom_query_vars( $vars ) {
611 611
         $vars[] = 'getpaid-ipn';
612 612
         return $vars;
613
-	}
613
+    }
614 614
 
615
-	/**
616
-	 * Add rewrite tags and rules.
617
-	 *
618
-	 */
619
-	public function add_rewrite_rule() {
615
+    /**
616
+     * Add rewrite tags and rules.
617
+     *
618
+     */
619
+    public function add_rewrite_rule() {
620 620
         $tag = 'getpaid-ipn';
621 621
         add_rewrite_tag( "%$tag%", '([^&]+)' );
622 622
         add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' );
623
-	}
623
+    }
624 624
 
625
-	/**
626
-	 * Processes non-query string ipns.
627
-	 *
628
-	 */
629
-	public function maybe_process_new_ipn( $query ) {
625
+    /**
626
+     * Processes non-query string ipns.
627
+     *
628
+     */
629
+    public function maybe_process_new_ipn( $query ) {
630 630
 
631 631
         if ( is_admin() || ! $query->is_main_query() ) {
632 632
             return;
633 633
         }
634 634
 
635
-		$gateway = get_query_var( 'getpaid-ipn' );
635
+        $gateway = get_query_var( 'getpaid-ipn' );
636 636
 
637 637
         if ( ! empty( $gateway ) ) {
638 638
 
639
-			$gateway = sanitize_text_field( $gateway );
640
-			nocache_headers();
641
-			do_action( 'wpinv_verify_payment_ipn', $gateway );
642
-			do_action( "wpinv_verify_{$gateway}_ipn" );
643
-			exit;
639
+            $gateway = sanitize_text_field( $gateway );
640
+            nocache_headers();
641
+            do_action( 'wpinv_verify_payment_ipn', $gateway );
642
+            do_action( "wpinv_verify_{$gateway}_ipn" );
643
+            exit;
644 644
 
645 645
         }
646 646
 
647
-	}
647
+    }
648 648
 
649 649
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-installer.php 1 patch
Indentation   +384 added lines, -384 removed lines patch added patch discarded remove patch
@@ -20,237 +20,237 @@  discard block
 block discarded – undo
20 20
  */
21 21
 class GetPaid_Installer {
22 22
 
23
-	/**
24
-	 * Upgrades the install.
25
-	 *
26
-	 * @param string $upgrade_from The current invoicing version.
27
-	 */
28
-	public function upgrade_db( $upgrade_from ) {
29
-
30
-		// Save the current invoicing version.
31
-		update_option( 'wpinv_version', WPINV_VERSION );
32
-
33
-		// Setup the invoice Custom Post Type.
34
-		GetPaid_Post_Types::register_post_types();
35
-
36
-		// Clear the permalinks
37
-		flush_rewrite_rules();
38
-
39
-		// Maybe create new/missing pages.
40
-		$this->create_pages();
41
-
42
-		// Maybe re(add) admin capabilities.
43
-		$this->add_capabilities();
44
-
45
-		// Maybe create the default payment form.
46
-		wpinv_get_default_payment_form();
47
-
48
-		// Create any missing database tables.
49
-		$method = "upgrade_from_$upgrade_from";
50
-
51
-		$installed = get_option( 'gepaid_installed_on' );
52
-
53
-		if ( empty( $installed ) ) {
54
-			update_option( 'gepaid_installed_on', time() );
55
-		}
56
-
57
-		if ( method_exists( $this, $method ) ) {
58
-			$this->$method();
59
-		}
60
-
61
-	}
62
-
63
-	/**
64
-	 * Do a fresh install.
65
-	 *
66
-	 */
67
-	public function upgrade_from_0() {
68
-		$this->create_subscriptions_table();
69
-		$this->create_invoices_table();
70
-		$this->create_invoice_items_table();
71
-
72
-		// Save default tax rates.
73
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
74
-	}
75
-
76
-	/**
77
-	 * Upgrade to 0.0.5
78
-	 *
79
-	 */
80
-	public function upgrade_from_004() {
81
-		global $wpdb;
82
-
83
-		// Invoices.
84
-		$results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
85
-		if ( ! empty( $results ) ) {
86
-			$wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
87
-
88
-			// Clean post cache
89
-			foreach ( $results as $row ) {
90
-				clean_post_cache( $row->ID );
91
-			}
92
-		}
93
-
94
-		// Item meta key changes
95
-		$query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
96
-		$results = $wpdb->get_results( $query );
97
-
98
-		if ( ! empty( $results ) ) {
99
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
100
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
101
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
102
-
103
-			foreach ( $results as $row ) {
104
-				clean_post_cache( $row->post_id );
105
-			}
106
-		}
107
-
108
-		$this->upgrade_from_102();
109
-	}
110
-
111
-	/**
112
-	 * Upgrade to 1.0.3
113
-	 *
114
-	 */
115
-	public function upgrade_from_102() {
116
-		$this->create_subscriptions_table();
117
-		$this->upgrade_from_118();
118
-	}
119
-
120
-	/**
121
-	 * Upgrade to version 2.0.0.
122
-	 *
123
-	 */
124
-	public function upgrade_from_118() {
125
-		$this->create_invoices_table();
126
-		$this->create_invoice_items_table();
127
-		$this->migrate_old_invoices();
128
-	}
129
-
130
-	/**
131
-	 * Upgrade to version 2.0.8.
132
-	 *
133
-	 */
134
-	public function upgrade_from_207() {
135
-		global $wpdb;
136
-		$wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" );
137
-		$this->upgrade_from_2615();
138
-	}
139
-
140
-	/**
141
-	 * Upgrade to version 2.6.16.
142
-	 *
143
-	 */
144
-	public function upgrade_from_2615() {
145
-		global $wpdb;
146
-		$wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN item_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY custom_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY price DECIMAL(16,4) NOT NULL DEFAULT '0';" );
147
-		$wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices MODIFY COLUMN subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY tax DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY fees_total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0';" );
148
-	}
149
-
150
-	/**
151
-	 * Give administrators the capability to manage GetPaid.
152
-	 *
153
-	 */
154
-	public function add_capabilities() {
155
-		$GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
156
-	}
157
-
158
-	/**
159
-	 * Retreives GetPaid pages.
160
-	 *
161
-	 */
162
-	public static function get_pages() {
163
-
164
-		return apply_filters(
165
-			'wpinv_create_pages',
166
-			array(
167
-
168
-				// Checkout page.
169
-				'checkout_page'             => array(
170
-					'name'    => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
171
-					'title'   => _x( 'Checkout', 'Page title', 'invoicing' ),
172
-					'content' => '
23
+    /**
24
+     * Upgrades the install.
25
+     *
26
+     * @param string $upgrade_from The current invoicing version.
27
+     */
28
+    public function upgrade_db( $upgrade_from ) {
29
+
30
+        // Save the current invoicing version.
31
+        update_option( 'wpinv_version', WPINV_VERSION );
32
+
33
+        // Setup the invoice Custom Post Type.
34
+        GetPaid_Post_Types::register_post_types();
35
+
36
+        // Clear the permalinks
37
+        flush_rewrite_rules();
38
+
39
+        // Maybe create new/missing pages.
40
+        $this->create_pages();
41
+
42
+        // Maybe re(add) admin capabilities.
43
+        $this->add_capabilities();
44
+
45
+        // Maybe create the default payment form.
46
+        wpinv_get_default_payment_form();
47
+
48
+        // Create any missing database tables.
49
+        $method = "upgrade_from_$upgrade_from";
50
+
51
+        $installed = get_option( 'gepaid_installed_on' );
52
+
53
+        if ( empty( $installed ) ) {
54
+            update_option( 'gepaid_installed_on', time() );
55
+        }
56
+
57
+        if ( method_exists( $this, $method ) ) {
58
+            $this->$method();
59
+        }
60
+
61
+    }
62
+
63
+    /**
64
+     * Do a fresh install.
65
+     *
66
+     */
67
+    public function upgrade_from_0() {
68
+        $this->create_subscriptions_table();
69
+        $this->create_invoices_table();
70
+        $this->create_invoice_items_table();
71
+
72
+        // Save default tax rates.
73
+        update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
74
+    }
75
+
76
+    /**
77
+     * Upgrade to 0.0.5
78
+     *
79
+     */
80
+    public function upgrade_from_004() {
81
+        global $wpdb;
82
+
83
+        // Invoices.
84
+        $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
85
+        if ( ! empty( $results ) ) {
86
+            $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
87
+
88
+            // Clean post cache
89
+            foreach ( $results as $row ) {
90
+                clean_post_cache( $row->ID );
91
+            }
92
+        }
93
+
94
+        // Item meta key changes
95
+        $query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
96
+        $results = $wpdb->get_results( $query );
97
+
98
+        if ( ! empty( $results ) ) {
99
+            $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
100
+            $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
101
+            $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
102
+
103
+            foreach ( $results as $row ) {
104
+                clean_post_cache( $row->post_id );
105
+            }
106
+        }
107
+
108
+        $this->upgrade_from_102();
109
+    }
110
+
111
+    /**
112
+     * Upgrade to 1.0.3
113
+     *
114
+     */
115
+    public function upgrade_from_102() {
116
+        $this->create_subscriptions_table();
117
+        $this->upgrade_from_118();
118
+    }
119
+
120
+    /**
121
+     * Upgrade to version 2.0.0.
122
+     *
123
+     */
124
+    public function upgrade_from_118() {
125
+        $this->create_invoices_table();
126
+        $this->create_invoice_items_table();
127
+        $this->migrate_old_invoices();
128
+    }
129
+
130
+    /**
131
+     * Upgrade to version 2.0.8.
132
+     *
133
+     */
134
+    public function upgrade_from_207() {
135
+        global $wpdb;
136
+        $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" );
137
+        $this->upgrade_from_2615();
138
+    }
139
+
140
+    /**
141
+     * Upgrade to version 2.6.16.
142
+     *
143
+     */
144
+    public function upgrade_from_2615() {
145
+        global $wpdb;
146
+        $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN item_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY custom_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY price DECIMAL(16,4) NOT NULL DEFAULT '0';" );
147
+        $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices MODIFY COLUMN subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY tax DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY fees_total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0';" );
148
+    }
149
+
150
+    /**
151
+     * Give administrators the capability to manage GetPaid.
152
+     *
153
+     */
154
+    public function add_capabilities() {
155
+        $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
156
+    }
157
+
158
+    /**
159
+     * Retreives GetPaid pages.
160
+     *
161
+     */
162
+    public static function get_pages() {
163
+
164
+        return apply_filters(
165
+            'wpinv_create_pages',
166
+            array(
167
+
168
+                // Checkout page.
169
+                'checkout_page'             => array(
170
+                    'name'    => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
171
+                    'title'   => _x( 'Checkout', 'Page title', 'invoicing' ),
172
+                    'content' => '
173 173
 						<!-- wp:shortcode -->
174 174
 						[wpinv_checkout]
175 175
 						<!-- /wp:shortcode -->
176 176
 					',
177
-					'parent'  => '',
178
-				),
179
-
180
-				// Invoice history page.
181
-				'invoice_history_page'      => array(
182
-					'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
183
-					'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
184
-					'content' => '
177
+                    'parent'  => '',
178
+                ),
179
+
180
+                // Invoice history page.
181
+                'invoice_history_page'      => array(
182
+                    'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
183
+                    'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
184
+                    'content' => '
185 185
 					<!-- wp:shortcode -->
186 186
 					[wpinv_history]
187 187
 					<!-- /wp:shortcode -->
188 188
 				',
189
-					'parent'  => '',
190
-				),
191
-
192
-				// Success page content.
193
-				'success_page'              => array(
194
-					'name'    => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
195
-					'title'   => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
196
-					'content' => '
189
+                    'parent'  => '',
190
+                ),
191
+
192
+                // Success page content.
193
+                'success_page'              => array(
194
+                    'name'    => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
195
+                    'title'   => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
196
+                    'content' => '
197 197
 					<!-- wp:shortcode -->
198 198
 					[wpinv_receipt]
199 199
 					<!-- /wp:shortcode -->
200 200
 				',
201
-					'parent'  => 'gp-checkout',
202
-				),
203
-
204
-				// Failure page content.
205
-				'failure_page'              => array(
206
-					'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
207
-					'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
208
-					'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ),
209
-					'parent'  => 'gp-checkout',
210
-				),
211
-
212
-				// Subscriptions history page.
213
-				'invoice_subscription_page' => array(
214
-					'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
215
-					'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
216
-					'content' => '
201
+                    'parent'  => 'gp-checkout',
202
+                ),
203
+
204
+                // Failure page content.
205
+                'failure_page'              => array(
206
+                    'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
207
+                    'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
208
+                    'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ),
209
+                    'parent'  => 'gp-checkout',
210
+                ),
211
+
212
+                // Subscriptions history page.
213
+                'invoice_subscription_page' => array(
214
+                    'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
215
+                    'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
216
+                    'content' => '
217 217
 					<!-- wp:shortcode -->
218 218
 					[wpinv_subscriptions]
219 219
 					<!-- /wp:shortcode -->
220 220
 				',
221
-					'parent'  => '',
222
-				),
221
+                    'parent'  => '',
222
+                ),
223 223
 
224
-			)
225
-		);
224
+            )
225
+        );
226 226
 
227
-	}
227
+    }
228 228
 
229
-	/**
230
-	 * Re-create GetPaid pages.
231
-	 *
232
-	 */
233
-	public function create_pages() {
229
+    /**
230
+     * Re-create GetPaid pages.
231
+     *
232
+     */
233
+    public function create_pages() {
234 234
 
235
-		foreach ( self::get_pages() as $key => $page ) {
236
-			wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
237
-		}
235
+        foreach ( self::get_pages() as $key => $page ) {
236
+            wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
237
+        }
238 238
 
239
-	}
239
+    }
240 240
 
241
-	/**
242
-	 * Create subscriptions table.
243
-	 *
244
-	 */
245
-	public function create_subscriptions_table() {
241
+    /**
242
+     * Create subscriptions table.
243
+     *
244
+     */
245
+    public function create_subscriptions_table() {
246 246
 
247
-		global $wpdb;
247
+        global $wpdb;
248 248
 
249
-		require_once ABSPATH . 'wp-admin/includes/upgrade.php';
249
+        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
250 250
 
251
-		// Create tables.
252
-		$charset_collate = $wpdb->get_charset_collate();
253
-		$sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions (
251
+        // Create tables.
252
+        $charset_collate = $wpdb->get_charset_collate();
253
+        $sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions (
254 254
 			id bigint(20) unsigned NOT NULL auto_increment,
255 255
 			customer_id bigint(20) NOT NULL,
256 256
 			frequency int(11) NOT NULL DEFAULT '1',
@@ -273,22 +273,22 @@  discard block
 block discarded – undo
273 273
 			KEY customer_and_status (customer_id, status)
274 274
 		  ) $charset_collate;";
275 275
 
276
-		dbDelta( $sql );
276
+        dbDelta( $sql );
277 277
 
278
-	}
278
+    }
279 279
 
280
-	/**
281
-	 * Create invoices table.
282
-	 *
283
-	 */
284
-	public function create_invoices_table() {
285
-		global $wpdb;
280
+    /**
281
+     * Create invoices table.
282
+     *
283
+     */
284
+    public function create_invoices_table() {
285
+        global $wpdb;
286 286
 
287
-		require_once ABSPATH . 'wp-admin/includes/upgrade.php';
287
+        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
288 288
 
289
-		// Create tables.
290
-		$charset_collate = $wpdb->get_charset_collate();
291
-		$sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices (
289
+        // Create tables.
290
+        $charset_collate = $wpdb->get_charset_collate();
291
+        $sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices (
292 292
 			post_id BIGINT(20) NOT NULL,
293 293
             `number` VARCHAR(100),
294 294
             `key` VARCHAR(100),
@@ -324,22 +324,22 @@  discard block
 block discarded – undo
324 324
 			KEY `key` (`key`)
325 325
 		  ) $charset_collate;";
326 326
 
327
-		dbDelta( $sql );
327
+        dbDelta( $sql );
328 328
 
329
-	}
329
+    }
330 330
 
331
-	/**
332
-	 * Create invoice items table.
333
-	 *
334
-	 */
335
-	public function create_invoice_items_table() {
336
-		global $wpdb;
331
+    /**
332
+     * Create invoice items table.
333
+     *
334
+     */
335
+    public function create_invoice_items_table() {
336
+        global $wpdb;
337 337
 
338
-		require_once ABSPATH . 'wp-admin/includes/upgrade.php';
338
+        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
339 339
 
340
-		// Create tables.
341
-		$charset_collate = $wpdb->get_charset_collate();
342
-		$sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items (
340
+        // Create tables.
341
+        $charset_collate = $wpdb->get_charset_collate();
342
+        $sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items (
343 343
 			ID BIGINT(20) NOT NULL AUTO_INCREMENT,
344 344
             post_id BIGINT(20) NOT NULL,
345 345
             item_id BIGINT(20) NOT NULL,
@@ -361,159 +361,159 @@  discard block
 block discarded – undo
361 361
 			KEY post_id (post_id)
362 362
 		  ) $charset_collate;";
363 363
 
364
-		dbDelta( $sql );
365
-
366
-	}
367
-
368
-	/**
369
-	 * Migrates old invoices to new invoices.
370
-	 *
371
-	 */
372
-	public function migrate_old_invoices() {
373
-		global $wpdb;
374
-
375
-		$invoices_table      = $wpdb->prefix . 'getpaid_invoices';
376
-		$invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
377
-		$migrated            = $wpdb->get_col( "SELECT post_id FROM $invoices_table" );
378
-		$invoices            = array_unique(
379
-			get_posts(
380
-				array(
381
-					'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
382
-					'posts_per_page' => -1,
383
-					'fields'         => 'ids',
384
-					'post_status'    => array_keys( get_post_stati() ),
385
-					'exclude'        => (array) $migrated,
386
-				)
387
-			)
388
-		);
389
-
390
-		// Abort if we do not have any invoices.
391
-		if ( empty( $invoices ) ) {
392
-			return;
393
-		}
394
-
395
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php';
396
-
397
-		$invoice_rows = array();
398
-		foreach ( $invoices as $invoice ) {
399
-
400
-			$invoice = new WPInv_Legacy_Invoice( $invoice );
401
-
402
-			if ( empty( $invoice->ID ) ) {
403
-				return;
404
-			}
405
-
406
-			$fields = array(
407
-				'post_id'            => $invoice->ID,
408
-				'number'             => $invoice->get_number(),
409
-				'key'                => $invoice->get_key(),
410
-				'type'               => str_replace( 'wpi_', '', $invoice->post_type ),
411
-				'mode'               => $invoice->mode,
412
-				'user_ip'            => $invoice->get_ip(),
413
-				'first_name'         => $invoice->get_first_name(),
414
-				'last_name'          => $invoice->get_last_name(),
415
-				'address'            => $invoice->get_address(),
416
-				'city'               => $invoice->city,
417
-				'state'              => $invoice->state,
418
-				'country'            => $invoice->country,
419
-				'zip'                => $invoice->zip,
420
-				'adddress_confirmed' => (int) $invoice->adddress_confirmed,
421
-				'gateway'            => $invoice->get_gateway(),
422
-				'transaction_id'     => $invoice->get_transaction_id(),
423
-				'currency'           => $invoice->get_currency(),
424
-				'subtotal'           => $invoice->get_subtotal(),
425
-				'tax'                => $invoice->get_tax(),
426
-				'fees_total'         => $invoice->get_fees_total(),
427
-				'total'              => $invoice->get_total(),
428
-				'discount'           => $invoice->get_discount(),
429
-				'discount_code'      => $invoice->get_discount_code(),
430
-				'disable_taxes'      => $invoice->disable_taxes,
431
-				'due_date'           => $invoice->get_due_date(),
432
-				'completed_date'     => $invoice->get_completed_date(),
433
-				'company'            => $invoice->company,
434
-				'vat_number'         => $invoice->vat_number,
435
-				'vat_rate'           => $invoice->vat_rate,
436
-				'custom_meta'        => $invoice->payment_meta,
437
-			);
438
-
439
-			foreach ( $fields as $key => $val ) {
440
-				if ( is_null( $val ) ) {
441
-					$val = '';
442
-				}
443
-				$val = maybe_serialize( $val );
444
-				$fields[ $key ] = $wpdb->prepare( '%s', $val );
445
-			}
446
-
447
-			$fields = implode( ', ', $fields );
448
-			$invoice_rows[] = "($fields)";
449
-
450
-			$item_rows    = array();
451
-			$item_columns = array();
452
-			foreach ( $invoice->get_cart_details() as $details ) {
453
-				$fields = array(
454
-					'post_id'          => $invoice->ID,
455
-					'item_id'          => $details['id'],
456
-					'item_name'        => $details['name'],
457
-					'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
458
-					'vat_rate'         => $details['vat_rate'],
459
-					'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
460
-					'tax'              => $details['tax'],
461
-					'item_price'       => $details['item_price'],
462
-					'custom_price'     => $details['custom_price'],
463
-					'quantity'         => $details['quantity'],
464
-					'discount'         => $details['discount'],
465
-					'subtotal'         => $details['subtotal'],
466
-					'price'            => $details['price'],
467
-					'meta'             => $details['meta'],
468
-					'fees'             => $details['fees'],
469
-				);
470
-
471
-				$item_columns = array_keys( $fields );
472
-
473
-				foreach ( $fields as $key => $val ) {
474
-					if ( is_null( $val ) ) {
475
-						$val = '';
476
-					}
477
-					$val = maybe_serialize( $val );
478
-					$fields[ $key ] = $wpdb->prepare( '%s', $val );
479
-				}
480
-
481
-				$fields = implode( ', ', $fields );
482
-				$item_rows[] = "($fields)";
483
-			}
484
-
485
-			$item_rows    = implode( ', ', $item_rows );
486
-			$item_columns = implode( ', ', $item_columns );
487
-			$wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
488
-		}
489
-
490
-		if ( empty( $invoice_rows ) ) {
491
-			return;
492
-		}
493
-
494
-		$invoice_rows = implode( ', ', $invoice_rows );
495
-		$wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
496
-
497
-	}
498
-
499
-	/**
500
-	 * Migrates old invoices to new invoices.
501
-	 *
502
-	 */
503
-	public static function rename_gateways_label() {
504
-		global $wpdb;
505
-
506
-		foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) {
507
-
508
-			$wpdb->update(
509
-				$wpdb->prefix . 'getpaid_invoices',
510
-				array( 'gateway' => $gateway ),
511
-				array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ),
512
-				'%s',
513
-				'%s'
514
-			);
515
-
516
-		}
517
-	}
364
+        dbDelta( $sql );
365
+
366
+    }
367
+
368
+    /**
369
+     * Migrates old invoices to new invoices.
370
+     *
371
+     */
372
+    public function migrate_old_invoices() {
373
+        global $wpdb;
374
+
375
+        $invoices_table      = $wpdb->prefix . 'getpaid_invoices';
376
+        $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
377
+        $migrated            = $wpdb->get_col( "SELECT post_id FROM $invoices_table" );
378
+        $invoices            = array_unique(
379
+            get_posts(
380
+                array(
381
+                    'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
382
+                    'posts_per_page' => -1,
383
+                    'fields'         => 'ids',
384
+                    'post_status'    => array_keys( get_post_stati() ),
385
+                    'exclude'        => (array) $migrated,
386
+                )
387
+            )
388
+        );
389
+
390
+        // Abort if we do not have any invoices.
391
+        if ( empty( $invoices ) ) {
392
+            return;
393
+        }
394
+
395
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php';
396
+
397
+        $invoice_rows = array();
398
+        foreach ( $invoices as $invoice ) {
399
+
400
+            $invoice = new WPInv_Legacy_Invoice( $invoice );
401
+
402
+            if ( empty( $invoice->ID ) ) {
403
+                return;
404
+            }
405
+
406
+            $fields = array(
407
+                'post_id'            => $invoice->ID,
408
+                'number'             => $invoice->get_number(),
409
+                'key'                => $invoice->get_key(),
410
+                'type'               => str_replace( 'wpi_', '', $invoice->post_type ),
411
+                'mode'               => $invoice->mode,
412
+                'user_ip'            => $invoice->get_ip(),
413
+                'first_name'         => $invoice->get_first_name(),
414
+                'last_name'          => $invoice->get_last_name(),
415
+                'address'            => $invoice->get_address(),
416
+                'city'               => $invoice->city,
417
+                'state'              => $invoice->state,
418
+                'country'            => $invoice->country,
419
+                'zip'                => $invoice->zip,
420
+                'adddress_confirmed' => (int) $invoice->adddress_confirmed,
421
+                'gateway'            => $invoice->get_gateway(),
422
+                'transaction_id'     => $invoice->get_transaction_id(),
423
+                'currency'           => $invoice->get_currency(),
424
+                'subtotal'           => $invoice->get_subtotal(),
425
+                'tax'                => $invoice->get_tax(),
426
+                'fees_total'         => $invoice->get_fees_total(),
427
+                'total'              => $invoice->get_total(),
428
+                'discount'           => $invoice->get_discount(),
429
+                'discount_code'      => $invoice->get_discount_code(),
430
+                'disable_taxes'      => $invoice->disable_taxes,
431
+                'due_date'           => $invoice->get_due_date(),
432
+                'completed_date'     => $invoice->get_completed_date(),
433
+                'company'            => $invoice->company,
434
+                'vat_number'         => $invoice->vat_number,
435
+                'vat_rate'           => $invoice->vat_rate,
436
+                'custom_meta'        => $invoice->payment_meta,
437
+            );
438
+
439
+            foreach ( $fields as $key => $val ) {
440
+                if ( is_null( $val ) ) {
441
+                    $val = '';
442
+                }
443
+                $val = maybe_serialize( $val );
444
+                $fields[ $key ] = $wpdb->prepare( '%s', $val );
445
+            }
446
+
447
+            $fields = implode( ', ', $fields );
448
+            $invoice_rows[] = "($fields)";
449
+
450
+            $item_rows    = array();
451
+            $item_columns = array();
452
+            foreach ( $invoice->get_cart_details() as $details ) {
453
+                $fields = array(
454
+                    'post_id'          => $invoice->ID,
455
+                    'item_id'          => $details['id'],
456
+                    'item_name'        => $details['name'],
457
+                    'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
458
+                    'vat_rate'         => $details['vat_rate'],
459
+                    'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
460
+                    'tax'              => $details['tax'],
461
+                    'item_price'       => $details['item_price'],
462
+                    'custom_price'     => $details['custom_price'],
463
+                    'quantity'         => $details['quantity'],
464
+                    'discount'         => $details['discount'],
465
+                    'subtotal'         => $details['subtotal'],
466
+                    'price'            => $details['price'],
467
+                    'meta'             => $details['meta'],
468
+                    'fees'             => $details['fees'],
469
+                );
470
+
471
+                $item_columns = array_keys( $fields );
472
+
473
+                foreach ( $fields as $key => $val ) {
474
+                    if ( is_null( $val ) ) {
475
+                        $val = '';
476
+                    }
477
+                    $val = maybe_serialize( $val );
478
+                    $fields[ $key ] = $wpdb->prepare( '%s', $val );
479
+                }
480
+
481
+                $fields = implode( ', ', $fields );
482
+                $item_rows[] = "($fields)";
483
+            }
484
+
485
+            $item_rows    = implode( ', ', $item_rows );
486
+            $item_columns = implode( ', ', $item_columns );
487
+            $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
488
+        }
489
+
490
+        if ( empty( $invoice_rows ) ) {
491
+            return;
492
+        }
493
+
494
+        $invoice_rows = implode( ', ', $invoice_rows );
495
+        $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
496
+
497
+    }
498
+
499
+    /**
500
+     * Migrates old invoices to new invoices.
501
+     *
502
+     */
503
+    public static function rename_gateways_label() {
504
+        global $wpdb;
505
+
506
+        foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) {
507
+
508
+            $wpdb->update(
509
+                $wpdb->prefix . 'getpaid_invoices',
510
+                array( 'gateway' => $gateway ),
511
+                array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ),
512
+                '%s',
513
+                '%s'
514
+            );
515
+
516
+        }
517
+    }
518 518
 
519 519
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-admin.php 1 patch
Indentation   +600 added lines, -600 removed lines patch added patch discarded remove patch
@@ -14,92 +14,92 @@  discard block
 block discarded – undo
14 14
 class GetPaid_Admin {
15 15
 
16 16
     /**
17
-	 * Local path to this plugins admin directory
18
-	 *
19
-	 * @var         string
20
-	 */
21
-	public $admin_path;
22
-
23
-	/**
24
-	 * Web path to this plugins admin directory
25
-	 *
26
-	 * @var         string
27
-	 */
28
-	public $admin_url;
29
-
30
-	/**
31
-	 * Reports components.
32
-	 *
33
-	 * @var GetPaid_Reports
34
-	 */
17
+     * Local path to this plugins admin directory
18
+     *
19
+     * @var         string
20
+     */
21
+    public $admin_path;
22
+
23
+    /**
24
+     * Web path to this plugins admin directory
25
+     *
26
+     * @var         string
27
+     */
28
+    public $admin_url;
29
+
30
+    /**
31
+     * Reports components.
32
+     *
33
+     * @var GetPaid_Reports
34
+     */
35 35
     public $reports;
36 36
 
37 37
     /**
38
-	 * Class constructor.
39
-	 */
40
-	public function __construct() {
38
+     * Class constructor.
39
+     */
40
+    public function __construct() {
41 41
 
42 42
         $this->admin_path  = plugin_dir_path( __FILE__ );
43
-		$this->admin_url   = plugins_url( '/', __FILE__ );
44
-		$this->reports     = new GetPaid_Reports();
43
+        $this->admin_url   = plugins_url( '/', __FILE__ );
44
+        $this->reports     = new GetPaid_Reports();
45 45
 
46 46
         if ( is_admin() ) {
47
-			$this->init_admin_hooks();
47
+            $this->init_admin_hooks();
48 48
         }
49 49
 
50 50
     }
51 51
 
52 52
     /**
53
-	 * Init action and filter hooks
54
-	 *
55
-	 */
56
-	private function init_admin_hooks() {
53
+     * Init action and filter hooks
54
+     *
55
+     */
56
+    private function init_admin_hooks() {
57 57
         add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ), 9 );
58 58
         add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
59 59
         add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
60 60
         add_action( 'admin_init', array( $this, 'activation_redirect' ) );
61 61
         add_action( 'admin_init', array( $this, 'maybe_do_admin_action' ) );
62
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
-		add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
-		add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) );
65
-		add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) );
66
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
67
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
62
+        add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
+        add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
+        add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) );
65
+        add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) );
66
+        add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
67
+        add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
68 68
         add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) );
69
-		add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) );
70
-		add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) );
71
-		add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) );
72
-		add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) );
73
-		add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) );
74
-		add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) );
75
-		add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) );
76
-		add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) );
77
-		add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
78
-		do_action( 'getpaid_init_admin_hooks', $this );
79
-
80
-		// Setup/welcome
81
-		if ( ! empty( $_GET['page'] ) ) {
82
-			switch ( sanitize_text_field( $_GET['page'] ) ) {
83
-				case 'gp-setup':
84
-					include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php';
85
-					break;
86
-			}
87
-		}
88
-
89
-    }
90
-
91
-    /**
92
-	 * Register admin scripts
93
-	 *
94
-	 */
95
-	public function enqeue_scripts() {
69
+        add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) );
70
+        add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) );
71
+        add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) );
72
+        add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) );
73
+        add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) );
74
+        add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) );
75
+        add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) );
76
+        add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) );
77
+        add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
78
+        do_action( 'getpaid_init_admin_hooks', $this );
79
+
80
+        // Setup/welcome
81
+        if ( ! empty( $_GET['page'] ) ) {
82
+            switch ( sanitize_text_field( $_GET['page'] ) ) {
83
+                case 'gp-setup':
84
+                    include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php';
85
+                    break;
86
+            }
87
+        }
88
+
89
+    }
90
+
91
+    /**
92
+     * Register admin scripts
93
+     *
94
+     */
95
+    public function enqeue_scripts() {
96 96
         global $current_screen, $pagenow;
97 97
 
98
-		$page    = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
99
-		$editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
98
+        $page    = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
99
+        $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
100 100
 
101 101
         if ( ! empty( $current_screen->post_type ) ) {
102
-			$page = $current_screen->post_type;
102
+            $page = $current_screen->post_type;
103 103
         }
104 104
 
105 105
         // General styles.
@@ -120,53 +120,53 @@  discard block
 block discarded – undo
120 120
         }
121 121
 
122 122
         // Payment form scripts.
123
-		if ( 'wpi_payment_form' == $page && $editing ) {
123
+        if ( 'wpi_payment_form' == $page && $editing ) {
124 124
             $this->load_payment_form_scripts();
125 125
         }
126 126
 
127
-		if ( $page == 'wpinv-subscriptions' ) {
128
-			wp_enqueue_script( 'postbox' );
129
-		}
127
+        if ( $page == 'wpinv-subscriptions' ) {
128
+            wp_enqueue_script( 'postbox' );
129
+        }
130 130
 
131 131
     }
132 132
 
133 133
     /**
134
-	 * Returns admin js translations.
135
-	 *
136
-	 */
137
-	protected function get_admin_i18() {
134
+     * Returns admin js translations.
135
+     *
136
+     */
137
+    protected function get_admin_i18() {
138 138
         global $post;
139 139
 
140
-		$date_range = array(
141
-			'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days',
142
-		);
140
+        $date_range = array(
141
+            'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days',
142
+        );
143 143
 
144
-		if ( $date_range['period'] == 'custom' ) {
144
+        if ( $date_range['period'] == 'custom' ) {
145 145
 
146
-			if ( isset( $_GET['from'] ) ) {
147
-				$date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
148
-			}
146
+            if ( isset( $_GET['from'] ) ) {
147
+                $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
148
+            }
149 149
 
150
-			if ( isset( $_GET['to'] ) ) {
151
-				$date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
152
-			}
150
+            if ( isset( $_GET['to'] ) ) {
151
+                $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
152
+            }
153 153
 }
154 154
 
155 155
         $i18n = array(
156 156
             'ajax_url'                  => admin_url( 'admin-ajax.php' ),
157 157
             'post_ID'                   => isset( $post->ID ) ? $post->ID : '',
158
-			'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
159
-			'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
160
-			'rest_root'                 => esc_url_raw( rest_url() ),
161
-			'date_range'                => $date_range,
158
+            'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
159
+            'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
160
+            'rest_root'                 => esc_url_raw( rest_url() ),
161
+            'date_range'                => $date_range,
162 162
             'add_invoice_note_nonce'    => wp_create_nonce( 'add-invoice-note' ),
163 163
             'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ),
164 164
             'invoice_item_nonce'        => wp_create_nonce( 'invoice-item' ),
165 165
             'billing_details_nonce'     => wp_create_nonce( 'get-billing-details' ),
166 166
             'tax'                       => wpinv_tax_amount(),
167 167
             'discount'                  => 0,
168
-			'currency_symbol'           => wpinv_currency_symbol(),
169
-			'currency'                  => wpinv_get_currency(),
168
+            'currency_symbol'           => wpinv_currency_symbol(),
169
+            'currency'                  => wpinv_get_currency(),
170 170
             'currency_pos'              => wpinv_currency_position(),
171 171
             'thousand_sep'              => wpinv_thousands_separator(),
172 172
             'decimal_sep'               => wpinv_decimal_separator(),
@@ -186,118 +186,118 @@  discard block
 block discarded – undo
186 186
             'item_description'          => __( 'Item Description', 'invoicing' ),
187 187
             'invoice_description'       => __( 'Invoice Description', 'invoicing' ),
188 188
             'discount_description'      => __( 'Discount Description', 'invoicing' ),
189
-			'searching'                 => __( 'Searching', 'invoicing' ),
190
-			'loading'                   => __( 'Loading...', 'invoicing' ),
191
-			'search_customers'          => __( 'Enter customer name or email', 'invoicing' ),
192
-			'search_items'              => __( 'Enter item name', 'invoicing' ),
193
-			'graphs'                    => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ),
189
+            'searching'                 => __( 'Searching', 'invoicing' ),
190
+            'loading'                   => __( 'Loading...', 'invoicing' ),
191
+            'search_customers'          => __( 'Enter customer name or email', 'invoicing' ),
192
+            'search_items'              => __( 'Enter item name', 'invoicing' ),
193
+            'graphs'                    => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ),
194 194
         );
195 195
 
196
-		if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
196
+        if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
197 197
 
198
-			$invoice              = new WPInv_Invoice( $post );
199
-			$i18n['save_invoice'] = sprintf(
200
-				__( 'Save %s', 'invoicing' ),
201
-				ucfirst( $invoice->get_invoice_quote_type() )
202
-			);
198
+            $invoice              = new WPInv_Invoice( $post );
199
+            $i18n['save_invoice'] = sprintf(
200
+                __( 'Save %s', 'invoicing' ),
201
+                ucfirst( $invoice->get_invoice_quote_type() )
202
+            );
203 203
 
204
-			$i18n['invoice_description'] = sprintf(
205
-				__( '%s Description', 'invoicing' ),
206
-				ucfirst( $invoice->get_invoice_quote_type() )
207
-			);
204
+            $i18n['invoice_description'] = sprintf(
205
+                __( '%s Description', 'invoicing' ),
206
+                ucfirst( $invoice->get_invoice_quote_type() )
207
+            );
208 208
 
209
-		}
210
-		return $i18n;
211
-	}
209
+        }
210
+        return $i18n;
211
+    }
212 212
 
213
-	/**
214
-	 * Change the admin footer text on GetPaid admin pages.
215
-	 *
216
-	 * @since  2.0.0
217
-	 * @param  string $footer_text
218
-	 * @return string
219
-	 */
220
-	public function admin_footer_text( $footer_text ) {
221
-		global $current_screen;
213
+    /**
214
+     * Change the admin footer text on GetPaid admin pages.
215
+     *
216
+     * @since  2.0.0
217
+     * @param  string $footer_text
218
+     * @return string
219
+     */
220
+    public function admin_footer_text( $footer_text ) {
221
+        global $current_screen;
222 222
 
223
-		$page    = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
223
+        $page    = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
224 224
 
225 225
         if ( ! empty( $current_screen->post_type ) ) {
226
-			$page = $current_screen->post_type;
226
+            $page = $current_screen->post_type;
227 227
         }
228 228
 
229 229
         // General styles.
230 230
         if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) {
231 231
 
232
-			// Change the footer text
233
-			if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
232
+            // Change the footer text
233
+            if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
234 234
 
235
-				$rating_url  = esc_url(
236
-					wp_nonce_url(
237
-						admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
238
-						'getpaid-nonce',
239
-						'getpaid-nonce'
235
+                $rating_url  = esc_url(
236
+                    wp_nonce_url(
237
+                        admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
238
+                        'getpaid-nonce',
239
+                        'getpaid-nonce'
240 240
                     )
241
-				);
241
+                );
242 242
 
243
-				$footer_text = sprintf(
244
-					/* translators: %s: five stars */
245
-					__( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
246
-					"<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
247
-				);
243
+                $footer_text = sprintf(
244
+                    /* translators: %s: five stars */
245
+                    __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
246
+                    "<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
247
+                );
248 248
 
249
-			} else {
249
+            } else {
250 250
 
251
-				$footer_text = sprintf(
252
-					/* translators: %s: GetPaid */
253
-					__( 'Thank you for using %s!', 'invoicing' ),
254
-					"<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
255
-				);
251
+                $footer_text = sprintf(
252
+                    /* translators: %s: GetPaid */
253
+                    __( 'Thank you for using %s!', 'invoicing' ),
254
+                    "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
255
+                );
256 256
 
257
-			}
257
+            }
258 258
 }
259 259
 
260
-		return $footer_text;
261
-	}
262
-
263
-	/**
264
-	 * Redirects to wp.org to rate the plugin.
265
-	 *
266
-	 * @since  2.0.0
267
-	 */
268
-	public function redirect_to_wordpress_rating_page() {
269
-		update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
270
-		wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
271
-		exit;
272
-	}
273
-
274
-    /**
275
-	 * Loads payment form js.
276
-	 *
277
-	 */
278
-	protected function load_payment_form_scripts() {
260
+        return $footer_text;
261
+    }
262
+
263
+    /**
264
+     * Redirects to wp.org to rate the plugin.
265
+     *
266
+     * @since  2.0.0
267
+     */
268
+    public function redirect_to_wordpress_rating_page() {
269
+        update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
270
+        wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
271
+        exit;
272
+    }
273
+
274
+    /**
275
+     * Loads payment form js.
276
+     *
277
+     */
278
+    protected function load_payment_form_scripts() {
279 279
         global $post;
280 280
 
281 281
         wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION );
282
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
283
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
282
+        wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
283
+        wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
284 284
 
285
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
286
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version );
285
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
286
+        wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version );
287 287
 
288
-		wp_localize_script(
288
+        wp_localize_script(
289 289
             'wpinv-admin-payment-form-script',
290 290
             'wpinvPaymentFormAdmin',
291 291
             array(
292
-				'elements'      => wpinv_get_data( 'payment-form-elements' ),
293
-				'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
294
-				'currency'      => wpinv_currency_symbol(),
295
-				'position'      => wpinv_currency_position(),
296
-				'decimals'      => (int) wpinv_decimals(),
297
-				'thousands_sep' => wpinv_thousands_separator(),
298
-				'decimals_sep'  => wpinv_decimal_separator(),
299
-				'form_items'    => gepaid_get_form_items( $post->ID ),
300
-				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
292
+                'elements'      => wpinv_get_data( 'payment-form-elements' ),
293
+                'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
294
+                'currency'      => wpinv_currency_symbol(),
295
+                'position'      => wpinv_currency_position(),
296
+                'decimals'      => (int) wpinv_decimals(),
297
+                'thousands_sep' => wpinv_thousands_separator(),
298
+                'decimals_sep'  => wpinv_decimal_separator(),
299
+                'form_items'    => gepaid_get_form_items( $post->ID ),
300
+                'is_default'    => $post->ID == wpinv_get_default_payment_form(),
301 301
             )
302 302
         );
303 303
 
@@ -306,19 +306,19 @@  discard block
 block discarded – undo
306 306
     }
307 307
 
308 308
     /**
309
-	 * Add our classes to admin pages.
309
+     * Add our classes to admin pages.
310 310
      *
311 311
      * @param string $classes
312 312
      * @return string
313
-	 *
314
-	 */
313
+     *
314
+     */
315 315
     public function admin_body_class( $classes ) {
316
-		global $pagenow, $post, $current_screen;
316
+        global $pagenow, $post, $current_screen;
317 317
 
318 318
         $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
319 319
 
320 320
         if ( ! empty( $current_screen->post_type ) ) {
321
-			$page = $current_screen->post_type;
321
+            $page = $current_screen->post_type;
322 322
         }
323 323
 
324 324
         if ( false !== stripos( $page, 'wpi' ) ) {
@@ -327,70 +327,70 @@  discard block
 block discarded – undo
327 327
 
328 328
         if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
329 329
             $classes .= ' wpinv-cpt wpinv';
330
-		}
330
+        }
331 331
 
332
-		if ( getpaid_is_invoice_post_type( $page ) ) {
332
+        if ( getpaid_is_invoice_post_type( $page ) ) {
333 333
             $classes .= ' getpaid-is-invoice-cpt';
334 334
         }
335 335
 
336
-		return $classes;
336
+        return $classes;
337 337
     }
338 338
 
339 339
     /**
340
-	 * Maybe show the AyeCode Connect Notice.
341
-	 */
342
-	public function init_ayecode_connect_helper() {
340
+     * Maybe show the AyeCode Connect Notice.
341
+     */
342
+    public function init_ayecode_connect_helper() {
343 343
 
344
-		// Register with the deactivation survey class.
345
-		AyeCode_Deactivation_Survey::instance(
344
+        // Register with the deactivation survey class.
345
+        AyeCode_Deactivation_Survey::instance(
346 346
             array(
347
-				'slug'              => 'invoicing',
348
-				'version'           => WPINV_VERSION,
349
-				'support_url'       => 'https://wpgetpaid.com/support/',
350
-				'documentation_url' => 'https://docs.wpgetpaid.com/',
351
-				'activated'         => (int) get_option( 'gepaid_installed_on' ),
347
+                'slug'              => 'invoicing',
348
+                'version'           => WPINV_VERSION,
349
+                'support_url'       => 'https://wpgetpaid.com/support/',
350
+                'documentation_url' => 'https://docs.wpgetpaid.com/',
351
+                'activated'         => (int) get_option( 'gepaid_installed_on' ),
352 352
             )
353 353
         );
354 354
 
355 355
         new AyeCode_Connect_Helper(
356 356
             array(
357
-				'connect_title'     => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ),
358
-				'connect_external'  => __( 'Please confirm you wish to connect your site?', 'invoicing' ),
359
-				'connect'           => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ),
360
-				'connect_button'    => __( 'Connect Site', 'invoicing' ),
361
-				'connecting_button' => __( 'Connecting...', 'invoicing' ),
362
-				'error_localhost'   => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ),
363
-				'error'             => __( 'Something went wrong, please refresh and try again.', 'invoicing' ),
357
+                'connect_title'     => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ),
358
+                'connect_external'  => __( 'Please confirm you wish to connect your site?', 'invoicing' ),
359
+                'connect'           => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ),
360
+                'connect_button'    => __( 'Connect Site', 'invoicing' ),
361
+                'connecting_button' => __( 'Connecting...', 'invoicing' ),
362
+                'error_localhost'   => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ),
363
+                'error'             => __( 'Something went wrong, please refresh and try again.', 'invoicing' ),
364 364
             ),
365 365
             array( 'wpi-addons' )
366 366
         );
367 367
 
368 368
     }
369 369
 
370
-	/**
371
-	 * Redirect users to settings on activation.
372
-	 *
373
-	 * @return void
374
-	 */
375
-	public function activation_redirect() {
370
+    /**
371
+     * Redirect users to settings on activation.
372
+     *
373
+     * @return void
374
+     */
375
+    public function activation_redirect() {
376 376
 
377
-		$redirected = get_option( 'wpinv_redirected_to_settings' );
377
+        $redirected = get_option( 'wpinv_redirected_to_settings' );
378 378
 
379
-		if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
380
-			return;
381
-		}
379
+        if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
380
+            return;
381
+        }
382 382
 
383
-		// Bail if activating from network, or bulk
384
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
385
-			return;
386
-		}
383
+        // Bail if activating from network, or bulk
384
+        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
385
+            return;
386
+        }
387 387
 
388
-	    update_option( 'wpinv_redirected_to_settings', 1 );
388
+        update_option( 'wpinv_redirected_to_settings', 1 );
389 389
 
390 390
         wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) );
391 391
         exit;
392 392
 
393
-	}
393
+    }
394 394
 
395 395
     /**
396 396
      * Fires an admin action after verifying that a user can fire them.
@@ -404,535 +404,535 @@  discard block
 block discarded – undo
404 404
 
405 405
     }
406 406
 
407
-	/**
407
+    /**
408 408
      * Duplicate invoice.
409
-	 *
410
-	 * @param array $args
409
+     *
410
+     * @param array $args
411 411
      */
412 412
     public function duplicate_invoice( $args ) {
413 413
 
414
-		if ( empty( $args['invoice_id'] ) ) {
415
-			return;
416
-		}
414
+        if ( empty( $args['invoice_id'] ) ) {
415
+            return;
416
+        }
417 417
 
418
-		$invoice = new WPInv_Invoice( (int) $args['invoice_id'] );
418
+        $invoice = new WPInv_Invoice( (int) $args['invoice_id'] );
419 419
 
420
-		if ( ! $invoice->exists() ) {
421
-			return;
422
-		}
420
+        if ( ! $invoice->exists() ) {
421
+            return;
422
+        }
423 423
 
424
-		$new_invoice = getpaid_duplicate_invoice( $invoice );
425
-		$new_invoice->save();
424
+        $new_invoice = getpaid_duplicate_invoice( $invoice );
425
+        $new_invoice->save();
426 426
 
427
-		if ( $new_invoice->exists() ) {
427
+        if ( $new_invoice->exists() ) {
428 428
 
429
-			getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'newsletter-optin-box' ) );
429
+            getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'newsletter-optin-box' ) );
430 430
 
431
-			wp_safe_redirect(
432
-				add_query_arg(
433
-					array(
434
-						'action' => 'edit',
435
-						'post'   => $new_invoice->get_id(),
436
-					),
437
-					admin_url( 'post.php' )
438
-				)
439
-			);
440
-			exit;
431
+            wp_safe_redirect(
432
+                add_query_arg(
433
+                    array(
434
+                        'action' => 'edit',
435
+                        'post'   => $new_invoice->get_id(),
436
+                    ),
437
+                    admin_url( 'post.php' )
438
+                )
439
+            );
440
+            exit;
441 441
 
442
-		}
442
+        }
443 443
 
444
-		getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'newsletter-optin-box' ) );
444
+        getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'newsletter-optin-box' ) );
445 445
 
446
-	}
446
+    }
447 447
 
448
-	/**
448
+    /**
449 449
      * Sends a payment reminder to a customer.
450
-	 *
451
-	 * @param array $args
450
+     *
451
+     * @param array $args
452 452
      */
453 453
     public function duplicate_payment_form( $args ) {
454 454
 
455
-		if ( empty( $args['form_id'] ) ) {
456
-			return;
457
-		}
458
-
459
-		$form = new GetPaid_Payment_Form( (int) $args['form_id'] );
455
+        if ( empty( $args['form_id'] ) ) {
456
+            return;
457
+        }
460 458
 
461
-		if ( ! $form->exists() ) {
462
-			return;
463
-		}
459
+        $form = new GetPaid_Payment_Form( (int) $args['form_id'] );
464 460
 
465
-		$new_form = new GetPaid_Payment_Form();
466
-		$new_form->set_author( $form->get_author( 'edit' ) );
467
-		$new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) );
468
-		$new_form->set_elements( $form->get_elements( 'edit' ) );
469
-		$new_form->set_items( $form->get_items( 'edit' ) );
470
-		$new_form->save();
461
+        if ( ! $form->exists() ) {
462
+            return;
463
+        }
471 464
 
472
-		if ( $new_form->exists() ) {
473
-			$this->show_success( __( 'Form duplicated successfully', 'invoicing' ) );
474
-			$url = get_edit_post_link( $new_form->get_id(), 'edit' );
475
-		} else {
476
-			$this->show_error( __( 'Unable to duplicate form', 'invoicing' ) );
477
-			$url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) );
478
-		}
465
+        $new_form = new GetPaid_Payment_Form();
466
+        $new_form->set_author( $form->get_author( 'edit' ) );
467
+        $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) );
468
+        $new_form->set_elements( $form->get_elements( 'edit' ) );
469
+        $new_form->set_items( $form->get_items( 'edit' ) );
470
+        $new_form->save();
471
+
472
+        if ( $new_form->exists() ) {
473
+            $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) );
474
+            $url = get_edit_post_link( $new_form->get_id(), 'edit' );
475
+        } else {
476
+            $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) );
477
+            $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) );
478
+        }
479 479
 
480
-		wp_redirect( $url );
481
-		exit;
482
-	}
480
+        wp_redirect( $url );
481
+        exit;
482
+    }
483 483
 
484
-	/**
484
+    /**
485 485
      * Sends a payment reminder to a customer.
486
-	 *
487
-	 * @param array $args
486
+     *
487
+     * @param array $args
488 488
      */
489 489
     public function send_customer_invoice( $args ) {
490
-		getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true );
491
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
492
-		exit;
493
-	}
490
+        getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true );
491
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
492
+        exit;
493
+    }
494 494
 
495
-	/**
495
+    /**
496 496
      * Sends a payment reminder to a customer.
497
-	 *
498
-	 * @param array $args
497
+     *
498
+     * @param array $args
499 499
      */
500 500
     public function send_customer_payment_reminder( $args ) {
501
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
501
+        $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
502 502
 
503
-		if ( $sent ) {
504
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
505
-		} else {
506
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
507
-		}
503
+        if ( $sent ) {
504
+            $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
505
+        } else {
506
+            $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
507
+        }
508 508
 
509
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
510
-		exit;
511
-	}
509
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
510
+        exit;
511
+    }
512 512
 
513
-	/**
513
+    /**
514 514
      * Resets tax rates.
515
-	 *
515
+     *
516 516
      */
517 517
     public function admin_reset_tax_rates() {
518 518
 
519
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
520
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
521
-		exit;
519
+        update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
520
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
521
+        exit;
522 522
 
523
-	}
523
+    }
524 524
 
525
-	/**
525
+    /**
526 526
      * Resets admin pages.
527
-	 *
527
+     *
528 528
      */
529 529
     public function admin_create_missing_pages() {
530
-		$installer = new GetPaid_Installer();
531
-		$installer->create_pages();
532
-		$this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) );
533
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
534
-		exit;
535
-	}
536
-
537
-	/**
538
-	 * Refreshes the permalinks.
539
-	 */
540
-	public function admin_refresh_permalinks() {
541
-		flush_rewrite_rules();
542
-		$this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) );
543
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
544
-		exit;
545
-	}
546
-
547
-	/**
530
+        $installer = new GetPaid_Installer();
531
+        $installer->create_pages();
532
+        $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) );
533
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
534
+        exit;
535
+    }
536
+
537
+    /**
538
+     * Refreshes the permalinks.
539
+     */
540
+    public function admin_refresh_permalinks() {
541
+        flush_rewrite_rules();
542
+        $this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) );
543
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
544
+        exit;
545
+    }
546
+
547
+    /**
548 548
      * Creates an missing admin tables.
549
-	 *
549
+     *
550 550
      */
551 551
     public function admin_create_missing_tables() {
552
-		global $wpdb;
553
-		$installer = new GetPaid_Installer();
552
+        global $wpdb;
553
+        $installer = new GetPaid_Installer();
554 554
 
555
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) {
556
-			$installer->create_subscriptions_table();
555
+        if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) {
556
+            $installer->create_subscriptions_table();
557 557
 
558
-			if ( $wpdb->last_error !== '' ) {
559
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
560
-			}
561
-		}
558
+            if ( $wpdb->last_error !== '' ) {
559
+                $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
560
+            }
561
+        }
562 562
 
563
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) {
564
-			$installer->create_invoices_table();
563
+        if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) {
564
+            $installer->create_invoices_table();
565 565
 
566
-			if ( '' !== $wpdb->last_error ) {
567
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
568
-			}
569
-		}
566
+            if ( '' !== $wpdb->last_error ) {
567
+                $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
568
+            }
569
+        }
570 570
 
571
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) {
572
-			$installer->create_invoice_items_table();
571
+        if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) {
572
+            $installer->create_invoice_items_table();
573 573
 
574
-			if ( '' !== $wpdb->last_error ) {
575
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
576
-			}
577
-		}
574
+            if ( '' !== $wpdb->last_error ) {
575
+                $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
576
+            }
577
+        }
578 578
 
579
-		if ( ! $this->has_notices() ) {
580
-			$this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) );
581
-		}
579
+        if ( ! $this->has_notices() ) {
580
+            $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) );
581
+        }
582 582
 
583
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
584
-		exit;
585
-	}
583
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
584
+        exit;
585
+    }
586 586
 
587
-	/**
587
+    /**
588 588
      * Migrates old invoices to the new database tables.
589
-	 *
589
+     *
590 590
      */
591 591
     public function admin_migrate_old_invoices() {
592 592
 
593
-		// Migrate the invoices.
594
-		$installer = new GetPaid_Installer();
595
-		$installer->migrate_old_invoices();
593
+        // Migrate the invoices.
594
+        $installer = new GetPaid_Installer();
595
+        $installer->migrate_old_invoices();
596 596
 
597
-		// Show an admin message.
598
-		$this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) );
597
+        // Show an admin message.
598
+        $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) );
599 599
 
600
-		// Redirect the admin.
601
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
602
-		exit;
600
+        // Redirect the admin.
601
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
602
+        exit;
603 603
 
604
-	}
604
+    }
605 605
 
606
-	/**
606
+    /**
607 607
      * Download customers.
608
-	 *
608
+     *
609 609
      */
610 610
     public function admin_download_customers() {
611
-		global $wpdb;
612
-
613
-		$output = fopen( 'php://output', 'w' );
614
-
615
-		if ( false === $output ) {
616
-			wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 );
617
-		}
611
+        global $wpdb;
618 612
 
619
-		header( 'Content-Type:text/csv' );
620
-		header( 'Content-Disposition:attachment;filename=customers.csv' );
613
+        $output = fopen( 'php://output', 'w' );
621 614
 
622
-		$post_types = '';
615
+        if ( false === $output ) {
616
+            wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 );
617
+        }
623 618
 
624
-		foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
625
-			$post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type );
626
-		}
619
+        header( 'Content-Type:text/csv' );
620
+        header( 'Content-Disposition:attachment;filename=customers.csv' );
627 621
 
628
-		$post_types = rtrim( $post_types, ' OR' );
622
+        $post_types = '';
629 623
 
630
-		$customers = $wpdb->get_col( "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" );
624
+        foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
625
+            $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type );
626
+        }
631 627
 
632
-		$columns = array(
633
-			'name'       => __( 'Name', 'invoicing' ),
634
-			'email'      => __( 'Email', 'invoicing' ),
635
-			'country'    => __( 'Country', 'invoicing' ),
636
-			'state'      => __( 'State', 'invoicing' ),
637
-			'city'       => __( 'City', 'invoicing' ),
638
-			'zip'        => __( 'ZIP', 'invoicing' ),
639
-			'address'    => __( 'Address', 'invoicing' ),
640
-			'phone'      => __( 'Phone', 'invoicing' ),
641
-			'company'    => __( 'Company', 'invoicing' ),
642
-			'company_id' => __( 'Company ID', 'invoicing' ),
643
-			'invoices'   => __( 'Invoices', 'invoicing' ),
644
-			'total_raw'  => __( 'Total Spend', 'invoicing' ),
645
-			'signup'     => __( 'Date created', 'invoicing' ),
646
-		);
628
+        $post_types = rtrim( $post_types, ' OR' );
629
+
630
+        $customers = $wpdb->get_col( "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" );
631
+
632
+        $columns = array(
633
+            'name'       => __( 'Name', 'invoicing' ),
634
+            'email'      => __( 'Email', 'invoicing' ),
635
+            'country'    => __( 'Country', 'invoicing' ),
636
+            'state'      => __( 'State', 'invoicing' ),
637
+            'city'       => __( 'City', 'invoicing' ),
638
+            'zip'        => __( 'ZIP', 'invoicing' ),
639
+            'address'    => __( 'Address', 'invoicing' ),
640
+            'phone'      => __( 'Phone', 'invoicing' ),
641
+            'company'    => __( 'Company', 'invoicing' ),
642
+            'company_id' => __( 'Company ID', 'invoicing' ),
643
+            'invoices'   => __( 'Invoices', 'invoicing' ),
644
+            'total_raw'  => __( 'Total Spend', 'invoicing' ),
645
+            'signup'     => __( 'Date created', 'invoicing' ),
646
+        );
647 647
 
648
-		// Output the csv column headers.
649
-		fputcsv( $output, array_values( $columns ) );
648
+        // Output the csv column headers.
649
+        fputcsv( $output, array_values( $columns ) );
650 650
 
651
-		// Loop through
652
-		$table = new WPInv_Customers_Table();
653
-		foreach ( $customers as $customer_id ) {
651
+        // Loop through
652
+        $table = new WPInv_Customers_Table();
653
+        foreach ( $customers as $customer_id ) {
654 654
 
655
-			$user = get_user_by( 'id', $customer_id );
656
-			$row  = array();
657
-			if ( empty( $user ) ) {
658
-				continue;
659
-			}
655
+            $user = get_user_by( 'id', $customer_id );
656
+            $row  = array();
657
+            if ( empty( $user ) ) {
658
+                continue;
659
+            }
660 660
 
661
-			foreach ( array_keys( $columns ) as $column ) {
661
+            foreach ( array_keys( $columns ) as $column ) {
662 662
 
663
-				$method = 'column_' . $column;
663
+                $method = 'column_' . $column;
664 664
 
665
-				if ( 'name' == $column ) {
666
-					$value = esc_html( $user->display_name );
667
-				} elseif ( 'email' == $column ) {
668
-					$value = sanitize_email( $user->user_email );
669
-				} elseif ( is_callable( array( $table, $method ) ) ) {
670
-					$value = wp_strip_all_tags( $table->$method( $user ) );
671
-				}
665
+                if ( 'name' == $column ) {
666
+                    $value = esc_html( $user->display_name );
667
+                } elseif ( 'email' == $column ) {
668
+                    $value = sanitize_email( $user->user_email );
669
+                } elseif ( is_callable( array( $table, $method ) ) ) {
670
+                    $value = wp_strip_all_tags( $table->$method( $user ) );
671
+                }
672 672
 
673
-				if ( empty( $value ) ) {
674
-					$value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) );
675
-				}
673
+                if ( empty( $value ) ) {
674
+                    $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) );
675
+                }
676 676
 
677
-				$row[] = $value;
677
+                $row[] = $value;
678 678
 
679
-			}
679
+            }
680 680
 
681
-			fputcsv( $output, $row );
682
-		}
681
+            fputcsv( $output, $row );
682
+        }
683 683
 
684
-		fclose( $output );
685
-		exit;
684
+        fclose( $output );
685
+        exit;
686 686
 
687
-	}
687
+    }
688 688
 
689
-	/**
689
+    /**
690 690
      * Installs a plugin.
691
-	 *
692
-	 * @param array $data
691
+     *
692
+     * @param array $data
693 693
      */
694 694
     public function admin_install_plugin( $data ) {
695 695
 
696
-		if ( ! empty( $data['plugins'] ) ) {
697
-			include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
698
-			wp_cache_flush();
696
+        if ( ! empty( $data['plugins'] ) ) {
697
+            include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
698
+            wp_cache_flush();
699 699
 
700
-			foreach ( $data['plugins'] as $slug => $file ) {
701
-				$plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' );
702
-				$upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
703
-				$installed  = $upgrader->install( $plugin_zip );
700
+            foreach ( $data['plugins'] as $slug => $file ) {
701
+                $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' );
702
+                $upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
703
+                $installed  = $upgrader->install( $plugin_zip );
704 704
 
705
-				if ( ! is_wp_error( $installed ) && $installed ) {
706
-					activate_plugin( $file, '', false, true );
707
-				} else {
708
-					wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false );
709
-				}
705
+                if ( ! is_wp_error( $installed ) && $installed ) {
706
+                    activate_plugin( $file, '', false, true );
707
+                } else {
708
+                    wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false );
709
+                }
710 710
 }
711 711
 }
712 712
 
713
-		$redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' );
714
-		wp_safe_redirect( $redirect );
715
-		exit;
713
+        $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' );
714
+        wp_safe_redirect( $redirect );
715
+        exit;
716 716
 
717
-	}
717
+    }
718 718
 
719
-	/**
719
+    /**
720 720
      * Connects a gateway.
721
-	 *
722
-	 * @param array $data
721
+     *
722
+     * @param array $data
723 723
      */
724 724
     public function admin_connect_gateway( $data ) {
725 725
 
726
-		if ( ! empty( $data['plugin'] ) ) {
726
+        if ( ! empty( $data['plugin'] ) ) {
727 727
 
728
-			$gateway     = sanitize_key( $data['plugin'] );
729
-			$connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
728
+            $gateway     = sanitize_key( $data['plugin'] );
729
+            $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
730 730
 
731
-			if ( ! empty( $connect_url ) ) {
732
-				wp_redirect( $connect_url );
733
-				exit;
734
-			}
731
+            if ( ! empty( $connect_url ) ) {
732
+                wp_redirect( $connect_url );
733
+                exit;
734
+            }
735 735
 
736
-			if ( 'stripe' == $data['plugin'] ) {
737
-				require_once ABSPATH . 'wp-admin/includes/plugin.php';
738
-				include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
739
-				wp_cache_flush();
736
+            if ( 'stripe' == $data['plugin'] ) {
737
+                require_once ABSPATH . 'wp-admin/includes/plugin.php';
738
+                include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
739
+                wp_cache_flush();
740 740
 
741
-				if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) {
742
-					$plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' );
743
-					$upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
744
-					$upgrader->install( $plugin_zip );
745
-				}
741
+                if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) {
742
+                    $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' );
743
+                    $upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
744
+                    $upgrader->install( $plugin_zip );
745
+                }
746 746
 
747
-				activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true );
748
-			}
747
+                activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true );
748
+            }
749 749
 
750
-			$connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
751
-			if ( ! empty( $connect_url ) ) {
752
-				wp_redirect( $connect_url );
753
-				exit;
754
-			}
750
+            $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
751
+            if ( ! empty( $connect_url ) ) {
752
+                wp_redirect( $connect_url );
753
+                exit;
754
+            }
755 755
 }
756 756
 
757
-		$redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' );
758
-		wp_safe_redirect( $redirect );
759
-		exit;
757
+        $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' );
758
+        wp_safe_redirect( $redirect );
759
+        exit;
760 760
 
761
-	}
761
+    }
762 762
 
763
-	/**
763
+    /**
764 764
      * Recalculates discounts.
765
-	 *
765
+     *
766 766
      */
767 767
     public function admin_recalculate_discounts() {
768
-		global $wpdb;
768
+        global $wpdb;
769 769
 
770
-		// Fetch all invoices that have discount codes.
771
-		$table    = $wpdb->prefix . 'getpaid_invoices';
772
-		$invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" );
770
+        // Fetch all invoices that have discount codes.
771
+        $table    = $wpdb->prefix . 'getpaid_invoices';
772
+        $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" );
773 773
 
774
-		foreach ( $invoices as $invoice ) {
774
+        foreach ( $invoices as $invoice ) {
775 775
 
776
-			$invoice = new WPInv_Invoice( $invoice );
776
+            $invoice = new WPInv_Invoice( $invoice );
777 777
 
778
-			if ( ! $invoice->exists() ) {
779
-				continue;
780
-			}
778
+            if ( ! $invoice->exists() ) {
779
+                continue;
780
+            }
781 781
 
782
-			// Abort if the discount does not exist or does not apply here.
783
-			$discount = new WPInv_Discount( $invoice->get_discount_code() );
784
-			if ( ! $discount->exists() ) {
785
-				continue;
786
-			}
782
+            // Abort if the discount does not exist or does not apply here.
783
+            $discount = new WPInv_Discount( $invoice->get_discount_code() );
784
+            if ( ! $discount->exists() ) {
785
+                continue;
786
+            }
787 787
 
788
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
789
-			$invoice->recalculate_total();
788
+            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
789
+            $invoice->recalculate_total();
790 790
 
791
-			if ( $invoice->get_total_discount() > 0 ) {
792
-				$invoice->save();
793
-			}
791
+            if ( $invoice->get_total_discount() > 0 ) {
792
+                $invoice->save();
793
+            }
794 794
 }
795 795
 
796
-		// Show an admin message.
797
-		$this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) );
796
+        // Show an admin message.
797
+        $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) );
798 798
 
799
-		// Redirect the admin.
800
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
801
-		exit;
799
+        // Redirect the admin.
800
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
801
+        exit;
802 802
 
803
-	}
803
+    }
804 804
 
805 805
     /**
806
-	 * Returns an array of admin notices.
807
-	 *
808
-	 * @since       1.0.19
806
+     * Returns an array of admin notices.
807
+     *
808
+     * @since       1.0.19
809 809
      * @return array
810
-	 */
811
-	public function get_notices() {
812
-		$notices = get_option( 'wpinv_admin_notices' );
810
+     */
811
+    public function get_notices() {
812
+        $notices = get_option( 'wpinv_admin_notices' );
813 813
         return is_array( $notices ) ? $notices : array();
814
-	}
814
+    }
815 815
 
816
-	/**
817
-	 * Checks if we have any admin notices.
818
-	 *
819
-	 * @since       2.0.4
816
+    /**
817
+     * Checks if we have any admin notices.
818
+     *
819
+     * @since       2.0.4
820 820
      * @return array
821
-	 */
822
-	public function has_notices() {
823
-		return count( $this->get_notices() ) > 0;
824
-	}
825
-
826
-	/**
827
-	 * Clears all admin notices
828
-	 *
829
-	 * @access      public
830
-	 * @since       1.0.19
831
-	 */
832
-	public function clear_notices() {
833
-		delete_option( 'wpinv_admin_notices' );
834
-	}
835
-
836
-	/**
837
-	 * Saves a new admin notice
838
-	 *
839
-	 * @access      public
840
-	 * @since       1.0.19
841
-	 */
842
-	public function save_notice( $type, $message ) {
843
-		$notices = $this->get_notices();
844
-
845
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) {
846
-			$notices[ $type ] = array();
847
-		}
848
-
849
-		$notices[ $type ][] = $message;
850
-
851
-		update_option( 'wpinv_admin_notices', $notices );
852
-	}
853
-
854
-	/**
855
-	 * Displays a success notice
856
-	 *
857
-	 * @param       string $msg The message to qeue.
858
-	 * @access      public
859
-	 * @since       1.0.19
860
-	 */
861
-	public function show_success( $msg ) {
862
-		$this->save_notice( 'success', $msg );
863
-	}
864
-
865
-	/**
866
-	 * Displays a error notice
867
-	 *
868
-	 * @access      public
869
-	 * @param       string $msg The message to qeue.
870
-	 * @since       1.0.19
871
-	 */
872
-	public function show_error( $msg ) {
873
-		$this->save_notice( 'error', $msg );
874
-	}
875
-
876
-	/**
877
-	 * Displays a warning notice
878
-	 *
879
-	 * @access      public
880
-	 * @param       string $msg The message to qeue.
881
-	 * @since       1.0.19
882
-	 */
883
-	public function show_warning( $msg ) {
884
-		$this->save_notice( 'warning', $msg );
885
-	}
886
-
887
-	/**
888
-	 * Displays a info notice
889
-	 *
890
-	 * @access      public
891
-	 * @param       string $msg The message to qeue.
892
-	 * @since       1.0.19
893
-	 */
894
-	public function show_info( $msg ) {
895
-		$this->save_notice( 'info', $msg );
896
-	}
897
-
898
-	/**
899
-	 * Show notices
900
-	 *
901
-	 * @access      public
902
-	 * @since       1.0.19
903
-	 */
904
-	public function show_notices() {
821
+     */
822
+    public function has_notices() {
823
+        return count( $this->get_notices() ) > 0;
824
+    }
825
+
826
+    /**
827
+     * Clears all admin notices
828
+     *
829
+     * @access      public
830
+     * @since       1.0.19
831
+     */
832
+    public function clear_notices() {
833
+        delete_option( 'wpinv_admin_notices' );
834
+    }
835
+
836
+    /**
837
+     * Saves a new admin notice
838
+     *
839
+     * @access      public
840
+     * @since       1.0.19
841
+     */
842
+    public function save_notice( $type, $message ) {
843
+        $notices = $this->get_notices();
844
+
845
+        if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) {
846
+            $notices[ $type ] = array();
847
+        }
848
+
849
+        $notices[ $type ][] = $message;
850
+
851
+        update_option( 'wpinv_admin_notices', $notices );
852
+    }
853
+
854
+    /**
855
+     * Displays a success notice
856
+     *
857
+     * @param       string $msg The message to qeue.
858
+     * @access      public
859
+     * @since       1.0.19
860
+     */
861
+    public function show_success( $msg ) {
862
+        $this->save_notice( 'success', $msg );
863
+    }
864
+
865
+    /**
866
+     * Displays a error notice
867
+     *
868
+     * @access      public
869
+     * @param       string $msg The message to qeue.
870
+     * @since       1.0.19
871
+     */
872
+    public function show_error( $msg ) {
873
+        $this->save_notice( 'error', $msg );
874
+    }
875
+
876
+    /**
877
+     * Displays a warning notice
878
+     *
879
+     * @access      public
880
+     * @param       string $msg The message to qeue.
881
+     * @since       1.0.19
882
+     */
883
+    public function show_warning( $msg ) {
884
+        $this->save_notice( 'warning', $msg );
885
+    }
886
+
887
+    /**
888
+     * Displays a info notice
889
+     *
890
+     * @access      public
891
+     * @param       string $msg The message to qeue.
892
+     * @since       1.0.19
893
+     */
894
+    public function show_info( $msg ) {
895
+        $this->save_notice( 'info', $msg );
896
+    }
897
+
898
+    /**
899
+     * Show notices
900
+     *
901
+     * @access      public
902
+     * @since       1.0.19
903
+     */
904
+    public function show_notices() {
905 905
 
906 906
         $notices = $this->get_notices();
907 907
         $this->clear_notices();
908 908
 
909
-		foreach ( $notices as $type => $messages ) {
909
+        foreach ( $notices as $type => $messages ) {
910 910
 
911
-			if ( ! is_array( $messages ) ) {
912
-				continue;
913
-			}
911
+            if ( ! is_array( $messages ) ) {
912
+                continue;
913
+            }
914 914
 
915 915
             $type  = esc_attr( $type );
916
-			foreach ( $messages as $message ) {
917
-				echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" );
916
+            foreach ( $messages as $message ) {
917
+                echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" );
918 918
             }
919 919
 }
920 920
 
921
-		foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) {
922
-
923
-			if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) {
924
-				$url     = wp_nonce_url(
925
-					add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
926
-					'getpaid-nonce',
927
-					'getpaid-nonce'
928
-				);
929
-				$message  = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' );
930
-				$message2 = __( 'Generate Pages', 'invoicing' );
931
-				echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" );
932
-				break;
933
-			}
921
+        foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) {
922
+
923
+            if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) {
924
+                $url     = wp_nonce_url(
925
+                    add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
926
+                    'getpaid-nonce',
927
+                    'getpaid-nonce'
928
+                );
929
+                $message  = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' );
930
+                $message2 = __( 'Generate Pages', 'invoicing' );
931
+                echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" );
932
+                break;
933
+            }
934 934
 }
935 935
 
936
-	}
936
+    }
937 937
 
938 938
 }
Please login to merge, or discard this patch.
includes/class-getpaid-invoice-notification-emails.php 1 patch
Indentation   +466 added lines, -466 removed lines patch added patch discarded remove patch
@@ -12,491 +12,491 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Invoice_Notification_Emails {
14 14
 
15
-	/**
16
-	 * The array of invoice email actions.
17
-	 *
18
-	 * @param array
19
-	 */
20
-	public $invoice_actions;
21
-
22
-	/**
23
-	 * Class constructor
24
-	 *
25
-	 */
26
-	public function __construct() {
27
-
28
-		$this->invoice_actions = apply_filters(
29
-			'getpaid_notification_email_invoice_triggers',
30
-			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
-				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
-				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
-				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
-				'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
-				'getpaid_invoice_status_publish'        => 'completed_invoice',
37
-				'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
-				'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
-				'getpaid_new_customer_note'             => 'user_note',
40
-				'getpaid_daily_maintenance'             => 'overdue',
41
-			)
42
-		);
43
-
44
-		$this->init_hooks();
45
-
46
-	}
47
-
48
-	/**
49
-	 * Registers email hooks.
50
-	 */
51
-	public function init_hooks() {
52
-
53
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
-
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
58
-		}
59
-	}
60
-
61
-	/**
62
-	 * Registers an email hook for an invoice action.
63
-	 *
64
-	 * @param string $hook
65
-	 * @param string|array $email_type
66
-	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
68
-
69
-		$email_type = wpinv_parse_list( $email_type );
70
-
71
-		foreach ( $email_type as $type ) {
72
-
73
-			$email = new GetPaid_Notification_Email( $type );
74
-
75
-			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
77
-				continue;
78
-			}
79
-
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
82
-				continue;
83
-			}
84
-
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
-		}
87
-
88
-	}
89
-
90
-	/**
91
-	 * Filters invoice merge tags.
92
-	 *
93
-	 * @param array $merge_tags
94
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
-	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
97
-
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
-			return array_merge(
100
-				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
102
-			);
103
-		}
104
-
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
-			return array_merge(
107
-				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
109
-			);
110
-		}
111
-
112
-		return $merge_tags;
113
-
114
-	}
115
-
116
-	/**
117
-	 * Generates invoice merge tags.
118
-	 *
119
-	 * @param WPInv_Invoice $invoice
120
-	 * @return array
121
-	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
123
-
124
-		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
126
-			return array();
127
-		}
128
-
129
-		$merge_tags = array(
130
-			'{name}'                 => sanitize_text_field( $invoice->get_user_full_name() ),
131
-			'{full_name}'            => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{first_name}'           => sanitize_text_field( $invoice->get_first_name() ),
133
-			'{last_name}'            => sanitize_text_field( $invoice->get_last_name() ),
134
-			'{email}'                => sanitize_email( $invoice->get_email() ),
135
-			'{invoice_number}'       => sanitize_text_field( $invoice->get_number() ),
136
-			'{invoice_currency}'     => sanitize_text_field( $invoice->get_currency() ),
137
-			'{invoice_total}'        => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
-			'{invoice_link}'         => esc_url( $invoice->get_view_url() ),
139
-			'{invoice_pay_link}'     => esc_url( $invoice->get_checkout_payment_url() ),
140
-			'{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ),
141
-			'{invoice_date}'         => getpaid_format_date_value( $invoice->get_date_created() ),
142
-			'{invoice_due_date}'     => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
-			'{invoice_quote}'        => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
-			'{invoice_label}'        => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
-			'{invoice_description}'  => wp_kses_post( $invoice->get_description() ),
146
-			'{subscription_name}'    => wp_kses_post( $invoice->get_subscription_name() ),
147
-			'{is_was}'               => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
-		);
149
-
150
-		$payment_form_data = $invoice->get_meta( 'payment_form_data', true );
151
-
152
-		if ( is_array( $payment_form_data ) ) {
153
-
154
-			foreach ( $payment_form_data as $label => $value ) {
155
-
156
-				$label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
-				$value = is_array( $value ) ? implode( ', ', $value ) : $value;
158
-
159
-				if ( is_scalar( $value ) ) {
160
-					$merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
161
-				}
162
-			}
163
-		}
164
-
165
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
166
-	}
167
-
168
-	/**
169
-	 * Helper function to send an email.
170
-	 *
171
-	 * @param WPInv_Invoice $invoice
172
-	 * @param GetPaid_Notification_Email $email
173
-	 * @param string $type
174
-	 * @param string|array $recipients
175
-	 * @param array $extra_args Extra template args.
176
-	 */
177
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
178
-
179
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
180
-
181
-		$skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
182
-		if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
183
-			return;
184
-		}
185
-
186
-		$mailer     = new GetPaid_Notification_Email_Sender();
187
-		$merge_tags = $email->get_merge_tags();
188
-
189
-		$result = $mailer->send(
190
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
191
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
192
-			$email->get_content( $merge_tags, $extra_args ),
193
-			$email->get_attachments()
194
-		);
195
-
196
-		// Maybe send a copy to the admin.
197
-		if ( $email->include_admin_bcc() ) {
198
-			$mailer->send(
199
-				wpinv_get_admin_email(),
200
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
201
-				$email->get_content( $merge_tags ),
202
-				$email->get_attachments()
203
-			);
204
-		}
205
-
206
-		if ( $result ) {
207
-			$invoice->add_system_note(
208
-				sprintf(
209
-					// translators: %1 is the email type, %2 is the invoice recipient.
210
-					__( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ),
211
-					sanitize_key( $type ),
212
-					$email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
213
-				)
214
-			);
215
-		} else {
216
-			$invoice->add_system_note(
217
-				sprintf(
218
-					// translators: %1 is the email type, %2 is the invoice recipient.
219
-					__( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ),
220
-					sanitize_key( $type ),
221
-					$email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
222
-				)
223
-			);
224
-		}
225
-
226
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
227
-
228
-		return $result;
229
-	}
230
-
231
-	/**
232
-	 * Also send emails to any cc users.
233
-	 *
234
-	 * @param array $recipients
235
-	 * @param GetPaid_Notification_Email $email
236
-	 */
237
-	public function filter_email_recipients( $recipients, $email ) {
238
-
239
-		if ( ! $email->is_admin_email() ) {
240
-			$cc   = $email->object->get_email_cc();
241
-			$cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true );
242
-
243
-			if ( ! empty( $cc ) ) {
244
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
245
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
246
-			}
247
-
248
-			if ( ! empty( $cc_2 ) ) {
249
-				$cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) );
250
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) );
251
-			}
252
-		}
253
-
254
-		return $recipients;
255
-
256
-	}
257
-
258
-	/**
259
-	 * Sends a new invoice notification.
260
-	 *
261
-	 * @param WPInv_Invoice $invoice
262
-	 */
263
-	public function new_invoice( $invoice ) {
264
-
265
-		// Only send this email for invoices created via the admin page.
266
-		if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
267
-			return;
268
-		}
269
-
270
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
271
-		$recipient = wpinv_get_admin_email();
272
-
273
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
274
-
275
-	}
276
-
277
-	/**
278
-	 * Sends a cancelled invoice notification.
279
-	 *
280
-	 * @param WPInv_Invoice $invoice
281
-	 */
282
-	public function cancelled_invoice( $invoice ) {
283
-
284
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
285
-		$recipient = $invoice->get_email();
286
-
287
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
288
-	}
289
-
290
-	/**
291
-	 * Sends a failed invoice notification.
292
-	 *
293
-	 * @param WPInv_Invoice $invoice
294
-	 */
295
-	public function failed_invoice( $invoice ) {
296
-
297
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
298
-		$recipient = wpinv_get_admin_email();
299
-
300
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
301
-
302
-	}
303
-
304
-	/**
305
-	 * Sends a notification whenever an invoice is put on hold.
306
-	 *
307
-	 * @param WPInv_Invoice $invoice
308
-	 */
309
-	public function onhold_invoice( $invoice ) {
310
-
311
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
312
-		$recipient = $invoice->get_email();
313
-
314
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
315
-
316
-	}
317
-
318
-	/**
319
-	 * Sends a notification whenever an invoice is marked as processing payment.
320
-	 *
321
-	 * @param WPInv_Invoice $invoice
322
-	 */
323
-	public function processing_invoice( $invoice ) {
324
-
325
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
326
-		$recipient = $invoice->get_email();
327
-
328
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
329
-
330
-	}
331
-
332
-	/**
333
-	 * Sends a notification whenever an invoice is paid.
334
-	 *
335
-	 * @param WPInv_Invoice $invoice
336
-	 */
337
-	public function completed_invoice( $invoice ) {
338
-
339
-		// (Maybe) abort if it is a renewal invoice.
340
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
341
-			return;
342
-		}
343
-
344
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
345
-		$recipient = $invoice->get_email();
346
-
347
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
348
-
349
-	}
15
+    /**
16
+     * The array of invoice email actions.
17
+     *
18
+     * @param array
19
+     */
20
+    public $invoice_actions;
21
+
22
+    /**
23
+     * Class constructor
24
+     *
25
+     */
26
+    public function __construct() {
27
+
28
+        $this->invoice_actions = apply_filters(
29
+            'getpaid_notification_email_invoice_triggers',
30
+            array(
31
+                'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
+                'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
+                'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
+                'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
+                'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
+                'getpaid_invoice_status_publish'        => 'completed_invoice',
37
+                'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
+                'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
+                'getpaid_new_customer_note'             => 'user_note',
40
+                'getpaid_daily_maintenance'             => 'overdue',
41
+            )
42
+        );
43
+
44
+        $this->init_hooks();
45
+
46
+    }
47
+
48
+    /**
49
+     * Registers email hooks.
50
+     */
51
+    public function init_hooks() {
52
+
53
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
+        add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
+
56
+        foreach ( $this->invoice_actions as $hook => $email_type ) {
57
+            $this->init_email_type_hook( $hook, $email_type );
58
+        }
59
+    }
60
+
61
+    /**
62
+     * Registers an email hook for an invoice action.
63
+     *
64
+     * @param string $hook
65
+     * @param string|array $email_type
66
+     */
67
+    public function init_email_type_hook( $hook, $email_type ) {
68
+
69
+        $email_type = wpinv_parse_list( $email_type );
70
+
71
+        foreach ( $email_type as $type ) {
72
+
73
+            $email = new GetPaid_Notification_Email( $type );
74
+
75
+            // Abort if it is not active.
76
+            if ( ! $email->is_active() ) {
77
+                continue;
78
+            }
79
+
80
+            if ( method_exists( $this, $type ) ) {
81
+                add_action( $hook, array( $this, $type ), 100, 2 );
82
+                continue;
83
+            }
84
+
85
+            do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
+        }
87
+
88
+    }
89
+
90
+    /**
91
+     * Filters invoice merge tags.
92
+     *
93
+     * @param array $merge_tags
94
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
+     */
96
+    public function invoice_merge_tags( $merge_tags, $object ) {
97
+
98
+        if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
+            return array_merge(
100
+                $merge_tags,
101
+                $this->get_invoice_merge_tags( $object )
102
+            );
103
+        }
104
+
105
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
+            return array_merge(
107
+                $merge_tags,
108
+                $this->get_invoice_merge_tags( $object->get_parent_payment() )
109
+            );
110
+        }
111
+
112
+        return $merge_tags;
113
+
114
+    }
115
+
116
+    /**
117
+     * Generates invoice merge tags.
118
+     *
119
+     * @param WPInv_Invoice $invoice
120
+     * @return array
121
+     */
122
+    public function get_invoice_merge_tags( $invoice ) {
123
+
124
+        // Abort if it does not exist.
125
+        if ( ! $invoice->get_id() ) {
126
+            return array();
127
+        }
128
+
129
+        $merge_tags = array(
130
+            '{name}'                 => sanitize_text_field( $invoice->get_user_full_name() ),
131
+            '{full_name}'            => sanitize_text_field( $invoice->get_user_full_name() ),
132
+            '{first_name}'           => sanitize_text_field( $invoice->get_first_name() ),
133
+            '{last_name}'            => sanitize_text_field( $invoice->get_last_name() ),
134
+            '{email}'                => sanitize_email( $invoice->get_email() ),
135
+            '{invoice_number}'       => sanitize_text_field( $invoice->get_number() ),
136
+            '{invoice_currency}'     => sanitize_text_field( $invoice->get_currency() ),
137
+            '{invoice_total}'        => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
+            '{invoice_link}'         => esc_url( $invoice->get_view_url() ),
139
+            '{invoice_pay_link}'     => esc_url( $invoice->get_checkout_payment_url() ),
140
+            '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ),
141
+            '{invoice_date}'         => getpaid_format_date_value( $invoice->get_date_created() ),
142
+            '{invoice_due_date}'     => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
+            '{invoice_quote}'        => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
+            '{invoice_label}'        => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
+            '{invoice_description}'  => wp_kses_post( $invoice->get_description() ),
146
+            '{subscription_name}'    => wp_kses_post( $invoice->get_subscription_name() ),
147
+            '{is_was}'               => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
+        );
149
+
150
+        $payment_form_data = $invoice->get_meta( 'payment_form_data', true );
151
+
152
+        if ( is_array( $payment_form_data ) ) {
153
+
154
+            foreach ( $payment_form_data as $label => $value ) {
155
+
156
+                $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
+                $value = is_array( $value ) ? implode( ', ', $value ) : $value;
158
+
159
+                if ( is_scalar( $value ) ) {
160
+                    $merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
161
+                }
162
+            }
163
+        }
164
+
165
+        return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
166
+    }
350 167
 
351
-	/**
352
-	 * Sends a notification whenever an invoice is refunded.
353
-	 *
354
-	 * @param WPInv_Invoice $invoice
355
-	 */
356
-	public function refunded_invoice( $invoice ) {
357
-
358
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
359
-		$recipient = $invoice->get_email();
360
-
361
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
362
-
363
-	}
168
+    /**
169
+     * Helper function to send an email.
170
+     *
171
+     * @param WPInv_Invoice $invoice
172
+     * @param GetPaid_Notification_Email $email
173
+     * @param string $type
174
+     * @param string|array $recipients
175
+     * @param array $extra_args Extra template args.
176
+     */
177
+    public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
364 178
 
365
-	/**
366
-	 * Notifies a user about new invoices
367
-	 *
368
-	 * @param WPInv_Invoice $invoice
369
-	 * @param bool $force
370
-	 */
371
-	public function user_invoice( $invoice, $force = false ) {
179
+        do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
372 180
 
373
-		if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
374
-			return;
375
-		}
376
-
377
-		// Only send this email for invoices created via the admin page.
378
-		if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
379
-			return;
380
-		}
381
-
382
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
383
-		$recipient = $invoice->get_email();
384
-
385
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
386
-
387
-	}
388
-
389
-	/**
390
-	 * Checks if an invoice is a payment form invoice.
391
-	 *
392
-	 * @param int $invoice
393
-	 * @return bool
394
-	 */
395
-	public function is_payment_form_invoice( $invoice ) {
396
-		$created_via             = get_post_meta( $invoice, 'wpinv_created_via', true );
397
-		$is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via;
398
-		$is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
399
-		return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice;
400
-	}
401
-
402
-	/**
403
-	 * Notifies admin about new invoice notes
404
-	 *
405
-	 * @param WPInv_Invoice $invoice
406
-	 * @param string $note
407
-	 */
408
-	public function user_note( $invoice, $note ) {
409
-
410
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
411
-		$recipient = $invoice->get_email();
412
-
413
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
414
-
415
-	}
416
-
417
-	/**
418
-	 * (Force) Sends overdue notices.
419
-	 *
420
-	 * @param WPInv_Invoice $invoice
421
-	 */
422
-	public function force_send_overdue_notice( $invoice ) {
423
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
424
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
425
-	}
426
-
427
-	/**
428
-	 * Sends overdue notices.
429
-	 *
430
-	 * @TODO: Create an invoices query class.
431
-	 */
432
-	public function overdue() {
433
-		global $wpdb;
434
-
435
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
436
-
437
-		// Fetch reminder days.
438
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
439
-
440
-		// Abort if non is set.
441
-		if ( empty( $reminder_days ) ) {
442
-			return;
443
-		}
444
-
445
-		// Retrieve date query.
446
-		$date_query = $this->get_date_query( $reminder_days );
447
-
448
-		// Invoices table.
449
-		$table = $wpdb->prefix . 'getpaid_invoices';
450
-
451
-		// Fetch invoices.
452
-		$invoices  = $wpdb->get_col(
453
-			"SELECT posts.ID FROM $wpdb->posts as posts
181
+        $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
182
+        if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
183
+            return;
184
+        }
185
+
186
+        $mailer     = new GetPaid_Notification_Email_Sender();
187
+        $merge_tags = $email->get_merge_tags();
188
+
189
+        $result = $mailer->send(
190
+            apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
191
+            $email->add_merge_tags( $email->get_subject(), $merge_tags ),
192
+            $email->get_content( $merge_tags, $extra_args ),
193
+            $email->get_attachments()
194
+        );
195
+
196
+        // Maybe send a copy to the admin.
197
+        if ( $email->include_admin_bcc() ) {
198
+            $mailer->send(
199
+                wpinv_get_admin_email(),
200
+                $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
201
+                $email->get_content( $merge_tags ),
202
+                $email->get_attachments()
203
+            );
204
+        }
205
+
206
+        if ( $result ) {
207
+            $invoice->add_system_note(
208
+                sprintf(
209
+                    // translators: %1 is the email type, %2 is the invoice recipient.
210
+                    __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ),
211
+                    sanitize_key( $type ),
212
+                    $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
213
+                )
214
+            );
215
+        } else {
216
+            $invoice->add_system_note(
217
+                sprintf(
218
+                    // translators: %1 is the email type, %2 is the invoice recipient.
219
+                    __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ),
220
+                    sanitize_key( $type ),
221
+                    $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
222
+                )
223
+            );
224
+        }
225
+
226
+        do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
227
+
228
+        return $result;
229
+    }
230
+
231
+    /**
232
+     * Also send emails to any cc users.
233
+     *
234
+     * @param array $recipients
235
+     * @param GetPaid_Notification_Email $email
236
+     */
237
+    public function filter_email_recipients( $recipients, $email ) {
238
+
239
+        if ( ! $email->is_admin_email() ) {
240
+            $cc   = $email->object->get_email_cc();
241
+            $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true );
242
+
243
+            if ( ! empty( $cc ) ) {
244
+                $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
245
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
246
+            }
247
+
248
+            if ( ! empty( $cc_2 ) ) {
249
+                $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) );
250
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) );
251
+            }
252
+        }
253
+
254
+        return $recipients;
255
+
256
+    }
257
+
258
+    /**
259
+     * Sends a new invoice notification.
260
+     *
261
+     * @param WPInv_Invoice $invoice
262
+     */
263
+    public function new_invoice( $invoice ) {
264
+
265
+        // Only send this email for invoices created via the admin page.
266
+        if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
267
+            return;
268
+        }
269
+
270
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
271
+        $recipient = wpinv_get_admin_email();
272
+
273
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
274
+
275
+    }
276
+
277
+    /**
278
+     * Sends a cancelled invoice notification.
279
+     *
280
+     * @param WPInv_Invoice $invoice
281
+     */
282
+    public function cancelled_invoice( $invoice ) {
283
+
284
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
285
+        $recipient = $invoice->get_email();
286
+
287
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
288
+    }
289
+
290
+    /**
291
+     * Sends a failed invoice notification.
292
+     *
293
+     * @param WPInv_Invoice $invoice
294
+     */
295
+    public function failed_invoice( $invoice ) {
296
+
297
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
298
+        $recipient = wpinv_get_admin_email();
299
+
300
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
301
+
302
+    }
303
+
304
+    /**
305
+     * Sends a notification whenever an invoice is put on hold.
306
+     *
307
+     * @param WPInv_Invoice $invoice
308
+     */
309
+    public function onhold_invoice( $invoice ) {
310
+
311
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
312
+        $recipient = $invoice->get_email();
313
+
314
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
315
+
316
+    }
317
+
318
+    /**
319
+     * Sends a notification whenever an invoice is marked as processing payment.
320
+     *
321
+     * @param WPInv_Invoice $invoice
322
+     */
323
+    public function processing_invoice( $invoice ) {
324
+
325
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
326
+        $recipient = $invoice->get_email();
327
+
328
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
329
+
330
+    }
331
+
332
+    /**
333
+     * Sends a notification whenever an invoice is paid.
334
+     *
335
+     * @param WPInv_Invoice $invoice
336
+     */
337
+    public function completed_invoice( $invoice ) {
338
+
339
+        // (Maybe) abort if it is a renewal invoice.
340
+        if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
341
+            return;
342
+        }
343
+
344
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
345
+        $recipient = $invoice->get_email();
346
+
347
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
348
+
349
+    }
350
+
351
+    /**
352
+     * Sends a notification whenever an invoice is refunded.
353
+     *
354
+     * @param WPInv_Invoice $invoice
355
+     */
356
+    public function refunded_invoice( $invoice ) {
357
+
358
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
359
+        $recipient = $invoice->get_email();
360
+
361
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
362
+
363
+    }
364
+
365
+    /**
366
+     * Notifies a user about new invoices
367
+     *
368
+     * @param WPInv_Invoice $invoice
369
+     * @param bool $force
370
+     */
371
+    public function user_invoice( $invoice, $force = false ) {
372
+
373
+        if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
374
+            return;
375
+        }
376
+
377
+        // Only send this email for invoices created via the admin page.
378
+        if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
379
+            return;
380
+        }
381
+
382
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
383
+        $recipient = $invoice->get_email();
384
+
385
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
386
+
387
+    }
388
+
389
+    /**
390
+     * Checks if an invoice is a payment form invoice.
391
+     *
392
+     * @param int $invoice
393
+     * @return bool
394
+     */
395
+    public function is_payment_form_invoice( $invoice ) {
396
+        $created_via             = get_post_meta( $invoice, 'wpinv_created_via', true );
397
+        $is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via;
398
+        $is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
399
+        return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice;
400
+    }
401
+
402
+    /**
403
+     * Notifies admin about new invoice notes
404
+     *
405
+     * @param WPInv_Invoice $invoice
406
+     * @param string $note
407
+     */
408
+    public function user_note( $invoice, $note ) {
409
+
410
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
411
+        $recipient = $invoice->get_email();
412
+
413
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
414
+
415
+    }
416
+
417
+    /**
418
+     * (Force) Sends overdue notices.
419
+     *
420
+     * @param WPInv_Invoice $invoice
421
+     */
422
+    public function force_send_overdue_notice( $invoice ) {
423
+        $email = new GetPaid_Notification_Email( 'overdue', $invoice );
424
+        return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
425
+    }
426
+
427
+    /**
428
+     * Sends overdue notices.
429
+     *
430
+     * @TODO: Create an invoices query class.
431
+     */
432
+    public function overdue() {
433
+        global $wpdb;
434
+
435
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
436
+
437
+        // Fetch reminder days.
438
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
439
+
440
+        // Abort if non is set.
441
+        if ( empty( $reminder_days ) ) {
442
+            return;
443
+        }
444
+
445
+        // Retrieve date query.
446
+        $date_query = $this->get_date_query( $reminder_days );
447
+
448
+        // Invoices table.
449
+        $table = $wpdb->prefix . 'getpaid_invoices';
450
+
451
+        // Fetch invoices.
452
+        $invoices  = $wpdb->get_col(
453
+            "SELECT posts.ID FROM $wpdb->posts as posts
454 454
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
455 455
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query"
456 456
         );
457 457
 
458
-		foreach ( $invoices as $invoice ) {
458
+        foreach ( $invoices as $invoice ) {
459 459
 
460
-			// Only send this email for invoices created via the admin page.
461
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
462
-				$invoice       = new WPInv_Invoice( $invoice );
463
-				$email->object = $invoice;
460
+            // Only send this email for invoices created via the admin page.
461
+            if ( ! $this->is_payment_form_invoice( $invoice ) ) {
462
+                $invoice       = new WPInv_Invoice( $invoice );
463
+                $email->object = $invoice;
464 464
 
465
-				if ( $invoice->needs_payment() ) {
466
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
467
-				}
465
+                if ( $invoice->needs_payment() ) {
466
+                    $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
467
+                }
468 468
 }
469 469
 }
470 470
 
471
-	}
471
+    }
472 472
 
473
-	/**
474
-	 * Calculates the date query for an invoices query
475
-	 *
476
-	 * @param array $reminder_days
477
-	 * @return string
478
-	 */
479
-	public function get_date_query( $reminder_days ) {
473
+    /**
474
+     * Calculates the date query for an invoices query
475
+     *
476
+     * @param array $reminder_days
477
+     * @return string
478
+     */
479
+    public function get_date_query( $reminder_days ) {
480 480
 
481
-		$date_query = array(
482
-			'relation' => 'OR',
483
-		);
481
+        $date_query = array(
482
+            'relation' => 'OR',
483
+        );
484 484
 
485
-		foreach ( $reminder_days as $days ) {
486
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
485
+        foreach ( $reminder_days as $days ) {
486
+            $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
487 487
 
488
-			$date_query[] = array(
489
-				'year'  => $date['year'],
490
-				'month' => $date['month'],
491
-				'day'   => $date['day'],
492
-			);
488
+            $date_query[] = array(
489
+                'year'  => $date['year'],
490
+                'month' => $date['month'],
491
+                'day'   => $date['day'],
492
+            );
493 493
 
494
-		}
494
+        }
495 495
 
496
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
496
+        $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
497 497
 
498
-		return $date_query->get_sql();
498
+        return $date_query->get_sql();
499 499
 
500
-	}
500
+    }
501 501
 
502 502
 }
Please login to merge, or discard this patch.
includes/admin/register-settings.php 1 patch
Indentation   +315 added lines, -315 removed lines patch added patch discarded remove patch
@@ -192,13 +192,13 @@  discard block
 block discarded – undo
192 192
     $name       = isset( $option['name'] ) ? $option['name'] : '';
193 193
     $cb         = "wpinv_{$option['type']}_callback";
194 194
     $section    = "wpinv_settings_{$tab}_$section";
195
-	$is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page'];
195
+    $is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page'];
196 196
 
197
-	if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) {
198
-		$tip   = wpinv_clean( $option['desc'] );
199
-		$name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>";
200
-		unset( $option['desc'] );
201
-	}
197
+    if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) {
198
+        $tip   = wpinv_clean( $option['desc'] );
199
+        $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>";
200
+        unset( $option['desc'] );
201
+    }
202 202
 
203 203
     // Loop through all tabs.
204 204
     add_settings_field(
@@ -225,9 +225,9 @@  discard block
 block discarded – undo
225 225
             'faux'            => isset( $option['faux'] ) ? $option['faux'] : false,
226 226
             'onchange'        => isset( $option['onchange'] ) ? $option['onchange'] : '',
227 227
             'custom'          => isset( $option['custom'] ) ? $option['custom'] : '',
228
-			'default_content' => isset( $option['default_content'] ) ? $option['default_content'] : '',
229
-			'class'           => isset( $option['class'] ) ? $option['class'] : '',
230
-			'style'           => isset( $option['style'] ) ? $option['style'] : '',
228
+            'default_content' => isset( $option['default_content'] ) ? $option['default_content'] : '',
229
+            'class'           => isset( $option['class'] ) ? $option['class'] : '',
230
+            'style'           => isset( $option['style'] ) ? $option['style'] : '',
231 231
             'cols'            => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50,
232 232
             'rows'            => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5,
233 233
         )
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
  * @return array
242 242
  */
243 243
 function wpinv_get_registered_settings() {
244
-	return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) );
244
+    return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) );
245 245
 }
246 246
 
247 247
 /**
@@ -260,18 +260,18 @@  discard block
 block discarded – undo
260 260
  */
261 261
 function wpinv_settings_sanitize( $input = array() ) {
262 262
 
263
-	$wpinv_options = wpinv_get_options();
264
-	$raw_referrer  = wp_get_raw_referer();
263
+    $wpinv_options = wpinv_get_options();
264
+    $raw_referrer  = wp_get_raw_referer();
265 265
 
266 266
     if ( empty( $raw_referrer ) ) {
267
-		return array_merge( $wpinv_options, $input );
267
+        return array_merge( $wpinv_options, $input );
268 268
     }
269 269
 
270 270
     wp_parse_str( $raw_referrer, $referrer );
271 271
 
272
-	if ( in_array( 'gp-setup', $referrer ) ) {
273
-		return array_merge( $wpinv_options, $input );
274
-	}
272
+    if ( in_array( 'gp-setup', $referrer ) ) {
273
+        return array_merge( $wpinv_options, $input );
274
+    }
275 275
 
276 276
     $settings = wpinv_get_registered_settings();
277 277
     $tab      = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general';
@@ -293,10 +293,10 @@  discard block
 block discarded – undo
293 293
         }
294 294
 
295 295
         // General filter
296
-		$input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
296
+        $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
297 297
 
298
-		// Key specific filter.
299
-		$input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] );
298
+        // Key specific filter.
299
+        $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] );
300 300
     }
301 301
 
302 302
     // Loop through the whitelist and unset any that are empty for the tab being saved
@@ -339,14 +339,14 @@  discard block
 block discarded – undo
339 339
 
340 340
     foreach ( $new_rates as $rate ) {
341 341
 
342
-		$rate['rate']    = wpinv_sanitize_amount( $rate['rate'] );
343
-		$rate['name']    = sanitize_text_field( $rate['name'] );
344
-		$rate['state']   = sanitize_text_field( $rate['state'] );
345
-		$rate['country'] = sanitize_text_field( $rate['country'] );
346
-		$rate['global']  = empty( $rate['state'] );
347
-		$tax_rates[]     = $rate;
342
+        $rate['rate']    = wpinv_sanitize_amount( $rate['rate'] );
343
+        $rate['name']    = sanitize_text_field( $rate['name'] );
344
+        $rate['state']   = sanitize_text_field( $rate['state'] );
345
+        $rate['country'] = sanitize_text_field( $rate['country'] );
346
+        $rate['global']  = empty( $rate['state'] );
347
+        $tax_rates[]     = $rate;
348 348
 
349
-	}
349
+    }
350 350
 
351 351
     update_option( 'wpinv_tax_rates', $tax_rates );
352 352
 
@@ -359,21 +359,21 @@  discard block
 block discarded – undo
359 359
         return $input;
360 360
     }
361 361
 
362
-	if ( empty( $_POST['wpinv_tax_rules_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_tax_rules_nonce'], 'wpinv_tax_rules' ) ) {
363
-		return $input;
364
-	}
362
+    if ( empty( $_POST['wpinv_tax_rules_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_tax_rules_nonce'], 'wpinv_tax_rules' ) ) {
363
+        return $input;
364
+    }
365 365
 
366 366
     $new_rules = ! empty( $_POST['tax_rules'] ) ? wp_kses_post_deep( array_values( $_POST['tax_rules'] ) ) : array();
367 367
     $tax_rules = array();
368 368
 
369 369
     foreach ( $new_rules as $rule ) {
370 370
 
371
-		$rule['key']      = sanitize_title_with_dashes( $rule['key'] );
372
-		$rule['label']    = sanitize_text_field( $rule['label'] );
373
-		$rule['tax_base'] = sanitize_text_field( $rule['tax_base'] );
374
-		$tax_rules[]      = $rule;
371
+        $rule['key']      = sanitize_title_with_dashes( $rule['key'] );
372
+        $rule['label']    = sanitize_text_field( $rule['label'] );
373
+        $rule['tax_base'] = sanitize_text_field( $rule['tax_base'] );
374
+        $tax_rules[]      = $rule;
375 375
 
376
-	}
376
+    }
377 377
 
378 378
     update_option( 'wpinv_tax_rules', $tax_rules );
379 379
 
@@ -386,11 +386,11 @@  discard block
 block discarded – undo
386 386
     $tabs['general']  = __( 'General', 'invoicing' );
387 387
     $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' );
388 388
     $tabs['taxes']    = __( 'Taxes', 'invoicing' );
389
-	$tabs['emails']   = __( 'Emails', 'invoicing' );
389
+    $tabs['emails']   = __( 'Emails', 'invoicing' );
390 390
 
391
-	if ( count( getpaid_get_integration_settings() ) > 0 ) {
392
-		$tabs['integrations'] = __( 'Integrations', 'invoicing' );
393
-	}
391
+    if ( count( getpaid_get_integration_settings() ) > 0 ) {
392
+        $tabs['integrations'] = __( 'Integrations', 'invoicing' );
393
+    }
394 394
 
395 395
     $tabs['privacy']  = __( 'Privacy', 'invoicing' );
396 396
     $tabs['misc']     = __( 'Misc', 'invoicing' );
@@ -421,53 +421,53 @@  discard block
 block discarded – undo
421 421
         'general'      => apply_filters(
422 422
             'wpinv_settings_sections_general',
423 423
             array(
424
-				'main'             => __( 'General Settings', 'invoicing' ),
425
-				'page_section'     => __( 'Page Settings', 'invoicing' ),
426
-				'currency_section' => __( 'Currency Settings', 'invoicing' ),
427
-				'labels'           => __( 'Label Texts', 'invoicing' ),
424
+                'main'             => __( 'General Settings', 'invoicing' ),
425
+                'page_section'     => __( 'Page Settings', 'invoicing' ),
426
+                'currency_section' => __( 'Currency Settings', 'invoicing' ),
427
+                'labels'           => __( 'Label Texts', 'invoicing' ),
428 428
             )
429 429
         ),
430 430
         'gateways'     => apply_filters(
431 431
             'wpinv_settings_sections_gateways',
432 432
             array(
433
-				'main' => __( 'Gateway Settings', 'invoicing' ),
433
+                'main' => __( 'Gateway Settings', 'invoicing' ),
434 434
             )
435 435
         ),
436 436
         'taxes'        => apply_filters(
437 437
             'wpinv_settings_sections_taxes',
438 438
             array(
439
-				'main'  => __( 'Tax Settings', 'invoicing' ),
440
-				'rules' => __( 'Tax Rules', 'invoicing' ),
441
-				'rates' => __( 'Tax Rates', 'invoicing' ),
442
-				'vat'   => __( 'EU VAT Settings', 'invoicing' ),
439
+                'main'  => __( 'Tax Settings', 'invoicing' ),
440
+                'rules' => __( 'Tax Rules', 'invoicing' ),
441
+                'rates' => __( 'Tax Rates', 'invoicing' ),
442
+                'vat'   => __( 'EU VAT Settings', 'invoicing' ),
443 443
             )
444 444
         ),
445 445
         'emails'       => apply_filters(
446 446
             'wpinv_settings_sections_emails',
447 447
             array(
448
-				'main' => __( 'Email Settings', 'invoicing' ),
448
+                'main' => __( 'Email Settings', 'invoicing' ),
449 449
             )
450 450
         ),
451 451
 
452
-		'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ),
452
+        'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ),
453 453
 
454 454
         'privacy'      => apply_filters(
455 455
             'wpinv_settings_sections_privacy',
456 456
             array(
457
-				'main' => __( 'Privacy policy', 'invoicing' ),
457
+                'main' => __( 'Privacy policy', 'invoicing' ),
458 458
             )
459 459
         ),
460 460
         'misc'         => apply_filters(
461 461
             'wpinv_settings_sections_misc',
462 462
             array(
463
-				'main'       => __( 'Miscellaneous', 'invoicing' ),
464
-				'custom-css' => __( 'Custom CSS', 'invoicing' ),
463
+                'main'       => __( 'Miscellaneous', 'invoicing' ),
464
+                'custom-css' => __( 'Custom CSS', 'invoicing' ),
465 465
             )
466 466
         ),
467 467
         'tools'        => apply_filters(
468 468
             'wpinv_settings_sections_tools',
469 469
             array(
470
-				'main' => __( 'Diagnostic Tools', 'invoicing' ),
470
+                'main' => __( 'Diagnostic Tools', 'invoicing' ),
471 471
             )
472 472
         ),
473 473
     );
@@ -478,46 +478,46 @@  discard block
 block discarded – undo
478 478
 }
479 479
 
480 480
 function wpinv_get_pages( $with_slug = false, $default_label = null ) {
481
-	$pages_options = array();
481
+    $pages_options = array();
482 482
 
483
-	if ( $default_label !== null && $default_label !== false ) {
484
-		$pages_options = array( '' => $default_label ); // Blank option
485
-	}
483
+    if ( $default_label !== null && $default_label !== false ) {
484
+        $pages_options = array( '' => $default_label ); // Blank option
485
+    }
486 486
 
487
-	$pages = get_pages();
488
-	if ( $pages ) {
489
-		foreach ( $pages as $page ) {
490
-			$title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
487
+    $pages = get_pages();
488
+    if ( $pages ) {
489
+        foreach ( $pages as $page ) {
490
+            $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
491 491
             $pages_options[ $page->ID ] = $title;
492
-		}
493
-	}
492
+        }
493
+    }
494 494
 
495
-	return $pages_options;
495
+    return $pages_options;
496 496
 }
497 497
 
498 498
 function wpinv_header_callback( $args ) {
499
-	if ( ! empty( $args['desc'] ) ) {
499
+    if ( ! empty( $args['desc'] ) ) {
500 500
         echo wp_kses_post( $args['desc'] );
501 501
     }
502 502
 }
503 503
 
504 504
 function wpinv_hidden_callback( $args ) {
505 505
 
506
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
507
-	$value   = wpinv_get_option( $args['id'], $std );
506
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
507
+    $value   = wpinv_get_option( $args['id'], $std );
508 508
 
509
-	if ( isset( $args['set_value'] ) ) {
510
-		$value = $args['set_value'];
511
-	}
509
+    if ( isset( $args['set_value'] ) ) {
510
+        $value = $args['set_value'];
511
+    }
512 512
 
513
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
514
-		$args['readonly'] = true;
515
-		$name  = '';
516
-	} else {
517
-		$name = 'wpinv_settings[' . esc_attr( $args['id'] ) . ']';
518
-	}
513
+    if ( isset( $args['faux'] ) && true === $args['faux'] ) {
514
+        $args['readonly'] = true;
515
+        $name  = '';
516
+    } else {
517
+        $name = 'wpinv_settings[' . esc_attr( $args['id'] ) . ']';
518
+    }
519 519
 
520
-	echo '<input type="hidden" id="wpinv_settings[' . esc_attr( $args['id'] ) . ']" name="' . esc_attr( $name ) . '" value="' . esc_attr( stripslashes( $value ) ) . '" />';
520
+    echo '<input type="hidden" id="wpinv_settings[' . esc_attr( $args['id'] ) . ']" name="' . esc_attr( $name ) . '" value="' . esc_attr( stripslashes( $value ) ) . '" />';
521 521
 
522 522
 }
523 523
 
@@ -526,12 +526,12 @@  discard block
 block discarded – undo
526 526
  */
527 527
 function wpinv_checkbox_callback( $args ) {
528 528
 
529
-	$std = isset( $args['std'] ) ? $args['std'] : '';
530
-	$std = wpinv_get_option( $args['id'], $std );
531
-	$id  = esc_attr( $args['id'] );
529
+    $std = isset( $args['std'] ) ? $args['std'] : '';
530
+    $std = wpinv_get_option( $args['id'], $std );
531
+    $id  = esc_attr( $args['id'] );
532 532
 
533
-	getpaid_hidden_field( "wpinv_settings[$id]", '0' );
534
-	?>
533
+    getpaid_hidden_field( "wpinv_settings[$id]", '0' );
534
+    ?>
535 535
 		<fieldset>
536 536
 			<label>
537 537
 				<input id="wpinv-settings-<?php echo esc_attr( $id ); ?>" name="wpinv_settings[<?php echo esc_attr( $id ); ?>]" <?php checked( empty( $std ), false ); ?> value="1" type="checkbox" />
@@ -543,75 +543,75 @@  discard block
 block discarded – undo
543 543
 
544 544
 function wpinv_multicheck_callback( $args ) {
545 545
 
546
-	$sanitize_id = wpinv_sanitize_key( $args['id'] );
547
-	$class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
546
+    $sanitize_id = wpinv_sanitize_key( $args['id'] );
547
+    $class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
548 548
 
549
-	if ( ! empty( $args['options'] ) ) {
549
+    if ( ! empty( $args['options'] ) ) {
550 550
 
551
-		$std     = isset( $args['std'] ) ? $args['std'] : array();
552
-		$value   = wpinv_get_option( $args['id'], $std );
551
+        $std     = isset( $args['std'] ) ? $args['std'] : array();
552
+        $value   = wpinv_get_option( $args['id'], $std );
553 553
 
554
-		echo '<div class="wpi-mcheck-rows wpi-mcheck-' . esc_attr( $sanitize_id . $class ) . '">';
554
+        echo '<div class="wpi-mcheck-rows wpi-mcheck-' . esc_attr( $sanitize_id . $class ) . '">';
555 555
         foreach ( $args['options'] as $key => $option ) :
556
-			$sanitize_key = esc_attr( wpinv_sanitize_key( $key ) );
557
-			if ( in_array( $sanitize_key, $value ) ) {
558
-				$enabled = $sanitize_key;
559
-			} else {
560
-				$enabled = null;
561
-			}
562
-			echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
563
-			echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']">' . wp_kses_post( $option ) . '</label></div>';
564
-		endforeach;
565
-		echo '</div>';
566
-		echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>';
567
-	}
556
+            $sanitize_key = esc_attr( wpinv_sanitize_key( $key ) );
557
+            if ( in_array( $sanitize_key, $value ) ) {
558
+                $enabled = $sanitize_key;
559
+            } else {
560
+                $enabled = null;
561
+            }
562
+            echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
563
+            echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']">' . wp_kses_post( $option ) . '</label></div>';
564
+        endforeach;
565
+        echo '</div>';
566
+        echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>';
567
+    }
568 568
 }
569 569
 
570 570
 function wpinv_payment_icons_callback( $args ) {
571 571
 
572 572
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
573
-	$value   = wpinv_get_option( $args['id'], false );
573
+    $value   = wpinv_get_option( $args['id'], false );
574 574
 
575
-	if ( ! empty( $args['options'] ) ) {
576
-		foreach ( $args['options'] as $key => $option ) {
575
+    if ( ! empty( $args['options'] ) ) {
576
+        foreach ( $args['options'] as $key => $option ) {
577 577
             $sanitize_key = wpinv_sanitize_key( $key );
578 578
 
579
-			if ( empty( $value ) ) {
580
-				$enabled = $option;
581
-			} else {
582
-				$enabled = null;
583
-			}
584
-
585
-			echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
586
-
587
-				echo '<input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
588
-
589
-				if ( wpinv_string_is_image_url( $key ) ) {
590
-				echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
591
-				} else {
592
-				$card = strtolower( str_replace( ' ', '', $option ) );
593
-
594
-				if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
595
-					$image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
596
-					} else {
597
-					$image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
598
-					$content_dir = WP_CONTENT_DIR;
599
-
600
-					if ( function_exists( 'wp_normalize_path' ) ) {
601
-						// Replaces backslashes with forward slashes for Windows systems
602
-						$image = wp_normalize_path( $image );
603
-						$content_dir = wp_normalize_path( $content_dir );
604
-						}
605
-
606
-					$image = str_replace( $content_dir, content_url(), $image );
607
-					}
608
-
609
-				echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
610
-				}
611
-			echo wp_kses_post( $option ) . '</label>';
612
-		}
613
-		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
614
-	}
579
+            if ( empty( $value ) ) {
580
+                $enabled = $option;
581
+            } else {
582
+                $enabled = null;
583
+            }
584
+
585
+            echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
586
+
587
+                echo '<input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
588
+
589
+                if ( wpinv_string_is_image_url( $key ) ) {
590
+                echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
591
+                } else {
592
+                $card = strtolower( str_replace( ' ', '', $option ) );
593
+
594
+                if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
595
+                    $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
596
+                    } else {
597
+                    $image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
598
+                    $content_dir = WP_CONTENT_DIR;
599
+
600
+                    if ( function_exists( 'wp_normalize_path' ) ) {
601
+                        // Replaces backslashes with forward slashes for Windows systems
602
+                        $image = wp_normalize_path( $image );
603
+                        $content_dir = wp_normalize_path( $content_dir );
604
+                        }
605
+
606
+                    $image = str_replace( $content_dir, content_url(), $image );
607
+                    }
608
+
609
+                echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
610
+                }
611
+            echo wp_kses_post( $option ) . '</label>';
612
+        }
613
+        echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
614
+    }
615 615
 }
616 616
 
617 617
 /**
@@ -619,9 +619,9 @@  discard block
 block discarded – undo
619 619
  */
620 620
 function wpinv_radio_callback( $args ) {
621 621
 
622
-	$std = isset( $args['std'] ) ? $args['std'] : '';
623
-	$std = wpinv_get_option( $args['id'], $std );
624
-	?>
622
+    $std = isset( $args['std'] ) ? $args['std'] : '';
623
+    $std = wpinv_get_option( $args['id'], $std );
624
+    ?>
625 625
 		<fieldset>
626 626
 			<ul id="wpinv-settings-<?php echo esc_attr( $args['id'] ); ?>" style="margin-top: 0;">
627 627
 				<?php foreach ( $args['options'] as $key => $option ) : ?>
@@ -635,7 +635,7 @@  discard block
 block discarded – undo
635 635
 			</ul>
636 636
 		</fieldset>
637 637
 	<?php
638
-	getpaid_settings_description_callback( $args );
638
+    getpaid_settings_description_callback( $args );
639 639
 }
640 640
 
641 641
 /**
@@ -643,10 +643,10 @@  discard block
 block discarded – undo
643 643
  */
644 644
 function getpaid_settings_description_callback( $args ) {
645 645
 
646
-	if ( ! empty( $args['desc'] ) ) {
647
-		$description = $args['desc'];
648
-		echo wp_kses_post( "<p class='description'>$description</p>" );
649
-	}
646
+    if ( ! empty( $args['desc'] ) ) {
647
+        $description = $args['desc'];
648
+        echo wp_kses_post( "<p class='description'>$description</p>" );
649
+    }
650 650
 
651 651
 }
652 652
 
@@ -655,7 +655,7 @@  discard block
 block discarded – undo
655 655
  */
656 656
 function wpinv_gateways_callback() {
657 657
 
658
-	?>
658
+    ?>
659 659
 		</td>
660 660
 	</tr>
661 661
 	<tr class="bsui">
@@ -669,26 +669,26 @@  discard block
 block discarded – undo
669 669
 
670 670
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
671 671
     $class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
672
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
673
-	$value   = wpinv_get_option( $args['id'], $std );
672
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
673
+    $value   = wpinv_get_option( $args['id'], $std );
674 674
 
675
-	echo '<select name="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" class="' . esc_attr( $class ) . '" >';
675
+    echo '<select name="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" class="' . esc_attr( $class ) . '" >';
676 676
 
677
-	foreach ( $args['options'] as $key => $option ) :
677
+    foreach ( $args['options'] as $key => $option ) :
678 678
 
679
-		echo '<option value="' . esc_attr( $key ) . '" ';
679
+        echo '<option value="' . esc_attr( $key ) . '" ';
680 680
 
681
-		if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
681
+        if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
682 682
             selected( $key, $args['selected'] );
683 683
         } else {
684 684
             selected( $key, $value );
685 685
         }
686 686
 
687
-		echo '>' . esc_html( $option['admin_label'] ) . '</option>';
688
-	endforeach;
687
+        echo '>' . esc_html( $option['admin_label'] ) . '</option>';
688
+    endforeach;
689 689
 
690
-	echo '</select>';
691
-	echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
690
+    echo '</select>';
691
+    echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
692 692
 }
693 693
 
694 694
 /**
@@ -699,38 +699,38 @@  discard block
 block discarded – undo
699 699
  */
700 700
 function wpinv_settings_attrs_helper( $args ) {
701 701
 
702
-	$value = isset( $args['std'] ) ? $args['std'] : '';
703
-	$id    = esc_attr( $args['id'] );
704
-	$value = is_scalar( $value ) ? $value : '';
705
-
706
-	$attrs = array(
707
-		'name'     => ! empty( $args['faux'] ) ? false : "wpinv_settings[$id]",
708
-		'readonly' => ! empty( $args['faux'] ),
709
-		'value'    => ! empty( $args['faux'] ) ? $value : wpinv_get_option( $args['id'], $value ),
710
-		'id'       => 'wpinv-settings-' . $args['id'],
711
-		'style'    => $args['style'],
712
-		'class'    => $args['class'],
713
-		'placeholder' => $args['placeholder'],
714
-		'data-placeholder' => $args['placeholder'],
715
-	);
702
+    $value = isset( $args['std'] ) ? $args['std'] : '';
703
+    $id    = esc_attr( $args['id'] );
704
+    $value = is_scalar( $value ) ? $value : '';
705
+
706
+    $attrs = array(
707
+        'name'     => ! empty( $args['faux'] ) ? false : "wpinv_settings[$id]",
708
+        'readonly' => ! empty( $args['faux'] ),
709
+        'value'    => ! empty( $args['faux'] ) ? $value : wpinv_get_option( $args['id'], $value ),
710
+        'id'       => 'wpinv-settings-' . $args['id'],
711
+        'style'    => $args['style'],
712
+        'class'    => $args['class'],
713
+        'placeholder' => $args['placeholder'],
714
+        'data-placeholder' => $args['placeholder'],
715
+    );
716 716
 
717
-	if ( ! empty( $args['onchange'] ) ) {
718
-		$attrs['onchange'] = $args['onchange'];
719
-	}
717
+    if ( ! empty( $args['onchange'] ) ) {
718
+        $attrs['onchange'] = $args['onchange'];
719
+    }
720 720
 
721
-	foreach ( $attrs as $key => $value ) {
721
+    foreach ( $attrs as $key => $value ) {
722 722
 
723
-		if ( false === $value ) {
724
-			continue;
725
-		}
723
+        if ( false === $value ) {
724
+            continue;
725
+        }
726 726
 
727
-		if ( true === $value ) {
728
-			echo ' ' . esc_attr( $key );
729
-		} else {
730
-			echo ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
731
-		}
727
+        if ( true === $value ) {
728
+            echo ' ' . esc_attr( $key );
729
+        } else {
730
+            echo ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
731
+        }
732 732
 
733
-	}
733
+    }
734 734
 
735 735
 }
736 736
 
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
  */
740 740
 function wpinv_text_callback( $args ) {
741 741
 
742
-	?>
742
+    ?>
743 743
 		<label style="width: 100%;">
744 744
 			<input type="text" <?php wpinv_settings_attrs_helper( $args ); ?>>
745 745
 			<?php getpaid_settings_description_callback( $args ); ?>
@@ -753,7 +753,7 @@  discard block
 block discarded – undo
753 753
  */
754 754
 function wpinv_number_callback( $args ) {
755 755
 
756
-	?>
756
+    ?>
757 757
 		<label style="width: 100%;">
758 758
 			<input type="number" step="<?php echo esc_attr( $args['step'] ); ?>" max="<?php echo intval( $args['max'] ); ?>" min="<?php echo intval( $args['min'] ); ?>" <?php wpinv_settings_attrs_helper( $args ); ?>>
759 759
 			<?php getpaid_settings_description_callback( $args ); ?>
@@ -765,34 +765,34 @@  discard block
 block discarded – undo
765 765
 function wpinv_textarea_callback( $args ) {
766 766
 
767 767
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
768
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
769
-	$value   = wpinv_get_option( $args['id'], $std );
768
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
769
+    $value   = wpinv_get_option( $args['id'], $std );
770 770
 
771 771
     $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
772 772
     $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text';
773 773
 
774
-	echo '<textarea class="' . esc_attr( $class ) . ' txtarea-' . esc_attr( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . esc_attr( $args['cols'] ) . '" rows="' . esc_attr( $args['rows'] ) . '" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
775
-	echo '<br /><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
774
+    echo '<textarea class="' . esc_attr( $class ) . ' txtarea-' . esc_attr( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . esc_attr( $args['cols'] ) . '" rows="' . esc_attr( $args['rows'] ) . '" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
775
+    echo '<br /><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
776 776
 
777 777
 }
778 778
 
779 779
 function wpinv_password_callback( $args ) {
780 780
 
781 781
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
782
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
783
-	$value   = wpinv_get_option( $args['id'], $std );
782
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
783
+    $value   = wpinv_get_option( $args['id'], $std );
784 784
 
785
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
786
-	echo '<input type="password" class="' . esc_attr( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
787
-	echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
785
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
786
+    echo '<input type="password" class="' . esc_attr( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
787
+    echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
788 788
 
789 789
 }
790 790
 
791 791
 function wpinv_missing_callback( $args ) {
792
-	printf(
793
-		esc_html__( 'The callback function used for the %s setting is missing.', 'invoicing' ),
794
-		'<strong>' . esc_html( $args['id'] ) . '</strong>'
795
-	);
792
+    printf(
793
+        esc_html__( 'The callback function used for the %s setting is missing.', 'invoicing' ),
794
+        '<strong>' . esc_html( $args['id'] ) . '</strong>'
795
+    );
796 796
 }
797 797
 
798 798
 /**
@@ -800,13 +800,13 @@  discard block
 block discarded – undo
800 800
  */
801 801
 function wpinv_select_callback( $args ) {
802 802
 
803
-	$desc   = wp_kses_post( $args['desc'] );
804
-	$desc   = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
805
-	$value  = isset( $args['std'] ) ? $args['std'] : '';
806
-	$value  = wpinv_get_option( $args['id'], $value );
807
-	$rand   = uniqid( 'random_id' );
803
+    $desc   = wp_kses_post( $args['desc'] );
804
+    $desc   = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
805
+    $value  = isset( $args['std'] ) ? $args['std'] : '';
806
+    $value  = wpinv_get_option( $args['id'], $value );
807
+    $rand   = uniqid( 'random_id' );
808 808
 
809
-	?>
809
+    ?>
810 810
 		<label style="width: 100%;">
811 811
 			<select <?php wpinv_settings_attrs_helper( $args ); ?> data-allow-clear="true">
812 812
 				<?php foreach ( $args['options'] as $option => $name ) : ?>
@@ -839,50 +839,50 @@  discard block
 block discarded – undo
839 839
 function wpinv_color_select_callback( $args ) {
840 840
 
841 841
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
842
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
843
-	$value   = wpinv_get_option( $args['id'], $std );
842
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
843
+    $value   = wpinv_get_option( $args['id'], $std );
844 844
 
845
-	echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
845
+    echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
846 846
 
847
-	foreach ( $args['options'] as $option => $color ) {
848
-		echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $color['label'] ) . '</option>';
849
-	}
847
+    foreach ( $args['options'] as $option => $color ) {
848
+        echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $color['label'] ) . '</option>';
849
+    }
850 850
 
851
-	echo '</select>';
852
-	echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
851
+    echo '</select>';
852
+    echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
853 853
 
854 854
 }
855 855
 
856 856
 function wpinv_rich_editor_callback( $args ) {
857
-	global $wp_version;
857
+    global $wp_version;
858 858
 
859 859
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
860 860
 
861
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
862
-	$value   = wpinv_get_option( $args['id'], $std );
861
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
862
+    $value   = wpinv_get_option( $args['id'], $std );
863 863
 
864
-	if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) {
865
-		$value = $std;
866
-	}
864
+    if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) {
865
+        $value = $std;
866
+    }
867 867
 
868
-	$rows = isset( $args['size'] ) ? $args['size'] : 20;
868
+    $rows = isset( $args['size'] ) ? $args['size'] : 20;
869 869
 
870
-	echo '<div class="getpaid-settings-editor-input">';
871
-	if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
872
-		wp_editor(
870
+    echo '<div class="getpaid-settings-editor-input">';
871
+    if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
872
+        wp_editor(
873 873
             stripslashes( $value ),
874 874
             'wpinv_settings_' . esc_attr( $args['id'] ),
875 875
             array(
876
-				'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']',
877
-				'textarea_rows' => absint( $rows ),
878
-				'media_buttons' => false,
876
+                'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']',
877
+                'textarea_rows' => absint( $rows ),
878
+                'media_buttons' => false,
879 879
             )
880 880
         );
881
-	} else {
882
-		echo '<textarea class="large-text" rows="10" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
883
-	}
881
+    } else {
882
+        echo '<textarea class="large-text" rows="10" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
883
+    }
884 884
 
885
-	echo '</div><br/><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
885
+    echo '</div><br/><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
886 886
 
887 887
 }
888 888
 
@@ -890,51 +890,51 @@  discard block
 block discarded – undo
890 890
 
891 891
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
892 892
 
893
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
894
-	$value   = wpinv_get_option( $args['id'], $std );
893
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
894
+    $value   = wpinv_get_option( $args['id'], $std );
895 895
 
896
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
897
-	echo '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
898
-	echo '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . esc_attr__( 'Upload File', 'invoicing' ) . '"/></span>';
899
-	echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
896
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
897
+    echo '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
898
+    echo '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . esc_attr__( 'Upload File', 'invoicing' ) . '"/></span>';
899
+    echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
900 900
 
901 901
 }
902 902
 
903 903
 function wpinv_color_callback( $args ) {
904 904
 
905
-	$std         = isset( $args['std'] ) ? $args['std'] : '';
906
-	$value       = wpinv_get_option( $args['id'], $std );
905
+    $std         = isset( $args['std'] ) ? $args['std'] : '';
906
+    $value       = wpinv_get_option( $args['id'], $std );
907 907
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
908 908
 
909
-	echo '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $std ) . '" />';
910
-	echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
909
+    echo '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $std ) . '" />';
910
+    echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
911 911
 
912 912
 }
913 913
 
914 914
 function wpinv_country_states_callback( $args ) {
915 915
 
916
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
917
-	$value   = wpinv_get_option( $args['id'], $std );
916
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
917
+    $value   = wpinv_get_option( $args['id'], $std );
918 918
 
919 919
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
920 920
 
921
-	if ( isset( $args['placeholder'] ) ) {
922
-		$placeholder = $args['placeholder'];
923
-	} else {
924
-		$placeholder = '';
925
-	}
921
+    if ( isset( $args['placeholder'] ) ) {
922
+        $placeholder = $args['placeholder'];
923
+    } else {
924
+        $placeholder = '';
925
+    }
926 926
 
927
-	$states = wpinv_get_country_states();
927
+    $states = wpinv_get_country_states();
928 928
 
929
-	$class = empty( $states ) ? 'wpinv-no-states' : 'wpi_select2';
930
-	echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="' . esc_attr( $class ) . '" data-placeholder="' . esc_html( $placeholder ) . '"/>';
929
+    $class = empty( $states ) ? 'wpinv-no-states' : 'wpi_select2';
930
+    echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="' . esc_attr( $class ) . '" data-placeholder="' . esc_html( $placeholder ) . '"/>';
931 931
 
932
-	foreach ( $states as $option => $name ) {
933
-		echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $name ) . '</option>';
934
-	}
932
+    foreach ( $states as $option => $name ) {
933
+        echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $name ) . '</option>';
934
+    }
935 935
 
936
-	echo '</select>';
937
-	echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
936
+    echo '</select>';
937
+    echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
938 938
 
939 939
 }
940 940
 
@@ -943,7 +943,7 @@  discard block
 block discarded – undo
943 943
  */
944 944
 function wpinv_tax_rates_callback() {
945 945
 
946
-	?>
946
+    ?>
947 947
 		</td>
948 948
 	</tr>
949 949
 	<tr class="bsui">
@@ -959,9 +959,9 @@  discard block
 block discarded – undo
959 959
  */
960 960
 function wpinv_tax_rate_callback( $tax_rate, $key ) {
961 961
 
962
-	$key                      = sanitize_key( $key );
963
-	$tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate'];
964
-	include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php';
962
+    $key                      = sanitize_key( $key );
963
+    $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate'];
964
+    include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php';
965 965
 
966 966
 }
967 967
 
@@ -970,7 +970,7 @@  discard block
 block discarded – undo
970 970
  */
971 971
 function wpinv_tax_rules_callback() {
972 972
 
973
-	?>
973
+    ?>
974 974
 		</td>
975 975
 	</tr>
976 976
 	<tr class="bsui">
@@ -1008,14 +1008,14 @@  discard block
 block discarded – undo
1008 1008
                 <td>
1009 1009
 					<a href="
1010 1010
                     <?php
1011
-						echo esc_url(
1012
-							wp_nonce_url(
1013
-								add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
1014
-								'getpaid-nonce',
1015
-								'getpaid-nonce'
1016
-							)
1017
-						);
1018
-					?>
1011
+                        echo esc_url(
1012
+                            wp_nonce_url(
1013
+                                add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
1014
+                                'getpaid-nonce',
1015
+                                'getpaid-nonce'
1016
+                            )
1017
+                        );
1018
+                    ?>
1019 1019
                     " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a>
1020 1020
                 </td>
1021 1021
             </tr>
@@ -1027,14 +1027,14 @@  discard block
 block discarded – undo
1027 1027
                 <td>
1028 1028
 					<a href="
1029 1029
                     <?php
1030
-						echo esc_url(
1031
-							wp_nonce_url(
1032
-								add_query_arg( 'getpaid-admin-action', 'refresh_permalinks' ),
1033
-								'getpaid-nonce',
1034
-								'getpaid-nonce'
1035
-							)
1036
-						);
1037
-					?>
1030
+                        echo esc_url(
1031
+                            wp_nonce_url(
1032
+                                add_query_arg( 'getpaid-admin-action', 'refresh_permalinks' ),
1033
+                                'getpaid-nonce',
1034
+                                'getpaid-nonce'
1035
+                            )
1036
+                        );
1037
+                    ?>
1038 1038
                     " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a>
1039 1039
                 </td>
1040 1040
             </tr>
@@ -1046,14 +1046,14 @@  discard block
 block discarded – undo
1046 1046
                 <td>
1047 1047
 					<a href="
1048 1048
                     <?php
1049
-						echo esc_url(
1050
-							wp_nonce_url(
1051
-								add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ),
1052
-								'getpaid-nonce',
1053
-								'getpaid-nonce'
1054
-							)
1055
-						);
1056
-					?>
1049
+                        echo esc_url(
1050
+                            wp_nonce_url(
1051
+                                add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ),
1052
+                                'getpaid-nonce',
1053
+                                'getpaid-nonce'
1054
+                            )
1055
+                        );
1056
+                    ?>
1057 1057
                     " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a>
1058 1058
                 </td>
1059 1059
             </tr>
@@ -1065,14 +1065,14 @@  discard block
 block discarded – undo
1065 1065
                 <td>
1066 1066
 					<a href="
1067 1067
                     <?php
1068
-						echo esc_url(
1069
-							wp_nonce_url(
1070
-								add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ),
1071
-								'getpaid-nonce',
1072
-								'getpaid-nonce'
1073
-							)
1074
-						);
1075
-					?>
1068
+                        echo esc_url(
1069
+                            wp_nonce_url(
1070
+                                add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ),
1071
+                                'getpaid-nonce',
1072
+                                'getpaid-nonce'
1073
+                            )
1074
+                        );
1075
+                    ?>
1076 1076
                     " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a>
1077 1077
                 </td>
1078 1078
             </tr>
@@ -1085,14 +1085,14 @@  discard block
 block discarded – undo
1085 1085
                 <td>
1086 1086
 					<a href="
1087 1087
                     <?php
1088
-						echo esc_url(
1089
-							wp_nonce_url(
1090
-								add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ),
1091
-								'getpaid-nonce',
1092
-								'getpaid-nonce'
1093
-							)
1094
-						);
1095
-					?>
1088
+                        echo esc_url(
1089
+                            wp_nonce_url(
1090
+                                add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ),
1091
+                                'getpaid-nonce',
1092
+                                'getpaid-nonce'
1093
+                            )
1094
+                        );
1095
+                    ?>
1096 1096
                     " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a>
1097 1097
                 </td>
1098 1098
             </tr>
@@ -1105,8 +1105,8 @@  discard block
 block discarded – undo
1105 1105
                 <td>
1106 1106
 					<a href="
1107 1107
                     <?php
1108
-						echo esc_url( admin_url( 'index.php?page=gp-setup' ) );
1109
-					?>
1108
+                        echo esc_url( admin_url( 'index.php?page=gp-setup' ) );
1109
+                    ?>
1110 1110
                     " class="button button-primary"><?php esc_html_e( 'Launch', 'invoicing' ); ?></a>
1111 1111
                 </td>
1112 1112
             </tr>
@@ -1120,19 +1120,19 @@  discard block
 block discarded – undo
1120 1120
 
1121 1121
 
1122 1122
 function wpinv_descriptive_text_callback( $args ) {
1123
-	echo wp_kses_post( $args['desc'] );
1123
+    echo wp_kses_post( $args['desc'] );
1124 1124
 }
1125 1125
 
1126 1126
 function wpinv_raw_html_callback( $args ) {
1127
-	echo wp_kses( $args['desc'], getpaid_allowed_html() );
1127
+    echo wp_kses( $args['desc'], getpaid_allowed_html() );
1128 1128
 }
1129 1129
 
1130 1130
 function wpinv_hook_callback( $args ) {
1131
-	do_action( 'wpinv_' . $args['id'], $args );
1131
+    do_action( 'wpinv_' . $args['id'], $args );
1132 1132
 }
1133 1133
 
1134 1134
 function wpinv_set_settings_cap() {
1135
-	return wpinv_get_capability();
1135
+    return wpinv_get_capability();
1136 1136
 }
1137 1137
 add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' );
1138 1138
 
@@ -1156,15 +1156,15 @@  discard block
 block discarded – undo
1156 1156
  */
1157 1157
 function wpinv_get_merge_tags_help_text( $subscription = false ) {
1158 1158
 
1159
-	$url  = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f';
1160
-	$link = sprintf(
1161
-		'<strong><a href="%s" target="_blank">%s</a></strong>',
1162
-		$url,
1163
-		esc_html__( 'View available merge tags.', 'wpinv-quotes' )
1164
-	);
1159
+    $url  = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f';
1160
+    $link = sprintf(
1161
+        '<strong><a href="%s" target="_blank">%s</a></strong>',
1162
+        $url,
1163
+        esc_html__( 'View available merge tags.', 'wpinv-quotes' )
1164
+    );
1165 1165
 
1166
-	$description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' );
1166
+    $description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' );
1167 1167
 
1168
-	return "$description $link";
1168
+    return "$description $link";
1169 1169
 
1170 1170
 }
Please login to merge, or discard this patch.
ayecode/wp-ayecode-ui/includes/components/class-aui-component-input.php 1 patch
Indentation   +1214 added lines, -1214 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,1233 +11,1233 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class AUI_Component_Input {
13 13
 
14
-	/**
15
-	 * Build the component.
16
-	 *
17
-	 * @param array $args
18
-	 *
19
-	 * @return string The rendered component.
20
-	 */
21
-	public static function input( $args = array() ) {
22
-		$defaults = array(
23
-			'type'                     => 'text',
24
-			'name'                     => '',
25
-			'class'                    => '',
26
-			'wrap_class'               => '',
27
-			'id'                       => '',
28
-			'placeholder'              => '',
29
-			'title'                    => '',
30
-			'value'                    => '',
31
-			'required'                 => false,
32
-			'size'                     => '', // sm, lg, small, large
33
-			'clear_icon'               => '', // true will show a clear icon, can't be used with input_group_right
34
-			'label'                    => '',
35
-			'label_after'              => false,
36
-			'label_class'              => '',
37
-			'label_col'                => '2',
38
-			'label_type'               => '', // top, horizontal, empty = hidden
39
-			'label_force_left'         => false, // used to force checkbox label left when using horizontal
40
-			// sets the label type, default: hidden. Options: hidden, top, horizontal, floating
41
-			'help_text'                => '',
42
-			'validation_text'          => '',
43
-			'validation_pattern'       => '',
44
-			'no_wrap'                  => false,
45
-			'input_group_right'        => '',
46
-			'input_group_left'         => '',
47
-			'input_group_right_inside' => false,
48
-			// forces the input group inside the input
49
-			'input_group_left_inside'  => false,
50
-			// forces the input group inside the input
51
-			'step'                     => '',
52
-			'switch'                   => false,
53
-			// to show checkbox as a switch
54
-			'checked'                  => false,
55
-			// set a checkbox or radio as selected
56
-			'password_toggle'          => true,
57
-			// toggle view/hide password
58
-			'element_require'          => '',
59
-			// [%element_id%] == "1"
60
-			'extra_attributes'         => array(),
61
-			// an array of extra attributes
62
-			'wrap_attributes'          => array()
63
-		);
64
-
65
-		/**
66
-		 * Parse incoming $args into an array and merge it with $defaults
67
-		 */
68
-		$args   = wp_parse_args( $args, $defaults );
69
-		$output = '';
70
-		if ( ! empty( $args['type'] ) ) {
71
-			// hidden label option needs to be empty
72
-			$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
73
-
74
-			$type = sanitize_html_class( $args['type'] );
75
-
76
-			$help_text   = '';
77
-			$label       = '';
78
-			$label_after = $args['label_after'];
79
-			$label_args  = array(
80
-				'title'      => $args['label'],
81
-				'for'        => $args['id'],
82
-				'class'      => $args['label_class'] . " ",
83
-				'label_type' => $args['label_type'],
84
-				'label_col'  => $args['label_col']
85
-			);
86
-
87
-			// floating labels need label after
88
-			if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) {
89
-				$label_after         = true;
90
-				$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
91
-			}
92
-
93
-			// size
94
-			$size = '';
95
-			if ( $args['size'] == 'lg' || $args['size'] == 'large' ) {
96
-				$size = 'lg';
97
-				$args['class'] .= ' form-control-lg';
98
-			}elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) {
99
-				$size = 'sm';
100
-				$args['class'] .= ' form-control-sm';
101
-			}
102
-
103
-			// clear function
104
-			$clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');';
105
-
106
-			// Some special sauce for files
107
-			if ( $type == 'file' ) {
108
-				$label_after = true; // if type file we need the label after
109
-				$args['class'] .= ' custom-file-input ';
110
-			} elseif ( $type == 'checkbox' ) {
111
-				$label_after = true; // if type file we need the label after
112
-				$args['class'] .= ' custom-control-input ';
113
-			} elseif ( $type == 'datepicker' || $type == 'timepicker' ) {
114
-				$type = 'text';
115
-				$args['class'] .= ' bg-initial '; // @todo not sure why we have this?
116
-				$clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');";
117
-
118
-				$args['extra_attributes']['data-aui-init'] = 'flatpickr';
119
-
120
-				// set a way to clear field if empty
121
-				if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) {
122
-					$args['input_group_right_inside'] = true;
123
-					$args['clear_icon'] = true;
124
-				}
125
-
126
-				// enqueue the script
127
-				$aui_settings = AyeCode_UI_Settings::instance();
128
-				$aui_settings->enqueue_flatpickr();
129
-			} elseif ( $type == 'iconpicker' ) {
130
-				$type = 'text';
131
-				//$args['class'] .= ' aui-flatpickr bg-initial ';
14
+    /**
15
+     * Build the component.
16
+     *
17
+     * @param array $args
18
+     *
19
+     * @return string The rendered component.
20
+     */
21
+    public static function input( $args = array() ) {
22
+        $defaults = array(
23
+            'type'                     => 'text',
24
+            'name'                     => '',
25
+            'class'                    => '',
26
+            'wrap_class'               => '',
27
+            'id'                       => '',
28
+            'placeholder'              => '',
29
+            'title'                    => '',
30
+            'value'                    => '',
31
+            'required'                 => false,
32
+            'size'                     => '', // sm, lg, small, large
33
+            'clear_icon'               => '', // true will show a clear icon, can't be used with input_group_right
34
+            'label'                    => '',
35
+            'label_after'              => false,
36
+            'label_class'              => '',
37
+            'label_col'                => '2',
38
+            'label_type'               => '', // top, horizontal, empty = hidden
39
+            'label_force_left'         => false, // used to force checkbox label left when using horizontal
40
+            // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
41
+            'help_text'                => '',
42
+            'validation_text'          => '',
43
+            'validation_pattern'       => '',
44
+            'no_wrap'                  => false,
45
+            'input_group_right'        => '',
46
+            'input_group_left'         => '',
47
+            'input_group_right_inside' => false,
48
+            // forces the input group inside the input
49
+            'input_group_left_inside'  => false,
50
+            // forces the input group inside the input
51
+            'step'                     => '',
52
+            'switch'                   => false,
53
+            // to show checkbox as a switch
54
+            'checked'                  => false,
55
+            // set a checkbox or radio as selected
56
+            'password_toggle'          => true,
57
+            // toggle view/hide password
58
+            'element_require'          => '',
59
+            // [%element_id%] == "1"
60
+            'extra_attributes'         => array(),
61
+            // an array of extra attributes
62
+            'wrap_attributes'          => array()
63
+        );
64
+
65
+        /**
66
+         * Parse incoming $args into an array and merge it with $defaults
67
+         */
68
+        $args   = wp_parse_args( $args, $defaults );
69
+        $output = '';
70
+        if ( ! empty( $args['type'] ) ) {
71
+            // hidden label option needs to be empty
72
+            $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
73
+
74
+            $type = sanitize_html_class( $args['type'] );
75
+
76
+            $help_text   = '';
77
+            $label       = '';
78
+            $label_after = $args['label_after'];
79
+            $label_args  = array(
80
+                'title'      => $args['label'],
81
+                'for'        => $args['id'],
82
+                'class'      => $args['label_class'] . " ",
83
+                'label_type' => $args['label_type'],
84
+                'label_col'  => $args['label_col']
85
+            );
86
+
87
+            // floating labels need label after
88
+            if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) {
89
+                $label_after         = true;
90
+                $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
91
+            }
92
+
93
+            // size
94
+            $size = '';
95
+            if ( $args['size'] == 'lg' || $args['size'] == 'large' ) {
96
+                $size = 'lg';
97
+                $args['class'] .= ' form-control-lg';
98
+            }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) {
99
+                $size = 'sm';
100
+                $args['class'] .= ' form-control-sm';
101
+            }
102
+
103
+            // clear function
104
+            $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');';
105
+
106
+            // Some special sauce for files
107
+            if ( $type == 'file' ) {
108
+                $label_after = true; // if type file we need the label after
109
+                $args['class'] .= ' custom-file-input ';
110
+            } elseif ( $type == 'checkbox' ) {
111
+                $label_after = true; // if type file we need the label after
112
+                $args['class'] .= ' custom-control-input ';
113
+            } elseif ( $type == 'datepicker' || $type == 'timepicker' ) {
114
+                $type = 'text';
115
+                $args['class'] .= ' bg-initial '; // @todo not sure why we have this?
116
+                $clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');";
117
+
118
+                $args['extra_attributes']['data-aui-init'] = 'flatpickr';
119
+
120
+                // set a way to clear field if empty
121
+                if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) {
122
+                    $args['input_group_right_inside'] = true;
123
+                    $args['clear_icon'] = true;
124
+                }
125
+
126
+                // enqueue the script
127
+                $aui_settings = AyeCode_UI_Settings::instance();
128
+                $aui_settings->enqueue_flatpickr();
129
+            } elseif ( $type == 'iconpicker' ) {
130
+                $type = 'text';
131
+                //$args['class'] .= ' aui-flatpickr bg-initial ';
132 132
 //				$args['class'] .= ' bg-initial ';
133 133
 
134
-				$args['extra_attributes']['data-aui-init'] = 'iconpicker';
135
-				$args['extra_attributes']['data-placement'] = 'bottomRight';
134
+                $args['extra_attributes']['data-aui-init'] = 'iconpicker';
135
+                $args['extra_attributes']['data-placement'] = 'bottomRight';
136 136
 
137
-				$args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>';
137
+                $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>';
138 138
 //				$args['input_group_right_inside'] = true;
139
-				// enqueue the script
140
-				$aui_settings = AyeCode_UI_Settings::instance();
141
-				$aui_settings->enqueue_iconpicker();
142
-			}
143
-
144
-			if ( $type == 'checkbox' && !empty($args['name'] ) && strpos($args['name'], '[') === false ) {
145
-				$output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />';
146
-			}
147
-
148
-			// allow clear icon
149
-			if ( $args['input_group_right'] === '' && $args['clear_icon'] ) {
150
-				$font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' );
151
-				$args['input_group_right_inside'] = true;
152
-				$args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none" onclick="' . $clear_function . '"><span style="font-size: '.$font_size.'rem" aria-hidden="true" class="close">&times;</span></span>';
153
-			}
154
-
155
-			// open/type
156
-			$output .= '<input type="' . $type . '" ';
157
-
158
-			// name
159
-			if ( ! empty( $args['name'] ) ) {
160
-				$output .= ' name="' . esc_attr( $args['name'] ) . '" ';
161
-			}
162
-
163
-			// id
164
-			if ( ! empty( $args['id'] ) ) {
165
-				$output .= ' id="' . sanitize_html_class( $args['id'] ) . '" ';
166
-			}
167
-
168
-			// placeholder
169
-			if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) {
170
-				$output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" ';
171
-			}
172
-
173
-			// title
174
-			if ( ! empty( $args['title'] ) ) {
175
-				$output .= ' title="' . esc_attr( $args['title'] ) . '" ';
176
-			}
177
-
178
-			// value
179
-			if ( ! empty( $args['value'] ) ) {
180
-				$output .= AUI_Component_Helper::value( $args['value'] );
181
-			}
182
-
183
-			// checked, for radio and checkboxes
184
-			if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) {
185
-				$output .= ' checked ';
186
-			}
187
-
188
-			// validation text
189
-			if ( ! empty( $args['validation_text'] ) ) {
190
-				$output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" ';
191
-				$output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
192
-			}
193
-
194
-			// validation_pattern
195
-			if ( ! empty( $args['validation_pattern'] ) ) {
196
-				$output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" ';
197
-			}
198
-
199
-			// step (for numbers)
200
-			if ( ! empty( $args['step'] ) ) {
201
-				$output .= ' step="' . $args['step'] . '" ';
202
-			}
203
-
204
-			// required
205
-			if ( ! empty( $args['required'] ) ) {
206
-				$output .= ' required ';
207
-			}
208
-
209
-			// class
210
-			$class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
211
-			$output .= ' class="form-control ' . $class . '" ';
212
-
213
-			// data-attributes
214
-			$output .= AUI_Component_Helper::data_attributes( $args );
215
-
216
-			// extra attributes
217
-			if ( ! empty( $args['extra_attributes'] ) ) {
218
-				$output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
219
-			}
220
-
221
-			// close
222
-			$output .= ' >';
223
-
224
-			// help text
225
-			if ( ! empty( $args['help_text'] ) ) {
226
-				$help_text = AUI_Component_Helper::help_text( $args['help_text'] );
227
-			}
228
-
229
-			// label
230
-			if ( ! empty( $args['label'] ) ) {
231
-				$label_base_class = '';
232
-				if ( $type == 'file' ) {
233
-					$label_base_class = ' custom-file-label';
234
-				} elseif ( $type == 'checkbox' ) {
235
-					if ( ! empty( $args['label_force_left'] ) ) {
236
-						$label_args['title'] = wp_kses_post( $args['help_text'] );
237
-						$help_text = '';
238
-						//$label_args['class'] .= ' d-inline ';
239
-						$args['wrap_class'] .= ' align-items-center ';
240
-					}else{
241
-
242
-					}
243
-
244
-					$label_base_class = ' custom-control-label';
245
-				}
246
-				$label_args['class'] .= $label_base_class;
247
-				$temp_label_args = $label_args;
248
-				if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";}
249
-				$label = self::label( $temp_label_args, $type );
250
-			}
251
-
252
-
253
-
254
-
255
-			// set help text in the correct position
256
-			if ( $label_after ) {
257
-				$output .= $label . $help_text;
258
-			}
259
-
260
-			// some input types need a separate wrap
261
-			if ( $type == 'file' ) {
262
-				$output = self::wrap( array(
263
-					'content' => $output,
264
-					'class'   => 'form-group custom-file'
265
-				) );
266
-			} elseif ( $type == 'checkbox' ) {
267
-
268
-				$label_args['title'] = $args['label'];
269
-				$label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' );
270
-				$label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>';
271
-				$switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : '';
272
-				$wrap_class = $args['switch'] ? 'custom-switch'.$switch_size_class : 'custom-checkbox';
273
-				if ( ! empty( $args['label_force_left'] ) ) {
274
-					$wrap_class .= ' d-flex align-content-center';
275
-					$label = str_replace("custom-control-label","", self::label( $label_args, 'cb' ) );
276
-				}
277
-				$output     = self::wrap( array(
278
-					'content' => $output,
279
-					'class'   => 'custom-control ' . $wrap_class
280
-				) );
281
-
282
-				if ( $args['label_type'] == 'horizontal' ) {
283
-					$input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
284
-					$output    = $label . '<div class="' . $input_col . '">' . $output . '</div>';
285
-				}
286
-			} elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) {
287
-
288
-
289
-				// allow password field to toggle view
290
-				$args['input_group_right'] = '<span class="input-group-text c-pointer px-3" 
139
+                // enqueue the script
140
+                $aui_settings = AyeCode_UI_Settings::instance();
141
+                $aui_settings->enqueue_iconpicker();
142
+            }
143
+
144
+            if ( $type == 'checkbox' && !empty($args['name'] ) && strpos($args['name'], '[') === false ) {
145
+                $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />';
146
+            }
147
+
148
+            // allow clear icon
149
+            if ( $args['input_group_right'] === '' && $args['clear_icon'] ) {
150
+                $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' );
151
+                $args['input_group_right_inside'] = true;
152
+                $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none" onclick="' . $clear_function . '"><span style="font-size: '.$font_size.'rem" aria-hidden="true" class="close">&times;</span></span>';
153
+            }
154
+
155
+            // open/type
156
+            $output .= '<input type="' . $type . '" ';
157
+
158
+            // name
159
+            if ( ! empty( $args['name'] ) ) {
160
+                $output .= ' name="' . esc_attr( $args['name'] ) . '" ';
161
+            }
162
+
163
+            // id
164
+            if ( ! empty( $args['id'] ) ) {
165
+                $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" ';
166
+            }
167
+
168
+            // placeholder
169
+            if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) {
170
+                $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" ';
171
+            }
172
+
173
+            // title
174
+            if ( ! empty( $args['title'] ) ) {
175
+                $output .= ' title="' . esc_attr( $args['title'] ) . '" ';
176
+            }
177
+
178
+            // value
179
+            if ( ! empty( $args['value'] ) ) {
180
+                $output .= AUI_Component_Helper::value( $args['value'] );
181
+            }
182
+
183
+            // checked, for radio and checkboxes
184
+            if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) {
185
+                $output .= ' checked ';
186
+            }
187
+
188
+            // validation text
189
+            if ( ! empty( $args['validation_text'] ) ) {
190
+                $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" ';
191
+                $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
192
+            }
193
+
194
+            // validation_pattern
195
+            if ( ! empty( $args['validation_pattern'] ) ) {
196
+                $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" ';
197
+            }
198
+
199
+            // step (for numbers)
200
+            if ( ! empty( $args['step'] ) ) {
201
+                $output .= ' step="' . $args['step'] . '" ';
202
+            }
203
+
204
+            // required
205
+            if ( ! empty( $args['required'] ) ) {
206
+                $output .= ' required ';
207
+            }
208
+
209
+            // class
210
+            $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
211
+            $output .= ' class="form-control ' . $class . '" ';
212
+
213
+            // data-attributes
214
+            $output .= AUI_Component_Helper::data_attributes( $args );
215
+
216
+            // extra attributes
217
+            if ( ! empty( $args['extra_attributes'] ) ) {
218
+                $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
219
+            }
220
+
221
+            // close
222
+            $output .= ' >';
223
+
224
+            // help text
225
+            if ( ! empty( $args['help_text'] ) ) {
226
+                $help_text = AUI_Component_Helper::help_text( $args['help_text'] );
227
+            }
228
+
229
+            // label
230
+            if ( ! empty( $args['label'] ) ) {
231
+                $label_base_class = '';
232
+                if ( $type == 'file' ) {
233
+                    $label_base_class = ' custom-file-label';
234
+                } elseif ( $type == 'checkbox' ) {
235
+                    if ( ! empty( $args['label_force_left'] ) ) {
236
+                        $label_args['title'] = wp_kses_post( $args['help_text'] );
237
+                        $help_text = '';
238
+                        //$label_args['class'] .= ' d-inline ';
239
+                        $args['wrap_class'] .= ' align-items-center ';
240
+                    }else{
241
+
242
+                    }
243
+
244
+                    $label_base_class = ' custom-control-label';
245
+                }
246
+                $label_args['class'] .= $label_base_class;
247
+                $temp_label_args = $label_args;
248
+                if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";}
249
+                $label = self::label( $temp_label_args, $type );
250
+            }
251
+
252
+
253
+
254
+
255
+            // set help text in the correct position
256
+            if ( $label_after ) {
257
+                $output .= $label . $help_text;
258
+            }
259
+
260
+            // some input types need a separate wrap
261
+            if ( $type == 'file' ) {
262
+                $output = self::wrap( array(
263
+                    'content' => $output,
264
+                    'class'   => 'form-group custom-file'
265
+                ) );
266
+            } elseif ( $type == 'checkbox' ) {
267
+
268
+                $label_args['title'] = $args['label'];
269
+                $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' );
270
+                $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>';
271
+                $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : '';
272
+                $wrap_class = $args['switch'] ? 'custom-switch'.$switch_size_class : 'custom-checkbox';
273
+                if ( ! empty( $args['label_force_left'] ) ) {
274
+                    $wrap_class .= ' d-flex align-content-center';
275
+                    $label = str_replace("custom-control-label","", self::label( $label_args, 'cb' ) );
276
+                }
277
+                $output     = self::wrap( array(
278
+                    'content' => $output,
279
+                    'class'   => 'custom-control ' . $wrap_class
280
+                ) );
281
+
282
+                if ( $args['label_type'] == 'horizontal' ) {
283
+                    $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
284
+                    $output    = $label . '<div class="' . $input_col . '">' . $output . '</div>';
285
+                }
286
+            } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) {
287
+
288
+
289
+                // allow password field to toggle view
290
+                $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" 
291 291
 onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\');
292 292
 var $eli = jQuery(this).parent().parent().find(\'input\');
293 293
 if($el.hasClass(\'fa-eye\'))
294 294
 {$eli.attr(\'type\',\'text\');}
295 295
 else{$eli.attr(\'type\',\'password\');}"
296 296
 ><i class="far fa-fw fa-eye-slash"></i></span>';
297
-			}
298
-
299
-			// input group wraps
300
-			if ( $args['input_group_left'] || $args['input_group_right'] ) {
301
-				$w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
302
-				$group_size = $size == 'lg' ? ' input-group-lg' : '';
303
-				$group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size;
304
-
305
-				if ( $args['input_group_left'] ) {
306
-					$output = self::wrap( array(
307
-						'content'                 => $output,
308
-						'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size,
309
-						'input_group_left'        => $args['input_group_left'],
310
-						'input_group_left_inside' => $args['input_group_left_inside']
311
-					) );
312
-				}
313
-				if ( $args['input_group_right'] ) {
314
-					$output = self::wrap( array(
315
-						'content'                  => $output,
316
-						'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size,
317
-						'input_group_right'        => $args['input_group_right'],
318
-						'input_group_right_inside' => $args['input_group_right_inside']
319
-					) );
320
-				}
321
-
322
-			}
323
-
324
-			if ( ! $label_after ) {
325
-				$output .= $help_text;
326
-			}
327
-
328
-
329
-			if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) {
330
-				$output = self::wrap( array(
331
-					'content' => $output,
332
-					'class'   => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' )
333
-				) );
334
-			}
335
-
336
-			if ( ! $label_after ) {
337
-				$output = $label . $output;
338
-			}
339
-
340
-			// wrap
341
-			if ( ! $args['no_wrap'] ) {
342
-				$form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group';
343
-				$wrap_class       = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class;
344
-				$wrap_class       = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
345
-				$output           = self::wrap( array(
346
-					'content'         => $output,
347
-					'class'           => $wrap_class,
348
-					'element_require' => $args['element_require'],
349
-					'argument_id'     => $args['id'],
350
-					'wrap_attributes' => $args['wrap_attributes'],
351
-				) );
352
-			}
353
-		}
354
-
355
-		return $output;
356
-	}
357
-
358
-	public static function label( $args = array(), $type = '' ) {
359
-		//<label for="exampleInputEmail1">Email address</label>
360
-		$defaults = array(
361
-			'title'      => 'div',
362
-			'for'        => '',
363
-			'class'      => '',
364
-			'label_type' => '', // empty = hidden, top, horizontal
365
-			'label_col'  => '',
366
-		);
367
-
368
-		/**
369
-		 * Parse incoming $args into an array and merge it with $defaults
370
-		 */
371
-		$args   = wp_parse_args( $args, $defaults );
372
-		$output = '';
373
-
374
-		if ( $args['title'] ) {
375
-
376
-			// maybe hide labels //@todo set a global option for visibility class
377
-			if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) {
378
-				$class = $args['class'];
379
-			} else {
380
-				$class = 'sr-only ' . $args['class'];
381
-			}
382
-
383
-			// maybe horizontal
384
-			if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) {
385
-				$class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label';
386
-			}
387
-
388
-			// open
389
-			$output .= '<label ';
390
-
391
-			// for
392
-			if ( ! empty( $args['for'] ) ) {
393
-				$output .= ' for="' . esc_attr( $args['for'] ) . '" ';
394
-			}
395
-
396
-			// class
397
-			$class = $class ? AUI_Component_Helper::esc_classes( $class ) : '';
398
-			$output .= ' class="' . $class . '" ';
399
-
400
-			// close
401
-			$output .= '>';
402
-
403
-
404
-			// title, don't escape fully as can contain html
405
-			if ( ! empty( $args['title'] ) ) {
406
-				$output .= wp_kses_post( $args['title'] );
407
-			}
408
-
409
-			// close wrap
410
-			$output .= '</label>';
411
-
412
-
413
-		}
414
-
415
-
416
-		return $output;
417
-	}
418
-
419
-	/**
420
-	 * Wrap some content in a HTML wrapper.
421
-	 *
422
-	 * @param array $args
423
-	 *
424
-	 * @return string
425
-	 */
426
-	public static function wrap( $args = array() ) {
427
-		$defaults = array(
428
-			'type'                     => 'div',
429
-			'class'                    => 'form-group',
430
-			'content'                  => '',
431
-			'input_group_left'         => '',
432
-			'input_group_right'        => '',
433
-			'input_group_left_inside'  => false,
434
-			'input_group_right_inside' => false,
435
-			'element_require'          => '',
436
-			'argument_id'              => '',
437
-			'wrap_attributes'          => array()
438
-		);
439
-
440
-		/**
441
-		 * Parse incoming $args into an array and merge it with $defaults
442
-		 */
443
-		$args   = wp_parse_args( $args, $defaults );
444
-		$output = '';
445
-		if ( $args['type'] ) {
446
-
447
-			// open
448
-			$output .= '<' . sanitize_html_class( $args['type'] );
449
-
450
-			// element require
451
-			if ( ! empty( $args['element_require'] ) ) {
452
-				$output .= AUI_Component_Helper::element_require( $args['element_require'] );
453
-				$args['class'] .= " aui-conditional-field";
454
-			}
455
-
456
-			// argument_id
457
-			if ( ! empty( $args['argument_id'] ) ) {
458
-				$output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"';
459
-			}
460
-
461
-			// class
462
-			$class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
463
-			$output .= ' class="' . $class . '" ';
464
-
465
-			// Attributes
466
-			if ( ! empty( $args['wrap_attributes'] ) ) {
467
-				$output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] );
468
-			}
469
-
470
-			// close wrap
471
-			$output .= ' >';
472
-
473
-
474
-			// Input group left
475
-			if ( ! empty( $args['input_group_left'] ) ) {
476
-				$position_class   = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : '';
477
-				$input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>';
478
-				$output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>';
479
-			}
480
-
481
-			// content
482
-			$output .= $args['content'];
483
-
484
-			// Input group right
485
-			if ( ! empty( $args['input_group_right'] ) ) {
486
-				$position_class    = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : '';
487
-				$input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>';
488
-				$output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>';
489
-			}
490
-
491
-
492
-			// close wrap
493
-			$output .= '</' . sanitize_html_class( $args['type'] ) . '>';
494
-
495
-
496
-		} else {
497
-			$output = $args['content'];
498
-		}
499
-
500
-		return $output;
501
-	}
502
-
503
-	/**
504
-	 * Build the component.
505
-	 *
506
-	 * @param array $args
507
-	 *
508
-	 * @return string The rendered component.
509
-	 */
510
-	public static function textarea( $args = array() ) {
511
-		$defaults = array(
512
-			'name'               => '',
513
-			'class'              => '',
514
-			'wrap_class'         => '',
515
-			'id'                 => '',
516
-			'placeholder'        => '',
517
-			'title'              => '',
518
-			'value'              => '',
519
-			'required'           => false,
520
-			'label'              => '',
521
-			'label_after'        => false,
522
-			'label_class'        => '',
523
-			'label_type'         => '',
524
-			'label_col'          => '',
525
-			// sets the label type, default: hidden. Options: hidden, top, horizontal, floating
526
-			'input_group_right'        => '',
527
-			'input_group_left'         => '',
528
-			'input_group_right_inside' => false,
529
-			'help_text'          => '',
530
-			'validation_text'    => '',
531
-			'validation_pattern' => '',
532
-			'no_wrap'            => false,
533
-			'rows'               => '',
534
-			'wysiwyg'            => false,
535
-			'allow_tags'         => false,
536
-			// Allow HTML tags
537
-			'element_require'    => '',
538
-			// [%element_id%] == "1"
539
-			'extra_attributes'   => array(),
540
-			// an array of extra attributes
541
-			'wrap_attributes'    => array(),
542
-		);
543
-
544
-		/**
545
-		 * Parse incoming $args into an array and merge it with $defaults
546
-		 */
547
-		$args   = wp_parse_args( $args, $defaults );
548
-		$output = '';
549
-
550
-		// hidden label option needs to be empty
551
-		$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
552
-
553
-		// floating labels don't work with wysiwyg so set it as top
554
-		if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) {
555
-			$args['label_type'] = 'top';
556
-		}
557
-
558
-		$label_after = $args['label_after'];
559
-
560
-		// floating labels need label after
561
-		if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) {
562
-			$label_after         = true;
563
-			$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
564
-		}
565
-
566
-		// label
567
-		if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
568
-		} elseif ( ! empty( $args['label'] ) && ! $label_after ) {
569
-			$label_args = array(
570
-				'title'      => $args['label'],
571
-				'for'        => $args['id'],
572
-				'class'      => $args['label_class'] . " ",
573
-				'label_type' => $args['label_type'],
574
-				'label_col'  => $args['label_col']
575
-			);
576
-			$output .= self::label( $label_args );
577
-		}
578
-
579
-		// maybe horizontal label
580
-		if ( $args['label_type'] == 'horizontal' ) {
581
-			$input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
582
-			$output .= '<div class="' . $input_col . '">';
583
-		}
584
-
585
-		if ( ! empty( $args['wysiwyg'] ) ) {
586
-			ob_start();
587
-			$content   = $args['value'];
588
-			$editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor';
589
-			$settings  = array(
590
-				'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4,
591
-				'quicktags'     => false,
592
-				'media_buttons' => false,
593
-				'editor_class'  => 'form-control',
594
-				'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ),
595
-				'teeny'         => true,
596
-			);
597
-
598
-			// maybe set settings if array
599
-			if ( is_array( $args['wysiwyg'] ) ) {
600
-				$settings = wp_parse_args( $args['wysiwyg'], $settings );
601
-			}
602
-
603
-			wp_editor( $content, $editor_id, $settings );
604
-			$output .= ob_get_clean();
605
-		} else {
606
-
607
-			// open
608
-			$output .= '<textarea ';
609
-
610
-			// name
611
-			if ( ! empty( $args['name'] ) ) {
612
-				$output .= ' name="' . esc_attr( $args['name'] ) . '" ';
613
-			}
614
-
615
-			// id
616
-			if ( ! empty( $args['id'] ) ) {
617
-				$output .= ' id="' . sanitize_html_class( $args['id'] ) . '" ';
618
-			}
619
-
620
-			// placeholder
621
-			if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) {
622
-				$output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" ';
623
-			}
624
-
625
-			// title
626
-			if ( ! empty( $args['title'] ) ) {
627
-				$output .= ' title="' . esc_attr( $args['title'] ) . '" ';
628
-			}
629
-
630
-			// validation text
631
-			if ( ! empty( $args['validation_text'] ) ) {
632
-				$output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" ';
633
-				$output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
634
-			}
635
-
636
-			// validation_pattern
637
-			if ( ! empty( $args['validation_pattern'] ) ) {
638
-				$output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" ';
639
-			}
640
-
641
-			// required
642
-			if ( ! empty( $args['required'] ) ) {
643
-				$output .= ' required ';
644
-			}
645
-
646
-			// rows
647
-			if ( ! empty( $args['rows'] ) ) {
648
-				$output .= ' rows="' . absint( $args['rows'] ) . '" ';
649
-			}
650
-
651
-
652
-			// class
653
-			$class = ! empty( $args['class'] ) ? $args['class'] : '';
654
-			$output .= ' class="form-control ' . $class . '" ';
655
-
656
-			// extra attributes
657
-			if ( ! empty( $args['extra_attributes'] ) ) {
658
-				$output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
659
-			}
660
-
661
-			// close tag
662
-			$output .= ' >';
663
-
664
-			// value
665
-			if ( ! empty( $args['value'] ) ) {
666
-				if ( ! empty( $args['allow_tags'] ) ) {
667
-					$output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML.
668
-				} else {
669
-					$output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] );
670
-				}
671
-			}
672
-
673
-			// closing tag
674
-			$output .= '</textarea>';
675
-
676
-
677
-			// input group wraps
678
-			if ( $args['input_group_left'] || $args['input_group_right'] ) {
679
-				$w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
680
-				if ( $args['input_group_left'] ) {
681
-					$output = self::wrap( array(
682
-						'content'                 => $output,
683
-						'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
684
-						'input_group_left'        => $args['input_group_left'],
685
-						'input_group_left_inside' => $args['input_group_left_inside']
686
-					) );
687
-				}
688
-				if ( $args['input_group_right'] ) {
689
-					$output = self::wrap( array(
690
-						'content'                  => $output,
691
-						'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
692
-						'input_group_right'        => $args['input_group_right'],
693
-						'input_group_right_inside' => $args['input_group_right_inside']
694
-					) );
695
-				}
696
-
697
-			}
698
-
699
-
700
-		}
701
-
702
-		if ( ! empty( $args['label'] ) && $label_after ) {
703
-			$label_args = array(
704
-				'title'      => $args['label'],
705
-				'for'        => $args['id'],
706
-				'class'      => $args['label_class'] . " ",
707
-				'label_type' => $args['label_type'],
708
-				'label_col'  => $args['label_col']
709
-			);
710
-			$output .= self::label( $label_args );
711
-		}
712
-
713
-		// help text
714
-		if ( ! empty( $args['help_text'] ) ) {
715
-			$output .= AUI_Component_Helper::help_text( $args['help_text'] );
716
-		}
717
-
718
-		// maybe horizontal label
719
-		if ( $args['label_type'] == 'horizontal' ) {
720
-			$output .= '</div>';
721
-		}
722
-
723
-
724
-		// wrap
725
-		if ( ! $args['no_wrap'] ) {
726
-			$form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : 'form-group';
727
-			$wrap_class       = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class;
728
-			$wrap_class       = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
729
-			$output           = self::wrap( array(
730
-				'content'         => $output,
731
-				'class'           => $wrap_class,
732
-				'element_require' => $args['element_require'],
733
-				'argument_id'     => $args['id'],
734
-				'wrap_attributes' => $args['wrap_attributes'],
735
-			) );
736
-		}
737
-
738
-
739
-		return $output;
740
-	}
741
-
742
-	/**
743
-	 * Build the component.
744
-	 *
745
-	 * @param array $args
746
-	 *
747
-	 * @return string The rendered component.
748
-	 */
749
-	public static function select( $args = array() ) {
750
-		$defaults = array(
751
-			'class'            => '',
752
-			'wrap_class'       => '',
753
-			'id'               => '',
754
-			'title'            => '',
755
-			'value'            => '',
756
-			// can be an array or a string
757
-			'required'         => false,
758
-			'label'            => '',
759
-			'label_after'      => false,
760
-			'label_type'       => '',
761
-			'label_col'        => '',
762
-			// sets the label type, default: hidden. Options: hidden, top, horizontal, floating
763
-			'label_class'      => '',
764
-			'help_text'        => '',
765
-			'placeholder'      => '',
766
-			'options'          => array(),
767
-			// array or string
768
-			'icon'             => '',
769
-			'multiple'         => false,
770
-			'select2'          => false,
771
-			'no_wrap'          => false,
772
-			'input_group_right' => '',
773
-			'input_group_left' => '',
774
-			'input_group_right_inside' => false, // forces the input group inside the input
775
-			'input_group_left_inside' => false, // forces the input group inside the input
776
-			'element_require'  => '',
777
-			// [%element_id%] == "1"
778
-			'extra_attributes' => array(),
779
-			// an array of extra attributes
780
-			'wrap_attributes'  => array(),
781
-		);
782
-
783
-		/**
784
-		 * Parse incoming $args into an array and merge it with $defaults
785
-		 */
786
-		$args   = wp_parse_args( $args, $defaults );
787
-		$output = '';
788
-
789
-		// for now lets hide floating labels
790
-		if ( $args['label_type'] == 'floating' ) {
791
-			$args['label_type'] = 'hidden';
792
-		}
793
-
794
-		// hidden label option needs to be empty
795
-		$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
796
-
797
-
798
-		$label_after = $args['label_after'];
799
-
800
-		// floating labels need label after
801
-		if ( $args['label_type'] == 'floating' ) {
802
-			$label_after         = true;
803
-			$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
804
-		}
805
-
806
-		// Maybe setup select2
807
-		$is_select2 = false;
808
-		if ( ! empty( $args['select2'] ) ) {
809
-			$args['class'] .= ' aui-select2';
810
-			$is_select2 = true;
811
-		} elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) {
812
-			$is_select2 = true;
813
-		}
814
-
815
-		// select2 tags
816
-		if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason
817
-			$args['data-tags']             = 'true';
818
-			$args['data-token-separators'] = "[',']";
819
-			$args['multiple']              = true;
820
-		}
821
-
822
-		// select2 placeholder
823
-		if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) {
824
-			$args['data-placeholder'] = esc_attr( $args['placeholder'] );
825
-			$args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true;
826
-		}
827
-
828
-		// Set hidden input to save empty value for multiselect.
829
-		if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) {
830
-			$output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>';
831
-		}
832
-
833
-		// open/type
834
-		$output .= '<select ';
835
-
836
-		// style
837
-		if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) {
838
-			$output .= " style='width:100%;' ";
839
-		}
840
-
841
-		// element require
842
-		if ( ! empty( $args['element_require'] ) ) {
843
-			$output .= AUI_Component_Helper::element_require( $args['element_require'] );
844
-			$args['class'] .= " aui-conditional-field";
845
-		}
846
-
847
-		// class
848
-		$class = ! empty( $args['class'] ) ? $args['class'] : '';
849
-		$output .= AUI_Component_Helper::class_attr( 'custom-select ' . $class );
850
-
851
-		// name
852
-		if ( ! empty( $args['name'] ) ) {
853
-			$output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] );
854
-		}
855
-
856
-		// id
857
-		if ( ! empty( $args['id'] ) ) {
858
-			$output .= AUI_Component_Helper::id( $args['id'] );
859
-		}
860
-
861
-		// title
862
-		if ( ! empty( $args['title'] ) ) {
863
-			$output .= AUI_Component_Helper::title( $args['title'] );
864
-		}
865
-
866
-		// data-attributes
867
-		$output .= AUI_Component_Helper::data_attributes( $args );
868
-
869
-		// aria-attributes
870
-		$output .= AUI_Component_Helper::aria_attributes( $args );
871
-
872
-		// extra attributes
873
-		if ( ! empty( $args['extra_attributes'] ) ) {
874
-			$output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
875
-		}
876
-
877
-		// required
878
-		if ( ! empty( $args['required'] ) ) {
879
-			$output .= ' required ';
880
-		}
881
-
882
-		// multiple
883
-		if ( ! empty( $args['multiple'] ) ) {
884
-			$output .= ' multiple ';
885
-		}
886
-
887
-		// close opening tag
888
-		$output .= ' >';
889
-
890
-		// placeholder
891
-		if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) {
892
-			$output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>';
893
-		} elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) {
894
-			$output .= "<option></option>"; // select2 needs an empty select to fill the placeholder
895
-		}
896
-
897
-		// Options
898
-		if ( ! empty( $args['options'] ) ) {
899
-
900
-			if ( ! is_array( $args['options'] ) ) {
901
-				$output .= $args['options']; // not the preferred way but an option
902
-			} else {
903
-				foreach ( $args['options'] as $val => $name ) {
904
-					$selected = '';
905
-					if ( is_array( $name ) ) {
906
-						if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) {
907
-							$option_label = isset( $name['label'] ) ? $name['label'] : '';
908
-
909
-							$output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>';
910
-						} else {
911
-							$option_label = isset( $name['label'] ) ? $name['label'] : '';
912
-							$option_value = isset( $name['value'] ) ? $name['value'] : '';
913
-							$extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : '';
914
-							if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) {
915
-								$selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : "";
916
-							} elseif ( ! empty( $args['value'] ) ) {
917
-								$selected = selected( $option_value, stripslashes_deep( $args['value'] ), false );
918
-							} elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) {
919
-								$selected = selected( $option_value, $args['value'], false );
920
-							}
921
-
922
-							$output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>';
923
-						}
924
-					} else {
925
-						if ( ! empty( $args['value'] ) ) {
926
-							if ( is_array( $args['value'] ) ) {
927
-								$selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : '';
928
-							} elseif ( ! empty( $args['value'] ) ) {
929
-								$selected = selected( $args['value'], $val, false );
930
-							}
931
-						} elseif ( $args['value'] === $val ) {
932
-							$selected = selected( $args['value'], $val, false );
933
-						}
934
-						$output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>';
935
-					}
936
-				}
937
-			}
938
-
939
-		}
940
-
941
-		// closing tag
942
-		$output .= '</select>';
943
-
944
-		$label = '';
945
-		$help_text = '';
946
-		// label
947
-		if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
948
-		} elseif ( ! empty( $args['label'] ) && ! $label_after ) {
949
-			$label_args = array(
950
-				'title'      => $args['label'],
951
-				'for'        => $args['id'],
952
-				'class'      => $args['label_class'] . " ",
953
-				'label_type' => $args['label_type'],
954
-				'label_col'  => $args['label_col']
955
-			);
956
-			$label = self::label( $label_args );
957
-		}
958
-
959
-		// help text
960
-		if ( ! empty( $args['help_text'] ) ) {
961
-			$help_text = AUI_Component_Helper::help_text( $args['help_text'] );
962
-		}
963
-
964
-		// input group wraps
965
-		if ( $args['input_group_left'] || $args['input_group_right'] ) {
966
-			$w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
967
-			if ( $args['input_group_left'] ) {
968
-				$output = self::wrap( array(
969
-					'content'                 => $output,
970
-					'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
971
-					'input_group_left'        => $args['input_group_left'],
972
-					'input_group_left_inside' => $args['input_group_left_inside']
973
-				) );
974
-			}
975
-			if ( $args['input_group_right'] ) {
976
-				$output = self::wrap( array(
977
-					'content'                  => $output,
978
-					'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
979
-					'input_group_right'        => $args['input_group_right'],
980
-					'input_group_right_inside' => $args['input_group_right_inside']
981
-				) );
982
-			}
983
-
984
-		}
985
-
986
-		if ( ! $label_after ) {
987
-			$output .= $help_text;
988
-		}
989
-
990
-
991
-		if ( $args['label_type'] == 'horizontal' ) {
992
-			$output = self::wrap( array(
993
-				'content' => $output,
994
-				'class'   => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' )
995
-			) );
996
-		}
997
-
998
-		if ( ! $label_after ) {
999
-			$output = $label . $output;
1000
-		}
1001
-
1002
-		// maybe horizontal label
297
+            }
298
+
299
+            // input group wraps
300
+            if ( $args['input_group_left'] || $args['input_group_right'] ) {
301
+                $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
302
+                $group_size = $size == 'lg' ? ' input-group-lg' : '';
303
+                $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size;
304
+
305
+                if ( $args['input_group_left'] ) {
306
+                    $output = self::wrap( array(
307
+                        'content'                 => $output,
308
+                        'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size,
309
+                        'input_group_left'        => $args['input_group_left'],
310
+                        'input_group_left_inside' => $args['input_group_left_inside']
311
+                    ) );
312
+                }
313
+                if ( $args['input_group_right'] ) {
314
+                    $output = self::wrap( array(
315
+                        'content'                  => $output,
316
+                        'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size,
317
+                        'input_group_right'        => $args['input_group_right'],
318
+                        'input_group_right_inside' => $args['input_group_right_inside']
319
+                    ) );
320
+                }
321
+
322
+            }
323
+
324
+            if ( ! $label_after ) {
325
+                $output .= $help_text;
326
+            }
327
+
328
+
329
+            if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) {
330
+                $output = self::wrap( array(
331
+                    'content' => $output,
332
+                    'class'   => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' )
333
+                ) );
334
+            }
335
+
336
+            if ( ! $label_after ) {
337
+                $output = $label . $output;
338
+            }
339
+
340
+            // wrap
341
+            if ( ! $args['no_wrap'] ) {
342
+                $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group';
343
+                $wrap_class       = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class;
344
+                $wrap_class       = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
345
+                $output           = self::wrap( array(
346
+                    'content'         => $output,
347
+                    'class'           => $wrap_class,
348
+                    'element_require' => $args['element_require'],
349
+                    'argument_id'     => $args['id'],
350
+                    'wrap_attributes' => $args['wrap_attributes'],
351
+                ) );
352
+            }
353
+        }
354
+
355
+        return $output;
356
+    }
357
+
358
+    public static function label( $args = array(), $type = '' ) {
359
+        //<label for="exampleInputEmail1">Email address</label>
360
+        $defaults = array(
361
+            'title'      => 'div',
362
+            'for'        => '',
363
+            'class'      => '',
364
+            'label_type' => '', // empty = hidden, top, horizontal
365
+            'label_col'  => '',
366
+        );
367
+
368
+        /**
369
+         * Parse incoming $args into an array and merge it with $defaults
370
+         */
371
+        $args   = wp_parse_args( $args, $defaults );
372
+        $output = '';
373
+
374
+        if ( $args['title'] ) {
375
+
376
+            // maybe hide labels //@todo set a global option for visibility class
377
+            if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) {
378
+                $class = $args['class'];
379
+            } else {
380
+                $class = 'sr-only ' . $args['class'];
381
+            }
382
+
383
+            // maybe horizontal
384
+            if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) {
385
+                $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label';
386
+            }
387
+
388
+            // open
389
+            $output .= '<label ';
390
+
391
+            // for
392
+            if ( ! empty( $args['for'] ) ) {
393
+                $output .= ' for="' . esc_attr( $args['for'] ) . '" ';
394
+            }
395
+
396
+            // class
397
+            $class = $class ? AUI_Component_Helper::esc_classes( $class ) : '';
398
+            $output .= ' class="' . $class . '" ';
399
+
400
+            // close
401
+            $output .= '>';
402
+
403
+
404
+            // title, don't escape fully as can contain html
405
+            if ( ! empty( $args['title'] ) ) {
406
+                $output .= wp_kses_post( $args['title'] );
407
+            }
408
+
409
+            // close wrap
410
+            $output .= '</label>';
411
+
412
+
413
+        }
414
+
415
+
416
+        return $output;
417
+    }
418
+
419
+    /**
420
+     * Wrap some content in a HTML wrapper.
421
+     *
422
+     * @param array $args
423
+     *
424
+     * @return string
425
+     */
426
+    public static function wrap( $args = array() ) {
427
+        $defaults = array(
428
+            'type'                     => 'div',
429
+            'class'                    => 'form-group',
430
+            'content'                  => '',
431
+            'input_group_left'         => '',
432
+            'input_group_right'        => '',
433
+            'input_group_left_inside'  => false,
434
+            'input_group_right_inside' => false,
435
+            'element_require'          => '',
436
+            'argument_id'              => '',
437
+            'wrap_attributes'          => array()
438
+        );
439
+
440
+        /**
441
+         * Parse incoming $args into an array and merge it with $defaults
442
+         */
443
+        $args   = wp_parse_args( $args, $defaults );
444
+        $output = '';
445
+        if ( $args['type'] ) {
446
+
447
+            // open
448
+            $output .= '<' . sanitize_html_class( $args['type'] );
449
+
450
+            // element require
451
+            if ( ! empty( $args['element_require'] ) ) {
452
+                $output .= AUI_Component_Helper::element_require( $args['element_require'] );
453
+                $args['class'] .= " aui-conditional-field";
454
+            }
455
+
456
+            // argument_id
457
+            if ( ! empty( $args['argument_id'] ) ) {
458
+                $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"';
459
+            }
460
+
461
+            // class
462
+            $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
463
+            $output .= ' class="' . $class . '" ';
464
+
465
+            // Attributes
466
+            if ( ! empty( $args['wrap_attributes'] ) ) {
467
+                $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] );
468
+            }
469
+
470
+            // close wrap
471
+            $output .= ' >';
472
+
473
+
474
+            // Input group left
475
+            if ( ! empty( $args['input_group_left'] ) ) {
476
+                $position_class   = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : '';
477
+                $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>';
478
+                $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>';
479
+            }
480
+
481
+            // content
482
+            $output .= $args['content'];
483
+
484
+            // Input group right
485
+            if ( ! empty( $args['input_group_right'] ) ) {
486
+                $position_class    = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : '';
487
+                $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>';
488
+                $output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>';
489
+            }
490
+
491
+
492
+            // close wrap
493
+            $output .= '</' . sanitize_html_class( $args['type'] ) . '>';
494
+
495
+
496
+        } else {
497
+            $output = $args['content'];
498
+        }
499
+
500
+        return $output;
501
+    }
502
+
503
+    /**
504
+     * Build the component.
505
+     *
506
+     * @param array $args
507
+     *
508
+     * @return string The rendered component.
509
+     */
510
+    public static function textarea( $args = array() ) {
511
+        $defaults = array(
512
+            'name'               => '',
513
+            'class'              => '',
514
+            'wrap_class'         => '',
515
+            'id'                 => '',
516
+            'placeholder'        => '',
517
+            'title'              => '',
518
+            'value'              => '',
519
+            'required'           => false,
520
+            'label'              => '',
521
+            'label_after'        => false,
522
+            'label_class'        => '',
523
+            'label_type'         => '',
524
+            'label_col'          => '',
525
+            // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
526
+            'input_group_right'        => '',
527
+            'input_group_left'         => '',
528
+            'input_group_right_inside' => false,
529
+            'help_text'          => '',
530
+            'validation_text'    => '',
531
+            'validation_pattern' => '',
532
+            'no_wrap'            => false,
533
+            'rows'               => '',
534
+            'wysiwyg'            => false,
535
+            'allow_tags'         => false,
536
+            // Allow HTML tags
537
+            'element_require'    => '',
538
+            // [%element_id%] == "1"
539
+            'extra_attributes'   => array(),
540
+            // an array of extra attributes
541
+            'wrap_attributes'    => array(),
542
+        );
543
+
544
+        /**
545
+         * Parse incoming $args into an array and merge it with $defaults
546
+         */
547
+        $args   = wp_parse_args( $args, $defaults );
548
+        $output = '';
549
+
550
+        // hidden label option needs to be empty
551
+        $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
552
+
553
+        // floating labels don't work with wysiwyg so set it as top
554
+        if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) {
555
+            $args['label_type'] = 'top';
556
+        }
557
+
558
+        $label_after = $args['label_after'];
559
+
560
+        // floating labels need label after
561
+        if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) {
562
+            $label_after         = true;
563
+            $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
564
+        }
565
+
566
+        // label
567
+        if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
568
+        } elseif ( ! empty( $args['label'] ) && ! $label_after ) {
569
+            $label_args = array(
570
+                'title'      => $args['label'],
571
+                'for'        => $args['id'],
572
+                'class'      => $args['label_class'] . " ",
573
+                'label_type' => $args['label_type'],
574
+                'label_col'  => $args['label_col']
575
+            );
576
+            $output .= self::label( $label_args );
577
+        }
578
+
579
+        // maybe horizontal label
580
+        if ( $args['label_type'] == 'horizontal' ) {
581
+            $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
582
+            $output .= '<div class="' . $input_col . '">';
583
+        }
584
+
585
+        if ( ! empty( $args['wysiwyg'] ) ) {
586
+            ob_start();
587
+            $content   = $args['value'];
588
+            $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor';
589
+            $settings  = array(
590
+                'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4,
591
+                'quicktags'     => false,
592
+                'media_buttons' => false,
593
+                'editor_class'  => 'form-control',
594
+                'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ),
595
+                'teeny'         => true,
596
+            );
597
+
598
+            // maybe set settings if array
599
+            if ( is_array( $args['wysiwyg'] ) ) {
600
+                $settings = wp_parse_args( $args['wysiwyg'], $settings );
601
+            }
602
+
603
+            wp_editor( $content, $editor_id, $settings );
604
+            $output .= ob_get_clean();
605
+        } else {
606
+
607
+            // open
608
+            $output .= '<textarea ';
609
+
610
+            // name
611
+            if ( ! empty( $args['name'] ) ) {
612
+                $output .= ' name="' . esc_attr( $args['name'] ) . '" ';
613
+            }
614
+
615
+            // id
616
+            if ( ! empty( $args['id'] ) ) {
617
+                $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" ';
618
+            }
619
+
620
+            // placeholder
621
+            if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) {
622
+                $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" ';
623
+            }
624
+
625
+            // title
626
+            if ( ! empty( $args['title'] ) ) {
627
+                $output .= ' title="' . esc_attr( $args['title'] ) . '" ';
628
+            }
629
+
630
+            // validation text
631
+            if ( ! empty( $args['validation_text'] ) ) {
632
+                $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" ';
633
+                $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
634
+            }
635
+
636
+            // validation_pattern
637
+            if ( ! empty( $args['validation_pattern'] ) ) {
638
+                $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" ';
639
+            }
640
+
641
+            // required
642
+            if ( ! empty( $args['required'] ) ) {
643
+                $output .= ' required ';
644
+            }
645
+
646
+            // rows
647
+            if ( ! empty( $args['rows'] ) ) {
648
+                $output .= ' rows="' . absint( $args['rows'] ) . '" ';
649
+            }
650
+
651
+
652
+            // class
653
+            $class = ! empty( $args['class'] ) ? $args['class'] : '';
654
+            $output .= ' class="form-control ' . $class . '" ';
655
+
656
+            // extra attributes
657
+            if ( ! empty( $args['extra_attributes'] ) ) {
658
+                $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
659
+            }
660
+
661
+            // close tag
662
+            $output .= ' >';
663
+
664
+            // value
665
+            if ( ! empty( $args['value'] ) ) {
666
+                if ( ! empty( $args['allow_tags'] ) ) {
667
+                    $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML.
668
+                } else {
669
+                    $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] );
670
+                }
671
+            }
672
+
673
+            // closing tag
674
+            $output .= '</textarea>';
675
+
676
+
677
+            // input group wraps
678
+            if ( $args['input_group_left'] || $args['input_group_right'] ) {
679
+                $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
680
+                if ( $args['input_group_left'] ) {
681
+                    $output = self::wrap( array(
682
+                        'content'                 => $output,
683
+                        'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
684
+                        'input_group_left'        => $args['input_group_left'],
685
+                        'input_group_left_inside' => $args['input_group_left_inside']
686
+                    ) );
687
+                }
688
+                if ( $args['input_group_right'] ) {
689
+                    $output = self::wrap( array(
690
+                        'content'                  => $output,
691
+                        'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
692
+                        'input_group_right'        => $args['input_group_right'],
693
+                        'input_group_right_inside' => $args['input_group_right_inside']
694
+                    ) );
695
+                }
696
+
697
+            }
698
+
699
+
700
+        }
701
+
702
+        if ( ! empty( $args['label'] ) && $label_after ) {
703
+            $label_args = array(
704
+                'title'      => $args['label'],
705
+                'for'        => $args['id'],
706
+                'class'      => $args['label_class'] . " ",
707
+                'label_type' => $args['label_type'],
708
+                'label_col'  => $args['label_col']
709
+            );
710
+            $output .= self::label( $label_args );
711
+        }
712
+
713
+        // help text
714
+        if ( ! empty( $args['help_text'] ) ) {
715
+            $output .= AUI_Component_Helper::help_text( $args['help_text'] );
716
+        }
717
+
718
+        // maybe horizontal label
719
+        if ( $args['label_type'] == 'horizontal' ) {
720
+            $output .= '</div>';
721
+        }
722
+
723
+
724
+        // wrap
725
+        if ( ! $args['no_wrap'] ) {
726
+            $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : 'form-group';
727
+            $wrap_class       = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class;
728
+            $wrap_class       = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
729
+            $output           = self::wrap( array(
730
+                'content'         => $output,
731
+                'class'           => $wrap_class,
732
+                'element_require' => $args['element_require'],
733
+                'argument_id'     => $args['id'],
734
+                'wrap_attributes' => $args['wrap_attributes'],
735
+            ) );
736
+        }
737
+
738
+
739
+        return $output;
740
+    }
741
+
742
+    /**
743
+     * Build the component.
744
+     *
745
+     * @param array $args
746
+     *
747
+     * @return string The rendered component.
748
+     */
749
+    public static function select( $args = array() ) {
750
+        $defaults = array(
751
+            'class'            => '',
752
+            'wrap_class'       => '',
753
+            'id'               => '',
754
+            'title'            => '',
755
+            'value'            => '',
756
+            // can be an array or a string
757
+            'required'         => false,
758
+            'label'            => '',
759
+            'label_after'      => false,
760
+            'label_type'       => '',
761
+            'label_col'        => '',
762
+            // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
763
+            'label_class'      => '',
764
+            'help_text'        => '',
765
+            'placeholder'      => '',
766
+            'options'          => array(),
767
+            // array or string
768
+            'icon'             => '',
769
+            'multiple'         => false,
770
+            'select2'          => false,
771
+            'no_wrap'          => false,
772
+            'input_group_right' => '',
773
+            'input_group_left' => '',
774
+            'input_group_right_inside' => false, // forces the input group inside the input
775
+            'input_group_left_inside' => false, // forces the input group inside the input
776
+            'element_require'  => '',
777
+            // [%element_id%] == "1"
778
+            'extra_attributes' => array(),
779
+            // an array of extra attributes
780
+            'wrap_attributes'  => array(),
781
+        );
782
+
783
+        /**
784
+         * Parse incoming $args into an array and merge it with $defaults
785
+         */
786
+        $args   = wp_parse_args( $args, $defaults );
787
+        $output = '';
788
+
789
+        // for now lets hide floating labels
790
+        if ( $args['label_type'] == 'floating' ) {
791
+            $args['label_type'] = 'hidden';
792
+        }
793
+
794
+        // hidden label option needs to be empty
795
+        $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
796
+
797
+
798
+        $label_after = $args['label_after'];
799
+
800
+        // floating labels need label after
801
+        if ( $args['label_type'] == 'floating' ) {
802
+            $label_after         = true;
803
+            $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
804
+        }
805
+
806
+        // Maybe setup select2
807
+        $is_select2 = false;
808
+        if ( ! empty( $args['select2'] ) ) {
809
+            $args['class'] .= ' aui-select2';
810
+            $is_select2 = true;
811
+        } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) {
812
+            $is_select2 = true;
813
+        }
814
+
815
+        // select2 tags
816
+        if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason
817
+            $args['data-tags']             = 'true';
818
+            $args['data-token-separators'] = "[',']";
819
+            $args['multiple']              = true;
820
+        }
821
+
822
+        // select2 placeholder
823
+        if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) {
824
+            $args['data-placeholder'] = esc_attr( $args['placeholder'] );
825
+            $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true;
826
+        }
827
+
828
+        // Set hidden input to save empty value for multiselect.
829
+        if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) {
830
+            $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>';
831
+        }
832
+
833
+        // open/type
834
+        $output .= '<select ';
835
+
836
+        // style
837
+        if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) {
838
+            $output .= " style='width:100%;' ";
839
+        }
840
+
841
+        // element require
842
+        if ( ! empty( $args['element_require'] ) ) {
843
+            $output .= AUI_Component_Helper::element_require( $args['element_require'] );
844
+            $args['class'] .= " aui-conditional-field";
845
+        }
846
+
847
+        // class
848
+        $class = ! empty( $args['class'] ) ? $args['class'] : '';
849
+        $output .= AUI_Component_Helper::class_attr( 'custom-select ' . $class );
850
+
851
+        // name
852
+        if ( ! empty( $args['name'] ) ) {
853
+            $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] );
854
+        }
855
+
856
+        // id
857
+        if ( ! empty( $args['id'] ) ) {
858
+            $output .= AUI_Component_Helper::id( $args['id'] );
859
+        }
860
+
861
+        // title
862
+        if ( ! empty( $args['title'] ) ) {
863
+            $output .= AUI_Component_Helper::title( $args['title'] );
864
+        }
865
+
866
+        // data-attributes
867
+        $output .= AUI_Component_Helper::data_attributes( $args );
868
+
869
+        // aria-attributes
870
+        $output .= AUI_Component_Helper::aria_attributes( $args );
871
+
872
+        // extra attributes
873
+        if ( ! empty( $args['extra_attributes'] ) ) {
874
+            $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
875
+        }
876
+
877
+        // required
878
+        if ( ! empty( $args['required'] ) ) {
879
+            $output .= ' required ';
880
+        }
881
+
882
+        // multiple
883
+        if ( ! empty( $args['multiple'] ) ) {
884
+            $output .= ' multiple ';
885
+        }
886
+
887
+        // close opening tag
888
+        $output .= ' >';
889
+
890
+        // placeholder
891
+        if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) {
892
+            $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>';
893
+        } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) {
894
+            $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder
895
+        }
896
+
897
+        // Options
898
+        if ( ! empty( $args['options'] ) ) {
899
+
900
+            if ( ! is_array( $args['options'] ) ) {
901
+                $output .= $args['options']; // not the preferred way but an option
902
+            } else {
903
+                foreach ( $args['options'] as $val => $name ) {
904
+                    $selected = '';
905
+                    if ( is_array( $name ) ) {
906
+                        if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) {
907
+                            $option_label = isset( $name['label'] ) ? $name['label'] : '';
908
+
909
+                            $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>';
910
+                        } else {
911
+                            $option_label = isset( $name['label'] ) ? $name['label'] : '';
912
+                            $option_value = isset( $name['value'] ) ? $name['value'] : '';
913
+                            $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : '';
914
+                            if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) {
915
+                                $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : "";
916
+                            } elseif ( ! empty( $args['value'] ) ) {
917
+                                $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false );
918
+                            } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) {
919
+                                $selected = selected( $option_value, $args['value'], false );
920
+                            }
921
+
922
+                            $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>';
923
+                        }
924
+                    } else {
925
+                        if ( ! empty( $args['value'] ) ) {
926
+                            if ( is_array( $args['value'] ) ) {
927
+                                $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : '';
928
+                            } elseif ( ! empty( $args['value'] ) ) {
929
+                                $selected = selected( $args['value'], $val, false );
930
+                            }
931
+                        } elseif ( $args['value'] === $val ) {
932
+                            $selected = selected( $args['value'], $val, false );
933
+                        }
934
+                        $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>';
935
+                    }
936
+                }
937
+            }
938
+
939
+        }
940
+
941
+        // closing tag
942
+        $output .= '</select>';
943
+
944
+        $label = '';
945
+        $help_text = '';
946
+        // label
947
+        if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
948
+        } elseif ( ! empty( $args['label'] ) && ! $label_after ) {
949
+            $label_args = array(
950
+                'title'      => $args['label'],
951
+                'for'        => $args['id'],
952
+                'class'      => $args['label_class'] . " ",
953
+                'label_type' => $args['label_type'],
954
+                'label_col'  => $args['label_col']
955
+            );
956
+            $label = self::label( $label_args );
957
+        }
958
+
959
+        // help text
960
+        if ( ! empty( $args['help_text'] ) ) {
961
+            $help_text = AUI_Component_Helper::help_text( $args['help_text'] );
962
+        }
963
+
964
+        // input group wraps
965
+        if ( $args['input_group_left'] || $args['input_group_right'] ) {
966
+            $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
967
+            if ( $args['input_group_left'] ) {
968
+                $output = self::wrap( array(
969
+                    'content'                 => $output,
970
+                    'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
971
+                    'input_group_left'        => $args['input_group_left'],
972
+                    'input_group_left_inside' => $args['input_group_left_inside']
973
+                ) );
974
+            }
975
+            if ( $args['input_group_right'] ) {
976
+                $output = self::wrap( array(
977
+                    'content'                  => $output,
978
+                    'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
979
+                    'input_group_right'        => $args['input_group_right'],
980
+                    'input_group_right_inside' => $args['input_group_right_inside']
981
+                ) );
982
+            }
983
+
984
+        }
985
+
986
+        if ( ! $label_after ) {
987
+            $output .= $help_text;
988
+        }
989
+
990
+
991
+        if ( $args['label_type'] == 'horizontal' ) {
992
+            $output = self::wrap( array(
993
+                'content' => $output,
994
+                'class'   => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' )
995
+            ) );
996
+        }
997
+
998
+        if ( ! $label_after ) {
999
+            $output = $label . $output;
1000
+        }
1001
+
1002
+        // maybe horizontal label
1003 1003
 //		if ( $args['label_type'] == 'horizontal' ) {
1004 1004
 //			$output .= '</div>';
1005 1005
 //		}
1006 1006
 
1007 1007
 
1008
-		// wrap
1009
-		if ( ! $args['no_wrap'] ) {
1010
-			$wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group';
1011
-			$wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
1012
-			$output     = self::wrap( array(
1013
-				'content'         => $output,
1014
-				'class'           => $wrap_class,
1015
-				'element_require' => $args['element_require'],
1016
-				'argument_id'     => $args['id'],
1017
-				'wrap_attributes' => $args['wrap_attributes'],
1018
-			) );
1019
-		}
1020
-
1021
-
1022
-		return $output;
1023
-	}
1024
-
1025
-	/**
1026
-	 * Build the component.
1027
-	 *
1028
-	 * @param array $args
1029
-	 *
1030
-	 * @return string The rendered component.
1031
-	 */
1032
-	public static function radio( $args = array() ) {
1033
-		$defaults = array(
1034
-			'class'            => '',
1035
-			'wrap_class'       => '',
1036
-			'id'               => '',
1037
-			'title'            => '',
1038
-			'horizontal'       => false,
1039
-			// sets the lable horizontal
1040
-			'value'            => '',
1041
-			'label'            => '',
1042
-			'label_class'      => '',
1043
-			'label_type'       => '',
1044
-			'label_col'        => '',
1045
-			// sets the label type, default: hidden. Options: hidden, top, horizontal, floating
1046
-			'help_text'        => '',
1047
-			'inline'           => true,
1048
-			'required'         => false,
1049
-			'options'          => array(),
1050
-			'icon'             => '',
1051
-			'no_wrap'          => false,
1052
-			'element_require'  => '',
1053
-			// [%element_id%] == "1"
1054
-			'extra_attributes' => array(),
1055
-			// an array of extra attributes
1056
-			'wrap_attributes'  => array()
1057
-		);
1058
-
1059
-		/**
1060
-		 * Parse incoming $args into an array and merge it with $defaults
1061
-		 */
1062
-		$args = wp_parse_args( $args, $defaults );
1063
-
1064
-		// for now lets use horizontal for floating
1065
-		if ( $args['label_type'] == 'floating' ) {
1066
-			$args['label_type'] = 'horizontal';
1067
-		}
1068
-
1069
-		$label_args = array(
1070
-			'title'      => $args['label'],
1071
-			'class'      => $args['label_class'] . " pt-0 ",
1072
-			'label_type' => $args['label_type'],
1073
-			'label_col'  => $args['label_col']
1074
-		);
1075
-
1076
-		$output = '';
1077
-
1078
-
1079
-		// label before
1080
-		if ( ! empty( $args['label'] ) ) {
1081
-			$output .= self::label( $label_args, 'radio' );
1082
-		}
1083
-
1084
-		// maybe horizontal label
1085
-		if ( $args['label_type'] == 'horizontal' ) {
1086
-			$input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
1087
-			$output .= '<div class="' . $input_col . '">';
1088
-		}
1089
-
1090
-		if ( ! empty( $args['options'] ) ) {
1091
-			$count = 0;
1092
-			foreach ( $args['options'] as $value => $label ) {
1093
-				$option_args            = $args;
1094
-				$option_args['value']   = $value;
1095
-				$option_args['label']   = $label;
1096
-				$option_args['checked'] = $value == $args['value'] ? true : false;
1097
-				$output .= self::radio_option( $option_args, $count );
1098
-				$count ++;
1099
-			}
1100
-		}
1101
-
1102
-		// help text
1103
-		$help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : '';
1104
-		$output .= $help_text;
1105
-
1106
-		// maybe horizontal label
1107
-		if ( $args['label_type'] == 'horizontal' ) {
1108
-			$output .= '</div>';
1109
-		}
1110
-
1111
-		// wrap
1112
-		$wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group';
1113
-		$wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
1114
-		$output     = self::wrap( array(
1115
-			'content'         => $output,
1116
-			'class'           => $wrap_class,
1117
-			'element_require' => $args['element_require'],
1118
-			'argument_id'     => $args['id'],
1119
-			'wrap_attributes' => $args['wrap_attributes'],
1120
-		) );
1121
-
1122
-
1123
-		return $output;
1124
-	}
1125
-
1126
-	/**
1127
-	 * Build the component.
1128
-	 *
1129
-	 * @param array $args
1130
-	 *
1131
-	 * @return string The rendered component.
1132
-	 */
1133
-	public static function radio_option( $args = array(), $count = '' ) {
1134
-		$defaults = array(
1135
-			'class'            => '',
1136
-			'id'               => '',
1137
-			'title'            => '',
1138
-			'value'            => '',
1139
-			'required'         => false,
1140
-			'inline'           => true,
1141
-			'label'            => '',
1142
-			'options'          => array(),
1143
-			'icon'             => '',
1144
-			'no_wrap'          => false,
1145
-			'extra_attributes' => array() // an array of extra attributes
1146
-		);
1147
-
1148
-		/**
1149
-		 * Parse incoming $args into an array and merge it with $defaults
1150
-		 */
1151
-		$args = wp_parse_args( $args, $defaults );
1152
-
1153
-		$output = '';
1154
-
1155
-		// open/type
1156
-		$output .= '<input type="radio"';
1157
-
1158
-		// class
1159
-		$output .= ' class="form-check-input" ';
1160
-
1161
-		// name
1162
-		if ( ! empty( $args['name'] ) ) {
1163
-			$output .= AUI_Component_Helper::name( $args['name'] );
1164
-		}
1165
-
1166
-		// id
1167
-		if ( ! empty( $args['id'] ) ) {
1168
-			$output .= AUI_Component_Helper::id( $args['id'] . $count );
1169
-		}
1170
-
1171
-		// title
1172
-		if ( ! empty( $args['title'] ) ) {
1173
-			$output .= AUI_Component_Helper::title( $args['title'] );
1174
-		}
1175
-
1176
-		// value
1177
-		if ( isset( $args['value'] ) ) {
1178
-			$output .= AUI_Component_Helper::value( $args['value'] );
1179
-		}
1180
-
1181
-		// checked, for radio and checkboxes
1182
-		if ( $args['checked'] ) {
1183
-			$output .= ' checked ';
1184
-		}
1185
-
1186
-		// data-attributes
1187
-		$output .= AUI_Component_Helper::data_attributes( $args );
1188
-
1189
-		// aria-attributes
1190
-		$output .= AUI_Component_Helper::aria_attributes( $args );
1191
-
1192
-		// extra attributes
1193
-		if ( ! empty( $args['extra_attributes'] ) ) {
1194
-			$output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
1195
-		}
1196
-
1197
-		// required
1198
-		if ( ! empty( $args['required'] ) ) {
1199
-			$output .= ' required ';
1200
-		}
1201
-
1202
-		// close opening tag
1203
-		$output .= ' >';
1204
-
1205
-		// label
1206
-		if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
1207
-		} elseif ( ! empty( $args['label'] ) ) {
1208
-			$output .= self::label( array(
1209
-				'title' => $args['label'],
1210
-				'for'   => $args['id'] . $count,
1211
-				'class' => 'form-check-label'
1212
-			), 'radio' );
1213
-		}
1214
-
1215
-		// wrap
1216
-		if ( ! $args['no_wrap'] ) {
1217
-			$wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check';
1218
-
1219
-			// Unique wrap class
1220
-			$uniq_class = 'fwrap';
1221
-			if ( ! empty( $args['name'] ) ) {
1222
-				$uniq_class .= '-' . $args['name'];
1223
-			} else if ( ! empty( $args['id'] ) ) {
1224
-				$uniq_class .= '-' . $args['id'];
1225
-			}
1226
-
1227
-			if ( isset( $args['value'] ) || $args['value'] !== "" ) {
1228
-				$uniq_class .= '-' . $args['value'];
1229
-			} else {
1230
-				$uniq_class .= '-' . $count;
1231
-			}
1232
-			$wrap_class .= ' ' . sanitize_html_class( $uniq_class );
1233
-
1234
-			$output = self::wrap( array(
1235
-				'content' => $output,
1236
-				'class'   => $wrap_class
1237
-			) );
1238
-		}
1239
-
1240
-		return $output;
1241
-	}
1008
+        // wrap
1009
+        if ( ! $args['no_wrap'] ) {
1010
+            $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group';
1011
+            $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
1012
+            $output     = self::wrap( array(
1013
+                'content'         => $output,
1014
+                'class'           => $wrap_class,
1015
+                'element_require' => $args['element_require'],
1016
+                'argument_id'     => $args['id'],
1017
+                'wrap_attributes' => $args['wrap_attributes'],
1018
+            ) );
1019
+        }
1020
+
1021
+
1022
+        return $output;
1023
+    }
1024
+
1025
+    /**
1026
+     * Build the component.
1027
+     *
1028
+     * @param array $args
1029
+     *
1030
+     * @return string The rendered component.
1031
+     */
1032
+    public static function radio( $args = array() ) {
1033
+        $defaults = array(
1034
+            'class'            => '',
1035
+            'wrap_class'       => '',
1036
+            'id'               => '',
1037
+            'title'            => '',
1038
+            'horizontal'       => false,
1039
+            // sets the lable horizontal
1040
+            'value'            => '',
1041
+            'label'            => '',
1042
+            'label_class'      => '',
1043
+            'label_type'       => '',
1044
+            'label_col'        => '',
1045
+            // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
1046
+            'help_text'        => '',
1047
+            'inline'           => true,
1048
+            'required'         => false,
1049
+            'options'          => array(),
1050
+            'icon'             => '',
1051
+            'no_wrap'          => false,
1052
+            'element_require'  => '',
1053
+            // [%element_id%] == "1"
1054
+            'extra_attributes' => array(),
1055
+            // an array of extra attributes
1056
+            'wrap_attributes'  => array()
1057
+        );
1058
+
1059
+        /**
1060
+         * Parse incoming $args into an array and merge it with $defaults
1061
+         */
1062
+        $args = wp_parse_args( $args, $defaults );
1063
+
1064
+        // for now lets use horizontal for floating
1065
+        if ( $args['label_type'] == 'floating' ) {
1066
+            $args['label_type'] = 'horizontal';
1067
+        }
1068
+
1069
+        $label_args = array(
1070
+            'title'      => $args['label'],
1071
+            'class'      => $args['label_class'] . " pt-0 ",
1072
+            'label_type' => $args['label_type'],
1073
+            'label_col'  => $args['label_col']
1074
+        );
1075
+
1076
+        $output = '';
1077
+
1078
+
1079
+        // label before
1080
+        if ( ! empty( $args['label'] ) ) {
1081
+            $output .= self::label( $label_args, 'radio' );
1082
+        }
1083
+
1084
+        // maybe horizontal label
1085
+        if ( $args['label_type'] == 'horizontal' ) {
1086
+            $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
1087
+            $output .= '<div class="' . $input_col . '">';
1088
+        }
1089
+
1090
+        if ( ! empty( $args['options'] ) ) {
1091
+            $count = 0;
1092
+            foreach ( $args['options'] as $value => $label ) {
1093
+                $option_args            = $args;
1094
+                $option_args['value']   = $value;
1095
+                $option_args['label']   = $label;
1096
+                $option_args['checked'] = $value == $args['value'] ? true : false;
1097
+                $output .= self::radio_option( $option_args, $count );
1098
+                $count ++;
1099
+            }
1100
+        }
1101
+
1102
+        // help text
1103
+        $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : '';
1104
+        $output .= $help_text;
1105
+
1106
+        // maybe horizontal label
1107
+        if ( $args['label_type'] == 'horizontal' ) {
1108
+            $output .= '</div>';
1109
+        }
1110
+
1111
+        // wrap
1112
+        $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group';
1113
+        $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
1114
+        $output     = self::wrap( array(
1115
+            'content'         => $output,
1116
+            'class'           => $wrap_class,
1117
+            'element_require' => $args['element_require'],
1118
+            'argument_id'     => $args['id'],
1119
+            'wrap_attributes' => $args['wrap_attributes'],
1120
+        ) );
1121
+
1122
+
1123
+        return $output;
1124
+    }
1125
+
1126
+    /**
1127
+     * Build the component.
1128
+     *
1129
+     * @param array $args
1130
+     *
1131
+     * @return string The rendered component.
1132
+     */
1133
+    public static function radio_option( $args = array(), $count = '' ) {
1134
+        $defaults = array(
1135
+            'class'            => '',
1136
+            'id'               => '',
1137
+            'title'            => '',
1138
+            'value'            => '',
1139
+            'required'         => false,
1140
+            'inline'           => true,
1141
+            'label'            => '',
1142
+            'options'          => array(),
1143
+            'icon'             => '',
1144
+            'no_wrap'          => false,
1145
+            'extra_attributes' => array() // an array of extra attributes
1146
+        );
1147
+
1148
+        /**
1149
+         * Parse incoming $args into an array and merge it with $defaults
1150
+         */
1151
+        $args = wp_parse_args( $args, $defaults );
1152
+
1153
+        $output = '';
1154
+
1155
+        // open/type
1156
+        $output .= '<input type="radio"';
1157
+
1158
+        // class
1159
+        $output .= ' class="form-check-input" ';
1160
+
1161
+        // name
1162
+        if ( ! empty( $args['name'] ) ) {
1163
+            $output .= AUI_Component_Helper::name( $args['name'] );
1164
+        }
1165
+
1166
+        // id
1167
+        if ( ! empty( $args['id'] ) ) {
1168
+            $output .= AUI_Component_Helper::id( $args['id'] . $count );
1169
+        }
1170
+
1171
+        // title
1172
+        if ( ! empty( $args['title'] ) ) {
1173
+            $output .= AUI_Component_Helper::title( $args['title'] );
1174
+        }
1175
+
1176
+        // value
1177
+        if ( isset( $args['value'] ) ) {
1178
+            $output .= AUI_Component_Helper::value( $args['value'] );
1179
+        }
1180
+
1181
+        // checked, for radio and checkboxes
1182
+        if ( $args['checked'] ) {
1183
+            $output .= ' checked ';
1184
+        }
1185
+
1186
+        // data-attributes
1187
+        $output .= AUI_Component_Helper::data_attributes( $args );
1188
+
1189
+        // aria-attributes
1190
+        $output .= AUI_Component_Helper::aria_attributes( $args );
1191
+
1192
+        // extra attributes
1193
+        if ( ! empty( $args['extra_attributes'] ) ) {
1194
+            $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
1195
+        }
1196
+
1197
+        // required
1198
+        if ( ! empty( $args['required'] ) ) {
1199
+            $output .= ' required ';
1200
+        }
1201
+
1202
+        // close opening tag
1203
+        $output .= ' >';
1204
+
1205
+        // label
1206
+        if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
1207
+        } elseif ( ! empty( $args['label'] ) ) {
1208
+            $output .= self::label( array(
1209
+                'title' => $args['label'],
1210
+                'for'   => $args['id'] . $count,
1211
+                'class' => 'form-check-label'
1212
+            ), 'radio' );
1213
+        }
1214
+
1215
+        // wrap
1216
+        if ( ! $args['no_wrap'] ) {
1217
+            $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check';
1218
+
1219
+            // Unique wrap class
1220
+            $uniq_class = 'fwrap';
1221
+            if ( ! empty( $args['name'] ) ) {
1222
+                $uniq_class .= '-' . $args['name'];
1223
+            } else if ( ! empty( $args['id'] ) ) {
1224
+                $uniq_class .= '-' . $args['id'];
1225
+            }
1226
+
1227
+            if ( isset( $args['value'] ) || $args['value'] !== "" ) {
1228
+                $uniq_class .= '-' . $args['value'];
1229
+            } else {
1230
+                $uniq_class .= '-' . $count;
1231
+            }
1232
+            $wrap_class .= ' ' . sanitize_html_class( $uniq_class );
1233
+
1234
+            $output = self::wrap( array(
1235
+                'content' => $output,
1236
+                'class'   => $wrap_class
1237
+            ) );
1238
+        }
1239
+
1240
+        return $output;
1241
+    }
1242 1242
 
1243 1243
 }
1244 1244
\ No newline at end of file
Please login to merge, or discard this patch.
includes/reports/class-getpaid-reports-export.php 1 patch
Indentation   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -12,47 +12,47 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Reports_Export {
14 14
 
15
-	/**
16
-	 * Displays the reports tab.
17
-	 *
18
-	 */
19
-	public function display() {
20
-
21
-		echo "<div class='row mt-4' style='max-width: 920px;' >";
22
-		foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
23
-			$this->display_post_type_export( $post_type );
24
-		}
25
-		$this->display_subscription_export();
26
-		echo '</div>';
27
-
28
-	}
29
-
30
-	/**
31
-	 * Retrieves the download url.
32
-	 *
33
-	 */
34
-	public function get_download_url( $post_type ) {
35
-
36
-		return wp_nonce_url(
37
-			add_query_arg(
38
-				array(
39
-					'getpaid-admin-action' => 'export_invoices',
40
-					'post_type'            => urlencode( $post_type ),
41
-				)
42
-			),
43
-			'getpaid-nonce',
44
-			'getpaid-nonce'
45
-		);
46
-
47
-	}
48
-
49
-	/**
50
-	 * Displays a single post type export card.
51
-	 *
52
-	 */
53
-	public function display_post_type_export( $post_type ) {
54
-
55
-		?>
15
+    /**
16
+     * Displays the reports tab.
17
+     *
18
+     */
19
+    public function display() {
20
+
21
+        echo "<div class='row mt-4' style='max-width: 920px;' >";
22
+        foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
23
+            $this->display_post_type_export( $post_type );
24
+        }
25
+        $this->display_subscription_export();
26
+        echo '</div>';
27
+
28
+    }
29
+
30
+    /**
31
+     * Retrieves the download url.
32
+     *
33
+     */
34
+    public function get_download_url( $post_type ) {
35
+
36
+        return wp_nonce_url(
37
+            add_query_arg(
38
+                array(
39
+                    'getpaid-admin-action' => 'export_invoices',
40
+                    'post_type'            => urlencode( $post_type ),
41
+                )
42
+            ),
43
+            'getpaid-nonce',
44
+            'getpaid-nonce'
45
+        );
46
+
47
+    }
48
+
49
+    /**
50
+     * Displays a single post type export card.
51
+     *
52
+     */
53
+    public function display_post_type_export( $post_type ) {
54
+
55
+        ?>
56 56
 
57 57
 		<div class="col-12 col-md-6">
58 58
 			<div class="card m-0 p-0" style="max-width:100%">
@@ -60,11 +60,11 @@  discard block
 block discarded – undo
60 60
 				<div class="card-header">
61 61
 					<strong>
62 62
 						<?php
63
-							printf(
64
-								esc_html__( 'Export %s', 'invoicing' ),
65
-								esc_html( getpaid_get_post_type_label( $post_type ) )
66
-							);
67
-						?>
63
+                            printf(
64
+                                esc_html__( 'Export %s', 'invoicing' ),
65
+                                esc_html( getpaid_get_post_type_label( $post_type ) )
66
+                            );
67
+                        ?>
68 68
 					</strong>
69 69
 				</div>
70 70
 
@@ -73,12 +73,12 @@  discard block
 block discarded – undo
73 73
 					<form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>">
74 74
 
75 75
 						<?php
76
-							$this->generate_from_date( $post_type );
77
-							$this->generate_to_date( $post_type );
78
-							$this->generate_post_status_select( $post_type );
79
-							$this->generate_file_type_select( $post_type );
80
-							submit_button( __( 'Download', 'invoicing' ) );
81
-						?>
76
+                            $this->generate_from_date( $post_type );
77
+                            $this->generate_to_date( $post_type );
78
+                            $this->generate_post_status_select( $post_type );
79
+                            $this->generate_file_type_select( $post_type );
80
+                            submit_button( __( 'Download', 'invoicing' ) );
81
+                        ?>
82 82
 
83 83
 					</form>
84 84
 
@@ -89,135 +89,135 @@  discard block
 block discarded – undo
89 89
 
90 90
 		<?php
91 91
 
92
-	}
93
-
94
-	/**
95
-	 * Generates the from date input field.
96
-	 *
97
-	 */
98
-	public function generate_from_date( $post_type ) {
99
-
100
-		aui()->input(
101
-			array(
102
-				'type'             => 'datepicker',
103
-				'id'               => esc_attr( "$post_type-from_date" ),
104
-				'name'             => 'from_date',
105
-				'label'            => __( 'From Date', 'invoicing' ),
106
-				'label_type'       => 'vertical',
107
-				'placeholder'      => 'YYYY-MM-DD',
108
-				'extra_attributes' => array(
109
-					'data-enable-time' => 'false',
110
-					'data-allow-input' => 'true',
111
-				),
112
-			),
113
-			true
114
-		);
115
-
116
-	}
117
-
118
-	/**
119
-	 * Generates the to date input field.
120
-	 *
121
-	 */
122
-	public function generate_to_date( $post_type ) {
123
-
124
-		aui()->input(
125
-			array(
126
-				'type'             => 'datepicker',
127
-				'id'               => esc_attr( "$post_type-to_date" ),
128
-				'name'             => 'to_date',
129
-				'label'            => __( 'To Date', 'invoicing' ),
130
-				'label_type'       => 'vertical',
131
-				'placeholder'      => 'YYYY-MM-DD',
132
-				'extra_attributes' => array(
133
-					'data-enable-time' => 'false',
134
-					'data-allow-input' => 'true',
135
-				),
136
-			),
137
-			true
138
-		);
139
-	}
140
-
141
-	/**
142
-	 * Generates the to post status select field.
143
-	 *
144
-	 */
145
-	public function generate_post_status_select( $post_type ) {
146
-
147
-		if ( 'subscriptions' === $post_type ) {
148
-			$options = getpaid_get_subscription_statuses();
149
-		} else {
150
-			$options = wpinv_get_invoice_statuses( true, false, $post_type );
151
-		}
152
-
153
-		aui()->select(
154
-			array(
155
-				'name'        => 'status',
156
-				'id'          => esc_attr( "$post_type-status" ),
157
-				'placeholder' => __( 'All Statuses', 'invoicing' ),
158
-				'label'       => __( 'Status', 'invoicing' ),
159
-				'label_type'  => 'vertical',
160
-				'label_class' => 'd-block',
161
-				'options'     => $options,
162
-			),
163
-			true
164
-		);
165
-
166
-	}
167
-
168
-	/**
169
-	 * Generates the to file type select field.
170
-	 *
171
-	 */
172
-	public function generate_file_type_select( $post_type ) {
173
-
174
-		aui()->select(
175
-			array(
176
-				'name'        => 'file_type',
177
-				'id'          => esc_attr( "$post_type-file_type" ),
178
-				'placeholder' => __( 'Select File Type', 'invoicing' ),
179
-				'label'       => __( 'Export File', 'invoicing' ),
180
-				'label_type'  => 'vertical',
181
-				'label_class' => 'd-block',
182
-				'value'       => 'csv',
183
-				'options'     => array(
184
-					'csv'  => __( 'CSV', 'invoicing' ),
185
-					'xml'  => __( 'XML', 'invoicing' ),
186
-					'json' => __( 'JSON', 'invoicing' ),
187
-				),
188
-			),
189
-			true
190
-		);
191
-
192
-	}
193
-
194
-	/**
195
-	 * Displays a field's markup.
196
-	 *
197
-	 */
198
-	public function display_markup( $markup ) {
199
-
200
-		echo wp_kses(
201
-			str_replace(
202
-				array(
203
-					'form-control',
204
-					'custom-select',
205
-				),
206
-				'regular-text',
207
-				$markup
208
-			),
209
-			getpaid_allowed_html()
210
-		);
211
-
212
-	}
213
-
214
-	/**
215
-	 * Displays a subscription export card.
216
-	 *
217
-	 */
218
-	public function display_subscription_export() {
219
-
220
-		?>
92
+    }
93
+
94
+    /**
95
+     * Generates the from date input field.
96
+     *
97
+     */
98
+    public function generate_from_date( $post_type ) {
99
+
100
+        aui()->input(
101
+            array(
102
+                'type'             => 'datepicker',
103
+                'id'               => esc_attr( "$post_type-from_date" ),
104
+                'name'             => 'from_date',
105
+                'label'            => __( 'From Date', 'invoicing' ),
106
+                'label_type'       => 'vertical',
107
+                'placeholder'      => 'YYYY-MM-DD',
108
+                'extra_attributes' => array(
109
+                    'data-enable-time' => 'false',
110
+                    'data-allow-input' => 'true',
111
+                ),
112
+            ),
113
+            true
114
+        );
115
+
116
+    }
117
+
118
+    /**
119
+     * Generates the to date input field.
120
+     *
121
+     */
122
+    public function generate_to_date( $post_type ) {
123
+
124
+        aui()->input(
125
+            array(
126
+                'type'             => 'datepicker',
127
+                'id'               => esc_attr( "$post_type-to_date" ),
128
+                'name'             => 'to_date',
129
+                'label'            => __( 'To Date', 'invoicing' ),
130
+                'label_type'       => 'vertical',
131
+                'placeholder'      => 'YYYY-MM-DD',
132
+                'extra_attributes' => array(
133
+                    'data-enable-time' => 'false',
134
+                    'data-allow-input' => 'true',
135
+                ),
136
+            ),
137
+            true
138
+        );
139
+    }
140
+
141
+    /**
142
+     * Generates the to post status select field.
143
+     *
144
+     */
145
+    public function generate_post_status_select( $post_type ) {
146
+
147
+        if ( 'subscriptions' === $post_type ) {
148
+            $options = getpaid_get_subscription_statuses();
149
+        } else {
150
+            $options = wpinv_get_invoice_statuses( true, false, $post_type );
151
+        }
152
+
153
+        aui()->select(
154
+            array(
155
+                'name'        => 'status',
156
+                'id'          => esc_attr( "$post_type-status" ),
157
+                'placeholder' => __( 'All Statuses', 'invoicing' ),
158
+                'label'       => __( 'Status', 'invoicing' ),
159
+                'label_type'  => 'vertical',
160
+                'label_class' => 'd-block',
161
+                'options'     => $options,
162
+            ),
163
+            true
164
+        );
165
+
166
+    }
167
+
168
+    /**
169
+     * Generates the to file type select field.
170
+     *
171
+     */
172
+    public function generate_file_type_select( $post_type ) {
173
+
174
+        aui()->select(
175
+            array(
176
+                'name'        => 'file_type',
177
+                'id'          => esc_attr( "$post_type-file_type" ),
178
+                'placeholder' => __( 'Select File Type', 'invoicing' ),
179
+                'label'       => __( 'Export File', 'invoicing' ),
180
+                'label_type'  => 'vertical',
181
+                'label_class' => 'd-block',
182
+                'value'       => 'csv',
183
+                'options'     => array(
184
+                    'csv'  => __( 'CSV', 'invoicing' ),
185
+                    'xml'  => __( 'XML', 'invoicing' ),
186
+                    'json' => __( 'JSON', 'invoicing' ),
187
+                ),
188
+            ),
189
+            true
190
+        );
191
+
192
+    }
193
+
194
+    /**
195
+     * Displays a field's markup.
196
+     *
197
+     */
198
+    public function display_markup( $markup ) {
199
+
200
+        echo wp_kses(
201
+            str_replace(
202
+                array(
203
+                    'form-control',
204
+                    'custom-select',
205
+                ),
206
+                'regular-text',
207
+                $markup
208
+            ),
209
+            getpaid_allowed_html()
210
+        );
211
+
212
+    }
213
+
214
+    /**
215
+     * Displays a subscription export card.
216
+     *
217
+     */
218
+    public function display_subscription_export() {
219
+
220
+        ?>
221 221
 
222 222
 		<div class="col-12 col-md-6">
223 223
 			<div class="card m-0 p-0" style="max-width:100%">
@@ -233,12 +233,12 @@  discard block
 block discarded – undo
233 233
 					<form method="post" action="<?php echo esc_url( $this->get_download_url( 'subscriptions' ) ); ?>">
234 234
 
235 235
 						<?php
236
-							$this->generate_from_date( 'subscriptions' );
237
-							$this->generate_to_date( 'subscriptions' );
238
-							$this->generate_post_status_select( 'subscriptions' );
239
-							$this->generate_file_type_select( 'subscriptions' );
240
-							submit_button( __( 'Download', 'invoicing' ) );
241
-						?>
236
+                            $this->generate_from_date( 'subscriptions' );
237
+                            $this->generate_to_date( 'subscriptions' );
238
+                            $this->generate_post_status_select( 'subscriptions' );
239
+                            $this->generate_file_type_select( 'subscriptions' );
240
+                            submit_button( __( 'Download', 'invoicing' ) );
241
+                        ?>
242 242
 
243 243
 					</form>
244 244
 
@@ -249,6 +249,6 @@  discard block
 block discarded – undo
249 249
 
250 250
 		<?php
251 251
 
252
-	}
252
+    }
253 253
 
254 254
 }
Please login to merge, or discard this patch.
invoicing.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,16 +19,16 @@  discard block
 block discarded – undo
19 19
 
20 20
 // Define constants.
21 21
 if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) {
22
-	define( 'WPINV_PLUGIN_FILE', __FILE__ );
22
+    define( 'WPINV_PLUGIN_FILE', __FILE__ );
23 23
 }
24 24
 
25 25
 if ( ! defined( 'WPINV_VERSION' ) ) {
26
-	define( 'WPINV_VERSION', '2.6.18' );
26
+    define( 'WPINV_VERSION', '2.6.18' );
27 27
 }
28 28
 
29 29
 // Include the main Invoicing class.
30 30
 if ( ! class_exists( 'WPInv_Plugin', false ) ) {
31
-	require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php';
31
+    require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php';
32 32
 }
33 33
 
34 34
 /**
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
         $GLOBALS['invoicing'] = new WPInv_Plugin();
44 44
     }
45 45
 
46
-	return $GLOBALS['invoicing'];
46
+    return $GLOBALS['invoicing'];
47 47
 }
48 48
 
49 49
 /**
Please login to merge, or discard this patch.