Passed
Push — master ( 039fc1...a932b5 )
by Brian
05:54
created
includes/payments/class-getpaid-payment-form-submission-items.php 1 patch
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -12,51 +12,51 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Items {
14 14
 
15
-	/**
16
-	 * Submission items.
17
-	 * @var GetPaid_Form_Item[]
18
-	 */
19
-	public $items = array();
15
+    /**
16
+     * Submission items.
17
+     * @var GetPaid_Form_Item[]
18
+     */
19
+    public $items = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$data         = $submission->get_data();
29
-		$payment_form = $submission->get_payment_form();
30
-		$invoice      = $submission->get_invoice();
31
-		$force_prices = array();
32
-
33
-		// Prepare the selected items.
34
-		$selected_items = array();
35
-		if ( ! empty( $data['getpaid-items'] ) ) {
36
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
37
-
38
-			if ( ! empty( $invoice ) && $submission->is_initial_fetch() ) {
39
-				foreach ( $invoice->get_items() as $invoice_item ) {
40
-					if ( isset( $selected_items[ $invoice_item->get_id() ] ) ) {
41
-						$selected_items[ $invoice_item->get_id() ]['quantity'] = $invoice_item->get_quantity();
42
-						$selected_items[ $invoice_item->get_id() ]['price']    = $invoice_item->get_price();
43
-
44
-						$force_prices[ $invoice_item->get_id() ] = $invoice_item->get_price();
45
-					}
46
-				}
47
-			}
48
-		}
49
-
50
-		// (Maybe) set form items.
51
-		if ( isset( $data['getpaid-form-items'] ) ) {
52
-
53
-			// Confirm items key.
54
-			$form_items = wpinv_clean( $data['getpaid-form-items'] );
55
-			if ( ! isset( $data['getpaid-form-items-key'] ) || md5( NONCE_KEY . AUTH_KEY . $form_items ) !== $data['getpaid-form-items-key'] ) {
56
-				throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) );
57
-			}
58
-
59
-			$items    = array();
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $data         = $submission->get_data();
29
+        $payment_form = $submission->get_payment_form();
30
+        $invoice      = $submission->get_invoice();
31
+        $force_prices = array();
32
+
33
+        // Prepare the selected items.
34
+        $selected_items = array();
35
+        if ( ! empty( $data['getpaid-items'] ) ) {
36
+            $selected_items = wpinv_clean( $data['getpaid-items'] );
37
+
38
+            if ( ! empty( $invoice ) && $submission->is_initial_fetch() ) {
39
+                foreach ( $invoice->get_items() as $invoice_item ) {
40
+                    if ( isset( $selected_items[ $invoice_item->get_id() ] ) ) {
41
+                        $selected_items[ $invoice_item->get_id() ]['quantity'] = $invoice_item->get_quantity();
42
+                        $selected_items[ $invoice_item->get_id() ]['price']    = $invoice_item->get_price();
43
+
44
+                        $force_prices[ $invoice_item->get_id() ] = $invoice_item->get_price();
45
+                    }
46
+                }
47
+            }
48
+        }
49
+
50
+        // (Maybe) set form items.
51
+        if ( isset( $data['getpaid-form-items'] ) ) {
52
+
53
+            // Confirm items key.
54
+            $form_items = wpinv_clean( $data['getpaid-form-items'] );
55
+            if ( ! isset( $data['getpaid-form-items-key'] ) || md5( NONCE_KEY . AUTH_KEY . $form_items ) !== $data['getpaid-form-items-key'] ) {
56
+                throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) );
57
+            }
58
+
59
+            $items    = array();
60 60
             $item_ids = array();
61 61
 
62 62
             foreach ( getpaid_convert_items_to_array( $form_items ) as $item_id => $qty ) {
@@ -69,10 +69,10 @@  discard block
 block discarded – undo
69 69
                         $item->set_is_required( false );
70 70
                     }
71 71
 
72
-					if ( ! $item->user_can_set_their_price() && isset( $force_prices[ $item_id ] ) ) {
73
-						$item->set_is_dynamic_pricing( true );
74
-						$item->set_minimum_price( 0 );
75
-					}
72
+                    if ( ! $item->user_can_set_their_price() && isset( $force_prices[ $item_id ] ) ) {
73
+                        $item->set_is_dynamic_pricing( true );
74
+                        $item->set_minimum_price( 0 );
75
+                    }
76 76
 
77 77
                     $item_ids[] = $item->get_id();
78 78
                     $items[]    = $item;
@@ -87,61 +87,61 @@  discard block
 block discarded – undo
87 87
                         $items[]    = $item;
88 88
                     }
89 89
                 }
90
-			}
90
+            }
91 91
 
92 92
             $payment_form->set_items( $items );
93 93
 
94
-		}
95
-
96
-		// Process each individual item.
97
-		foreach ( $payment_form->get_items() as $item ) {
98
-			$this->process_item( $item, $selected_items, $submission );
99
-		}
100
-
101
-	}
102
-
103
-	/**
104
-	 * Process a single item.
105
-	 *
106
-	 * @param GetPaid_Form_Item $item
107
-	 * @param array $selected_items
108
-	 * @param GetPaid_Payment_Form_Submission $submission
109
-	 */
110
-	public function process_item( $item, $selected_items, $submission ) {
94
+        }
111 95
 
112
-		// Abort if this is an optional item and it has not been selected.
113
-		if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
114
-			return;
115
-		}
96
+        // Process each individual item.
97
+        foreach ( $payment_form->get_items() as $item ) {
98
+            $this->process_item( $item, $selected_items, $submission );
99
+        }
116 100
 
117
-		// (maybe) let customers change the quantities and prices.
118
-		if ( isset( $selected_items[ $item->get_id() ] ) ) {
101
+    }
119 102
 
120
-			// Maybe change the quantities.
121
-			if ( $item->allows_quantities() ) {
122
-				$item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] );
123
-			}
103
+    /**
104
+     * Process a single item.
105
+     *
106
+     * @param GetPaid_Form_Item $item
107
+     * @param array $selected_items
108
+     * @param GetPaid_Payment_Form_Submission $submission
109
+     */
110
+    public function process_item( $item, $selected_items, $submission ) {
111
+
112
+        // Abort if this is an optional item and it has not been selected.
113
+        if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
114
+            return;
115
+        }
116
+
117
+        // (maybe) let customers change the quantities and prices.
118
+        if ( isset( $selected_items[ $item->get_id() ] ) ) {
119
+
120
+            // Maybe change the quantities.
121
+            if ( $item->allows_quantities() ) {
122
+                $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] );
123
+            }
124 124
 
125
-			// Maybe change the price.
126
-			if ( $item->user_can_set_their_price() ) {
127
-				$price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
125
+            // Maybe change the price.
126
+            if ( $item->user_can_set_their_price() ) {
127
+                $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
128 128
 
129
-				if ( $item->get_minimum_price() > $price ) {
130
-					throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) );
131
-				}
129
+                if ( $item->get_minimum_price() > $price ) {
130
+                    throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) );
131
+                }
132 132
 
133
-				$item->set_price( $price );
133
+                $item->set_price( $price );
134 134
 
135
-			}
136
-		}
135
+            }
136
+        }
137 137
 
138
-		if ( 0 == $item->get_quantity() ) {
139
-			return;
140
-		}
138
+        if ( 0 == $item->get_quantity() ) {
139
+            return;
140
+        }
141 141
 
142
-		// Save the item.
143
-		$this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission );
142
+        // Save the item.
143
+        $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission );
144 144
 
145
-	}
145
+    }
146 146
 
147 147
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-refresh-prices.php 1 patch
Indentation   +271 added lines, -271 removed lines patch added patch discarded remove patch
@@ -12,305 +12,305 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Refresh_Prices {
14 14
 
15
-	/**
16
-	 * Contains the response for refreshing prices.
17
-	 * @var array
18
-	 */
19
-	public $response = array();
15
+    /**
16
+     * Contains the response for refreshing prices.
17
+     * @var array
18
+     */
19
+    public $response = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$this->response = array(
29
-			'submission_id'                    => $submission->id,
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $this->response = array(
29
+            'submission_id'                    => $submission->id,
30 30
             'has_recurring'                    => $submission->has_recurring,
31
-			'has_subscription_group'           => $submission->has_subscription_group(),
32
-			'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(),
31
+            'has_subscription_group'           => $submission->has_subscription_group(),
32
+            'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(),
33 33
             'is_free'                          => ! $submission->should_collect_payment_details(),
34
-		);
35
-
36
-		$payment_form = $submission->get_payment_form();
37
-		if ( ! empty( $payment_form->invoice ) ) {
38
-			$this->response['invoice'] = $payment_form->invoice->get_id();
39
-		}
40
-
41
-		$this->add_totals( $submission );
42
-		$this->add_texts( $submission );
43
-		$this->add_items( $submission );
44
-		$this->add_fees( $submission );
45
-		$this->add_discounts( $submission );
46
-		$this->add_taxes( $submission );
47
-		$this->add_gateways( $submission );
48
-		$this->add_data( $submission );
49
-
50
-	}
51
-
52
-	/**
53
-	 * Adds totals to a response for submission refresh prices.
54
-	 *
55
-	 * @param GetPaid_Payment_Form_Submission $submission
56
-	 */
57
-	public function add_totals( $submission ) {
58
-
59
-		$this->response = array_merge(
60
-			$this->response,
61
-			array(
62
-
63
-				'totals'      => array(
64
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
65
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
66
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
67
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
68
-					'total'     => $submission->format_amount( $submission->get_total() ),
69
-					'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
70
-				),
71
-
72
-				'recurring'   => array(
73
-					'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ),
74
-					'discount' => $submission->format_amount( $submission->get_recurring_discount() ),
75
-					'fees'     => $submission->format_amount( $submission->get_recurring_fee() ),
76
-					'tax'      => $submission->format_amount( $submission->get_recurring_tax() ),
77
-					'total'    => $submission->format_amount( $submission->get_recurring_total() ),
78
-				),
79
-
80
-				'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ),
81
-				'currency'    => $submission->get_currency(),
82
-
83
-			)
84
-		);
85
-
86
-	}
87
-
88
-	/**
89
-	 * Adds texts to a response for submission refresh prices.
90
-	 *
91
-	 * @param GetPaid_Payment_Form_Submission $submission
92
-	 */
93
-	public function add_texts( $submission ) {
94
-
95
-		$payable = $submission->format_amount( $submission->get_total() );
96
-		$groups  = getpaid_get_subscription_groups( $submission );
97
-
98
-		if ( $submission->has_recurring && 2 > count( $groups ) ) {
99
-
100
-			$recurring = new WPInv_Item( $submission->has_recurring );
101
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
102
-			$main_item = reset( $groups );
103
-
104
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
105
-				$payable = "$payable / $period";
106
-			} elseif ( $main_item ) {
107
-
108
-				$main_item = reset( $main_item );
109
-
110
-				// Calculate the next renewal date.
111
-				$_period      = $main_item->get_recurring_period( true );
112
-				$_interval    = $main_item->get_recurring_interval();
113
-
114
-				// If the subscription item has a trial period...
115
-				if ( $main_item->has_free_trial() ) {
116
-					$_period   = $main_item->get_trial_period( true );
117
-					$_interval = $main_item->get_trial_interval();
118
-				}
119
-
120
-				$payable = sprintf(
121
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
122
-					$submission->format_amount( $submission->get_total() ),
123
-					$submission->format_amount( $submission->get_recurring_total() ),
124
-					$period
125
-				);
126
-
127
-				$payable .= sprintf(
128
-					'<small class="text-muted form-text">%s</small>',
129
-					sprintf(
130
-						__( 'First renewal on %s', 'invoicing' ),
131
-						getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) )
132
-					)
133
-				);
134
-
135
-			} else {
136
-				$payable = sprintf(
137
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
138
-					$submission->format_amount( $submission->get_total() ),
139
-					$submission->format_amount( $submission->get_recurring_total() ),
140
-					$period
141
-				);
142
-			}
143
-}
34
+        );
35
+
36
+        $payment_form = $submission->get_payment_form();
37
+        if ( ! empty( $payment_form->invoice ) ) {
38
+            $this->response['invoice'] = $payment_form->invoice->get_id();
39
+        }
40
+
41
+        $this->add_totals( $submission );
42
+        $this->add_texts( $submission );
43
+        $this->add_items( $submission );
44
+        $this->add_fees( $submission );
45
+        $this->add_discounts( $submission );
46
+        $this->add_taxes( $submission );
47
+        $this->add_gateways( $submission );
48
+        $this->add_data( $submission );
144 49
 
145
-		$texts = array(
146
-			'.getpaid-checkout-total-payable' => $payable,
147
-		);
50
+    }
148 51
 
149
-		foreach ( $submission->get_items() as $item ) {
150
-			$item_id                                               = $item->get_id();
151
-			$initial_price                                         = $submission->format_amount( $item->get_sub_total() - $item->item_discount );
152
-			$recurring_price                                       = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount );
153
-			$texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
154
-			$texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) );
52
+    /**
53
+     * Adds totals to a response for submission refresh prices.
54
+     *
55
+     * @param GetPaid_Payment_Form_Submission $submission
56
+     */
57
+    public function add_totals( $submission ) {
58
+
59
+        $this->response = array_merge(
60
+            $this->response,
61
+            array(
62
+
63
+                'totals'      => array(
64
+                    'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
65
+                    'discount'  => $submission->format_amount( $submission->get_discount() ),
66
+                    'fees'      => $submission->format_amount( $submission->get_fee() ),
67
+                    'tax'       => $submission->format_amount( $submission->get_tax() ),
68
+                    'total'     => $submission->format_amount( $submission->get_total() ),
69
+                    'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
70
+                ),
71
+
72
+                'recurring'   => array(
73
+                    'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ),
74
+                    'discount' => $submission->format_amount( $submission->get_recurring_discount() ),
75
+                    'fees'     => $submission->format_amount( $submission->get_recurring_fee() ),
76
+                    'tax'      => $submission->format_amount( $submission->get_recurring_tax() ),
77
+                    'total'    => $submission->format_amount( $submission->get_recurring_total() ),
78
+                ),
79
+
80
+                'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ),
81
+                'currency'    => $submission->get_currency(),
82
+
83
+            )
84
+        );
85
+
86
+    }
155 87
 
156
-			if ( $item->get_quantity() == 1 ) {
157
-				$texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = '';
158
-			}
88
+    /**
89
+     * Adds texts to a response for submission refresh prices.
90
+     *
91
+     * @param GetPaid_Payment_Form_Submission $submission
92
+     */
93
+    public function add_texts( $submission ) {
94
+
95
+        $payable = $submission->format_amount( $submission->get_total() );
96
+        $groups  = getpaid_get_subscription_groups( $submission );
97
+
98
+        if ( $submission->has_recurring && 2 > count( $groups ) ) {
99
+
100
+            $recurring = new WPInv_Item( $submission->has_recurring );
101
+            $period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
102
+            $main_item = reset( $groups );
103
+
104
+            if ( $submission->get_total() == $submission->get_recurring_total() ) {
105
+                $payable = "$payable / $period";
106
+            } elseif ( $main_item ) {
107
+
108
+                $main_item = reset( $main_item );
109
+
110
+                // Calculate the next renewal date.
111
+                $_period      = $main_item->get_recurring_period( true );
112
+                $_interval    = $main_item->get_recurring_interval();
113
+
114
+                // If the subscription item has a trial period...
115
+                if ( $main_item->has_free_trial() ) {
116
+                    $_period   = $main_item->get_trial_period( true );
117
+                    $_interval = $main_item->get_trial_interval();
118
+                }
119
+
120
+                $payable = sprintf(
121
+                    __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
122
+                    $submission->format_amount( $submission->get_total() ),
123
+                    $submission->format_amount( $submission->get_recurring_total() ),
124
+                    $period
125
+                );
126
+
127
+                $payable .= sprintf(
128
+                    '<small class="text-muted form-text">%s</small>',
129
+                    sprintf(
130
+                        __( 'First renewal on %s', 'invoicing' ),
131
+                        getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) )
132
+                    )
133
+                );
134
+
135
+            } else {
136
+                $payable = sprintf(
137
+                    __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
138
+                    $submission->format_amount( $submission->get_total() ),
139
+                    $submission->format_amount( $submission->get_recurring_total() ),
140
+                    $period
141
+                );
142
+            }
159 143
 }
160 144
 
161
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
145
+        $texts = array(
146
+            '.getpaid-checkout-total-payable' => $payable,
147
+        );
162 148
 
163
-	}
149
+        foreach ( $submission->get_items() as $item ) {
150
+            $item_id                                               = $item->get_id();
151
+            $initial_price                                         = $submission->format_amount( $item->get_sub_total() - $item->item_discount );
152
+            $recurring_price                                       = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount );
153
+            $texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
154
+            $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) );
155
+
156
+            if ( $item->get_quantity() == 1 ) {
157
+                $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = '';
158
+            }
159
+}
164 160
 
165
-	/**
166
-	 * Adds items to a response for submission refresh prices.
167
-	 *
168
-	 * @param GetPaid_Payment_Form_Submission $submission
169
-	 */
170
-	public function add_items( $submission ) {
161
+        $this->response = array_merge( $this->response, array( 'texts' => $texts ) );
171 162
 
172
-		// Add items.
173
-		$items          = array();
174
-		$selected_items = array();
163
+    }
164
+
165
+    /**
166
+     * Adds items to a response for submission refresh prices.
167
+     *
168
+     * @param GetPaid_Payment_Form_Submission $submission
169
+     */
170
+    public function add_items( $submission ) {
171
+
172
+        // Add items.
173
+        $items          = array();
174
+        $selected_items = array();
175 175
 
176 176
         foreach ( $submission->get_items() as $item ) {
177
-			$item_id             = $item->get_id();
178
-			$items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() );
179
-
180
-			$selected_items[ "$item_id" ] = array(
181
-				'quantity'  => $item->get_quantity(),
182
-				'price'     => $item->get_price(),
183
-				'price_fmt' => $submission->format_amount( $item->get_price() ),
184
-			);
185
-		}
186
-
187
-		$this->response = array_merge(
188
-			$this->response,
189
-			array(
190
-				'items'          => $items,
191
-				'selected_items' => $selected_items,
192
-			)
193
-		);
194
-
195
-	}
196
-
197
-	/**
198
-	 * Adds fees to a response for submission refresh prices.
199
-	 *
200
-	 * @param GetPaid_Payment_Form_Submission $submission
201
-	 */
202
-	public function add_fees( $submission ) {
203
-
204
-		$fees = array();
177
+            $item_id             = $item->get_id();
178
+            $items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() );
179
+
180
+            $selected_items[ "$item_id" ] = array(
181
+                'quantity'  => $item->get_quantity(),
182
+                'price'     => $item->get_price(),
183
+                'price_fmt' => $submission->format_amount( $item->get_price() ),
184
+            );
185
+        }
186
+
187
+        $this->response = array_merge(
188
+            $this->response,
189
+            array(
190
+                'items'          => $items,
191
+                'selected_items' => $selected_items,
192
+            )
193
+        );
194
+
195
+    }
196
+
197
+    /**
198
+     * Adds fees to a response for submission refresh prices.
199
+     *
200
+     * @param GetPaid_Payment_Form_Submission $submission
201
+     */
202
+    public function add_fees( $submission ) {
203
+
204
+        $fees = array();
205 205
 
206 206
         foreach ( $submission->get_fees() as $name => $data ) {
207
-			$fees[ $name ] = $submission->format_amount( $data['initial_fee'] );
208
-		}
207
+            $fees[ $name ] = $submission->format_amount( $data['initial_fee'] );
208
+        }
209 209
 
210
-		$this->response = array_merge(
211
-			$this->response,
212
-			array( 'fees' => $fees )
213
-		);
210
+        $this->response = array_merge(
211
+            $this->response,
212
+            array( 'fees' => $fees )
213
+        );
214 214
 
215
-	}
215
+    }
216 216
 
217
-	/**
218
-	 * Adds discounts to a response for submission refresh prices.
219
-	 *
220
-	 * @param GetPaid_Payment_Form_Submission $submission
221
-	 */
222
-	public function add_discounts( $submission ) {
217
+    /**
218
+     * Adds discounts to a response for submission refresh prices.
219
+     *
220
+     * @param GetPaid_Payment_Form_Submission $submission
221
+     */
222
+    public function add_discounts( $submission ) {
223 223
 
224
-		$discounts = array();
224
+        $discounts = array();
225 225
 
226 226
         foreach ( $submission->get_discounts() as $name => $data ) {
227
-			$discounts[ $name ] = $submission->format_amount( $data['initial_discount'] );
228
-		}
227
+            $discounts[ $name ] = $submission->format_amount( $data['initial_discount'] );
228
+        }
229 229
 
230
-		$this->response = array_merge(
231
-			$this->response,
232
-			array( 'discounts' => $discounts )
233
-		);
230
+        $this->response = array_merge(
231
+            $this->response,
232
+            array( 'discounts' => $discounts )
233
+        );
234 234
 
235
-	}
235
+    }
236 236
 
237
-	/**
238
-	 * Adds taxes to a response for submission refresh prices.
239
-	 *
240
-	 * @param GetPaid_Payment_Form_Submission $submission
241
-	 */
242
-	public function add_taxes( $submission ) {
243
-
244
-		$taxes  = array();
245
-		$markup = '';
237
+    /**
238
+     * Adds taxes to a response for submission refresh prices.
239
+     *
240
+     * @param GetPaid_Payment_Form_Submission $submission
241
+     */
242
+    public function add_taxes( $submission ) {
243
+
244
+        $taxes  = array();
245
+        $markup = '';
246 246
         foreach ( $submission->get_taxes() as $name => $data ) {
247
-			$name          = sanitize_text_field( $name );
248
-			$amount        = $submission->format_amount( $data['initial_tax'] );
249
-			$taxes[ $name ]  = $amount;
250
-			$markup       .= "<small class='form-text'>$name : $amount</small>";
251
-		}
252
-
253
-		if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) {
254
-			$this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
255
-		}
256
-
257
-		$this->response = array_merge(
258
-			$this->response,
259
-			array( 'taxes' => $taxes )
260
-		);
261
-
262
-	}
263
-
264
-	/**
265
-	 * Adds gateways to a response for submission refresh prices.
266
-	 *
267
-	 * @param GetPaid_Payment_Form_Submission $submission
268
-	 */
269
-	public function add_gateways( $submission ) {
270
-
271
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
272
-
273
-		if ( $this->response['has_recurring'] ) {
274
-
275
-			foreach ( $gateways as $i => $gateway ) {
276
-
277
-				if (
278
-					! getpaid_payment_gateway_supports( $gateway, 'subscription' )
279
-					|| ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) )
280
-					|| ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) {
281
-					unset( $gateways[ $i ] );
282
-				}
247
+            $name          = sanitize_text_field( $name );
248
+            $amount        = $submission->format_amount( $data['initial_tax'] );
249
+            $taxes[ $name ]  = $amount;
250
+            $markup       .= "<small class='form-text'>$name : $amount</small>";
251
+        }
252
+
253
+        if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) {
254
+            $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
255
+        }
256
+
257
+        $this->response = array_merge(
258
+            $this->response,
259
+            array( 'taxes' => $taxes )
260
+        );
261
+
262
+    }
263
+
264
+    /**
265
+     * Adds gateways to a response for submission refresh prices.
266
+     *
267
+     * @param GetPaid_Payment_Form_Submission $submission
268
+     */
269
+    public function add_gateways( $submission ) {
270
+
271
+        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
272
+
273
+        if ( $this->response['has_recurring'] ) {
274
+
275
+            foreach ( $gateways as $i => $gateway ) {
276
+
277
+                if (
278
+                    ! getpaid_payment_gateway_supports( $gateway, 'subscription' )
279
+                    || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) )
280
+                    || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) {
281
+                    unset( $gateways[ $i ] );
282
+                }
283 283
 }
284 284
 }
285 285
 
286
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
287
-		$this->response = array_merge(
288
-			$this->response,
289
-			array( 'gateways' => $gateways )
290
-		);
291
-
292
-	}
293
-
294
-	/**
295
-	 * Adds data to a response for submission refresh prices.
296
-	 *
297
-	 * @param GetPaid_Payment_Form_Submission $submission
298
-	 */
299
-	public function add_data( $submission ) {
300
-
301
-		$this->response = array_merge(
302
-			$this->response,
303
-			array(
304
-				'js_data' => apply_filters(
305
-					'getpaid_submission_js_data',
306
-					array(
307
-						'is_recurring' => $this->response['has_recurring'],
308
-					),
309
-					$submission
310
-				),
311
-			)
312
-		);
313
-
314
-	}
286
+        $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
287
+        $this->response = array_merge(
288
+            $this->response,
289
+            array( 'gateways' => $gateways )
290
+        );
291
+
292
+    }
293
+
294
+    /**
295
+     * Adds data to a response for submission refresh prices.
296
+     *
297
+     * @param GetPaid_Payment_Form_Submission $submission
298
+     */
299
+    public function add_data( $submission ) {
300
+
301
+        $this->response = array_merge(
302
+            $this->response,
303
+            array(
304
+                'js_data' => apply_filters(
305
+                    'getpaid_submission_js_data',
306
+                    array(
307
+                        'is_recurring' => $this->response['has_recurring'],
308
+                    ),
309
+                    $submission
310
+                ),
311
+            )
312
+        );
313
+
314
+    }
315 315
 
316 316
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-form-item.php 1 patch
Indentation   +359 added lines, -359 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,67 +10,67 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Form_Item  extends WPInv_Item {
11 11
 
12 12
     /**
13
-	 * Stores a custom description for the item.
14
-	 *
15
-	 * @var string
16
-	 */
17
-	protected $custom_description = null;
18
-
19
-	/**
20
-	 * Stores the item quantity.
21
-	 *
22
-	 * @var float
23
-	 */
24
-	protected $quantity = 1;
25
-
26
-	/**
27
-	 * Stores the item meta.
28
-	 *
29
-	 * @var array
30
-	 */
31
-	protected $meta = array();
32
-
33
-	/**
34
-	 * Is this item required?
35
-	 *
36
-	 * @var int
37
-	 */
38
-	protected $is_required = true;
39
-
40
-	/**
41
-	 * Are quantities allowed?
42
-	 *
43
-	 * @var int
44
-	 */
45
-	protected $allow_quantities = false;
46
-
47
-	/**
48
-	 * Associated invoice.
49
-	 *
50
-	 * @var int
51
-	 */
52
-	public $invoice_id = 0;
53
-
54
-	/**
55
-	 * Item discount.
56
-	 *
57
-	 * @var float
58
-	 */
59
-	public $item_discount = 0;
60
-
61
-	/**
62
-	 * Recurring item discount.
63
-	 *
64
-	 * @var float
65
-	 */
66
-	public $recurring_item_discount = 0;
67
-
68
-	/**
69
-	 * Item tax.
70
-	 *
71
-	 * @var float
72
-	 */
73
-	public $item_tax = 0;
13
+     * Stores a custom description for the item.
14
+     *
15
+     * @var string
16
+     */
17
+    protected $custom_description = null;
18
+
19
+    /**
20
+     * Stores the item quantity.
21
+     *
22
+     * @var float
23
+     */
24
+    protected $quantity = 1;
25
+
26
+    /**
27
+     * Stores the item meta.
28
+     *
29
+     * @var array
30
+     */
31
+    protected $meta = array();
32
+
33
+    /**
34
+     * Is this item required?
35
+     *
36
+     * @var int
37
+     */
38
+    protected $is_required = true;
39
+
40
+    /**
41
+     * Are quantities allowed?
42
+     *
43
+     * @var int
44
+     */
45
+    protected $allow_quantities = false;
46
+
47
+    /**
48
+     * Associated invoice.
49
+     *
50
+     * @var int
51
+     */
52
+    public $invoice_id = 0;
53
+
54
+    /**
55
+     * Item discount.
56
+     *
57
+     * @var float
58
+     */
59
+    public $item_discount = 0;
60
+
61
+    /**
62
+     * Recurring item discount.
63
+     *
64
+     * @var float
65
+     */
66
+    public $recurring_item_discount = 0;
67
+
68
+    /**
69
+     * Item tax.
70
+     *
71
+     * @var float
72
+     */
73
+    public $item_tax = 0;
74 74
 
75 75
     /*
76 76
 	|--------------------------------------------------------------------------
@@ -88,230 +88,230 @@  discard block
 block discarded – undo
88 88
     */
89 89
 
90 90
     /**
91
-	 * Get the item name.
92
-	 *
93
-	 * @since 1.0.19
94
-	 * @param  string $context View or edit context.
95
-	 * @return string
96
-	 */
97
-	public function get_name( $context = 'view' ) {
98
-		$name = parent::get_name( $context );
99
-		return $name . wpinv_get_item_suffix( $this );
100
-	}
101
-
102
-	/**
103
-	 * Get the item name without a suffix.
104
-	 *
105
-	 * @since 1.0.19
106
-	 * @param  string $context View or edit context.
107
-	 * @return string
108
-	 */
109
-	public function get_raw_name( $context = 'view' ) {
110
-		return parent::get_name( $context );
111
-	}
112
-
113
-	/**
114
-	 * Get the item description.
115
-	 *
116
-	 * @since 1.0.19
117
-	 * @param  string $context View or edit context.
118
-	 * @return string
119
-	 */
120
-	public function get_description( $context = 'view' ) {
121
-
122
-		if ( isset( $this->custom_description ) ) {
123
-			return $this->custom_description;
124
-		}
125
-
126
-		return parent::get_description( $context );
127
-	}
128
-
129
-	/**
130
-	 * Returns the sub total.
131
-	 *
132
-	 * @since 1.0.19
133
-	 * @param  string $context View or edit context.
134
-	 * @return float
135
-	 */
136
-	public function get_sub_total( $context = 'view' ) {
137
-		return $this->get_quantity( $context ) * $this->get_initial_price( $context );
138
-	}
139
-
140
-	/**
141
-	 * Returns the recurring sub total.
142
-	 *
143
-	 * @since 1.0.19
144
-	 * @param  string $context View or edit context.
145
-	 * @return float
146
-	 */
147
-	public function get_recurring_sub_total( $context = 'view' ) {
148
-
149
-		if ( $this->is_recurring() ) {
150
-			return $this->get_quantity( $context ) * $this->get_price( $context );
151
-		}
152
-
153
-		return 0;
154
-	}
155
-
156
-	/**
157
-	 * @deprecated
158
-	 */
159
-	public function get_qantity( $context = 'view' ) {
160
-		return $this->get_quantity( $context );
161
-	}
162
-
163
-	/**
164
-	 * Get the item quantity.
165
-	 *
166
-	 * @since 1.0.19
167
-	 * @param  string $context View or edit context.
168
-	 * @return float
169
-	 */
170
-	public function get_quantity( $context = 'view' ) {
171
-		$quantity = (float) $this->quantity;
172
-
173
-		if ( 'view' === $context ) {
174
-			return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this );
175
-		}
176
-
177
-		return $quantity;
178
-
179
-	}
180
-
181
-	/**
182
-	 * Get the item meta data.
183
-	 *
184
-	 * @since 1.0.19
185
-	 * @param  string $context View or edit context.
186
-	 * @return meta
187
-	 */
188
-	public function get_item_meta( $context = 'view' ) {
189
-		$meta = $this->meta;
190
-
191
-		if ( 'view' === $context ) {
192
-			return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this );
193
-		}
194
-
195
-		return $meta;
196
-
197
-	}
198
-
199
-	/**
200
-	 * Returns whether or not customers can update the item quantity.
201
-	 *
202
-	 * @since 1.0.19
203
-	 * @param  string $context View or edit context.
204
-	 * @return bool
205
-	 */
206
-	public function get_allow_quantities( $context = 'view' ) {
207
-		$allow_quantities = (bool) $this->allow_quantities;
208
-
209
-		if ( 'view' === $context ) {
210
-			return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this );
211
-		}
212
-
213
-		return $allow_quantities;
214
-
215
-	}
216
-
217
-	/**
218
-	 * Returns whether or not the item is required.
219
-	 *
220
-	 * @since 1.0.19
221
-	 * @param  string $context View or edit context.
222
-	 * @return bool
223
-	 */
224
-	public function get_is_required( $context = 'view' ) {
225
-		$is_required = (bool) $this->is_required;
226
-
227
-		if ( 'view' === $context ) {
228
-			return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this );
229
-		}
230
-
231
-		return $is_required;
232
-
233
-	}
234
-
235
-	/**
236
-	 * Prepares form data for use.
237
-	 *
238
-	 * @since 1.0.19
239
-	 * @return array
240
-	 */
241
-	public function prepare_data_for_use( $required = null ) {
242
-
243
-		$required = is_null( $required ) ? $this->is_required() : $required;
244
-		return array(
245
-			'title'            => wp_strip_all_tags( $this->get_name() ),
246
-			'id'               => $this->get_id(),
247
-			'price'            => $this->get_price(),
248
-			'recurring'        => $this->is_recurring(),
249
-			'description'      => $this->get_description(),
250
-			'allow_quantities' => $this->allows_quantities(),
251
-			'required'         => $required,
252
-		);
253
-
254
-	}
255
-
256
-	/**
257
-	 * Prepares form data for ajax use.
258
-	 *
259
-	 * @since 1.0.19
260
-	 * @return array
261
-	 */
262
-	public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) {
263
-
264
-		$description = getpaid_item_recurring_price_help_text( $this, $currency );
265
-
266
-		if ( $description ) {
267
-			$description = "<div class='getpaid-subscription-help-text'>$description</div>";
268
-		}
269
-
270
-		$price    = ! $is_renewal ? $this->get_price() : $this->get_recurring_price();
271
-		$subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total();
272
-		return array(
273
-			'id'     => $this->get_id(),
274
-			'texts'  => array(
275
-				'item-name'        => sanitize_text_field( $this->get_name() ),
276
-				'item-description' => wp_kses_post( $this->get_description() ) . $description,
277
-				'item-quantity'    => floatval( $this->get_quantity() ),
278
-				'item-price'       => wpinv_price( $price, $currency ),
279
-				'item-total'       => wpinv_price( $subtotal, $currency ),
280
-			),
281
-			'inputs' => array(
282
-				'item-id'          => $this->get_id(),
283
-				'item-name'        => sanitize_text_field( $this->get_name() ),
284
-				'item-description' => wp_kses_post( $this->get_description() ),
285
-				'item-quantity'    => floatval( $this->get_quantity() ),
286
-				'item-price'       => $price,
287
-			),
288
-		);
289
-
290
-	}
291
-
292
-	/**
293
-	 * Prepares form data for saving (cart_details).
294
-	 *
295
-	 * @since 1.0.19
296
-	 * @return array
297
-	 */
298
-	public function prepare_data_for_saving() {
299
-
300
-		return array(
301
-			'post_id'          => $this->invoice_id,
302
-			'item_id'          => $this->get_id(),
303
-			'item_name'        => sanitize_text_field( $this->get_raw_name( 'edit' ) ),
304
-			'item_description' => $this->get_description( 'edit' ),
305
-			'tax'              => $this->item_tax,
306
-			'item_price'       => $this->get_price( 'edit' ),
307
-			'quantity'         => (float) $this->get_quantity( 'edit' ),
308
-			'discount'         => $this->item_discount,
309
-			'subtotal'         => $this->get_sub_total( 'edit' ),
310
-			'price'            => $this->get_sub_total( 'edit' ) + $this->item_tax - $this->item_discount,
311
-			'meta'             => $this->get_item_meta( 'edit' ),
312
-		);
313
-
314
-	}
91
+     * Get the item name.
92
+     *
93
+     * @since 1.0.19
94
+     * @param  string $context View or edit context.
95
+     * @return string
96
+     */
97
+    public function get_name( $context = 'view' ) {
98
+        $name = parent::get_name( $context );
99
+        return $name . wpinv_get_item_suffix( $this );
100
+    }
101
+
102
+    /**
103
+     * Get the item name without a suffix.
104
+     *
105
+     * @since 1.0.19
106
+     * @param  string $context View or edit context.
107
+     * @return string
108
+     */
109
+    public function get_raw_name( $context = 'view' ) {
110
+        return parent::get_name( $context );
111
+    }
112
+
113
+    /**
114
+     * Get the item description.
115
+     *
116
+     * @since 1.0.19
117
+     * @param  string $context View or edit context.
118
+     * @return string
119
+     */
120
+    public function get_description( $context = 'view' ) {
121
+
122
+        if ( isset( $this->custom_description ) ) {
123
+            return $this->custom_description;
124
+        }
125
+
126
+        return parent::get_description( $context );
127
+    }
128
+
129
+    /**
130
+     * Returns the sub total.
131
+     *
132
+     * @since 1.0.19
133
+     * @param  string $context View or edit context.
134
+     * @return float
135
+     */
136
+    public function get_sub_total( $context = 'view' ) {
137
+        return $this->get_quantity( $context ) * $this->get_initial_price( $context );
138
+    }
139
+
140
+    /**
141
+     * Returns the recurring sub total.
142
+     *
143
+     * @since 1.0.19
144
+     * @param  string $context View or edit context.
145
+     * @return float
146
+     */
147
+    public function get_recurring_sub_total( $context = 'view' ) {
148
+
149
+        if ( $this->is_recurring() ) {
150
+            return $this->get_quantity( $context ) * $this->get_price( $context );
151
+        }
152
+
153
+        return 0;
154
+    }
155
+
156
+    /**
157
+     * @deprecated
158
+     */
159
+    public function get_qantity( $context = 'view' ) {
160
+        return $this->get_quantity( $context );
161
+    }
162
+
163
+    /**
164
+     * Get the item quantity.
165
+     *
166
+     * @since 1.0.19
167
+     * @param  string $context View or edit context.
168
+     * @return float
169
+     */
170
+    public function get_quantity( $context = 'view' ) {
171
+        $quantity = (float) $this->quantity;
172
+
173
+        if ( 'view' === $context ) {
174
+            return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this );
175
+        }
176
+
177
+        return $quantity;
178
+
179
+    }
180
+
181
+    /**
182
+     * Get the item meta data.
183
+     *
184
+     * @since 1.0.19
185
+     * @param  string $context View or edit context.
186
+     * @return meta
187
+     */
188
+    public function get_item_meta( $context = 'view' ) {
189
+        $meta = $this->meta;
190
+
191
+        if ( 'view' === $context ) {
192
+            return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this );
193
+        }
194
+
195
+        return $meta;
196
+
197
+    }
198
+
199
+    /**
200
+     * Returns whether or not customers can update the item quantity.
201
+     *
202
+     * @since 1.0.19
203
+     * @param  string $context View or edit context.
204
+     * @return bool
205
+     */
206
+    public function get_allow_quantities( $context = 'view' ) {
207
+        $allow_quantities = (bool) $this->allow_quantities;
208
+
209
+        if ( 'view' === $context ) {
210
+            return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this );
211
+        }
212
+
213
+        return $allow_quantities;
214
+
215
+    }
216
+
217
+    /**
218
+     * Returns whether or not the item is required.
219
+     *
220
+     * @since 1.0.19
221
+     * @param  string $context View or edit context.
222
+     * @return bool
223
+     */
224
+    public function get_is_required( $context = 'view' ) {
225
+        $is_required = (bool) $this->is_required;
226
+
227
+        if ( 'view' === $context ) {
228
+            return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this );
229
+        }
230
+
231
+        return $is_required;
232
+
233
+    }
234
+
235
+    /**
236
+     * Prepares form data for use.
237
+     *
238
+     * @since 1.0.19
239
+     * @return array
240
+     */
241
+    public function prepare_data_for_use( $required = null ) {
242
+
243
+        $required = is_null( $required ) ? $this->is_required() : $required;
244
+        return array(
245
+            'title'            => wp_strip_all_tags( $this->get_name() ),
246
+            'id'               => $this->get_id(),
247
+            'price'            => $this->get_price(),
248
+            'recurring'        => $this->is_recurring(),
249
+            'description'      => $this->get_description(),
250
+            'allow_quantities' => $this->allows_quantities(),
251
+            'required'         => $required,
252
+        );
253
+
254
+    }
255
+
256
+    /**
257
+     * Prepares form data for ajax use.
258
+     *
259
+     * @since 1.0.19
260
+     * @return array
261
+     */
262
+    public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) {
263
+
264
+        $description = getpaid_item_recurring_price_help_text( $this, $currency );
265
+
266
+        if ( $description ) {
267
+            $description = "<div class='getpaid-subscription-help-text'>$description</div>";
268
+        }
269
+
270
+        $price    = ! $is_renewal ? $this->get_price() : $this->get_recurring_price();
271
+        $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total();
272
+        return array(
273
+            'id'     => $this->get_id(),
274
+            'texts'  => array(
275
+                'item-name'        => sanitize_text_field( $this->get_name() ),
276
+                'item-description' => wp_kses_post( $this->get_description() ) . $description,
277
+                'item-quantity'    => floatval( $this->get_quantity() ),
278
+                'item-price'       => wpinv_price( $price, $currency ),
279
+                'item-total'       => wpinv_price( $subtotal, $currency ),
280
+            ),
281
+            'inputs' => array(
282
+                'item-id'          => $this->get_id(),
283
+                'item-name'        => sanitize_text_field( $this->get_name() ),
284
+                'item-description' => wp_kses_post( $this->get_description() ),
285
+                'item-quantity'    => floatval( $this->get_quantity() ),
286
+                'item-price'       => $price,
287
+            ),
288
+        );
289
+
290
+    }
291
+
292
+    /**
293
+     * Prepares form data for saving (cart_details).
294
+     *
295
+     * @since 1.0.19
296
+     * @return array
297
+     */
298
+    public function prepare_data_for_saving() {
299
+
300
+        return array(
301
+            'post_id'          => $this->invoice_id,
302
+            'item_id'          => $this->get_id(),
303
+            'item_name'        => sanitize_text_field( $this->get_raw_name( 'edit' ) ),
304
+            'item_description' => $this->get_description( 'edit' ),
305
+            'tax'              => $this->item_tax,
306
+            'item_price'       => $this->get_price( 'edit' ),
307
+            'quantity'         => (float) $this->get_quantity( 'edit' ),
308
+            'discount'         => $this->item_discount,
309
+            'subtotal'         => $this->get_sub_total( 'edit' ),
310
+            'price'            => $this->get_sub_total( 'edit' ) + $this->item_tax - $this->item_discount,
311
+            'meta'             => $this->get_item_meta( 'edit' ),
312
+        );
313
+
314
+    }
315 315
 
316 316
     /*
317 317
 	|--------------------------------------------------------------------------
@@ -323,70 +323,70 @@  discard block
 block discarded – undo
323 323
 	| object.
324 324
     */
325 325
 
326
-	/**
327
-	 * Set the item qantity.
328
-	 *
329
-	 * @since 1.0.19
330
-	 * @param  float $quantity The item quantity.
331
-	 */
332
-	public function set_quantity( $quantity ) {
333
-
334
-		if ( ! is_numeric( $quantity ) ) {
335
-			$quantity = 1;
336
-		}
337
-
338
-		$this->quantity = (float) $quantity;
339
-
340
-	}
341
-
342
-	/**
343
-	 * Set the item meta data.
344
-	 *
345
-	 * @since 1.0.19
346
-	 * @param  array $meta The item meta data.
347
-	 */
348
-	public function set_item_meta( $meta ) {
349
-		$this->meta = maybe_unserialize( $meta );
350
-	}
351
-
352
-	/**
353
-	 * Set whether or not the quantities are allowed.
354
-	 *
355
-	 * @since 1.0.19
356
-	 * @param  bool $allow_quantities
357
-	 */
358
-	public function set_allow_quantities( $allow_quantities ) {
359
-		$this->allow_quantities = (bool) $allow_quantities;
360
-	}
361
-
362
-	/**
363
-	 * Set whether or not the item is required.
364
-	 *
365
-	 * @since 1.0.19
366
-	 * @param  bool $is_required
367
-	 */
368
-	public function set_is_required( $is_required ) {
369
-		$this->is_required = (bool) $is_required;
370
-	}
371
-
372
-	/**
373
-	 * Sets the custom item description.
374
-	 *
375
-	 * @since 1.0.19
376
-	 * @param  string $description
377
-	 */
378
-	public function set_custom_description( $description ) {
379
-		$this->custom_description = $description;
380
-	}
326
+    /**
327
+     * Set the item qantity.
328
+     *
329
+     * @since 1.0.19
330
+     * @param  float $quantity The item quantity.
331
+     */
332
+    public function set_quantity( $quantity ) {
333
+
334
+        if ( ! is_numeric( $quantity ) ) {
335
+            $quantity = 1;
336
+        }
337
+
338
+        $this->quantity = (float) $quantity;
339
+
340
+    }
341
+
342
+    /**
343
+     * Set the item meta data.
344
+     *
345
+     * @since 1.0.19
346
+     * @param  array $meta The item meta data.
347
+     */
348
+    public function set_item_meta( $meta ) {
349
+        $this->meta = maybe_unserialize( $meta );
350
+    }
351
+
352
+    /**
353
+     * Set whether or not the quantities are allowed.
354
+     *
355
+     * @since 1.0.19
356
+     * @param  bool $allow_quantities
357
+     */
358
+    public function set_allow_quantities( $allow_quantities ) {
359
+        $this->allow_quantities = (bool) $allow_quantities;
360
+    }
361
+
362
+    /**
363
+     * Set whether or not the item is required.
364
+     *
365
+     * @since 1.0.19
366
+     * @param  bool $is_required
367
+     */
368
+    public function set_is_required( $is_required ) {
369
+        $this->is_required = (bool) $is_required;
370
+    }
371
+
372
+    /**
373
+     * Sets the custom item description.
374
+     *
375
+     * @since 1.0.19
376
+     * @param  string $description
377
+     */
378
+    public function set_custom_description( $description ) {
379
+        $this->custom_description = $description;
380
+    }
381 381
 
382 382
     /**
383 383
      * We do not want to save items to the database.
384 384
      *
385
-	 * @return int item id
385
+     * @return int item id
386 386
      */
387 387
     public function save( $data = array() ) {
388 388
         return $this->get_id();
389
-	}
389
+    }
390 390
 
391 391
     /*
392 392
 	|--------------------------------------------------------------------------
@@ -398,23 +398,23 @@  discard block
 block discarded – undo
398 398
 	*/
399 399
 
400 400
     /**
401
-	 * Checks whether the item has enabled dynamic pricing.
402
-	 *
403
-	 * @since 1.0.19
404
-	 * @return bool
405
-	 */
406
-	public function is_required() {
401
+     * Checks whether the item has enabled dynamic pricing.
402
+     *
403
+     * @since 1.0.19
404
+     * @return bool
405
+     */
406
+    public function is_required() {
407 407
         return (bool) $this->get_is_required();
408
-	}
409
-
410
-	/**
411
-	 * Checks whether users can edit the quantities.
412
-	 *
413
-	 * @since 1.0.19
414
-	 * @return bool
415
-	 */
416
-	public function allows_quantities() {
408
+    }
409
+
410
+    /**
411
+     * Checks whether users can edit the quantities.
412
+     *
413
+     * @since 1.0.19
414
+     * @return bool
415
+     */
416
+    public function allows_quantities() {
417 417
         return (bool) $this->get_allow_quantities();
418
-	}
418
+    }
419 419
 
420 420
 }
Please login to merge, or discard this patch.
vendor/ayecode/wp-font-awesome-settings/wp-font-awesome-settings.php 1 patch
Indentation   +763 added lines, -763 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * Bail if we are not in WP.
14 14
  */
15 15
 if ( ! defined( 'ABSPATH' ) ) {
16
-	exit;
16
+    exit;
17 17
 }
18 18
 
19 19
 /**
@@ -21,362 +21,362 @@  discard block
 block discarded – undo
21 21
  */
22 22
 if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) {
23 23
 
24
-	/**
25
-	 * A Class to be able to change settings for Font Awesome.
26
-	 *
27
-	 * Class WP_Font_Awesome_Settings
28
-	 * @since 1.0.10 Now able to pass wp.org theme check.
29
-	 * @since 1.0.11 Font Awesome Pro now supported.
30
-	 * @since 1.0.11 Font Awesome Kits now supported.
31
-	 * @since 1.0.13 RTL language support added.
32
-	 * @since 1.0.14 Warning added for v6 pro requires kit and will now not work if official FA plugin installed.
33
-	 * @since 1.0.15 Font Awesome will now load in the FSE if enable din the backend.
34
-	 * @since 1.1.0 Option added to load FontAwesome locally.
35
-	 * @since 1.1.1 Requires to re-save settings to load locally when option does not exists - FIXED.
36
-	 * @since 1.1.2 Bumped the latest version to 6.3.0 - CHANGED.
37
-	 * @ver 1.0.15
38
-	 * @todo decide how to implement textdomain
39
-	 */
40
-	class WP_Font_Awesome_Settings {
41
-
42
-		/**
43
-		 * Class version version.
44
-		 *
45
-		 * @var string
46
-		 */
47
-		public $version = '1.1.2';
48
-
49
-		/**
50
-		 * Class textdomain.
51
-		 *
52
-		 * @var string
53
-		 */
54
-		public $textdomain = 'font-awesome-settings';
55
-
56
-		/**
57
-		 * Latest version of Font Awesome at time of publish published.
58
-		 *
59
-		 * @var string
60
-		 */
61
-		public $latest = "6.3.0";
62
-
63
-		/**
64
-		 * The title.
65
-		 *
66
-		 * @var string
67
-		 */
68
-		public $name = 'Font Awesome';
69
-
70
-		/**
71
-		 * Holds the settings values.
72
-		 *
73
-		 * @var array
74
-		 */
75
-		private $settings;
76
-
77
-		/**
78
-		 * WP_Font_Awesome_Settings instance.
79
-		 *
80
-		 * @access private
81
-		 * @since  1.0.0
82
-		 * @var    WP_Font_Awesome_Settings There can be only one!
83
-		 */
84
-		private static $instance = null;
85
-
86
-		/**
87
-		 * Main WP_Font_Awesome_Settings Instance.
88
-		 *
89
-		 * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded.
90
-		 *
91
-		 * @since 1.0.0
92
-		 * @static
93
-		 * @return WP_Font_Awesome_Settings - Main instance.
94
-		 */
95
-		public static function instance() {
96
-			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
97
-				self::$instance = new WP_Font_Awesome_Settings;
98
-
99
-				add_action( 'init', array( self::$instance, 'init' ) ); // set settings
100
-
101
-				if ( is_admin() ) {
102
-					add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
103
-					add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
104
-					add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) );
105
-				}
106
-
107
-				do_action( 'wp_font_awesome_settings_loaded' );
108
-			}
109
-
110
-			return self::$instance;
111
-		}
112
-
113
-		/**
114
-		 * Initiate the settings and add the required action hooks.
115
-		 *
116
-		 * @since 1.0.8 Settings name wrong - FIXED
117
-		 */
118
-		public function init() {
119
-			// Download fontawesome locally.
120
-			add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 );
121
-			add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );
122
-
123
-			$this->settings = $this->get_settings();
124
-
125
-			// check if the official plugin is active and use that instead if so.
126
-			if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
127
-
128
-				if ( $this->settings['type'] == 'CSS' ) {
129
-
130
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
131
-						add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
132
-					}
133
-
134
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
135
-						add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
136
-						add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 );
137
-					}
138
-
139
-				} else {
140
-
141
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
142
-						add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
143
-					}
144
-
145
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
146
-						add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
147
-						add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 );
148
-					}
149
-				}
150
-
151
-				// remove font awesome if set to do so
152
-				if ( $this->settings['dequeue'] == '1' ) {
153
-					add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
154
-				}
155
-			}
156
-
157
-		}
158
-
159
-		/**
160
-		 * Add FA to the FSE.
161
-		 *
162
-		 * @param $editor_settings
163
-		 * @param $block_editor_context
164
-		 *
165
-		 * @return array
166
-		 */
167
-		public function enqueue_editor_styles( $editor_settings, $block_editor_context ){
168
-
169
-			if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) {
170
-				$url = $this->get_url();
171
-				$editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css'  href='$url' media='all' />";
172
-			}
173
-
174
-			return $editor_settings;
175
-		}
176
-
177
-		/**
178
-		 * Add FA to the FSE.
179
-		 *
180
-		 * @param $editor_settings
181
-		 * @param $block_editor_context
182
-		 *
183
-		 * @return array
184
-		 */
185
-		public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){
186
-
187
-			$url = $this->get_url();
188
-			$editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>";
189
-
190
-			return $editor_settings;
191
-		}
192
-
193
-		/**
194
-		 * Adds the Font Awesome styles.
195
-		 */
196
-		public function enqueue_style() {
197
-			// build url
198
-			$url = $this->get_url();
199
-			$version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null;
200
-
201
-			wp_deregister_style( 'font-awesome' ); // deregister in case its already there
202
-			wp_register_style( 'font-awesome', $url, array(), $version );
203
-			wp_enqueue_style( 'font-awesome' );
204
-
205
-			// RTL language support CSS.
206
-			if ( is_rtl() ) {
207
-				wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() );
208
-			}
209
-
210
-			if ( $this->settings['shims'] ) {
211
-				$url = $this->get_url( true );
212
-				wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
213
-				wp_register_style( 'font-awesome-shims', $url, array(), $version );
214
-				wp_enqueue_style( 'font-awesome-shims' );
215
-			}
216
-		}
217
-
218
-		/**
219
-		 * Adds the Font Awesome JS.
220
-		 */
221
-		public function enqueue_scripts() {
222
-			// build url
223
-			$url = $this->get_url();
224
-
225
-			$deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script';
226
-			call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there
227
-			wp_register_script( 'font-awesome', $url, array(), null );
228
-			wp_enqueue_script( 'font-awesome' );
229
-
230
-			if ( $this->settings['shims'] ) {
231
-				$url = $this->get_url( true );
232
-				call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there
233
-				wp_register_script( 'font-awesome-shims', $url, array(), null );
234
-				wp_enqueue_script( 'font-awesome-shims' );
235
-			}
236
-		}
237
-
238
-		/**
239
-		 * Get the url of the Font Awesome files.
240
-		 *
241
-		 * @param bool $shims If this is a shim file or not.
242
-		 * @param bool $local Load locally if allowed.
243
-		 *
244
-		 * @return string The url to the file.
245
-		 */
246
-		public function get_url( $shims = false, $local = true ) {
247
-			$script  = $shims ? 'v4-shims' : 'all';
248
-			$sub     = $this->settings['pro'] ? 'pro' : 'use';
249
-			$type    = $this->settings['type'];
250
-			$version = $this->settings['version'];
251
-			$kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : '';
252
-			$url     = '';
253
-
254
-			if ( $type == 'KIT' && $kit_url ) {
255
-				if ( $shims ) {
256
-					// if its a kit then we don't add shims here
257
-					return '';
258
-				}
259
-				$url .= $kit_url; // CDN
260
-				$url .= "?wpfas=true"; // set our var so our version is not removed
261
-			} else {
262
-				$v = '';
263
-				// Check and load locally.
264
-				if ( $local && $this->has_local() ) {
265
-					$script .= ".min";
266
-					$v .= '&ver=' . strip_tags( $this->settings['local_version'] );
267
-					$url .= $this->get_fonts_url(); // Local fonts url.
268
-				} else {
269
-					$url .= "https://$sub.fontawesome.com/releases/"; // CDN
270
-					$url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
271
-				}
272
-				$url .= $type == 'CSS' ? 'css/' : 'js/'; // type
273
-				$url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
274
-				$url .= "?wpfas=true" . $v; // set our var so our version is not removed
275
-			}
276
-
277
-			return $url;
278
-		}
279
-
280
-		/**
281
-		 * Try and remove any other versions of Font Awesome added by other plugins/themes.
282
-		 *
283
-		 * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version.
284
-		 *
285
-		 * @param $url
286
-		 * @param $original_url
287
-		 * @param $_context
288
-		 *
289
-		 * @return string The filtered url.
290
-		 */
291
-		public function remove_font_awesome( $url, $original_url, $_context ) {
292
-
293
-			if ( $_context == 'display'
294
-			     && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
295
-			     && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
296
-			) {// it's a font-awesome-url (probably)
297
-
298
-				if ( strstr( $url, "wpfas=true" ) !== false ) {
299
-					if ( $this->settings['type'] == 'JS' ) {
300
-						if ( $this->settings['js-pseudo'] ) {
301
-							$url .= "' data-search-pseudo-elements defer='defer";
302
-						} else {
303
-							$url .= "' defer='defer";
304
-						}
305
-					}
306
-				} else {
307
-					$url = ''; // removing the url removes the file
308
-				}
309
-
310
-			}
311
-
312
-			return $url;
313
-		}
314
-
315
-		/**
316
-		 * Register the database settings with WordPress.
317
-		 */
318
-		public function register_settings() {
319
-			register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
320
-		}
321
-
322
-		/**
323
-		 * Add the WordPress settings menu item.
324
-		 * @since 1.0.10 Calling function name direct will fail theme check so we don't.
325
-		 */
326
-		public function menu_item() {
327
-			$menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
328
-			call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
329
-				$this,
330
-				'settings_page'
331
-			) );
332
-		}
333
-
334
-		/**
335
-		 * Get the current Font Awesome output settings.
336
-		 *
337
-		 * @return array The array of settings.
338
-		 */
339
-		public function get_settings() {
340
-			$db_settings = get_option( 'wp-font-awesome-settings' );
341
-
342
-			$defaults = array(
343
-				'type'      => 'CSS', // type to use, CSS or JS or KIT
344
-				'version'   => '', // latest
345
-				'enqueue'   => '', // front and backend
346
-				'shims'     => '0', // default OFF now in 2020
347
-				'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive)
348
-				'dequeue'   => '0', // if we should try to remove other versions added by other plugins/themes
349
-				'pro'       => '0', // if pro CDN url should be used
350
-				'local'     => '0', // Store fonts locally.
351
-				'local_version' => '', // Local fonts version.
352
-				'kit-url'   => '', // the kit url
353
-			);
354
-
355
-			$settings = wp_parse_args( $db_settings, $defaults );
356
-
357
-			/**
358
-			 * Filter the Font Awesome settings.
359
-			 *
360
-			 * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
361
-			 */
362
-			return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
363
-		}
364
-
365
-		/**
366
-		 * The settings page html output.
367
-		 */
368
-		public function settings_page() {
369
-			if ( ! current_user_can( 'manage_options' ) ) {
370
-				wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) );
371
-			}
372
-
373
-			// a hidden way to force the update of the version number via api instead of waiting the 48 hours
374
-			if ( isset( $_REQUEST['force-version-check'] ) ) {
375
-				$this->get_latest_version( $force_api = true );
376
-			}
377
-
378
-			if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
379
-				?>
24
+    /**
25
+     * A Class to be able to change settings for Font Awesome.
26
+     *
27
+     * Class WP_Font_Awesome_Settings
28
+     * @since 1.0.10 Now able to pass wp.org theme check.
29
+     * @since 1.0.11 Font Awesome Pro now supported.
30
+     * @since 1.0.11 Font Awesome Kits now supported.
31
+     * @since 1.0.13 RTL language support added.
32
+     * @since 1.0.14 Warning added for v6 pro requires kit and will now not work if official FA plugin installed.
33
+     * @since 1.0.15 Font Awesome will now load in the FSE if enable din the backend.
34
+     * @since 1.1.0 Option added to load FontAwesome locally.
35
+     * @since 1.1.1 Requires to re-save settings to load locally when option does not exists - FIXED.
36
+     * @since 1.1.2 Bumped the latest version to 6.3.0 - CHANGED.
37
+     * @ver 1.0.15
38
+     * @todo decide how to implement textdomain
39
+     */
40
+    class WP_Font_Awesome_Settings {
41
+
42
+        /**
43
+         * Class version version.
44
+         *
45
+         * @var string
46
+         */
47
+        public $version = '1.1.2';
48
+
49
+        /**
50
+         * Class textdomain.
51
+         *
52
+         * @var string
53
+         */
54
+        public $textdomain = 'font-awesome-settings';
55
+
56
+        /**
57
+         * Latest version of Font Awesome at time of publish published.
58
+         *
59
+         * @var string
60
+         */
61
+        public $latest = "6.3.0";
62
+
63
+        /**
64
+         * The title.
65
+         *
66
+         * @var string
67
+         */
68
+        public $name = 'Font Awesome';
69
+
70
+        /**
71
+         * Holds the settings values.
72
+         *
73
+         * @var array
74
+         */
75
+        private $settings;
76
+
77
+        /**
78
+         * WP_Font_Awesome_Settings instance.
79
+         *
80
+         * @access private
81
+         * @since  1.0.0
82
+         * @var    WP_Font_Awesome_Settings There can be only one!
83
+         */
84
+        private static $instance = null;
85
+
86
+        /**
87
+         * Main WP_Font_Awesome_Settings Instance.
88
+         *
89
+         * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded.
90
+         *
91
+         * @since 1.0.0
92
+         * @static
93
+         * @return WP_Font_Awesome_Settings - Main instance.
94
+         */
95
+        public static function instance() {
96
+            if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
97
+                self::$instance = new WP_Font_Awesome_Settings;
98
+
99
+                add_action( 'init', array( self::$instance, 'init' ) ); // set settings
100
+
101
+                if ( is_admin() ) {
102
+                    add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
103
+                    add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
104
+                    add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) );
105
+                }
106
+
107
+                do_action( 'wp_font_awesome_settings_loaded' );
108
+            }
109
+
110
+            return self::$instance;
111
+        }
112
+
113
+        /**
114
+         * Initiate the settings and add the required action hooks.
115
+         *
116
+         * @since 1.0.8 Settings name wrong - FIXED
117
+         */
118
+        public function init() {
119
+            // Download fontawesome locally.
120
+            add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 );
121
+            add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );
122
+
123
+            $this->settings = $this->get_settings();
124
+
125
+            // check if the official plugin is active and use that instead if so.
126
+            if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
127
+
128
+                if ( $this->settings['type'] == 'CSS' ) {
129
+
130
+                    if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
131
+                        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
132
+                    }
133
+
134
+                    if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
135
+                        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
136
+                        add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 );
137
+                    }
138
+
139
+                } else {
140
+
141
+                    if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
142
+                        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
143
+                    }
144
+
145
+                    if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
146
+                        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
147
+                        add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 );
148
+                    }
149
+                }
150
+
151
+                // remove font awesome if set to do so
152
+                if ( $this->settings['dequeue'] == '1' ) {
153
+                    add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
154
+                }
155
+            }
156
+
157
+        }
158
+
159
+        /**
160
+         * Add FA to the FSE.
161
+         *
162
+         * @param $editor_settings
163
+         * @param $block_editor_context
164
+         *
165
+         * @return array
166
+         */
167
+        public function enqueue_editor_styles( $editor_settings, $block_editor_context ){
168
+
169
+            if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) {
170
+                $url = $this->get_url();
171
+                $editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css'  href='$url' media='all' />";
172
+            }
173
+
174
+            return $editor_settings;
175
+        }
176
+
177
+        /**
178
+         * Add FA to the FSE.
179
+         *
180
+         * @param $editor_settings
181
+         * @param $block_editor_context
182
+         *
183
+         * @return array
184
+         */
185
+        public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){
186
+
187
+            $url = $this->get_url();
188
+            $editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>";
189
+
190
+            return $editor_settings;
191
+        }
192
+
193
+        /**
194
+         * Adds the Font Awesome styles.
195
+         */
196
+        public function enqueue_style() {
197
+            // build url
198
+            $url = $this->get_url();
199
+            $version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null;
200
+
201
+            wp_deregister_style( 'font-awesome' ); // deregister in case its already there
202
+            wp_register_style( 'font-awesome', $url, array(), $version );
203
+            wp_enqueue_style( 'font-awesome' );
204
+
205
+            // RTL language support CSS.
206
+            if ( is_rtl() ) {
207
+                wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() );
208
+            }
209
+
210
+            if ( $this->settings['shims'] ) {
211
+                $url = $this->get_url( true );
212
+                wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
213
+                wp_register_style( 'font-awesome-shims', $url, array(), $version );
214
+                wp_enqueue_style( 'font-awesome-shims' );
215
+            }
216
+        }
217
+
218
+        /**
219
+         * Adds the Font Awesome JS.
220
+         */
221
+        public function enqueue_scripts() {
222
+            // build url
223
+            $url = $this->get_url();
224
+
225
+            $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script';
226
+            call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there
227
+            wp_register_script( 'font-awesome', $url, array(), null );
228
+            wp_enqueue_script( 'font-awesome' );
229
+
230
+            if ( $this->settings['shims'] ) {
231
+                $url = $this->get_url( true );
232
+                call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there
233
+                wp_register_script( 'font-awesome-shims', $url, array(), null );
234
+                wp_enqueue_script( 'font-awesome-shims' );
235
+            }
236
+        }
237
+
238
+        /**
239
+         * Get the url of the Font Awesome files.
240
+         *
241
+         * @param bool $shims If this is a shim file or not.
242
+         * @param bool $local Load locally if allowed.
243
+         *
244
+         * @return string The url to the file.
245
+         */
246
+        public function get_url( $shims = false, $local = true ) {
247
+            $script  = $shims ? 'v4-shims' : 'all';
248
+            $sub     = $this->settings['pro'] ? 'pro' : 'use';
249
+            $type    = $this->settings['type'];
250
+            $version = $this->settings['version'];
251
+            $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : '';
252
+            $url     = '';
253
+
254
+            if ( $type == 'KIT' && $kit_url ) {
255
+                if ( $shims ) {
256
+                    // if its a kit then we don't add shims here
257
+                    return '';
258
+                }
259
+                $url .= $kit_url; // CDN
260
+                $url .= "?wpfas=true"; // set our var so our version is not removed
261
+            } else {
262
+                $v = '';
263
+                // Check and load locally.
264
+                if ( $local && $this->has_local() ) {
265
+                    $script .= ".min";
266
+                    $v .= '&ver=' . strip_tags( $this->settings['local_version'] );
267
+                    $url .= $this->get_fonts_url(); // Local fonts url.
268
+                } else {
269
+                    $url .= "https://$sub.fontawesome.com/releases/"; // CDN
270
+                    $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
271
+                }
272
+                $url .= $type == 'CSS' ? 'css/' : 'js/'; // type
273
+                $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
274
+                $url .= "?wpfas=true" . $v; // set our var so our version is not removed
275
+            }
276
+
277
+            return $url;
278
+        }
279
+
280
+        /**
281
+         * Try and remove any other versions of Font Awesome added by other plugins/themes.
282
+         *
283
+         * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version.
284
+         *
285
+         * @param $url
286
+         * @param $original_url
287
+         * @param $_context
288
+         *
289
+         * @return string The filtered url.
290
+         */
291
+        public function remove_font_awesome( $url, $original_url, $_context ) {
292
+
293
+            if ( $_context == 'display'
294
+                 && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
295
+                 && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
296
+            ) {// it's a font-awesome-url (probably)
297
+
298
+                if ( strstr( $url, "wpfas=true" ) !== false ) {
299
+                    if ( $this->settings['type'] == 'JS' ) {
300
+                        if ( $this->settings['js-pseudo'] ) {
301
+                            $url .= "' data-search-pseudo-elements defer='defer";
302
+                        } else {
303
+                            $url .= "' defer='defer";
304
+                        }
305
+                    }
306
+                } else {
307
+                    $url = ''; // removing the url removes the file
308
+                }
309
+
310
+            }
311
+
312
+            return $url;
313
+        }
314
+
315
+        /**
316
+         * Register the database settings with WordPress.
317
+         */
318
+        public function register_settings() {
319
+            register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
320
+        }
321
+
322
+        /**
323
+         * Add the WordPress settings menu item.
324
+         * @since 1.0.10 Calling function name direct will fail theme check so we don't.
325
+         */
326
+        public function menu_item() {
327
+            $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
328
+            call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
329
+                $this,
330
+                'settings_page'
331
+            ) );
332
+        }
333
+
334
+        /**
335
+         * Get the current Font Awesome output settings.
336
+         *
337
+         * @return array The array of settings.
338
+         */
339
+        public function get_settings() {
340
+            $db_settings = get_option( 'wp-font-awesome-settings' );
341
+
342
+            $defaults = array(
343
+                'type'      => 'CSS', // type to use, CSS or JS or KIT
344
+                'version'   => '', // latest
345
+                'enqueue'   => '', // front and backend
346
+                'shims'     => '0', // default OFF now in 2020
347
+                'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive)
348
+                'dequeue'   => '0', // if we should try to remove other versions added by other plugins/themes
349
+                'pro'       => '0', // if pro CDN url should be used
350
+                'local'     => '0', // Store fonts locally.
351
+                'local_version' => '', // Local fonts version.
352
+                'kit-url'   => '', // the kit url
353
+            );
354
+
355
+            $settings = wp_parse_args( $db_settings, $defaults );
356
+
357
+            /**
358
+             * Filter the Font Awesome settings.
359
+             *
360
+             * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
361
+             */
362
+            return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
363
+        }
364
+
365
+        /**
366
+         * The settings page html output.
367
+         */
368
+        public function settings_page() {
369
+            if ( ! current_user_can( 'manage_options' ) ) {
370
+                wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) );
371
+            }
372
+
373
+            // a hidden way to force the update of the version number via api instead of waiting the 48 hours
374
+            if ( isset( $_REQUEST['force-version-check'] ) ) {
375
+                $this->get_latest_version( $force_api = true );
376
+            }
377
+
378
+            if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
379
+                ?>
380 380
                 <style>
381 381
                     .wpfas-kit-show {
382 382
                         display: none;
@@ -402,16 +402,16 @@  discard block
 block discarded – undo
402 402
                     <h1><?php echo $this->name; ?></h1>
403 403
                     <form method="post" action="options.php" class="fas-settings-form">
404 404
 						<?php
405
-						settings_fields( 'wp-font-awesome-settings' );
406
-						do_settings_sections( 'wp-font-awesome-settings' );
407
-						$table_class = '';
408
-						if ( $this->settings['type'] ) {
409
-							$table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set';
410
-						}
411
-						if ( ! empty( $this->settings['pro'] ) ) {
412
-							$table_class .= ' wpfas-has-pro';
413
-						}
414
-						?>
405
+                        settings_fields( 'wp-font-awesome-settings' );
406
+                        do_settings_sections( 'wp-font-awesome-settings' );
407
+                        $table_class = '';
408
+                        if ( $this->settings['type'] ) {
409
+                            $table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set';
410
+                        }
411
+                        if ( ! empty( $this->settings['pro'] ) ) {
412
+                            $table_class .= ' wpfas-has-pro';
413
+                        }
414
+                        ?>
415 415
 						<?php if ( $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ) { ?>
416 416
 							<?php if ( $this->has_local() ) { ?>
417 417
 							<div class="notice notice-info"><p><strong><?php _e( 'Font Awesome fonts are loading locally.', 'font-awesome-settings' ); ?></strong></p></div>
@@ -436,12 +436,12 @@  discard block
 block discarded – undo
436 436
                                 <td>
437 437
                                     <input class="regular-text" id="wpfas-kit-url" type="url" name="wp-font-awesome-settings[kit-url]" value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/>
438 438
                                     <span><?php
439
-										echo sprintf(
440
-											__( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ),
441
-											'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>',
442
-											'</a>'
443
-										);
444
-										?></span>
439
+                                        echo sprintf(
440
+                                            __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ),
441
+                                            '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>',
442
+                                            '</a>'
443
+                                        );
444
+                                        ?></span>
445 445
                                 </td>
446 446
                             </tr>
447 447
 
@@ -482,14 +482,14 @@  discard block
 block discarded – undo
482 482
                                     <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/>
483 483
                                     <input type="checkbox" name="wp-font-awesome-settings[pro]" value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro" onchange="if(jQuery(this).is(':checked')){jQuery('.wpfas-table-settings').addClass('wpfas-has-pro')}else{jQuery('.wpfas-table-settings').removeClass('wpfas-has-pro')}"/>
484 484
                                     <span><?php
485
-										echo wp_sprintf(
486
-											__( 'Requires a subscription. %sLearn more%s  %sManage my allowed domains%s', 'font-awesome-settings' ),
487
-											'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">',
488
-											' <i class="fas fa-external-link-alt"></i></a>',
489
-											'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">',
490
-											' <i class="fas fa-external-link-alt"></i></a>'
491
-										);
492
-										?></span>
485
+                                        echo wp_sprintf(
486
+                                            __( 'Requires a subscription. %sLearn more%s  %sManage my allowed domains%s', 'font-awesome-settings' ),
487
+                                            '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">',
488
+                                            ' <i class="fas fa-external-link-alt"></i></a>',
489
+                                            '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">',
490
+                                            ' <i class="fas fa-external-link-alt"></i></a>'
491
+                                        );
492
+                                        ?></span>
493 493
                                 </td>
494 494
                             </tr>
495 495
 
@@ -543,8 +543,8 @@  discard block
 block discarded – undo
543 543
                         </table>
544 544
                         <div class="fas-buttons">
545 545
 							<?php
546
-							submit_button();
547
-							?>
546
+                            submit_button();
547
+                            ?>
548 548
                             <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 14,000+ more icons with Font Awesome Pro','font-awesome-settings'); ?> <i class="fas fa-external-link-alt"></i></a></p>
549 549
 
550 550
                         </div>
@@ -553,392 +553,392 @@  discard block
 block discarded – undo
553 553
                     <div id="wpfas-version"><?php echo sprintf(__( 'Version: %s (affiliate links provided)', 'font-awesome-settings' ), $this->version ); ?></div>
554 554
                 </div>
555 555
 				<?php
556
-			}
557
-		}
558
-
559
-		/**
560
-		 * Check a version number is valid and if so return it or else return an empty string.
561
-		 *
562
-		 * @param $version string The version number to check.
563
-		 *
564
-		 * @since 1.0.6
565
-		 *
566
-		 * @return string Either a valid version number or an empty string.
567
-		 */
568
-		public function validate_version_number( $version ) {
569
-
570
-			if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
571
-				// valid
572
-			} else {
573
-				$version = '';// not validated
574
-			}
575
-
576
-			return $version;
577
-		}
578
-
579
-
580
-		/**
581
-		 * Get the latest version of Font Awesome.
582
-		 *
583
-		 * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours.
584
-		 *
585
-		 * @since 1.0.7
586
-		 * @return mixed|string The latest version number found.
587
-		 */
588
-		public function get_latest_version( $force_api = false ) {
589
-			$latest_version = $this->latest;
590
-
591
-			$cache = get_transient( 'wp-font-awesome-settings-version' );
592
-
593
-			if ( $cache === false || $force_api ) { // its not set
594
-				$api_ver = $this->get_latest_version_from_api();
595
-				if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
596
-					$latest_version = $api_ver;
597
-					set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
598
-				}
599
-			} elseif ( $this->validate_version_number( $cache ) ) {
600
-				if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
601
-					$latest_version = $cache;
602
-				}
603
-			}
604
-
605
-			// Check and auto download fonts locally.
606
-			if ( empty( $this->settings['pro'] ) && empty( $this->settings['version'] ) && $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && ! empty( $this->settings['local_version'] ) && ! empty( $latest_version ) ) {
607
-				if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) {
608
-					$this->download_package( $latest_version );
609
-				}
610
-			}
611
-
612
-			return $latest_version;
613
-		}
614
-
615
-		/**
616
-		 * Get the latest Font Awesome version from the github API.
617
-		 *
618
-		 * @since 1.0.7
619
-		 * @return string The latest version number or `0` on API fail.
620
-		 */
621
-		public function get_latest_version_from_api() {
622
-			$version  = "0";
623
-			$response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
624
-			if ( ! is_wp_error( $response ) && is_array( $response ) ) {
625
-				$api_response = json_decode( wp_remote_retrieve_body( $response ), true );
626
-				if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
627
-					$version = $api_response['tag_name'];
628
-				}
629
-			}
630
-
631
-			return $version;
632
-		}
633
-
634
-		/**
635
-		 * Inline CSS for RTL language support.
636
-		 *
637
-		 * @since 1.0.13
638
-		 * @return string Inline CSS.
639
-		 */
640
-		public function rtl_inline_css() {
641
-			$inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}';
642
-
643
-			return $inline_css;
644
-		}
645
-
646
-		/**
647
-		 * Show any warnings as an admin notice.
648
-		 *
649
-		 * @return void
650
-		 */
651
-		public function admin_notices() {
652
-			$settings = $this->settings;
653
-
654
-			if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
655
-				if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) {
656
-					?>
556
+            }
557
+        }
558
+
559
+        /**
560
+         * Check a version number is valid and if so return it or else return an empty string.
561
+         *
562
+         * @param $version string The version number to check.
563
+         *
564
+         * @since 1.0.6
565
+         *
566
+         * @return string Either a valid version number or an empty string.
567
+         */
568
+        public function validate_version_number( $version ) {
569
+
570
+            if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
571
+                // valid
572
+            } else {
573
+                $version = '';// not validated
574
+            }
575
+
576
+            return $version;
577
+        }
578
+
579
+
580
+        /**
581
+         * Get the latest version of Font Awesome.
582
+         *
583
+         * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours.
584
+         *
585
+         * @since 1.0.7
586
+         * @return mixed|string The latest version number found.
587
+         */
588
+        public function get_latest_version( $force_api = false ) {
589
+            $latest_version = $this->latest;
590
+
591
+            $cache = get_transient( 'wp-font-awesome-settings-version' );
592
+
593
+            if ( $cache === false || $force_api ) { // its not set
594
+                $api_ver = $this->get_latest_version_from_api();
595
+                if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
596
+                    $latest_version = $api_ver;
597
+                    set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
598
+                }
599
+            } elseif ( $this->validate_version_number( $cache ) ) {
600
+                if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
601
+                    $latest_version = $cache;
602
+                }
603
+            }
604
+
605
+            // Check and auto download fonts locally.
606
+            if ( empty( $this->settings['pro'] ) && empty( $this->settings['version'] ) && $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && ! empty( $this->settings['local_version'] ) && ! empty( $latest_version ) ) {
607
+                if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) {
608
+                    $this->download_package( $latest_version );
609
+                }
610
+            }
611
+
612
+            return $latest_version;
613
+        }
614
+
615
+        /**
616
+         * Get the latest Font Awesome version from the github API.
617
+         *
618
+         * @since 1.0.7
619
+         * @return string The latest version number or `0` on API fail.
620
+         */
621
+        public function get_latest_version_from_api() {
622
+            $version  = "0";
623
+            $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
624
+            if ( ! is_wp_error( $response ) && is_array( $response ) ) {
625
+                $api_response = json_decode( wp_remote_retrieve_body( $response ), true );
626
+                if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
627
+                    $version = $api_response['tag_name'];
628
+                }
629
+            }
630
+
631
+            return $version;
632
+        }
633
+
634
+        /**
635
+         * Inline CSS for RTL language support.
636
+         *
637
+         * @since 1.0.13
638
+         * @return string Inline CSS.
639
+         */
640
+        public function rtl_inline_css() {
641
+            $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}';
642
+
643
+            return $inline_css;
644
+        }
645
+
646
+        /**
647
+         * Show any warnings as an admin notice.
648
+         *
649
+         * @return void
650
+         */
651
+        public function admin_notices() {
652
+            $settings = $this->settings;
653
+
654
+            if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
655
+                if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) {
656
+                    ?>
657 657
                     <div class="notice  notice-error is-dismissible">
658 658
                         <p><?php _e( 'The Official Font Awesome Plugin is active, please adjust your settings there.', 'font-awesome-settings' ); ?></p>
659 659
                     </div>
660 660
 					<?php
661
-				}
662
-			} else {
663
-				if ( ! empty( $settings ) ) {
664
-					if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) {
665
-						$link = admin_url('options-general.php?page=wp-font-awesome-settings');
666
-						?>
661
+                }
662
+            } else {
663
+                if ( ! empty( $settings ) ) {
664
+                    if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) {
665
+                        $link = admin_url('options-general.php?page=wp-font-awesome-settings');
666
+                        ?>
667 667
                         <div class="notice  notice-error is-dismissible">
668 668
                             <p><?php echo sprintf( __( 'Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'font-awesome-settings' ),"<a href='". esc_url_raw( $link )."'>","</a>" ); ?></p>
669 669
                         </div>
670 670
 						<?php
671
-					}
672
-				}
673
-			}
674
-		}
675
-
676
-		/**
677
-		 * Handle fontawesome add settings to download fontawesome to store locally.
678
-		 *
679
-		 * @since 1.1.1
680
-		 *
681
-		 * @param string $option The option name.
682
-		 * @param mixed  $value  The option value.
683
-		 */
684
-		public function add_option_wp_font_awesome_settings( $option, $value ) {
685
-			// Do nothing if WordPress is being installed.
686
-			if ( wp_installing() ) {
687
-				return;
688
-			}
689
-
690
-			if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) {
691
-				$version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version();
692
-
693
-				if ( ! empty( $version ) ) {
694
-					$response = $this->download_package( $version, $value );
695
-
696
-					if ( is_wp_error( $response ) ) {
697
-						add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'font-awesome-settings' ) . ' ' . $response->get_error_message(), 'error' );
698
-					}
699
-				}
700
-			}
701
-		}
702
-
703
-		/**
704
-		 * Handle fontawesome update settings to download fontawesome to store locally.
705
-		 *
706
-		 * @since 1.1.0
707
-		 *
708
-		 * @param mixed $old_value The old option value.
709
-		 * @param mixed $value     The new option value.
710
-		 */
711
-		public function update_option_wp_font_awesome_settings( $old_value, $new_value ) {
712
-			// Do nothing if WordPress is being installed.
713
-			if ( wp_installing() ) {
714
-				return;
715
-			}
716
-
717
-			if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) {
718
-				// Old values
719
-				$old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' );
720
-				$old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0;
721
-
722
-				// New values
723
-				$new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version();
724
-
725
-				if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
726
-					$response = $this->download_package( $new_version, $new_value );
727
-
728
-					if ( is_wp_error( $response ) ) {
729
-						add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'font-awesome-settings' ) . ' ' . $response->get_error_message(), 'error' );
730
-					}
731
-				}
732
-			}
733
-		}
734
-
735
-		/**
736
-		 * Get the fonts directory local path.
737
-		 *
738
-		 * @since 1.1.0
739
-		 *
740
-		 * @param string Fonts directory local path.
741
-		 */
742
-		public function get_fonts_dir() {
743
-			$upload_dir = wp_upload_dir( null, false );
744
-
745
-			return $upload_dir['basedir'] . DIRECTORY_SEPARATOR .  'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR;
746
-		}
747
-
748
-		/**
749
-		 * Get the fonts directory local url.
750
-		 *
751
-		 * @since 1.1.0
752
-		 *
753
-		 * @param string Fonts directory local url.
754
-		 */
755
-		public function get_fonts_url() {
756
-			$upload_dir = wp_upload_dir( null, false );
757
-
758
-			return $upload_dir['baseurl'] .  '/ayefonts/fa/';
759
-		}
760
-
761
-		/**
762
-		 * Check whether load locally active.
763
-		 *
764
-		 * @since 1.1.0
765
-		 *
766
-		 * @return bool True if active else false.
767
-		 */
768
-		public function has_local() {
769
-			if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
770
-				return true;
771
-			}
772
-
773
-			return false;
774
-		}
775
-
776
-		/**
777
-		 * Get the WP Filesystem access.
778
-		 *
779
-		 * @since 1.1.0
780
-		 *
781
-		 * @return object The WP Filesystem.
782
-		 */
783
-		public function get_wp_filesystem() {
784
-			if ( ! function_exists( 'get_filesystem_method' ) ) {
785
-				require_once( ABSPATH . "/wp-admin/includes/file.php" );
786
-			}
787
-
788
-			$access_type = get_filesystem_method();
789
-
790
-			if ( $access_type === 'direct' ) {
791
-				/* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */
792
-				$creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() );
793
-
794
-				/* Initialize the API */
795
-				if ( ! WP_Filesystem( $creds ) ) {
796
-					/* Any problems and we exit */
797
-					return false;
798
-				}
799
-
800
-				global $wp_filesystem;
801
-
802
-				return $wp_filesystem;
803
-				/* Do our file manipulations below */
804
-			} else if ( defined( 'FTP_USER' ) ) {
805
-				$creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() );
806
-
807
-				/* Initialize the API */
808
-				if ( ! WP_Filesystem( $creds ) ) {
809
-					/* Any problems and we exit */
810
-					return false;
811
-				}
812
-
813
-				global $wp_filesystem;
814
-
815
-				return $wp_filesystem;
816
-			} else {
817
-				/* Don't have direct write access. Prompt user with our notice */
818
-				return false;
819
-			}
820
-		}
821
-
822
-		/**
823
-		 * Download the fontawesome package file.
824
-		 *
825
-		 * @since 1.1.0
826
-		 *
827
-		 * @param mixed $version The font awesome.
828
-		 * @param array $option Fontawesome settings.
829
-		 * @return WP_ERROR|bool Error on fail and true on success.
830
-		 */
831
-		public function download_package( $version, $option = array() ) {
832
-			$filename = 'fontawesome-free-' . $version . '-web';
833
-			$url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip';
834
-
835
-			if ( ! function_exists( 'wp_handle_upload' ) ) {
836
-				require_once ABSPATH . 'wp-admin/includes/file.php';
837
-			}
838
-
839
-			$download_file = download_url( esc_url_raw( $url ) );
840
-
841
-			if ( is_wp_error( $download_file ) ) {
842
-				return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'font-awesome-settings' ) );
843
-			} else if ( empty( $download_file ) ) {
844
-				return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'font-awesome-settings' ) );
845
-			}
846
-
847
-			$response = $this->extract_package( $download_file, $filename, true );
848
-
849
-			// Update local version.
850
-			if ( is_wp_error( $response ) ) {
851
-				return $response;
852
-			} else if ( $response ) {
853
-				if ( empty( $option ) ) {
854
-					$option = get_option( 'wp-font-awesome-settings' );
855
-				}
856
-
857
-				$option['local_version'] = $version;
858
-
859
-				// Remove action to prevent looping.
860
-				remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );
861
-
862
-				update_option( 'wp-font-awesome-settings', $option );
863
-
864
-				return true;
865
-			}
866
-
867
-			return false;
868
-		}
869
-
870
-		/**
871
-		 * Extract the fontawesome package file.
872
-		 *
873
-		 * @since 1.1.0
874
-		 *
875
-		 * @param string $package The package file path.
876
-		 * @param string $dirname Package file name.
877
-		 * @param bool   $delete_package Delete temp file or not.
878
-		 * @return WP_Error|bool True on success WP_Error on fail.
879
-		 */
880
-		public function extract_package( $package, $dirname = '', $delete_package = false ) {
881
-			global $wp_filesystem;
882
-
883
-			$wp_filesystem = $this->get_wp_filesystem();
884
-
885
-			if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
886
-				return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'font-awesome-settings' ) );
887
-			} else if ( empty( $wp_filesystem ) ) {
888
-				return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'font-awesome-settings' ) );
889
-			}
890
-
891
-			$fonts_dir = $this->get_fonts_dir();
892
-			$fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR;
893
-
894
-			if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) {
895
-				$wp_filesystem->delete( $fonts_tmp_dir, true );
896
-			}
897
-
898
-			// Unzip package to working directory.
899
-			$result = unzip_file( $package, $fonts_tmp_dir );
900
-
901
-			if ( is_wp_error( $result ) ) {
902
-				$wp_filesystem->delete( $fonts_tmp_dir, true );
903
-
904
-				if ( 'incompatible_archive' === $result->get_error_code() ) {
905
-					return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'font-awesome-settings' ) );
906
-				}
907
-
908
-				return $result;
909
-			}
910
-
911
-			if ( $wp_filesystem->is_dir( $fonts_dir ) ) {
912
-				$wp_filesystem->delete( $fonts_dir, true );
913
-			}
914
-
915
-			$extract_dir = $fonts_tmp_dir;
916
-
917
-			if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) {
918
-				$extract_dir .= $dirname . DIRECTORY_SEPARATOR;
919
-			}
920
-
921
-			try {
922
-				$return = $wp_filesystem->move( $extract_dir, $fonts_dir, true );
923
-			} catch ( Exception $e ) {
924
-				$return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'font-awesome-settings' ) );
925
-			}
926
-
927
-			if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) {
928
-				$wp_filesystem->delete( $fonts_tmp_dir, true );
929
-			}
930
-
931
-			// Once extracted, delete the package if required.
932
-			if ( $delete_package ) {
933
-				unlink( $package );
934
-			}
935
-
936
-			return $return;
937
-		}
938
-	}
939
-
940
-	/**
941
-	 * Run the class if found.
942
-	 */
943
-	WP_Font_Awesome_Settings::instance();
671
+                    }
672
+                }
673
+            }
674
+        }
675
+
676
+        /**
677
+         * Handle fontawesome add settings to download fontawesome to store locally.
678
+         *
679
+         * @since 1.1.1
680
+         *
681
+         * @param string $option The option name.
682
+         * @param mixed  $value  The option value.
683
+         */
684
+        public function add_option_wp_font_awesome_settings( $option, $value ) {
685
+            // Do nothing if WordPress is being installed.
686
+            if ( wp_installing() ) {
687
+                return;
688
+            }
689
+
690
+            if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) {
691
+                $version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version();
692
+
693
+                if ( ! empty( $version ) ) {
694
+                    $response = $this->download_package( $version, $value );
695
+
696
+                    if ( is_wp_error( $response ) ) {
697
+                        add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'font-awesome-settings' ) . ' ' . $response->get_error_message(), 'error' );
698
+                    }
699
+                }
700
+            }
701
+        }
702
+
703
+        /**
704
+         * Handle fontawesome update settings to download fontawesome to store locally.
705
+         *
706
+         * @since 1.1.0
707
+         *
708
+         * @param mixed $old_value The old option value.
709
+         * @param mixed $value     The new option value.
710
+         */
711
+        public function update_option_wp_font_awesome_settings( $old_value, $new_value ) {
712
+            // Do nothing if WordPress is being installed.
713
+            if ( wp_installing() ) {
714
+                return;
715
+            }
716
+
717
+            if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) {
718
+                // Old values
719
+                $old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' );
720
+                $old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0;
721
+
722
+                // New values
723
+                $new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version();
724
+
725
+                if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
726
+                    $response = $this->download_package( $new_version, $new_value );
727
+
728
+                    if ( is_wp_error( $response ) ) {
729
+                        add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'font-awesome-settings' ) . ' ' . $response->get_error_message(), 'error' );
730
+                    }
731
+                }
732
+            }
733
+        }
734
+
735
+        /**
736
+         * Get the fonts directory local path.
737
+         *
738
+         * @since 1.1.0
739
+         *
740
+         * @param string Fonts directory local path.
741
+         */
742
+        public function get_fonts_dir() {
743
+            $upload_dir = wp_upload_dir( null, false );
744
+
745
+            return $upload_dir['basedir'] . DIRECTORY_SEPARATOR .  'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR;
746
+        }
747
+
748
+        /**
749
+         * Get the fonts directory local url.
750
+         *
751
+         * @since 1.1.0
752
+         *
753
+         * @param string Fonts directory local url.
754
+         */
755
+        public function get_fonts_url() {
756
+            $upload_dir = wp_upload_dir( null, false );
757
+
758
+            return $upload_dir['baseurl'] .  '/ayefonts/fa/';
759
+        }
760
+
761
+        /**
762
+         * Check whether load locally active.
763
+         *
764
+         * @since 1.1.0
765
+         *
766
+         * @return bool True if active else false.
767
+         */
768
+        public function has_local() {
769
+            if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
770
+                return true;
771
+            }
772
+
773
+            return false;
774
+        }
775
+
776
+        /**
777
+         * Get the WP Filesystem access.
778
+         *
779
+         * @since 1.1.0
780
+         *
781
+         * @return object The WP Filesystem.
782
+         */
783
+        public function get_wp_filesystem() {
784
+            if ( ! function_exists( 'get_filesystem_method' ) ) {
785
+                require_once( ABSPATH . "/wp-admin/includes/file.php" );
786
+            }
787
+
788
+            $access_type = get_filesystem_method();
789
+
790
+            if ( $access_type === 'direct' ) {
791
+                /* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */
792
+                $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() );
793
+
794
+                /* Initialize the API */
795
+                if ( ! WP_Filesystem( $creds ) ) {
796
+                    /* Any problems and we exit */
797
+                    return false;
798
+                }
799
+
800
+                global $wp_filesystem;
801
+
802
+                return $wp_filesystem;
803
+                /* Do our file manipulations below */
804
+            } else if ( defined( 'FTP_USER' ) ) {
805
+                $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() );
806
+
807
+                /* Initialize the API */
808
+                if ( ! WP_Filesystem( $creds ) ) {
809
+                    /* Any problems and we exit */
810
+                    return false;
811
+                }
812
+
813
+                global $wp_filesystem;
814
+
815
+                return $wp_filesystem;
816
+            } else {
817
+                /* Don't have direct write access. Prompt user with our notice */
818
+                return false;
819
+            }
820
+        }
821
+
822
+        /**
823
+         * Download the fontawesome package file.
824
+         *
825
+         * @since 1.1.0
826
+         *
827
+         * @param mixed $version The font awesome.
828
+         * @param array $option Fontawesome settings.
829
+         * @return WP_ERROR|bool Error on fail and true on success.
830
+         */
831
+        public function download_package( $version, $option = array() ) {
832
+            $filename = 'fontawesome-free-' . $version . '-web';
833
+            $url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip';
834
+
835
+            if ( ! function_exists( 'wp_handle_upload' ) ) {
836
+                require_once ABSPATH . 'wp-admin/includes/file.php';
837
+            }
838
+
839
+            $download_file = download_url( esc_url_raw( $url ) );
840
+
841
+            if ( is_wp_error( $download_file ) ) {
842
+                return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'font-awesome-settings' ) );
843
+            } else if ( empty( $download_file ) ) {
844
+                return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'font-awesome-settings' ) );
845
+            }
846
+
847
+            $response = $this->extract_package( $download_file, $filename, true );
848
+
849
+            // Update local version.
850
+            if ( is_wp_error( $response ) ) {
851
+                return $response;
852
+            } else if ( $response ) {
853
+                if ( empty( $option ) ) {
854
+                    $option = get_option( 'wp-font-awesome-settings' );
855
+                }
856
+
857
+                $option['local_version'] = $version;
858
+
859
+                // Remove action to prevent looping.
860
+                remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );
861
+
862
+                update_option( 'wp-font-awesome-settings', $option );
863
+
864
+                return true;
865
+            }
866
+
867
+            return false;
868
+        }
869
+
870
+        /**
871
+         * Extract the fontawesome package file.
872
+         *
873
+         * @since 1.1.0
874
+         *
875
+         * @param string $package The package file path.
876
+         * @param string $dirname Package file name.
877
+         * @param bool   $delete_package Delete temp file or not.
878
+         * @return WP_Error|bool True on success WP_Error on fail.
879
+         */
880
+        public function extract_package( $package, $dirname = '', $delete_package = false ) {
881
+            global $wp_filesystem;
882
+
883
+            $wp_filesystem = $this->get_wp_filesystem();
884
+
885
+            if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
886
+                return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'font-awesome-settings' ) );
887
+            } else if ( empty( $wp_filesystem ) ) {
888
+                return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'font-awesome-settings' ) );
889
+            }
890
+
891
+            $fonts_dir = $this->get_fonts_dir();
892
+            $fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR;
893
+
894
+            if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) {
895
+                $wp_filesystem->delete( $fonts_tmp_dir, true );
896
+            }
897
+
898
+            // Unzip package to working directory.
899
+            $result = unzip_file( $package, $fonts_tmp_dir );
900
+
901
+            if ( is_wp_error( $result ) ) {
902
+                $wp_filesystem->delete( $fonts_tmp_dir, true );
903
+
904
+                if ( 'incompatible_archive' === $result->get_error_code() ) {
905
+                    return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'font-awesome-settings' ) );
906
+                }
907
+
908
+                return $result;
909
+            }
910
+
911
+            if ( $wp_filesystem->is_dir( $fonts_dir ) ) {
912
+                $wp_filesystem->delete( $fonts_dir, true );
913
+            }
914
+
915
+            $extract_dir = $fonts_tmp_dir;
916
+
917
+            if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) {
918
+                $extract_dir .= $dirname . DIRECTORY_SEPARATOR;
919
+            }
920
+
921
+            try {
922
+                $return = $wp_filesystem->move( $extract_dir, $fonts_dir, true );
923
+            } catch ( Exception $e ) {
924
+                $return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'font-awesome-settings' ) );
925
+            }
926
+
927
+            if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) {
928
+                $wp_filesystem->delete( $fonts_tmp_dir, true );
929
+            }
930
+
931
+            // Once extracted, delete the package if required.
932
+            if ( $delete_package ) {
933
+                unlink( $package );
934
+            }
935
+
936
+            return $return;
937
+        }
938
+    }
939
+
940
+    /**
941
+     * Run the class if found.
942
+     */
943
+    WP_Font_Awesome_Settings::instance();
944 944
 }
Please login to merge, or discard this patch.
ayecode/wp-ayecode-ui/includes/components/class-aui-component-input.php 1 patch
Indentation   +1260 added lines, -1260 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,1283 +11,1283 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class AUI_Component_Input {
13 13
 
14
-	/**
15
-	 * Build the component.
16
-	 *
17
-	 * @param array $args
18
-	 *
19
-	 * @return string The rendered component.
20
-	 */
21
-	public static function input( $args = array() ) {
22
-		global $aui_bs5;
23
-
24
-		$defaults = array(
25
-			'type'                     => 'text',
26
-			'name'                     => '',
27
-			'class'                    => '',
28
-			'wrap_class'               => '',
29
-			'id'                       => '',
30
-			'placeholder'              => '',
31
-			'title'                    => '',
32
-			'value'                    => '',
33
-			'required'                 => false,
34
-			'size'                     => '', // sm, lg, small, large
35
-			'clear_icon'               => '', // true will show a clear icon, can't be used with input_group_right
36
-			'with_hidden'              => false, // Append hidden field for single checkbox.
37
-			'label'                    => '',
38
-			'label_after'              => false,
39
-			'label_class'              => '',
40
-			'label_col'                => '2',
41
-			'label_type'               => '', // top, horizontal, empty = hidden
42
-			'label_force_left'         => false, // used to force checkbox label left when using horizontal
43
-			// sets the label type, default: hidden. Options: hidden, top, horizontal, floating
44
-			'help_text'                => '',
45
-			'validation_text'          => '',
46
-			'validation_pattern'       => '',
47
-			'no_wrap'                  => false,
48
-			'input_group_right'        => '',
49
-			'input_group_left'         => '',
50
-			'input_group_right_inside' => false,
51
-			// forces the input group inside the input
52
-			'input_group_left_inside'  => false,
53
-			// forces the input group inside the input
54
-			'form_group_class'         => '',
55
-			'step'                     => '',
56
-			'switch'                   => false,
57
-			// to show checkbox as a switch
58
-			'checked'                  => false,
59
-			// set a checkbox or radio as selected
60
-			'password_toggle'          => true,
61
-			// toggle view/hide password
62
-			'element_require'          => '',
63
-			// [%element_id%] == "1"
64
-			'extra_attributes'         => array(),
65
-			// an array of extra attributes
66
-			'wrap_attributes'          => array()
67
-		);
68
-
69
-		/**
70
-		 * Parse incoming $args into an array and merge it with $defaults
71
-		 */
72
-		$args   = wp_parse_args( $args, $defaults );
73
-		$output = '';
74
-		if ( ! empty( $args['type'] ) ) {
75
-			// hidden label option needs to be empty
76
-			$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
77
-
78
-			$type = sanitize_html_class( $args['type'] );
79
-
80
-			$help_text   = '';
81
-			$label       = '';
82
-			$label_after = $args['label_after'];
83
-			$label_args  = array(
84
-				'title'      => $args['label'],
85
-				'for'        => $args['id'],
86
-				'class'      => $args['label_class'] . " ",
87
-				'label_type' => $args['label_type'],
88
-				'label_col'  => $args['label_col']
89
-			);
90
-
91
-			// floating labels need label after
92
-			if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) {
93
-				$label_after         = true;
94
-				$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
95
-			}
96
-
97
-			// size
98
-			$size = '';
99
-			if ( $args['size'] == 'lg' || $args['size'] == 'large' ) {
100
-				$size = 'lg';
101
-				$args['class'] .= ' form-control-lg';
102
-			}elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) {
103
-				$size = 'sm';
104
-				$args['class'] .= ' form-control-sm';
105
-			}
106
-
107
-			// clear function
108
-			$clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');';
109
-
110
-			// Some special sauce for files
111
-			if ( $type == 'file' ) {
112
-				$label_after = true; // if type file we need the label after
113
-				$args['class'] .= ' custom-file-input ';
114
-			} elseif ( $type == 'checkbox' ) {
115
-				$label_after = true; // if type file we need the label after
116
-				$args['class'] .= $aui_bs5 ? ' form-check-input' : ' custom-control-input ';
117
-			} elseif ( $type == 'datepicker' || $type == 'timepicker' ) {
118
-				$orig_type = $type;
119
-				$type = 'text';
120
-				$args['class'] .= ' bg-initial '; // @todo not sure why we have this?
121
-				$clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');";
122
-
123
-				$args['extra_attributes']['data-aui-init'] = 'flatpickr';
124
-
125
-				// Disable native datetime inputs.
126
-				if ( ( $orig_type == 'timepicker' || ! empty( $args['extra_attributes']['data-enable-time'] ) ) && ! isset( $args['extra_attributes']['data-disable-mobile'] ) ) {
127
-					$args['extra_attributes']['data-disable-mobile'] = 'true';
128
-				}
129
-
130
-				// set a way to clear field if empty
131
-				if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) {
132
-					$args['input_group_right_inside'] = true;
133
-					$args['clear_icon'] = true;
134
-				}
135
-
136
-				// enqueue the script
137
-				$aui_settings = AyeCode_UI_Settings::instance();
138
-				$aui_settings->enqueue_flatpickr();
139
-			} elseif ( $type == 'iconpicker' ) {
140
-				$type = 'text';
141
-				//$args['class'] .= ' aui-flatpickr bg-initial ';
14
+    /**
15
+     * Build the component.
16
+     *
17
+     * @param array $args
18
+     *
19
+     * @return string The rendered component.
20
+     */
21
+    public static function input( $args = array() ) {
22
+        global $aui_bs5;
23
+
24
+        $defaults = array(
25
+            'type'                     => 'text',
26
+            'name'                     => '',
27
+            'class'                    => '',
28
+            'wrap_class'               => '',
29
+            'id'                       => '',
30
+            'placeholder'              => '',
31
+            'title'                    => '',
32
+            'value'                    => '',
33
+            'required'                 => false,
34
+            'size'                     => '', // sm, lg, small, large
35
+            'clear_icon'               => '', // true will show a clear icon, can't be used with input_group_right
36
+            'with_hidden'              => false, // Append hidden field for single checkbox.
37
+            'label'                    => '',
38
+            'label_after'              => false,
39
+            'label_class'              => '',
40
+            'label_col'                => '2',
41
+            'label_type'               => '', // top, horizontal, empty = hidden
42
+            'label_force_left'         => false, // used to force checkbox label left when using horizontal
43
+            // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
44
+            'help_text'                => '',
45
+            'validation_text'          => '',
46
+            'validation_pattern'       => '',
47
+            'no_wrap'                  => false,
48
+            'input_group_right'        => '',
49
+            'input_group_left'         => '',
50
+            'input_group_right_inside' => false,
51
+            // forces the input group inside the input
52
+            'input_group_left_inside'  => false,
53
+            // forces the input group inside the input
54
+            'form_group_class'         => '',
55
+            'step'                     => '',
56
+            'switch'                   => false,
57
+            // to show checkbox as a switch
58
+            'checked'                  => false,
59
+            // set a checkbox or radio as selected
60
+            'password_toggle'          => true,
61
+            // toggle view/hide password
62
+            'element_require'          => '',
63
+            // [%element_id%] == "1"
64
+            'extra_attributes'         => array(),
65
+            // an array of extra attributes
66
+            'wrap_attributes'          => array()
67
+        );
68
+
69
+        /**
70
+         * Parse incoming $args into an array and merge it with $defaults
71
+         */
72
+        $args   = wp_parse_args( $args, $defaults );
73
+        $output = '';
74
+        if ( ! empty( $args['type'] ) ) {
75
+            // hidden label option needs to be empty
76
+            $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
77
+
78
+            $type = sanitize_html_class( $args['type'] );
79
+
80
+            $help_text   = '';
81
+            $label       = '';
82
+            $label_after = $args['label_after'];
83
+            $label_args  = array(
84
+                'title'      => $args['label'],
85
+                'for'        => $args['id'],
86
+                'class'      => $args['label_class'] . " ",
87
+                'label_type' => $args['label_type'],
88
+                'label_col'  => $args['label_col']
89
+            );
90
+
91
+            // floating labels need label after
92
+            if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) {
93
+                $label_after         = true;
94
+                $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
95
+            }
96
+
97
+            // size
98
+            $size = '';
99
+            if ( $args['size'] == 'lg' || $args['size'] == 'large' ) {
100
+                $size = 'lg';
101
+                $args['class'] .= ' form-control-lg';
102
+            }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) {
103
+                $size = 'sm';
104
+                $args['class'] .= ' form-control-sm';
105
+            }
106
+
107
+            // clear function
108
+            $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');';
109
+
110
+            // Some special sauce for files
111
+            if ( $type == 'file' ) {
112
+                $label_after = true; // if type file we need the label after
113
+                $args['class'] .= ' custom-file-input ';
114
+            } elseif ( $type == 'checkbox' ) {
115
+                $label_after = true; // if type file we need the label after
116
+                $args['class'] .= $aui_bs5 ? ' form-check-input' : ' custom-control-input ';
117
+            } elseif ( $type == 'datepicker' || $type == 'timepicker' ) {
118
+                $orig_type = $type;
119
+                $type = 'text';
120
+                $args['class'] .= ' bg-initial '; // @todo not sure why we have this?
121
+                $clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');";
122
+
123
+                $args['extra_attributes']['data-aui-init'] = 'flatpickr';
124
+
125
+                // Disable native datetime inputs.
126
+                if ( ( $orig_type == 'timepicker' || ! empty( $args['extra_attributes']['data-enable-time'] ) ) && ! isset( $args['extra_attributes']['data-disable-mobile'] ) ) {
127
+                    $args['extra_attributes']['data-disable-mobile'] = 'true';
128
+                }
129
+
130
+                // set a way to clear field if empty
131
+                if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) {
132
+                    $args['input_group_right_inside'] = true;
133
+                    $args['clear_icon'] = true;
134
+                }
135
+
136
+                // enqueue the script
137
+                $aui_settings = AyeCode_UI_Settings::instance();
138
+                $aui_settings->enqueue_flatpickr();
139
+            } elseif ( $type == 'iconpicker' ) {
140
+                $type = 'text';
141
+                //$args['class'] .= ' aui-flatpickr bg-initial ';
142 142
 //				$args['class'] .= ' bg-initial ';
143 143
 
144
-				$args['extra_attributes']['data-aui-init'] = 'iconpicker';
145
-				$args['extra_attributes']['data-placement'] = 'bottomRight';
144
+                $args['extra_attributes']['data-aui-init'] = 'iconpicker';
145
+                $args['extra_attributes']['data-placement'] = 'bottomRight';
146 146
 
147
-				$args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>';
147
+                $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>';
148 148
 //				$args['input_group_right_inside'] = true;
149
-				// enqueue the script
150
-				$aui_settings = AyeCode_UI_Settings::instance();
151
-				$aui_settings->enqueue_iconpicker();
152
-			}
153
-
154
-			if ( $type == 'checkbox' && ( ( ! empty( $args['name'] ) && strpos( $args['name'], '[' ) === false ) || ! empty( $args['with_hidden'] ) ) ) {
155
-				$output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />';
156
-			}
157
-
158
-			// allow clear icon
159
-			if ( $args['input_group_right'] === '' && $args['clear_icon'] ) {
160
-				$font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' );
161
-				$args['input_group_right_inside'] = true;
162
-				$align_class = $aui_bs5 ? ' h-100 py-0' : '';
163
-				$args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none ' . $align_class . '" onclick="' . $clear_function . '"><span style="font-size: ' . $font_size . 'rem" aria-hidden="true" class="' . ( $aui_bs5 ? 'btn-close' : 'close' ) . '">' . ( $aui_bs5 ? '' : '&times;' ) . '</span></span>';
164
-			}
165
-
166
-			// open/type
167
-			$output .= '<input type="' . $type . '" ';
168
-
169
-			// name
170
-			if ( ! empty( $args['name'] ) ) {
171
-				$output .= ' name="' . esc_attr( $args['name'] ) . '" ';
172
-			}
173
-
174
-			// id
175
-			if ( ! empty( $args['id'] ) ) {
176
-				$output .= ' id="' . sanitize_html_class( $args['id'] ) . '" ';
177
-			}
178
-
179
-			// placeholder
180
-			if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) {
181
-				$output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" ';
182
-			}
183
-
184
-			// title
185
-			if ( ! empty( $args['title'] ) ) {
186
-				$output .= ' title="' . esc_attr( $args['title'] ) . '" ';
187
-			}
188
-
189
-			// value
190
-			if ( ! empty( $args['value'] ) ) {
191
-				$output .= AUI_Component_Helper::value( $args['value'] );
192
-			}
193
-
194
-			// checked, for radio and checkboxes
195
-			if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) {
196
-				$output .= ' checked ';
197
-			}
198
-
199
-			// validation text
200
-			if ( ! empty( $args['validation_text'] ) ) {
201
-				$output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" ';
202
-				$output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
203
-			}
204
-
205
-			// validation_pattern
206
-			if ( ! empty( $args['validation_pattern'] ) ) {
207
-				$output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" ';
208
-			}
209
-
210
-			// step (for numbers)
211
-			if ( ! empty( $args['step'] ) ) {
212
-				$output .= ' step="' . $args['step'] . '" ';
213
-			}
214
-
215
-			// required
216
-			if ( ! empty( $args['required'] ) ) {
217
-				$output .= ' required ';
218
-			}
219
-
220
-			// class
221
-			$class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
222
-			$output .= $aui_bs5 &&  $type == 'checkbox' ? ' class="' . $class . '" ' : ' class="form-control ' . $class . '" ';
223
-
224
-			// data-attributes
225
-			$output .= AUI_Component_Helper::data_attributes( $args );
226
-
227
-			// extra attributes
228
-			if ( ! empty( $args['extra_attributes'] ) ) {
229
-				$output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
230
-			}
231
-
232
-			// close
233
-			$output .= ' >';
234
-
235
-			// help text
236
-			if ( ! empty( $args['help_text'] ) ) {
237
-				$help_text = AUI_Component_Helper::help_text( $args['help_text'] );
238
-			}
239
-
240
-			// label
241
-			if ( ! empty( $args['label'] ) ) {
242
-				$label_base_class = '';
243
-				if ( $type == 'file' ) {
244
-					$label_base_class = ' custom-file-label';
245
-				} elseif ( $type == 'checkbox' ) {
246
-					if ( ! empty( $args['label_force_left'] ) ) {
247
-						$label_args['title'] = wp_kses_post( $args['help_text'] );
248
-						$help_text = '';
249
-						//$label_args['class'] .= ' d-inline ';
250
-						$args['wrap_class'] .= ' align-items-center ';
251
-					}else{
252
-
253
-					}
254
-
255
-					$label_base_class = $aui_bs5 ? ' form-check-label' : ' custom-control-label';
256
-				}
257
-				$label_args['class'] .= $label_base_class;
258
-				$temp_label_args = $label_args;
259
-				if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";}
260
-				$label = self::label( $temp_label_args, $type );
261
-			}
262
-
263
-
264
-
265
-
266
-			// set help text in the correct position
267
-			if ( $label_after ) {
268
-				$output .= $label . $help_text;
269
-			}
270
-
271
-			// some input types need a separate wrap
272
-			if ( $type == 'file' ) {
273
-				$output = self::wrap( array(
274
-					'content' => $output,
275
-					'class'   => $aui_bs5 ? 'mb-3 custom-file' : 'form-group custom-file'
276
-				) );
277
-			} elseif ( $type == 'checkbox' ) {
278
-
279
-				$label_args['title'] = $args['label'];
280
-				$label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' );
281
-				$label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>';
282
-				$switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : '';
283
-				if ( $aui_bs5 ) {
284
-					$wrap_class = $args['switch'] ? 'form-check form-switch' . $switch_size_class : 'form-check';
285
-				}else{
286
-					$wrap_class = $args['switch'] ? 'custom-switch' . $switch_size_class :  'custom-checkbox' ;
287
-				}
288
-				if ( ! empty( $args['label_force_left'] ) ) {
289
-					$wrap_class .= $aui_bs5 ? '' : ' d-flex align-content-center';
290
-					$label = str_replace(array("form-check-label","custom-control-label"),"", self::label( $label_args, 'cb' ) );
291
-				}
292
-				$output     = self::wrap( array(
293
-					'content' => $output,
294
-					'class'   => $aui_bs5 ? $wrap_class : 'custom-control ' . $wrap_class
295
-				) );
296
-
297
-				if ( $args['label_type'] == 'horizontal' ) {
298
-					$input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
299
-					$output    = $label . '<div class="' . $input_col . '">' . $output . '</div>';
300
-				}
301
-			} elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) {
302
-
303
-
304
-				// allow password field to toggle view
305
-				$args['input_group_right'] = '<span class="input-group-text c-pointer px-3" 
149
+                // enqueue the script
150
+                $aui_settings = AyeCode_UI_Settings::instance();
151
+                $aui_settings->enqueue_iconpicker();
152
+            }
153
+
154
+            if ( $type == 'checkbox' && ( ( ! empty( $args['name'] ) && strpos( $args['name'], '[' ) === false ) || ! empty( $args['with_hidden'] ) ) ) {
155
+                $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />';
156
+            }
157
+
158
+            // allow clear icon
159
+            if ( $args['input_group_right'] === '' && $args['clear_icon'] ) {
160
+                $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' );
161
+                $args['input_group_right_inside'] = true;
162
+                $align_class = $aui_bs5 ? ' h-100 py-0' : '';
163
+                $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none ' . $align_class . '" onclick="' . $clear_function . '"><span style="font-size: ' . $font_size . 'rem" aria-hidden="true" class="' . ( $aui_bs5 ? 'btn-close' : 'close' ) . '">' . ( $aui_bs5 ? '' : '&times;' ) . '</span></span>';
164
+            }
165
+
166
+            // open/type
167
+            $output .= '<input type="' . $type . '" ';
168
+
169
+            // name
170
+            if ( ! empty( $args['name'] ) ) {
171
+                $output .= ' name="' . esc_attr( $args['name'] ) . '" ';
172
+            }
173
+
174
+            // id
175
+            if ( ! empty( $args['id'] ) ) {
176
+                $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" ';
177
+            }
178
+
179
+            // placeholder
180
+            if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) {
181
+                $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" ';
182
+            }
183
+
184
+            // title
185
+            if ( ! empty( $args['title'] ) ) {
186
+                $output .= ' title="' . esc_attr( $args['title'] ) . '" ';
187
+            }
188
+
189
+            // value
190
+            if ( ! empty( $args['value'] ) ) {
191
+                $output .= AUI_Component_Helper::value( $args['value'] );
192
+            }
193
+
194
+            // checked, for radio and checkboxes
195
+            if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) {
196
+                $output .= ' checked ';
197
+            }
198
+
199
+            // validation text
200
+            if ( ! empty( $args['validation_text'] ) ) {
201
+                $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" ';
202
+                $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
203
+            }
204
+
205
+            // validation_pattern
206
+            if ( ! empty( $args['validation_pattern'] ) ) {
207
+                $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" ';
208
+            }
209
+
210
+            // step (for numbers)
211
+            if ( ! empty( $args['step'] ) ) {
212
+                $output .= ' step="' . $args['step'] . '" ';
213
+            }
214
+
215
+            // required
216
+            if ( ! empty( $args['required'] ) ) {
217
+                $output .= ' required ';
218
+            }
219
+
220
+            // class
221
+            $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
222
+            $output .= $aui_bs5 &&  $type == 'checkbox' ? ' class="' . $class . '" ' : ' class="form-control ' . $class . '" ';
223
+
224
+            // data-attributes
225
+            $output .= AUI_Component_Helper::data_attributes( $args );
226
+
227
+            // extra attributes
228
+            if ( ! empty( $args['extra_attributes'] ) ) {
229
+                $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
230
+            }
231
+
232
+            // close
233
+            $output .= ' >';
234
+
235
+            // help text
236
+            if ( ! empty( $args['help_text'] ) ) {
237
+                $help_text = AUI_Component_Helper::help_text( $args['help_text'] );
238
+            }
239
+
240
+            // label
241
+            if ( ! empty( $args['label'] ) ) {
242
+                $label_base_class = '';
243
+                if ( $type == 'file' ) {
244
+                    $label_base_class = ' custom-file-label';
245
+                } elseif ( $type == 'checkbox' ) {
246
+                    if ( ! empty( $args['label_force_left'] ) ) {
247
+                        $label_args['title'] = wp_kses_post( $args['help_text'] );
248
+                        $help_text = '';
249
+                        //$label_args['class'] .= ' d-inline ';
250
+                        $args['wrap_class'] .= ' align-items-center ';
251
+                    }else{
252
+
253
+                    }
254
+
255
+                    $label_base_class = $aui_bs5 ? ' form-check-label' : ' custom-control-label';
256
+                }
257
+                $label_args['class'] .= $label_base_class;
258
+                $temp_label_args = $label_args;
259
+                if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";}
260
+                $label = self::label( $temp_label_args, $type );
261
+            }
262
+
263
+
264
+
265
+
266
+            // set help text in the correct position
267
+            if ( $label_after ) {
268
+                $output .= $label . $help_text;
269
+            }
270
+
271
+            // some input types need a separate wrap
272
+            if ( $type == 'file' ) {
273
+                $output = self::wrap( array(
274
+                    'content' => $output,
275
+                    'class'   => $aui_bs5 ? 'mb-3 custom-file' : 'form-group custom-file'
276
+                ) );
277
+            } elseif ( $type == 'checkbox' ) {
278
+
279
+                $label_args['title'] = $args['label'];
280
+                $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' );
281
+                $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>';
282
+                $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : '';
283
+                if ( $aui_bs5 ) {
284
+                    $wrap_class = $args['switch'] ? 'form-check form-switch' . $switch_size_class : 'form-check';
285
+                }else{
286
+                    $wrap_class = $args['switch'] ? 'custom-switch' . $switch_size_class :  'custom-checkbox' ;
287
+                }
288
+                if ( ! empty( $args['label_force_left'] ) ) {
289
+                    $wrap_class .= $aui_bs5 ? '' : ' d-flex align-content-center';
290
+                    $label = str_replace(array("form-check-label","custom-control-label"),"", self::label( $label_args, 'cb' ) );
291
+                }
292
+                $output     = self::wrap( array(
293
+                    'content' => $output,
294
+                    'class'   => $aui_bs5 ? $wrap_class : 'custom-control ' . $wrap_class
295
+                ) );
296
+
297
+                if ( $args['label_type'] == 'horizontal' ) {
298
+                    $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
299
+                    $output    = $label . '<div class="' . $input_col . '">' . $output . '</div>';
300
+                }
301
+            } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) {
302
+
303
+
304
+                // allow password field to toggle view
305
+                $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" 
306 306
 onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\');
307 307
 var $eli = jQuery(this).parent().parent().find(\'input\');
308 308
 if($el.hasClass(\'fa-eye\'))
309 309
 {$eli.attr(\'type\',\'text\');}
310 310
 else{$eli.attr(\'type\',\'password\');}"
311 311
 ><i class="far fa-fw fa-eye-slash"></i></span>';
312
-			}
313
-
314
-			// input group wraps
315
-			if ( $args['input_group_left'] || $args['input_group_right'] ) {
316
-				$w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
317
-				$group_size = $size == 'lg' ? ' input-group-lg' : '';
318
-				$group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size;
319
-
320
-				if ( $args['input_group_left'] ) {
321
-					$output = self::wrap( array(
322
-						'content'                 => $output,
323
-						'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size,
324
-						'input_group_left'        => $args['input_group_left'],
325
-						'input_group_left_inside' => $args['input_group_left_inside']
326
-					) );
327
-				}
328
-				if ( $args['input_group_right'] ) {
329
-					$output = self::wrap( array(
330
-						'content'                  => $output,
331
-						'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size,
332
-						'input_group_right'        => $args['input_group_right'],
333
-						'input_group_right_inside' => $args['input_group_right_inside']
334
-					) );
335
-				}
336
-
337
-			}
338
-
339
-			if ( ! $label_after ) {
340
-				$output .= $help_text;
341
-			}
342
-
343
-
344
-			if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) {
345
-				$output = self::wrap( array(
346
-					'content' => $output,
347
-					'class'   => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' )
348
-				) );
349
-			}
350
-
351
-			if ( ! $label_after ) {
352
-				$output = $label . $output;
353
-			}
354
-
355
-			// wrap
356
-			if ( ! $args['no_wrap'] ) {
357
-				if ( ! empty( $args['form_group_class'] ) ) {
358
-					$fg_class = esc_attr( $args['form_group_class'] );
359
-				}else{
360
-					$fg_class = $aui_bs5 ? 'mb-3' : 'form-group';
361
-				}
362
-				$form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : $fg_class;
363
-				$wrap_class       = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class;
364
-				$wrap_class       = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
365
-				$output           = self::wrap( array(
366
-					'content'         => $output,
367
-					'class'           => $wrap_class,
368
-					'element_require' => $args['element_require'],
369
-					'argument_id'     => $args['id'],
370
-					'wrap_attributes' => $args['wrap_attributes'],
371
-				) );
372
-			}
373
-		}
374
-
375
-		return $output;
376
-	}
377
-
378
-	public static function label( $args = array(), $type = '' ) {
379
-		global $aui_bs5;
380
-		//<label for="exampleInputEmail1">Email address</label>
381
-		$defaults = array(
382
-			'title'      => 'div',
383
-			'for'        => '',
384
-			'class'      => '',
385
-			'label_type' => '', // empty = hidden, top, horizontal
386
-			'label_col'  => '',
387
-		);
388
-
389
-		/**
390
-		 * Parse incoming $args into an array and merge it with $defaults
391
-		 */
392
-		$args   = wp_parse_args( $args, $defaults );
393
-		$output = '';
394
-
395
-		if ( $args['title'] ) {
396
-
397
-			// maybe hide labels //@todo set a global option for visibility class
398
-			if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) {
399
-				$class = $args['class'];
400
-			} else {
401
-				$class = 'sr-only ' . $args['class'];
402
-			}
403
-
404
-			// maybe horizontal
405
-			if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) {
406
-				$class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label '.$type;
407
-			}
408
-
409
-			if( $aui_bs5 ){ $class .= ' form-label'; }
410
-
411
-			// open
412
-			$output .= '<label ';
413
-
414
-			// for
415
-			if ( ! empty( $args['for'] ) ) {
416
-				$output .= ' for="' . esc_attr( $args['for'] ) . '" ';
417
-			}
418
-
419
-			// class
420
-			$class = $class ? AUI_Component_Helper::esc_classes( $class ) : '';
421
-			$output .= ' class="' . $class . '" ';
422
-
423
-			// close
424
-			$output .= '>';
425
-
426
-
427
-			// title, don't escape fully as can contain html
428
-			if ( ! empty( $args['title'] ) ) {
429
-				$output .= wp_kses_post( $args['title'] );
430
-			}
431
-
432
-			// close wrap
433
-			$output .= '</label>';
434
-
435
-
436
-		}
437
-
438
-
439
-		return $output;
440
-	}
441
-
442
-	/**
443
-	 * Wrap some content in a HTML wrapper.
444
-	 *
445
-	 * @param array $args
446
-	 *
447
-	 * @return string
448
-	 */
449
-	public static function wrap( $args = array() ) {
450
-		global $aui_bs5;
451
-		$defaults = array(
452
-			'type'                     => 'div',
453
-			'class'                    => $aui_bs5 ? 'mb-3' : 'form-group',
454
-			'content'                  => '',
455
-			'input_group_left'         => '',
456
-			'input_group_right'        => '',
457
-			'input_group_left_inside'  => false,
458
-			'input_group_right_inside' => false,
459
-			'element_require'          => '',
460
-			'argument_id'              => '',
461
-			'wrap_attributes'          => array()
462
-		);
463
-
464
-		/**
465
-		 * Parse incoming $args into an array and merge it with $defaults
466
-		 */
467
-		$args   = wp_parse_args( $args, $defaults );
468
-		$output = '';
469
-		if ( $args['type'] ) {
470
-
471
-			// open
472
-			$output .= '<' . sanitize_html_class( $args['type'] );
473
-
474
-			// element require
475
-			if ( ! empty( $args['element_require'] ) ) {
476
-				$output .= AUI_Component_Helper::element_require( $args['element_require'] );
477
-				$args['class'] .= " aui-conditional-field";
478
-			}
479
-
480
-			// argument_id
481
-			if ( ! empty( $args['argument_id'] ) ) {
482
-				$output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"';
483
-			}
484
-
485
-			// class
486
-			$class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
487
-			$output .= ' class="' . $class . '" ';
488
-
489
-			// Attributes
490
-			if ( ! empty( $args['wrap_attributes'] ) ) {
491
-				$output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] );
492
-			}
493
-
494
-			// close wrap
495
-			$output .= ' >';
496
-
497
-
498
-			// Input group left
499
-			if ( ! empty( $args['input_group_left'] ) ) {
500
-				$position_class   = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : '';
501
-				$input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>';
502
-				$output .= $aui_bs5 ? $input_group_left : '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>';
312
+            }
313
+
314
+            // input group wraps
315
+            if ( $args['input_group_left'] || $args['input_group_right'] ) {
316
+                $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
317
+                $group_size = $size == 'lg' ? ' input-group-lg' : '';
318
+                $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size;
319
+
320
+                if ( $args['input_group_left'] ) {
321
+                    $output = self::wrap( array(
322
+                        'content'                 => $output,
323
+                        'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size,
324
+                        'input_group_left'        => $args['input_group_left'],
325
+                        'input_group_left_inside' => $args['input_group_left_inside']
326
+                    ) );
327
+                }
328
+                if ( $args['input_group_right'] ) {
329
+                    $output = self::wrap( array(
330
+                        'content'                  => $output,
331
+                        'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size,
332
+                        'input_group_right'        => $args['input_group_right'],
333
+                        'input_group_right_inside' => $args['input_group_right_inside']
334
+                    ) );
335
+                }
336
+
337
+            }
338
+
339
+            if ( ! $label_after ) {
340
+                $output .= $help_text;
341
+            }
342
+
343
+
344
+            if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) {
345
+                $output = self::wrap( array(
346
+                    'content' => $output,
347
+                    'class'   => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' )
348
+                ) );
349
+            }
350
+
351
+            if ( ! $label_after ) {
352
+                $output = $label . $output;
353
+            }
354
+
355
+            // wrap
356
+            if ( ! $args['no_wrap'] ) {
357
+                if ( ! empty( $args['form_group_class'] ) ) {
358
+                    $fg_class = esc_attr( $args['form_group_class'] );
359
+                }else{
360
+                    $fg_class = $aui_bs5 ? 'mb-3' : 'form-group';
361
+                }
362
+                $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : $fg_class;
363
+                $wrap_class       = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class;
364
+                $wrap_class       = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
365
+                $output           = self::wrap( array(
366
+                    'content'         => $output,
367
+                    'class'           => $wrap_class,
368
+                    'element_require' => $args['element_require'],
369
+                    'argument_id'     => $args['id'],
370
+                    'wrap_attributes' => $args['wrap_attributes'],
371
+                ) );
372
+            }
373
+        }
374
+
375
+        return $output;
376
+    }
377
+
378
+    public static function label( $args = array(), $type = '' ) {
379
+        global $aui_bs5;
380
+        //<label for="exampleInputEmail1">Email address</label>
381
+        $defaults = array(
382
+            'title'      => 'div',
383
+            'for'        => '',
384
+            'class'      => '',
385
+            'label_type' => '', // empty = hidden, top, horizontal
386
+            'label_col'  => '',
387
+        );
388
+
389
+        /**
390
+         * Parse incoming $args into an array and merge it with $defaults
391
+         */
392
+        $args   = wp_parse_args( $args, $defaults );
393
+        $output = '';
394
+
395
+        if ( $args['title'] ) {
396
+
397
+            // maybe hide labels //@todo set a global option for visibility class
398
+            if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) {
399
+                $class = $args['class'];
400
+            } else {
401
+                $class = 'sr-only ' . $args['class'];
402
+            }
403
+
404
+            // maybe horizontal
405
+            if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) {
406
+                $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label '.$type;
407
+            }
408
+
409
+            if( $aui_bs5 ){ $class .= ' form-label'; }
410
+
411
+            // open
412
+            $output .= '<label ';
413
+
414
+            // for
415
+            if ( ! empty( $args['for'] ) ) {
416
+                $output .= ' for="' . esc_attr( $args['for'] ) . '" ';
417
+            }
418
+
419
+            // class
420
+            $class = $class ? AUI_Component_Helper::esc_classes( $class ) : '';
421
+            $output .= ' class="' . $class . '" ';
422
+
423
+            // close
424
+            $output .= '>';
425
+
426
+
427
+            // title, don't escape fully as can contain html
428
+            if ( ! empty( $args['title'] ) ) {
429
+                $output .= wp_kses_post( $args['title'] );
430
+            }
431
+
432
+            // close wrap
433
+            $output .= '</label>';
434
+
435
+
436
+        }
437
+
438
+
439
+        return $output;
440
+    }
441
+
442
+    /**
443
+     * Wrap some content in a HTML wrapper.
444
+     *
445
+     * @param array $args
446
+     *
447
+     * @return string
448
+     */
449
+    public static function wrap( $args = array() ) {
450
+        global $aui_bs5;
451
+        $defaults = array(
452
+            'type'                     => 'div',
453
+            'class'                    => $aui_bs5 ? 'mb-3' : 'form-group',
454
+            'content'                  => '',
455
+            'input_group_left'         => '',
456
+            'input_group_right'        => '',
457
+            'input_group_left_inside'  => false,
458
+            'input_group_right_inside' => false,
459
+            'element_require'          => '',
460
+            'argument_id'              => '',
461
+            'wrap_attributes'          => array()
462
+        );
463
+
464
+        /**
465
+         * Parse incoming $args into an array and merge it with $defaults
466
+         */
467
+        $args   = wp_parse_args( $args, $defaults );
468
+        $output = '';
469
+        if ( $args['type'] ) {
470
+
471
+            // open
472
+            $output .= '<' . sanitize_html_class( $args['type'] );
473
+
474
+            // element require
475
+            if ( ! empty( $args['element_require'] ) ) {
476
+                $output .= AUI_Component_Helper::element_require( $args['element_require'] );
477
+                $args['class'] .= " aui-conditional-field";
478
+            }
479
+
480
+            // argument_id
481
+            if ( ! empty( $args['argument_id'] ) ) {
482
+                $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"';
483
+            }
484
+
485
+            // class
486
+            $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : '';
487
+            $output .= ' class="' . $class . '" ';
488
+
489
+            // Attributes
490
+            if ( ! empty( $args['wrap_attributes'] ) ) {
491
+                $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] );
492
+            }
493
+
494
+            // close wrap
495
+            $output .= ' >';
496
+
497
+
498
+            // Input group left
499
+            if ( ! empty( $args['input_group_left'] ) ) {
500
+                $position_class   = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : '';
501
+                $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>';
502
+                $output .= $aui_bs5 ? $input_group_left : '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>';
503 503
 //				$output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>';
504
-			}
504
+            }
505 505
 
506
-			// content
507
-			$output .= $args['content'];
506
+            // content
507
+            $output .= $args['content'];
508 508
 
509
-			// Input group right
510
-			if ( ! empty( $args['input_group_right'] ) ) {
511
-				$position_class    = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : '';
512
-				$input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>';
513
-				$output .= $aui_bs5 ? str_replace( 'input-group-text','input-group-text top-0 end-0', $input_group_right ) : '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>';
509
+            // Input group right
510
+            if ( ! empty( $args['input_group_right'] ) ) {
511
+                $position_class    = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : '';
512
+                $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>';
513
+                $output .= $aui_bs5 ? str_replace( 'input-group-text','input-group-text top-0 end-0', $input_group_right ) : '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>';
514 514
 //				$output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>';
515
-			}
516
-
517
-
518
-			// close wrap
519
-			$output .= '</' . sanitize_html_class( $args['type'] ) . '>';
520
-
521
-
522
-		} else {
523
-			$output = $args['content'];
524
-		}
525
-
526
-		return $output;
527
-	}
528
-
529
-	/**
530
-	 * Build the component.
531
-	 *
532
-	 * @param array $args
533
-	 *
534
-	 * @return string The rendered component.
535
-	 */
536
-	public static function textarea( $args = array() ) {
537
-		global $aui_bs5;
538
-
539
-		$defaults = array(
540
-			'name'               => '',
541
-			'class'              => '',
542
-			'wrap_class'         => '',
543
-			'id'                 => '',
544
-			'placeholder'        => '',
545
-			'title'              => '',
546
-			'value'              => '',
547
-			'required'           => false,
548
-			'label'              => '',
549
-			'label_after'        => false,
550
-			'label_class'        => '',
551
-			'label_type'         => '',
552
-			'label_col'          => '',
553
-			// sets the label type, default: hidden. Options: hidden, top, horizontal, floating
554
-			'input_group_right'        => '',
555
-			'input_group_left'         => '',
556
-			'input_group_right_inside' => false,
557
-			'form_group_class'      => '',
558
-			'help_text'          => '',
559
-			'validation_text'    => '',
560
-			'validation_pattern' => '',
561
-			'no_wrap'            => false,
562
-			'rows'               => '',
563
-			'wysiwyg'            => false,
564
-			'allow_tags'         => false,
565
-			// Allow HTML tags
566
-			'element_require'    => '',
567
-			// [%element_id%] == "1"
568
-			'extra_attributes'   => array(),
569
-			// an array of extra attributes
570
-			'wrap_attributes'    => array(),
571
-		);
572
-
573
-		/**
574
-		 * Parse incoming $args into an array and merge it with $defaults
575
-		 */
576
-		$args   = wp_parse_args( $args, $defaults );
577
-		$output = '';
578
-		$label = '';
579
-
580
-		// hidden label option needs to be empty
581
-		$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
582
-
583
-		// floating labels don't work with wysiwyg so set it as top
584
-		if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) {
585
-			$args['label_type'] = 'top';
586
-		}
587
-
588
-		$label_after = $args['label_after'];
589
-
590
-		// floating labels need label after
591
-		if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) {
592
-			$label_after         = true;
593
-			$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
594
-		}
595
-
596
-		// label
597
-		if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
598
-		} elseif ( ! empty( $args['label'] ) && ! $label_after ) {
599
-			$label_args = array(
600
-				'title'      => $args['label'],
601
-				'for'        => $args['id'],
602
-				'class'      => $args['label_class'] . " ",
603
-				'label_type' => $args['label_type'],
604
-				'label_col'  => $args['label_col']
605
-			);
606
-			$label .= self::label( $label_args );
607
-		}
608
-
609
-		// maybe horizontal label
610
-		if ( $args['label_type'] == 'horizontal' ) {
611
-			$input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
612
-			$label .= '<div class="' . $input_col . '">';
613
-		}
614
-
615
-		if ( ! empty( $args['wysiwyg'] ) ) {
616
-			ob_start();
617
-			$content   = $args['value'];
618
-			$editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor';
619
-			$settings  = array(
620
-				'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4,
621
-				'quicktags'     => false,
622
-				'media_buttons' => false,
623
-				'editor_class'  => 'form-control',
624
-				'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ),
625
-				'teeny'         => true,
626
-			);
627
-
628
-			// maybe set settings if array
629
-			if ( is_array( $args['wysiwyg'] ) ) {
630
-				$settings = wp_parse_args( $args['wysiwyg'], $settings );
631
-			}
632
-
633
-			wp_editor( $content, $editor_id, $settings );
634
-			$output .= ob_get_clean();
635
-		} else {
636
-
637
-			// open
638
-			$output .= '<textarea ';
639
-
640
-			// name
641
-			if ( ! empty( $args['name'] ) ) {
642
-				$output .= ' name="' . esc_attr( $args['name'] ) . '" ';
643
-			}
644
-
645
-			// id
646
-			if ( ! empty( $args['id'] ) ) {
647
-				$output .= ' id="' . sanitize_html_class( $args['id'] ) . '" ';
648
-			}
649
-
650
-			// placeholder
651
-			if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) {
652
-				$output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" ';
653
-			}
654
-
655
-			// title
656
-			if ( ! empty( $args['title'] ) ) {
657
-				$output .= ' title="' . esc_attr( $args['title'] ) . '" ';
658
-			}
659
-
660
-			// validation text
661
-			if ( ! empty( $args['validation_text'] ) ) {
662
-				$output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" ';
663
-				$output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
664
-			}
665
-
666
-			// validation_pattern
667
-			if ( ! empty( $args['validation_pattern'] ) ) {
668
-				$output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" ';
669
-			}
670
-
671
-			// required
672
-			if ( ! empty( $args['required'] ) ) {
673
-				$output .= ' required ';
674
-			}
675
-
676
-			// rows
677
-			if ( ! empty( $args['rows'] ) ) {
678
-				$output .= ' rows="' . absint( $args['rows'] ) . '" ';
679
-			}
680
-
681
-
682
-			// class
683
-			$class = ! empty( $args['class'] ) ? $args['class'] : '';
684
-			$output .= ' class="form-control ' . $class . '" ';
685
-
686
-			// extra attributes
687
-			if ( ! empty( $args['extra_attributes'] ) ) {
688
-				$output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
689
-			}
690
-
691
-			// close tag
692
-			$output .= ' >';
693
-
694
-			// value
695
-			if ( ! empty( $args['value'] ) ) {
696
-				if ( ! empty( $args['allow_tags'] ) ) {
697
-					$output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML.
698
-				} else {
699
-					$output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] );
700
-				}
701
-			}
702
-
703
-			// closing tag
704
-			$output .= '</textarea>';
705
-
706
-
707
-			// input group wraps
708
-			if ( $args['input_group_left'] || $args['input_group_right'] ) {
709
-				$w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
710
-				if ( $args['input_group_left'] ) {
711
-					$output = self::wrap( array(
712
-						'content'                 => $output,
713
-						'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
714
-						'input_group_left'        => $args['input_group_left'],
715
-						'input_group_left_inside' => $args['input_group_left_inside']
716
-					) );
717
-				}
718
-				if ( $args['input_group_right'] ) {
719
-					$output = self::wrap( array(
720
-						'content'                  => $output,
721
-						'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
722
-						'input_group_right'        => $args['input_group_right'],
723
-						'input_group_right_inside' => $args['input_group_right_inside']
724
-					) );
725
-				}
726
-
727
-			}
728
-
729
-
730
-		}
731
-
732
-		if ( ! empty( $args['label'] ) && $label_after ) {
733
-			$label_args = array(
734
-				'title'      => $args['label'],
735
-				'for'        => $args['id'],
736
-				'class'      => $args['label_class'] . " ",
737
-				'label_type' => $args['label_type'],
738
-				'label_col'  => $args['label_col']
739
-			);
740
-			$output .= self::label( $label_args );
741
-		}
742
-
743
-		// help text
744
-		if ( ! empty( $args['help_text'] ) ) {
745
-			$output .= AUI_Component_Helper::help_text( $args['help_text'] );
746
-		}
747
-
748
-		if ( ! $label_after ) {
749
-			$output = $label . $output;
750
-		}
751
-
752
-		// maybe horizontal label
753
-		if ( $args['label_type'] == 'horizontal' ) {
754
-			$output .= '</div>';
755
-		}
756
-
757
-
758
-		// wrap
759
-		if ( ! $args['no_wrap'] ) {
760
-			if ( ! empty( $args['form_group_class'] ) ) {
761
-				$fg_class = esc_attr( $args['form_group_class'] );
762
-			}else{
763
-				$fg_class = $aui_bs5 ? 'mb-3' : 'form-group';
764
-			}
765
-			$form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : $fg_class;
766
-			$wrap_class       = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class;
767
-			$wrap_class       = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
768
-			$output           = self::wrap( array(
769
-				'content'         => $output,
770
-				'class'           => $wrap_class,
771
-				'element_require' => $args['element_require'],
772
-				'argument_id'     => $args['id'],
773
-				'wrap_attributes' => $args['wrap_attributes'],
774
-			) );
775
-		}
776
-
777
-
778
-		return $output;
779
-	}
780
-
781
-	/**
782
-	 * Build the component.
783
-	 *
784
-	 * @param array $args
785
-	 *
786
-	 * @return string The rendered component.
787
-	 */
788
-	public static function select( $args = array() ) {
789
-		global $aui_bs5;
790
-		$defaults = array(
791
-			'class'            => '',
792
-			'wrap_class'       => '',
793
-			'id'               => '',
794
-			'title'            => '',
795
-			'value'            => '',
796
-			// can be an array or a string
797
-			'required'         => false,
798
-			'label'            => '',
799
-			'label_after'      => false,
800
-			'label_type'       => '',
801
-			'label_col'        => '',
802
-			// sets the label type, default: hidden. Options: hidden, top, horizontal, floating
803
-			'label_class'      => '',
804
-			'help_text'        => '',
805
-			'placeholder'      => '',
806
-			'options'          => array(),
807
-			// array or string
808
-			'icon'             => '',
809
-			'multiple'         => false,
810
-			'select2'          => false,
811
-			'no_wrap'          => false,
812
-			'input_group_right' => '',
813
-			'input_group_left' => '',
814
-			'input_group_right_inside' => false, // forces the input group inside the input
815
-			'input_group_left_inside' => false, // forces the input group inside the input
816
-			'form_group_class'  => '',
817
-			'element_require'  => '',
818
-			// [%element_id%] == "1"
819
-			'extra_attributes' => array(),
820
-			// an array of extra attributes
821
-			'wrap_attributes'  => array(),
822
-		);
823
-
824
-		/**
825
-		 * Parse incoming $args into an array and merge it with $defaults
826
-		 */
827
-		$args   = wp_parse_args( $args, $defaults );
828
-		$output = '';
829
-
830
-		// for now lets hide floating labels
831
-		if ( $args['label_type'] == 'floating' ) {
832
-			$args['label_type'] = 'hidden';
833
-		}
834
-
835
-		// hidden label option needs to be empty
836
-		$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
837
-
838
-
839
-		$label_after = $args['label_after'];
840
-
841
-		// floating labels need label after
842
-		if ( $args['label_type'] == 'floating' ) {
843
-			$label_after         = true;
844
-			$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
845
-		}
846
-
847
-		// Maybe setup select2
848
-		$is_select2 = false;
849
-		if ( ! empty( $args['select2'] ) ) {
850
-			$args['class'] .= ' aui-select2';
851
-			$is_select2 = true;
852
-		} elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) {
853
-			$is_select2 = true;
854
-		}
855
-
856
-		// select2 tags
857
-		if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason
858
-			$args['data-tags']             = 'true';
859
-			$args['data-token-separators'] = "[',']";
860
-			$args['multiple']              = true;
861
-		}
862
-
863
-		// select2 placeholder
864
-		if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) {
865
-			$args['data-placeholder'] = esc_attr( $args['placeholder'] );
866
-			$args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true;
867
-		}
868
-
869
-		// Set hidden input to save empty value for multiselect.
870
-		if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) {
871
-			$output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>';
872
-		}
873
-
874
-		// open/type
875
-		$output .= '<select ';
876
-
877
-		// style
878
-		if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) {
879
-			$output .= " style='width:100%;' ";
880
-		}
881
-
882
-		// element require
883
-		if ( ! empty( $args['element_require'] ) ) {
884
-			$output .= AUI_Component_Helper::element_require( $args['element_require'] );
885
-			$args['class'] .= " aui-conditional-field";
886
-		}
887
-
888
-		// class
889
-		$class = ! empty( $args['class'] ) ? $args['class'] : '';
890
-		$select_class = $aui_bs5 ? 'form-select ' : 'custom-select ';
891
-		$output .= AUI_Component_Helper::class_attr( $select_class . $class );
892
-
893
-		// name
894
-		if ( ! empty( $args['name'] ) ) {
895
-			$output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] );
896
-		}
897
-
898
-		// id
899
-		if ( ! empty( $args['id'] ) ) {
900
-			$output .= AUI_Component_Helper::id( $args['id'] );
901
-		}
902
-
903
-		// title
904
-		if ( ! empty( $args['title'] ) ) {
905
-			$output .= AUI_Component_Helper::title( $args['title'] );
906
-		}
907
-
908
-		// data-attributes
909
-		$output .= AUI_Component_Helper::data_attributes( $args );
910
-
911
-		// aria-attributes
912
-		$output .= AUI_Component_Helper::aria_attributes( $args );
913
-
914
-		// extra attributes
915
-		if ( ! empty( $args['extra_attributes'] ) ) {
916
-			$output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
917
-		}
918
-
919
-		// required
920
-		if ( ! empty( $args['required'] ) ) {
921
-			$output .= ' required ';
922
-		}
923
-
924
-		// multiple
925
-		if ( ! empty( $args['multiple'] ) ) {
926
-			$output .= ' multiple ';
927
-		}
928
-
929
-		// close opening tag
930
-		$output .= ' >';
931
-
932
-		// placeholder
933
-		if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) {
934
-			$output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>';
935
-		} elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) {
936
-			$output .= "<option></option>"; // select2 needs an empty select to fill the placeholder
937
-		}
938
-
939
-		// Options
940
-		if ( ! empty( $args['options'] ) ) {
941
-
942
-			if ( ! is_array( $args['options'] ) ) {
943
-				$output .= $args['options']; // not the preferred way but an option
944
-			} else {
945
-				foreach ( $args['options'] as $val => $name ) {
946
-					$selected = '';
947
-					if ( is_array( $name ) ) {
948
-						if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) {
949
-							$option_label = isset( $name['label'] ) ? $name['label'] : '';
950
-
951
-							$output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>';
952
-						} else {
953
-							$option_label = isset( $name['label'] ) ? $name['label'] : '';
954
-							$option_value = isset( $name['value'] ) ? $name['value'] : '';
955
-							$extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : '';
956
-							if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) {
957
-								$selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : "";
958
-							} elseif ( ! empty( $args['value'] ) ) {
959
-								$selected = selected( $option_value, stripslashes_deep( $args['value'] ), false );
960
-							} elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) {
961
-								$selected = selected( $option_value, $args['value'], false );
962
-							}
963
-
964
-							$output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>';
965
-						}
966
-					} else {
967
-						if ( ! empty( $args['value'] ) ) {
968
-							if ( is_array( $args['value'] ) ) {
969
-								$selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : '';
970
-							} elseif ( ! empty( $args['value'] ) ) {
971
-								$selected = selected( $args['value'], $val, false );
972
-							}
973
-						} elseif ( $args['value'] === $val ) {
974
-							$selected = selected( $args['value'], $val, false );
975
-						}
976
-						$output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>';
977
-					}
978
-				}
979
-			}
980
-
981
-		}
982
-
983
-		// closing tag
984
-		$output .= '</select>';
985
-
986
-		$label = '';
987
-		$help_text = '';
988
-		// label
989
-		if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
990
-		} elseif ( ! empty( $args['label'] ) && ! $label_after ) {
991
-			$label_args = array(
992
-				'title'      => $args['label'],
993
-				'for'        => $args['id'],
994
-				'class'      => $args['label_class'] . " ",
995
-				'label_type' => $args['label_type'],
996
-				'label_col'  => $args['label_col']
997
-			);
998
-			$label = self::label( $label_args );
999
-		}
1000
-
1001
-		// help text
1002
-		if ( ! empty( $args['help_text'] ) ) {
1003
-			$help_text = AUI_Component_Helper::help_text( $args['help_text'] );
1004
-		}
1005
-
1006
-		// input group wraps
1007
-		if ( $args['input_group_left'] || $args['input_group_right'] ) {
1008
-			$w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
1009
-			if ( $args['input_group_left'] ) {
1010
-				$output = self::wrap( array(
1011
-					'content'                 => $output,
1012
-					'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
1013
-					'input_group_left'        => $args['input_group_left'],
1014
-					'input_group_left_inside' => $args['input_group_left_inside']
1015
-				) );
1016
-			}
1017
-			if ( $args['input_group_right'] ) {
1018
-				$output = self::wrap( array(
1019
-					'content'                  => $output,
1020
-					'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
1021
-					'input_group_right'        => $args['input_group_right'],
1022
-					'input_group_right_inside' => $args['input_group_right_inside']
1023
-				) );
1024
-			}
1025
-
1026
-		}
1027
-
1028
-		if ( ! $label_after ) {
1029
-			$output .= $help_text;
1030
-		}
1031
-
1032
-
1033
-		if ( $args['label_type'] == 'horizontal' ) {
1034
-			$output = self::wrap( array(
1035
-				'content' => $output,
1036
-				'class'   => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' )
1037
-			) );
1038
-		}
1039
-
1040
-		if ( ! $label_after ) {
1041
-			$output = $label . $output;
1042
-		}
1043
-
1044
-		// maybe horizontal label
515
+            }
516
+
517
+
518
+            // close wrap
519
+            $output .= '</' . sanitize_html_class( $args['type'] ) . '>';
520
+
521
+
522
+        } else {
523
+            $output = $args['content'];
524
+        }
525
+
526
+        return $output;
527
+    }
528
+
529
+    /**
530
+     * Build the component.
531
+     *
532
+     * @param array $args
533
+     *
534
+     * @return string The rendered component.
535
+     */
536
+    public static function textarea( $args = array() ) {
537
+        global $aui_bs5;
538
+
539
+        $defaults = array(
540
+            'name'               => '',
541
+            'class'              => '',
542
+            'wrap_class'         => '',
543
+            'id'                 => '',
544
+            'placeholder'        => '',
545
+            'title'              => '',
546
+            'value'              => '',
547
+            'required'           => false,
548
+            'label'              => '',
549
+            'label_after'        => false,
550
+            'label_class'        => '',
551
+            'label_type'         => '',
552
+            'label_col'          => '',
553
+            // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
554
+            'input_group_right'        => '',
555
+            'input_group_left'         => '',
556
+            'input_group_right_inside' => false,
557
+            'form_group_class'      => '',
558
+            'help_text'          => '',
559
+            'validation_text'    => '',
560
+            'validation_pattern' => '',
561
+            'no_wrap'            => false,
562
+            'rows'               => '',
563
+            'wysiwyg'            => false,
564
+            'allow_tags'         => false,
565
+            // Allow HTML tags
566
+            'element_require'    => '',
567
+            // [%element_id%] == "1"
568
+            'extra_attributes'   => array(),
569
+            // an array of extra attributes
570
+            'wrap_attributes'    => array(),
571
+        );
572
+
573
+        /**
574
+         * Parse incoming $args into an array and merge it with $defaults
575
+         */
576
+        $args   = wp_parse_args( $args, $defaults );
577
+        $output = '';
578
+        $label = '';
579
+
580
+        // hidden label option needs to be empty
581
+        $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
582
+
583
+        // floating labels don't work with wysiwyg so set it as top
584
+        if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) {
585
+            $args['label_type'] = 'top';
586
+        }
587
+
588
+        $label_after = $args['label_after'];
589
+
590
+        // floating labels need label after
591
+        if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) {
592
+            $label_after         = true;
593
+            $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
594
+        }
595
+
596
+        // label
597
+        if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
598
+        } elseif ( ! empty( $args['label'] ) && ! $label_after ) {
599
+            $label_args = array(
600
+                'title'      => $args['label'],
601
+                'for'        => $args['id'],
602
+                'class'      => $args['label_class'] . " ",
603
+                'label_type' => $args['label_type'],
604
+                'label_col'  => $args['label_col']
605
+            );
606
+            $label .= self::label( $label_args );
607
+        }
608
+
609
+        // maybe horizontal label
610
+        if ( $args['label_type'] == 'horizontal' ) {
611
+            $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
612
+            $label .= '<div class="' . $input_col . '">';
613
+        }
614
+
615
+        if ( ! empty( $args['wysiwyg'] ) ) {
616
+            ob_start();
617
+            $content   = $args['value'];
618
+            $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor';
619
+            $settings  = array(
620
+                'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4,
621
+                'quicktags'     => false,
622
+                'media_buttons' => false,
623
+                'editor_class'  => 'form-control',
624
+                'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ),
625
+                'teeny'         => true,
626
+            );
627
+
628
+            // maybe set settings if array
629
+            if ( is_array( $args['wysiwyg'] ) ) {
630
+                $settings = wp_parse_args( $args['wysiwyg'], $settings );
631
+            }
632
+
633
+            wp_editor( $content, $editor_id, $settings );
634
+            $output .= ob_get_clean();
635
+        } else {
636
+
637
+            // open
638
+            $output .= '<textarea ';
639
+
640
+            // name
641
+            if ( ! empty( $args['name'] ) ) {
642
+                $output .= ' name="' . esc_attr( $args['name'] ) . '" ';
643
+            }
644
+
645
+            // id
646
+            if ( ! empty( $args['id'] ) ) {
647
+                $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" ';
648
+            }
649
+
650
+            // placeholder
651
+            if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) {
652
+                $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" ';
653
+            }
654
+
655
+            // title
656
+            if ( ! empty( $args['title'] ) ) {
657
+                $output .= ' title="' . esc_attr( $args['title'] ) . '" ';
658
+            }
659
+
660
+            // validation text
661
+            if ( ! empty( $args['validation_text'] ) ) {
662
+                $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" ';
663
+                $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
664
+            }
665
+
666
+            // validation_pattern
667
+            if ( ! empty( $args['validation_pattern'] ) ) {
668
+                $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" ';
669
+            }
670
+
671
+            // required
672
+            if ( ! empty( $args['required'] ) ) {
673
+                $output .= ' required ';
674
+            }
675
+
676
+            // rows
677
+            if ( ! empty( $args['rows'] ) ) {
678
+                $output .= ' rows="' . absint( $args['rows'] ) . '" ';
679
+            }
680
+
681
+
682
+            // class
683
+            $class = ! empty( $args['class'] ) ? $args['class'] : '';
684
+            $output .= ' class="form-control ' . $class . '" ';
685
+
686
+            // extra attributes
687
+            if ( ! empty( $args['extra_attributes'] ) ) {
688
+                $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
689
+            }
690
+
691
+            // close tag
692
+            $output .= ' >';
693
+
694
+            // value
695
+            if ( ! empty( $args['value'] ) ) {
696
+                if ( ! empty( $args['allow_tags'] ) ) {
697
+                    $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML.
698
+                } else {
699
+                    $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] );
700
+                }
701
+            }
702
+
703
+            // closing tag
704
+            $output .= '</textarea>';
705
+
706
+
707
+            // input group wraps
708
+            if ( $args['input_group_left'] || $args['input_group_right'] ) {
709
+                $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
710
+                if ( $args['input_group_left'] ) {
711
+                    $output = self::wrap( array(
712
+                        'content'                 => $output,
713
+                        'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
714
+                        'input_group_left'        => $args['input_group_left'],
715
+                        'input_group_left_inside' => $args['input_group_left_inside']
716
+                    ) );
717
+                }
718
+                if ( $args['input_group_right'] ) {
719
+                    $output = self::wrap( array(
720
+                        'content'                  => $output,
721
+                        'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
722
+                        'input_group_right'        => $args['input_group_right'],
723
+                        'input_group_right_inside' => $args['input_group_right_inside']
724
+                    ) );
725
+                }
726
+
727
+            }
728
+
729
+
730
+        }
731
+
732
+        if ( ! empty( $args['label'] ) && $label_after ) {
733
+            $label_args = array(
734
+                'title'      => $args['label'],
735
+                'for'        => $args['id'],
736
+                'class'      => $args['label_class'] . " ",
737
+                'label_type' => $args['label_type'],
738
+                'label_col'  => $args['label_col']
739
+            );
740
+            $output .= self::label( $label_args );
741
+        }
742
+
743
+        // help text
744
+        if ( ! empty( $args['help_text'] ) ) {
745
+            $output .= AUI_Component_Helper::help_text( $args['help_text'] );
746
+        }
747
+
748
+        if ( ! $label_after ) {
749
+            $output = $label . $output;
750
+        }
751
+
752
+        // maybe horizontal label
753
+        if ( $args['label_type'] == 'horizontal' ) {
754
+            $output .= '</div>';
755
+        }
756
+
757
+
758
+        // wrap
759
+        if ( ! $args['no_wrap'] ) {
760
+            if ( ! empty( $args['form_group_class'] ) ) {
761
+                $fg_class = esc_attr( $args['form_group_class'] );
762
+            }else{
763
+                $fg_class = $aui_bs5 ? 'mb-3' : 'form-group';
764
+            }
765
+            $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : $fg_class;
766
+            $wrap_class       = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class;
767
+            $wrap_class       = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
768
+            $output           = self::wrap( array(
769
+                'content'         => $output,
770
+                'class'           => $wrap_class,
771
+                'element_require' => $args['element_require'],
772
+                'argument_id'     => $args['id'],
773
+                'wrap_attributes' => $args['wrap_attributes'],
774
+            ) );
775
+        }
776
+
777
+
778
+        return $output;
779
+    }
780
+
781
+    /**
782
+     * Build the component.
783
+     *
784
+     * @param array $args
785
+     *
786
+     * @return string The rendered component.
787
+     */
788
+    public static function select( $args = array() ) {
789
+        global $aui_bs5;
790
+        $defaults = array(
791
+            'class'            => '',
792
+            'wrap_class'       => '',
793
+            'id'               => '',
794
+            'title'            => '',
795
+            'value'            => '',
796
+            // can be an array or a string
797
+            'required'         => false,
798
+            'label'            => '',
799
+            'label_after'      => false,
800
+            'label_type'       => '',
801
+            'label_col'        => '',
802
+            // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
803
+            'label_class'      => '',
804
+            'help_text'        => '',
805
+            'placeholder'      => '',
806
+            'options'          => array(),
807
+            // array or string
808
+            'icon'             => '',
809
+            'multiple'         => false,
810
+            'select2'          => false,
811
+            'no_wrap'          => false,
812
+            'input_group_right' => '',
813
+            'input_group_left' => '',
814
+            'input_group_right_inside' => false, // forces the input group inside the input
815
+            'input_group_left_inside' => false, // forces the input group inside the input
816
+            'form_group_class'  => '',
817
+            'element_require'  => '',
818
+            // [%element_id%] == "1"
819
+            'extra_attributes' => array(),
820
+            // an array of extra attributes
821
+            'wrap_attributes'  => array(),
822
+        );
823
+
824
+        /**
825
+         * Parse incoming $args into an array and merge it with $defaults
826
+         */
827
+        $args   = wp_parse_args( $args, $defaults );
828
+        $output = '';
829
+
830
+        // for now lets hide floating labels
831
+        if ( $args['label_type'] == 'floating' ) {
832
+            $args['label_type'] = 'hidden';
833
+        }
834
+
835
+        // hidden label option needs to be empty
836
+        $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
837
+
838
+
839
+        $label_after = $args['label_after'];
840
+
841
+        // floating labels need label after
842
+        if ( $args['label_type'] == 'floating' ) {
843
+            $label_after         = true;
844
+            $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
845
+        }
846
+
847
+        // Maybe setup select2
848
+        $is_select2 = false;
849
+        if ( ! empty( $args['select2'] ) ) {
850
+            $args['class'] .= ' aui-select2';
851
+            $is_select2 = true;
852
+        } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) {
853
+            $is_select2 = true;
854
+        }
855
+
856
+        // select2 tags
857
+        if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason
858
+            $args['data-tags']             = 'true';
859
+            $args['data-token-separators'] = "[',']";
860
+            $args['multiple']              = true;
861
+        }
862
+
863
+        // select2 placeholder
864
+        if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) {
865
+            $args['data-placeholder'] = esc_attr( $args['placeholder'] );
866
+            $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true;
867
+        }
868
+
869
+        // Set hidden input to save empty value for multiselect.
870
+        if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) {
871
+            $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>';
872
+        }
873
+
874
+        // open/type
875
+        $output .= '<select ';
876
+
877
+        // style
878
+        if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) {
879
+            $output .= " style='width:100%;' ";
880
+        }
881
+
882
+        // element require
883
+        if ( ! empty( $args['element_require'] ) ) {
884
+            $output .= AUI_Component_Helper::element_require( $args['element_require'] );
885
+            $args['class'] .= " aui-conditional-field";
886
+        }
887
+
888
+        // class
889
+        $class = ! empty( $args['class'] ) ? $args['class'] : '';
890
+        $select_class = $aui_bs5 ? 'form-select ' : 'custom-select ';
891
+        $output .= AUI_Component_Helper::class_attr( $select_class . $class );
892
+
893
+        // name
894
+        if ( ! empty( $args['name'] ) ) {
895
+            $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] );
896
+        }
897
+
898
+        // id
899
+        if ( ! empty( $args['id'] ) ) {
900
+            $output .= AUI_Component_Helper::id( $args['id'] );
901
+        }
902
+
903
+        // title
904
+        if ( ! empty( $args['title'] ) ) {
905
+            $output .= AUI_Component_Helper::title( $args['title'] );
906
+        }
907
+
908
+        // data-attributes
909
+        $output .= AUI_Component_Helper::data_attributes( $args );
910
+
911
+        // aria-attributes
912
+        $output .= AUI_Component_Helper::aria_attributes( $args );
913
+
914
+        // extra attributes
915
+        if ( ! empty( $args['extra_attributes'] ) ) {
916
+            $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
917
+        }
918
+
919
+        // required
920
+        if ( ! empty( $args['required'] ) ) {
921
+            $output .= ' required ';
922
+        }
923
+
924
+        // multiple
925
+        if ( ! empty( $args['multiple'] ) ) {
926
+            $output .= ' multiple ';
927
+        }
928
+
929
+        // close opening tag
930
+        $output .= ' >';
931
+
932
+        // placeholder
933
+        if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) {
934
+            $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>';
935
+        } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) {
936
+            $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder
937
+        }
938
+
939
+        // Options
940
+        if ( ! empty( $args['options'] ) ) {
941
+
942
+            if ( ! is_array( $args['options'] ) ) {
943
+                $output .= $args['options']; // not the preferred way but an option
944
+            } else {
945
+                foreach ( $args['options'] as $val => $name ) {
946
+                    $selected = '';
947
+                    if ( is_array( $name ) ) {
948
+                        if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) {
949
+                            $option_label = isset( $name['label'] ) ? $name['label'] : '';
950
+
951
+                            $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>';
952
+                        } else {
953
+                            $option_label = isset( $name['label'] ) ? $name['label'] : '';
954
+                            $option_value = isset( $name['value'] ) ? $name['value'] : '';
955
+                            $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : '';
956
+                            if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) {
957
+                                $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : "";
958
+                            } elseif ( ! empty( $args['value'] ) ) {
959
+                                $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false );
960
+                            } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) {
961
+                                $selected = selected( $option_value, $args['value'], false );
962
+                            }
963
+
964
+                            $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>';
965
+                        }
966
+                    } else {
967
+                        if ( ! empty( $args['value'] ) ) {
968
+                            if ( is_array( $args['value'] ) ) {
969
+                                $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : '';
970
+                            } elseif ( ! empty( $args['value'] ) ) {
971
+                                $selected = selected( $args['value'], $val, false );
972
+                            }
973
+                        } elseif ( $args['value'] === $val ) {
974
+                            $selected = selected( $args['value'], $val, false );
975
+                        }
976
+                        $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>';
977
+                    }
978
+                }
979
+            }
980
+
981
+        }
982
+
983
+        // closing tag
984
+        $output .= '</select>';
985
+
986
+        $label = '';
987
+        $help_text = '';
988
+        // label
989
+        if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
990
+        } elseif ( ! empty( $args['label'] ) && ! $label_after ) {
991
+            $label_args = array(
992
+                'title'      => $args['label'],
993
+                'for'        => $args['id'],
994
+                'class'      => $args['label_class'] . " ",
995
+                'label_type' => $args['label_type'],
996
+                'label_col'  => $args['label_col']
997
+            );
998
+            $label = self::label( $label_args );
999
+        }
1000
+
1001
+        // help text
1002
+        if ( ! empty( $args['help_text'] ) ) {
1003
+            $help_text = AUI_Component_Helper::help_text( $args['help_text'] );
1004
+        }
1005
+
1006
+        // input group wraps
1007
+        if ( $args['input_group_left'] || $args['input_group_right'] ) {
1008
+            $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : '';
1009
+            if ( $args['input_group_left'] ) {
1010
+                $output = self::wrap( array(
1011
+                    'content'                 => $output,
1012
+                    'class'                   => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
1013
+                    'input_group_left'        => $args['input_group_left'],
1014
+                    'input_group_left_inside' => $args['input_group_left_inside']
1015
+                ) );
1016
+            }
1017
+            if ( $args['input_group_right'] ) {
1018
+                $output = self::wrap( array(
1019
+                    'content'                  => $output,
1020
+                    'class'                    => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group',
1021
+                    'input_group_right'        => $args['input_group_right'],
1022
+                    'input_group_right_inside' => $args['input_group_right_inside']
1023
+                ) );
1024
+            }
1025
+
1026
+        }
1027
+
1028
+        if ( ! $label_after ) {
1029
+            $output .= $help_text;
1030
+        }
1031
+
1032
+
1033
+        if ( $args['label_type'] == 'horizontal' ) {
1034
+            $output = self::wrap( array(
1035
+                'content' => $output,
1036
+                'class'   => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' )
1037
+            ) );
1038
+        }
1039
+
1040
+        if ( ! $label_after ) {
1041
+            $output = $label . $output;
1042
+        }
1043
+
1044
+        // maybe horizontal label
1045 1045
 //		if ( $args['label_type'] == 'horizontal' ) {
1046 1046
 //			$output .= '</div>';
1047 1047
 //		}
1048 1048
 
1049 1049
 
1050
-		// wrap
1051
-		if ( ! $args['no_wrap'] ) {
1052
-			if ( ! empty( $args['form_group_class'] ) ) {
1053
-				$fg_class = esc_attr( $args['form_group_class'] );
1054
-			}else{
1055
-				$fg_class = $aui_bs5 ? 'mb-3' : 'form-group';
1056
-			}
1057
-			$wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class;
1058
-			$wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
1059
-			$output     = self::wrap( array(
1060
-				'content'         => $output,
1061
-				'class'           => $wrap_class,
1062
-				'element_require' => $args['element_require'],
1063
-				'argument_id'     => $args['id'],
1064
-				'wrap_attributes' => $args['wrap_attributes'],
1065
-			) );
1066
-		}
1067
-
1068
-
1069
-		return $output;
1070
-	}
1071
-
1072
-	/**
1073
-	 * Build the component.
1074
-	 *
1075
-	 * @param array $args
1076
-	 *
1077
-	 * @return string The rendered component.
1078
-	 */
1079
-	public static function radio( $args = array() ) {
1080
-		global $aui_bs5;
1081
-
1082
-		$defaults = array(
1083
-			'class'            => '',
1084
-			'wrap_class'       => '',
1085
-			'id'               => '',
1086
-			'title'            => '',
1087
-			'horizontal'       => false,
1088
-			// sets the lable horizontal
1089
-			'value'            => '',
1090
-			'label'            => '',
1091
-			'label_class'      => '',
1092
-			'label_type'       => '',
1093
-			'label_col'        => '',
1094
-			// sets the label type, default: hidden. Options: hidden, top, horizontal, floating
1095
-			'help_text'        => '',
1096
-			'inline'           => true,
1097
-			'required'         => false,
1098
-			'options'          => array(),
1099
-			'icon'             => '',
1100
-			'no_wrap'          => false,
1101
-			'element_require'  => '',
1102
-			// [%element_id%] == "1"
1103
-			'extra_attributes' => array(),
1104
-			// an array of extra attributes
1105
-			'wrap_attributes'  => array()
1106
-		);
1107
-
1108
-		/**
1109
-		 * Parse incoming $args into an array and merge it with $defaults
1110
-		 */
1111
-		$args = wp_parse_args( $args, $defaults );
1112
-
1113
-		// for now lets use horizontal for floating
1114
-		if ( $args['label_type'] == 'floating' ) {
1115
-			$args['label_type'] = 'horizontal';
1116
-		}
1117
-
1118
-		$label_args = array(
1119
-			'title'      => $args['label'],
1120
-			'class'      => $args['label_class'] . " pt-0 ",
1121
-			'label_type' => $args['label_type'],
1122
-			'label_col'  => $args['label_col']
1123
-		);
1124
-
1125
-		$output = '';
1126
-
1127
-
1128
-		// label before
1129
-		if ( ! empty( $args['label'] ) ) {
1130
-			$output .= self::label( $label_args, 'radio' );
1131
-		}
1132
-
1133
-		// maybe horizontal label
1134
-		if ( $args['label_type'] == 'horizontal' ) {
1135
-			$input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
1136
-			$output .= '<div class="' . $input_col . '">';
1137
-		}
1138
-
1139
-		if ( ! empty( $args['options'] ) ) {
1140
-			$count = 0;
1141
-			foreach ( $args['options'] as $value => $label ) {
1142
-				$option_args            = $args;
1143
-				$option_args['value']   = $value;
1144
-				$option_args['label']   = $label;
1145
-				$option_args['checked'] = $value == $args['value'] ? true : false;
1146
-				$output .= self::radio_option( $option_args, $count );
1147
-				$count ++;
1148
-			}
1149
-		}
1150
-
1151
-		// help text
1152
-		$help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : '';
1153
-		$output .= $help_text;
1154
-
1155
-		// maybe horizontal label
1156
-		if ( $args['label_type'] == 'horizontal' ) {
1157
-			$output .= '</div>';
1158
-		}
1159
-
1160
-		// wrap
1161
-		$fg_class = $aui_bs5 ? 'mb-3' : 'form-group';
1162
-		$wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class;
1163
-		$wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
1164
-		$output     = self::wrap( array(
1165
-			'content'         => $output,
1166
-			'class'           => $wrap_class,
1167
-			'element_require' => $args['element_require'],
1168
-			'argument_id'     => $args['id'],
1169
-			'wrap_attributes' => $args['wrap_attributes'],
1170
-		) );
1171
-
1172
-
1173
-		return $output;
1174
-	}
1175
-
1176
-	/**
1177
-	 * Build the component.
1178
-	 *
1179
-	 * @param array $args
1180
-	 *
1181
-	 * @return string The rendered component.
1182
-	 */
1183
-	public static function radio_option( $args = array(), $count = '' ) {
1184
-		$defaults = array(
1185
-			'class'            => '',
1186
-			'id'               => '',
1187
-			'title'            => '',
1188
-			'value'            => '',
1189
-			'required'         => false,
1190
-			'inline'           => true,
1191
-			'label'            => '',
1192
-			'options'          => array(),
1193
-			'icon'             => '',
1194
-			'no_wrap'          => false,
1195
-			'extra_attributes' => array() // an array of extra attributes
1196
-		);
1197
-
1198
-		/**
1199
-		 * Parse incoming $args into an array and merge it with $defaults
1200
-		 */
1201
-		$args = wp_parse_args( $args, $defaults );
1202
-
1203
-		$output = '';
1204
-
1205
-		// open/type
1206
-		$output .= '<input type="radio"';
1207
-
1208
-		// class
1209
-		$output .= ' class="form-check-input" ';
1210
-
1211
-		// name
1212
-		if ( ! empty( $args['name'] ) ) {
1213
-			$output .= AUI_Component_Helper::name( $args['name'] );
1214
-		}
1215
-
1216
-		// id
1217
-		if ( ! empty( $args['id'] ) ) {
1218
-			$output .= AUI_Component_Helper::id( $args['id'] . $count );
1219
-		}
1220
-
1221
-		// title
1222
-		if ( ! empty( $args['title'] ) ) {
1223
-			$output .= AUI_Component_Helper::title( $args['title'] );
1224
-		}
1225
-
1226
-		// value
1227
-		if ( isset( $args['value'] ) ) {
1228
-			$output .= AUI_Component_Helper::value( $args['value'] );
1229
-		}
1230
-
1231
-		// checked, for radio and checkboxes
1232
-		if ( $args['checked'] ) {
1233
-			$output .= ' checked ';
1234
-		}
1235
-
1236
-		// data-attributes
1237
-		$output .= AUI_Component_Helper::data_attributes( $args );
1238
-
1239
-		// aria-attributes
1240
-		$output .= AUI_Component_Helper::aria_attributes( $args );
1241
-
1242
-		// extra attributes
1243
-		if ( ! empty( $args['extra_attributes'] ) ) {
1244
-			$output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
1245
-		}
1246
-
1247
-		// required
1248
-		if ( ! empty( $args['required'] ) ) {
1249
-			$output .= ' required ';
1250
-		}
1251
-
1252
-		// close opening tag
1253
-		$output .= ' >';
1254
-
1255
-		// label
1256
-		if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
1257
-		} elseif ( ! empty( $args['label'] ) ) {
1258
-			$output .= self::label( array(
1259
-				'title' => $args['label'],
1260
-				'for'   => $args['id'] . $count,
1261
-				'class' => 'form-check-label'
1262
-			), 'radio' );
1263
-		}
1264
-
1265
-		// wrap
1266
-		if ( ! $args['no_wrap'] ) {
1267
-			$wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check';
1268
-
1269
-			// Unique wrap class
1270
-			$uniq_class = 'fwrap';
1271
-			if ( ! empty( $args['name'] ) ) {
1272
-				$uniq_class .= '-' . $args['name'];
1273
-			} else if ( ! empty( $args['id'] ) ) {
1274
-				$uniq_class .= '-' . $args['id'];
1275
-			}
1276
-
1277
-			if ( isset( $args['value'] ) || $args['value'] !== "" ) {
1278
-				$uniq_class .= '-' . $args['value'];
1279
-			} else {
1280
-				$uniq_class .= '-' . $count;
1281
-			}
1282
-			$wrap_class .= ' ' . sanitize_html_class( $uniq_class );
1283
-
1284
-			$output = self::wrap( array(
1285
-				'content' => $output,
1286
-				'class'   => $wrap_class
1287
-			) );
1288
-		}
1289
-
1290
-		return $output;
1291
-	}
1050
+        // wrap
1051
+        if ( ! $args['no_wrap'] ) {
1052
+            if ( ! empty( $args['form_group_class'] ) ) {
1053
+                $fg_class = esc_attr( $args['form_group_class'] );
1054
+            }else{
1055
+                $fg_class = $aui_bs5 ? 'mb-3' : 'form-group';
1056
+            }
1057
+            $wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class;
1058
+            $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
1059
+            $output     = self::wrap( array(
1060
+                'content'         => $output,
1061
+                'class'           => $wrap_class,
1062
+                'element_require' => $args['element_require'],
1063
+                'argument_id'     => $args['id'],
1064
+                'wrap_attributes' => $args['wrap_attributes'],
1065
+            ) );
1066
+        }
1067
+
1068
+
1069
+        return $output;
1070
+    }
1071
+
1072
+    /**
1073
+     * Build the component.
1074
+     *
1075
+     * @param array $args
1076
+     *
1077
+     * @return string The rendered component.
1078
+     */
1079
+    public static function radio( $args = array() ) {
1080
+        global $aui_bs5;
1081
+
1082
+        $defaults = array(
1083
+            'class'            => '',
1084
+            'wrap_class'       => '',
1085
+            'id'               => '',
1086
+            'title'            => '',
1087
+            'horizontal'       => false,
1088
+            // sets the lable horizontal
1089
+            'value'            => '',
1090
+            'label'            => '',
1091
+            'label_class'      => '',
1092
+            'label_type'       => '',
1093
+            'label_col'        => '',
1094
+            // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
1095
+            'help_text'        => '',
1096
+            'inline'           => true,
1097
+            'required'         => false,
1098
+            'options'          => array(),
1099
+            'icon'             => '',
1100
+            'no_wrap'          => false,
1101
+            'element_require'  => '',
1102
+            // [%element_id%] == "1"
1103
+            'extra_attributes' => array(),
1104
+            // an array of extra attributes
1105
+            'wrap_attributes'  => array()
1106
+        );
1107
+
1108
+        /**
1109
+         * Parse incoming $args into an array and merge it with $defaults
1110
+         */
1111
+        $args = wp_parse_args( $args, $defaults );
1112
+
1113
+        // for now lets use horizontal for floating
1114
+        if ( $args['label_type'] == 'floating' ) {
1115
+            $args['label_type'] = 'horizontal';
1116
+        }
1117
+
1118
+        $label_args = array(
1119
+            'title'      => $args['label'],
1120
+            'class'      => $args['label_class'] . " pt-0 ",
1121
+            'label_type' => $args['label_type'],
1122
+            'label_col'  => $args['label_col']
1123
+        );
1124
+
1125
+        $output = '';
1126
+
1127
+
1128
+        // label before
1129
+        if ( ! empty( $args['label'] ) ) {
1130
+            $output .= self::label( $label_args, 'radio' );
1131
+        }
1132
+
1133
+        // maybe horizontal label
1134
+        if ( $args['label_type'] == 'horizontal' ) {
1135
+            $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' );
1136
+            $output .= '<div class="' . $input_col . '">';
1137
+        }
1138
+
1139
+        if ( ! empty( $args['options'] ) ) {
1140
+            $count = 0;
1141
+            foreach ( $args['options'] as $value => $label ) {
1142
+                $option_args            = $args;
1143
+                $option_args['value']   = $value;
1144
+                $option_args['label']   = $label;
1145
+                $option_args['checked'] = $value == $args['value'] ? true : false;
1146
+                $output .= self::radio_option( $option_args, $count );
1147
+                $count ++;
1148
+            }
1149
+        }
1150
+
1151
+        // help text
1152
+        $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : '';
1153
+        $output .= $help_text;
1154
+
1155
+        // maybe horizontal label
1156
+        if ( $args['label_type'] == 'horizontal' ) {
1157
+            $output .= '</div>';
1158
+        }
1159
+
1160
+        // wrap
1161
+        $fg_class = $aui_bs5 ? 'mb-3' : 'form-group';
1162
+        $wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class;
1163
+        $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class;
1164
+        $output     = self::wrap( array(
1165
+            'content'         => $output,
1166
+            'class'           => $wrap_class,
1167
+            'element_require' => $args['element_require'],
1168
+            'argument_id'     => $args['id'],
1169
+            'wrap_attributes' => $args['wrap_attributes'],
1170
+        ) );
1171
+
1172
+
1173
+        return $output;
1174
+    }
1175
+
1176
+    /**
1177
+     * Build the component.
1178
+     *
1179
+     * @param array $args
1180
+     *
1181
+     * @return string The rendered component.
1182
+     */
1183
+    public static function radio_option( $args = array(), $count = '' ) {
1184
+        $defaults = array(
1185
+            'class'            => '',
1186
+            'id'               => '',
1187
+            'title'            => '',
1188
+            'value'            => '',
1189
+            'required'         => false,
1190
+            'inline'           => true,
1191
+            'label'            => '',
1192
+            'options'          => array(),
1193
+            'icon'             => '',
1194
+            'no_wrap'          => false,
1195
+            'extra_attributes' => array() // an array of extra attributes
1196
+        );
1197
+
1198
+        /**
1199
+         * Parse incoming $args into an array and merge it with $defaults
1200
+         */
1201
+        $args = wp_parse_args( $args, $defaults );
1202
+
1203
+        $output = '';
1204
+
1205
+        // open/type
1206
+        $output .= '<input type="radio"';
1207
+
1208
+        // class
1209
+        $output .= ' class="form-check-input" ';
1210
+
1211
+        // name
1212
+        if ( ! empty( $args['name'] ) ) {
1213
+            $output .= AUI_Component_Helper::name( $args['name'] );
1214
+        }
1215
+
1216
+        // id
1217
+        if ( ! empty( $args['id'] ) ) {
1218
+            $output .= AUI_Component_Helper::id( $args['id'] . $count );
1219
+        }
1220
+
1221
+        // title
1222
+        if ( ! empty( $args['title'] ) ) {
1223
+            $output .= AUI_Component_Helper::title( $args['title'] );
1224
+        }
1225
+
1226
+        // value
1227
+        if ( isset( $args['value'] ) ) {
1228
+            $output .= AUI_Component_Helper::value( $args['value'] );
1229
+        }
1230
+
1231
+        // checked, for radio and checkboxes
1232
+        if ( $args['checked'] ) {
1233
+            $output .= ' checked ';
1234
+        }
1235
+
1236
+        // data-attributes
1237
+        $output .= AUI_Component_Helper::data_attributes( $args );
1238
+
1239
+        // aria-attributes
1240
+        $output .= AUI_Component_Helper::aria_attributes( $args );
1241
+
1242
+        // extra attributes
1243
+        if ( ! empty( $args['extra_attributes'] ) ) {
1244
+            $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] );
1245
+        }
1246
+
1247
+        // required
1248
+        if ( ! empty( $args['required'] ) ) {
1249
+            $output .= ' required ';
1250
+        }
1251
+
1252
+        // close opening tag
1253
+        $output .= ' >';
1254
+
1255
+        // label
1256
+        if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) {
1257
+        } elseif ( ! empty( $args['label'] ) ) {
1258
+            $output .= self::label( array(
1259
+                'title' => $args['label'],
1260
+                'for'   => $args['id'] . $count,
1261
+                'class' => 'form-check-label'
1262
+            ), 'radio' );
1263
+        }
1264
+
1265
+        // wrap
1266
+        if ( ! $args['no_wrap'] ) {
1267
+            $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check';
1268
+
1269
+            // Unique wrap class
1270
+            $uniq_class = 'fwrap';
1271
+            if ( ! empty( $args['name'] ) ) {
1272
+                $uniq_class .= '-' . $args['name'];
1273
+            } else if ( ! empty( $args['id'] ) ) {
1274
+                $uniq_class .= '-' . $args['id'];
1275
+            }
1276
+
1277
+            if ( isset( $args['value'] ) || $args['value'] !== "" ) {
1278
+                $uniq_class .= '-' . $args['value'];
1279
+            } else {
1280
+                $uniq_class .= '-' . $count;
1281
+            }
1282
+            $wrap_class .= ' ' . sanitize_html_class( $uniq_class );
1283
+
1284
+            $output = self::wrap( array(
1285
+                'content' => $output,
1286
+                'class'   => $wrap_class
1287
+            ) );
1288
+        }
1289
+
1290
+        return $output;
1291
+    }
1292 1292
 
1293 1293
 }
1294 1294
\ No newline at end of file
Please login to merge, or discard this patch.
vendor/ayecode/wp-ayecode-ui/includes/inc/bs-conversion.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -14,57 +14,57 @@
 block discarded – undo
14 14
  * @return array|mixed|string|string[]
15 15
  */
16 16
 function aui_bs_convert_sd_output( $output, $instance = '', $args = '', $sd = '' ) {
17
-	global $aui_bs5;
17
+    global $aui_bs5;
18 18
 
19
-	if ( $aui_bs5 ) {
19
+    if ( $aui_bs5 ) {
20 20
 
21
-		$convert = array(
22
-			'ml-'                   => 'ms-',
23
-			'mr-'                   => 'me-',
24
-			'pl-'                   => 'ps-',
25
-			'pr-'                   => 'pe-',
26
-			' form-row'              => ' row',
27
-			' embed-responsive-item' => '',
28
-			' embed-responsive' => ' ratio',
29
-			'-1by1'    => '-1x1',
30
-			'-4by3'    => '-4x3',
31
-			'-16by9'    => '-16x9',
32
-			'-21by9'    => '-21x9',
33
-			'geodir-lightbox-image' => 'aui-lightbox-image',
34
-			' badge-'   => ' text-bg-',
35
-			'form-group'   => 'mb-3',
36
-			'custom-select'   => 'form-select',
37
-			'float-left'   => 'float-start',
38
-			'float-right'   => 'float-end',
39
-			'text-left'    => 'text-start',
40
-			'text-right'    => 'text-end',
41
-			'border-right'    => 'border-end',
42
-			'border-left'    => 'border-start',
43
-			'font-weight-'  => 'fw-',
44
-			'btn-block'     => 'w-100',
45
-			'rounded-left'  => 'rounded-start',
46
-			'rounded-right'  => 'rounded-end',
21
+        $convert = array(
22
+            'ml-'                   => 'ms-',
23
+            'mr-'                   => 'me-',
24
+            'pl-'                   => 'ps-',
25
+            'pr-'                   => 'pe-',
26
+            ' form-row'              => ' row',
27
+            ' embed-responsive-item' => '',
28
+            ' embed-responsive' => ' ratio',
29
+            '-1by1'    => '-1x1',
30
+            '-4by3'    => '-4x3',
31
+            '-16by9'    => '-16x9',
32
+            '-21by9'    => '-21x9',
33
+            'geodir-lightbox-image' => 'aui-lightbox-image',
34
+            ' badge-'   => ' text-bg-',
35
+            'form-group'   => 'mb-3',
36
+            'custom-select'   => 'form-select',
37
+            'float-left'   => 'float-start',
38
+            'float-right'   => 'float-end',
39
+            'text-left'    => 'text-start',
40
+            'text-right'    => 'text-end',
41
+            'border-right'    => 'border-end',
42
+            'border-left'    => 'border-start',
43
+            'font-weight-'  => 'fw-',
44
+            'btn-block'     => 'w-100',
45
+            'rounded-left'  => 'rounded-start',
46
+            'rounded-right'  => 'rounded-end',
47 47
 
48 48
 //			'custom-control custom-checkbox'    => 'form-check',
49
-			// data
50
-			' data-toggle=' => ' data-bs-toggle=',
51
-			'data-ride=' => 'data-bs-ride=',
52
-			'data-controlnav=' => 'data-bs-controlnav=',
53
-			'data-slide='   => 'data-bs-slide=',
54
-			'data-slide-to=' => 'data-bs-slide-to=',
55
-			'data-target='  => 'data-bs-target=',
56
-			'data-dismiss="modal"'  => 'data-bs-dismiss="modal"',
57
-			'class="close"' => 'class="btn-close"',
58
-			'<span aria-hidden="true">&times;</span>' => '',
59
-		);
60
-		$output  = str_replace(
61
-			array_keys( $convert ),
62
-			array_values( $convert ),
63
-			$output
64
-		);
65
-	}
49
+            // data
50
+            ' data-toggle=' => ' data-bs-toggle=',
51
+            'data-ride=' => 'data-bs-ride=',
52
+            'data-controlnav=' => 'data-bs-controlnav=',
53
+            'data-slide='   => 'data-bs-slide=',
54
+            'data-slide-to=' => 'data-bs-slide-to=',
55
+            'data-target='  => 'data-bs-target=',
56
+            'data-dismiss="modal"'  => 'data-bs-dismiss="modal"',
57
+            'class="close"' => 'class="btn-close"',
58
+            '<span aria-hidden="true">&times;</span>' => '',
59
+        );
60
+        $output  = str_replace(
61
+            array_keys( $convert ),
62
+            array_values( $convert ),
63
+            $output
64
+        );
65
+    }
66 66
 
67
-	return $output;
67
+    return $output;
68 68
 }
69 69
 
70 70
 add_filter( 'wp_super_duper_widget_output', 'aui_bs_convert_sd_output', 10, 4 ); //$output, $instance, $args, $this
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-payment-gateway.php 1 patch
Indentation   +615 added lines, -615 removed lines patch added patch discarded remove patch
@@ -13,464 +13,464 @@  discard block
 block discarded – undo
13 13
  */
14 14
 abstract class GetPaid_Payment_Gateway {
15 15
 
16
-	/**
17
-	 * Set if the place checkout button should be renamed on selection.
18
-	 *
19
-	 * @var string
20
-	 */
21
-	public $checkout_button_text;
22
-
23
-	/**
24
-	 * Boolean whether the method is enabled.
25
-	 *
26
-	 * @var bool
27
-	 */
28
-	public $enabled = true;
29
-
30
-	/**
31
-	 * Payment method id.
32
-	 *
33
-	 * @var string
34
-	 */
35
-	public $id;
36
-
37
-	/**
38
-	 * Payment method order.
39
-	 *
40
-	 * @var int
41
-	 */
42
-	public $order = 10;
43
-
44
-	/**
45
-	 * Payment method title for the frontend.
46
-	 *
47
-	 * @var string
48
-	 */
49
-	public $title;
50
-
51
-	/**
52
-	 * Payment method description for the frontend.
53
-	 *
54
-	 * @var string
55
-	 */
56
-	public $description;
57
-
58
-	/**
59
-	 * Gateway title.
60
-	 *
61
-	 * @var string
62
-	 */
63
-	public $method_title = '';
64
-
65
-	/**
66
-	 * Gateway description.
67
-	 *
68
-	 * @var string
69
-	 */
70
-	public $method_description = '';
71
-
72
-	/**
73
-	 * Countries this gateway is allowed for.
74
-	 *
75
-	 * @var array
76
-	 */
77
-	public $countries;
78
-
79
-	/**
80
-	 * Currencies this gateway is allowed for.
81
-	 *
82
-	 * @var array
83
-	 */
84
-	public $currencies;
85
-
86
-	/**
87
-	 * Currencies this gateway is not allowed for.
88
-	 *
89
-	 * @var array
90
-	 */
91
-	public $exclude_currencies;
92
-
93
-	/**
94
-	 * Maximum transaction amount, zero does not define a maximum.
95
-	 *
96
-	 * @var int
97
-	 */
98
-	public $max_amount = 0;
99
-
100
-	/**
101
-	 * Optional URL to view a transaction.
102
-	 *
103
-	 * @var string
104
-	 */
105
-	public $view_transaction_url = '';
106
-
107
-	/**
108
-	 * Optional URL to view a subscription.
109
-	 *
110
-	 * @var string
111
-	 */
112
-	public $view_subscription_url = '';
113
-
114
-	/**
115
-	 * Optional label to show for "new payment method" in the payment
116
-	 * method/token selection radio selection.
117
-	 *
118
-	 * @var string
119
-	 */
120
-	public $new_method_label = '';
121
-
122
-	/**
123
-	 * Contains a user's saved tokens for this gateway.
124
-	 *
125
-	 * @var array
126
-	 */
127
-	protected $tokens = array();
128
-
129
-	/**
130
-	 * An array of features that this gateway supports.
131
-	 *
132
-	 * @var array
133
-	 */
134
-	protected $supports = array();
135
-
136
-	/**
137
-	 * Class constructor.
138
-	 */
139
-	public function __construct() {
140
-
141
-		do_action( 'getpaid_before_init_payment_gateway_' . $this->id, $this );
142
-
143
-		// Register gateway.
144
-		add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) );
145
-
146
-		$this->enabled = wpinv_is_gateway_active( $this->id );
147
-
148
-		// Add support for various features.
149
-		foreach ( $this->supports as $feature ) {
150
-			add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' );
151
-			add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' );
152
-			add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' );
153
-		}
154
-
155
-		// Invoice addons.
156
-		if ( $this->supports( 'addons' ) ) {
157
-			add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 );
158
-		}
159
-
160
-		// Gateway settings.
161
-		add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) );
162
-
163
-		// Gateway checkout fiellds.
164
-		add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 );
165
-
166
-		// Process payment.
167
-		add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 );
168
-
169
-		// Change the checkout button text.
170
-		if ( ! empty( $this->checkout_button_text ) ) {
171
-			add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) );
172
-		}
173
-
174
-		// Check if a gateway is valid for a given currency.
175
-		add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 );
176
-
177
-		// Generate the transaction url.
178
-		add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 );
179
-
180
-		// Generate the subscription url.
181
-		add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 );
182
-
183
-		// Confirm payments.
184
-		add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 );
185
-
186
-		// Verify IPNs.
187
-		add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) );
188
-
189
-	}
190
-
191
-	/**
192
-	 * Checks if this gateway is a given gateway.
193
-	 *
194
-	 * @since 1.0.19
195
-	 * @return bool
196
-	 */
197
-	public function is( $gateway ) {
198
-		return $gateway == $this->id;
199
-	}
200
-
201
-	/**
202
-	 * Returns a users saved tokens for this gateway.
203
-	 *
204
-	 * @since 1.0.19
205
-	 * @return array
206
-	 */
207
-	public function get_tokens( $sandbox = null ) {
208
-
209
-		if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) {
210
-			$tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true );
211
-
212
-			if ( is_array( $tokens ) ) {
213
-				$this->tokens = $tokens;
214
-			}
16
+    /**
17
+     * Set if the place checkout button should be renamed on selection.
18
+     *
19
+     * @var string
20
+     */
21
+    public $checkout_button_text;
22
+
23
+    /**
24
+     * Boolean whether the method is enabled.
25
+     *
26
+     * @var bool
27
+     */
28
+    public $enabled = true;
29
+
30
+    /**
31
+     * Payment method id.
32
+     *
33
+     * @var string
34
+     */
35
+    public $id;
36
+
37
+    /**
38
+     * Payment method order.
39
+     *
40
+     * @var int
41
+     */
42
+    public $order = 10;
43
+
44
+    /**
45
+     * Payment method title for the frontend.
46
+     *
47
+     * @var string
48
+     */
49
+    public $title;
50
+
51
+    /**
52
+     * Payment method description for the frontend.
53
+     *
54
+     * @var string
55
+     */
56
+    public $description;
57
+
58
+    /**
59
+     * Gateway title.
60
+     *
61
+     * @var string
62
+     */
63
+    public $method_title = '';
64
+
65
+    /**
66
+     * Gateway description.
67
+     *
68
+     * @var string
69
+     */
70
+    public $method_description = '';
71
+
72
+    /**
73
+     * Countries this gateway is allowed for.
74
+     *
75
+     * @var array
76
+     */
77
+    public $countries;
78
+
79
+    /**
80
+     * Currencies this gateway is allowed for.
81
+     *
82
+     * @var array
83
+     */
84
+    public $currencies;
85
+
86
+    /**
87
+     * Currencies this gateway is not allowed for.
88
+     *
89
+     * @var array
90
+     */
91
+    public $exclude_currencies;
92
+
93
+    /**
94
+     * Maximum transaction amount, zero does not define a maximum.
95
+     *
96
+     * @var int
97
+     */
98
+    public $max_amount = 0;
99
+
100
+    /**
101
+     * Optional URL to view a transaction.
102
+     *
103
+     * @var string
104
+     */
105
+    public $view_transaction_url = '';
106
+
107
+    /**
108
+     * Optional URL to view a subscription.
109
+     *
110
+     * @var string
111
+     */
112
+    public $view_subscription_url = '';
113
+
114
+    /**
115
+     * Optional label to show for "new payment method" in the payment
116
+     * method/token selection radio selection.
117
+     *
118
+     * @var string
119
+     */
120
+    public $new_method_label = '';
121
+
122
+    /**
123
+     * Contains a user's saved tokens for this gateway.
124
+     *
125
+     * @var array
126
+     */
127
+    protected $tokens = array();
128
+
129
+    /**
130
+     * An array of features that this gateway supports.
131
+     *
132
+     * @var array
133
+     */
134
+    protected $supports = array();
135
+
136
+    /**
137
+     * Class constructor.
138
+     */
139
+    public function __construct() {
140
+
141
+        do_action( 'getpaid_before_init_payment_gateway_' . $this->id, $this );
142
+
143
+        // Register gateway.
144
+        add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) );
145
+
146
+        $this->enabled = wpinv_is_gateway_active( $this->id );
147
+
148
+        // Add support for various features.
149
+        foreach ( $this->supports as $feature ) {
150
+            add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' );
151
+            add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' );
152
+            add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' );
153
+        }
154
+
155
+        // Invoice addons.
156
+        if ( $this->supports( 'addons' ) ) {
157
+            add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 );
158
+        }
159
+
160
+        // Gateway settings.
161
+        add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) );
162
+
163
+        // Gateway checkout fiellds.
164
+        add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 );
165
+
166
+        // Process payment.
167
+        add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 );
168
+
169
+        // Change the checkout button text.
170
+        if ( ! empty( $this->checkout_button_text ) ) {
171
+            add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) );
172
+        }
173
+
174
+        // Check if a gateway is valid for a given currency.
175
+        add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 );
176
+
177
+        // Generate the transaction url.
178
+        add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 );
179
+
180
+        // Generate the subscription url.
181
+        add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 );
182
+
183
+        // Confirm payments.
184
+        add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 );
185
+
186
+        // Verify IPNs.
187
+        add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) );
188
+
189
+    }
190
+
191
+    /**
192
+     * Checks if this gateway is a given gateway.
193
+     *
194
+     * @since 1.0.19
195
+     * @return bool
196
+     */
197
+    public function is( $gateway ) {
198
+        return $gateway == $this->id;
199
+    }
200
+
201
+    /**
202
+     * Returns a users saved tokens for this gateway.
203
+     *
204
+     * @since 1.0.19
205
+     * @return array
206
+     */
207
+    public function get_tokens( $sandbox = null ) {
208
+
209
+        if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) {
210
+            $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true );
211
+
212
+            if ( is_array( $tokens ) ) {
213
+                $this->tokens = $tokens;
214
+            }
215 215
 }
216 216
 
217
-		if ( ! is_bool( $sandbox ) ) {
218
-			return $this->tokens;
219
-		}
220
-
221
-		// Filter tokens.
222
-		$args = array( 'type' => $sandbox ? 'sandbox' : 'live' );
223
-		return wp_list_filter( $this->tokens, $args );
224
-
225
-	}
226
-
227
-	/**
228
-	 * Saves a token for this gateway.
229
-	 *
230
-	 * @since 1.0.19
231
-	 */
232
-	public function save_token( $token ) {
233
-
234
-		$tokens   = $this->get_tokens();
235
-		$tokens[] = $token;
236
-
237
-		update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens );
238
-
239
-		$this->tokens = $tokens;
240
-
241
-	}
242
-
243
-	/**
244
-	 * Return the title for admin screens.
245
-	 *
246
-	 * @return string
247
-	 */
248
-	public function get_method_title() {
249
-		return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this );
250
-	}
251
-
252
-	/**
253
-	 * Return the description for admin screens.
254
-	 *
255
-	 * @return string
256
-	 */
257
-	public function get_method_description() {
258
-		return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this );
259
-	}
260
-
261
-	/**
262
-	 * Get the success url.
263
-	 *
264
-	 * @param WPInv_Invoice $invoice Invoice object.
265
-	 * @return string
266
-	 */
267
-	public function get_return_url( $invoice ) {
268
-
269
-		// Payment success url
270
-		$return_url = add_query_arg(
271
-			array(
272
-				'payment-confirm' => $this->id,
273
-				'invoice_key'     => $invoice->get_key(),
274
-				'utm_nooverride'  => 1,
275
-			),
276
-			wpinv_get_success_page_uri()
277
-		);
278
-
279
-		return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this );
280
-	}
281
-
282
-	/**
283
-	 * Confirms payments when rendering the success page.
284
-	 *
285
-	 * @param string $content Success page content.
286
-	 * @return string
287
-	 */
288
-	public function confirm_payment( $content ) {
289
-
290
-		// Retrieve the invoice.
291
-		$invoice_id = getpaid_get_current_invoice_id();
292
-		$invoice    = wpinv_get_invoice( $invoice_id );
293
-
294
-		// Ensure that it exists and that it is pending payment.
295
-		if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) {
296
-			return $content;
297
-		}
298
-
299
-		// Can the user view this invoice??
300
-		if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
301
-			return $content;
302
-		}
303
-
304
-		// Show payment processing indicator.
305
-		return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
306
-	}
307
-
308
-	/**
309
-	 * Processes ipns and marks payments as complete.
310
-	 *
311
-	 * @return void
312
-	 */
313
-	public function verify_ipn() {}
314
-
315
-	/**
316
-	 * Processes invoice addons.
317
-	 *
318
-	 * @param WPInv_Invoice $invoice
319
-	 * @param GetPaid_Form_Item[] $items
320
-	 * @return WPInv_Invoice
321
-	 */
322
-	public function process_addons( $invoice, $items ) {
323
-
324
-	}
325
-
326
-	/**
327
-	 * Get a link to the transaction on the 3rd party gateway site (if applicable).
328
-	 *
329
-	 * @param string $transaction_url transaction url.
330
-	 * @param WPInv_Invoice $invoice Invoice object.
331
-	 * @return string transaction URL, or empty string.
332
-	 */
333
-	public function filter_transaction_url( $transaction_url, $invoice ) {
334
-
335
-		$transaction_id  = $invoice->get_transaction_id();
336
-
337
-		if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
338
-			$transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
339
-			$replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
340
-			$transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
341
-		}
342
-
343
-		return $transaction_url;
344
-	}
345
-
346
-	/**
347
-	 * Get a link to the subscription on the 3rd party gateway site (if applicable).
348
-	 *
349
-	 * @param string $subscription_url transaction url.
350
-	 * @param WPInv_Subscription $subscription Subscription objectt.
351
-	 * @return string subscription URL, or empty string.
352
-	 */
353
-	public function generate_subscription_url( $subscription_url, $subscription ) {
354
-
355
-		$profile_id      = $subscription->get_profile_id();
356
-
357
-		if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
358
-
359
-			$subscription_url = sprintf( $this->view_subscription_url, $profile_id );
360
-			$replace          = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : '';
361
-			$subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
362
-
363
-		}
364
-
365
-		return $subscription_url;
366
-	}
367
-
368
-	/**
369
-	 * Check if the gateway is available for use.
370
-	 *
371
-	 * @return bool
372
-	 */
373
-	public function is_available() {
374
-		return ! empty( $this->enabled );
375
-	}
376
-
377
-	/**
378
-	 * Return the gateway's title.
379
-	 *
380
-	 * @return string
381
-	 */
382
-	public function get_title() {
383
-		return apply_filters( 'getpaid_gateway_title', $this->title, $this );
384
-	}
385
-
386
-	/**
387
-	 * Return the gateway's description.
388
-	 *
389
-	 * @return string
390
-	 */
391
-	public function get_description() {
392
-		return apply_filters( 'getpaid_gateway_description', $this->description, $this );
393
-	}
394
-
395
-	/**
396
-	 * Process Payment.
397
-	 *
398
-	 *
399
-	 * @param WPInv_Invoice $invoice Invoice.
400
-	 * @param array $submission_data Posted checkout fields.
401
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
402
-	 * @return void
403
-	 */
404
-	public function process_payment( $invoice, $submission_data, $submission ) {
405
-		// Process the payment then either redirect to the success page or the gateway.
406
-		do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission );
407
-	}
408
-
409
-	/**
410
-	 * Process refund.
411
-	 *
412
-	 * If the gateway declares 'refunds' support, this will allow it to refund.
413
-	 * a passed in amount.
414
-	 *
415
-	 * @param WPInv_Invoice $invoice Invoice.
416
-	 * @param  float  $amount Refund amount.
417
-	 * @param  string $reason Refund reason.
418
-	 * @return WP_Error|bool True or false based on success, or a WP_Error object.
419
-	 */
420
-	public function process_refund( $invoice, $amount = null, $reason = '' ) {
421
-		return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason );
422
-	}
423
-
424
-	/**
425
-	 * Displays the payment fields, credit cards etc.
426
-	 *
427
-	 * @param int $invoice_id 0 or invoice id.
428
-	 * @param GetPaid_Payment_Form $form Current payment form.
429
-	 */
430
-	public function payment_fields( $invoice_id, $form ) {
431
-		do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form );
432
-	}
433
-
434
-	/**
435
-	 * Filters the gateway settings.
436
-	 *
437
-	 * @param array $admin_settings
438
-	 */
439
-	public function admin_settings( $admin_settings ) {
440
-		return $admin_settings;
441
-	}
442
-
443
-	/**
444
-	 * Retrieves the value of a gateway setting.
445
-	 *
446
-	 * @param string $option
447
-	 */
448
-	public function get_option( $option, $default = false ) {
449
-		return wpinv_get_option( $this->id . '_' . $option, $default );
450
-	}
451
-
452
-	/**
453
-	 * Check if a gateway supports a given feature.
454
-	 *
455
-	 * Gateways should override this to declare support (or lack of support) for a feature.
456
-	 * For backward compatibility, gateways support 'products' by default, but nothing else.
457
-	 *
458
-	 * @param string $feature string The name of a feature to test support for.
459
-	 * @return bool True if the gateway supports the feature, false otherwise.
460
-	 * @since 1.0.19
461
-	 */
462
-	public function supports( $feature ) {
463
-		return getpaid_payment_gateway_supports( $this->id, $feature );
464
-	}
465
-
466
-	/**
467
-	 * Returns the credit card form html.
468
-	 *
469
-	 * @param bool $save whether or not to display the save button.
470
-	 */
217
+        if ( ! is_bool( $sandbox ) ) {
218
+            return $this->tokens;
219
+        }
220
+
221
+        // Filter tokens.
222
+        $args = array( 'type' => $sandbox ? 'sandbox' : 'live' );
223
+        return wp_list_filter( $this->tokens, $args );
224
+
225
+    }
226
+
227
+    /**
228
+     * Saves a token for this gateway.
229
+     *
230
+     * @since 1.0.19
231
+     */
232
+    public function save_token( $token ) {
233
+
234
+        $tokens   = $this->get_tokens();
235
+        $tokens[] = $token;
236
+
237
+        update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens );
238
+
239
+        $this->tokens = $tokens;
240
+
241
+    }
242
+
243
+    /**
244
+     * Return the title for admin screens.
245
+     *
246
+     * @return string
247
+     */
248
+    public function get_method_title() {
249
+        return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this );
250
+    }
251
+
252
+    /**
253
+     * Return the description for admin screens.
254
+     *
255
+     * @return string
256
+     */
257
+    public function get_method_description() {
258
+        return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this );
259
+    }
260
+
261
+    /**
262
+     * Get the success url.
263
+     *
264
+     * @param WPInv_Invoice $invoice Invoice object.
265
+     * @return string
266
+     */
267
+    public function get_return_url( $invoice ) {
268
+
269
+        // Payment success url
270
+        $return_url = add_query_arg(
271
+            array(
272
+                'payment-confirm' => $this->id,
273
+                'invoice_key'     => $invoice->get_key(),
274
+                'utm_nooverride'  => 1,
275
+            ),
276
+            wpinv_get_success_page_uri()
277
+        );
278
+
279
+        return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this );
280
+    }
281
+
282
+    /**
283
+     * Confirms payments when rendering the success page.
284
+     *
285
+     * @param string $content Success page content.
286
+     * @return string
287
+     */
288
+    public function confirm_payment( $content ) {
289
+
290
+        // Retrieve the invoice.
291
+        $invoice_id = getpaid_get_current_invoice_id();
292
+        $invoice    = wpinv_get_invoice( $invoice_id );
293
+
294
+        // Ensure that it exists and that it is pending payment.
295
+        if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) {
296
+            return $content;
297
+        }
298
+
299
+        // Can the user view this invoice??
300
+        if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
301
+            return $content;
302
+        }
303
+
304
+        // Show payment processing indicator.
305
+        return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
306
+    }
307
+
308
+    /**
309
+     * Processes ipns and marks payments as complete.
310
+     *
311
+     * @return void
312
+     */
313
+    public function verify_ipn() {}
314
+
315
+    /**
316
+     * Processes invoice addons.
317
+     *
318
+     * @param WPInv_Invoice $invoice
319
+     * @param GetPaid_Form_Item[] $items
320
+     * @return WPInv_Invoice
321
+     */
322
+    public function process_addons( $invoice, $items ) {
323
+
324
+    }
325
+
326
+    /**
327
+     * Get a link to the transaction on the 3rd party gateway site (if applicable).
328
+     *
329
+     * @param string $transaction_url transaction url.
330
+     * @param WPInv_Invoice $invoice Invoice object.
331
+     * @return string transaction URL, or empty string.
332
+     */
333
+    public function filter_transaction_url( $transaction_url, $invoice ) {
334
+
335
+        $transaction_id  = $invoice->get_transaction_id();
336
+
337
+        if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
338
+            $transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
339
+            $replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
340
+            $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
341
+        }
342
+
343
+        return $transaction_url;
344
+    }
345
+
346
+    /**
347
+     * Get a link to the subscription on the 3rd party gateway site (if applicable).
348
+     *
349
+     * @param string $subscription_url transaction url.
350
+     * @param WPInv_Subscription $subscription Subscription objectt.
351
+     * @return string subscription URL, or empty string.
352
+     */
353
+    public function generate_subscription_url( $subscription_url, $subscription ) {
354
+
355
+        $profile_id      = $subscription->get_profile_id();
356
+
357
+        if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
358
+
359
+            $subscription_url = sprintf( $this->view_subscription_url, $profile_id );
360
+            $replace          = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : '';
361
+            $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
362
+
363
+        }
364
+
365
+        return $subscription_url;
366
+    }
367
+
368
+    /**
369
+     * Check if the gateway is available for use.
370
+     *
371
+     * @return bool
372
+     */
373
+    public function is_available() {
374
+        return ! empty( $this->enabled );
375
+    }
376
+
377
+    /**
378
+     * Return the gateway's title.
379
+     *
380
+     * @return string
381
+     */
382
+    public function get_title() {
383
+        return apply_filters( 'getpaid_gateway_title', $this->title, $this );
384
+    }
385
+
386
+    /**
387
+     * Return the gateway's description.
388
+     *
389
+     * @return string
390
+     */
391
+    public function get_description() {
392
+        return apply_filters( 'getpaid_gateway_description', $this->description, $this );
393
+    }
394
+
395
+    /**
396
+     * Process Payment.
397
+     *
398
+     *
399
+     * @param WPInv_Invoice $invoice Invoice.
400
+     * @param array $submission_data Posted checkout fields.
401
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
402
+     * @return void
403
+     */
404
+    public function process_payment( $invoice, $submission_data, $submission ) {
405
+        // Process the payment then either redirect to the success page or the gateway.
406
+        do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission );
407
+    }
408
+
409
+    /**
410
+     * Process refund.
411
+     *
412
+     * If the gateway declares 'refunds' support, this will allow it to refund.
413
+     * a passed in amount.
414
+     *
415
+     * @param WPInv_Invoice $invoice Invoice.
416
+     * @param  float  $amount Refund amount.
417
+     * @param  string $reason Refund reason.
418
+     * @return WP_Error|bool True or false based on success, or a WP_Error object.
419
+     */
420
+    public function process_refund( $invoice, $amount = null, $reason = '' ) {
421
+        return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason );
422
+    }
423
+
424
+    /**
425
+     * Displays the payment fields, credit cards etc.
426
+     *
427
+     * @param int $invoice_id 0 or invoice id.
428
+     * @param GetPaid_Payment_Form $form Current payment form.
429
+     */
430
+    public function payment_fields( $invoice_id, $form ) {
431
+        do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form );
432
+    }
433
+
434
+    /**
435
+     * Filters the gateway settings.
436
+     *
437
+     * @param array $admin_settings
438
+     */
439
+    public function admin_settings( $admin_settings ) {
440
+        return $admin_settings;
441
+    }
442
+
443
+    /**
444
+     * Retrieves the value of a gateway setting.
445
+     *
446
+     * @param string $option
447
+     */
448
+    public function get_option( $option, $default = false ) {
449
+        return wpinv_get_option( $this->id . '_' . $option, $default );
450
+    }
451
+
452
+    /**
453
+     * Check if a gateway supports a given feature.
454
+     *
455
+     * Gateways should override this to declare support (or lack of support) for a feature.
456
+     * For backward compatibility, gateways support 'products' by default, but nothing else.
457
+     *
458
+     * @param string $feature string The name of a feature to test support for.
459
+     * @return bool True if the gateway supports the feature, false otherwise.
460
+     * @since 1.0.19
461
+     */
462
+    public function supports( $feature ) {
463
+        return getpaid_payment_gateway_supports( $this->id, $feature );
464
+    }
465
+
466
+    /**
467
+     * Returns the credit card form html.
468
+     *
469
+     * @param bool $save whether or not to display the save button.
470
+     */
471 471
     public function get_cc_form( $save = false ) {
472 472
 
473
-		ob_start();
473
+        ob_start();
474 474
 
475 475
         $id_prefix = esc_attr( uniqid( $this->id ) );
476 476
 
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
             '11' => __( 'November', 'invoicing' ),
489 489
             '12' => __( 'December', 'invoicing' ),
490 490
         );
491
-		$months = apply_filters( 'getpaid_cc_months', $months, $this );
491
+        $months = apply_filters( 'getpaid_cc_months', $months, $this );
492 492
 
493 493
         $year  = (int) current_time( 'Y' );
494 494
         $years = array();
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
             $years[ $year + $i ] = $year + $i;
498 498
         }
499 499
 
500
-		$years = apply_filters( 'getpaid_cc_years', $years, $this );
500
+        $years = apply_filters( 'getpaid_cc_years', $years, $this );
501 501
 
502 502
         ?>
503 503
             <div class="<?php echo esc_attr( $this->id ); ?>-cc-form getpaid-cc-form mt-1">
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
 
540 540
                                             <?php
541 541
                                                 foreach ( $months as $key => $month ) {
542
-												echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $month ) . '</option>';
542
+                                                echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $month ) . '</option>';
543 543
                                                 }
544 544
                                             ?>
545 545
 
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
 
553 553
                                             <?php
554 554
                                                 foreach ( $years as $key => $year ) {
555
-												echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $year ) . '</option>';
555
+                                                echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $year ) . '</option>';
556 556
                                                 }
557 557
                                             ?>
558 558
 
@@ -570,13 +570,13 @@  discard block
 block discarded – undo
570 570
                                         'name'             => $this->id . '[cc_cvv2]',
571 571
                                         'id'               => "$id_prefix-cc-cvv2",
572 572
                                         'label'            => __( 'CCV', 'invoicing' ),
573
-										'label_type'       => 'vertical',
574
-										'class'            => 'form-control-sm',
575
-										'extra_attributes' => array(
576
-											'autocomplete' => 'cc-csc',
577
-										),
573
+                                        'label_type'       => 'vertical',
574
+                                        'class'            => 'form-control-sm',
575
+                                        'extra_attributes' => array(
576
+                                            'autocomplete' => 'cc-csc',
577
+                                        ),
578 578
                                     ),
579
-									true
579
+                                    true
580 580
                                 );
581 581
                             ?>
582 582
                         </div>
@@ -585,192 +585,192 @@  discard block
 block discarded – undo
585 585
 
586 586
 					<?php
587 587
 
588
-						if ( $save ) {
589
-							$this->save_payment_method_checkbox();
590
-						}
588
+                        if ( $save ) {
589
+                            $this->save_payment_method_checkbox();
590
+                        }
591 591
 
592
-					?>
592
+                    ?>
593 593
                 </div>
594 594
 
595 595
             </div>
596 596
 		<?php
597 597
 
598
-		return ob_get_clean();
598
+        return ob_get_clean();
599
+
600
+    }
601
+
602
+    /**
603
+     * Displays a new payment method entry form.
604
+     *
605
+     * @since 1.0.19
606
+     */
607
+    public function new_payment_method_entry( $form ) {
608
+        echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses( $form, getpaid_allowed_html() ) . '</div>';
609
+    }
610
+
611
+    /**
612
+     * Grab and display our saved payment methods.
613
+     *
614
+     * @since 1.0.19
615
+     */
616
+    public function saved_payment_methods() {
617
+        echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">';
618
+
619
+        foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) {
620
+            $this->get_saved_payment_method_option_html( $token );
621
+        }
622
+
623
+        $this->get_new_payment_method_option_html();
624
+        echo '</ul>';
599 625
 
600 626
     }
601 627
 
602
-	/**
603
-	 * Displays a new payment method entry form.
604
-	 *
605
-	 * @since 1.0.19
606
-	 */
607
-	public function new_payment_method_entry( $form ) {
608
-		echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses( $form, getpaid_allowed_html() ) . '</div>';
609
-	}
610
-
611
-	/**
612
-	 * Grab and display our saved payment methods.
613
-	 *
614
-	 * @since 1.0.19
615
-	 */
616
-	public function saved_payment_methods() {
617
-		echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">';
618
-
619
-		foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) {
620
-			$this->get_saved_payment_method_option_html( $token );
621
-		}
622
-
623
-		$this->get_new_payment_method_option_html();
624
-		echo '</ul>';
625
-
626
-	}
627
-
628
-	/**
629
-	 * Gets saved payment method HTML from a token.
630
-	 *
631
-	 * @since 1.0.19
632
-	 * @param  array $token Payment Token.
633
-	 * @return string Generated payment method HTML
634
-	 */
635
-	public function get_saved_payment_method_option_html( $token ) {
636
-
637
-		printf(
638
-			'<li class="getpaid-payment-method form-group mb-3">
628
+    /**
629
+     * Gets saved payment method HTML from a token.
630
+     *
631
+     * @since 1.0.19
632
+     * @param  array $token Payment Token.
633
+     * @return string Generated payment method HTML
634
+     */
635
+    public function get_saved_payment_method_option_html( $token ) {
636
+
637
+        printf(
638
+            '<li class="getpaid-payment-method form-group mb-3">
639 639
 				<label>
640 640
 					<input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" data-currency="%5$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s />
641 641
 					<span>%3$s</span>
642 642
 				</label>
643 643
 			</li>',
644
-			esc_attr( $this->id ),
645
-			esc_attr( $token['id'] ),
646
-			esc_html( $token['name'] ),
647
-			checked( empty( $token['default'] ), false, false ),
648
-			empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] )
649
-		);
650
-
651
-	}
652
-
653
-	/**
654
-	 * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method.
655
-	 *
656
-	 * @since 1.0.19
657
-	 */
658
-	public function get_new_payment_method_option_html() {
659
-
660
-		$label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
661
-
662
-		printf(
663
-			'<li class="getpaid-new-payment-method">
644
+            esc_attr( $this->id ),
645
+            esc_attr( $token['id'] ),
646
+            esc_html( $token['name'] ),
647
+            checked( empty( $token['default'] ), false, false ),
648
+            empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] )
649
+        );
650
+
651
+    }
652
+
653
+    /**
654
+     * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method.
655
+     *
656
+     * @since 1.0.19
657
+     */
658
+    public function get_new_payment_method_option_html() {
659
+
660
+        $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
661
+
662
+        printf(
663
+            '<li class="getpaid-new-payment-method">
664 664
 				<label>
665 665
 					<input name="getpaid-%1$s-payment-method" type="radio" data-currency="none" value="new" style="width:auto;" />
666 666
 					<span>%2$s</span>
667 667
 				</label>
668 668
 			</li>',
669
-			esc_attr( $this->id ),
670
-			esc_html( $label )
671
-		);
672
-
673
-	}
674
-
675
-	/**
676
-	 * Outputs a checkbox for saving a new payment method to the database.
677
-	 *
678
-	 * @since 1.0.19
679
-	 */
680
-	public function save_payment_method_checkbox() {
681
-
682
-		aui()->input(
683
-			array(
684
-				'type'       => 'checkbox',
685
-				'name'       => esc_attr( "getpaid-$this->id-new-payment-method" ),
686
-				'id'         => esc_attr( uniqid( $this->id ) ),
687
-				'required'   => false,
688
-				'label'      => esc_html__( 'Save payment method', 'invoicing' ),
689
-				'value'      => 'true',
690
-				'checked'    => true,
691
-				'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1',
692
-			),
693
-			true
694
-		);
695
-
696
-	}
697
-
698
-	/**
699
-	 * Registers the gateway.
700
-	 *
701
-	 * @return array
702
-	 */
703
-	public function register_gateway( $gateways ) {
704
-
705
-		$gateways[ $this->id ] = array(
706
-
707
-			'admin_label'    => $this->method_title,
669
+            esc_attr( $this->id ),
670
+            esc_html( $label )
671
+        );
672
+
673
+    }
674
+
675
+    /**
676
+     * Outputs a checkbox for saving a new payment method to the database.
677
+     *
678
+     * @since 1.0.19
679
+     */
680
+    public function save_payment_method_checkbox() {
681
+
682
+        aui()->input(
683
+            array(
684
+                'type'       => 'checkbox',
685
+                'name'       => esc_attr( "getpaid-$this->id-new-payment-method" ),
686
+                'id'         => esc_attr( uniqid( $this->id ) ),
687
+                'required'   => false,
688
+                'label'      => esc_html__( 'Save payment method', 'invoicing' ),
689
+                'value'      => 'true',
690
+                'checked'    => true,
691
+                'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1',
692
+            ),
693
+            true
694
+        );
695
+
696
+    }
697
+
698
+    /**
699
+     * Registers the gateway.
700
+     *
701
+     * @return array
702
+     */
703
+    public function register_gateway( $gateways ) {
704
+
705
+        $gateways[ $this->id ] = array(
706
+
707
+            'admin_label'    => $this->method_title,
708 708
             'checkout_label' => $this->title,
709
-			'ordering'       => $this->order,
709
+            'ordering'       => $this->order,
710 710
 
711
-		);
711
+        );
712 712
 
713
-		return $gateways;
713
+        return $gateways;
714 714
 
715
-	}
715
+    }
716 716
 
717
-	/**
718
-	 * Checks whether or not this is a sandbox request.
719
-	 *
720
-	 * @param  WPInv_Invoice|null $invoice Invoice object or null.
721
-	 * @return bool
722
-	 */
723
-	public function is_sandbox( $invoice = null ) {
717
+    /**
718
+     * Checks whether or not this is a sandbox request.
719
+     *
720
+     * @param  WPInv_Invoice|null $invoice Invoice object or null.
721
+     * @return bool
722
+     */
723
+    public function is_sandbox( $invoice = null ) {
724 724
 
725
-		if ( is_a( $invoice, 'WPInv_Invoice' ) && ! $invoice->needs_payment() ) {
726
-			return $invoice->get_mode() === 'test';
727
-		}
725
+        if ( is_a( $invoice, 'WPInv_Invoice' ) && ! $invoice->needs_payment() ) {
726
+            return $invoice->get_mode() === 'test';
727
+        }
728 728
 
729
-		return wpinv_is_test_mode( $this->id );
729
+        return wpinv_is_test_mode( $this->id );
730 730
 
731
-	}
731
+    }
732 732
 
733
-	/**
734
-	 * Renames the checkout button
735
-	 *
736
-	 * @return string
737
-	 */
738
-	public function rename_checkout_button() {
739
-		return $this->checkout_button_text;
740
-	}
733
+    /**
734
+     * Renames the checkout button
735
+     *
736
+     * @return string
737
+     */
738
+    public function rename_checkout_button() {
739
+        return $this->checkout_button_text;
740
+    }
741 741
 
742
-	/**
743
-	 * Validate gateway currency
744
-	 *
745
-	 * @return bool
746
-	 */
747
-	public function validate_currency( $validation, $currency ) {
742
+    /**
743
+     * Validate gateway currency
744
+     *
745
+     * @return bool
746
+     */
747
+    public function validate_currency( $validation, $currency ) {
748 748
 
749
-		// Required currencies.
750
-		if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
751
-			return false;
752
-		}
749
+        // Required currencies.
750
+        if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
751
+            return false;
752
+        }
753 753
 
754
-		// Excluded currencies.
755
-		if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
756
-			return false;
757
-		}
754
+        // Excluded currencies.
755
+        if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
756
+            return false;
757
+        }
758 758
 
759
-		return $validation;
760
-	}
759
+        return $validation;
760
+    }
761 761
 
762
-	/**
763
-	 * Displays an error
764
-	 *
765
-	 */
766
-	public function show_error( $code, $message, $type ) {
762
+    /**
763
+     * Displays an error
764
+     *
765
+     */
766
+    public function show_error( $code, $message, $type ) {
767 767
 
768
-		if ( is_admin() ) {
769
-			getpaid_admin()->{"show_$type"}( $message );
770
-		}
768
+        if ( is_admin() ) {
769
+            getpaid_admin()->{"show_$type"}( $message );
770
+        }
771 771
 
772
-		wpinv_set_error( $code, $message, $type );
772
+        wpinv_set_error( $code, $message, $type );
773 773
 
774
-	}
774
+    }
775 775
 
776 776
 }
Please login to merge, or discard this patch.
includes/admin/register-settings.php 1 patch
Indentation   +320 added lines, -320 removed lines patch added patch discarded remove patch
@@ -25,8 +25,8 @@  discard block
 block discarded – undo
25 25
                     $defaults[ $key ] = $setting['std'];
26 26
                 }
27 27
             }
28
-		}
29
-	}
28
+        }
29
+    }
30 30
 
31 31
     return $defaults;
32 32
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
  *
145 145
  */
146 146
 function wpinv_register_settings() {
147
-	do_action( 'getpaid_before_register_settings' );
147
+    do_action( 'getpaid_before_register_settings' );
148 148
 
149 149
     // Loop through all tabs.
150 150
     foreach ( wpinv_get_registered_settings() as $tab => $sections ) {
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
                 $settings = $sections;
160 160
             }
161 161
 
162
-			do_action( "getpaid_register_{$tab}_{$section}" );
162
+            do_action( "getpaid_register_{$tab}_{$section}" );
163 163
 
164 164
             // Register the setting section.
165 165
             add_settings_section(
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
     // Creates our settings in the options table.
181 181
     register_setting( 'wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize' );
182 182
 
183
-	do_action( 'getpaid_after_register_settings' );
183
+    do_action( 'getpaid_after_register_settings' );
184 184
 }
185 185
 add_action( 'admin_init', 'wpinv_register_settings' );
186 186
 
@@ -197,13 +197,13 @@  discard block
 block discarded – undo
197 197
     $name       = isset( $option['name'] ) ? $option['name'] : '';
198 198
     $cb         = "wpinv_{$option['type']}_callback";
199 199
     $section    = "wpinv_settings_{$tab}_$section";
200
-	$is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page'];
200
+    $is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page'];
201 201
 
202
-	if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) {
203
-		$tip   = wpinv_clean( $option['desc'] );
204
-		$name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>";
205
-		unset( $option['desc'] );
206
-	}
202
+    if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) {
203
+        $tip   = wpinv_clean( $option['desc'] );
204
+        $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>";
205
+        unset( $option['desc'] );
206
+    }
207 207
 
208 208
     // Loop through all tabs.
209 209
     add_settings_field(
@@ -230,9 +230,9 @@  discard block
 block discarded – undo
230 230
             'faux'            => isset( $option['faux'] ) ? $option['faux'] : false,
231 231
             'onchange'        => isset( $option['onchange'] ) ? $option['onchange'] : '',
232 232
             'custom'          => isset( $option['custom'] ) ? $option['custom'] : '',
233
-			'default_content' => isset( $option['default_content'] ) ? $option['default_content'] : '',
234
-			'class'           => isset( $option['class'] ) ? $option['class'] : '',
235
-			'style'           => isset( $option['style'] ) ? $option['style'] : '',
233
+            'default_content' => isset( $option['default_content'] ) ? $option['default_content'] : '',
234
+            'class'           => isset( $option['class'] ) ? $option['class'] : '',
235
+            'style'           => isset( $option['style'] ) ? $option['style'] : '',
236 236
             'cols'            => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50,
237 237
             'rows'            => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5,
238 238
         )
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
  * @return array
247 247
  */
248 248
 function wpinv_get_registered_settings() {
249
-	return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) );
249
+    return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) );
250 250
 }
251 251
 
252 252
 /**
@@ -265,18 +265,18 @@  discard block
 block discarded – undo
265 265
  */
266 266
 function wpinv_settings_sanitize( $input = array() ) {
267 267
 
268
-	$wpinv_options = wpinv_get_options();
269
-	$raw_referrer  = wp_get_raw_referer();
268
+    $wpinv_options = wpinv_get_options();
269
+    $raw_referrer  = wp_get_raw_referer();
270 270
 
271 271
     if ( empty( $raw_referrer ) ) {
272
-		return array_merge( $wpinv_options, $input );
272
+        return array_merge( $wpinv_options, $input );
273 273
     }
274 274
 
275 275
     wp_parse_str( $raw_referrer, $referrer );
276 276
 
277
-	if ( in_array( 'gp-setup', $referrer ) ) {
278
-		return array_merge( $wpinv_options, $input );
279
-	}
277
+    if ( in_array( 'gp-setup', $referrer ) ) {
278
+        return array_merge( $wpinv_options, $input );
279
+    }
280 280
 
281 281
     $settings = wpinv_get_registered_settings();
282 282
     $tab      = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general';
@@ -298,10 +298,10 @@  discard block
 block discarded – undo
298 298
         }
299 299
 
300 300
         // General filter
301
-		$input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
301
+        $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
302 302
 
303
-		// Key specific filter.
304
-		$input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] );
303
+        // Key specific filter.
304
+        $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] );
305 305
     }
306 306
 
307 307
     // Loop through the whitelist and unset any that are empty for the tab being saved
@@ -344,14 +344,14 @@  discard block
 block discarded – undo
344 344
 
345 345
     foreach ( $new_rates as $rate ) {
346 346
 
347
-		$rate['rate']    = wpinv_sanitize_amount( $rate['rate'] );
348
-		$rate['name']    = sanitize_text_field( $rate['name'] );
349
-		$rate['state']   = sanitize_text_field( $rate['state'] );
350
-		$rate['country'] = sanitize_text_field( $rate['country'] );
351
-		$rate['global']  = empty( $rate['state'] );
352
-		$tax_rates[]     = $rate;
347
+        $rate['rate']    = wpinv_sanitize_amount( $rate['rate'] );
348
+        $rate['name']    = sanitize_text_field( $rate['name'] );
349
+        $rate['state']   = sanitize_text_field( $rate['state'] );
350
+        $rate['country'] = sanitize_text_field( $rate['country'] );
351
+        $rate['global']  = empty( $rate['state'] );
352
+        $tax_rates[]     = $rate;
353 353
 
354
-	}
354
+    }
355 355
 
356 356
     update_option( 'wpinv_tax_rates', $tax_rates );
357 357
 
@@ -364,21 +364,21 @@  discard block
 block discarded – undo
364 364
         return $input;
365 365
     }
366 366
 
367
-	if ( empty( $_POST['wpinv_tax_rules_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_tax_rules_nonce'], 'wpinv_tax_rules' ) ) {
368
-		return $input;
369
-	}
367
+    if ( empty( $_POST['wpinv_tax_rules_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_tax_rules_nonce'], 'wpinv_tax_rules' ) ) {
368
+        return $input;
369
+    }
370 370
 
371 371
     $new_rules = ! empty( $_POST['tax_rules'] ) ? wp_kses_post_deep( array_values( $_POST['tax_rules'] ) ) : array();
372 372
     $tax_rules = array();
373 373
 
374 374
     foreach ( $new_rules as $rule ) {
375 375
 
376
-		$rule['key']      = sanitize_title_with_dashes( $rule['key'] );
377
-		$rule['label']    = sanitize_text_field( $rule['label'] );
378
-		$rule['tax_base'] = sanitize_text_field( $rule['tax_base'] );
379
-		$tax_rules[]      = $rule;
376
+        $rule['key']      = sanitize_title_with_dashes( $rule['key'] );
377
+        $rule['label']    = sanitize_text_field( $rule['label'] );
378
+        $rule['tax_base'] = sanitize_text_field( $rule['tax_base'] );
379
+        $tax_rules[]      = $rule;
380 380
 
381
-	}
381
+    }
382 382
 
383 383
     update_option( 'wpinv_tax_rules', $tax_rules );
384 384
 
@@ -391,11 +391,11 @@  discard block
 block discarded – undo
391 391
     $tabs['general']  = __( 'General', 'invoicing' );
392 392
     $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' );
393 393
     $tabs['taxes']    = __( 'Taxes', 'invoicing' );
394
-	$tabs['emails']   = __( 'Emails', 'invoicing' );
394
+    $tabs['emails']   = __( 'Emails', 'invoicing' );
395 395
 
396
-	if ( count( getpaid_get_integration_settings() ) > 0 ) {
397
-		$tabs['integrations'] = __( 'Integrations', 'invoicing' );
398
-	}
396
+    if ( count( getpaid_get_integration_settings() ) > 0 ) {
397
+        $tabs['integrations'] = __( 'Integrations', 'invoicing' );
398
+    }
399 399
 
400 400
     $tabs['privacy']  = __( 'Privacy', 'invoicing' );
401 401
     $tabs['misc']     = __( 'Misc', 'invoicing' );
@@ -426,53 +426,53 @@  discard block
 block discarded – undo
426 426
         'general'      => apply_filters(
427 427
             'wpinv_settings_sections_general',
428 428
             array(
429
-				'main'             => __( 'General Settings', 'invoicing' ),
430
-				'page_section'     => __( 'Page Settings', 'invoicing' ),
431
-				'currency_section' => __( 'Currency Settings', 'invoicing' ),
432
-				'labels'           => __( 'Label Texts', 'invoicing' ),
429
+                'main'             => __( 'General Settings', 'invoicing' ),
430
+                'page_section'     => __( 'Page Settings', 'invoicing' ),
431
+                'currency_section' => __( 'Currency Settings', 'invoicing' ),
432
+                'labels'           => __( 'Label Texts', 'invoicing' ),
433 433
             )
434 434
         ),
435 435
         'gateways'     => apply_filters(
436 436
             'wpinv_settings_sections_gateways',
437 437
             array(
438
-				'main' => __( 'Gateway Settings', 'invoicing' ),
438
+                'main' => __( 'Gateway Settings', 'invoicing' ),
439 439
             )
440 440
         ),
441 441
         'taxes'        => apply_filters(
442 442
             'wpinv_settings_sections_taxes',
443 443
             array(
444
-				'main'  => __( 'Tax Settings', 'invoicing' ),
445
-				'rules' => __( 'Tax Rules', 'invoicing' ),
446
-				'rates' => __( 'Tax Rates', 'invoicing' ),
447
-				'vat'   => __( 'EU VAT Settings', 'invoicing' ),
444
+                'main'  => __( 'Tax Settings', 'invoicing' ),
445
+                'rules' => __( 'Tax Rules', 'invoicing' ),
446
+                'rates' => __( 'Tax Rates', 'invoicing' ),
447
+                'vat'   => __( 'EU VAT Settings', 'invoicing' ),
448 448
             )
449 449
         ),
450 450
         'emails'       => apply_filters(
451 451
             'wpinv_settings_sections_emails',
452 452
             array(
453
-				'main' => __( 'Email Settings', 'invoicing' ),
453
+                'main' => __( 'Email Settings', 'invoicing' ),
454 454
             )
455 455
         ),
456 456
 
457
-		'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ),
457
+        'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ),
458 458
 
459 459
         'privacy'      => apply_filters(
460 460
             'wpinv_settings_sections_privacy',
461 461
             array(
462
-				'main' => __( 'Privacy policy', 'invoicing' ),
462
+                'main' => __( 'Privacy policy', 'invoicing' ),
463 463
             )
464 464
         ),
465 465
         'misc'         => apply_filters(
466 466
             'wpinv_settings_sections_misc',
467 467
             array(
468
-				'main'       => __( 'Miscellaneous', 'invoicing' ),
469
-				'custom-css' => __( 'Custom CSS', 'invoicing' ),
468
+                'main'       => __( 'Miscellaneous', 'invoicing' ),
469
+                'custom-css' => __( 'Custom CSS', 'invoicing' ),
470 470
             )
471 471
         ),
472 472
         'tools'        => apply_filters(
473 473
             'wpinv_settings_sections_tools',
474 474
             array(
475
-				'main' => __( 'Diagnostic Tools', 'invoicing' ),
475
+                'main' => __( 'Diagnostic Tools', 'invoicing' ),
476 476
             )
477 477
         ),
478 478
     );
@@ -483,46 +483,46 @@  discard block
 block discarded – undo
483 483
 }
484 484
 
485 485
 function wpinv_get_pages( $with_slug = false, $default_label = null ) {
486
-	$pages_options = array();
486
+    $pages_options = array();
487 487
 
488
-	if ( $default_label !== null && $default_label !== false ) {
489
-		$pages_options = array( '' => $default_label ); // Blank option
490
-	}
488
+    if ( $default_label !== null && $default_label !== false ) {
489
+        $pages_options = array( '' => $default_label ); // Blank option
490
+    }
491 491
 
492
-	$pages = get_pages();
493
-	if ( $pages ) {
494
-		foreach ( $pages as $page ) {
495
-			$title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
492
+    $pages = get_pages();
493
+    if ( $pages ) {
494
+        foreach ( $pages as $page ) {
495
+            $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
496 496
             $pages_options[ $page->ID ] = $title;
497
-		}
498
-	}
497
+        }
498
+    }
499 499
 
500
-	return $pages_options;
500
+    return $pages_options;
501 501
 }
502 502
 
503 503
 function wpinv_header_callback( $args ) {
504
-	if ( ! empty( $args['desc'] ) ) {
504
+    if ( ! empty( $args['desc'] ) ) {
505 505
         echo wp_kses_post( $args['desc'] );
506 506
     }
507 507
 }
508 508
 
509 509
 function wpinv_hidden_callback( $args ) {
510 510
 
511
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
512
-	$value   = wpinv_get_option( $args['id'], $std );
511
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
512
+    $value   = wpinv_get_option( $args['id'], $std );
513 513
 
514
-	if ( isset( $args['set_value'] ) ) {
515
-		$value = $args['set_value'];
516
-	}
514
+    if ( isset( $args['set_value'] ) ) {
515
+        $value = $args['set_value'];
516
+    }
517 517
 
518
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
519
-		$args['readonly'] = true;
520
-		$name  = '';
521
-	} else {
522
-		$name = 'wpinv_settings[' . esc_attr( $args['id'] ) . ']';
523
-	}
518
+    if ( isset( $args['faux'] ) && true === $args['faux'] ) {
519
+        $args['readonly'] = true;
520
+        $name  = '';
521
+    } else {
522
+        $name = 'wpinv_settings[' . esc_attr( $args['id'] ) . ']';
523
+    }
524 524
 
525
-	echo '<input type="hidden" id="wpinv_settings[' . esc_attr( $args['id'] ) . ']" name="' . esc_attr( $name ) . '" value="' . esc_attr( stripslashes( $value ) ) . '" />';
525
+    echo '<input type="hidden" id="wpinv_settings[' . esc_attr( $args['id'] ) . ']" name="' . esc_attr( $name ) . '" value="' . esc_attr( stripslashes( $value ) ) . '" />';
526 526
 
527 527
 }
528 528
 
@@ -531,12 +531,12 @@  discard block
 block discarded – undo
531 531
  */
532 532
 function wpinv_checkbox_callback( $args ) {
533 533
 
534
-	$std = isset( $args['std'] ) ? $args['std'] : '';
535
-	$std = wpinv_get_option( $args['id'], $std );
536
-	$id  = esc_attr( $args['id'] );
534
+    $std = isset( $args['std'] ) ? $args['std'] : '';
535
+    $std = wpinv_get_option( $args['id'], $std );
536
+    $id  = esc_attr( $args['id'] );
537 537
 
538
-	getpaid_hidden_field( "wpinv_settings[$id]", '0' );
539
-	?>
538
+    getpaid_hidden_field( "wpinv_settings[$id]", '0' );
539
+    ?>
540 540
 		<label>
541 541
 			<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" />
542 542
 			<?php echo wp_kses_post( $args['desc'] ); ?>
@@ -546,75 +546,75 @@  discard block
 block discarded – undo
546 546
 
547 547
 function wpinv_multicheck_callback( $args ) {
548 548
 
549
-	$sanitize_id = wpinv_sanitize_key( $args['id'] );
550
-	$class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
549
+    $sanitize_id = wpinv_sanitize_key( $args['id'] );
550
+    $class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
551 551
 
552
-	if ( ! empty( $args['options'] ) ) {
552
+    if ( ! empty( $args['options'] ) ) {
553 553
 
554
-		$std     = isset( $args['std'] ) ? $args['std'] : array();
555
-		$value   = wpinv_get_option( $args['id'], $std );
554
+        $std     = isset( $args['std'] ) ? $args['std'] : array();
555
+        $value   = wpinv_get_option( $args['id'], $std );
556 556
 
557
-		echo '<div class="wpi-mcheck-rows wpi-mcheck-' . esc_attr( $sanitize_id . $class ) . '">';
557
+        echo '<div class="wpi-mcheck-rows wpi-mcheck-' . esc_attr( $sanitize_id . $class ) . '">';
558 558
         foreach ( $args['options'] as $key => $option ) :
559
-			$sanitize_key = esc_attr( wpinv_sanitize_key( $key ) );
560
-			if ( in_array( $sanitize_key, $value ) ) {
561
-				$enabled = $sanitize_key;
562
-			} else {
563
-				$enabled = null;
564
-			}
565
-			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;';
566
-			echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']">' . wp_kses_post( $option ) . '</label></div>';
567
-		endforeach;
568
-		echo '</div>';
569
-		echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>';
570
-	}
559
+            $sanitize_key = esc_attr( wpinv_sanitize_key( $key ) );
560
+            if ( in_array( $sanitize_key, $value ) ) {
561
+                $enabled = $sanitize_key;
562
+            } else {
563
+                $enabled = null;
564
+            }
565
+            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;';
566
+            echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']">' . wp_kses_post( $option ) . '</label></div>';
567
+        endforeach;
568
+        echo '</div>';
569
+        echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>';
570
+    }
571 571
 }
572 572
 
573 573
 function wpinv_payment_icons_callback( $args ) {
574 574
 
575 575
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
576
-	$value   = wpinv_get_option( $args['id'], false );
576
+    $value   = wpinv_get_option( $args['id'], false );
577 577
 
578
-	if ( ! empty( $args['options'] ) ) {
579
-		foreach ( $args['options'] as $key => $option ) {
578
+    if ( ! empty( $args['options'] ) ) {
579
+        foreach ( $args['options'] as $key => $option ) {
580 580
             $sanitize_key = wpinv_sanitize_key( $key );
581 581
 
582
-			if ( empty( $value ) ) {
583
-				$enabled = $option;
584
-			} else {
585
-				$enabled = null;
586
-			}
587
-
588
-			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;">';
589
-
590
-				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;';
591
-
592
-				if ( wpinv_string_is_image_url( $key ) ) {
593
-				echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
594
-				} else {
595
-				$card = strtolower( str_replace( ' ', '', $option ) );
596
-
597
-				if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
598
-					$image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
599
-					} else {
600
-					$image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
601
-					$content_dir = WP_CONTENT_DIR;
602
-
603
-					if ( function_exists( 'wp_normalize_path' ) ) {
604
-						// Replaces backslashes with forward slashes for Windows systems
605
-						$image = wp_normalize_path( $image );
606
-						$content_dir = wp_normalize_path( $content_dir );
607
-						}
608
-
609
-					$image = str_replace( $content_dir, content_url(), $image );
610
-					}
611
-
612
-				echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
613
-				}
614
-			echo wp_kses_post( $option ) . '</label>';
615
-		}
616
-		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
617
-	}
582
+            if ( empty( $value ) ) {
583
+                $enabled = $option;
584
+            } else {
585
+                $enabled = null;
586
+            }
587
+
588
+            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;">';
589
+
590
+                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;';
591
+
592
+                if ( wpinv_string_is_image_url( $key ) ) {
593
+                echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
594
+                } else {
595
+                $card = strtolower( str_replace( ' ', '', $option ) );
596
+
597
+                if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
598
+                    $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
599
+                    } else {
600
+                    $image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
601
+                    $content_dir = WP_CONTENT_DIR;
602
+
603
+                    if ( function_exists( 'wp_normalize_path' ) ) {
604
+                        // Replaces backslashes with forward slashes for Windows systems
605
+                        $image = wp_normalize_path( $image );
606
+                        $content_dir = wp_normalize_path( $content_dir );
607
+                        }
608
+
609
+                    $image = str_replace( $content_dir, content_url(), $image );
610
+                    }
611
+
612
+                echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
613
+                }
614
+            echo wp_kses_post( $option ) . '</label>';
615
+        }
616
+        echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
617
+    }
618 618
 }
619 619
 
620 620
 /**
@@ -622,9 +622,9 @@  discard block
 block discarded – undo
622 622
  */
623 623
 function wpinv_radio_callback( $args ) {
624 624
 
625
-	$std = isset( $args['std'] ) ? $args['std'] : '';
626
-	$std = wpinv_get_option( $args['id'], $std );
627
-	?>
625
+    $std = isset( $args['std'] ) ? $args['std'] : '';
626
+    $std = wpinv_get_option( $args['id'], $std );
627
+    ?>
628 628
 		<fieldset>
629 629
 			<ul id="wpinv-settings-<?php echo esc_attr( $args['id'] ); ?>" style="margin-top: 0;">
630 630
 				<?php foreach ( $args['options'] as $key => $option ) : ?>
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
 			</ul>
639 639
 		</fieldset>
640 640
 	<?php
641
-	getpaid_settings_description_callback( $args );
641
+    getpaid_settings_description_callback( $args );
642 642
 }
643 643
 
644 644
 /**
@@ -646,10 +646,10 @@  discard block
 block discarded – undo
646 646
  */
647 647
 function getpaid_settings_description_callback( $args ) {
648 648
 
649
-	if ( ! empty( $args['desc'] ) ) {
650
-		$description = $args['desc'];
651
-		echo wp_kses_post( "<p class='description'>$description</p>" );
652
-	}
649
+    if ( ! empty( $args['desc'] ) ) {
650
+        $description = $args['desc'];
651
+        echo wp_kses_post( "<p class='description'>$description</p>" );
652
+    }
653 653
 
654 654
 }
655 655
 
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
  */
659 659
 function wpinv_gateways_callback() {
660 660
 
661
-	?>
661
+    ?>
662 662
 		</td>
663 663
 	</tr>
664 664
 	<tr class="bsui">
@@ -672,26 +672,26 @@  discard block
 block discarded – undo
672 672
 
673 673
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
674 674
     $class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
675
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
676
-	$value   = wpinv_get_option( $args['id'], $std );
675
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
676
+    $value   = wpinv_get_option( $args['id'], $std );
677 677
 
678
-	echo '<select name="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" class="' . esc_attr( $class ) . '" >';
678
+    echo '<select name="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" class="' . esc_attr( $class ) . '" >';
679 679
 
680
-	foreach ( $args['options'] as $key => $option ) :
680
+    foreach ( $args['options'] as $key => $option ) :
681 681
 
682
-		echo '<option value="' . esc_attr( $key ) . '" ';
682
+        echo '<option value="' . esc_attr( $key ) . '" ';
683 683
 
684
-		if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
684
+        if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
685 685
             selected( $key, $args['selected'] );
686 686
         } else {
687 687
             selected( $key, $value );
688 688
         }
689 689
 
690
-		echo '>' . esc_html( $option['admin_label'] ) . '</option>';
691
-	endforeach;
690
+        echo '>' . esc_html( $option['admin_label'] ) . '</option>';
691
+    endforeach;
692 692
 
693
-	echo '</select>';
694
-	echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
693
+    echo '</select>';
694
+    echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
695 695
 }
696 696
 
697 697
 /**
@@ -702,38 +702,38 @@  discard block
 block discarded – undo
702 702
  */
703 703
 function wpinv_settings_attrs_helper( $args ) {
704 704
 
705
-	$value = isset( $args['std'] ) ? $args['std'] : '';
706
-	$id    = esc_attr( $args['id'] );
707
-	$value = is_scalar( $value ) ? $value : '';
708
-
709
-	$attrs = array(
710
-		'name'     => ! empty( $args['faux'] ) ? false : "wpinv_settings[$id]",
711
-		'readonly' => ! empty( $args['faux'] ),
712
-		'value'    => ! empty( $args['faux'] ) ? $value : wpinv_get_option( $args['id'], $value ),
713
-		'id'       => 'wpinv-settings-' . $args['id'],
714
-		'style'    => $args['style'],
715
-		'class'    => $args['class'],
716
-		'placeholder' => $args['placeholder'],
717
-		'data-placeholder' => $args['placeholder'],
718
-	);
705
+    $value = isset( $args['std'] ) ? $args['std'] : '';
706
+    $id    = esc_attr( $args['id'] );
707
+    $value = is_scalar( $value ) ? $value : '';
708
+
709
+    $attrs = array(
710
+        'name'     => ! empty( $args['faux'] ) ? false : "wpinv_settings[$id]",
711
+        'readonly' => ! empty( $args['faux'] ),
712
+        'value'    => ! empty( $args['faux'] ) ? $value : wpinv_get_option( $args['id'], $value ),
713
+        'id'       => 'wpinv-settings-' . $args['id'],
714
+        'style'    => $args['style'],
715
+        'class'    => $args['class'],
716
+        'placeholder' => $args['placeholder'],
717
+        'data-placeholder' => $args['placeholder'],
718
+    );
719 719
 
720
-	if ( ! empty( $args['onchange'] ) ) {
721
-		$attrs['onchange'] = $args['onchange'];
722
-	}
720
+    if ( ! empty( $args['onchange'] ) ) {
721
+        $attrs['onchange'] = $args['onchange'];
722
+    }
723 723
 
724
-	foreach ( $attrs as $key => $value ) {
724
+    foreach ( $attrs as $key => $value ) {
725 725
 
726
-		if ( false === $value ) {
727
-			continue;
728
-		}
726
+        if ( false === $value ) {
727
+            continue;
728
+        }
729 729
 
730
-		if ( true === $value ) {
731
-			echo ' ' . esc_attr( $key );
732
-		} else {
733
-			echo ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
734
-		}
730
+        if ( true === $value ) {
731
+            echo ' ' . esc_attr( $key );
732
+        } else {
733
+            echo ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
734
+        }
735 735
 
736
-	}
736
+    }
737 737
 
738 738
 }
739 739
 
@@ -742,7 +742,7 @@  discard block
 block discarded – undo
742 742
  */
743 743
 function wpinv_text_callback( $args ) {
744 744
 
745
-	?>
745
+    ?>
746 746
 		<label style="width: 100%;">
747 747
 			<input type="text" <?php wpinv_settings_attrs_helper( $args ); ?>>
748 748
 			<?php getpaid_settings_description_callback( $args ); ?>
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
  */
757 757
 function wpinv_number_callback( $args ) {
758 758
 
759
-	?>
759
+    ?>
760 760
 		<label style="width: 100%;">
761 761
 			<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 ); ?>>
762 762
 			<?php getpaid_settings_description_callback( $args ); ?>
@@ -768,34 +768,34 @@  discard block
 block discarded – undo
768 768
 function wpinv_textarea_callback( $args ) {
769 769
 
770 770
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
771
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
772
-	$value   = wpinv_get_option( $args['id'], $std );
771
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
772
+    $value   = wpinv_get_option( $args['id'], $std );
773 773
 
774 774
     $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
775 775
     $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text';
776 776
 
777
-	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>';
778
-	echo '<br /><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
777
+    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>';
778
+    echo '<br /><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
779 779
 
780 780
 }
781 781
 
782 782
 function wpinv_password_callback( $args ) {
783 783
 
784 784
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
785
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
786
-	$value   = wpinv_get_option( $args['id'], $std );
785
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
786
+    $value   = wpinv_get_option( $args['id'], $std );
787 787
 
788
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
789
-	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 ) . '"/>';
790
-	echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
788
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
789
+    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 ) . '"/>';
790
+    echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
791 791
 
792 792
 }
793 793
 
794 794
 function wpinv_missing_callback( $args ) {
795
-	printf(
796
-		esc_html__( 'The callback function used for the %s setting is missing.', 'invoicing' ),
797
-		'<strong>' . esc_html( $args['id'] ) . '</strong>'
798
-	);
795
+    printf(
796
+        esc_html__( 'The callback function used for the %s setting is missing.', 'invoicing' ),
797
+        '<strong>' . esc_html( $args['id'] ) . '</strong>'
798
+    );
799 799
 }
800 800
 
801 801
 /**
@@ -803,13 +803,13 @@  discard block
 block discarded – undo
803 803
  */
804 804
 function wpinv_select_callback( $args ) {
805 805
 
806
-	$desc   = wp_kses_post( $args['desc'] );
807
-	$desc   = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
808
-	$value  = isset( $args['std'] ) ? $args['std'] : '';
809
-	$value  = wpinv_get_option( $args['id'], $value );
810
-	$rand   = uniqid( 'random_id' );
806
+    $desc   = wp_kses_post( $args['desc'] );
807
+    $desc   = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
808
+    $value  = isset( $args['std'] ) ? $args['std'] : '';
809
+    $value  = wpinv_get_option( $args['id'], $value );
810
+    $rand   = uniqid( 'random_id' );
811 811
 
812
-	?>
812
+    ?>
813 813
 		<label style="width: 100%;">
814 814
 			<select <?php wpinv_settings_attrs_helper( $args ); ?> data-allow-clear="true">
815 815
 				<?php foreach ( $args['options'] as $option => $name ) : ?>
@@ -842,50 +842,50 @@  discard block
 block discarded – undo
842 842
 function wpinv_color_select_callback( $args ) {
843 843
 
844 844
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
845
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
846
-	$value   = wpinv_get_option( $args['id'], $std );
845
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
846
+    $value   = wpinv_get_option( $args['id'], $std );
847 847
 
848
-	echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
848
+    echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
849 849
 
850
-	foreach ( $args['options'] as $option => $color ) {
851
-		echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $color['label'] ) . '</option>';
852
-	}
850
+    foreach ( $args['options'] as $option => $color ) {
851
+        echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $color['label'] ) . '</option>';
852
+    }
853 853
 
854
-	echo '</select>';
855
-	echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
854
+    echo '</select>';
855
+    echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
856 856
 
857 857
 }
858 858
 
859 859
 function wpinv_rich_editor_callback( $args ) {
860
-	global $wp_version;
860
+    global $wp_version;
861 861
 
862 862
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
863 863
 
864
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
865
-	$value   = wpinv_get_option( $args['id'], $std );
864
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
865
+    $value   = wpinv_get_option( $args['id'], $std );
866 866
 
867
-	if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) {
868
-		$value = $std;
869
-	}
867
+    if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) {
868
+        $value = $std;
869
+    }
870 870
 
871
-	$rows = isset( $args['size'] ) ? $args['size'] : 20;
871
+    $rows = isset( $args['size'] ) ? $args['size'] : 20;
872 872
 
873
-	echo '<div class="getpaid-settings-editor-input">';
874
-	if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
875
-		wp_editor(
873
+    echo '<div class="getpaid-settings-editor-input">';
874
+    if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
875
+        wp_editor(
876 876
             stripslashes( $value ),
877 877
             'wpinv_settings_' . esc_attr( $args['id'] ),
878 878
             array(
879
-				'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']',
880
-				'textarea_rows' => absint( $rows ),
881
-				'media_buttons' => false,
879
+                'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']',
880
+                'textarea_rows' => absint( $rows ),
881
+                'media_buttons' => false,
882 882
             )
883 883
         );
884
-	} else {
885
-		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>';
886
-	}
884
+    } else {
885
+        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>';
886
+    }
887 887
 
888
-	echo '</div><br/><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
888
+    echo '</div><br/><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
889 889
 
890 890
 }
891 891
 
@@ -893,51 +893,51 @@  discard block
 block discarded – undo
893 893
 
894 894
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
895 895
 
896
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
897
-	$value   = wpinv_get_option( $args['id'], $std );
896
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
897
+    $value   = wpinv_get_option( $args['id'], $std );
898 898
 
899
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
900
-	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 ) ) . '"/>';
901
-	echo '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . esc_attr__( 'Upload File', 'invoicing' ) . '"/></span>';
902
-	echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
899
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
900
+    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 ) ) . '"/>';
901
+    echo '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . esc_attr__( 'Upload File', 'invoicing' ) . '"/></span>';
902
+    echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
903 903
 
904 904
 }
905 905
 
906 906
 function wpinv_color_callback( $args ) {
907 907
 
908
-	$std         = isset( $args['std'] ) ? $args['std'] : '';
909
-	$value       = wpinv_get_option( $args['id'], $std );
908
+    $std         = isset( $args['std'] ) ? $args['std'] : '';
909
+    $value       = wpinv_get_option( $args['id'], $std );
910 910
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
911 911
 
912
-	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 ) . '" />';
913
-	echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
912
+    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 ) . '" />';
913
+    echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
914 914
 
915 915
 }
916 916
 
917 917
 function wpinv_country_states_callback( $args ) {
918 918
 
919
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
920
-	$value   = wpinv_get_option( $args['id'], $std );
919
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
920
+    $value   = wpinv_get_option( $args['id'], $std );
921 921
 
922 922
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
923 923
 
924
-	if ( isset( $args['placeholder'] ) ) {
925
-		$placeholder = $args['placeholder'];
926
-	} else {
927
-		$placeholder = '';
928
-	}
924
+    if ( isset( $args['placeholder'] ) ) {
925
+        $placeholder = $args['placeholder'];
926
+    } else {
927
+        $placeholder = '';
928
+    }
929 929
 
930
-	$states = wpinv_get_country_states();
930
+    $states = wpinv_get_country_states();
931 931
 
932
-	$class = empty( $states ) ? 'wpinv-no-states' : 'wpi_select2';
933
-	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 ) . '"/>';
932
+    $class = empty( $states ) ? 'wpinv-no-states' : 'wpi_select2';
933
+    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 ) . '"/>';
934 934
 
935
-	foreach ( $states as $option => $name ) {
936
-		echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $name ) . '</option>';
937
-	}
935
+    foreach ( $states as $option => $name ) {
936
+        echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $name ) . '</option>';
937
+    }
938 938
 
939
-	echo '</select>';
940
-	echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
939
+    echo '</select>';
940
+    echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
941 941
 
942 942
 }
943 943
 
@@ -946,7 +946,7 @@  discard block
 block discarded – undo
946 946
  */
947 947
 function wpinv_tax_rates_callback() {
948 948
 
949
-	?>
949
+    ?>
950 950
 		</td>
951 951
 	</tr>
952 952
 	<tr class="bsui">
@@ -962,9 +962,9 @@  discard block
 block discarded – undo
962 962
  */
963 963
 function wpinv_tax_rate_callback( $tax_rate, $key ) {
964 964
 
965
-	$key                      = sanitize_key( $key );
966
-	$tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate'];
967
-	include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php';
965
+    $key                      = sanitize_key( $key );
966
+    $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate'];
967
+    include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php';
968 968
 
969 969
 }
970 970
 
@@ -973,7 +973,7 @@  discard block
 block discarded – undo
973 973
  */
974 974
 function wpinv_tax_rules_callback() {
975 975
 
976
-	?>
976
+    ?>
977 977
 		</td>
978 978
 	</tr>
979 979
 	<tr class="bsui">
@@ -1011,14 +1011,14 @@  discard block
 block discarded – undo
1011 1011
                 <td>
1012 1012
 					<a href="
1013 1013
                     <?php
1014
-						echo esc_url(
1015
-							wp_nonce_url(
1016
-								add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
1017
-								'getpaid-nonce',
1018
-								'getpaid-nonce'
1019
-							)
1020
-						);
1021
-					?>
1014
+                        echo esc_url(
1015
+                            wp_nonce_url(
1016
+                                add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
1017
+                                'getpaid-nonce',
1018
+                                'getpaid-nonce'
1019
+                            )
1020
+                        );
1021
+                    ?>
1022 1022
                     " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a>
1023 1023
                 </td>
1024 1024
             </tr>
@@ -1030,14 +1030,14 @@  discard block
 block discarded – undo
1030 1030
                 <td>
1031 1031
 					<a href="
1032 1032
                     <?php
1033
-						echo esc_url(
1034
-							wp_nonce_url(
1035
-								add_query_arg( 'getpaid-admin-action', 'refresh_permalinks' ),
1036
-								'getpaid-nonce',
1037
-								'getpaid-nonce'
1038
-							)
1039
-						);
1040
-					?>
1033
+                        echo esc_url(
1034
+                            wp_nonce_url(
1035
+                                add_query_arg( 'getpaid-admin-action', 'refresh_permalinks' ),
1036
+                                'getpaid-nonce',
1037
+                                'getpaid-nonce'
1038
+                            )
1039
+                        );
1040
+                    ?>
1041 1041
                     " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a>
1042 1042
                 </td>
1043 1043
             </tr>
@@ -1049,14 +1049,14 @@  discard block
 block discarded – undo
1049 1049
                 <td>
1050 1050
 					<a href="
1051 1051
                     <?php
1052
-						echo esc_url(
1053
-							wp_nonce_url(
1054
-								add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ),
1055
-								'getpaid-nonce',
1056
-								'getpaid-nonce'
1057
-							)
1058
-						);
1059
-					?>
1052
+                        echo esc_url(
1053
+                            wp_nonce_url(
1054
+                                add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ),
1055
+                                'getpaid-nonce',
1056
+                                'getpaid-nonce'
1057
+                            )
1058
+                        );
1059
+                    ?>
1060 1060
                     " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a>
1061 1061
                 </td>
1062 1062
             </tr>
@@ -1068,14 +1068,14 @@  discard block
 block discarded – undo
1068 1068
                 <td>
1069 1069
 					<a href="
1070 1070
                     <?php
1071
-						echo esc_url(
1072
-							wp_nonce_url(
1073
-								add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ),
1074
-								'getpaid-nonce',
1075
-								'getpaid-nonce'
1076
-							)
1077
-						);
1078
-					?>
1071
+                        echo esc_url(
1072
+                            wp_nonce_url(
1073
+                                add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ),
1074
+                                'getpaid-nonce',
1075
+                                'getpaid-nonce'
1076
+                            )
1077
+                        );
1078
+                    ?>
1079 1079
                     " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a>
1080 1080
                 </td>
1081 1081
             </tr>
@@ -1088,14 +1088,14 @@  discard block
 block discarded – undo
1088 1088
                 <td>
1089 1089
 					<a href="
1090 1090
                     <?php
1091
-						echo esc_url(
1092
-							wp_nonce_url(
1093
-								add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ),
1094
-								'getpaid-nonce',
1095
-								'getpaid-nonce'
1096
-							)
1097
-						);
1098
-					?>
1091
+                        echo esc_url(
1092
+                            wp_nonce_url(
1093
+                                add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ),
1094
+                                'getpaid-nonce',
1095
+                                'getpaid-nonce'
1096
+                            )
1097
+                        );
1098
+                    ?>
1099 1099
                     " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a>
1100 1100
                 </td>
1101 1101
             </tr>
@@ -1108,8 +1108,8 @@  discard block
 block discarded – undo
1108 1108
                 <td>
1109 1109
 					<a href="
1110 1110
                     <?php
1111
-						echo esc_url( admin_url( 'index.php?page=gp-setup' ) );
1112
-					?>
1111
+                        echo esc_url( admin_url( 'index.php?page=gp-setup' ) );
1112
+                    ?>
1113 1113
                     " class="button button-primary"><?php esc_html_e( 'Launch', 'invoicing' ); ?></a>
1114 1114
                 </td>
1115 1115
             </tr>
@@ -1123,19 +1123,19 @@  discard block
 block discarded – undo
1123 1123
 
1124 1124
 
1125 1125
 function wpinv_descriptive_text_callback( $args ) {
1126
-	echo wp_kses_post( $args['desc'] );
1126
+    echo wp_kses_post( $args['desc'] );
1127 1127
 }
1128 1128
 
1129 1129
 function wpinv_raw_html_callback( $args ) {
1130
-	echo wp_kses( $args['desc'], getpaid_allowed_html() );
1130
+    echo wp_kses( $args['desc'], getpaid_allowed_html() );
1131 1131
 }
1132 1132
 
1133 1133
 function wpinv_hook_callback( $args ) {
1134
-	do_action( 'wpinv_' . $args['id'], $args );
1134
+    do_action( 'wpinv_' . $args['id'], $args );
1135 1135
 }
1136 1136
 
1137 1137
 function wpinv_set_settings_cap() {
1138
-	return wpinv_get_capability();
1138
+    return wpinv_get_capability();
1139 1139
 }
1140 1140
 add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' );
1141 1141
 
@@ -1159,15 +1159,15 @@  discard block
 block discarded – undo
1159 1159
  */
1160 1160
 function wpinv_get_merge_tags_help_text( $subscription = false ) {
1161 1161
 
1162
-	$url  = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f';
1163
-	$link = sprintf(
1164
-		'<strong><a href="%s" target="_blank">%s</a></strong>',
1165
-		$url,
1166
-		esc_html__( 'View available merge tags.', 'invoicing' )
1167
-	);
1162
+    $url  = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f';
1163
+    $link = sprintf(
1164
+        '<strong><a href="%s" target="_blank">%s</a></strong>',
1165
+        $url,
1166
+        esc_html__( 'View available merge tags.', 'invoicing' )
1167
+    );
1168 1168
 
1169
-	$description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' );
1169
+    $description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' );
1170 1170
 
1171
-	return "$description $link";
1171
+    return "$description $link";
1172 1172
 
1173 1173
 }
Please login to merge, or discard this patch.
includes/class-wpinv.php 1 patch
Indentation   +605 added lines, -605 removed lines patch added patch discarded remove patch
@@ -14,650 +14,650 @@
 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( 'notes', new WPInv_Notes() );
90
-		$this->set( 'api', new WPInv_API() );
91
-		$this->set( 'post_types', new GetPaid_Post_Types() );
92
-		$this->set( 'template', new GetPaid_Template() );
93
-		$this->set( 'admin', new GetPaid_Admin() );
94
-		$this->set( 'subscriptions', new WPInv_Subscriptions() );
95
-		$this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
96
-		$this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
97
-		$this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
98
-		$this->set( 'payment_forms', new GetPaid_Payment_Forms() );
99
-		$this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
100
-
101
-	}
102
-
103
-	 /**
104
-	 * Define plugin constants.
105
-	 */
106
-	public function define_constants() {
107
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
108
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
109
-		$this->version = WPINV_VERSION;
110
-	}
111
-
112
-	/**
113
-	 * Hook into actions and filters.
114
-	 *
115
-	 * @since 1.0.19
116
-	 */
117
-	protected function init_hooks() {
118
-		/* Internationalize the text strings used. */
119
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
120
-
121
-		// Init the plugin after WordPress inits.
122
-		add_action( 'init', array( $this, 'init' ), 1 );
123
-		add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
124
-		add_action( 'init', array( $this, 'wpinv_actions' ) );
125
-		add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
126
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
127
-		add_action( 'wp_footer', array( $this, 'wp_footer' ) );
128
-		add_action( 'wp_head', array( $this, 'wp_head' ) );
129
-		add_action( 'widgets_init', array( $this, 'register_widgets' ) );
130
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
131
-		add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) );
132
-		add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
133
-
134
-		add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
17
+    /**
18
+     * GetPaid version.
19
+     *
20
+     * @var string
21
+     */
22
+    public $version;
23
+
24
+    /**
25
+     * Data container.
26
+     *
27
+     * @var array
28
+     */
29
+    protected $data = array();
30
+
31
+    /**
32
+     * Form elements instance.
33
+     *
34
+     * @var WPInv_Payment_Form_Elements
35
+     */
36
+    public $form_elements;
37
+
38
+    /**
39
+     * @var array An array of payment gateways.
40
+     */
41
+    public $gateways;
42
+
43
+    /**
44
+     * Class constructor.
45
+     */
46
+    public function __construct() {
47
+        $this->define_constants();
48
+        $this->includes();
49
+        $this->init_hooks();
50
+        $this->set_properties();
51
+    }
52
+
53
+    /**
54
+     * Sets a custom data property.
55
+     *
56
+     * @param string $prop The prop to set.
57
+     * @param mixed $value The value to retrieve.
58
+     */
59
+    public function set( $prop, $value ) {
60
+        $this->data[ $prop ] = $value;
61
+    }
62
+
63
+    /**
64
+     * Gets a custom data property.
65
+     *
66
+     * @param string $prop The prop to set.
67
+     * @return mixed The value.
68
+     */
69
+    public function get( $prop ) {
70
+
71
+        if ( isset( $this->data[ $prop ] ) ) {
72
+            return $this->data[ $prop ];
73
+        }
74
+
75
+        return null;
76
+    }
77
+
78
+    /**
79
+     * Define class properties.
80
+     */
81
+    public function set_properties() {
82
+
83
+        // Sessions.
84
+        $this->set( 'session', new WPInv_Session_Handler() );
85
+        $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
86
+        $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
87
+
88
+        // Init other objects.
89
+        $this->set( 'notes', new WPInv_Notes() );
90
+        $this->set( 'api', new WPInv_API() );
91
+        $this->set( 'post_types', new GetPaid_Post_Types() );
92
+        $this->set( 'template', new GetPaid_Template() );
93
+        $this->set( 'admin', new GetPaid_Admin() );
94
+        $this->set( 'subscriptions', new WPInv_Subscriptions() );
95
+        $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
96
+        $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
97
+        $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
98
+        $this->set( 'payment_forms', new GetPaid_Payment_Forms() );
99
+        $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
100
+
101
+    }
102
+
103
+        /**
104
+         * Define plugin constants.
105
+         */
106
+    public function define_constants() {
107
+        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
108
+        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
109
+        $this->version = WPINV_VERSION;
110
+    }
111
+
112
+    /**
113
+     * Hook into actions and filters.
114
+     *
115
+     * @since 1.0.19
116
+     */
117
+    protected function init_hooks() {
118
+        /* Internationalize the text strings used. */
119
+        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
120
+
121
+        // Init the plugin after WordPress inits.
122
+        add_action( 'init', array( $this, 'init' ), 1 );
123
+        add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
124
+        add_action( 'init', array( $this, 'wpinv_actions' ) );
125
+        add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
126
+        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
127
+        add_action( 'wp_footer', array( $this, 'wp_footer' ) );
128
+        add_action( 'wp_head', array( $this, 'wp_head' ) );
129
+        add_action( 'widgets_init', array( $this, 'register_widgets' ) );
130
+        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
131
+        add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) );
132
+        add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
133
+
134
+        add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
135 135
         add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 );
136
-		add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
137
-
138
-		// Fires after registering actions.
139
-		do_action( 'wpinv_actions', $this );
140
-		do_action( 'getpaid_actions', $this );
141
-
142
-	}
143
-
144
-	public function plugins_loaded() {
145
-		/* Internationalize the text strings used. */
146
-		$this->load_textdomain();
147
-
148
-		do_action( 'wpinv_loaded' );
149
-
150
-		// Fix oxygen page builder conflict
151
-		if ( function_exists( 'ct_css_output' ) ) {
152
-			wpinv_oxygen_fix_conflict();
153
-		}
154
-	}
155
-
156
-	/**
157
-	 * Load Localisation files.
158
-	 *
159
-	 * Note: the first-loaded translation file overrides any following ones if the same translation is present.
160
-	 *
161
-	 * Locales found in:
162
-	 *      - WP_LANG_DIR/plugins/invoicing-LOCALE.mo
163
-	 *      - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo
164
-	 *
165
-	 * @since 1.0.0
166
-	 */
167
-	public function load_textdomain() {
168
-
169
-		load_plugin_textdomain(
170
-			'invoicing',
171
-			false,
172
-			plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/'
173
-		);
174
-
175
-	}
176
-
177
-	/**
178
-	 * Include required core files used in admin and on the frontend.
179
-	 */
180
-	public function includes() {
181
-
182
-		// Start with the settings.
183
-		require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php';
184
-
185
-		// Packages/libraries.
186
-		require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php';
187
-		require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php';
188
-
189
-		// Load functions.
190
-		require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php';
191
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php';
192
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php';
193
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php';
194
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php';
195
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php';
196
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php';
197
-		require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php';
198
-		require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php';
199
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php';
200
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php';
201
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php';
202
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php';
203
-		require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php';
204
-		require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php';
205
-
206
-		// Register autoloader.
207
-		try {
208
-			spl_autoload_register( array( $this, 'autoload' ), true );
209
-		} catch ( Exception $e ) {
210
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
211
-		}
212
-
213
-		require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php';
214
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php';
215
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php';
216
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php';
217
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php';
218
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php';
219
-		require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php';
220
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php';
221
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php';
222
-		require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php';
223
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php';
224
-		require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php';
225
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php';
226
-		require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php';
227
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php';
228
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php';
229
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php';
230
-		require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php';
231
-		require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php';
232
-		require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php';
233
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php';
234
-		require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php';
235
-
236
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
237
-			GetPaid_Post_Types_Admin::init();
238
-
239
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php';
240
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php';
241
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php';
242
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php';
243
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php';
244
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php';
245
-			// load the user class only on the users.php page
246
-			global $pagenow;
247
-			if ( $pagenow == 'users.php' ) {
248
-				new WPInv_Admin_Users();
249
-			}
250
-		}
251
-
252
-		// Register cli commands
253
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
254
-			require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php';
255
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
256
-		}
257
-
258
-	}
259
-
260
-	/**
261
-	 * Class autoloader
262
-	 *
263
-	 * @param       string $class_name The name of the class to load.
264
-	 * @access      public
265
-	 * @since       1.0.19
266
-	 * @return      void
267
-	 */
268
-	public function autoload( $class_name ) {
269
-
270
-		// Normalize the class name...
271
-		$class_name  = strtolower( $class_name );
272
-
273
-		// ... and make sure it is our class.
274
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
275
-			return;
276
-		}
277
-
278
-		// Next, prepare the file name from the class.
279
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
280
-
281
-		// Base path of the classes.
282
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
283
-
284
-		// And an array of possible locations in order of importance.
285
-		$locations = array(
286
-			"$plugin_path/includes",
287
-			"$plugin_path/includes/data-stores",
288
-			"$plugin_path/includes/gateways",
289
-			"$plugin_path/includes/payments",
290
-			"$plugin_path/includes/geolocation",
291
-			"$plugin_path/includes/reports",
292
-			"$plugin_path/includes/api",
293
-			"$plugin_path/includes/admin",
294
-			"$plugin_path/includes/admin/meta-boxes",
295
-		);
296
-
297
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
298
-
299
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
300
-				include trailingslashit( $location ) . $file_name;
301
-				break;
302
-			}
136
+        add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
137
+
138
+        // Fires after registering actions.
139
+        do_action( 'wpinv_actions', $this );
140
+        do_action( 'getpaid_actions', $this );
141
+
142
+    }
143
+
144
+    public function plugins_loaded() {
145
+        /* Internationalize the text strings used. */
146
+        $this->load_textdomain();
147
+
148
+        do_action( 'wpinv_loaded' );
149
+
150
+        // Fix oxygen page builder conflict
151
+        if ( function_exists( 'ct_css_output' ) ) {
152
+            wpinv_oxygen_fix_conflict();
153
+        }
154
+    }
155
+
156
+    /**
157
+     * Load Localisation files.
158
+     *
159
+     * Note: the first-loaded translation file overrides any following ones if the same translation is present.
160
+     *
161
+     * Locales found in:
162
+     *      - WP_LANG_DIR/plugins/invoicing-LOCALE.mo
163
+     *      - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo
164
+     *
165
+     * @since 1.0.0
166
+     */
167
+    public function load_textdomain() {
168
+
169
+        load_plugin_textdomain(
170
+            'invoicing',
171
+            false,
172
+            plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/'
173
+        );
174
+
175
+    }
176
+
177
+    /**
178
+     * Include required core files used in admin and on the frontend.
179
+     */
180
+    public function includes() {
181
+
182
+        // Start with the settings.
183
+        require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php';
184
+
185
+        // Packages/libraries.
186
+        require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php';
187
+        require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php';
188
+
189
+        // Load functions.
190
+        require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php';
191
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php';
192
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php';
193
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php';
194
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php';
195
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php';
196
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php';
197
+        require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php';
198
+        require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php';
199
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php';
200
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php';
201
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php';
202
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php';
203
+        require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php';
204
+        require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php';
205
+
206
+        // Register autoloader.
207
+        try {
208
+            spl_autoload_register( array( $this, 'autoload' ), true );
209
+        } catch ( Exception $e ) {
210
+            wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
211
+        }
212
+
213
+        require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php';
214
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php';
215
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php';
216
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php';
217
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php';
218
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php';
219
+        require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php';
220
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php';
221
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php';
222
+        require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php';
223
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php';
224
+        require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php';
225
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php';
226
+        require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php';
227
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php';
228
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php';
229
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php';
230
+        require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php';
231
+        require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php';
232
+        require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php';
233
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php';
234
+        require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php';
235
+
236
+        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
237
+            GetPaid_Post_Types_Admin::init();
238
+
239
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php';
240
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php';
241
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php';
242
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php';
243
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php';
244
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php';
245
+            // load the user class only on the users.php page
246
+            global $pagenow;
247
+            if ( $pagenow == 'users.php' ) {
248
+                new WPInv_Admin_Users();
249
+            }
250
+        }
251
+
252
+        // Register cli commands
253
+        if ( defined( 'WP_CLI' ) && WP_CLI ) {
254
+            require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php';
255
+            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
256
+        }
257
+
258
+    }
259
+
260
+    /**
261
+     * Class autoloader
262
+     *
263
+     * @param       string $class_name The name of the class to load.
264
+     * @access      public
265
+     * @since       1.0.19
266
+     * @return      void
267
+     */
268
+    public function autoload( $class_name ) {
269
+
270
+        // Normalize the class name...
271
+        $class_name  = strtolower( $class_name );
272
+
273
+        // ... and make sure it is our class.
274
+        if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
275
+            return;
276
+        }
277
+
278
+        // Next, prepare the file name from the class.
279
+        $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
280
+
281
+        // Base path of the classes.
282
+        $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
283
+
284
+        // And an array of possible locations in order of importance.
285
+        $locations = array(
286
+            "$plugin_path/includes",
287
+            "$plugin_path/includes/data-stores",
288
+            "$plugin_path/includes/gateways",
289
+            "$plugin_path/includes/payments",
290
+            "$plugin_path/includes/geolocation",
291
+            "$plugin_path/includes/reports",
292
+            "$plugin_path/includes/api",
293
+            "$plugin_path/includes/admin",
294
+            "$plugin_path/includes/admin/meta-boxes",
295
+        );
296
+
297
+        foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
298
+
299
+            if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
300
+                include trailingslashit( $location ) . $file_name;
301
+                break;
302
+            }
303 303
 }
304 304
 
305
-	}
306
-
307
-	/**
308
-	 * Inits hooks etc.
309
-	 */
310
-	public function init() {
311
-
312
-		// Fires before getpaid inits.
313
-		do_action( 'before_getpaid_init', $this );
314
-
315
-		// Maybe upgrade.
316
-		$this->maybe_upgrade_database();
317
-
318
-		// Load default gateways.
319
-		$gateways = apply_filters(
320
-			'getpaid_default_gateways',
321
-			array(
322
-				'manual'        => 'GetPaid_Manual_Gateway',
323
-				'paypal'        => 'GetPaid_Paypal_Gateway',
324
-				'worldpay'      => 'GetPaid_Worldpay_Gateway',
325
-				'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
326
-				'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
327
-			)
328
-		);
329
-
330
-		foreach ( $gateways as $id => $class ) {
331
-			$this->gateways[ $id ] = new $class();
332
-		}
333
-
334
-		if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
335
-			GetPaid_Installer::rename_gateways_label();
336
-			update_option( 'wpinv_renamed_gateways', 'yes' );
337
-		}
338
-
339
-		// Fires after getpaid inits.
340
-		do_action( 'getpaid_init', $this );
341
-
342
-	}
343
-
344
-	/**
345
-	 * Checks if this is an IPN request and processes it.
346
-	 */
347
-	public function maybe_process_ipn() {
348
-
349
-		// Ensure that this is an IPN request.
350
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
351
-			return;
352
-		}
353
-
354
-		$gateway = sanitize_text_field( $_GET['wpi-gateway'] );
355
-
356
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
357
-		do_action( "wpinv_verify_{$gateway}_ipn" );
358
-		exit;
359
-
360
-	}
361
-
362
-	public function enqueue_scripts() {
363
-
364
-		// Fires before adding scripts.
365
-		do_action( 'getpaid_enqueue_scripts' );
366
-
367
-		$localize                         = array();
368
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
369
-		$localize['thousands']            = wpinv_thousands_separator();
370
-		$localize['decimals']             = wpinv_decimal_separator();
371
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
372
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
373
-		$localize['UseTaxes']             = wpinv_use_taxes();
374
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
375
-		$localize['loading']              = __( 'Loading...', 'invoicing' );
376
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
377
-		$localize['recaptchaSettings']    = getpaid_get_recaptcha_settings();
378
-
379
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
380
-
381
-		// reCaptcha.
382
-		if ( getpaid_is_recaptcha_enabled() ) {
383
-			$url = apply_filters(
384
-				'getpaid_recaptcha_api_url',
385
-				add_query_arg(
386
-					array(
387
-						'render' => 'v2' === getpaid_get_recaptcha_version() ? 'explicit' : getpaid_get_recaptcha_site_key(),
388
-					),
389
-					'https://www.google.com/recaptcha/api.js'
390
-				)
391
-			);
392
-			wp_enqueue_script( 'recaptcha', $url, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
393
-		}
394
-
395
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
396
-		wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true );
397
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
398
-	}
399
-
400
-	public function wpinv_actions() {
401
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
402
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
403
-		}
404
-
405
-		if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) {
406
-			include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php';
407
-		}
408
-	}
409
-
410
-	/**
305
+    }
306
+
307
+    /**
308
+     * Inits hooks etc.
309
+     */
310
+    public function init() {
311
+
312
+        // Fires before getpaid inits.
313
+        do_action( 'before_getpaid_init', $this );
314
+
315
+        // Maybe upgrade.
316
+        $this->maybe_upgrade_database();
317
+
318
+        // Load default gateways.
319
+        $gateways = apply_filters(
320
+            'getpaid_default_gateways',
321
+            array(
322
+                'manual'        => 'GetPaid_Manual_Gateway',
323
+                'paypal'        => 'GetPaid_Paypal_Gateway',
324
+                'worldpay'      => 'GetPaid_Worldpay_Gateway',
325
+                'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
326
+                'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
327
+            )
328
+        );
329
+
330
+        foreach ( $gateways as $id => $class ) {
331
+            $this->gateways[ $id ] = new $class();
332
+        }
333
+
334
+        if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
335
+            GetPaid_Installer::rename_gateways_label();
336
+            update_option( 'wpinv_renamed_gateways', 'yes' );
337
+        }
338
+
339
+        // Fires after getpaid inits.
340
+        do_action( 'getpaid_init', $this );
341
+
342
+    }
343
+
344
+    /**
345
+     * Checks if this is an IPN request and processes it.
346
+     */
347
+    public function maybe_process_ipn() {
348
+
349
+        // Ensure that this is an IPN request.
350
+        if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
351
+            return;
352
+        }
353
+
354
+        $gateway = sanitize_text_field( $_GET['wpi-gateway'] );
355
+
356
+        do_action( 'wpinv_verify_payment_ipn', $gateway );
357
+        do_action( "wpinv_verify_{$gateway}_ipn" );
358
+        exit;
359
+
360
+    }
361
+
362
+    public function enqueue_scripts() {
363
+
364
+        // Fires before adding scripts.
365
+        do_action( 'getpaid_enqueue_scripts' );
366
+
367
+        $localize                         = array();
368
+        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
369
+        $localize['thousands']            = wpinv_thousands_separator();
370
+        $localize['decimals']             = wpinv_decimal_separator();
371
+        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
372
+        $localize['txtComplete']          = __( 'Continue', 'invoicing' );
373
+        $localize['UseTaxes']             = wpinv_use_taxes();
374
+        $localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
375
+        $localize['loading']              = __( 'Loading...', 'invoicing' );
376
+        $localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
377
+        $localize['recaptchaSettings']    = getpaid_get_recaptcha_settings();
378
+
379
+        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
380
+
381
+        // reCaptcha.
382
+        if ( getpaid_is_recaptcha_enabled() ) {
383
+            $url = apply_filters(
384
+                'getpaid_recaptcha_api_url',
385
+                add_query_arg(
386
+                    array(
387
+                        'render' => 'v2' === getpaid_get_recaptcha_version() ? 'explicit' : getpaid_get_recaptcha_site_key(),
388
+                    ),
389
+                    'https://www.google.com/recaptcha/api.js'
390
+                )
391
+            );
392
+            wp_enqueue_script( 'recaptcha', $url, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
393
+        }
394
+
395
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
396
+        wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true );
397
+        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
398
+    }
399
+
400
+    public function wpinv_actions() {
401
+        if ( isset( $_REQUEST['wpi_action'] ) ) {
402
+            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
403
+        }
404
+
405
+        if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) {
406
+            include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php';
407
+        }
408
+    }
409
+
410
+    /**
411 411
      * Fires an action after verifying that a user can fire them.
412
-	 *
413
-	 * Note: If the action is on an invoice, subscription etc, esure that the
414
-	 * current user owns the invoice/subscription.
412
+     *
413
+     * Note: If the action is on an invoice, subscription etc, esure that the
414
+     * current user owns the invoice/subscription.
415 415
      */
416 416
     public function maybe_do_authenticated_action() {
417 417
 
418
-		if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
418
+        if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
419 419
 
420
-			$key  = sanitize_key( $_REQUEST['getpaid-action'] );
421
-			$data = wp_unslash( $_REQUEST );
422
-			if ( is_user_logged_in() ) {
423
-				do_action( "getpaid_authenticated_action_$key", $data );
424
-			}
420
+            $key  = sanitize_key( $_REQUEST['getpaid-action'] );
421
+            $data = wp_unslash( $_REQUEST );
422
+            if ( is_user_logged_in() ) {
423
+                do_action( "getpaid_authenticated_action_$key", $data );
424
+            }
425 425
 
426
-			do_action( "getpaid_unauthenticated_action_$key", $data );
426
+            do_action( "getpaid_unauthenticated_action_$key", $data );
427 427
 
428
-		}
428
+        }
429 429
 
430 430
     }
431 431
 
432
-	public function pre_get_posts( $wp_query ) {
433
-
434
-		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() ) {
435
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
436
-		}
437
-
438
-		return $wp_query;
439
-	}
440
-
441
-	/**
442
-	 * Register widgets
443
-	 *
444
-	 */
445
-	public function register_widgets() {
446
-		global $pagenow;
447
-
448
-		// Currently, UX Builder does not work particulaly well with SuperDuper.
449
-		// So we disable our widgets when editing a page with UX Builder.
450
-		if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
451
-			return;
452
-		}
453
-
454
-		$block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array();
455
-
456
-		if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) {
457
-			// don't initiate in these conditions.
458
-		} else {
459
-
460
-			// Only load allowed widgets.
461
-			$exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array();
462
-			$widgets = apply_filters(
463
-				'getpaid_widget_classes',
464
-				array(
465
-					'WPInv_Checkout_Widget',
466
-					'WPInv_History_Widget',
467
-					'WPInv_Receipt_Widget',
468
-					'WPInv_Subscriptions_Widget',
469
-					'WPInv_Buy_Item_Widget',
470
-					'WPInv_Messages_Widget',
471
-					'WPInv_GetPaid_Widget',
472
-					'WPInv_Invoice_Widget',
473
-				)
474
-			);
475
-
476
-			// For each widget...
477
-			foreach ( $widgets as $widget ) {
478
-
479
-				// Abort early if it is excluded for this page.
480
-				if ( in_array( $widget, $exclude ) ) {
481
-					continue;
482
-				}
483
-
484
-				// SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it.
485
-				if ( is_subclass_of( $widget, 'WP_Widget' ) ) {
486
-					register_widget( $widget );
487
-				} else {
488
-					new $widget();
489
-				}
432
+    public function pre_get_posts( $wp_query ) {
433
+
434
+        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() ) {
435
+            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
436
+        }
437
+
438
+        return $wp_query;
439
+    }
440
+
441
+    /**
442
+     * Register widgets
443
+     *
444
+     */
445
+    public function register_widgets() {
446
+        global $pagenow;
447
+
448
+        // Currently, UX Builder does not work particulaly well with SuperDuper.
449
+        // So we disable our widgets when editing a page with UX Builder.
450
+        if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
451
+            return;
452
+        }
453
+
454
+        $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array();
455
+
456
+        if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) {
457
+            // don't initiate in these conditions.
458
+        } else {
459
+
460
+            // Only load allowed widgets.
461
+            $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array();
462
+            $widgets = apply_filters(
463
+                'getpaid_widget_classes',
464
+                array(
465
+                    'WPInv_Checkout_Widget',
466
+                    'WPInv_History_Widget',
467
+                    'WPInv_Receipt_Widget',
468
+                    'WPInv_Subscriptions_Widget',
469
+                    'WPInv_Buy_Item_Widget',
470
+                    'WPInv_Messages_Widget',
471
+                    'WPInv_GetPaid_Widget',
472
+                    'WPInv_Invoice_Widget',
473
+                )
474
+            );
475
+
476
+            // For each widget...
477
+            foreach ( $widgets as $widget ) {
478
+
479
+                // Abort early if it is excluded for this page.
480
+                if ( in_array( $widget, $exclude ) ) {
481
+                    continue;
482
+                }
483
+
484
+                // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it.
485
+                if ( is_subclass_of( $widget, 'WP_Widget' ) ) {
486
+                    register_widget( $widget );
487
+                } else {
488
+                    new $widget();
489
+                }
490 490
 }
491 491
 }
492 492
 
493
-	}
493
+    }
494
+
495
+    /**
496
+     * Upgrades the database.
497
+     *
498
+     * @since 2.0.2
499
+     */
500
+    public function maybe_upgrade_database() {
501
+
502
+        $wpi_version = get_option( 'wpinv_version', 0 );
503
+
504
+        if ( $wpi_version == WPINV_VERSION ) {
505
+            return;
506
+        }
507
+
508
+        $installer = new GetPaid_Installer();
509
+
510
+        if ( empty( $wpi_version ) ) {
511
+            return $installer->upgrade_db( 0 );
512
+        }
513
+
514
+        $upgrades  = array(
515
+            '0.0.5'  => '004',
516
+            '1.0.3'  => '102',
517
+            '2.0.0'  => '118',
518
+            '2.0.8'  => '207',
519
+            '2.6.16' => '2615',
520
+        );
521
+
522
+        foreach ( $upgrades as $key => $method ) {
523
+
524
+            if ( version_compare( $wpi_version, $key, '<' ) ) {
525
+                return $installer->upgrade_db( $method );
526
+            }
527
+        }
528
+
529
+    }
530
+
531
+    /**
532
+     * Flushes the permalinks if needed.
533
+     *
534
+     * @since 2.0.8
535
+     */
536
+    public function maybe_flush_permalinks() {
537
+
538
+        $flush = get_option( 'wpinv_flush_permalinks', 0 );
539
+
540
+        if ( ! empty( $flush ) ) {
541
+            flush_rewrite_rules();
542
+            delete_option( 'wpinv_flush_permalinks' );
543
+        }
544
+
545
+    }
546
+
547
+    /**
548
+     * Remove our pages from yoast sitemaps.
549
+     *
550
+     * @since 1.0.19
551
+     * @param int[] $excluded_posts_ids
552
+     */
553
+    public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) {
554
+
555
+        // Ensure that we have an array.
556
+        if ( ! is_array( $excluded_posts_ids ) ) {
557
+            $excluded_posts_ids = array();
558
+        }
559
+
560
+        // Prepare our pages.
561
+        $our_pages = array();
562
+
563
+        // Checkout page.
564
+        $our_pages[] = wpinv_get_option( 'checkout_page', false );
565
+
566
+        // Success page.
567
+        $our_pages[] = wpinv_get_option( 'success_page', false );
568
+
569
+        // Failure page.
570
+        $our_pages[] = wpinv_get_option( 'failure_page', false );
571
+
572
+        // History page.
573
+        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
494 574
 
495
-	/**
496
-	 * Upgrades the database.
497
-	 *
498
-	 * @since 2.0.2
499
-	 */
500
-	public function maybe_upgrade_database() {
575
+        // Subscriptions page.
576
+        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
501 577
 
502
-		$wpi_version = get_option( 'wpinv_version', 0 );
578
+        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
503 579
 
504
-		if ( $wpi_version == WPINV_VERSION ) {
505
-			return;
506
-		}
580
+        $excluded_posts_ids = $excluded_posts_ids + $our_pages;
581
+        return array_unique( $excluded_posts_ids );
507 582
 
508
-		$installer = new GetPaid_Installer();
583
+    }
584
+
585
+    /**
586
+     * Remove our pages from yoast sitemaps.
587
+     *
588
+     * @since 1.0.19
589
+     * @param string[] $post_types
590
+     */
591
+    public function exclude_invoicing_post_types( $post_types ) {
592
+
593
+        // Ensure that we have an array.
594
+        if ( ! is_array( $post_types ) ) {
595
+            $post_types = array();
596
+        }
597
+
598
+        // Remove our post types.
599
+        return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) );
600
+    }
601
+
602
+    /**
603
+     * Displays additional footer code.
604
+     *
605
+     * @since 2.0.0
606
+     */
607
+    public function wp_footer() {
608
+        wpinv_get_template( 'frontend-footer.php' );
609
+    }
509 610
 
510
-		if ( empty( $wpi_version ) ) {
511
-			return $installer->upgrade_db( 0 );
512
-		}
611
+    /**
612
+     * Displays additional header code.
613
+     *
614
+     * @since 2.0.0
615
+     */
616
+    public function wp_head() {
617
+        wpinv_get_template( 'frontend-head.php' );
618
+    }
513 619
 
514
-		$upgrades  = array(
515
-			'0.0.5'  => '004',
516
-			'1.0.3'  => '102',
517
-			'2.0.0'  => '118',
518
-			'2.0.8'  => '207',
519
-			'2.6.16' => '2615',
520
-		);
521
-
522
-		foreach ( $upgrades as $key => $method ) {
523
-
524
-			if ( version_compare( $wpi_version, $key, '<' ) ) {
525
-				return $installer->upgrade_db( $method );
526
-			}
527
-		}
528
-
529
-	}
530
-
531
-	/**
532
-	 * Flushes the permalinks if needed.
533
-	 *
534
-	 * @since 2.0.8
535
-	 */
536
-	public function maybe_flush_permalinks() {
537
-
538
-		$flush = get_option( 'wpinv_flush_permalinks', 0 );
539
-
540
-		if ( ! empty( $flush ) ) {
541
-			flush_rewrite_rules();
542
-			delete_option( 'wpinv_flush_permalinks' );
543
-		}
544
-
545
-	}
546
-
547
-	/**
548
-	 * Remove our pages from yoast sitemaps.
549
-	 *
550
-	 * @since 1.0.19
551
-	 * @param int[] $excluded_posts_ids
552
-	 */
553
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) {
554
-
555
-		// Ensure that we have an array.
556
-		if ( ! is_array( $excluded_posts_ids ) ) {
557
-			$excluded_posts_ids = array();
558
-		}
559
-
560
-		// Prepare our pages.
561
-		$our_pages = array();
562
-
563
-		// Checkout page.
564
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
565
-
566
-		// Success page.
567
-		$our_pages[] = wpinv_get_option( 'success_page', false );
568
-
569
-		// Failure page.
570
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
571
-
572
-		// History page.
573
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
574
-
575
-		// Subscriptions page.
576
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
577
-
578
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
579
-
580
-		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
581
-		return array_unique( $excluded_posts_ids );
582
-
583
-	}
584
-
585
-	/**
586
-	 * Remove our pages from yoast sitemaps.
587
-	 *
588
-	 * @since 1.0.19
589
-	 * @param string[] $post_types
590
-	 */
591
-	public function exclude_invoicing_post_types( $post_types ) {
592
-
593
-		// Ensure that we have an array.
594
-		if ( ! is_array( $post_types ) ) {
595
-			$post_types = array();
596
-		}
597
-
598
-		// Remove our post types.
599
-		return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) );
600
-	}
601
-
602
-	/**
603
-	 * Displays additional footer code.
604
-	 *
605
-	 * @since 2.0.0
606
-	 */
607
-	public function wp_footer() {
608
-		wpinv_get_template( 'frontend-footer.php' );
609
-	}
610
-
611
-	/**
612
-	 * Displays additional header code.
613
-	 *
614
-	 * @since 2.0.0
615
-	 */
616
-	public function wp_head() {
617
-		wpinv_get_template( 'frontend-head.php' );
618
-	}
619
-
620
-	/**
621
-	 * Custom query vars.
622
-	 *
623
-	 */
624
-	public function custom_query_vars( $vars ) {
620
+    /**
621
+     * Custom query vars.
622
+     *
623
+     */
624
+    public function custom_query_vars( $vars ) {
625 625
         $vars[] = 'getpaid-ipn';
626 626
         return $vars;
627
-	}
627
+    }
628 628
 
629
-	/**
630
-	 * Add rewrite tags and rules.
631
-	 *
632
-	 */
633
-	public function add_rewrite_rule() {
629
+    /**
630
+     * Add rewrite tags and rules.
631
+     *
632
+     */
633
+    public function add_rewrite_rule() {
634 634
         $tag = 'getpaid-ipn';
635 635
         add_rewrite_tag( "%$tag%", '([^&]+)' );
636 636
         add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' );
637
-	}
637
+    }
638 638
 
639
-	/**
640
-	 * Processes non-query string ipns.
641
-	 *
642
-	 */
643
-	public function maybe_process_new_ipn( $query ) {
639
+    /**
640
+     * Processes non-query string ipns.
641
+     *
642
+     */
643
+    public function maybe_process_new_ipn( $query ) {
644 644
 
645 645
         if ( is_admin() || ! $query->is_main_query() ) {
646 646
             return;
647 647
         }
648 648
 
649
-		$gateway = get_query_var( 'getpaid-ipn' );
649
+        $gateway = get_query_var( 'getpaid-ipn' );
650 650
 
651 651
         if ( ! empty( $gateway ) ) {
652 652
 
653
-			$gateway = sanitize_text_field( $gateway );
654
-			nocache_headers();
655
-			do_action( 'wpinv_verify_payment_ipn', $gateway );
656
-			do_action( "wpinv_verify_{$gateway}_ipn" );
657
-			exit;
653
+            $gateway = sanitize_text_field( $gateway );
654
+            nocache_headers();
655
+            do_action( 'wpinv_verify_payment_ipn', $gateway );
656
+            do_action( "wpinv_verify_{$gateway}_ipn" );
657
+            exit;
658 658
 
659 659
         }
660 660
 
661
-	}
661
+    }
662 662
 
663 663
 }
Please login to merge, or discard this patch.