@@ -13,30 +13,30 @@ discard block |
||
13 | 13 | class GetPaid_Bank_Transfer_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'bank_transfer'; |
21 | 21 | |
22 | - /** |
|
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
22 | + /** |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
34 | - public $order = 8; |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | + public $order = 8; |
|
35 | 35 | |
36 | 36 | /** |
37 | - * Class constructor. |
|
38 | - */ |
|
39 | - public function __construct() { |
|
37 | + * Class constructor. |
|
38 | + */ |
|
39 | + public function __construct() { |
|
40 | 40 | parent::__construct(); |
41 | 41 | |
42 | 42 | $this->title = __( 'Direct bank transfer', 'invoicing' ); |
@@ -44,24 +44,24 @@ discard block |
||
44 | 44 | $this->checkout_button_text = __( 'Proceed', 'invoicing' ); |
45 | 45 | $this->instructions = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) ); |
46 | 46 | |
47 | - add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
48 | - add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
49 | - add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
50 | - add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
51 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
52 | - add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 ); |
|
47 | + add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
48 | + add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
49 | + add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
50 | + add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
51 | + add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
52 | + add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 ); |
|
53 | 53 | |
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
57 | - * Process Payment. |
|
58 | - * |
|
59 | - * @param WPInv_Invoice $invoice Invoice. |
|
60 | - * @param array $submission_data Posted checkout fields. |
|
61 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
62 | - * @return array |
|
63 | - */ |
|
64 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
57 | + * Process Payment. |
|
58 | + * |
|
59 | + * @param WPInv_Invoice $invoice Invoice. |
|
60 | + * @param array $submission_data Posted checkout fields. |
|
61 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
62 | + * @return array |
|
63 | + */ |
|
64 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
65 | 65 | |
66 | 66 | // Add a transaction id. |
67 | 67 | $invoice->set_transaction_id( $invoice->generate_key( 'bt_' ) ); |
@@ -82,66 +82,66 @@ discard block |
||
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | - * Output for the order received page. |
|
86 | - * |
|
87 | - * @param WPInv_Invoice $invoice Invoice. |
|
88 | - */ |
|
89 | - public function thankyou_page( $invoice ) { |
|
85 | + * Output for the order received page. |
|
86 | + * |
|
87 | + * @param WPInv_Invoice $invoice Invoice. |
|
88 | + */ |
|
89 | + public function thankyou_page( $invoice ) { |
|
90 | 90 | |
91 | 91 | if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
92 | 92 | |
93 | - echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
93 | + echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
94 | 94 | |
95 | 95 | if ( ! empty( $this->instructions ) ) { |
96 | 96 | echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) ); |
97 | - } |
|
97 | + } |
|
98 | 98 | |
99 | - $this->bank_details( $invoice ); |
|
99 | + $this->bank_details( $invoice ); |
|
100 | 100 | |
101 | - echo '</div>'; |
|
101 | + echo '</div>'; |
|
102 | 102 | |
103 | 103 | } |
104 | 104 | |
105 | - } |
|
105 | + } |
|
106 | 106 | |
107 | 107 | /** |
108 | - * Add content to the WPI emails. |
|
109 | - * |
|
110 | - * @param WPInv_Invoice $invoice Invoice. |
|
111 | - * @param string $email_type Email format: plain text or HTML. |
|
112 | - * @param bool $sent_to_admin Sent to admin. |
|
113 | - */ |
|
114 | - public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
108 | + * Add content to the WPI emails. |
|
109 | + * |
|
110 | + * @param WPInv_Invoice $invoice Invoice. |
|
111 | + * @param string $email_type Email format: plain text or HTML. |
|
112 | + * @param bool $sent_to_admin Sent to admin. |
|
113 | + */ |
|
114 | + public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
115 | 115 | |
116 | - if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
116 | + if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
117 | 117 | |
118 | - echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
118 | + echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
119 | 119 | |
120 | - if ( $this->instructions ) { |
|
121 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
120 | + if ( $this->instructions ) { |
|
121 | + echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
122 | 122 | } |
123 | 123 | |
124 | - $this->bank_details( $invoice ); |
|
124 | + $this->bank_details( $invoice ); |
|
125 | 125 | |
126 | - echo '</div>'; |
|
126 | + echo '</div>'; |
|
127 | 127 | |
128 | - } |
|
128 | + } |
|
129 | 129 | |
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
133 | - * Get bank details and place into a list format. |
|
134 | - * |
|
135 | - * @param WPInv_Invoice $invoice Invoice. |
|
136 | - */ |
|
137 | - protected function bank_details( $invoice ) { |
|
133 | + * Get bank details and place into a list format. |
|
134 | + * |
|
135 | + * @param WPInv_Invoice $invoice Invoice. |
|
136 | + */ |
|
137 | + protected function bank_details( $invoice ) { |
|
138 | 138 | |
139 | - // Get the invoice country and country $locale. |
|
140 | - $country = $invoice->get_country(); |
|
141 | - $locale = $this->get_country_locale(); |
|
139 | + // Get the invoice country and country $locale. |
|
140 | + $country = $invoice->get_country(); |
|
141 | + $locale = $this->get_country_locale(); |
|
142 | 142 | |
143 | - // Get sortcode label in the $locale array and use appropriate one. |
|
144 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
143 | + // Get sortcode label in the $locale array and use appropriate one. |
|
144 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
145 | 145 | |
146 | 146 | $bank_fields = array( |
147 | 147 | 'ac_name' => __( 'Account Name', 'invoicing' ), |
@@ -160,11 +160,11 @@ discard block |
||
160 | 160 | |
161 | 161 | if ( ! empty( $value ) ) { |
162 | 162 | $bank_info[ $field ] = array( |
163 | - 'label' => $label, |
|
164 | - 'value' => $value, |
|
165 | - ); |
|
163 | + 'label' => $label, |
|
164 | + 'value' => $value, |
|
165 | + ); |
|
166 | 166 | } |
167 | - } |
|
167 | + } |
|
168 | 168 | |
169 | 169 | $bank_info = apply_filters( 'wpinv_bank_info', $bank_info, $invoice ); |
170 | 170 | |
@@ -172,139 +172,139 @@ discard block |
||
172 | 172 | return; |
173 | 173 | } |
174 | 174 | |
175 | - echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL; |
|
175 | + echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL; |
|
176 | + |
|
177 | + echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
178 | + |
|
179 | + foreach ( $bank_info as $key => $data ) { |
|
180 | + echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL; |
|
181 | + } |
|
182 | + |
|
183 | + echo '</table>'; |
|
176 | 184 | |
177 | - echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
185 | + } |
|
178 | 186 | |
179 | - foreach ( $bank_info as $key => $data ) { |
|
180 | - echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL; |
|
181 | - } |
|
187 | + /** |
|
188 | + * Get country locale if localized. |
|
189 | + * |
|
190 | + * @return array |
|
191 | + */ |
|
192 | + public function get_country_locale() { |
|
193 | + |
|
194 | + if ( empty( $this->locale ) ) { |
|
195 | + |
|
196 | + // Locale information to be used - only those that are not 'Sort Code'. |
|
197 | + $this->locale = apply_filters( |
|
198 | + 'getpaid_get_bank_transfer_locale', |
|
199 | + array( |
|
200 | + 'AU' => array( |
|
201 | + 'sortcode' => array( |
|
202 | + 'label' => __( 'BSB', 'invoicing' ), |
|
203 | + ), |
|
204 | + ), |
|
205 | + 'CA' => array( |
|
206 | + 'sortcode' => array( |
|
207 | + 'label' => __( 'Bank transit number', 'invoicing' ), |
|
208 | + ), |
|
209 | + ), |
|
210 | + 'IN' => array( |
|
211 | + 'sortcode' => array( |
|
212 | + 'label' => __( 'IFSC', 'invoicing' ), |
|
213 | + ), |
|
214 | + ), |
|
215 | + 'IT' => array( |
|
216 | + 'sortcode' => array( |
|
217 | + 'label' => __( 'Branch sort', 'invoicing' ), |
|
218 | + ), |
|
219 | + ), |
|
220 | + 'NZ' => array( |
|
221 | + 'sortcode' => array( |
|
222 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
223 | + ), |
|
224 | + ), |
|
225 | + 'SE' => array( |
|
226 | + 'sortcode' => array( |
|
227 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
228 | + ), |
|
229 | + ), |
|
230 | + 'US' => array( |
|
231 | + 'sortcode' => array( |
|
232 | + 'label' => __( 'Routing number', 'invoicing' ), |
|
233 | + ), |
|
234 | + ), |
|
235 | + 'ZA' => array( |
|
236 | + 'sortcode' => array( |
|
237 | + 'label' => __( 'Branch code', 'invoicing' ), |
|
238 | + ), |
|
239 | + ), |
|
240 | + ) |
|
241 | + ); |
|
182 | 242 | |
183 | - echo '</table>'; |
|
243 | + } |
|
244 | + |
|
245 | + return $this->locale; |
|
184 | 246 | |
185 | 247 | } |
186 | 248 | |
187 | 249 | /** |
188 | - * Get country locale if localized. |
|
189 | - * |
|
190 | - * @return array |
|
191 | - */ |
|
192 | - public function get_country_locale() { |
|
193 | - |
|
194 | - if ( empty( $this->locale ) ) { |
|
195 | - |
|
196 | - // Locale information to be used - only those that are not 'Sort Code'. |
|
197 | - $this->locale = apply_filters( |
|
198 | - 'getpaid_get_bank_transfer_locale', |
|
199 | - array( |
|
200 | - 'AU' => array( |
|
201 | - 'sortcode' => array( |
|
202 | - 'label' => __( 'BSB', 'invoicing' ), |
|
203 | - ), |
|
204 | - ), |
|
205 | - 'CA' => array( |
|
206 | - 'sortcode' => array( |
|
207 | - 'label' => __( 'Bank transit number', 'invoicing' ), |
|
208 | - ), |
|
209 | - ), |
|
210 | - 'IN' => array( |
|
211 | - 'sortcode' => array( |
|
212 | - 'label' => __( 'IFSC', 'invoicing' ), |
|
213 | - ), |
|
214 | - ), |
|
215 | - 'IT' => array( |
|
216 | - 'sortcode' => array( |
|
217 | - 'label' => __( 'Branch sort', 'invoicing' ), |
|
218 | - ), |
|
219 | - ), |
|
220 | - 'NZ' => array( |
|
221 | - 'sortcode' => array( |
|
222 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
223 | - ), |
|
224 | - ), |
|
225 | - 'SE' => array( |
|
226 | - 'sortcode' => array( |
|
227 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
228 | - ), |
|
229 | - ), |
|
230 | - 'US' => array( |
|
231 | - 'sortcode' => array( |
|
232 | - 'label' => __( 'Routing number', 'invoicing' ), |
|
233 | - ), |
|
234 | - ), |
|
235 | - 'ZA' => array( |
|
236 | - 'sortcode' => array( |
|
237 | - 'label' => __( 'Branch code', 'invoicing' ), |
|
238 | - ), |
|
239 | - ), |
|
240 | - ) |
|
241 | - ); |
|
242 | - |
|
243 | - } |
|
244 | - |
|
245 | - return $this->locale; |
|
246 | - |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * Filters the gateway settings. |
|
251 | - * |
|
252 | - * @param array $admin_settings |
|
253 | - */ |
|
254 | - public function admin_settings( $admin_settings ) { |
|
250 | + * Filters the gateway settings. |
|
251 | + * |
|
252 | + * @param array $admin_settings |
|
253 | + */ |
|
254 | + public function admin_settings( $admin_settings ) { |
|
255 | 255 | |
256 | 256 | $admin_settings['bank_transfer_desc']['std'] = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ); |
257 | - $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
257 | + $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
258 | 258 | |
259 | - $locale = $this->get_country_locale(); |
|
259 | + $locale = $this->get_country_locale(); |
|
260 | 260 | |
261 | - // Get sortcode label in the $locale array and use appropriate one. |
|
262 | - $country = wpinv_default_billing_country(); |
|
263 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
261 | + // Get sortcode label in the $locale array and use appropriate one. |
|
262 | + $country = wpinv_default_billing_country(); |
|
263 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
264 | 264 | |
265 | - $admin_settings['bank_transfer_ac_name'] = array( |
|
265 | + $admin_settings['bank_transfer_ac_name'] = array( |
|
266 | 266 | 'type' => 'text', |
267 | 267 | 'id' => 'bank_transfer_ac_name', |
268 | 268 | 'name' => __( 'Account Name', 'invoicing' ), |
269 | - ); |
|
269 | + ); |
|
270 | 270 | |
271 | - $admin_settings['bank_transfer_ac_no'] = array( |
|
271 | + $admin_settings['bank_transfer_ac_no'] = array( |
|
272 | 272 | 'type' => 'text', |
273 | 273 | 'id' => 'bank_transfer_ac_no', |
274 | 274 | 'name' => __( 'Account Number', 'invoicing' ), |
275 | - ); |
|
275 | + ); |
|
276 | 276 | |
277 | - $admin_settings['bank_transfer_bank_name'] = array( |
|
277 | + $admin_settings['bank_transfer_bank_name'] = array( |
|
278 | 278 | 'type' => 'text', |
279 | 279 | 'id' => 'bank_transfer_bank_name', |
280 | 280 | 'name' => __( 'Bank Name', 'invoicing' ), |
281 | - ); |
|
281 | + ); |
|
282 | 282 | |
283 | - $admin_settings['bank_transfer_ifsc'] = array( |
|
283 | + $admin_settings['bank_transfer_ifsc'] = array( |
|
284 | 284 | 'type' => 'text', |
285 | 285 | 'id' => 'bank_transfer_ifsc', |
286 | 286 | 'name' => __( 'IFSC Code', 'invoicing' ), |
287 | - ); |
|
287 | + ); |
|
288 | 288 | |
289 | - $admin_settings['bank_transfer_iban'] = array( |
|
289 | + $admin_settings['bank_transfer_iban'] = array( |
|
290 | 290 | 'type' => 'text', |
291 | 291 | 'id' => 'bank_transfer_iban', |
292 | 292 | 'name' => __( 'IBAN', 'invoicing' ), |
293 | - ); |
|
293 | + ); |
|
294 | 294 | |
295 | - $admin_settings['bank_transfer_bic'] = array( |
|
295 | + $admin_settings['bank_transfer_bic'] = array( |
|
296 | 296 | 'type' => 'text', |
297 | 297 | 'id' => 'bank_transfer_bic', |
298 | 298 | 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
299 | - ); |
|
299 | + ); |
|
300 | 300 | |
301 | - $admin_settings['bank_transfer_sort_code'] = array( |
|
302 | - 'type' => 'text', |
|
303 | - 'id' => 'bank_transfer_sort_code', |
|
304 | - 'name' => $sortcode, |
|
305 | - ); |
|
301 | + $admin_settings['bank_transfer_sort_code'] = array( |
|
302 | + 'type' => 'text', |
|
303 | + 'id' => 'bank_transfer_sort_code', |
|
304 | + 'name' => $sortcode, |
|
305 | + ); |
|
306 | 306 | |
307 | - $admin_settings['bank_transfer_info'] = array( |
|
307 | + $admin_settings['bank_transfer_info'] = array( |
|
308 | 308 | 'id' => 'bank_transfer_info', |
309 | 309 | 'name' => __( 'Instructions', 'invoicing' ), |
310 | 310 | 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
@@ -314,17 +314,17 @@ discard block |
||
314 | 314 | 'rows' => 5, |
315 | 315 | ); |
316 | 316 | |
317 | - return $admin_settings; |
|
318 | - } |
|
317 | + return $admin_settings; |
|
318 | + } |
|
319 | 319 | |
320 | - /** |
|
321 | - * Processes invoice addons. |
|
322 | - * |
|
323 | - * @param WPInv_Invoice $invoice |
|
324 | - * @param GetPaid_Form_Item[] $items |
|
325 | - * @return WPInv_Invoice |
|
326 | - */ |
|
327 | - public function process_addons( $invoice, $items ) { |
|
320 | + /** |
|
321 | + * Processes invoice addons. |
|
322 | + * |
|
323 | + * @param WPInv_Invoice $invoice |
|
324 | + * @param GetPaid_Form_Item[] $items |
|
325 | + * @return WPInv_Invoice |
|
326 | + */ |
|
327 | + public function process_addons( $invoice, $items ) { |
|
328 | 328 | |
329 | 329 | foreach ( $items as $item ) { |
330 | 330 | $invoice->add_item( $item ); |
@@ -332,66 +332,66 @@ discard block |
||
332 | 332 | |
333 | 333 | $invoice->recalculate_total(); |
334 | 334 | $invoice->save(); |
335 | - } |
|
335 | + } |
|
336 | 336 | |
337 | - /** |
|
338 | - * (Maybe) renews a bank transfer subscription profile. |
|
339 | - * |
|
340 | - * |
|
337 | + /** |
|
338 | + * (Maybe) renews a bank transfer subscription profile. |
|
339 | + * |
|
340 | + * |
|
341 | 341 | * @param WPInv_Subscription $subscription |
342 | - */ |
|
343 | - public function maybe_renew_subscription( $subscription ) { |
|
342 | + */ |
|
343 | + public function maybe_renew_subscription( $subscription ) { |
|
344 | 344 | |
345 | 345 | // Ensure its our subscription && it's active. |
346 | 346 | if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
347 | - $subscription->create_payment(); |
|
347 | + $subscription->create_payment(); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | } |
351 | 351 | |
352 | - /** |
|
353 | - * Process a bank transfer payment. |
|
354 | - * |
|
355 | - * |
|
352 | + /** |
|
353 | + * Process a bank transfer payment. |
|
354 | + * |
|
355 | + * |
|
356 | 356 | * @param WPInv_Invoice $invoice |
357 | - */ |
|
358 | - public function invoice_paid( $invoice ) { |
|
359 | - |
|
360 | - // Abort if not paid by bank transfer. |
|
361 | - if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) { |
|
362 | - return; |
|
363 | - } |
|
364 | - |
|
365 | - // Is it a parent payment? |
|
366 | - if ( 0 == $invoice->get_parent_id() ) { |
|
367 | - |
|
368 | - // (Maybe) activate subscriptions. |
|
369 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
370 | - |
|
371 | - if ( ! empty( $subscriptions ) ) { |
|
372 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
373 | - |
|
374 | - foreach ( $subscriptions as $subscription ) { |
|
375 | - if ( $subscription->exists() ) { |
|
376 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
377 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
378 | - |
|
379 | - $subscription->set_next_renewal_date( $expiry ); |
|
380 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
381 | - $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ); |
|
382 | - $subscription->activate(); |
|
383 | - } |
|
384 | - } |
|
357 | + */ |
|
358 | + public function invoice_paid( $invoice ) { |
|
359 | + |
|
360 | + // Abort if not paid by bank transfer. |
|
361 | + if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) { |
|
362 | + return; |
|
363 | + } |
|
364 | + |
|
365 | + // Is it a parent payment? |
|
366 | + if ( 0 == $invoice->get_parent_id() ) { |
|
367 | + |
|
368 | + // (Maybe) activate subscriptions. |
|
369 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
370 | + |
|
371 | + if ( ! empty( $subscriptions ) ) { |
|
372 | + $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
373 | + |
|
374 | + foreach ( $subscriptions as $subscription ) { |
|
375 | + if ( $subscription->exists() ) { |
|
376 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
377 | + $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
378 | + |
|
379 | + $subscription->set_next_renewal_date( $expiry ); |
|
380 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
381 | + $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ); |
|
382 | + $subscription->activate(); |
|
383 | + } |
|
384 | + } |
|
385 | 385 | } |
386 | 386 | } else { |
387 | 387 | |
388 | - $subscription = getpaid_get_subscription( $invoice->get_subscription_id() ); |
|
388 | + $subscription = getpaid_get_subscription( $invoice->get_subscription_id() ); |
|
389 | 389 | |
390 | - // Renew the subscription. |
|
391 | - if ( $subscription && $subscription->exists() ) { |
|
392 | - $subscription->add_payment( array(), $invoice ); |
|
393 | - $subscription->renew(); |
|
394 | - } |
|
390 | + // Renew the subscription. |
|
391 | + if ( $subscription && $subscription->exists() ) { |
|
392 | + $subscription->add_payment( array(), $invoice ); |
|
393 | + $subscription->renew(); |
|
394 | + } |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Bank transfer Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
27 | + protected $supports = array('subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -39,17 +39,17 @@ discard block |
||
39 | 39 | public function __construct() { |
40 | 40 | parent::__construct(); |
41 | 41 | |
42 | - $this->title = __( 'Direct bank transfer', 'invoicing' ); |
|
43 | - $this->method_title = __( 'Bank transfer', 'invoicing' ); |
|
44 | - $this->checkout_button_text = __( 'Proceed', 'invoicing' ); |
|
45 | - $this->instructions = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) ); |
|
42 | + $this->title = __('Direct bank transfer', 'invoicing'); |
|
43 | + $this->method_title = __('Bank transfer', 'invoicing'); |
|
44 | + $this->checkout_button_text = __('Proceed', 'invoicing'); |
|
45 | + $this->instructions = apply_filters('wpinv_bank_instructions', $this->get_option('info')); |
|
46 | 46 | |
47 | - add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
48 | - add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
49 | - add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
50 | - add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
51 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
52 | - add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 ); |
|
47 | + add_action('wpinv_receipt_end', array($this, 'thankyou_page')); |
|
48 | + add_action('getpaid_invoice_line_items', array($this, 'thankyou_page'), 40); |
|
49 | + add_action('wpinv_pdf_content_billing', array($this, 'thankyou_page'), 11); |
|
50 | + add_action('wpinv_email_invoice_details', array($this, 'email_instructions'), 10, 3); |
|
51 | + add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription')); |
|
52 | + add_action('getpaid_invoice_status_publish', array($this, 'invoice_paid'), 20); |
|
53 | 53 | |
54 | 54 | } |
55 | 55 | |
@@ -61,23 +61,23 @@ discard block |
||
61 | 61 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
62 | 62 | * @return array |
63 | 63 | */ |
64 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
64 | + public function process_payment($invoice, $submission_data, $submission) { |
|
65 | 65 | |
66 | 66 | // Add a transaction id. |
67 | - $invoice->set_transaction_id( $invoice->generate_key( 'bt_' ) ); |
|
67 | + $invoice->set_transaction_id($invoice->generate_key('bt_')); |
|
68 | 68 | |
69 | 69 | // Set it as pending payment. |
70 | - if ( ! $invoice->needs_payment() ) { |
|
70 | + if (!$invoice->needs_payment()) { |
|
71 | 71 | $invoice->mark_paid(); |
72 | - } elseif ( ! $invoice->is_paid() ) { |
|
73 | - $invoice->set_status( 'wpi-onhold' ); |
|
72 | + } elseif (!$invoice->is_paid()) { |
|
73 | + $invoice->set_status('wpi-onhold'); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | // Save it. |
77 | 77 | $invoice->save(); |
78 | 78 | |
79 | 79 | // Send to the success page. |
80 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
80 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
81 | 81 | |
82 | 82 | } |
83 | 83 | |
@@ -86,17 +86,17 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @param WPInv_Invoice $invoice Invoice. |
88 | 88 | */ |
89 | - public function thankyou_page( $invoice ) { |
|
89 | + public function thankyou_page($invoice) { |
|
90 | 90 | |
91 | - if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
91 | + if ('bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment()) { |
|
92 | 92 | |
93 | 93 | echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
94 | 94 | |
95 | - if ( ! empty( $this->instructions ) ) { |
|
96 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) ); |
|
95 | + if (!empty($this->instructions)) { |
|
96 | + echo wp_kses_post(wpautop(wptexturize($this->instructions))); |
|
97 | 97 | } |
98 | 98 | |
99 | - $this->bank_details( $invoice ); |
|
99 | + $this->bank_details($invoice); |
|
100 | 100 | |
101 | 101 | echo '</div>'; |
102 | 102 | |
@@ -111,17 +111,17 @@ discard block |
||
111 | 111 | * @param string $email_type Email format: plain text or HTML. |
112 | 112 | * @param bool $sent_to_admin Sent to admin. |
113 | 113 | */ |
114 | - public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
114 | + public function email_instructions($invoice, $email_type, $sent_to_admin) { |
|
115 | 115 | |
116 | - if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
116 | + if (!$sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment()) { |
|
117 | 117 | |
118 | 118 | echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
119 | 119 | |
120 | - if ( $this->instructions ) { |
|
121 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
120 | + if ($this->instructions) { |
|
121 | + echo wp_kses_post(wpautop(wptexturize($this->instructions)) . PHP_EOL); |
|
122 | 122 | } |
123 | 123 | |
124 | - $this->bank_details( $invoice ); |
|
124 | + $this->bank_details($invoice); |
|
125 | 125 | |
126 | 126 | echo '</div>'; |
127 | 127 | |
@@ -134,50 +134,50 @@ discard block |
||
134 | 134 | * |
135 | 135 | * @param WPInv_Invoice $invoice Invoice. |
136 | 136 | */ |
137 | - protected function bank_details( $invoice ) { |
|
137 | + protected function bank_details($invoice) { |
|
138 | 138 | |
139 | 139 | // Get the invoice country and country $locale. |
140 | 140 | $country = $invoice->get_country(); |
141 | 141 | $locale = $this->get_country_locale(); |
142 | 142 | |
143 | 143 | // Get sortcode label in the $locale array and use appropriate one. |
144 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
144 | + $sortcode = isset($locale[$country]['sortcode']['label']) ? $locale[$country]['sortcode']['label'] : __('Sort code', 'invoicing'); |
|
145 | 145 | |
146 | 146 | $bank_fields = array( |
147 | - 'ac_name' => __( 'Account Name', 'invoicing' ), |
|
148 | - 'ac_no' => __( 'Account Number', 'invoicing' ), |
|
149 | - 'bank_name' => __( 'Bank Name', 'invoicing' ), |
|
150 | - 'ifsc' => __( 'IFSC code', 'invoicing' ), |
|
151 | - 'iban' => __( 'IBAN', 'invoicing' ), |
|
152 | - 'bic' => __( 'BIC/Swift code', 'invoicing' ), |
|
147 | + 'ac_name' => __('Account Name', 'invoicing'), |
|
148 | + 'ac_no' => __('Account Number', 'invoicing'), |
|
149 | + 'bank_name' => __('Bank Name', 'invoicing'), |
|
150 | + 'ifsc' => __('IFSC code', 'invoicing'), |
|
151 | + 'iban' => __('IBAN', 'invoicing'), |
|
152 | + 'bic' => __('BIC/Swift code', 'invoicing'), |
|
153 | 153 | 'sort_code' => $sortcode, |
154 | 154 | ); |
155 | 155 | |
156 | 156 | $bank_info = array(); |
157 | 157 | |
158 | - foreach ( $bank_fields as $field => $label ) { |
|
159 | - $value = $this->get_option( $field ); |
|
158 | + foreach ($bank_fields as $field => $label) { |
|
159 | + $value = $this->get_option($field); |
|
160 | 160 | |
161 | - if ( ! empty( $value ) ) { |
|
162 | - $bank_info[ $field ] = array( |
|
161 | + if (!empty($value)) { |
|
162 | + $bank_info[$field] = array( |
|
163 | 163 | 'label' => $label, |
164 | 164 | 'value' => $value, |
165 | 165 | ); |
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
169 | - $bank_info = apply_filters( 'wpinv_bank_info', $bank_info, $invoice ); |
|
169 | + $bank_info = apply_filters('wpinv_bank_info', $bank_info, $invoice); |
|
170 | 170 | |
171 | - if ( empty( $bank_info ) ) { |
|
171 | + if (empty($bank_info)) { |
|
172 | 172 | return; |
173 | 173 | } |
174 | 174 | |
175 | - echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL; |
|
175 | + echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html(apply_filters('wpinv_receipt_bank_details_title', __('Bank Details', 'invoicing'), $invoice)) . '</h3>' . PHP_EOL; |
|
176 | 176 | |
177 | 177 | echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
178 | 178 | |
179 | - foreach ( $bank_info as $key => $data ) { |
|
180 | - echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL; |
|
179 | + foreach ($bank_info as $key => $data) { |
|
180 | + echo "<tr class='getpaid-bank-transfer-" . esc_attr($key) . "'><th class='font-weight-bold'>" . wp_kses_post($data['label']) . "</th><td class='w-75'>" . wp_kses_post(wptexturize($data['value'])) . '</td></tr>' . PHP_EOL; |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | echo '</table>'; |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | */ |
192 | 192 | public function get_country_locale() { |
193 | 193 | |
194 | - if ( empty( $this->locale ) ) { |
|
194 | + if (empty($this->locale)) { |
|
195 | 195 | |
196 | 196 | // Locale information to be used - only those that are not 'Sort Code'. |
197 | 197 | $this->locale = apply_filters( |
@@ -199,42 +199,42 @@ discard block |
||
199 | 199 | array( |
200 | 200 | 'AU' => array( |
201 | 201 | 'sortcode' => array( |
202 | - 'label' => __( 'BSB', 'invoicing' ), |
|
202 | + 'label' => __('BSB', 'invoicing'), |
|
203 | 203 | ), |
204 | 204 | ), |
205 | 205 | 'CA' => array( |
206 | 206 | 'sortcode' => array( |
207 | - 'label' => __( 'Bank transit number', 'invoicing' ), |
|
207 | + 'label' => __('Bank transit number', 'invoicing'), |
|
208 | 208 | ), |
209 | 209 | ), |
210 | 210 | 'IN' => array( |
211 | 211 | 'sortcode' => array( |
212 | - 'label' => __( 'IFSC', 'invoicing' ), |
|
212 | + 'label' => __('IFSC', 'invoicing'), |
|
213 | 213 | ), |
214 | 214 | ), |
215 | 215 | 'IT' => array( |
216 | 216 | 'sortcode' => array( |
217 | - 'label' => __( 'Branch sort', 'invoicing' ), |
|
217 | + 'label' => __('Branch sort', 'invoicing'), |
|
218 | 218 | ), |
219 | 219 | ), |
220 | 220 | 'NZ' => array( |
221 | 221 | 'sortcode' => array( |
222 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
222 | + 'label' => __('Bank code', 'invoicing'), |
|
223 | 223 | ), |
224 | 224 | ), |
225 | 225 | 'SE' => array( |
226 | 226 | 'sortcode' => array( |
227 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
227 | + 'label' => __('Bank code', 'invoicing'), |
|
228 | 228 | ), |
229 | 229 | ), |
230 | 230 | 'US' => array( |
231 | 231 | 'sortcode' => array( |
232 | - 'label' => __( 'Routing number', 'invoicing' ), |
|
232 | + 'label' => __('Routing number', 'invoicing'), |
|
233 | 233 | ), |
234 | 234 | ), |
235 | 235 | 'ZA' => array( |
236 | 236 | 'sortcode' => array( |
237 | - 'label' => __( 'Branch code', 'invoicing' ), |
|
237 | + 'label' => __('Branch code', 'invoicing'), |
|
238 | 238 | ), |
239 | 239 | ), |
240 | 240 | ) |
@@ -251,51 +251,51 @@ discard block |
||
251 | 251 | * |
252 | 252 | * @param array $admin_settings |
253 | 253 | */ |
254 | - public function admin_settings( $admin_settings ) { |
|
254 | + public function admin_settings($admin_settings) { |
|
255 | 255 | |
256 | - $admin_settings['bank_transfer_desc']['std'] = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ); |
|
257 | - $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
256 | + $admin_settings['bank_transfer_desc']['std'] = __("Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing'); |
|
257 | + $admin_settings['bank_transfer_active']['desc'] = __('Enable bank transfer', 'invoicing'); |
|
258 | 258 | |
259 | - $locale = $this->get_country_locale(); |
|
259 | + $locale = $this->get_country_locale(); |
|
260 | 260 | |
261 | 261 | // Get sortcode label in the $locale array and use appropriate one. |
262 | 262 | $country = wpinv_default_billing_country(); |
263 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
263 | + $sortcode = isset($locale[$country]['sortcode']['label']) ? $locale[$country]['sortcode']['label'] : __('Sort code', 'invoicing'); |
|
264 | 264 | |
265 | 265 | $admin_settings['bank_transfer_ac_name'] = array( |
266 | 266 | 'type' => 'text', |
267 | 267 | 'id' => 'bank_transfer_ac_name', |
268 | - 'name' => __( 'Account Name', 'invoicing' ), |
|
268 | + 'name' => __('Account Name', 'invoicing'), |
|
269 | 269 | ); |
270 | 270 | |
271 | 271 | $admin_settings['bank_transfer_ac_no'] = array( |
272 | 272 | 'type' => 'text', |
273 | 273 | 'id' => 'bank_transfer_ac_no', |
274 | - 'name' => __( 'Account Number', 'invoicing' ), |
|
274 | + 'name' => __('Account Number', 'invoicing'), |
|
275 | 275 | ); |
276 | 276 | |
277 | 277 | $admin_settings['bank_transfer_bank_name'] = array( |
278 | 278 | 'type' => 'text', |
279 | 279 | 'id' => 'bank_transfer_bank_name', |
280 | - 'name' => __( 'Bank Name', 'invoicing' ), |
|
280 | + 'name' => __('Bank Name', 'invoicing'), |
|
281 | 281 | ); |
282 | 282 | |
283 | 283 | $admin_settings['bank_transfer_ifsc'] = array( |
284 | 284 | 'type' => 'text', |
285 | 285 | 'id' => 'bank_transfer_ifsc', |
286 | - 'name' => __( 'IFSC Code', 'invoicing' ), |
|
286 | + 'name' => __('IFSC Code', 'invoicing'), |
|
287 | 287 | ); |
288 | 288 | |
289 | 289 | $admin_settings['bank_transfer_iban'] = array( |
290 | 290 | 'type' => 'text', |
291 | 291 | 'id' => 'bank_transfer_iban', |
292 | - 'name' => __( 'IBAN', 'invoicing' ), |
|
292 | + 'name' => __('IBAN', 'invoicing'), |
|
293 | 293 | ); |
294 | 294 | |
295 | 295 | $admin_settings['bank_transfer_bic'] = array( |
296 | 296 | 'type' => 'text', |
297 | 297 | 'id' => 'bank_transfer_bic', |
298 | - 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
|
298 | + 'name' => __('BIC/Swift Code', 'invoicing'), |
|
299 | 299 | ); |
300 | 300 | |
301 | 301 | $admin_settings['bank_transfer_sort_code'] = array( |
@@ -306,10 +306,10 @@ discard block |
||
306 | 306 | |
307 | 307 | $admin_settings['bank_transfer_info'] = array( |
308 | 308 | 'id' => 'bank_transfer_info', |
309 | - 'name' => __( 'Instructions', 'invoicing' ), |
|
310 | - 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
|
309 | + 'name' => __('Instructions', 'invoicing'), |
|
310 | + 'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'), |
|
311 | 311 | 'type' => 'textarea', |
312 | - 'std' => __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ), |
|
312 | + 'std' => __("Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing'), |
|
313 | 313 | 'cols' => 50, |
314 | 314 | 'rows' => 5, |
315 | 315 | ); |
@@ -324,10 +324,10 @@ discard block |
||
324 | 324 | * @param GetPaid_Form_Item[] $items |
325 | 325 | * @return WPInv_Invoice |
326 | 326 | */ |
327 | - public function process_addons( $invoice, $items ) { |
|
327 | + public function process_addons($invoice, $items) { |
|
328 | 328 | |
329 | - foreach ( $items as $item ) { |
|
330 | - $invoice->add_item( $item ); |
|
329 | + foreach ($items as $item) { |
|
330 | + $invoice->add_item($item); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | $invoice->recalculate_total(); |
@@ -340,10 +340,10 @@ discard block |
||
340 | 340 | * |
341 | 341 | * @param WPInv_Subscription $subscription |
342 | 342 | */ |
343 | - public function maybe_renew_subscription( $subscription ) { |
|
343 | + public function maybe_renew_subscription($subscription) { |
|
344 | 344 | |
345 | 345 | // Ensure its our subscription && it's active. |
346 | - if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
346 | + if ($this->id === $subscription->get_gateway() && $subscription->has_status('active trialling')) { |
|
347 | 347 | $subscription->create_payment(); |
348 | 348 | } |
349 | 349 | |
@@ -355,41 +355,41 @@ discard block |
||
355 | 355 | * |
356 | 356 | * @param WPInv_Invoice $invoice |
357 | 357 | */ |
358 | - public function invoice_paid( $invoice ) { |
|
358 | + public function invoice_paid($invoice) { |
|
359 | 359 | |
360 | 360 | // Abort if not paid by bank transfer. |
361 | - if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) { |
|
361 | + if ($this->id !== $invoice->get_gateway() || !$invoice->is_recurring()) { |
|
362 | 362 | return; |
363 | 363 | } |
364 | 364 | |
365 | 365 | // Is it a parent payment? |
366 | - if ( 0 == $invoice->get_parent_id() ) { |
|
366 | + if (0 == $invoice->get_parent_id()) { |
|
367 | 367 | |
368 | 368 | // (Maybe) activate subscriptions. |
369 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
369 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
370 | 370 | |
371 | - if ( ! empty( $subscriptions ) ) { |
|
372 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
371 | + if (!empty($subscriptions)) { |
|
372 | + $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
373 | 373 | |
374 | - foreach ( $subscriptions as $subscription ) { |
|
375 | - if ( $subscription->exists() ) { |
|
376 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
377 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
374 | + foreach ($subscriptions as $subscription) { |
|
375 | + if ($subscription->exists()) { |
|
376 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
377 | + $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
378 | 378 | |
379 | - $subscription->set_next_renewal_date( $expiry ); |
|
380 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
381 | - $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ); |
|
379 | + $subscription->set_next_renewal_date($expiry); |
|
380 | + $subscription->set_date_created(current_time('mysql')); |
|
381 | + $subscription->set_profile_id('bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id()); |
|
382 | 382 | $subscription->activate(); |
383 | 383 | } |
384 | 384 | } |
385 | 385 | } |
386 | 386 | } else { |
387 | 387 | |
388 | - $subscription = getpaid_get_subscription( $invoice->get_subscription_id() ); |
|
388 | + $subscription = getpaid_get_subscription($invoice->get_subscription_id()); |
|
389 | 389 | |
390 | 390 | // Renew the subscription. |
391 | - if ( $subscription && $subscription->exists() ) { |
|
392 | - $subscription->add_payment( array(), $invoice ); |
|
391 | + if ($subscription && $subscription->exists()) { |
|
392 | + $subscription->add_payment(array(), $invoice); |
|
393 | 393 | $subscription->renew(); |
394 | 394 | } |
395 | 395 | } |
@@ -14,143 +14,143 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class WPInv_Subscriptions_Widget extends WP_Super_Duper { |
16 | 16 | |
17 | - /** |
|
18 | - * Register the widget with WordPress. |
|
19 | - * |
|
20 | - */ |
|
21 | - public function __construct() { |
|
22 | - |
|
23 | - $options = array( |
|
24 | - 'textdomain' => 'invoicing', |
|
25 | - 'block-icon' => 'controls-repeat', |
|
26 | - 'block-category' => 'widgets', |
|
27 | - 'block-keywords' => "['invoicing','subscriptions', 'getpaid']", |
|
28 | - 'class_name' => __CLASS__, |
|
29 | - 'base_id' => 'wpinv_subscriptions', |
|
30 | - 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
31 | - 'widget_ops' => array( |
|
32 | - 'classname' => 'getpaid-subscriptions bsui', |
|
33 | - 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
34 | - ), |
|
35 | - 'arguments' => array( |
|
36 | - 'title' => array( |
|
37 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
38 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
39 | - 'type' => 'text', |
|
40 | - 'desc_tip' => true, |
|
41 | - 'default' => '', |
|
42 | - 'advanced' => false, |
|
43 | - ), |
|
44 | - ), |
|
45 | - |
|
46 | - ); |
|
47 | - |
|
48 | - parent::__construct( $options ); |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Retrieves current user's subscriptions. |
|
53 | - * |
|
54 | - * @return GetPaid_Subscriptions_Query |
|
55 | - */ |
|
56 | - public function get_subscriptions() { |
|
57 | - |
|
58 | - // Prepare license args. |
|
59 | - $args = array( |
|
60 | - 'customer_in' => get_current_user_id(), |
|
61 | - 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
62 | - ); |
|
63 | - |
|
64 | - return new GetPaid_Subscriptions_Query( $args ); |
|
65 | - |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * The Super block output function. |
|
70 | - * |
|
71 | - * @param array $args |
|
72 | - * @param array $widget_args |
|
73 | - * @param string $content |
|
74 | - * |
|
75 | - * @return mixed|string|bool |
|
76 | - */ |
|
77 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
78 | - |
|
79 | - // Ensure that the user is logged in. |
|
80 | - if ( ! is_user_logged_in() ) { |
|
81 | - |
|
82 | - return aui()->alert( |
|
83 | - array( |
|
84 | - 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
85 | - 'type' => 'error', |
|
86 | - ) |
|
87 | - ); |
|
88 | - |
|
89 | - } |
|
90 | - |
|
91 | - // Are we displaying a single subscription? |
|
92 | - if ( isset( $_GET['subscription'] ) ) { |
|
93 | - return $this->display_single_subscription( intval( $_GET['subscription'] ) ); |
|
94 | - } |
|
95 | - |
|
96 | - // Retrieve the user's subscriptions. |
|
97 | - $subscriptions = $this->get_subscriptions(); |
|
98 | - |
|
99 | - // Start the output buffer. |
|
100 | - ob_start(); |
|
101 | - |
|
102 | - // Backwards compatibility. |
|
103 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
104 | - |
|
105 | - // Display errors and notices. |
|
106 | - wpinv_print_errors(); |
|
107 | - |
|
108 | - do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
109 | - |
|
110 | - // Print the table header. |
|
111 | - $this->print_table_header(); |
|
112 | - |
|
113 | - // Print table body. |
|
114 | - $this->print_table_body( $subscriptions->get_results() ); |
|
115 | - |
|
116 | - // Print table footer. |
|
117 | - $this->print_table_footer(); |
|
118 | - |
|
119 | - // Print the navigation. |
|
120 | - $this->print_navigation( $subscriptions->get_total() ); |
|
121 | - |
|
122 | - // Backwards compatibility. |
|
123 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
124 | - |
|
125 | - // Return the output. |
|
126 | - return ob_get_clean(); |
|
127 | - |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Retrieves the subscription columns. |
|
132 | - * |
|
133 | - * @return array |
|
134 | - */ |
|
135 | - public function get_subscriptions_table_columns() { |
|
17 | + /** |
|
18 | + * Register the widget with WordPress. |
|
19 | + * |
|
20 | + */ |
|
21 | + public function __construct() { |
|
22 | + |
|
23 | + $options = array( |
|
24 | + 'textdomain' => 'invoicing', |
|
25 | + 'block-icon' => 'controls-repeat', |
|
26 | + 'block-category' => 'widgets', |
|
27 | + 'block-keywords' => "['invoicing','subscriptions', 'getpaid']", |
|
28 | + 'class_name' => __CLASS__, |
|
29 | + 'base_id' => 'wpinv_subscriptions', |
|
30 | + 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
31 | + 'widget_ops' => array( |
|
32 | + 'classname' => 'getpaid-subscriptions bsui', |
|
33 | + 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
34 | + ), |
|
35 | + 'arguments' => array( |
|
36 | + 'title' => array( |
|
37 | + 'title' => __( 'Widget title', 'invoicing' ), |
|
38 | + 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
39 | + 'type' => 'text', |
|
40 | + 'desc_tip' => true, |
|
41 | + 'default' => '', |
|
42 | + 'advanced' => false, |
|
43 | + ), |
|
44 | + ), |
|
45 | + |
|
46 | + ); |
|
47 | + |
|
48 | + parent::__construct( $options ); |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Retrieves current user's subscriptions. |
|
53 | + * |
|
54 | + * @return GetPaid_Subscriptions_Query |
|
55 | + */ |
|
56 | + public function get_subscriptions() { |
|
57 | + |
|
58 | + // Prepare license args. |
|
59 | + $args = array( |
|
60 | + 'customer_in' => get_current_user_id(), |
|
61 | + 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
62 | + ); |
|
63 | + |
|
64 | + return new GetPaid_Subscriptions_Query( $args ); |
|
65 | + |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * The Super block output function. |
|
70 | + * |
|
71 | + * @param array $args |
|
72 | + * @param array $widget_args |
|
73 | + * @param string $content |
|
74 | + * |
|
75 | + * @return mixed|string|bool |
|
76 | + */ |
|
77 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
78 | + |
|
79 | + // Ensure that the user is logged in. |
|
80 | + if ( ! is_user_logged_in() ) { |
|
81 | + |
|
82 | + return aui()->alert( |
|
83 | + array( |
|
84 | + 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
85 | + 'type' => 'error', |
|
86 | + ) |
|
87 | + ); |
|
88 | + |
|
89 | + } |
|
90 | + |
|
91 | + // Are we displaying a single subscription? |
|
92 | + if ( isset( $_GET['subscription'] ) ) { |
|
93 | + return $this->display_single_subscription( intval( $_GET['subscription'] ) ); |
|
94 | + } |
|
95 | + |
|
96 | + // Retrieve the user's subscriptions. |
|
97 | + $subscriptions = $this->get_subscriptions(); |
|
98 | + |
|
99 | + // Start the output buffer. |
|
100 | + ob_start(); |
|
101 | + |
|
102 | + // Backwards compatibility. |
|
103 | + do_action( 'wpinv_before_user_subscriptions' ); |
|
104 | + |
|
105 | + // Display errors and notices. |
|
106 | + wpinv_print_errors(); |
|
107 | + |
|
108 | + do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
109 | + |
|
110 | + // Print the table header. |
|
111 | + $this->print_table_header(); |
|
112 | + |
|
113 | + // Print table body. |
|
114 | + $this->print_table_body( $subscriptions->get_results() ); |
|
115 | + |
|
116 | + // Print table footer. |
|
117 | + $this->print_table_footer(); |
|
118 | + |
|
119 | + // Print the navigation. |
|
120 | + $this->print_navigation( $subscriptions->get_total() ); |
|
121 | + |
|
122 | + // Backwards compatibility. |
|
123 | + do_action( 'wpinv_after_user_subscriptions' ); |
|
124 | + |
|
125 | + // Return the output. |
|
126 | + return ob_get_clean(); |
|
127 | + |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Retrieves the subscription columns. |
|
132 | + * |
|
133 | + * @return array |
|
134 | + */ |
|
135 | + public function get_subscriptions_table_columns() { |
|
136 | 136 | |
137 | - $columns = array( |
|
138 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
139 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
140 | - 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
141 | - 'status' => __( 'Status', 'invoicing' ), |
|
142 | - ); |
|
137 | + $columns = array( |
|
138 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
139 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
140 | + 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
141 | + 'status' => __( 'Status', 'invoicing' ), |
|
142 | + ); |
|
143 | 143 | |
144 | - return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
145 | - } |
|
144 | + return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * Displays the table header. |
|
149 | - * |
|
150 | - */ |
|
151 | - public function print_table_header() { |
|
147 | + /** |
|
148 | + * Displays the table header. |
|
149 | + * |
|
150 | + */ |
|
151 | + public function print_table_header() { |
|
152 | 152 | |
153 | - ?> |
|
153 | + ?> |
|
154 | 154 | |
155 | 155 | <table class="table table-bordered table-striped"> |
156 | 156 | |
@@ -166,122 +166,122 @@ discard block |
||
166 | 166 | |
167 | 167 | <?php |
168 | 168 | |
169 | - } |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * Displays the table body. |
|
173 | - * |
|
174 | - * @param WPInv_Subscription[] $subscriptions |
|
175 | - */ |
|
176 | - public function print_table_body( $subscriptions ) { |
|
171 | + /** |
|
172 | + * Displays the table body. |
|
173 | + * |
|
174 | + * @param WPInv_Subscription[] $subscriptions |
|
175 | + */ |
|
176 | + public function print_table_body( $subscriptions ) { |
|
177 | 177 | |
178 | - if ( empty( $subscriptions ) ) { |
|
179 | - $this->print_table_body_no_subscriptions(); |
|
180 | - } else { |
|
181 | - $this->print_table_body_subscriptions( $subscriptions ); |
|
182 | - } |
|
178 | + if ( empty( $subscriptions ) ) { |
|
179 | + $this->print_table_body_no_subscriptions(); |
|
180 | + } else { |
|
181 | + $this->print_table_body_subscriptions( $subscriptions ); |
|
182 | + } |
|
183 | 183 | |
184 | - } |
|
184 | + } |
|
185 | 185 | |
186 | - /** |
|
187 | - * Displays the table body if no subscriptions were found. |
|
188 | - * |
|
189 | - */ |
|
190 | - public function print_table_body_no_subscriptions() { |
|
186 | + /** |
|
187 | + * Displays the table body if no subscriptions were found. |
|
188 | + * |
|
189 | + */ |
|
190 | + public function print_table_body_no_subscriptions() { |
|
191 | 191 | |
192 | - ?> |
|
192 | + ?> |
|
193 | 193 | <tbody> |
194 | 194 | |
195 | 195 | <tr> |
196 | 196 | <td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>"> |
197 | 197 | |
198 | 198 | <?php |
199 | - aui()->alert( |
|
200 | - array( |
|
201 | - 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
202 | - 'type' => 'warning', |
|
203 | - ), |
|
199 | + aui()->alert( |
|
200 | + array( |
|
201 | + 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
202 | + 'type' => 'warning', |
|
203 | + ), |
|
204 | 204 | true |
205 | - ); |
|
206 | - ?> |
|
205 | + ); |
|
206 | + ?> |
|
207 | 207 | |
208 | 208 | </td> |
209 | 209 | </tr> |
210 | 210 | |
211 | 211 | </tbody> |
212 | 212 | <?php |
213 | - } |
|
213 | + } |
|
214 | 214 | |
215 | - /** |
|
216 | - * Displays the table body if subscriptions were found. |
|
217 | - * |
|
218 | - * @param WPInv_Subscription[] $subscriptions |
|
219 | - */ |
|
220 | - public function print_table_body_subscriptions( $subscriptions ) { |
|
215 | + /** |
|
216 | + * Displays the table body if subscriptions were found. |
|
217 | + * |
|
218 | + * @param WPInv_Subscription[] $subscriptions |
|
219 | + */ |
|
220 | + public function print_table_body_subscriptions( $subscriptions ) { |
|
221 | 221 | |
222 | - ?> |
|
222 | + ?> |
|
223 | 223 | <tbody> |
224 | 224 | |
225 | 225 | <?php foreach ( $subscriptions as $subscription ) : ?> |
226 | 226 | <tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>"> |
227 | 227 | <?php |
228 | - wpinv_get_template( |
|
229 | - 'subscriptions/subscriptions-table-row.php', |
|
230 | - array( |
|
231 | - 'subscription' => $subscription, |
|
232 | - 'widget' => $this, |
|
233 | - ) |
|
234 | - ); |
|
235 | - ?> |
|
228 | + wpinv_get_template( |
|
229 | + 'subscriptions/subscriptions-table-row.php', |
|
230 | + array( |
|
231 | + 'subscription' => $subscription, |
|
232 | + 'widget' => $this, |
|
233 | + ) |
|
234 | + ); |
|
235 | + ?> |
|
236 | 236 | </tr> |
237 | 237 | <?php endforeach; ?> |
238 | 238 | |
239 | 239 | </tbody> |
240 | 240 | <?php |
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * Adds row actions to a column |
|
245 | - * |
|
246 | - * @param string $content column content |
|
247 | - * @param WPInv_Subscription $subscription |
|
248 | - * @since 1.0.0 |
|
249 | - * @return string |
|
250 | - */ |
|
251 | - public function add_row_actions( $content, $subscription ) { |
|
252 | - |
|
253 | - // Prepare row actions. |
|
254 | - $actions = array(); |
|
255 | - |
|
256 | - // View subscription action. |
|
257 | - $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
258 | - $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
259 | - $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
260 | - |
|
261 | - // Filter the actions. |
|
262 | - $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
263 | - |
|
264 | - $sanitized = array(); |
|
265 | - foreach ( $actions as $key => $action ) { |
|
266 | - $key = sanitize_html_class( $key ); |
|
267 | - $action = wp_kses_post( $action ); |
|
268 | - $sanitized[] = "<span class='$key'>$action</span>"; |
|
269 | - } |
|
270 | - |
|
271 | - $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
|
272 | - $row_actions .= implode( ' | ', $sanitized ); |
|
273 | - $row_actions .= '</small>'; |
|
274 | - |
|
275 | - return $content . $row_actions; |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Displays the table footer. |
|
280 | - * |
|
281 | - */ |
|
282 | - public function print_table_footer() { |
|
283 | - |
|
284 | - ?> |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Adds row actions to a column |
|
245 | + * |
|
246 | + * @param string $content column content |
|
247 | + * @param WPInv_Subscription $subscription |
|
248 | + * @since 1.0.0 |
|
249 | + * @return string |
|
250 | + */ |
|
251 | + public function add_row_actions( $content, $subscription ) { |
|
252 | + |
|
253 | + // Prepare row actions. |
|
254 | + $actions = array(); |
|
255 | + |
|
256 | + // View subscription action. |
|
257 | + $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
258 | + $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
259 | + $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
260 | + |
|
261 | + // Filter the actions. |
|
262 | + $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
263 | + |
|
264 | + $sanitized = array(); |
|
265 | + foreach ( $actions as $key => $action ) { |
|
266 | + $key = sanitize_html_class( $key ); |
|
267 | + $action = wp_kses_post( $action ); |
|
268 | + $sanitized[] = "<span class='$key'>$action</span>"; |
|
269 | + } |
|
270 | + |
|
271 | + $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
|
272 | + $row_actions .= implode( ' | ', $sanitized ); |
|
273 | + $row_actions .= '</small>'; |
|
274 | + |
|
275 | + return $content . $row_actions; |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Displays the table footer. |
|
280 | + * |
|
281 | + */ |
|
282 | + public function print_table_footer() { |
|
283 | + |
|
284 | + ?> |
|
285 | 285 | |
286 | 286 | <tfoot> |
287 | 287 | <tr> |
@@ -296,145 +296,145 @@ discard block |
||
296 | 296 | </table> |
297 | 297 | <?php |
298 | 298 | |
299 | - } |
|
299 | + } |
|
300 | 300 | |
301 | - /** |
|
302 | - * Displays the navigation. |
|
303 | - * |
|
304 | - * @param int $total |
|
305 | - */ |
|
306 | - public function print_navigation( $total ) { |
|
301 | + /** |
|
302 | + * Displays the navigation. |
|
303 | + * |
|
304 | + * @param int $total |
|
305 | + */ |
|
306 | + public function print_navigation( $total ) { |
|
307 | 307 | |
308 | - if ( $total < 1 ) { |
|
308 | + if ( $total < 1 ) { |
|
309 | 309 | |
310 | - // Out-of-bounds, run the query again without LIMIT for total count. |
|
311 | - $args = array( |
|
312 | - 'customer_in' => get_current_user_id(), |
|
313 | - 'fields' => 'id', |
|
314 | - ); |
|
310 | + // Out-of-bounds, run the query again without LIMIT for total count. |
|
311 | + $args = array( |
|
312 | + 'customer_in' => get_current_user_id(), |
|
313 | + 'fields' => 'id', |
|
314 | + ); |
|
315 | 315 | |
316 | - $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
317 | - $total = $count_query->get_total(); |
|
318 | - } |
|
316 | + $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
317 | + $total = $count_query->get_total(); |
|
318 | + } |
|
319 | 319 | |
320 | - // Abort if we do not have pages. |
|
321 | - if ( 2 > $total ) { |
|
322 | - return; |
|
323 | - } |
|
320 | + // Abort if we do not have pages. |
|
321 | + if ( 2 > $total ) { |
|
322 | + return; |
|
323 | + } |
|
324 | 324 | |
325 | - ?> |
|
325 | + ?> |
|
326 | 326 | |
327 | 327 | <div class="getpaid-subscriptions-pagination"> |
328 | 328 | <?php |
329 | - $big = 999999; |
|
330 | - |
|
331 | - echo wp_kses_post( |
|
332 | - getpaid_paginate_links( |
|
333 | - array( |
|
334 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
335 | - 'format' => '?paged=%#%', |
|
336 | - 'total' => (int) ceil( $total / 10 ), |
|
337 | - ) |
|
338 | - ) |
|
339 | - ); |
|
340 | - ?> |
|
329 | + $big = 999999; |
|
330 | + |
|
331 | + echo wp_kses_post( |
|
332 | + getpaid_paginate_links( |
|
333 | + array( |
|
334 | + 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
335 | + 'format' => '?paged=%#%', |
|
336 | + 'total' => (int) ceil( $total / 10 ), |
|
337 | + ) |
|
338 | + ) |
|
339 | + ); |
|
340 | + ?> |
|
341 | 341 | </div> |
342 | 342 | |
343 | 343 | <?php |
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Returns a single subscription's columns. |
|
348 | - * |
|
349 | - * @param WPInv_Subscription $subscription |
|
350 | - * |
|
351 | - * @return array |
|
352 | - */ |
|
353 | - public function get_single_subscription_columns( $subscription ) { |
|
354 | - |
|
355 | - // Prepare subscription detail columns. |
|
356 | - $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
357 | - $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
358 | - $fields = apply_filters( |
|
359 | - 'getpaid_single_subscription_details_fields', |
|
360 | - array( |
|
361 | - 'status' => __( 'Status', 'invoicing' ), |
|
362 | - 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
363 | - 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
364 | - 'start_date' => __( 'Start date', 'invoicing' ), |
|
365 | - 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
366 | - 'payments' => __( 'Payments', 'invoicing' ), |
|
367 | - 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
368 | - ), |
|
369 | - $subscription, |
|
370 | - $items_count |
|
371 | - ); |
|
372 | - |
|
373 | - if ( isset( $fields['expiry_date'] ) ) { |
|
374 | - |
|
375 | - if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
376 | - $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
377 | - } |
|
378 | - |
|
379 | - if ( 'pending' === $subscription->get_status() ) { |
|
380 | - unset( $fields['expiry_date'] ); |
|
381 | - } |
|
382 | - } |
|
383 | - |
|
384 | - if ( isset( $fields['start_date'] ) && 'pending' === $subscription->get_status() ) { |
|
385 | - unset( $fields['start_date'] ); |
|
386 | - } |
|
387 | - |
|
388 | - if ( $subscription->get_initial_amount() === $subscription->get_recurring_amount() ) { |
|
389 | - unset( $fields['initial_amount'] ); |
|
390 | - } |
|
391 | - |
|
392 | - return $fields; |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Displays a single subscription. |
|
397 | - * |
|
398 | - * @param string $subscription |
|
399 | - * |
|
400 | - * @return string |
|
401 | - */ |
|
402 | - public function display_single_subscription( $subscription ) { |
|
403 | - |
|
404 | - // Fetch the subscription. |
|
405 | - $subscription = new WPInv_Subscription( (int) $subscription ); |
|
406 | - |
|
407 | - if ( ! $subscription->exists() ) { |
|
408 | - |
|
409 | - return aui()->alert( |
|
410 | - array( |
|
411 | - 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
412 | - 'type' => 'error', |
|
413 | - ) |
|
414 | - ); |
|
415 | - |
|
416 | - } |
|
417 | - |
|
418 | - // Ensure that the user owns this subscription key. |
|
419 | - if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) { |
|
420 | - |
|
421 | - return aui()->alert( |
|
422 | - array( |
|
423 | - 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
424 | - 'type' => 'error', |
|
425 | - ) |
|
426 | - ); |
|
427 | - |
|
428 | - } |
|
429 | - |
|
430 | - return wpinv_get_template_html( |
|
431 | - 'subscriptions/subscription-details.php', |
|
432 | - array( |
|
433 | - 'subscription' => $subscription, |
|
434 | - 'widget' => $this, |
|
435 | - ) |
|
436 | - ); |
|
437 | - |
|
438 | - } |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Returns a single subscription's columns. |
|
348 | + * |
|
349 | + * @param WPInv_Subscription $subscription |
|
350 | + * |
|
351 | + * @return array |
|
352 | + */ |
|
353 | + public function get_single_subscription_columns( $subscription ) { |
|
354 | + |
|
355 | + // Prepare subscription detail columns. |
|
356 | + $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
357 | + $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
358 | + $fields = apply_filters( |
|
359 | + 'getpaid_single_subscription_details_fields', |
|
360 | + array( |
|
361 | + 'status' => __( 'Status', 'invoicing' ), |
|
362 | + 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
363 | + 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
364 | + 'start_date' => __( 'Start date', 'invoicing' ), |
|
365 | + 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
366 | + 'payments' => __( 'Payments', 'invoicing' ), |
|
367 | + 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
368 | + ), |
|
369 | + $subscription, |
|
370 | + $items_count |
|
371 | + ); |
|
372 | + |
|
373 | + if ( isset( $fields['expiry_date'] ) ) { |
|
374 | + |
|
375 | + if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
376 | + $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
377 | + } |
|
378 | + |
|
379 | + if ( 'pending' === $subscription->get_status() ) { |
|
380 | + unset( $fields['expiry_date'] ); |
|
381 | + } |
|
382 | + } |
|
383 | + |
|
384 | + if ( isset( $fields['start_date'] ) && 'pending' === $subscription->get_status() ) { |
|
385 | + unset( $fields['start_date'] ); |
|
386 | + } |
|
387 | + |
|
388 | + if ( $subscription->get_initial_amount() === $subscription->get_recurring_amount() ) { |
|
389 | + unset( $fields['initial_amount'] ); |
|
390 | + } |
|
391 | + |
|
392 | + return $fields; |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Displays a single subscription. |
|
397 | + * |
|
398 | + * @param string $subscription |
|
399 | + * |
|
400 | + * @return string |
|
401 | + */ |
|
402 | + public function display_single_subscription( $subscription ) { |
|
403 | + |
|
404 | + // Fetch the subscription. |
|
405 | + $subscription = new WPInv_Subscription( (int) $subscription ); |
|
406 | + |
|
407 | + if ( ! $subscription->exists() ) { |
|
408 | + |
|
409 | + return aui()->alert( |
|
410 | + array( |
|
411 | + 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
412 | + 'type' => 'error', |
|
413 | + ) |
|
414 | + ); |
|
415 | + |
|
416 | + } |
|
417 | + |
|
418 | + // Ensure that the user owns this subscription key. |
|
419 | + if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) { |
|
420 | + |
|
421 | + return aui()->alert( |
|
422 | + array( |
|
423 | + 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
424 | + 'type' => 'error', |
|
425 | + ) |
|
426 | + ); |
|
427 | + |
|
428 | + } |
|
429 | + |
|
430 | + return wpinv_get_template_html( |
|
431 | + 'subscriptions/subscription-details.php', |
|
432 | + array( |
|
433 | + 'subscription' => $subscription, |
|
434 | + 'widget' => $this, |
|
435 | + ) |
|
436 | + ); |
|
437 | + |
|
438 | + } |
|
439 | 439 | |
440 | 440 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * @version 1.0.0 |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Contains the subscriptions widget. |
@@ -27,15 +27,15 @@ discard block |
||
27 | 27 | 'block-keywords' => "['invoicing','subscriptions', 'getpaid']", |
28 | 28 | 'class_name' => __CLASS__, |
29 | 29 | 'base_id' => 'wpinv_subscriptions', |
30 | - 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
30 | + 'name' => __('GetPaid > Subscriptions', 'invoicing'), |
|
31 | 31 | 'widget_ops' => array( |
32 | 32 | 'classname' => 'getpaid-subscriptions bsui', |
33 | - 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
33 | + 'description' => esc_html__("Displays the current user's subscriptions.", 'invoicing'), |
|
34 | 34 | ), |
35 | 35 | 'arguments' => array( |
36 | 36 | 'title' => array( |
37 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
38 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
37 | + 'title' => __('Widget title', 'invoicing'), |
|
38 | + 'desc' => __('Enter widget title.', 'invoicing'), |
|
39 | 39 | 'type' => 'text', |
40 | 40 | 'desc_tip' => true, |
41 | 41 | 'default' => '', |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | |
46 | 46 | ); |
47 | 47 | |
48 | - parent::__construct( $options ); |
|
48 | + parent::__construct($options); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -56,12 +56,12 @@ discard block |
||
56 | 56 | public function get_subscriptions() { |
57 | 57 | |
58 | 58 | // Prepare license args. |
59 | - $args = array( |
|
59 | + $args = array( |
|
60 | 60 | 'customer_in' => get_current_user_id(), |
61 | - 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
61 | + 'paged' => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1, |
|
62 | 62 | ); |
63 | 63 | |
64 | - return new GetPaid_Subscriptions_Query( $args ); |
|
64 | + return new GetPaid_Subscriptions_Query($args); |
|
65 | 65 | |
66 | 66 | } |
67 | 67 | |
@@ -74,14 +74,14 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @return mixed|string|bool |
76 | 76 | */ |
77 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
77 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
78 | 78 | |
79 | 79 | // Ensure that the user is logged in. |
80 | - if ( ! is_user_logged_in() ) { |
|
80 | + if (!is_user_logged_in()) { |
|
81 | 81 | |
82 | 82 | return aui()->alert( |
83 | 83 | array( |
84 | - 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
84 | + 'content' => wp_kses_post(__('You need to log-in or create an account to view this section.', 'invoicing')), |
|
85 | 85 | 'type' => 'error', |
86 | 86 | ) |
87 | 87 | ); |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | } |
90 | 90 | |
91 | 91 | // Are we displaying a single subscription? |
92 | - if ( isset( $_GET['subscription'] ) ) { |
|
93 | - return $this->display_single_subscription( intval( $_GET['subscription'] ) ); |
|
92 | + if (isset($_GET['subscription'])) { |
|
93 | + return $this->display_single_subscription(intval($_GET['subscription'])); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | // Retrieve the user's subscriptions. |
@@ -100,27 +100,27 @@ discard block |
||
100 | 100 | ob_start(); |
101 | 101 | |
102 | 102 | // Backwards compatibility. |
103 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
103 | + do_action('wpinv_before_user_subscriptions'); |
|
104 | 104 | |
105 | 105 | // Display errors and notices. |
106 | 106 | wpinv_print_errors(); |
107 | 107 | |
108 | - do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
108 | + do_action('getpaid_license_manager_before_subscriptions', $subscriptions); |
|
109 | 109 | |
110 | 110 | // Print the table header. |
111 | 111 | $this->print_table_header(); |
112 | 112 | |
113 | 113 | // Print table body. |
114 | - $this->print_table_body( $subscriptions->get_results() ); |
|
114 | + $this->print_table_body($subscriptions->get_results()); |
|
115 | 115 | |
116 | 116 | // Print table footer. |
117 | 117 | $this->print_table_footer(); |
118 | 118 | |
119 | 119 | // Print the navigation. |
120 | - $this->print_navigation( $subscriptions->get_total() ); |
|
120 | + $this->print_navigation($subscriptions->get_total()); |
|
121 | 121 | |
122 | 122 | // Backwards compatibility. |
123 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
123 | + do_action('wpinv_after_user_subscriptions'); |
|
124 | 124 | |
125 | 125 | // Return the output. |
126 | 126 | return ob_get_clean(); |
@@ -135,13 +135,13 @@ discard block |
||
135 | 135 | public function get_subscriptions_table_columns() { |
136 | 136 | |
137 | 137 | $columns = array( |
138 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
139 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
140 | - 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
141 | - 'status' => __( 'Status', 'invoicing' ), |
|
138 | + 'subscription' => __('Subscription', 'invoicing'), |
|
139 | + 'amount' => __('Amount', 'invoicing'), |
|
140 | + 'renewal-date' => __('Next payment', 'invoicing'), |
|
141 | + 'status' => __('Status', 'invoicing'), |
|
142 | 142 | ); |
143 | 143 | |
144 | - return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
144 | + return apply_filters('getpaid_frontend_subscriptions_table_columns', $columns); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -156,9 +156,9 @@ discard block |
||
156 | 156 | |
157 | 157 | <thead> |
158 | 158 | <tr> |
159 | - <?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?> |
|
160 | - <th scope="col" class="font-weight-bold getpaid-subscriptions-table-<?php echo esc_attr( $key ); ?>"> |
|
161 | - <?php echo esc_html( $label ); ?> |
|
159 | + <?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?> |
|
160 | + <th scope="col" class="font-weight-bold getpaid-subscriptions-table-<?php echo esc_attr($key); ?>"> |
|
161 | + <?php echo esc_html($label); ?> |
|
162 | 162 | </th> |
163 | 163 | <?php endforeach; ?> |
164 | 164 | </tr> |
@@ -173,12 +173,12 @@ discard block |
||
173 | 173 | * |
174 | 174 | * @param WPInv_Subscription[] $subscriptions |
175 | 175 | */ |
176 | - public function print_table_body( $subscriptions ) { |
|
176 | + public function print_table_body($subscriptions) { |
|
177 | 177 | |
178 | - if ( empty( $subscriptions ) ) { |
|
178 | + if (empty($subscriptions)) { |
|
179 | 179 | $this->print_table_body_no_subscriptions(); |
180 | 180 | } else { |
181 | - $this->print_table_body_subscriptions( $subscriptions ); |
|
181 | + $this->print_table_body_subscriptions($subscriptions); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | } |
@@ -193,12 +193,12 @@ discard block |
||
193 | 193 | <tbody> |
194 | 194 | |
195 | 195 | <tr> |
196 | - <td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>"> |
|
196 | + <td colspan="<?php echo count($this->get_subscriptions_table_columns()); ?>"> |
|
197 | 197 | |
198 | 198 | <?php |
199 | 199 | aui()->alert( |
200 | 200 | array( |
201 | - 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
201 | + 'content' => wp_kses_post(__('No subscriptions found.', 'invoicing')), |
|
202 | 202 | 'type' => 'warning', |
203 | 203 | ), |
204 | 204 | true |
@@ -217,12 +217,12 @@ discard block |
||
217 | 217 | * |
218 | 218 | * @param WPInv_Subscription[] $subscriptions |
219 | 219 | */ |
220 | - public function print_table_body_subscriptions( $subscriptions ) { |
|
220 | + public function print_table_body_subscriptions($subscriptions) { |
|
221 | 221 | |
222 | 222 | ?> |
223 | 223 | <tbody> |
224 | 224 | |
225 | - <?php foreach ( $subscriptions as $subscription ) : ?> |
|
225 | + <?php foreach ($subscriptions as $subscription) : ?> |
|
226 | 226 | <tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>"> |
227 | 227 | <?php |
228 | 228 | wpinv_get_template( |
@@ -248,28 +248,28 @@ discard block |
||
248 | 248 | * @since 1.0.0 |
249 | 249 | * @return string |
250 | 250 | */ |
251 | - public function add_row_actions( $content, $subscription ) { |
|
251 | + public function add_row_actions($content, $subscription) { |
|
252 | 252 | |
253 | 253 | // Prepare row actions. |
254 | 254 | $actions = array(); |
255 | 255 | |
256 | 256 | // View subscription action. |
257 | - $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
258 | - $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
259 | - $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
257 | + $view_url = getpaid_get_tab_url('gp-subscriptions', get_permalink((int) wpinv_get_option('invoice_subscription_page'))); |
|
258 | + $view_url = esc_url(add_query_arg('subscription', (int) $subscription->get_id(), $view_url)); |
|
259 | + $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __('Manage Subscription', 'invoicing') . '</a>'; |
|
260 | 260 | |
261 | 261 | // Filter the actions. |
262 | - $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
262 | + $actions = apply_filters('getpaid_subscriptions_table_subscription_actions', $actions, $subscription); |
|
263 | 263 | |
264 | - $sanitized = array(); |
|
265 | - foreach ( $actions as $key => $action ) { |
|
266 | - $key = sanitize_html_class( $key ); |
|
267 | - $action = wp_kses_post( $action ); |
|
264 | + $sanitized = array(); |
|
265 | + foreach ($actions as $key => $action) { |
|
266 | + $key = sanitize_html_class($key); |
|
267 | + $action = wp_kses_post($action); |
|
268 | 268 | $sanitized[] = "<span class='$key'>$action</span>"; |
269 | 269 | } |
270 | 270 | |
271 | 271 | $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
272 | - $row_actions .= implode( ' | ', $sanitized ); |
|
272 | + $row_actions .= implode(' | ', $sanitized); |
|
273 | 273 | $row_actions .= '</small>'; |
274 | 274 | |
275 | 275 | return $content . $row_actions; |
@@ -285,9 +285,9 @@ discard block |
||
285 | 285 | |
286 | 286 | <tfoot> |
287 | 287 | <tr> |
288 | - <?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?> |
|
289 | - <th class="font-weight-bold getpaid-subscriptions-<?php echo esc_attr( $key ); ?>"> |
|
290 | - <?php echo esc_html( $label ); ?> |
|
288 | + <?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?> |
|
289 | + <th class="font-weight-bold getpaid-subscriptions-<?php echo esc_attr($key); ?>"> |
|
290 | + <?php echo esc_html($label); ?> |
|
291 | 291 | </th> |
292 | 292 | <?php endforeach; ?> |
293 | 293 | </tr> |
@@ -303,22 +303,22 @@ discard block |
||
303 | 303 | * |
304 | 304 | * @param int $total |
305 | 305 | */ |
306 | - public function print_navigation( $total ) { |
|
306 | + public function print_navigation($total) { |
|
307 | 307 | |
308 | - if ( $total < 1 ) { |
|
308 | + if ($total < 1) { |
|
309 | 309 | |
310 | 310 | // Out-of-bounds, run the query again without LIMIT for total count. |
311 | - $args = array( |
|
311 | + $args = array( |
|
312 | 312 | 'customer_in' => get_current_user_id(), |
313 | 313 | 'fields' => 'id', |
314 | 314 | ); |
315 | 315 | |
316 | - $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
316 | + $count_query = new GetPaid_Subscriptions_Query($args); |
|
317 | 317 | $total = $count_query->get_total(); |
318 | 318 | } |
319 | 319 | |
320 | 320 | // Abort if we do not have pages. |
321 | - if ( 2 > $total ) { |
|
321 | + if (2 > $total) { |
|
322 | 322 | return; |
323 | 323 | } |
324 | 324 | |
@@ -331,9 +331,9 @@ discard block |
||
331 | 331 | echo wp_kses_post( |
332 | 332 | getpaid_paginate_links( |
333 | 333 | array( |
334 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
334 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
335 | 335 | 'format' => '?paged=%#%', |
336 | - 'total' => (int) ceil( $total / 10 ), |
|
336 | + 'total' => (int) ceil($total / 10), |
|
337 | 337 | ) |
338 | 338 | ) |
339 | 339 | ); |
@@ -350,43 +350,43 @@ discard block |
||
350 | 350 | * |
351 | 351 | * @return array |
352 | 352 | */ |
353 | - public function get_single_subscription_columns( $subscription ) { |
|
353 | + public function get_single_subscription_columns($subscription) { |
|
354 | 354 | |
355 | 355 | // Prepare subscription detail columns. |
356 | - $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
357 | - $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
356 | + $subscription_group = getpaid_get_invoice_subscription_group($subscription->get_parent_invoice_id(), $subscription->get_id()); |
|
357 | + $items_count = empty($subscription_group) ? 1 : count($subscription_group['items']); |
|
358 | 358 | $fields = apply_filters( |
359 | 359 | 'getpaid_single_subscription_details_fields', |
360 | 360 | array( |
361 | - 'status' => __( 'Status', 'invoicing' ), |
|
362 | - 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
363 | - 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
364 | - 'start_date' => __( 'Start date', 'invoicing' ), |
|
365 | - 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
366 | - 'payments' => __( 'Payments', 'invoicing' ), |
|
367 | - 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
361 | + 'status' => __('Status', 'invoicing'), |
|
362 | + 'initial_amount' => __('Initial amount', 'invoicing'), |
|
363 | + 'recurring_amount' => __('Recurring amount', 'invoicing'), |
|
364 | + 'start_date' => __('Start date', 'invoicing'), |
|
365 | + 'expiry_date' => __('Next payment', 'invoicing'), |
|
366 | + 'payments' => __('Payments', 'invoicing'), |
|
367 | + 'item' => _n('Item', 'Items', $items_count, 'invoicing'), |
|
368 | 368 | ), |
369 | 369 | $subscription, |
370 | 370 | $items_count |
371 | 371 | ); |
372 | 372 | |
373 | - if ( isset( $fields['expiry_date'] ) ) { |
|
373 | + if (isset($fields['expiry_date'])) { |
|
374 | 374 | |
375 | - if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
376 | - $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
375 | + if (!$subscription->is_active() || $subscription->is_last_renewal()) { |
|
376 | + $fields['expiry_date'] = __('End date', 'invoicing'); |
|
377 | 377 | } |
378 | 378 | |
379 | - if ( 'pending' === $subscription->get_status() ) { |
|
380 | - unset( $fields['expiry_date'] ); |
|
379 | + if ('pending' === $subscription->get_status()) { |
|
380 | + unset($fields['expiry_date']); |
|
381 | 381 | } |
382 | 382 | } |
383 | 383 | |
384 | - if ( isset( $fields['start_date'] ) && 'pending' === $subscription->get_status() ) { |
|
385 | - unset( $fields['start_date'] ); |
|
384 | + if (isset($fields['start_date']) && 'pending' === $subscription->get_status()) { |
|
385 | + unset($fields['start_date']); |
|
386 | 386 | } |
387 | 387 | |
388 | - if ( $subscription->get_initial_amount() === $subscription->get_recurring_amount() ) { |
|
389 | - unset( $fields['initial_amount'] ); |
|
388 | + if ($subscription->get_initial_amount() === $subscription->get_recurring_amount()) { |
|
389 | + unset($fields['initial_amount']); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | return $fields; |
@@ -399,16 +399,16 @@ discard block |
||
399 | 399 | * |
400 | 400 | * @return string |
401 | 401 | */ |
402 | - public function display_single_subscription( $subscription ) { |
|
402 | + public function display_single_subscription($subscription) { |
|
403 | 403 | |
404 | 404 | // Fetch the subscription. |
405 | - $subscription = new WPInv_Subscription( (int) $subscription ); |
|
405 | + $subscription = new WPInv_Subscription((int) $subscription); |
|
406 | 406 | |
407 | - if ( ! $subscription->exists() ) { |
|
407 | + if (!$subscription->exists()) { |
|
408 | 408 | |
409 | 409 | return aui()->alert( |
410 | 410 | array( |
411 | - 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
411 | + 'content' => wp_kses_post(__('Subscription not found.', 'invoicing')), |
|
412 | 412 | 'type' => 'error', |
413 | 413 | ) |
414 | 414 | ); |
@@ -416,11 +416,11 @@ discard block |
||
416 | 416 | } |
417 | 417 | |
418 | 418 | // Ensure that the user owns this subscription key. |
419 | - if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) { |
|
419 | + if (get_current_user_id() != $subscription->get_customer_id() && !wpinv_current_user_can_manage_invoicing()) { |
|
420 | 420 | |
421 | 421 | return aui()->alert( |
422 | 422 | array( |
423 | - 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
423 | + 'content' => wp_kses_post(__('You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing')), |
|
424 | 424 | 'type' => 'error', |
425 | 425 | ) |
426 | 426 | ); |
@@ -13,17 +13,17 @@ discard block |
||
13 | 13 | class GetPaid_Notification_Email_Sender { |
14 | 14 | |
15 | 15 | /** |
16 | - * Whether or not we should inline CSS into the email. |
|
17 | - */ |
|
18 | - public $inline_css = true; |
|
16 | + * Whether or not we should inline CSS into the email. |
|
17 | + */ |
|
18 | + public $inline_css = true; |
|
19 | 19 | |
20 | 20 | /** |
21 | - * The wp_mail() data. |
|
22 | - */ |
|
21 | + * The wp_mail() data. |
|
22 | + */ |
|
23 | 23 | public $wp_mail_data = null; |
24 | 24 | |
25 | 25 | /** |
26 | - * Sends a new email. |
|
26 | + * Sends a new email. |
|
27 | 27 | * |
28 | 28 | * @param string|array $to The recipients email or an array of recipient emails. |
29 | 29 | * @param string $subject The email's subject. |
@@ -31,49 +31,49 @@ discard block |
||
31 | 31 | * @param array $attachments The email attachments. |
32 | 32 | * |
33 | 33 | * @return bool |
34 | - */ |
|
35 | - public function send( $to, $subject, $email, $attachments = array() ) { |
|
34 | + */ |
|
35 | + public function send( $to, $subject, $email, $attachments = array() ) { |
|
36 | 36 | |
37 | - /* |
|
37 | + /* |
|
38 | 38 | * Allow to filter data on per-email basis. |
39 | 39 | */ |
40 | - $data = apply_filters( |
|
41 | - 'getpaid_email_data', |
|
42 | - array( |
|
43 | - 'to' => array_filter( array_unique( wpinv_parse_list( $to ) ) ), |
|
44 | - 'subject' => htmlspecialchars_decode( wp_strip_all_tags( $subject ), ENT_QUOTES ), |
|
45 | - 'email' => apply_filters( 'wpinv_mail_content', $email ), |
|
46 | - 'headers' => $this->get_headers(), |
|
47 | - 'attachments' => $attachments, |
|
48 | - ), |
|
49 | - $this |
|
50 | - ); |
|
40 | + $data = apply_filters( |
|
41 | + 'getpaid_email_data', |
|
42 | + array( |
|
43 | + 'to' => array_filter( array_unique( wpinv_parse_list( $to ) ) ), |
|
44 | + 'subject' => htmlspecialchars_decode( wp_strip_all_tags( $subject ), ENT_QUOTES ), |
|
45 | + 'email' => apply_filters( 'wpinv_mail_content', $email ), |
|
46 | + 'headers' => $this->get_headers(), |
|
47 | + 'attachments' => $attachments, |
|
48 | + ), |
|
49 | + $this |
|
50 | + ); |
|
51 | 51 | |
52 | 52 | // Remove slashes. |
53 | 53 | $data = (array) wp_unslash( $data ); |
54 | 54 | |
55 | 55 | // Cache it. |
56 | - $this->wp_mail_data = $data; |
|
56 | + $this->wp_mail_data = $data; |
|
57 | 57 | |
58 | - // Attach our own hooks. |
|
59 | - $this->before_sending(); |
|
58 | + // Attach our own hooks. |
|
59 | + $this->before_sending(); |
|
60 | 60 | |
61 | 61 | $result = false; |
62 | 62 | |
63 | 63 | foreach ( $this->wp_mail_data['to'] as $to ) { |
64 | - $result = $this->_send( $to, $data ); |
|
64 | + $result = $this->_send( $to, $data ); |
|
65 | 65 | } |
66 | 66 | |
67 | - // Remove our hooks. |
|
68 | - $this->after_sending(); |
|
67 | + // Remove our hooks. |
|
68 | + $this->after_sending(); |
|
69 | 69 | |
70 | - $this->wp_mail_data = null; |
|
70 | + $this->wp_mail_data = null; |
|
71 | 71 | |
72 | - return $result; |
|
73 | - } |
|
72 | + return $result; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Does the actual sending. |
|
75 | + /** |
|
76 | + * Does the actual sending. |
|
77 | 77 | * |
78 | 78 | * @param string $to The recipient's email. |
79 | 79 | * @param array $data The email's data. |
@@ -81,81 +81,81 @@ discard block |
||
81 | 81 | * @param array $attachments The email attachments. |
82 | 82 | * |
83 | 83 | * @return bool |
84 | - */ |
|
85 | - protected function _send( $to, $data ) { |
|
86 | - |
|
87 | - // Prepare the sending function. |
|
88 | - $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' ); |
|
89 | - |
|
90 | - // Send the actual email. |
|
91 | - $result = call_user_func( |
|
92 | - $sending_function, |
|
93 | - $to, |
|
94 | - html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ), |
|
95 | - $data['email'], |
|
96 | - $data['headers'], |
|
97 | - $data['attachments'] |
|
98 | - ); |
|
99 | - |
|
100 | - if ( ! $result ) { |
|
101 | - $log_message = wp_sprintf( __( "\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] ); |
|
102 | - wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ ); |
|
103 | - } |
|
104 | - |
|
105 | - return $result; |
|
106 | - } |
|
84 | + */ |
|
85 | + protected function _send( $to, $data ) { |
|
86 | + |
|
87 | + // Prepare the sending function. |
|
88 | + $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' ); |
|
89 | + |
|
90 | + // Send the actual email. |
|
91 | + $result = call_user_func( |
|
92 | + $sending_function, |
|
93 | + $to, |
|
94 | + html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ), |
|
95 | + $data['email'], |
|
96 | + $data['headers'], |
|
97 | + $data['attachments'] |
|
98 | + ); |
|
99 | + |
|
100 | + if ( ! $result ) { |
|
101 | + $log_message = wp_sprintf( __( "\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] ); |
|
102 | + wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ ); |
|
103 | + } |
|
104 | + |
|
105 | + return $result; |
|
106 | + } |
|
107 | 107 | |
108 | 108 | /** |
109 | - * Retrieves email headers. |
|
110 | - */ |
|
111 | - public function get_headers() { |
|
109 | + * Retrieves email headers. |
|
110 | + */ |
|
111 | + public function get_headers() { |
|
112 | 112 | |
113 | - $name = $this->get_from_name(); |
|
114 | - $reply_to = $this->get_reply_to(); |
|
115 | - $headers = array( "Reply-To:$name <$reply_to>" ); |
|
113 | + $name = $this->get_from_name(); |
|
114 | + $reply_to = $this->get_reply_to(); |
|
115 | + $headers = array( "Reply-To:$name <$reply_to>" ); |
|
116 | 116 | |
117 | - return apply_filters( 'getpaid_email_headers', $headers, $this ); |
|
117 | + return apply_filters( 'getpaid_email_headers', $headers, $this ); |
|
118 | 118 | |
119 | - } |
|
119 | + } |
|
120 | 120 | |
121 | 121 | /** |
122 | - * Fires before an email is sent |
|
123 | - * |
|
124 | - * @since 1.0.0 |
|
125 | - */ |
|
126 | - public function before_sending() { |
|
122 | + * Fires before an email is sent |
|
123 | + * |
|
124 | + * @since 1.0.0 |
|
125 | + */ |
|
126 | + public function before_sending() { |
|
127 | 127 | |
128 | 128 | do_action( 'getpaid_before_send_email', $this ); |
129 | - add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
130 | - add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
131 | - add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
132 | - add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
129 | + add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
130 | + add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
131 | + add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
132 | + add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
133 | 133 | |
134 | - } |
|
134 | + } |
|
135 | 135 | |
136 | 136 | /** |
137 | - * Returns the from name. |
|
138 | - */ |
|
139 | - public function get_from_name() { |
|
137 | + * Returns the from name. |
|
138 | + */ |
|
139 | + public function get_from_name() { |
|
140 | 140 | |
141 | 141 | $from_name = wpinv_get_option( 'email_from_name', get_bloginfo( 'name' ) ); |
142 | 142 | |
143 | - if ( empty( $from_name ) ) { |
|
144 | - $from_name = get_bloginfo( 'name' ); |
|
143 | + if ( empty( $from_name ) ) { |
|
144 | + $from_name = get_bloginfo( 'name' ); |
|
145 | 145 | } |
146 | 146 | |
147 | - return wp_specialchars_decode( $from_name, ENT_QUOTES ); |
|
147 | + return wp_specialchars_decode( $from_name, ENT_QUOTES ); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
151 | - * Returns the from email. |
|
152 | - */ |
|
153 | - public function get_from_address() { |
|
151 | + * Returns the from email. |
|
152 | + */ |
|
153 | + public function get_from_address() { |
|
154 | 154 | |
155 | 155 | $from_address = wpinv_get_option( 'email_from', $this->default_from_address() ); |
156 | 156 | |
157 | - if ( ! is_email( $from_address ) ) { |
|
158 | - $from_address = $this->default_from_address(); |
|
157 | + if ( ! is_email( $from_address ) ) { |
|
158 | + $from_address = $this->default_from_address(); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | return $from_address; |
@@ -163,75 +163,75 @@ discard block |
||
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
166 | - * The default emails from address. |
|
167 | - * |
|
168 | - * Defaults to wordpress@$sitename |
|
169 | - * Some hosts will block outgoing mail from this address if it doesn't exist, |
|
170 | - * but there's no easy alternative. Defaulting to admin_email might appear to be |
|
171 | - * another option, but some hosts may refuse to relay mail from an unknown domain. |
|
172 | - * |
|
173 | - */ |
|
174 | - public function default_from_address() { |
|
175 | - |
|
176 | - // Get the site domain and get rid of www. |
|
177 | - $sitename = strtolower( $_SERVER['SERVER_NAME'] ); |
|
178 | - if ( substr( $sitename, 0, 4 ) == 'www.' ) { |
|
179 | - $sitename = substr( $sitename, 4 ); |
|
180 | - } |
|
181 | - |
|
182 | - $from_email = 'wordpress@' . $sitename; |
|
183 | - |
|
184 | - return apply_filters( 'getpaid_default_from_address', $from_email ); |
|
166 | + * The default emails from address. |
|
167 | + * |
|
168 | + * Defaults to wordpress@$sitename |
|
169 | + * Some hosts will block outgoing mail from this address if it doesn't exist, |
|
170 | + * but there's no easy alternative. Defaulting to admin_email might appear to be |
|
171 | + * another option, but some hosts may refuse to relay mail from an unknown domain. |
|
172 | + * |
|
173 | + */ |
|
174 | + public function default_from_address() { |
|
175 | + |
|
176 | + // Get the site domain and get rid of www. |
|
177 | + $sitename = strtolower( $_SERVER['SERVER_NAME'] ); |
|
178 | + if ( substr( $sitename, 0, 4 ) == 'www.' ) { |
|
179 | + $sitename = substr( $sitename, 4 ); |
|
180 | + } |
|
181 | + |
|
182 | + $from_email = 'wordpress@' . $sitename; |
|
183 | + |
|
184 | + return apply_filters( 'getpaid_default_from_address', $from_email ); |
|
185 | 185 | |
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
189 | - * Get the email reply-to. |
|
190 | - * |
|
191 | - * |
|
192 | - * @return string The email reply-to address. |
|
193 | - */ |
|
194 | - public function get_reply_to() { |
|
189 | + * Get the email reply-to. |
|
190 | + * |
|
191 | + * |
|
192 | + * @return string The email reply-to address. |
|
193 | + */ |
|
194 | + public function get_reply_to() { |
|
195 | 195 | |
196 | - $reply_to = current( wpinv_parse_list( wpinv_get_admin_email() ) ); |
|
196 | + $reply_to = current( wpinv_parse_list( wpinv_get_admin_email() ) ); |
|
197 | 197 | |
198 | - if ( ! is_email( $reply_to ) ) { |
|
199 | - $reply_to = get_option( 'admin_email' ); |
|
200 | - } |
|
198 | + if ( ! is_email( $reply_to ) ) { |
|
199 | + $reply_to = get_option( 'admin_email' ); |
|
200 | + } |
|
201 | 201 | |
202 | - return $reply_to; |
|
202 | + return $reply_to; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
206 | - * Get the email content type. |
|
207 | - * |
|
208 | - */ |
|
209 | - public function get_content_type() { |
|
210 | - return apply_filters( 'getpaid_email_content_type', 'text/html', $this ); |
|
206 | + * Get the email content type. |
|
207 | + * |
|
208 | + */ |
|
209 | + public function get_content_type() { |
|
210 | + return apply_filters( 'getpaid_email_content_type', 'text/html', $this ); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
214 | - * Ensures that our email messages are not messed up by template plugins. |
|
215 | - * |
|
216 | - * @return array wp_mail_data. |
|
217 | - */ |
|
218 | - public function ensure_email_content( $args ) { |
|
219 | - $args['message'] = $this->wp_mail_data['email']; |
|
220 | - return $args; |
|
214 | + * Ensures that our email messages are not messed up by template plugins. |
|
215 | + * |
|
216 | + * @return array wp_mail_data. |
|
217 | + */ |
|
218 | + public function ensure_email_content( $args ) { |
|
219 | + $args['message'] = $this->wp_mail_data['email']; |
|
220 | + return $args; |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
224 | - * A little house keeping after an email is sent. |
|
225 | - * |
|
226 | - */ |
|
227 | - public function after_sending() { |
|
224 | + * A little house keeping after an email is sent. |
|
225 | + * |
|
226 | + */ |
|
227 | + public function after_sending() { |
|
228 | 228 | |
229 | 229 | do_action( 'getpaid_after_send_email', $this->wp_mail_data ); |
230 | - remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
231 | - remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
232 | - remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
233 | - remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
230 | + remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
231 | + remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
232 | + remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
233 | + remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
234 | 234 | |
235 | - } |
|
235 | + } |
|
236 | 236 | |
237 | 237 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * This function is responsible for sending emails. |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @return bool |
34 | 34 | */ |
35 | - public function send( $to, $subject, $email, $attachments = array() ) { |
|
35 | + public function send($to, $subject, $email, $attachments = array()) { |
|
36 | 36 | |
37 | 37 | /* |
38 | 38 | * Allow to filter data on per-email basis. |
@@ -40,9 +40,9 @@ discard block |
||
40 | 40 | $data = apply_filters( |
41 | 41 | 'getpaid_email_data', |
42 | 42 | array( |
43 | - 'to' => array_filter( array_unique( wpinv_parse_list( $to ) ) ), |
|
44 | - 'subject' => htmlspecialchars_decode( wp_strip_all_tags( $subject ), ENT_QUOTES ), |
|
45 | - 'email' => apply_filters( 'wpinv_mail_content', $email ), |
|
43 | + 'to' => array_filter(array_unique(wpinv_parse_list($to))), |
|
44 | + 'subject' => htmlspecialchars_decode(wp_strip_all_tags($subject), ENT_QUOTES), |
|
45 | + 'email' => apply_filters('wpinv_mail_content', $email), |
|
46 | 46 | 'headers' => $this->get_headers(), |
47 | 47 | 'attachments' => $attachments, |
48 | 48 | ), |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | ); |
51 | 51 | |
52 | 52 | // Remove slashes. |
53 | - $data = (array) wp_unslash( $data ); |
|
53 | + $data = (array) wp_unslash($data); |
|
54 | 54 | |
55 | 55 | // Cache it. |
56 | 56 | $this->wp_mail_data = $data; |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | |
61 | 61 | $result = false; |
62 | 62 | |
63 | - foreach ( $this->wp_mail_data['to'] as $to ) { |
|
64 | - $result = $this->_send( $to, $data ); |
|
63 | + foreach ($this->wp_mail_data['to'] as $to) { |
|
64 | + $result = $this->_send($to, $data); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | // Remove our hooks. |
@@ -82,24 +82,24 @@ discard block |
||
82 | 82 | * |
83 | 83 | * @return bool |
84 | 84 | */ |
85 | - protected function _send( $to, $data ) { |
|
85 | + protected function _send($to, $data) { |
|
86 | 86 | |
87 | 87 | // Prepare the sending function. |
88 | - $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' ); |
|
88 | + $sending_function = apply_filters('getpaid_email_email_sending_function', 'wp_mail'); |
|
89 | 89 | |
90 | 90 | // Send the actual email. |
91 | 91 | $result = call_user_func( |
92 | 92 | $sending_function, |
93 | 93 | $to, |
94 | - html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ), |
|
94 | + html_entity_decode($data['subject'], ENT_QUOTES, get_bloginfo('charset')), |
|
95 | 95 | $data['email'], |
96 | 96 | $data['headers'], |
97 | 97 | $data['attachments'] |
98 | 98 | ); |
99 | 99 | |
100 | - if ( ! $result ) { |
|
101 | - $log_message = wp_sprintf( __( "\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] ); |
|
102 | - wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ ); |
|
100 | + if (!$result) { |
|
101 | + $log_message = wp_sprintf(__("\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing'), date_i18n('F j Y H:i:s', current_time('timestamp')), $to, $data['subject']); |
|
102 | + wpinv_error_log($log_message, __('Email from Invoicing plugin failed to send', 'invoicing'), __FILE__, __LINE__); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | return $result; |
@@ -112,9 +112,9 @@ discard block |
||
112 | 112 | |
113 | 113 | $name = $this->get_from_name(); |
114 | 114 | $reply_to = $this->get_reply_to(); |
115 | - $headers = array( "Reply-To:$name <$reply_to>" ); |
|
115 | + $headers = array("Reply-To:$name <$reply_to>"); |
|
116 | 116 | |
117 | - return apply_filters( 'getpaid_email_headers', $headers, $this ); |
|
117 | + return apply_filters('getpaid_email_headers', $headers, $this); |
|
118 | 118 | |
119 | 119 | } |
120 | 120 | |
@@ -125,11 +125,11 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function before_sending() { |
127 | 127 | |
128 | - do_action( 'getpaid_before_send_email', $this ); |
|
129 | - add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
130 | - add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
131 | - add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
132 | - add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
128 | + do_action('getpaid_before_send_email', $this); |
|
129 | + add_filter('wp_mail_from', array($this, 'get_from_address'), 1000); |
|
130 | + add_filter('wp_mail_from_name', array($this, 'get_from_name'), 1000); |
|
131 | + add_filter('wp_mail_content_type', array($this, 'get_content_type'), 1000); |
|
132 | + add_filter('wp_mail', array($this, 'ensure_email_content'), 1000); |
|
133 | 133 | |
134 | 134 | } |
135 | 135 | |
@@ -138,13 +138,13 @@ discard block |
||
138 | 138 | */ |
139 | 139 | public function get_from_name() { |
140 | 140 | |
141 | - $from_name = wpinv_get_option( 'email_from_name', get_bloginfo( 'name' ) ); |
|
141 | + $from_name = wpinv_get_option('email_from_name', get_bloginfo('name')); |
|
142 | 142 | |
143 | - if ( empty( $from_name ) ) { |
|
144 | - $from_name = get_bloginfo( 'name' ); |
|
143 | + if (empty($from_name)) { |
|
144 | + $from_name = get_bloginfo('name'); |
|
145 | 145 | } |
146 | 146 | |
147 | - return wp_specialchars_decode( $from_name, ENT_QUOTES ); |
|
147 | + return wp_specialchars_decode($from_name, ENT_QUOTES); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -152,9 +152,9 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function get_from_address() { |
154 | 154 | |
155 | - $from_address = wpinv_get_option( 'email_from', $this->default_from_address() ); |
|
155 | + $from_address = wpinv_get_option('email_from', $this->default_from_address()); |
|
156 | 156 | |
157 | - if ( ! is_email( $from_address ) ) { |
|
157 | + if (!is_email($from_address)) { |
|
158 | 158 | $from_address = $this->default_from_address(); |
159 | 159 | } |
160 | 160 | |
@@ -174,14 +174,14 @@ discard block |
||
174 | 174 | public function default_from_address() { |
175 | 175 | |
176 | 176 | // Get the site domain and get rid of www. |
177 | - $sitename = strtolower( $_SERVER['SERVER_NAME'] ); |
|
178 | - if ( substr( $sitename, 0, 4 ) == 'www.' ) { |
|
179 | - $sitename = substr( $sitename, 4 ); |
|
177 | + $sitename = strtolower($_SERVER['SERVER_NAME']); |
|
178 | + if (substr($sitename, 0, 4) == 'www.') { |
|
179 | + $sitename = substr($sitename, 4); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | $from_email = 'wordpress@' . $sitename; |
183 | 183 | |
184 | - return apply_filters( 'getpaid_default_from_address', $from_email ); |
|
184 | + return apply_filters('getpaid_default_from_address', $from_email); |
|
185 | 185 | |
186 | 186 | } |
187 | 187 | |
@@ -193,10 +193,10 @@ discard block |
||
193 | 193 | */ |
194 | 194 | public function get_reply_to() { |
195 | 195 | |
196 | - $reply_to = current( wpinv_parse_list( wpinv_get_admin_email() ) ); |
|
196 | + $reply_to = current(wpinv_parse_list(wpinv_get_admin_email())); |
|
197 | 197 | |
198 | - if ( ! is_email( $reply_to ) ) { |
|
199 | - $reply_to = get_option( 'admin_email' ); |
|
198 | + if (!is_email($reply_to)) { |
|
199 | + $reply_to = get_option('admin_email'); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | return $reply_to; |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * |
208 | 208 | */ |
209 | 209 | public function get_content_type() { |
210 | - return apply_filters( 'getpaid_email_content_type', 'text/html', $this ); |
|
210 | + return apply_filters('getpaid_email_content_type', 'text/html', $this); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @return array wp_mail_data. |
217 | 217 | */ |
218 | - public function ensure_email_content( $args ) { |
|
218 | + public function ensure_email_content($args) { |
|
219 | 219 | $args['message'] = $this->wp_mail_data['email']; |
220 | 220 | return $args; |
221 | 221 | } |
@@ -226,11 +226,11 @@ discard block |
||
226 | 226 | */ |
227 | 227 | public function after_sending() { |
228 | 228 | |
229 | - do_action( 'getpaid_after_send_email', $this->wp_mail_data ); |
|
230 | - remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
231 | - remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
232 | - remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
233 | - remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
229 | + do_action('getpaid_after_send_email', $this->wp_mail_data); |
|
230 | + remove_filter('wp_mail_from', array($this, 'get_from_address'), 1000); |
|
231 | + remove_filter('wp_mail_from_name', array($this, 'get_from_name'), 1000); |
|
232 | + remove_filter('wp_mail_content_type', array($this, 'get_content_type'), 1000); |
|
233 | + remove_filter('wp_mail', array($this, 'ensure_email_content'), 1000); |
|
234 | 234 | |
235 | 235 | } |
236 | 236 |
@@ -17,45 +17,45 @@ discard block |
||
17 | 17 | */ |
18 | 18 | class BP_GetPaid_Component extends BP_Component { |
19 | 19 | |
20 | - /** |
|
21 | - * Start the component setup process. |
|
22 | - * |
|
23 | - * @since 2.1.5 |
|
24 | - */ |
|
25 | - public function __construct() { |
|
26 | - parent::start( |
|
27 | - 'getpaid', |
|
28 | - 'GetPaid', |
|
29 | - buddypress()->plugin_dir, |
|
30 | - array( |
|
31 | - 'adminbar_myaccount_order' => 30, |
|
32 | - ) |
|
33 | - ); |
|
34 | - } |
|
20 | + /** |
|
21 | + * Start the component setup process. |
|
22 | + * |
|
23 | + * @since 2.1.5 |
|
24 | + */ |
|
25 | + public function __construct() { |
|
26 | + parent::start( |
|
27 | + 'getpaid', |
|
28 | + 'GetPaid', |
|
29 | + buddypress()->plugin_dir, |
|
30 | + array( |
|
31 | + 'adminbar_myaccount_order' => 30, |
|
32 | + ) |
|
33 | + ); |
|
34 | + } |
|
35 | 35 | |
36 | 36 | /** |
37 | - * Set up component global variables. |
|
38 | - * |
|
39 | - * @since 2.1.5 |
|
40 | - * |
|
41 | - * |
|
42 | - * @param array $args { |
|
43 | - * All values are optional. |
|
44 | - * @type string $slug The component slug. Used to construct certain URLs, such as 'friends' in |
|
45 | - * http://example.com/members/joe/friends/. Default: the value of $this->id. |
|
46 | - * @type string $root_slug The component root slug. Note that this value is generally unused if the |
|
47 | - * component has a root directory (the slug will be overridden by the |
|
48 | - * post_name of the directory page). Default: the slug of the directory page |
|
49 | - * if one is found, otherwise an empty string. |
|
50 | - * @type bool $has_directory Set to true if the component requires an associated WordPress page. |
|
51 | - * @type callable $notification_callback Optional. The callable function that formats the component's notifications. |
|
52 | - * @type string $search_term Optional. The placeholder text in the component directory search box. Eg, |
|
53 | - * 'Search Groups...'. |
|
54 | - * @type array $global_tables Optional. An array of database table names. |
|
55 | - * @type array $meta_tables Optional. An array of metadata table names. |
|
56 | - * } |
|
57 | - */ |
|
58 | - public function setup_globals( $args = array() ) { |
|
37 | + * Set up component global variables. |
|
38 | + * |
|
39 | + * @since 2.1.5 |
|
40 | + * |
|
41 | + * |
|
42 | + * @param array $args { |
|
43 | + * All values are optional. |
|
44 | + * @type string $slug The component slug. Used to construct certain URLs, such as 'friends' in |
|
45 | + * http://example.com/members/joe/friends/. Default: the value of $this->id. |
|
46 | + * @type string $root_slug The component root slug. Note that this value is generally unused if the |
|
47 | + * component has a root directory (the slug will be overridden by the |
|
48 | + * post_name of the directory page). Default: the slug of the directory page |
|
49 | + * if one is found, otherwise an empty string. |
|
50 | + * @type bool $has_directory Set to true if the component requires an associated WordPress page. |
|
51 | + * @type callable $notification_callback Optional. The callable function that formats the component's notifications. |
|
52 | + * @type string $search_term Optional. The placeholder text in the component directory search box. Eg, |
|
53 | + * 'Search Groups...'. |
|
54 | + * @type array $global_tables Optional. An array of database table names. |
|
55 | + * @type array $meta_tables Optional. An array of metadata table names. |
|
56 | + * } |
|
57 | + */ |
|
58 | + public function setup_globals( $args = array() ) { |
|
59 | 59 | parent::setup_globals( |
60 | 60 | array( |
61 | 61 | 'id' => 'getpaid', |
@@ -64,21 +64,21 @@ discard block |
||
64 | 64 | 'has_directory' => false, |
65 | 65 | ) |
66 | 66 | ); |
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Set up component navigation. |
|
71 | - * |
|
72 | - * @since 2.1.5 |
|
73 | - * |
|
74 | - * @see BP_Component::setup_nav() for a description of arguments. |
|
75 | - * |
|
76 | - * @param array $main_nav Optional. See BP_Component::setup_nav() for description. |
|
77 | - * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. |
|
78 | - */ |
|
79 | - public function setup_nav( $main_nav = array(), $sub_nav = array() ) { |
|
80 | - |
|
81 | - // Abort if the integration is inactive. |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Set up component navigation. |
|
71 | + * |
|
72 | + * @since 2.1.5 |
|
73 | + * |
|
74 | + * @see BP_Component::setup_nav() for a description of arguments. |
|
75 | + * |
|
76 | + * @param array $main_nav Optional. See BP_Component::setup_nav() for description. |
|
77 | + * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. |
|
78 | + */ |
|
79 | + public function setup_nav( $main_nav = array(), $sub_nav = array() ) { |
|
80 | + |
|
81 | + // Abort if the integration is inactive. |
|
82 | 82 | if ( ! getpaid_is_buddypress_integration_active() || ! is_user_logged_in() ) { |
83 | 83 | return; |
84 | 84 | } |
@@ -88,25 +88,25 @@ discard block |
||
88 | 88 | return; |
89 | 89 | } |
90 | 90 | |
91 | - // Determine user to use. |
|
92 | - $user_domain = bp_loggedin_user_domain(); |
|
93 | - $slug = 'getpaid'; |
|
94 | - $payments_link = trailingslashit( $user_domain . $slug ); |
|
95 | - |
|
96 | - // Add 'Payments' to the main navigation. |
|
97 | - $main_nav = array( |
|
98 | - 'name' => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ), |
|
99 | - 'slug' => $slug, |
|
100 | - 'position' => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ), |
|
101 | - 'screen_function' => array( $this, 'display_current_tab' ), |
|
102 | - 'default_subnav_slug' => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
91 | + // Determine user to use. |
|
92 | + $user_domain = bp_loggedin_user_domain(); |
|
93 | + $slug = 'getpaid'; |
|
94 | + $payments_link = trailingslashit( $user_domain . $slug ); |
|
95 | + |
|
96 | + // Add 'Payments' to the main navigation. |
|
97 | + $main_nav = array( |
|
98 | + 'name' => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ), |
|
99 | + 'slug' => $slug, |
|
100 | + 'position' => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ), |
|
101 | + 'screen_function' => array( $this, 'display_current_tab' ), |
|
102 | + 'default_subnav_slug' => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
103 | 103 | 'show_for_displayed_user' => false, |
104 | - 'item_css_id' => $this->id, |
|
105 | - 'parent_url' => $user_domain, |
|
106 | - 'parent_slug' => buddypress()->slug, |
|
107 | - ); |
|
104 | + 'item_css_id' => $this->id, |
|
105 | + 'parent_url' => $user_domain, |
|
106 | + 'parent_slug' => buddypress()->slug, |
|
107 | + ); |
|
108 | 108 | |
109 | - // Add the subnav items to the payments nav item if we are using a theme that supports this. |
|
109 | + // Add the subnav items to the payments nav item if we are using a theme that supports this. |
|
110 | 110 | foreach ( getpaid_get_user_content_tabs() as $_slug => $tab ) { |
111 | 111 | |
112 | 112 | $sub_nav[] = array( |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | 'parent_slug' => $slug, |
117 | 117 | 'position' => 10, |
118 | 118 | 'screen_function' => function() use ( $tab ) { |
119 | - $GLOBALS['getpaid_bp_current_tab'] = $tab; |
|
120 | - $this->display_current_tab(); |
|
119 | + $GLOBALS['getpaid_bp_current_tab'] = $tab; |
|
120 | + $this->display_current_tab(); |
|
121 | 121 | }, |
122 | 122 | 'show_for_displayed_user' => false, |
123 | 123 | 'item_css_id' => "getpaid-bp-$_slug", |
@@ -125,27 +125,27 @@ discard block |
||
125 | 125 | |
126 | 126 | } |
127 | 127 | |
128 | - parent::setup_nav( $main_nav, $sub_nav ); |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Set up the component entries in the WordPress Admin Bar. |
|
133 | - * |
|
134 | - * @since 2.1.5 |
|
135 | - * |
|
136 | - * @see BP_Component::setup_nav() for a description of the $wp_admin_nav |
|
137 | - * parameter array. |
|
138 | - * |
|
139 | - * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a |
|
140 | - * description. |
|
141 | - */ |
|
142 | - public function setup_admin_bar( $wp_admin_nav = array() ) { |
|
128 | + parent::setup_nav( $main_nav, $sub_nav ); |
|
129 | + } |
|
143 | 130 | |
144 | - // Menus for logged in user. |
|
145 | - if ( is_user_logged_in() ) { |
|
146 | - |
|
147 | - // Setup the logged in user variables. |
|
148 | - $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' ); |
|
131 | + /** |
|
132 | + * Set up the component entries in the WordPress Admin Bar. |
|
133 | + * |
|
134 | + * @since 2.1.5 |
|
135 | + * |
|
136 | + * @see BP_Component::setup_nav() for a description of the $wp_admin_nav |
|
137 | + * parameter array. |
|
138 | + * |
|
139 | + * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a |
|
140 | + * description. |
|
141 | + */ |
|
142 | + public function setup_admin_bar( $wp_admin_nav = array() ) { |
|
143 | + |
|
144 | + // Menus for logged in user. |
|
145 | + if ( is_user_logged_in() ) { |
|
146 | + |
|
147 | + // Setup the logged in user variables. |
|
148 | + $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' ); |
|
149 | 149 | |
150 | 150 | // Add the "Payments" sub menu. |
151 | 151 | $wp_admin_nav[] = array( |
@@ -168,48 +168,48 @@ discard block |
||
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
171 | - parent::setup_admin_bar( $wp_admin_nav ); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Retrieves the current tab. |
|
176 | - * |
|
177 | - * @since 2.1.5 |
|
178 | - */ |
|
179 | - public function get_current_tab() { |
|
180 | - global $getpaid_bp_current_tab; |
|
181 | - |
|
182 | - if ( empty( $getpaid_bp_current_tab ) ) { |
|
183 | - return array( |
|
184 | - 'label' => __( 'Invoices', 'invoicing' ), |
|
185 | - 'content' => '[wpinv_history]', |
|
186 | - 'icon' => 'fas fa-file-invoice', |
|
187 | - ); |
|
188 | - } |
|
189 | - |
|
190 | - return $getpaid_bp_current_tab; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Displays the current tab. |
|
195 | - * |
|
196 | - * @since 2.1.5 |
|
197 | - */ |
|
198 | - public function display_current_tab() { |
|
199 | - |
|
200 | - add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) ); |
|
201 | - $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ); |
|
171 | + parent::setup_admin_bar( $wp_admin_nav ); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Retrieves the current tab. |
|
176 | + * |
|
177 | + * @since 2.1.5 |
|
178 | + */ |
|
179 | + public function get_current_tab() { |
|
180 | + global $getpaid_bp_current_tab; |
|
181 | + |
|
182 | + if ( empty( $getpaid_bp_current_tab ) ) { |
|
183 | + return array( |
|
184 | + 'label' => __( 'Invoices', 'invoicing' ), |
|
185 | + 'content' => '[wpinv_history]', |
|
186 | + 'icon' => 'fas fa-file-invoice', |
|
187 | + ); |
|
188 | + } |
|
189 | + |
|
190 | + return $getpaid_bp_current_tab; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Displays the current tab. |
|
195 | + * |
|
196 | + * @since 2.1.5 |
|
197 | + */ |
|
198 | + public function display_current_tab() { |
|
199 | + |
|
200 | + add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) ); |
|
201 | + $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ); |
|
202 | 202 | |
203 | 203 | bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) ); |
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Handles the actual display of the current tab. |
|
208 | - * |
|
209 | - * @since 2.1.5 |
|
210 | - */ |
|
211 | - public function handle_display_current_tab() { |
|
212 | - echo getpaid_prepare_user_content_tab( $this->get_current_tab() ); |
|
213 | - } |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Handles the actual display of the current tab. |
|
208 | + * |
|
209 | + * @since 2.1.5 |
|
210 | + */ |
|
211 | + public function handle_display_current_tab() { |
|
212 | + echo getpaid_prepare_user_content_tab( $this->get_current_tab() ); |
|
213 | + } |
|
214 | 214 | |
215 | 215 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | // Exit if accessed directly. |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Main GetPaid Class. |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @type array $meta_tables Optional. An array of metadata table names. |
56 | 56 | * } |
57 | 57 | */ |
58 | - public function setup_globals( $args = array() ) { |
|
58 | + public function setup_globals($args = array()) { |
|
59 | 59 | parent::setup_globals( |
60 | 60 | array( |
61 | 61 | 'id' => 'getpaid', |
@@ -76,30 +76,30 @@ discard block |
||
76 | 76 | * @param array $main_nav Optional. See BP_Component::setup_nav() for description. |
77 | 77 | * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. |
78 | 78 | */ |
79 | - public function setup_nav( $main_nav = array(), $sub_nav = array() ) { |
|
79 | + public function setup_nav($main_nav = array(), $sub_nav = array()) { |
|
80 | 80 | |
81 | 81 | // Abort if the integration is inactive. |
82 | - if ( ! getpaid_is_buddypress_integration_active() || ! is_user_logged_in() ) { |
|
82 | + if (!getpaid_is_buddypress_integration_active() || !is_user_logged_in()) { |
|
83 | 83 | return; |
84 | 84 | } |
85 | 85 | |
86 | 86 | // Or a user is not viewing their profile. |
87 | - if ( bp_displayed_user_id() !== bp_loggedin_user_id() ) { |
|
87 | + if (bp_displayed_user_id() !== bp_loggedin_user_id()) { |
|
88 | 88 | return; |
89 | 89 | } |
90 | 90 | |
91 | 91 | // Determine user to use. |
92 | 92 | $user_domain = bp_loggedin_user_domain(); |
93 | 93 | $slug = 'getpaid'; |
94 | - $payments_link = trailingslashit( $user_domain . $slug ); |
|
94 | + $payments_link = trailingslashit($user_domain . $slug); |
|
95 | 95 | |
96 | 96 | // Add 'Payments' to the main navigation. |
97 | 97 | $main_nav = array( |
98 | - 'name' => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ), |
|
98 | + 'name' => _x('Billing', 'BuddyPress profile payments screen nav', 'invoicing'), |
|
99 | 99 | 'slug' => $slug, |
100 | - 'position' => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ), |
|
101 | - 'screen_function' => array( $this, 'display_current_tab' ), |
|
102 | - 'default_subnav_slug' => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
100 | + 'position' => apply_filters('wpinv_bp_nav_position', wpinv_get_option('wpinv_menu_position', 91), $slug), |
|
101 | + 'screen_function' => array($this, 'display_current_tab'), |
|
102 | + 'default_subnav_slug' => apply_filters('getpaid_default_tab', 'gp-edit-address'), |
|
103 | 103 | 'show_for_displayed_user' => false, |
104 | 104 | 'item_css_id' => $this->id, |
105 | 105 | 'parent_url' => $user_domain, |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | ); |
108 | 108 | |
109 | 109 | // Add the subnav items to the payments nav item if we are using a theme that supports this. |
110 | - foreach ( getpaid_get_user_content_tabs() as $_slug => $tab ) { |
|
110 | + foreach (getpaid_get_user_content_tabs() as $_slug => $tab) { |
|
111 | 111 | |
112 | 112 | $sub_nav[] = array( |
113 | 113 | 'name' => $tab['label'], |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | 'parent_url' => $payments_link, |
116 | 116 | 'parent_slug' => $slug, |
117 | 117 | 'position' => 10, |
118 | - 'screen_function' => function() use ( $tab ) { |
|
118 | + 'screen_function' => function() use ($tab) { |
|
119 | 119 | $GLOBALS['getpaid_bp_current_tab'] = $tab; |
120 | 120 | $this->display_current_tab(); |
121 | 121 | }, |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | |
126 | 126 | } |
127 | 127 | |
128 | - parent::setup_nav( $main_nav, $sub_nav ); |
|
128 | + parent::setup_nav($main_nav, $sub_nav); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -139,36 +139,36 @@ discard block |
||
139 | 139 | * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a |
140 | 140 | * description. |
141 | 141 | */ |
142 | - public function setup_admin_bar( $wp_admin_nav = array() ) { |
|
142 | + public function setup_admin_bar($wp_admin_nav = array()) { |
|
143 | 143 | |
144 | 144 | // Menus for logged in user. |
145 | - if ( is_user_logged_in() ) { |
|
145 | + if (is_user_logged_in()) { |
|
146 | 146 | |
147 | 147 | // Setup the logged in user variables. |
148 | - $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' ); |
|
148 | + $payments_link = trailingslashit(bp_loggedin_user_domain() . 'getpaid/'); |
|
149 | 149 | |
150 | 150 | // Add the "Payments" sub menu. |
151 | 151 | $wp_admin_nav[] = array( |
152 | 152 | 'parent' => buddypress()->my_account_menu_id, |
153 | 153 | 'id' => 'my-account-getpaid', |
154 | - 'title' => _x( 'Billing', 'BuddyPress my account payments sub nav', 'invoicing' ), |
|
155 | - 'href' => $payments_link . apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
154 | + 'title' => _x('Billing', 'BuddyPress my account payments sub nav', 'invoicing'), |
|
155 | + 'href' => $payments_link . apply_filters('getpaid_default_tab', 'gp-edit-address'), |
|
156 | 156 | ); |
157 | 157 | |
158 | - foreach ( getpaid_get_user_content_tabs() as $slug => $tab ) { |
|
158 | + foreach (getpaid_get_user_content_tabs() as $slug => $tab) { |
|
159 | 159 | |
160 | 160 | $wp_admin_nav[] = array( |
161 | 161 | 'parent' => 'my-account-getpaid', |
162 | 162 | 'id' => 'my-account-getpaid' . $slug, |
163 | 163 | 'title' => $tab['label'], |
164 | - 'href' => trailingslashit( $payments_link . $slug ), |
|
164 | + 'href' => trailingslashit($payments_link . $slug), |
|
165 | 165 | 'position' => 20, |
166 | 166 | ); |
167 | 167 | |
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
171 | - parent::setup_admin_bar( $wp_admin_nav ); |
|
171 | + parent::setup_admin_bar($wp_admin_nav); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | public function get_current_tab() { |
180 | 180 | global $getpaid_bp_current_tab; |
181 | 181 | |
182 | - if ( empty( $getpaid_bp_current_tab ) ) { |
|
182 | + if (empty($getpaid_bp_current_tab)) { |
|
183 | 183 | return array( |
184 | - 'label' => __( 'Invoices', 'invoicing' ), |
|
184 | + 'label' => __('Invoices', 'invoicing'), |
|
185 | 185 | 'content' => '[wpinv_history]', |
186 | 186 | 'icon' => 'fas fa-file-invoice', |
187 | 187 | ); |
@@ -197,10 +197,10 @@ discard block |
||
197 | 197 | */ |
198 | 198 | public function display_current_tab() { |
199 | 199 | |
200 | - add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) ); |
|
201 | - $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ); |
|
200 | + add_action('bp_template_content', array($this, 'handle_display_current_tab')); |
|
201 | + $template = apply_filters('bp_core_template_plugin', 'members/single/plugins'); |
|
202 | 202 | |
203 | - bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) ); |
|
203 | + bp_core_load_template(apply_filters('wpinv_bp_core_template_plugin', $template)); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | * @since 2.1.5 |
210 | 210 | */ |
211 | 211 | public function handle_display_current_tab() { |
212 | - echo getpaid_prepare_user_content_tab( $this->get_current_tab() ); |
|
212 | + echo getpaid_prepare_user_content_tab($this->get_current_tab()); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | } |
@@ -26,71 +26,71 @@ discard block |
||
26 | 26 | |
27 | 27 | <?php |
28 | 28 | |
29 | - // Fires before printing a line item column. |
|
30 | - do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
29 | + // Fires before printing a line item column. |
|
30 | + do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
31 | 31 | |
32 | - // Item name. |
|
33 | - if ( 'name' === $key ) { |
|
32 | + // Item name. |
|
33 | + if ( 'name' === $key ) { |
|
34 | 34 | |
35 | 35 | |
36 | - ob_start(); |
|
36 | + ob_start(); |
|
37 | 37 | |
38 | - // Add an optional description. |
|
39 | - $description = $item->get_description(); |
|
38 | + // Add an optional description. |
|
39 | + $description = $item->get_description(); |
|
40 | 40 | |
41 | - if ( ! empty( $description ) ) { |
|
42 | - echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post( $description ) . '</small>'; |
|
43 | - } |
|
41 | + if ( ! empty( $description ) ) { |
|
42 | + echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post( $description ) . '</small>'; |
|
43 | + } |
|
44 | 44 | |
45 | - // Price help text. |
|
46 | - $description = getpaid_item_recurring_price_help_text( $item, $currency ); |
|
47 | - if ( $description ) { |
|
48 | - echo "<small class='getpaid-form-item-price-desc form-text text-muted font-italic pr-2 m-0'>" . wp_kses_post( $description ) . '</small>'; |
|
49 | - } |
|
45 | + // Price help text. |
|
46 | + $description = getpaid_item_recurring_price_help_text( $item, $currency ); |
|
47 | + if ( $description ) { |
|
48 | + echo "<small class='getpaid-form-item-price-desc form-text text-muted font-italic pr-2 m-0'>" . wp_kses_post( $description ) . '</small>'; |
|
49 | + } |
|
50 | 50 | |
51 | - do_action( 'getpaid_payment_form_cart_item_description', $item, $form ); |
|
51 | + do_action( 'getpaid_payment_form_cart_item_description', $item, $form ); |
|
52 | 52 | |
53 | - if ( wpinv_current_user_can_manage_invoicing() ) { |
|
53 | + if ( wpinv_current_user_can_manage_invoicing() ) { |
|
54 | 54 | |
55 | - edit_post_link( |
|
56 | - __( 'Edit this item.', 'invoicing' ), |
|
57 | - '<small class="form-text text-muted">', |
|
58 | - '</small>', |
|
59 | - $item->get_id(), |
|
60 | - 'text-danger' |
|
61 | - ); |
|
55 | + edit_post_link( |
|
56 | + __( 'Edit this item.', 'invoicing' ), |
|
57 | + '<small class="form-text text-muted">', |
|
58 | + '</small>', |
|
59 | + $item->get_id(), |
|
60 | + 'text-danger' |
|
61 | + ); |
|
62 | 62 | |
63 | - } |
|
63 | + } |
|
64 | 64 | |
65 | - $description = ob_get_clean(); |
|
65 | + $description = ob_get_clean(); |
|
66 | 66 | |
67 | - // Display the name. |
|
68 | - $tootip = empty( $description ) ? '' : ' <i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>'; |
|
67 | + // Display the name. |
|
68 | + $tootip = empty( $description ) ? '' : ' <i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>'; |
|
69 | 69 | |
70 | - $has_featured_image = has_post_thumbnail( $item->get_id() ); |
|
70 | + $has_featured_image = has_post_thumbnail( $item->get_id() ); |
|
71 | 71 | |
72 | - if ( $has_featured_image ) { |
|
73 | - echo '<div class="d-flex align-items-center getpaid-form-item-has-featured-image">'; |
|
74 | - echo '<div class="getpaid-form-item-image-container mr-2">'; |
|
75 | - echo get_the_post_thumbnail( $item->get_id(), 'thumbnail', array( 'class' => 'getpaid-form-item-image mb-0' ) ); |
|
76 | - echo '</div>'; |
|
77 | - echo '<div class="getpaid-form-item-name-container">'; |
|
78 | - } |
|
72 | + if ( $has_featured_image ) { |
|
73 | + echo '<div class="d-flex align-items-center getpaid-form-item-has-featured-image">'; |
|
74 | + echo '<div class="getpaid-form-item-image-container mr-2">'; |
|
75 | + echo get_the_post_thumbnail( $item->get_id(), 'thumbnail', array( 'class' => 'getpaid-form-item-image mb-0' ) ); |
|
76 | + echo '</div>'; |
|
77 | + echo '<div class="getpaid-form-item-name-container">'; |
|
78 | + } |
|
79 | 79 | |
80 | - echo '<div class="mb-1 font-weight-bold">' . esc_html( $item->get_name() ) . wp_kses_post( $tootip ) . '</div>'; |
|
80 | + echo '<div class="mb-1 font-weight-bold">' . esc_html( $item->get_name() ) . wp_kses_post( $tootip ) . '</div>'; |
|
81 | 81 | |
82 | - if ( ! empty( $description ) ) { |
|
83 | - printf( '<span class="d-none d-sm-block getpaid-item-desc">%s</span>', wp_kses_post( $description ) ); |
|
84 | - } |
|
82 | + if ( ! empty( $description ) ) { |
|
83 | + printf( '<span class="d-none d-sm-block getpaid-item-desc">%s</span>', wp_kses_post( $description ) ); |
|
84 | + } |
|
85 | 85 | |
86 | - if ( $item->allows_quantities() ) { |
|
87 | - printf( |
|
88 | - '<small class="d-sm-none text-muted form-text">%s</small>', |
|
89 | - sprintf( |
|
90 | - // translators: %s is the item quantity. |
|
91 | - esc_html__( 'Qty %s', 'invoicing' ), |
|
92 | - sprintf( |
|
93 | - '<input |
|
86 | + if ( $item->allows_quantities() ) { |
|
87 | + printf( |
|
88 | + '<small class="d-sm-none text-muted form-text">%s</small>', |
|
89 | + sprintf( |
|
90 | + // translators: %s is the item quantity. |
|
91 | + esc_html__( 'Qty %s', 'invoicing' ), |
|
92 | + sprintf( |
|
93 | + '<input |
|
94 | 94 | type="number" |
95 | 95 | step="0.01" |
96 | 96 | style="width: 48px;" |
@@ -99,62 +99,62 @@ discard block |
||
99 | 99 | min="1" |
100 | 100 | max="%s" |
101 | 101 | >', |
102 | - (float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(), |
|
103 | - floatval( null !== $max_qty ? $max_qty : 1000000000000 ) |
|
104 | - ) |
|
105 | - ) |
|
106 | - ); |
|
107 | - } else { |
|
108 | - printf( |
|
109 | - '<small class="d-sm-none text-muted form-text">%s</small>', |
|
110 | - sprintf( |
|
111 | - // translators: %s is the item quantity. |
|
112 | - esc_html__( 'Qty %s', 'invoicing' ), |
|
113 | - (float) $item->get_quantity() |
|
114 | - ) |
|
115 | - ); |
|
116 | - } |
|
117 | - |
|
118 | - if ( $has_featured_image ) { |
|
119 | - echo '</div>'; |
|
120 | - echo '</div>'; |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - // Item price. |
|
125 | - if ( 'price' === $key ) { |
|
126 | - |
|
127 | - // Set the currency position. |
|
128 | - $position = wpinv_currency_position(); |
|
129 | - |
|
130 | - if ( 'left_space' === $position ) { |
|
131 | - $position = 'left'; |
|
132 | - } |
|
133 | - |
|
134 | - if ( 'right_space' === $position ) { |
|
135 | - $position = 'right'; |
|
136 | - } |
|
137 | - |
|
138 | - if ( $item->user_can_set_their_price() ) { |
|
139 | - $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
140 | - $minimum = (float) $item->get_minimum_price(); |
|
141 | - $validate_minimum = ''; |
|
142 | - $class = ''; |
|
143 | - $data_minimum = ''; |
|
144 | - |
|
145 | - if ( $minimum > 0 ) { |
|
146 | - $validate_minimum = sprintf( |
|
147 | - // translators: %s is the minimum price. |
|
148 | - esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ), |
|
149 | - wp_strip_all_tags( wpinv_price( $minimum, $currency ) ) |
|
150 | - ); |
|
151 | - |
|
152 | - $class = 'getpaid-validate-minimum-amount'; |
|
153 | - |
|
154 | - $data_minimum = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'"; |
|
155 | - } |
|
156 | - |
|
157 | - ?> |
|
102 | + (float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(), |
|
103 | + floatval( null !== $max_qty ? $max_qty : 1000000000000 ) |
|
104 | + ) |
|
105 | + ) |
|
106 | + ); |
|
107 | + } else { |
|
108 | + printf( |
|
109 | + '<small class="d-sm-none text-muted form-text">%s</small>', |
|
110 | + sprintf( |
|
111 | + // translators: %s is the item quantity. |
|
112 | + esc_html__( 'Qty %s', 'invoicing' ), |
|
113 | + (float) $item->get_quantity() |
|
114 | + ) |
|
115 | + ); |
|
116 | + } |
|
117 | + |
|
118 | + if ( $has_featured_image ) { |
|
119 | + echo '</div>'; |
|
120 | + echo '</div>'; |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + // Item price. |
|
125 | + if ( 'price' === $key ) { |
|
126 | + |
|
127 | + // Set the currency position. |
|
128 | + $position = wpinv_currency_position(); |
|
129 | + |
|
130 | + if ( 'left_space' === $position ) { |
|
131 | + $position = 'left'; |
|
132 | + } |
|
133 | + |
|
134 | + if ( 'right_space' === $position ) { |
|
135 | + $position = 'right'; |
|
136 | + } |
|
137 | + |
|
138 | + if ( $item->user_can_set_their_price() ) { |
|
139 | + $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
140 | + $minimum = (float) $item->get_minimum_price(); |
|
141 | + $validate_minimum = ''; |
|
142 | + $class = ''; |
|
143 | + $data_minimum = ''; |
|
144 | + |
|
145 | + if ( $minimum > 0 ) { |
|
146 | + $validate_minimum = sprintf( |
|
147 | + // translators: %s is the minimum price. |
|
148 | + esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ), |
|
149 | + wp_strip_all_tags( wpinv_price( $minimum, $currency ) ) |
|
150 | + ); |
|
151 | + |
|
152 | + $class = 'getpaid-validate-minimum-amount'; |
|
153 | + |
|
154 | + $data_minimum = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'"; |
|
155 | + } |
|
156 | + |
|
157 | + ?> |
|
158 | 158 | <div class="input-group input-group-sm"> |
159 | 159 | <?php if ( 'left' === $position ) : ?> |
160 | 160 | <div class="input-group-prepend"> |
@@ -179,44 +179,44 @@ discard block |
||
179 | 179 | |
180 | 180 | <?php |
181 | 181 | |
182 | - } else { |
|
183 | - echo wp_kses_post( wpinv_price( $item->get_price(), $currency ) ); |
|
182 | + } else { |
|
183 | + echo wp_kses_post( wpinv_price( $item->get_price(), $currency ) ); |
|
184 | 184 | |
185 | - ?> |
|
185 | + ?> |
|
186 | 186 | <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr( $item->get_price() ); ?>'> |
187 | 187 | <?php |
188 | - } |
|
188 | + } |
|
189 | 189 | |
190 | - printf( |
|
190 | + printf( |
|
191 | 191 | '<small class="d-sm-none text-muted form-text getpaid-mobile-item-subtotal">%s</small>', |
192 | - // translators: %s is the item subtotal. |
|
192 | + // translators: %s is the item subtotal. |
|
193 | 193 | sprintf( esc_html__( 'Subtotal: %s', 'invoicing' ), wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ) ) |
194 | 194 | ); |
195 | - } |
|
195 | + } |
|
196 | 196 | |
197 | - // Item quantity. |
|
198 | - if ( 'quantity' === $key ) { |
|
197 | + // Item quantity. |
|
198 | + if ( 'quantity' === $key ) { |
|
199 | 199 | |
200 | - if ( $item->allows_quantities() ) { |
|
201 | - ?> |
|
200 | + if ( $item->allows_quantities() ) { |
|
201 | + ?> |
|
202 | 202 | <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' type="number" step="any" style='width: 64px; line-height: 1; min-height: 35px;' class='getpaid-item-quantity-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border' value='<?php echo (float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(); ?>' min='1' <?php echo null !== $max_qty ? 'max="' . (float) $max_qty . '"' : ''; ?> required> |
203 | 203 | <?php |
204 | - } else { |
|
205 | - echo (float) $item->get_quantity(); |
|
206 | - echo ' '; |
|
207 | - ?> |
|
204 | + } else { |
|
205 | + echo (float) $item->get_quantity(); |
|
206 | + echo ' '; |
|
207 | + ?> |
|
208 | 208 | <input type='hidden' name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' class='getpaid-item-quantity-input' value='<?php echo (float) $item->get_quantity(); ?>'> |
209 | 209 | <?php |
210 | - } |
|
210 | + } |
|
211 | 211 | } |
212 | 212 | |
213 | - // Item sub total. |
|
214 | - if ( 'subtotal' === $key ) { |
|
215 | - echo wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ); |
|
216 | - } |
|
213 | + // Item sub total. |
|
214 | + if ( 'subtotal' === $key ) { |
|
215 | + echo wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ); |
|
216 | + } |
|
217 | 217 | |
218 | - do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
219 | - ?> |
|
218 | + do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
219 | + ?> |
|
220 | 220 | |
221 | 221 | </div> |
222 | 222 |
@@ -9,28 +9,28 @@ discard block |
||
9 | 9 | * @var GetPaid_Form_Item $item |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | -do_action( 'getpaid_before_payment_form_cart_item', $form, $item ); |
|
14 | +do_action('getpaid_before_payment_form_cart_item', $form, $item); |
|
15 | 15 | |
16 | 16 | $currency = $form->get_currency(); |
17 | -$max_qty = wpinv_item_max_buyable_quantity( $item->get_id() ); |
|
17 | +$max_qty = wpinv_item_max_buyable_quantity($item->get_id()); |
|
18 | 18 | ?> |
19 | 19 | <div class='getpaid-payment-form-items-cart-item getpaid-<?php echo $item->is_required() ? 'required' : 'selectable'; ?> item-<?php echo (int) $item->get_id(); ?> border-bottom py-2 px-3'> |
20 | 20 | |
21 | 21 | <div class="form-row align-items-center needs-validation"> |
22 | 22 | |
23 | - <?php foreach ( array_keys( $columns ) as $key ) : ?> |
|
23 | + <?php foreach (array_keys($columns) as $key) : ?> |
|
24 | 24 | |
25 | - <div class="<?php echo 'name' === $key ? 'col-6' : 'col'; ?> <?php echo ( in_array( $key, array( 'subtotal', 'quantity', 'tax_rate' ), true ) ) ? 'd-none d-sm-block' : ''; ?> position-relative getpaid-form-cart-item-<?php echo esc_attr( $key ); ?> getpaid-form-cart-item-<?php echo esc_attr( $key ); ?>-<?php echo (int) $item->get_id(); ?>"> |
|
25 | + <div class="<?php echo 'name' === $key ? 'col-6' : 'col'; ?> <?php echo (in_array($key, array('subtotal', 'quantity', 'tax_rate'), true)) ? 'd-none d-sm-block' : ''; ?> position-relative getpaid-form-cart-item-<?php echo esc_attr($key); ?> getpaid-form-cart-item-<?php echo esc_attr($key); ?>-<?php echo (int) $item->get_id(); ?>"> |
|
26 | 26 | |
27 | 27 | <?php |
28 | 28 | |
29 | 29 | // Fires before printing a line item column. |
30 | - do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
30 | + do_action("getpaid_form_cart_item_before_$key", $item, $form); |
|
31 | 31 | |
32 | 32 | // Item name. |
33 | - if ( 'name' === $key ) { |
|
33 | + if ('name' === $key) { |
|
34 | 34 | |
35 | 35 | |
36 | 36 | ob_start(); |
@@ -38,22 +38,22 @@ discard block |
||
38 | 38 | // Add an optional description. |
39 | 39 | $description = $item->get_description(); |
40 | 40 | |
41 | - if ( ! empty( $description ) ) { |
|
42 | - echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post( $description ) . '</small>'; |
|
41 | + if (!empty($description)) { |
|
42 | + echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post($description) . '</small>'; |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | // Price help text. |
46 | - $description = getpaid_item_recurring_price_help_text( $item, $currency ); |
|
47 | - if ( $description ) { |
|
48 | - echo "<small class='getpaid-form-item-price-desc form-text text-muted font-italic pr-2 m-0'>" . wp_kses_post( $description ) . '</small>'; |
|
46 | + $description = getpaid_item_recurring_price_help_text($item, $currency); |
|
47 | + if ($description) { |
|
48 | + echo "<small class='getpaid-form-item-price-desc form-text text-muted font-italic pr-2 m-0'>" . wp_kses_post($description) . '</small>'; |
|
49 | 49 | } |
50 | 50 | |
51 | - do_action( 'getpaid_payment_form_cart_item_description', $item, $form ); |
|
51 | + do_action('getpaid_payment_form_cart_item_description', $item, $form); |
|
52 | 52 | |
53 | - if ( wpinv_current_user_can_manage_invoicing() ) { |
|
53 | + if (wpinv_current_user_can_manage_invoicing()) { |
|
54 | 54 | |
55 | 55 | edit_post_link( |
56 | - __( 'Edit this item.', 'invoicing' ), |
|
56 | + __('Edit this item.', 'invoicing'), |
|
57 | 57 | '<small class="form-text text-muted">', |
58 | 58 | '</small>', |
59 | 59 | $item->get_id(), |
@@ -65,30 +65,30 @@ discard block |
||
65 | 65 | $description = ob_get_clean(); |
66 | 66 | |
67 | 67 | // Display the name. |
68 | - $tootip = empty( $description ) ? '' : ' <i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>'; |
|
68 | + $tootip = empty($description) ? '' : ' <i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>'; |
|
69 | 69 | |
70 | - $has_featured_image = has_post_thumbnail( $item->get_id() ); |
|
70 | + $has_featured_image = has_post_thumbnail($item->get_id()); |
|
71 | 71 | |
72 | - if ( $has_featured_image ) { |
|
72 | + if ($has_featured_image) { |
|
73 | 73 | echo '<div class="d-flex align-items-center getpaid-form-item-has-featured-image">'; |
74 | 74 | echo '<div class="getpaid-form-item-image-container mr-2">'; |
75 | - echo get_the_post_thumbnail( $item->get_id(), 'thumbnail', array( 'class' => 'getpaid-form-item-image mb-0' ) ); |
|
75 | + echo get_the_post_thumbnail($item->get_id(), 'thumbnail', array('class' => 'getpaid-form-item-image mb-0')); |
|
76 | 76 | echo '</div>'; |
77 | 77 | echo '<div class="getpaid-form-item-name-container">'; |
78 | 78 | } |
79 | 79 | |
80 | - echo '<div class="mb-1 font-weight-bold">' . esc_html( $item->get_name() ) . wp_kses_post( $tootip ) . '</div>'; |
|
80 | + echo '<div class="mb-1 font-weight-bold">' . esc_html($item->get_name()) . wp_kses_post($tootip) . '</div>'; |
|
81 | 81 | |
82 | - if ( ! empty( $description ) ) { |
|
83 | - printf( '<span class="d-none d-sm-block getpaid-item-desc">%s</span>', wp_kses_post( $description ) ); |
|
82 | + if (!empty($description)) { |
|
83 | + printf('<span class="d-none d-sm-block getpaid-item-desc">%s</span>', wp_kses_post($description)); |
|
84 | 84 | } |
85 | 85 | |
86 | - if ( $item->allows_quantities() ) { |
|
86 | + if ($item->allows_quantities()) { |
|
87 | 87 | printf( |
88 | 88 | '<small class="d-sm-none text-muted form-text">%s</small>', |
89 | 89 | sprintf( |
90 | 90 | // translators: %s is the item quantity. |
91 | - esc_html__( 'Qty %s', 'invoicing' ), |
|
91 | + esc_html__('Qty %s', 'invoicing'), |
|
92 | 92 | sprintf( |
93 | 93 | '<input |
94 | 94 | type="number" |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | max="%s" |
101 | 101 | >', |
102 | 102 | (float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(), |
103 | - floatval( null !== $max_qty ? $max_qty : 1000000000000 ) |
|
103 | + floatval(null !== $max_qty ? $max_qty : 1000000000000) |
|
104 | 104 | ) |
105 | 105 | ) |
106 | 106 | ); |
@@ -109,70 +109,70 @@ discard block |
||
109 | 109 | '<small class="d-sm-none text-muted form-text">%s</small>', |
110 | 110 | sprintf( |
111 | 111 | // translators: %s is the item quantity. |
112 | - esc_html__( 'Qty %s', 'invoicing' ), |
|
112 | + esc_html__('Qty %s', 'invoicing'), |
|
113 | 113 | (float) $item->get_quantity() |
114 | 114 | ) |
115 | 115 | ); |
116 | 116 | } |
117 | 117 | |
118 | - if ( $has_featured_image ) { |
|
118 | + if ($has_featured_image) { |
|
119 | 119 | echo '</div>'; |
120 | 120 | echo '</div>'; |
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
124 | 124 | // Item price. |
125 | - if ( 'price' === $key ) { |
|
125 | + if ('price' === $key) { |
|
126 | 126 | |
127 | 127 | // Set the currency position. |
128 | 128 | $position = wpinv_currency_position(); |
129 | 129 | |
130 | - if ( 'left_space' === $position ) { |
|
130 | + if ('left_space' === $position) { |
|
131 | 131 | $position = 'left'; |
132 | 132 | } |
133 | 133 | |
134 | - if ( 'right_space' === $position ) { |
|
134 | + if ('right_space' === $position) { |
|
135 | 135 | $position = 'right'; |
136 | 136 | } |
137 | 137 | |
138 | - if ( $item->user_can_set_their_price() ) { |
|
139 | - $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
138 | + if ($item->user_can_set_their_price()) { |
|
139 | + $price = max((float) $item->get_price(), (float) $item->get_minimum_price()); |
|
140 | 140 | $minimum = (float) $item->get_minimum_price(); |
141 | 141 | $validate_minimum = ''; |
142 | 142 | $class = ''; |
143 | 143 | $data_minimum = ''; |
144 | 144 | |
145 | - if ( $minimum > 0 ) { |
|
145 | + if ($minimum > 0) { |
|
146 | 146 | $validate_minimum = sprintf( |
147 | 147 | // translators: %s is the minimum price. |
148 | - esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ), |
|
149 | - wp_strip_all_tags( wpinv_price( $minimum, $currency ) ) |
|
148 | + esc_attr__('The minimum allowed amount is %s', 'invoicing'), |
|
149 | + wp_strip_all_tags(wpinv_price($minimum, $currency)) |
|
150 | 150 | ); |
151 | 151 | |
152 | 152 | $class = 'getpaid-validate-minimum-amount'; |
153 | 153 | |
154 | - $data_minimum = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'"; |
|
154 | + $data_minimum = "data-minimum-amount='" . esc_attr(getpaid_unstandardize_amount($minimum)) . "'"; |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | ?> |
158 | 158 | <div class="input-group input-group-sm"> |
159 | - <?php if ( 'left' === $position ) : ?> |
|
159 | + <?php if ('left' === $position) : ?> |
|
160 | 160 | <div class="input-group-prepend"> |
161 | - <span class="input-group-text"><?php echo wp_kses_post( wpinv_currency_symbol( $currency ) ); ?></span> |
|
161 | + <span class="input-group-text"><?php echo wp_kses_post(wpinv_currency_symbol($currency)); ?></span> |
|
162 | 162 | </div> |
163 | 163 | <?php endif; ?> |
164 | 164 | |
165 | - <input type="text" <?php echo wp_kses_post( $data_minimum ); ?> name="getpaid-items[<?php echo (int) $item->get_id(); ?>][price]" value="<?php echo esc_attr( getpaid_unstandardize_amount( $price ) ); ?>" placeholder="<?php echo esc_attr( getpaid_unstandardize_amount( $item->get_minimum_price() ) ); ?>" class="getpaid-item-price-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border <?php echo esc_attr( $class ); ?>" style="width: 64px; line-height: 1; min-height: 35px;"> |
|
165 | + <input type="text" <?php echo wp_kses_post($data_minimum); ?> name="getpaid-items[<?php echo (int) $item->get_id(); ?>][price]" value="<?php echo esc_attr(getpaid_unstandardize_amount($price)); ?>" placeholder="<?php echo esc_attr(getpaid_unstandardize_amount($item->get_minimum_price())); ?>" class="getpaid-item-price-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border <?php echo esc_attr($class); ?>" style="width: 64px; line-height: 1; min-height: 35px;"> |
|
166 | 166 | |
167 | - <?php if ( ! empty( $validate_minimum ) ) : ?> |
|
167 | + <?php if (!empty($validate_minimum)) : ?> |
|
168 | 168 | <div class="invalid-tooltip"> |
169 | - <?php echo wp_kses_post( $validate_minimum ); ?> |
|
169 | + <?php echo wp_kses_post($validate_minimum); ?> |
|
170 | 170 | </div> |
171 | 171 | <?php endif; ?> |
172 | 172 | |
173 | - <?php if ( 'left' !== $position ) : ?> |
|
173 | + <?php if ('left' !== $position) : ?> |
|
174 | 174 | <div class="input-group-append"> |
175 | - <span class="input-group-text"><?php echo wp_kses_post( wpinv_currency_symbol( $currency ) ); ?></span> |
|
175 | + <span class="input-group-text"><?php echo wp_kses_post(wpinv_currency_symbol($currency)); ?></span> |
|
176 | 176 | </div> |
177 | 177 | <?php endif; ?> |
178 | 178 | </div> |
@@ -180,24 +180,24 @@ discard block |
||
180 | 180 | <?php |
181 | 181 | |
182 | 182 | } else { |
183 | - echo wp_kses_post( wpinv_price( $item->get_price(), $currency ) ); |
|
183 | + echo wp_kses_post(wpinv_price($item->get_price(), $currency)); |
|
184 | 184 | |
185 | 185 | ?> |
186 | - <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr( $item->get_price() ); ?>'> |
|
186 | + <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr($item->get_price()); ?>'> |
|
187 | 187 | <?php |
188 | 188 | } |
189 | 189 | |
190 | 190 | printf( |
191 | 191 | '<small class="d-sm-none text-muted form-text getpaid-mobile-item-subtotal">%s</small>', |
192 | 192 | // translators: %s is the item subtotal. |
193 | - sprintf( esc_html__( 'Subtotal: %s', 'invoicing' ), wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ) ) |
|
193 | + sprintf(esc_html__('Subtotal: %s', 'invoicing'), wp_kses_post(wpinv_price($item->get_sub_total(), $currency))) |
|
194 | 194 | ); |
195 | 195 | } |
196 | 196 | |
197 | 197 | // Item quantity. |
198 | - if ( 'quantity' === $key ) { |
|
198 | + if ('quantity' === $key) { |
|
199 | 199 | |
200 | - if ( $item->allows_quantities() ) { |
|
200 | + if ($item->allows_quantities()) { |
|
201 | 201 | ?> |
202 | 202 | <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' type="number" step="any" style='width: 64px; line-height: 1; min-height: 35px;' class='getpaid-item-quantity-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border' value='<?php echo (float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(); ?>' min='1' <?php echo null !== $max_qty ? 'max="' . (float) $max_qty . '"' : ''; ?> required> |
203 | 203 | <?php |
@@ -211,11 +211,11 @@ discard block |
||
211 | 211 | } |
212 | 212 | |
213 | 213 | // Item sub total. |
214 | - if ( 'subtotal' === $key ) { |
|
215 | - echo wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ); |
|
214 | + if ('subtotal' === $key) { |
|
215 | + echo wp_kses_post(wpinv_price($item->get_sub_total(), $currency)); |
|
216 | 216 | } |
217 | 217 | |
218 | - do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
218 | + do_action("getpaid_payment_form_cart_item_$key", $item, $form); |
|
219 | 219 | ?> |
220 | 220 | |
221 | 221 | </div> |
@@ -226,4 +226,4 @@ discard block |
||
226 | 226 | |
227 | 227 | </div> |
228 | 228 | <?php |
229 | -do_action( 'getpaid_payment_form_cart_item', $form, $item ); |
|
229 | +do_action('getpaid_payment_form_cart_item', $form, $item); |
@@ -13,462 +13,462 @@ discard block |
||
13 | 13 | */ |
14 | 14 | abstract class GetPaid_Payment_Gateway { |
15 | 15 | |
16 | - /** |
|
17 | - * Set if the place checkout button should be renamed on selection. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $checkout_button_text; |
|
22 | - |
|
23 | - /** |
|
24 | - * Boolean whether the method is enabled. |
|
25 | - * |
|
26 | - * @var bool |
|
27 | - */ |
|
28 | - public $enabled = true; |
|
29 | - |
|
30 | - /** |
|
31 | - * Payment method id. |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - public $id; |
|
36 | - |
|
37 | - /** |
|
38 | - * Payment method order. |
|
39 | - * |
|
40 | - * @var int |
|
41 | - */ |
|
42 | - public $order = 10; |
|
43 | - |
|
44 | - /** |
|
45 | - * Payment method title for the frontend. |
|
46 | - * |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - public $title; |
|
50 | - |
|
51 | - /** |
|
52 | - * Payment method description for the frontend. |
|
53 | - * |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - public $description; |
|
57 | - |
|
58 | - /** |
|
59 | - * Gateway title. |
|
60 | - * |
|
61 | - * @var string |
|
62 | - */ |
|
63 | - public $method_title = ''; |
|
64 | - |
|
65 | - /** |
|
66 | - * Gateway description. |
|
67 | - * |
|
68 | - * @var string |
|
69 | - */ |
|
70 | - public $method_description = ''; |
|
71 | - |
|
72 | - /** |
|
73 | - * Countries this gateway is allowed for. |
|
74 | - * |
|
75 | - * @var array |
|
76 | - */ |
|
77 | - public $countries; |
|
78 | - |
|
79 | - /** |
|
80 | - * Currencies this gateway is allowed for. |
|
81 | - * |
|
82 | - * @var array |
|
83 | - */ |
|
84 | - public $currencies; |
|
85 | - |
|
86 | - /** |
|
87 | - * Currencies this gateway is not allowed for. |
|
88 | - * |
|
89 | - * @var array |
|
90 | - */ |
|
91 | - public $exclude_currencies; |
|
92 | - |
|
93 | - /** |
|
94 | - * Maximum transaction amount, zero does not define a maximum. |
|
95 | - * |
|
96 | - * @var int |
|
97 | - */ |
|
98 | - public $max_amount = 0; |
|
99 | - |
|
100 | - /** |
|
101 | - * Optional URL to view a transaction. |
|
102 | - * |
|
103 | - * @var string |
|
104 | - */ |
|
105 | - public $view_transaction_url = ''; |
|
106 | - |
|
107 | - /** |
|
108 | - * Optional URL to view a subscription. |
|
109 | - * |
|
110 | - * @var string |
|
111 | - */ |
|
112 | - public $view_subscription_url = ''; |
|
113 | - |
|
114 | - /** |
|
115 | - * Optional label to show for "new payment method" in the payment |
|
116 | - * method/token selection radio selection. |
|
117 | - * |
|
118 | - * @var string |
|
119 | - */ |
|
120 | - public $new_method_label = ''; |
|
121 | - |
|
122 | - /** |
|
123 | - * Contains a user's saved tokens for this gateway. |
|
124 | - * |
|
125 | - * @var array |
|
126 | - */ |
|
127 | - protected $tokens = array(); |
|
128 | - |
|
129 | - /** |
|
130 | - * An array of features that this gateway supports. |
|
131 | - * |
|
132 | - * @var array |
|
133 | - */ |
|
134 | - protected $supports = array(); |
|
135 | - |
|
136 | - /** |
|
137 | - * Class constructor. |
|
138 | - */ |
|
139 | - public function __construct() { |
|
140 | - |
|
141 | - // Register gateway. |
|
142 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
143 | - |
|
144 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
145 | - |
|
146 | - // Add support for various features. |
|
147 | - foreach ( $this->supports as $feature ) { |
|
148 | - add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' ); |
|
149 | - add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' ); |
|
150 | - add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
151 | - } |
|
152 | - |
|
153 | - // Invoice addons. |
|
154 | - if ( $this->supports( 'addons' ) ) { |
|
155 | - add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
156 | - } |
|
157 | - |
|
158 | - // Gateway settings. |
|
159 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
160 | - |
|
161 | - // Gateway checkout fiellds. |
|
162 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
163 | - |
|
164 | - // Process payment. |
|
165 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
166 | - |
|
167 | - // Change the checkout button text. |
|
168 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
169 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
170 | - } |
|
171 | - |
|
172 | - // Check if a gateway is valid for a given currency. |
|
173 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
174 | - |
|
175 | - // Generate the transaction url. |
|
176 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
177 | - |
|
178 | - // Generate the subscription url. |
|
179 | - add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
180 | - |
|
181 | - // Confirm payments. |
|
182 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
183 | - |
|
184 | - // Verify IPNs. |
|
185 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
186 | - |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Checks if this gateway is a given gateway. |
|
191 | - * |
|
192 | - * @since 1.0.19 |
|
193 | - * @return bool |
|
194 | - */ |
|
195 | - public function is( $gateway ) { |
|
196 | - return $gateway == $this->id; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Returns a users saved tokens for this gateway. |
|
201 | - * |
|
202 | - * @since 1.0.19 |
|
203 | - * @return array |
|
204 | - */ |
|
205 | - public function get_tokens( $sandbox = null ) { |
|
206 | - |
|
207 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
208 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
209 | - |
|
210 | - if ( is_array( $tokens ) ) { |
|
211 | - $this->tokens = $tokens; |
|
212 | - } |
|
16 | + /** |
|
17 | + * Set if the place checkout button should be renamed on selection. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $checkout_button_text; |
|
22 | + |
|
23 | + /** |
|
24 | + * Boolean whether the method is enabled. |
|
25 | + * |
|
26 | + * @var bool |
|
27 | + */ |
|
28 | + public $enabled = true; |
|
29 | + |
|
30 | + /** |
|
31 | + * Payment method id. |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + public $id; |
|
36 | + |
|
37 | + /** |
|
38 | + * Payment method order. |
|
39 | + * |
|
40 | + * @var int |
|
41 | + */ |
|
42 | + public $order = 10; |
|
43 | + |
|
44 | + /** |
|
45 | + * Payment method title for the frontend. |
|
46 | + * |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + public $title; |
|
50 | + |
|
51 | + /** |
|
52 | + * Payment method description for the frontend. |
|
53 | + * |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + public $description; |
|
57 | + |
|
58 | + /** |
|
59 | + * Gateway title. |
|
60 | + * |
|
61 | + * @var string |
|
62 | + */ |
|
63 | + public $method_title = ''; |
|
64 | + |
|
65 | + /** |
|
66 | + * Gateway description. |
|
67 | + * |
|
68 | + * @var string |
|
69 | + */ |
|
70 | + public $method_description = ''; |
|
71 | + |
|
72 | + /** |
|
73 | + * Countries this gateway is allowed for. |
|
74 | + * |
|
75 | + * @var array |
|
76 | + */ |
|
77 | + public $countries; |
|
78 | + |
|
79 | + /** |
|
80 | + * Currencies this gateway is allowed for. |
|
81 | + * |
|
82 | + * @var array |
|
83 | + */ |
|
84 | + public $currencies; |
|
85 | + |
|
86 | + /** |
|
87 | + * Currencies this gateway is not allowed for. |
|
88 | + * |
|
89 | + * @var array |
|
90 | + */ |
|
91 | + public $exclude_currencies; |
|
92 | + |
|
93 | + /** |
|
94 | + * Maximum transaction amount, zero does not define a maximum. |
|
95 | + * |
|
96 | + * @var int |
|
97 | + */ |
|
98 | + public $max_amount = 0; |
|
99 | + |
|
100 | + /** |
|
101 | + * Optional URL to view a transaction. |
|
102 | + * |
|
103 | + * @var string |
|
104 | + */ |
|
105 | + public $view_transaction_url = ''; |
|
106 | + |
|
107 | + /** |
|
108 | + * Optional URL to view a subscription. |
|
109 | + * |
|
110 | + * @var string |
|
111 | + */ |
|
112 | + public $view_subscription_url = ''; |
|
113 | + |
|
114 | + /** |
|
115 | + * Optional label to show for "new payment method" in the payment |
|
116 | + * method/token selection radio selection. |
|
117 | + * |
|
118 | + * @var string |
|
119 | + */ |
|
120 | + public $new_method_label = ''; |
|
121 | + |
|
122 | + /** |
|
123 | + * Contains a user's saved tokens for this gateway. |
|
124 | + * |
|
125 | + * @var array |
|
126 | + */ |
|
127 | + protected $tokens = array(); |
|
128 | + |
|
129 | + /** |
|
130 | + * An array of features that this gateway supports. |
|
131 | + * |
|
132 | + * @var array |
|
133 | + */ |
|
134 | + protected $supports = array(); |
|
135 | + |
|
136 | + /** |
|
137 | + * Class constructor. |
|
138 | + */ |
|
139 | + public function __construct() { |
|
140 | + |
|
141 | + // Register gateway. |
|
142 | + add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
143 | + |
|
144 | + $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
145 | + |
|
146 | + // Add support for various features. |
|
147 | + foreach ( $this->supports as $feature ) { |
|
148 | + add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' ); |
|
149 | + add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' ); |
|
150 | + add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
151 | + } |
|
152 | + |
|
153 | + // Invoice addons. |
|
154 | + if ( $this->supports( 'addons' ) ) { |
|
155 | + add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
156 | + } |
|
157 | + |
|
158 | + // Gateway settings. |
|
159 | + add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
160 | + |
|
161 | + // Gateway checkout fiellds. |
|
162 | + add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
163 | + |
|
164 | + // Process payment. |
|
165 | + add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
166 | + |
|
167 | + // Change the checkout button text. |
|
168 | + if ( ! empty( $this->checkout_button_text ) ) { |
|
169 | + add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
170 | + } |
|
171 | + |
|
172 | + // Check if a gateway is valid for a given currency. |
|
173 | + add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
174 | + |
|
175 | + // Generate the transaction url. |
|
176 | + add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
177 | + |
|
178 | + // Generate the subscription url. |
|
179 | + add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
180 | + |
|
181 | + // Confirm payments. |
|
182 | + add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
183 | + |
|
184 | + // Verify IPNs. |
|
185 | + add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
186 | + |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Checks if this gateway is a given gateway. |
|
191 | + * |
|
192 | + * @since 1.0.19 |
|
193 | + * @return bool |
|
194 | + */ |
|
195 | + public function is( $gateway ) { |
|
196 | + return $gateway == $this->id; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Returns a users saved tokens for this gateway. |
|
201 | + * |
|
202 | + * @since 1.0.19 |
|
203 | + * @return array |
|
204 | + */ |
|
205 | + public function get_tokens( $sandbox = null ) { |
|
206 | + |
|
207 | + if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
208 | + $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
209 | + |
|
210 | + if ( is_array( $tokens ) ) { |
|
211 | + $this->tokens = $tokens; |
|
212 | + } |
|
213 | 213 | } |
214 | 214 | |
215 | - if ( ! is_bool( $sandbox ) ) { |
|
216 | - return $this->tokens; |
|
217 | - } |
|
218 | - |
|
219 | - // Filter tokens. |
|
220 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
221 | - return wp_list_filter( $this->tokens, $args ); |
|
222 | - |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Saves a token for this gateway. |
|
227 | - * |
|
228 | - * @since 1.0.19 |
|
229 | - */ |
|
230 | - public function save_token( $token ) { |
|
231 | - |
|
232 | - $tokens = $this->get_tokens(); |
|
233 | - $tokens[] = $token; |
|
234 | - |
|
235 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
236 | - |
|
237 | - $this->tokens = $tokens; |
|
238 | - |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * Return the title for admin screens. |
|
243 | - * |
|
244 | - * @return string |
|
245 | - */ |
|
246 | - public function get_method_title() { |
|
247 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Return the description for admin screens. |
|
252 | - * |
|
253 | - * @return string |
|
254 | - */ |
|
255 | - public function get_method_description() { |
|
256 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Get the success url. |
|
261 | - * |
|
262 | - * @param WPInv_Invoice $invoice Invoice object. |
|
263 | - * @return string |
|
264 | - */ |
|
265 | - public function get_return_url( $invoice ) { |
|
266 | - |
|
267 | - // Payment success url |
|
268 | - $return_url = add_query_arg( |
|
269 | - array( |
|
270 | - 'payment-confirm' => $this->id, |
|
271 | - 'invoice_key' => $invoice->get_key(), |
|
272 | - 'utm_nooverride' => 1, |
|
273 | - ), |
|
274 | - wpinv_get_success_page_uri() |
|
275 | - ); |
|
276 | - |
|
277 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * Confirms payments when rendering the success page. |
|
282 | - * |
|
283 | - * @param string $content Success page content. |
|
284 | - * @return string |
|
285 | - */ |
|
286 | - public function confirm_payment( $content ) { |
|
287 | - |
|
288 | - // Retrieve the invoice. |
|
289 | - $invoice_id = getpaid_get_current_invoice_id(); |
|
290 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
291 | - |
|
292 | - // Ensure that it exists and that it is pending payment. |
|
293 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
294 | - return $content; |
|
295 | - } |
|
296 | - |
|
297 | - // Can the user view this invoice?? |
|
298 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
299 | - return $content; |
|
300 | - } |
|
301 | - |
|
302 | - // Show payment processing indicator. |
|
303 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Processes ipns and marks payments as complete. |
|
308 | - * |
|
309 | - * @return void |
|
310 | - */ |
|
311 | - public function verify_ipn() {} |
|
312 | - |
|
313 | - /** |
|
314 | - * Processes invoice addons. |
|
315 | - * |
|
316 | - * @param WPInv_Invoice $invoice |
|
317 | - * @param GetPaid_Form_Item[] $items |
|
318 | - * @return WPInv_Invoice |
|
319 | - */ |
|
320 | - public function process_addons( $invoice, $items ) { |
|
321 | - |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
326 | - * |
|
327 | - * @param string $transaction_url transaction url. |
|
328 | - * @param WPInv_Invoice $invoice Invoice object. |
|
329 | - * @return string transaction URL, or empty string. |
|
330 | - */ |
|
331 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
332 | - |
|
333 | - $transaction_id = $invoice->get_transaction_id(); |
|
334 | - |
|
335 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
336 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
337 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
338 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
339 | - } |
|
340 | - |
|
341 | - return $transaction_url; |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
346 | - * |
|
347 | - * @param string $subscription_url transaction url. |
|
348 | - * @param WPInv_Subscription $subscription Subscription objectt. |
|
349 | - * @return string subscription URL, or empty string. |
|
350 | - */ |
|
351 | - public function generate_subscription_url( $subscription_url, $subscription ) { |
|
352 | - |
|
353 | - $profile_id = $subscription->get_profile_id(); |
|
354 | - |
|
355 | - if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
356 | - |
|
357 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
358 | - $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
359 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
360 | - |
|
361 | - } |
|
362 | - |
|
363 | - return $subscription_url; |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Check if the gateway is available for use. |
|
368 | - * |
|
369 | - * @return bool |
|
370 | - */ |
|
371 | - public function is_available() { |
|
372 | - return ! empty( $this->enabled ); |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * Return the gateway's title. |
|
377 | - * |
|
378 | - * @return string |
|
379 | - */ |
|
380 | - public function get_title() { |
|
381 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
382 | - } |
|
383 | - |
|
384 | - /** |
|
385 | - * Return the gateway's description. |
|
386 | - * |
|
387 | - * @return string |
|
388 | - */ |
|
389 | - public function get_description() { |
|
390 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * Process Payment. |
|
395 | - * |
|
396 | - * |
|
397 | - * @param WPInv_Invoice $invoice Invoice. |
|
398 | - * @param array $submission_data Posted checkout fields. |
|
399 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
400 | - * @return void |
|
401 | - */ |
|
402 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
403 | - // Process the payment then either redirect to the success page or the gateway. |
|
404 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * Process refund. |
|
409 | - * |
|
410 | - * If the gateway declares 'refunds' support, this will allow it to refund. |
|
411 | - * a passed in amount. |
|
412 | - * |
|
413 | - * @param WPInv_Invoice $invoice Invoice. |
|
414 | - * @param float $amount Refund amount. |
|
415 | - * @param string $reason Refund reason. |
|
416 | - * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
417 | - */ |
|
418 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
419 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * Displays the payment fields, credit cards etc. |
|
424 | - * |
|
425 | - * @param int $invoice_id 0 or invoice id. |
|
426 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
427 | - */ |
|
428 | - public function payment_fields( $invoice_id, $form ) { |
|
429 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * Filters the gateway settings. |
|
434 | - * |
|
435 | - * @param array $admin_settings |
|
436 | - */ |
|
437 | - public function admin_settings( $admin_settings ) { |
|
438 | - return $admin_settings; |
|
439 | - } |
|
440 | - |
|
441 | - /** |
|
442 | - * Retrieves the value of a gateway setting. |
|
443 | - * |
|
444 | - * @param string $option |
|
445 | - */ |
|
446 | - public function get_option( $option, $default = false ) { |
|
447 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
448 | - } |
|
449 | - |
|
450 | - /** |
|
451 | - * Check if a gateway supports a given feature. |
|
452 | - * |
|
453 | - * Gateways should override this to declare support (or lack of support) for a feature. |
|
454 | - * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
455 | - * |
|
456 | - * @param string $feature string The name of a feature to test support for. |
|
457 | - * @return bool True if the gateway supports the feature, false otherwise. |
|
458 | - * @since 1.0.19 |
|
459 | - */ |
|
460 | - public function supports( $feature ) { |
|
461 | - return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * Returns the credit card form html. |
|
466 | - * |
|
467 | - * @param bool $save whether or not to display the save button. |
|
468 | - */ |
|
215 | + if ( ! is_bool( $sandbox ) ) { |
|
216 | + return $this->tokens; |
|
217 | + } |
|
218 | + |
|
219 | + // Filter tokens. |
|
220 | + $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
221 | + return wp_list_filter( $this->tokens, $args ); |
|
222 | + |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Saves a token for this gateway. |
|
227 | + * |
|
228 | + * @since 1.0.19 |
|
229 | + */ |
|
230 | + public function save_token( $token ) { |
|
231 | + |
|
232 | + $tokens = $this->get_tokens(); |
|
233 | + $tokens[] = $token; |
|
234 | + |
|
235 | + update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
236 | + |
|
237 | + $this->tokens = $tokens; |
|
238 | + |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * Return the title for admin screens. |
|
243 | + * |
|
244 | + * @return string |
|
245 | + */ |
|
246 | + public function get_method_title() { |
|
247 | + return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Return the description for admin screens. |
|
252 | + * |
|
253 | + * @return string |
|
254 | + */ |
|
255 | + public function get_method_description() { |
|
256 | + return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Get the success url. |
|
261 | + * |
|
262 | + * @param WPInv_Invoice $invoice Invoice object. |
|
263 | + * @return string |
|
264 | + */ |
|
265 | + public function get_return_url( $invoice ) { |
|
266 | + |
|
267 | + // Payment success url |
|
268 | + $return_url = add_query_arg( |
|
269 | + array( |
|
270 | + 'payment-confirm' => $this->id, |
|
271 | + 'invoice_key' => $invoice->get_key(), |
|
272 | + 'utm_nooverride' => 1, |
|
273 | + ), |
|
274 | + wpinv_get_success_page_uri() |
|
275 | + ); |
|
276 | + |
|
277 | + return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * Confirms payments when rendering the success page. |
|
282 | + * |
|
283 | + * @param string $content Success page content. |
|
284 | + * @return string |
|
285 | + */ |
|
286 | + public function confirm_payment( $content ) { |
|
287 | + |
|
288 | + // Retrieve the invoice. |
|
289 | + $invoice_id = getpaid_get_current_invoice_id(); |
|
290 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
291 | + |
|
292 | + // Ensure that it exists and that it is pending payment. |
|
293 | + if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
294 | + return $content; |
|
295 | + } |
|
296 | + |
|
297 | + // Can the user view this invoice?? |
|
298 | + if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
299 | + return $content; |
|
300 | + } |
|
301 | + |
|
302 | + // Show payment processing indicator. |
|
303 | + return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Processes ipns and marks payments as complete. |
|
308 | + * |
|
309 | + * @return void |
|
310 | + */ |
|
311 | + public function verify_ipn() {} |
|
312 | + |
|
313 | + /** |
|
314 | + * Processes invoice addons. |
|
315 | + * |
|
316 | + * @param WPInv_Invoice $invoice |
|
317 | + * @param GetPaid_Form_Item[] $items |
|
318 | + * @return WPInv_Invoice |
|
319 | + */ |
|
320 | + public function process_addons( $invoice, $items ) { |
|
321 | + |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
326 | + * |
|
327 | + * @param string $transaction_url transaction url. |
|
328 | + * @param WPInv_Invoice $invoice Invoice object. |
|
329 | + * @return string transaction URL, or empty string. |
|
330 | + */ |
|
331 | + public function filter_transaction_url( $transaction_url, $invoice ) { |
|
332 | + |
|
333 | + $transaction_id = $invoice->get_transaction_id(); |
|
334 | + |
|
335 | + if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
336 | + $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
337 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
338 | + $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
339 | + } |
|
340 | + |
|
341 | + return $transaction_url; |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
346 | + * |
|
347 | + * @param string $subscription_url transaction url. |
|
348 | + * @param WPInv_Subscription $subscription Subscription objectt. |
|
349 | + * @return string subscription URL, or empty string. |
|
350 | + */ |
|
351 | + public function generate_subscription_url( $subscription_url, $subscription ) { |
|
352 | + |
|
353 | + $profile_id = $subscription->get_profile_id(); |
|
354 | + |
|
355 | + if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
356 | + |
|
357 | + $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
358 | + $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
359 | + $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
360 | + |
|
361 | + } |
|
362 | + |
|
363 | + return $subscription_url; |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Check if the gateway is available for use. |
|
368 | + * |
|
369 | + * @return bool |
|
370 | + */ |
|
371 | + public function is_available() { |
|
372 | + return ! empty( $this->enabled ); |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * Return the gateway's title. |
|
377 | + * |
|
378 | + * @return string |
|
379 | + */ |
|
380 | + public function get_title() { |
|
381 | + return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
382 | + } |
|
383 | + |
|
384 | + /** |
|
385 | + * Return the gateway's description. |
|
386 | + * |
|
387 | + * @return string |
|
388 | + */ |
|
389 | + public function get_description() { |
|
390 | + return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * Process Payment. |
|
395 | + * |
|
396 | + * |
|
397 | + * @param WPInv_Invoice $invoice Invoice. |
|
398 | + * @param array $submission_data Posted checkout fields. |
|
399 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
400 | + * @return void |
|
401 | + */ |
|
402 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
403 | + // Process the payment then either redirect to the success page or the gateway. |
|
404 | + do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * Process refund. |
|
409 | + * |
|
410 | + * If the gateway declares 'refunds' support, this will allow it to refund. |
|
411 | + * a passed in amount. |
|
412 | + * |
|
413 | + * @param WPInv_Invoice $invoice Invoice. |
|
414 | + * @param float $amount Refund amount. |
|
415 | + * @param string $reason Refund reason. |
|
416 | + * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
417 | + */ |
|
418 | + public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
419 | + return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * Displays the payment fields, credit cards etc. |
|
424 | + * |
|
425 | + * @param int $invoice_id 0 or invoice id. |
|
426 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
427 | + */ |
|
428 | + public function payment_fields( $invoice_id, $form ) { |
|
429 | + do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Filters the gateway settings. |
|
434 | + * |
|
435 | + * @param array $admin_settings |
|
436 | + */ |
|
437 | + public function admin_settings( $admin_settings ) { |
|
438 | + return $admin_settings; |
|
439 | + } |
|
440 | + |
|
441 | + /** |
|
442 | + * Retrieves the value of a gateway setting. |
|
443 | + * |
|
444 | + * @param string $option |
|
445 | + */ |
|
446 | + public function get_option( $option, $default = false ) { |
|
447 | + return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
448 | + } |
|
449 | + |
|
450 | + /** |
|
451 | + * Check if a gateway supports a given feature. |
|
452 | + * |
|
453 | + * Gateways should override this to declare support (or lack of support) for a feature. |
|
454 | + * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
455 | + * |
|
456 | + * @param string $feature string The name of a feature to test support for. |
|
457 | + * @return bool True if the gateway supports the feature, false otherwise. |
|
458 | + * @since 1.0.19 |
|
459 | + */ |
|
460 | + public function supports( $feature ) { |
|
461 | + return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | + * Returns the credit card form html. |
|
466 | + * |
|
467 | + * @param bool $save whether or not to display the save button. |
|
468 | + */ |
|
469 | 469 | public function get_cc_form( $save = false ) { |
470 | 470 | |
471 | - ob_start(); |
|
471 | + ob_start(); |
|
472 | 472 | |
473 | 473 | $id_prefix = esc_attr( uniqid( $this->id ) ); |
474 | 474 | |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | '11' => __( 'November', 'invoicing' ), |
487 | 487 | '12' => __( 'December', 'invoicing' ), |
488 | 488 | ); |
489 | - $months = apply_filters( 'getpaid_cc_months', $months, $this ); |
|
489 | + $months = apply_filters( 'getpaid_cc_months', $months, $this ); |
|
490 | 490 | |
491 | 491 | $year = (int) current_time( 'Y' ); |
492 | 492 | $years = array(); |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | $years[ $year + $i ] = $year + $i; |
496 | 496 | } |
497 | 497 | |
498 | - $years = apply_filters( 'getpaid_cc_years', $years, $this ); |
|
498 | + $years = apply_filters( 'getpaid_cc_years', $years, $this ); |
|
499 | 499 | |
500 | 500 | ?> |
501 | 501 | <div class="<?php echo esc_attr( $this->id ); ?>-cc-form getpaid-cc-form mt-1"> |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | |
532 | 532 | <?php |
533 | 533 | foreach ( $months as $key => $month ) { |
534 | - echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $month ) . '</option>'; |
|
534 | + echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $month ) . '</option>'; |
|
535 | 535 | } |
536 | 536 | ?> |
537 | 537 | |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | |
545 | 545 | <?php |
546 | 546 | foreach ( $years as $key => $year ) { |
547 | - echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $year ) . '</option>'; |
|
547 | + echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $year ) . '</option>'; |
|
548 | 548 | } |
549 | 549 | ?> |
550 | 550 | |
@@ -562,13 +562,13 @@ discard block |
||
562 | 562 | 'name' => $this->id . '[cc_cvv2]', |
563 | 563 | 'id' => "$id_prefix-cc-cvv2", |
564 | 564 | 'label' => __( 'CCV', 'invoicing' ), |
565 | - 'label_type' => 'vertical', |
|
566 | - 'class' => 'form-control-sm', |
|
567 | - 'extra_attributes' => array( |
|
568 | - 'autocomplete' => 'cc-csc', |
|
569 | - ), |
|
565 | + 'label_type' => 'vertical', |
|
566 | + 'class' => 'form-control-sm', |
|
567 | + 'extra_attributes' => array( |
|
568 | + 'autocomplete' => 'cc-csc', |
|
569 | + ), |
|
570 | 570 | ), |
571 | - true |
|
571 | + true |
|
572 | 572 | ); |
573 | 573 | ?> |
574 | 574 | </div> |
@@ -577,192 +577,192 @@ discard block |
||
577 | 577 | |
578 | 578 | <?php |
579 | 579 | |
580 | - if ( $save ) { |
|
581 | - $this->save_payment_method_checkbox(); |
|
582 | - } |
|
580 | + if ( $save ) { |
|
581 | + $this->save_payment_method_checkbox(); |
|
582 | + } |
|
583 | 583 | |
584 | - ?> |
|
584 | + ?> |
|
585 | 585 | </div> |
586 | 586 | |
587 | 587 | </div> |
588 | 588 | <?php |
589 | 589 | |
590 | - return ob_get_clean(); |
|
590 | + return ob_get_clean(); |
|
591 | + |
|
592 | + } |
|
593 | + |
|
594 | + /** |
|
595 | + * Displays a new payment method entry form. |
|
596 | + * |
|
597 | + * @since 1.0.19 |
|
598 | + */ |
|
599 | + public function new_payment_method_entry( $form ) { |
|
600 | + echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses( $form, getpaid_allowed_html() ) . '</div>'; |
|
601 | + } |
|
602 | + |
|
603 | + /** |
|
604 | + * Grab and display our saved payment methods. |
|
605 | + * |
|
606 | + * @since 1.0.19 |
|
607 | + */ |
|
608 | + public function saved_payment_methods() { |
|
609 | + echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
610 | + |
|
611 | + foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
612 | + $this->get_saved_payment_method_option_html( $token ); |
|
613 | + } |
|
614 | + |
|
615 | + $this->get_new_payment_method_option_html(); |
|
616 | + echo '</ul>'; |
|
591 | 617 | |
592 | 618 | } |
593 | 619 | |
594 | - /** |
|
595 | - * Displays a new payment method entry form. |
|
596 | - * |
|
597 | - * @since 1.0.19 |
|
598 | - */ |
|
599 | - public function new_payment_method_entry( $form ) { |
|
600 | - echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses( $form, getpaid_allowed_html() ) . '</div>'; |
|
601 | - } |
|
602 | - |
|
603 | - /** |
|
604 | - * Grab and display our saved payment methods. |
|
605 | - * |
|
606 | - * @since 1.0.19 |
|
607 | - */ |
|
608 | - public function saved_payment_methods() { |
|
609 | - echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
610 | - |
|
611 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
612 | - $this->get_saved_payment_method_option_html( $token ); |
|
613 | - } |
|
614 | - |
|
615 | - $this->get_new_payment_method_option_html(); |
|
616 | - echo '</ul>'; |
|
617 | - |
|
618 | - } |
|
619 | - |
|
620 | - /** |
|
621 | - * Gets saved payment method HTML from a token. |
|
622 | - * |
|
623 | - * @since 1.0.19 |
|
624 | - * @param array $token Payment Token. |
|
625 | - * @return string Generated payment method HTML |
|
626 | - */ |
|
627 | - public function get_saved_payment_method_option_html( $token ) { |
|
628 | - |
|
629 | - printf( |
|
630 | - '<li class="getpaid-payment-method form-group"> |
|
620 | + /** |
|
621 | + * Gets saved payment method HTML from a token. |
|
622 | + * |
|
623 | + * @since 1.0.19 |
|
624 | + * @param array $token Payment Token. |
|
625 | + * @return string Generated payment method HTML |
|
626 | + */ |
|
627 | + public function get_saved_payment_method_option_html( $token ) { |
|
628 | + |
|
629 | + printf( |
|
630 | + '<li class="getpaid-payment-method form-group"> |
|
631 | 631 | <label> |
632 | 632 | <input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" data-currency="%5$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s /> |
633 | 633 | <span>%3$s</span> |
634 | 634 | </label> |
635 | 635 | </li>', |
636 | - esc_attr( $this->id ), |
|
637 | - esc_attr( $token['id'] ), |
|
638 | - esc_html( $token['name'] ), |
|
639 | - checked( empty( $token['default'] ), false, false ), |
|
640 | - empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] ) |
|
641 | - ); |
|
642 | - |
|
643 | - } |
|
644 | - |
|
645 | - /** |
|
646 | - * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
647 | - * |
|
648 | - * @since 1.0.19 |
|
649 | - */ |
|
650 | - public function get_new_payment_method_option_html() { |
|
651 | - |
|
652 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
653 | - |
|
654 | - printf( |
|
655 | - '<li class="getpaid-new-payment-method"> |
|
636 | + esc_attr( $this->id ), |
|
637 | + esc_attr( $token['id'] ), |
|
638 | + esc_html( $token['name'] ), |
|
639 | + checked( empty( $token['default'] ), false, false ), |
|
640 | + empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] ) |
|
641 | + ); |
|
642 | + |
|
643 | + } |
|
644 | + |
|
645 | + /** |
|
646 | + * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
647 | + * |
|
648 | + * @since 1.0.19 |
|
649 | + */ |
|
650 | + public function get_new_payment_method_option_html() { |
|
651 | + |
|
652 | + $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
653 | + |
|
654 | + printf( |
|
655 | + '<li class="getpaid-new-payment-method"> |
|
656 | 656 | <label> |
657 | 657 | <input name="getpaid-%1$s-payment-method" type="radio" data-currency="none" value="new" style="width:auto;" /> |
658 | 658 | <span>%2$s</span> |
659 | 659 | </label> |
660 | 660 | </li>', |
661 | - esc_attr( $this->id ), |
|
662 | - esc_html( $label ) |
|
663 | - ); |
|
664 | - |
|
665 | - } |
|
666 | - |
|
667 | - /** |
|
668 | - * Outputs a checkbox for saving a new payment method to the database. |
|
669 | - * |
|
670 | - * @since 1.0.19 |
|
671 | - */ |
|
672 | - public function save_payment_method_checkbox() { |
|
673 | - |
|
674 | - aui()->input( |
|
675 | - array( |
|
676 | - 'type' => 'checkbox', |
|
677 | - 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
678 | - 'id' => esc_attr( uniqid( $this->id ) ), |
|
679 | - 'required' => false, |
|
680 | - 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
681 | - 'value' => 'true', |
|
682 | - 'checked' => true, |
|
683 | - 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
684 | - ), |
|
685 | - true |
|
686 | - ); |
|
687 | - |
|
688 | - } |
|
689 | - |
|
690 | - /** |
|
691 | - * Registers the gateway. |
|
692 | - * |
|
693 | - * @return array |
|
694 | - */ |
|
695 | - public function register_gateway( $gateways ) { |
|
696 | - |
|
697 | - $gateways[ $this->id ] = array( |
|
698 | - |
|
699 | - 'admin_label' => $this->method_title, |
|
661 | + esc_attr( $this->id ), |
|
662 | + esc_html( $label ) |
|
663 | + ); |
|
664 | + |
|
665 | + } |
|
666 | + |
|
667 | + /** |
|
668 | + * Outputs a checkbox for saving a new payment method to the database. |
|
669 | + * |
|
670 | + * @since 1.0.19 |
|
671 | + */ |
|
672 | + public function save_payment_method_checkbox() { |
|
673 | + |
|
674 | + aui()->input( |
|
675 | + array( |
|
676 | + 'type' => 'checkbox', |
|
677 | + 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
678 | + 'id' => esc_attr( uniqid( $this->id ) ), |
|
679 | + 'required' => false, |
|
680 | + 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
681 | + 'value' => 'true', |
|
682 | + 'checked' => true, |
|
683 | + 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
684 | + ), |
|
685 | + true |
|
686 | + ); |
|
687 | + |
|
688 | + } |
|
689 | + |
|
690 | + /** |
|
691 | + * Registers the gateway. |
|
692 | + * |
|
693 | + * @return array |
|
694 | + */ |
|
695 | + public function register_gateway( $gateways ) { |
|
696 | + |
|
697 | + $gateways[ $this->id ] = array( |
|
698 | + |
|
699 | + 'admin_label' => $this->method_title, |
|
700 | 700 | 'checkout_label' => $this->title, |
701 | - 'ordering' => $this->order, |
|
701 | + 'ordering' => $this->order, |
|
702 | 702 | |
703 | - ); |
|
703 | + ); |
|
704 | 704 | |
705 | - return $gateways; |
|
705 | + return $gateways; |
|
706 | 706 | |
707 | - } |
|
707 | + } |
|
708 | 708 | |
709 | - /** |
|
710 | - * Checks whether or not this is a sandbox request. |
|
711 | - * |
|
712 | - * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
713 | - * @return bool |
|
714 | - */ |
|
715 | - public function is_sandbox( $invoice = null ) { |
|
709 | + /** |
|
710 | + * Checks whether or not this is a sandbox request. |
|
711 | + * |
|
712 | + * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
713 | + * @return bool |
|
714 | + */ |
|
715 | + public function is_sandbox( $invoice = null ) { |
|
716 | 716 | |
717 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
718 | - return $invoice->get_mode() == 'test'; |
|
719 | - } |
|
717 | + if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
718 | + return $invoice->get_mode() == 'test'; |
|
719 | + } |
|
720 | 720 | |
721 | - return wpinv_is_test_mode( $this->id ); |
|
721 | + return wpinv_is_test_mode( $this->id ); |
|
722 | 722 | |
723 | - } |
|
723 | + } |
|
724 | 724 | |
725 | - /** |
|
726 | - * Renames the checkout button |
|
727 | - * |
|
728 | - * @return string |
|
729 | - */ |
|
730 | - public function rename_checkout_button() { |
|
731 | - return $this->checkout_button_text; |
|
732 | - } |
|
725 | + /** |
|
726 | + * Renames the checkout button |
|
727 | + * |
|
728 | + * @return string |
|
729 | + */ |
|
730 | + public function rename_checkout_button() { |
|
731 | + return $this->checkout_button_text; |
|
732 | + } |
|
733 | 733 | |
734 | - /** |
|
735 | - * Validate gateway currency |
|
736 | - * |
|
737 | - * @return bool |
|
738 | - */ |
|
739 | - public function validate_currency( $validation, $currency ) { |
|
734 | + /** |
|
735 | + * Validate gateway currency |
|
736 | + * |
|
737 | + * @return bool |
|
738 | + */ |
|
739 | + public function validate_currency( $validation, $currency ) { |
|
740 | 740 | |
741 | - // Required currencies. |
|
742 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
743 | - return false; |
|
744 | - } |
|
741 | + // Required currencies. |
|
742 | + if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
743 | + return false; |
|
744 | + } |
|
745 | 745 | |
746 | - // Excluded currencies. |
|
747 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
748 | - return false; |
|
749 | - } |
|
746 | + // Excluded currencies. |
|
747 | + if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
748 | + return false; |
|
749 | + } |
|
750 | 750 | |
751 | - return $validation; |
|
752 | - } |
|
751 | + return $validation; |
|
752 | + } |
|
753 | 753 | |
754 | - /** |
|
755 | - * Displays an error |
|
756 | - * |
|
757 | - */ |
|
758 | - public function show_error( $code, $message, $type ) { |
|
754 | + /** |
|
755 | + * Displays an error |
|
756 | + * |
|
757 | + */ |
|
758 | + public function show_error( $code, $message, $type ) { |
|
759 | 759 | |
760 | - if ( is_admin() ) { |
|
761 | - getpaid_admin()->{"show_$type"}( $message ); |
|
762 | - } |
|
760 | + if ( is_admin() ) { |
|
761 | + getpaid_admin()->{"show_$type"}( $message ); |
|
762 | + } |
|
763 | 763 | |
764 | - wpinv_set_error( $code, $message, $type ); |
|
764 | + wpinv_set_error( $code, $message, $type ); |
|
765 | 765 | |
766 | - } |
|
766 | + } |
|
767 | 767 | |
768 | 768 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Abstaract Payment Gateway class. |
@@ -139,50 +139,50 @@ discard block |
||
139 | 139 | public function __construct() { |
140 | 140 | |
141 | 141 | // Register gateway. |
142 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
142 | + add_filter('wpinv_payment_gateways', array($this, 'register_gateway')); |
|
143 | 143 | |
144 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
144 | + $this->enabled = wpinv_is_gateway_active($this->id); |
|
145 | 145 | |
146 | 146 | // Add support for various features. |
147 | - foreach ( $this->supports as $feature ) { |
|
148 | - add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' ); |
|
149 | - add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' ); |
|
150 | - add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
147 | + foreach ($this->supports as $feature) { |
|
148 | + add_filter("wpinv_{$this->id}_support_{$feature}", '__return_true'); |
|
149 | + add_filter("getpaid_{$this->id}_support_{$feature}", '__return_true'); |
|
150 | + add_filter("getpaid_{$this->id}_supports_{$feature}", '__return_true'); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | // Invoice addons. |
154 | - if ( $this->supports( 'addons' ) ) { |
|
155 | - add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
154 | + if ($this->supports('addons')) { |
|
155 | + add_action("getpaid_process_{$this->id}_invoice_addons", array($this, 'process_addons'), 10, 2); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | // Gateway settings. |
159 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
159 | + add_filter("wpinv_gateway_settings_{$this->id}", array($this, 'admin_settings')); |
|
160 | 160 | |
161 | 161 | // Gateway checkout fiellds. |
162 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
162 | + add_action("wpinv_{$this->id}_cc_form", array($this, 'payment_fields'), 10, 2); |
|
163 | 163 | |
164 | 164 | // Process payment. |
165 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
165 | + add_action("getpaid_gateway_{$this->id}", array($this, 'process_payment'), 10, 3); |
|
166 | 166 | |
167 | 167 | // Change the checkout button text. |
168 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
169 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
168 | + if (!empty($this->checkout_button_text)) { |
|
169 | + add_filter("getpaid_gateway_{$this->id}_checkout_button_label", array($this, 'rename_checkout_button')); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | // Check if a gateway is valid for a given currency. |
173 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
173 | + add_filter("getpaid_gateway_{$this->id}_is_valid_for_currency", array($this, 'validate_currency'), 10, 2); |
|
174 | 174 | |
175 | 175 | // Generate the transaction url. |
176 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
176 | + add_filter("getpaid_gateway_{$this->id}_transaction_url", array($this, 'filter_transaction_url'), 10, 2); |
|
177 | 177 | |
178 | 178 | // Generate the subscription url. |
179 | - add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
179 | + add_filter('getpaid_remote_subscription_profile_url', array($this, 'generate_subscription_url'), 10, 2); |
|
180 | 180 | |
181 | 181 | // Confirm payments. |
182 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
182 | + add_filter("wpinv_payment_confirm_{$this->id}", array($this, 'confirm_payment'), 10, 2); |
|
183 | 183 | |
184 | 184 | // Verify IPNs. |
185 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
185 | + add_action("wpinv_verify_{$this->id}_ipn", array($this, 'verify_ipn')); |
|
186 | 186 | |
187 | 187 | } |
188 | 188 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * @since 1.0.19 |
193 | 193 | * @return bool |
194 | 194 | */ |
195 | - public function is( $gateway ) { |
|
195 | + public function is($gateway) { |
|
196 | 196 | return $gateway == $this->id; |
197 | 197 | } |
198 | 198 | |
@@ -202,23 +202,23 @@ discard block |
||
202 | 202 | * @since 1.0.19 |
203 | 203 | * @return array |
204 | 204 | */ |
205 | - public function get_tokens( $sandbox = null ) { |
|
205 | + public function get_tokens($sandbox = null) { |
|
206 | 206 | |
207 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
208 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
207 | + if (is_user_logged_in() && $this->supports('tokens') && 0 == count($this->tokens)) { |
|
208 | + $tokens = get_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", true); |
|
209 | 209 | |
210 | - if ( is_array( $tokens ) ) { |
|
210 | + if (is_array($tokens)) { |
|
211 | 211 | $this->tokens = $tokens; |
212 | 212 | } |
213 | 213 | } |
214 | 214 | |
215 | - if ( ! is_bool( $sandbox ) ) { |
|
215 | + if (!is_bool($sandbox)) { |
|
216 | 216 | return $this->tokens; |
217 | 217 | } |
218 | 218 | |
219 | 219 | // Filter tokens. |
220 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
221 | - return wp_list_filter( $this->tokens, $args ); |
|
220 | + $args = array('type' => $sandbox ? 'sandbox' : 'live'); |
|
221 | + return wp_list_filter($this->tokens, $args); |
|
222 | 222 | |
223 | 223 | } |
224 | 224 | |
@@ -227,12 +227,12 @@ discard block |
||
227 | 227 | * |
228 | 228 | * @since 1.0.19 |
229 | 229 | */ |
230 | - public function save_token( $token ) { |
|
230 | + public function save_token($token) { |
|
231 | 231 | |
232 | 232 | $tokens = $this->get_tokens(); |
233 | 233 | $tokens[] = $token; |
234 | 234 | |
235 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
235 | + update_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens); |
|
236 | 236 | |
237 | 237 | $this->tokens = $tokens; |
238 | 238 | |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | * @return string |
245 | 245 | */ |
246 | 246 | public function get_method_title() { |
247 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
247 | + return apply_filters('getpaid_gateway_method_title', $this->method_title, $this); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * @return string |
254 | 254 | */ |
255 | 255 | public function get_method_description() { |
256 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
256 | + return apply_filters('getpaid_gateway_method_description', $this->method_description, $this); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * @param WPInv_Invoice $invoice Invoice object. |
263 | 263 | * @return string |
264 | 264 | */ |
265 | - public function get_return_url( $invoice ) { |
|
265 | + public function get_return_url($invoice) { |
|
266 | 266 | |
267 | 267 | // Payment success url |
268 | 268 | $return_url = add_query_arg( |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | wpinv_get_success_page_uri() |
275 | 275 | ); |
276 | 276 | |
277 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
277 | + return apply_filters('getpaid_gateway_success_url', $return_url, $invoice, $this); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | /** |
@@ -283,24 +283,24 @@ discard block |
||
283 | 283 | * @param string $content Success page content. |
284 | 284 | * @return string |
285 | 285 | */ |
286 | - public function confirm_payment( $content ) { |
|
286 | + public function confirm_payment($content) { |
|
287 | 287 | |
288 | 288 | // Retrieve the invoice. |
289 | 289 | $invoice_id = getpaid_get_current_invoice_id(); |
290 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
290 | + $invoice = wpinv_get_invoice($invoice_id); |
|
291 | 291 | |
292 | 292 | // Ensure that it exists and that it is pending payment. |
293 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
293 | + if (empty($invoice_id) || !$invoice->needs_payment()) { |
|
294 | 294 | return $content; |
295 | 295 | } |
296 | 296 | |
297 | 297 | // Can the user view this invoice?? |
298 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
298 | + if (!wpinv_user_can_view_invoice($invoice)) { |
|
299 | 299 | return $content; |
300 | 300 | } |
301 | 301 | |
302 | 302 | // Show payment processing indicator. |
303 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
303 | + return wpinv_get_template_html('wpinv-payment-processing.php', compact('invoice')); |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | /** |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | * @param GetPaid_Form_Item[] $items |
318 | 318 | * @return WPInv_Invoice |
319 | 319 | */ |
320 | - public function process_addons( $invoice, $items ) { |
|
320 | + public function process_addons($invoice, $items) { |
|
321 | 321 | |
322 | 322 | } |
323 | 323 | |
@@ -328,14 +328,14 @@ discard block |
||
328 | 328 | * @param WPInv_Invoice $invoice Invoice object. |
329 | 329 | * @return string transaction URL, or empty string. |
330 | 330 | */ |
331 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
331 | + public function filter_transaction_url($transaction_url, $invoice) { |
|
332 | 332 | |
333 | - $transaction_id = $invoice->get_transaction_id(); |
|
333 | + $transaction_id = $invoice->get_transaction_id(); |
|
334 | 334 | |
335 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
336 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
337 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
338 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
335 | + if (!empty($this->view_transaction_url) && !empty($transaction_id)) { |
|
336 | + $transaction_url = sprintf($this->view_transaction_url, $transaction_id); |
|
337 | + $replace = $this->is_sandbox($invoice) ? 'sandbox' : ''; |
|
338 | + $transaction_url = str_replace('{sandbox}', $replace, $transaction_url); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | return $transaction_url; |
@@ -348,15 +348,15 @@ discard block |
||
348 | 348 | * @param WPInv_Subscription $subscription Subscription objectt. |
349 | 349 | * @return string subscription URL, or empty string. |
350 | 350 | */ |
351 | - public function generate_subscription_url( $subscription_url, $subscription ) { |
|
351 | + public function generate_subscription_url($subscription_url, $subscription) { |
|
352 | 352 | |
353 | - $profile_id = $subscription->get_profile_id(); |
|
353 | + $profile_id = $subscription->get_profile_id(); |
|
354 | 354 | |
355 | - if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
355 | + if ($this->id == $subscription->get_gateway() && !empty($this->view_subscription_url) && !empty($profile_id)) { |
|
356 | 356 | |
357 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
358 | - $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
359 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
357 | + $subscription_url = sprintf($this->view_subscription_url, $profile_id); |
|
358 | + $replace = $this->is_sandbox($subscription->get_parent_invoice()) ? 'sandbox' : ''; |
|
359 | + $subscription_url = str_replace('{sandbox}', $replace, $subscription_url); |
|
360 | 360 | |
361 | 361 | } |
362 | 362 | |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | * @return bool |
370 | 370 | */ |
371 | 371 | public function is_available() { |
372 | - return ! empty( $this->enabled ); |
|
372 | + return !empty($this->enabled); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | /** |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | * @return string |
379 | 379 | */ |
380 | 380 | public function get_title() { |
381 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
381 | + return apply_filters('getpaid_gateway_title', $this->title, $this); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | /** |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | * @return string |
388 | 388 | */ |
389 | 389 | public function get_description() { |
390 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
390 | + return apply_filters('getpaid_gateway_description', $this->description, $this); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | /** |
@@ -399,9 +399,9 @@ discard block |
||
399 | 399 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
400 | 400 | * @return void |
401 | 401 | */ |
402 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
402 | + public function process_payment($invoice, $submission_data, $submission) { |
|
403 | 403 | // Process the payment then either redirect to the success page or the gateway. |
404 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
404 | + do_action('getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission); |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | /** |
@@ -415,8 +415,8 @@ discard block |
||
415 | 415 | * @param string $reason Refund reason. |
416 | 416 | * @return WP_Error|bool True or false based on success, or a WP_Error object. |
417 | 417 | */ |
418 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
419 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
418 | + public function process_refund($invoice, $amount = null, $reason = '') { |
|
419 | + return apply_filters('getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason); |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | /** |
@@ -425,8 +425,8 @@ discard block |
||
425 | 425 | * @param int $invoice_id 0 or invoice id. |
426 | 426 | * @param GetPaid_Payment_Form $form Current payment form. |
427 | 427 | */ |
428 | - public function payment_fields( $invoice_id, $form ) { |
|
429 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
428 | + public function payment_fields($invoice_id, $form) { |
|
429 | + do_action('getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | /** |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | * |
435 | 435 | * @param array $admin_settings |
436 | 436 | */ |
437 | - public function admin_settings( $admin_settings ) { |
|
437 | + public function admin_settings($admin_settings) { |
|
438 | 438 | return $admin_settings; |
439 | 439 | } |
440 | 440 | |
@@ -443,8 +443,8 @@ discard block |
||
443 | 443 | * |
444 | 444 | * @param string $option |
445 | 445 | */ |
446 | - public function get_option( $option, $default = false ) { |
|
447 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
446 | + public function get_option($option, $default = false) { |
|
447 | + return wpinv_get_option($this->id . '_' . $option, $default); |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | /** |
@@ -457,8 +457,8 @@ discard block |
||
457 | 457 | * @return bool True if the gateway supports the feature, false otherwise. |
458 | 458 | * @since 1.0.19 |
459 | 459 | */ |
460 | - public function supports( $feature ) { |
|
461 | - return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
460 | + public function supports($feature) { |
|
461 | + return getpaid_payment_gateway_supports($this->id, $feature); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | /** |
@@ -466,39 +466,39 @@ discard block |
||
466 | 466 | * |
467 | 467 | * @param bool $save whether or not to display the save button. |
468 | 468 | */ |
469 | - public function get_cc_form( $save = false ) { |
|
469 | + public function get_cc_form($save = false) { |
|
470 | 470 | |
471 | 471 | ob_start(); |
472 | 472 | |
473 | - $id_prefix = esc_attr( uniqid( $this->id ) ); |
|
473 | + $id_prefix = esc_attr(uniqid($this->id)); |
|
474 | 474 | |
475 | 475 | $months = array( |
476 | - '01' => __( 'January', 'invoicing' ), |
|
477 | - '02' => __( 'February', 'invoicing' ), |
|
478 | - '03' => __( 'March', 'invoicing' ), |
|
479 | - '04' => __( 'April', 'invoicing' ), |
|
480 | - '05' => __( 'May', 'invoicing' ), |
|
481 | - '06' => __( 'June', 'invoicing' ), |
|
482 | - '07' => __( 'July', 'invoicing' ), |
|
483 | - '08' => __( 'August', 'invoicing' ), |
|
484 | - '09' => __( 'September', 'invoicing' ), |
|
485 | - '10' => __( 'October', 'invoicing' ), |
|
486 | - '11' => __( 'November', 'invoicing' ), |
|
487 | - '12' => __( 'December', 'invoicing' ), |
|
476 | + '01' => __('January', 'invoicing'), |
|
477 | + '02' => __('February', 'invoicing'), |
|
478 | + '03' => __('March', 'invoicing'), |
|
479 | + '04' => __('April', 'invoicing'), |
|
480 | + '05' => __('May', 'invoicing'), |
|
481 | + '06' => __('June', 'invoicing'), |
|
482 | + '07' => __('July', 'invoicing'), |
|
483 | + '08' => __('August', 'invoicing'), |
|
484 | + '09' => __('September', 'invoicing'), |
|
485 | + '10' => __('October', 'invoicing'), |
|
486 | + '11' => __('November', 'invoicing'), |
|
487 | + '12' => __('December', 'invoicing'), |
|
488 | 488 | ); |
489 | - $months = apply_filters( 'getpaid_cc_months', $months, $this ); |
|
489 | + $months = apply_filters('getpaid_cc_months', $months, $this); |
|
490 | 490 | |
491 | - $year = (int) current_time( 'Y' ); |
|
491 | + $year = (int) current_time('Y'); |
|
492 | 492 | $years = array(); |
493 | 493 | |
494 | - for ( $i = 0; $i <= 10; $i++ ) { |
|
495 | - $years[ $year + $i ] = $year + $i; |
|
494 | + for ($i = 0; $i <= 10; $i++) { |
|
495 | + $years[$year + $i] = $year + $i; |
|
496 | 496 | } |
497 | 497 | |
498 | - $years = apply_filters( 'getpaid_cc_years', $years, $this ); |
|
498 | + $years = apply_filters('getpaid_cc_years', $years, $this); |
|
499 | 499 | |
500 | 500 | ?> |
501 | - <div class="<?php echo esc_attr( $this->id ); ?>-cc-form getpaid-cc-form mt-1"> |
|
501 | + <div class="<?php echo esc_attr($this->id); ?>-cc-form getpaid-cc-form mt-1"> |
|
502 | 502 | |
503 | 503 | |
504 | 504 | <div class="getpaid-cc-card-inner"> |
@@ -507,14 +507,14 @@ discard block |
||
507 | 507 | <div class="col-12"> |
508 | 508 | |
509 | 509 | <div class="form-group"> |
510 | - <label for="<?php echo esc_attr( "$id_prefix-cc-number" ); ?>"><?php esc_html_e( 'Card number', 'invoicing' ); ?></label> |
|
510 | + <label for="<?php echo esc_attr("$id_prefix-cc-number"); ?>"><?php esc_html_e('Card number', 'invoicing'); ?></label> |
|
511 | 511 | <div class="input-group input-group-sm"> |
512 | 512 | <div class="input-group-prepend "> |
513 | 513 | <span class="input-group-text"> |
514 | 514 | <i class="fa fa-credit-card"></i> |
515 | 515 | </span> |
516 | 516 | </div> |
517 | - <input type="text" name="<?php echo esc_attr( $this->id . '[cc_number]' ); ?>" id="<?php echo esc_attr( "$id_prefix-cc-number" ); ?>" class="form-control form-control-sm getpaid-format-card-number" autocomplete="cc-number"> |
|
517 | + <input type="text" name="<?php echo esc_attr($this->id . '[cc_number]'); ?>" id="<?php echo esc_attr("$id_prefix-cc-number"); ?>" class="form-control form-control-sm getpaid-format-card-number" autocomplete="cc-number"> |
|
518 | 518 | </div> |
519 | 519 | </div> |
520 | 520 | |
@@ -522,16 +522,16 @@ discard block |
||
522 | 522 | |
523 | 523 | <div class="col-12"> |
524 | 524 | <div class="form-group"> |
525 | - <label><?php esc_html_e( 'Expiration', 'invoicing' ); ?></label> |
|
525 | + <label><?php esc_html_e('Expiration', 'invoicing'); ?></label> |
|
526 | 526 | <div class="form-row"> |
527 | 527 | |
528 | 528 | <div class="col"> |
529 | - <select class="form-control form-control-sm" autocomplete="cc-exp-month" name="<?php echo esc_attr( $this->id ); ?>[cc_expire_month]"> |
|
530 | - <option disabled selected="selected"><?php esc_html_e( 'MM', 'invoicing' ); ?></option> |
|
529 | + <select class="form-control form-control-sm" autocomplete="cc-exp-month" name="<?php echo esc_attr($this->id); ?>[cc_expire_month]"> |
|
530 | + <option disabled selected="selected"><?php esc_html_e('MM', 'invoicing'); ?></option> |
|
531 | 531 | |
532 | 532 | <?php |
533 | - foreach ( $months as $key => $month ) { |
|
534 | - echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $month ) . '</option>'; |
|
533 | + foreach ($months as $key => $month) { |
|
534 | + echo "<option value='" . esc_attr($key) . "'>" . esc_html($month) . '</option>'; |
|
535 | 535 | } |
536 | 536 | ?> |
537 | 537 | |
@@ -539,12 +539,12 @@ discard block |
||
539 | 539 | </div> |
540 | 540 | |
541 | 541 | <div class="col"> |
542 | - <select class="form-control form-control-sm" autocomplete="cc-exp-year" name="<?php echo esc_attr( $this->id ); ?>[cc_expire_year]"> |
|
543 | - <option disabled selected="selected"><?php esc_html_e( 'YY', 'invoicing' ); ?></option> |
|
542 | + <select class="form-control form-control-sm" autocomplete="cc-exp-year" name="<?php echo esc_attr($this->id); ?>[cc_expire_year]"> |
|
543 | + <option disabled selected="selected"><?php esc_html_e('YY', 'invoicing'); ?></option> |
|
544 | 544 | |
545 | 545 | <?php |
546 | - foreach ( $years as $key => $year ) { |
|
547 | - echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $year ) . '</option>'; |
|
546 | + foreach ($years as $key => $year) { |
|
547 | + echo "<option value='" . esc_attr($key) . "'>" . esc_html($year) . '</option>'; |
|
548 | 548 | } |
549 | 549 | ?> |
550 | 550 | |
@@ -561,7 +561,7 @@ discard block |
||
561 | 561 | array( |
562 | 562 | 'name' => $this->id . '[cc_cvv2]', |
563 | 563 | 'id' => "$id_prefix-cc-cvv2", |
564 | - 'label' => __( 'CCV', 'invoicing' ), |
|
564 | + 'label' => __('CCV', 'invoicing'), |
|
565 | 565 | 'label_type' => 'vertical', |
566 | 566 | 'class' => 'form-control-sm', |
567 | 567 | 'extra_attributes' => array( |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | |
578 | 578 | <?php |
579 | 579 | |
580 | - if ( $save ) { |
|
580 | + if ($save) { |
|
581 | 581 | $this->save_payment_method_checkbox(); |
582 | 582 | } |
583 | 583 | |
@@ -596,8 +596,8 @@ discard block |
||
596 | 596 | * |
597 | 597 | * @since 1.0.19 |
598 | 598 | */ |
599 | - public function new_payment_method_entry( $form ) { |
|
600 | - echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses( $form, getpaid_allowed_html() ) . '</div>'; |
|
599 | + public function new_payment_method_entry($form) { |
|
600 | + echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses($form, getpaid_allowed_html()) . '</div>'; |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | /** |
@@ -606,10 +606,10 @@ discard block |
||
606 | 606 | * @since 1.0.19 |
607 | 607 | */ |
608 | 608 | public function saved_payment_methods() { |
609 | - echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
609 | + echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr(count($this->get_tokens($this->is_sandbox()))) . '">'; |
|
610 | 610 | |
611 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
612 | - $this->get_saved_payment_method_option_html( $token ); |
|
611 | + foreach ($this->get_tokens($this->is_sandbox()) as $token) { |
|
612 | + $this->get_saved_payment_method_option_html($token); |
|
613 | 613 | } |
614 | 614 | |
615 | 615 | $this->get_new_payment_method_option_html(); |
@@ -624,7 +624,7 @@ discard block |
||
624 | 624 | * @param array $token Payment Token. |
625 | 625 | * @return string Generated payment method HTML |
626 | 626 | */ |
627 | - public function get_saved_payment_method_option_html( $token ) { |
|
627 | + public function get_saved_payment_method_option_html($token) { |
|
628 | 628 | |
629 | 629 | printf( |
630 | 630 | '<li class="getpaid-payment-method form-group"> |
@@ -633,11 +633,11 @@ discard block |
||
633 | 633 | <span>%3$s</span> |
634 | 634 | </label> |
635 | 635 | </li>', |
636 | - esc_attr( $this->id ), |
|
637 | - esc_attr( $token['id'] ), |
|
638 | - esc_html( $token['name'] ), |
|
639 | - checked( empty( $token['default'] ), false, false ), |
|
640 | - empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] ) |
|
636 | + esc_attr($this->id), |
|
637 | + esc_attr($token['id']), |
|
638 | + esc_html($token['name']), |
|
639 | + checked(empty($token['default']), false, false), |
|
640 | + empty($token['currency']) ? 'none' : esc_attr($token['currency']) |
|
641 | 641 | ); |
642 | 642 | |
643 | 643 | } |
@@ -649,7 +649,7 @@ discard block |
||
649 | 649 | */ |
650 | 650 | public function get_new_payment_method_option_html() { |
651 | 651 | |
652 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
652 | + $label = apply_filters('getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __('Use a new payment method', 'invoicing'), $this); |
|
653 | 653 | |
654 | 654 | printf( |
655 | 655 | '<li class="getpaid-new-payment-method"> |
@@ -658,8 +658,8 @@ discard block |
||
658 | 658 | <span>%2$s</span> |
659 | 659 | </label> |
660 | 660 | </li>', |
661 | - esc_attr( $this->id ), |
|
662 | - esc_html( $label ) |
|
661 | + esc_attr($this->id), |
|
662 | + esc_html($label) |
|
663 | 663 | ); |
664 | 664 | |
665 | 665 | } |
@@ -674,10 +674,10 @@ discard block |
||
674 | 674 | aui()->input( |
675 | 675 | array( |
676 | 676 | 'type' => 'checkbox', |
677 | - 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
678 | - 'id' => esc_attr( uniqid( $this->id ) ), |
|
677 | + 'name' => esc_attr("getpaid-$this->id-new-payment-method"), |
|
678 | + 'id' => esc_attr(uniqid($this->id)), |
|
679 | 679 | 'required' => false, |
680 | - 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
680 | + 'label' => esc_html__('Save payment method', 'invoicing'), |
|
681 | 681 | 'value' => 'true', |
682 | 682 | 'checked' => true, |
683 | 683 | 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
@@ -692,9 +692,9 @@ discard block |
||
692 | 692 | * |
693 | 693 | * @return array |
694 | 694 | */ |
695 | - public function register_gateway( $gateways ) { |
|
695 | + public function register_gateway($gateways) { |
|
696 | 696 | |
697 | - $gateways[ $this->id ] = array( |
|
697 | + $gateways[$this->id] = array( |
|
698 | 698 | |
699 | 699 | 'admin_label' => $this->method_title, |
700 | 700 | 'checkout_label' => $this->title, |
@@ -712,13 +712,13 @@ discard block |
||
712 | 712 | * @param WPInv_Invoice|null $invoice Invoice object or null. |
713 | 713 | * @return bool |
714 | 714 | */ |
715 | - public function is_sandbox( $invoice = null ) { |
|
715 | + public function is_sandbox($invoice = null) { |
|
716 | 716 | |
717 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
717 | + if (!empty($invoice) && !$invoice->needs_payment()) { |
|
718 | 718 | return $invoice->get_mode() == 'test'; |
719 | 719 | } |
720 | 720 | |
721 | - return wpinv_is_test_mode( $this->id ); |
|
721 | + return wpinv_is_test_mode($this->id); |
|
722 | 722 | |
723 | 723 | } |
724 | 724 | |
@@ -736,15 +736,15 @@ discard block |
||
736 | 736 | * |
737 | 737 | * @return bool |
738 | 738 | */ |
739 | - public function validate_currency( $validation, $currency ) { |
|
739 | + public function validate_currency($validation, $currency) { |
|
740 | 740 | |
741 | 741 | // Required currencies. |
742 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
742 | + if (!empty($this->currencies) && !in_array($currency, $this->currencies)) { |
|
743 | 743 | return false; |
744 | 744 | } |
745 | 745 | |
746 | 746 | // Excluded currencies. |
747 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
747 | + if (!empty($this->exclude_currencies) && in_array($currency, $this->exclude_currencies)) { |
|
748 | 748 | return false; |
749 | 749 | } |
750 | 750 | |
@@ -755,13 +755,13 @@ discard block |
||
755 | 755 | * Displays an error |
756 | 756 | * |
757 | 757 | */ |
758 | - public function show_error( $code, $message, $type ) { |
|
758 | + public function show_error($code, $message, $type) { |
|
759 | 759 | |
760 | - if ( is_admin() ) { |
|
761 | - getpaid_admin()->{"show_$type"}( $message ); |
|
760 | + if (is_admin()) { |
|
761 | + getpaid_admin()->{"show_$type"}($message); |
|
762 | 762 | } |
763 | 763 | |
764 | - wpinv_set_error( $code, $message, $type ); |
|
764 | + wpinv_set_error($code, $message, $type); |
|
765 | 765 | |
766 | 766 | } |
767 | 767 |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
96 | 96 | $size = 'lg'; |
97 | 97 | $args['class'] .= ' form-control-lg'; |
98 | - }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
98 | + } elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
99 | 99 | $size = 'sm'; |
100 | 100 | $args['class'] .= ' form-control-sm'; |
101 | 101 | } |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | $help_text = ''; |
237 | 237 | //$label_args['class'] .= ' d-inline '; |
238 | 238 | $args['wrap_class'] .= ' align-items-center '; |
239 | - }else{ |
|
239 | + } else{ |
|
240 | 240 | |
241 | 241 | } |
242 | 242 |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
4 | - exit; // Exit if accessed directly |
|
4 | + exit; // Exit if accessed directly |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -11,1233 +11,1233 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class AUI_Component_Input { |
13 | 13 | |
14 | - /** |
|
15 | - * Build the component. |
|
16 | - * |
|
17 | - * @param array $args |
|
18 | - * |
|
19 | - * @return string The rendered component. |
|
20 | - */ |
|
21 | - public static function input( $args = array() ) { |
|
22 | - $defaults = array( |
|
23 | - 'type' => 'text', |
|
24 | - 'name' => '', |
|
25 | - 'class' => '', |
|
26 | - 'wrap_class' => '', |
|
27 | - 'id' => '', |
|
28 | - 'placeholder' => '', |
|
29 | - 'title' => '', |
|
30 | - 'value' => '', |
|
31 | - 'required' => false, |
|
32 | - 'size' => '', // sm, lg, small, large |
|
33 | - 'clear_icon' => '', // true will show a clear icon, can't be used with input_group_right |
|
34 | - 'label' => '', |
|
35 | - 'label_after' => false, |
|
36 | - 'label_class' => '', |
|
37 | - 'label_col' => '2', |
|
38 | - 'label_type' => '', // top, horizontal, empty = hidden |
|
39 | - 'label_force_left' => false, // used to force checkbox label left when using horizontal |
|
40 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
41 | - 'help_text' => '', |
|
42 | - 'validation_text' => '', |
|
43 | - 'validation_pattern' => '', |
|
44 | - 'no_wrap' => false, |
|
45 | - 'input_group_right' => '', |
|
46 | - 'input_group_left' => '', |
|
47 | - 'input_group_right_inside' => false, |
|
48 | - // forces the input group inside the input |
|
49 | - 'input_group_left_inside' => false, |
|
50 | - // forces the input group inside the input |
|
51 | - 'step' => '', |
|
52 | - 'switch' => false, |
|
53 | - // to show checkbox as a switch |
|
54 | - 'checked' => false, |
|
55 | - // set a checkbox or radio as selected |
|
56 | - 'password_toggle' => true, |
|
57 | - // toggle view/hide password |
|
58 | - 'element_require' => '', |
|
59 | - // [%element_id%] == "1" |
|
60 | - 'extra_attributes' => array(), |
|
61 | - // an array of extra attributes |
|
62 | - 'wrap_attributes' => array() |
|
63 | - ); |
|
64 | - |
|
65 | - /** |
|
66 | - * Parse incoming $args into an array and merge it with $defaults |
|
67 | - */ |
|
68 | - $args = wp_parse_args( $args, $defaults ); |
|
69 | - $output = ''; |
|
70 | - if ( ! empty( $args['type'] ) ) { |
|
71 | - // hidden label option needs to be empty |
|
72 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
73 | - |
|
74 | - $type = sanitize_html_class( $args['type'] ); |
|
75 | - |
|
76 | - $help_text = ''; |
|
77 | - $label = ''; |
|
78 | - $label_after = $args['label_after']; |
|
79 | - $label_args = array( |
|
80 | - 'title' => $args['label'], |
|
81 | - 'for' => $args['id'], |
|
82 | - 'class' => $args['label_class'] . " ", |
|
83 | - 'label_type' => $args['label_type'], |
|
84 | - 'label_col' => $args['label_col'] |
|
85 | - ); |
|
86 | - |
|
87 | - // floating labels need label after |
|
88 | - if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
89 | - $label_after = true; |
|
90 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
91 | - } |
|
92 | - |
|
93 | - // size |
|
94 | - $size = ''; |
|
95 | - if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
|
96 | - $size = 'lg'; |
|
97 | - $args['class'] .= ' form-control-lg'; |
|
98 | - }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
99 | - $size = 'sm'; |
|
100 | - $args['class'] .= ' form-control-sm'; |
|
101 | - } |
|
102 | - |
|
103 | - // clear function |
|
104 | - $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');'; |
|
105 | - |
|
106 | - // Some special sauce for files |
|
107 | - if ( $type == 'file' ) { |
|
108 | - $label_after = true; // if type file we need the label after |
|
109 | - $args['class'] .= ' custom-file-input '; |
|
110 | - } elseif ( $type == 'checkbox' ) { |
|
111 | - $label_after = true; // if type file we need the label after |
|
112 | - $args['class'] .= ' custom-control-input '; |
|
113 | - } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
114 | - $type = 'text'; |
|
115 | - $args['class'] .= ' bg-initial '; // @todo not sure why we have this? |
|
116 | - $clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');"; |
|
117 | - |
|
118 | - $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
119 | - |
|
120 | - // set a way to clear field if empty |
|
121 | - if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) { |
|
122 | - $args['input_group_right_inside'] = true; |
|
123 | - $args['clear_icon'] = true; |
|
124 | - } |
|
125 | - |
|
126 | - // enqueue the script |
|
127 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
128 | - $aui_settings->enqueue_flatpickr(); |
|
129 | - } elseif ( $type == 'iconpicker' ) { |
|
130 | - $type = 'text'; |
|
131 | - //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
14 | + /** |
|
15 | + * Build the component. |
|
16 | + * |
|
17 | + * @param array $args |
|
18 | + * |
|
19 | + * @return string The rendered component. |
|
20 | + */ |
|
21 | + public static function input( $args = array() ) { |
|
22 | + $defaults = array( |
|
23 | + 'type' => 'text', |
|
24 | + 'name' => '', |
|
25 | + 'class' => '', |
|
26 | + 'wrap_class' => '', |
|
27 | + 'id' => '', |
|
28 | + 'placeholder' => '', |
|
29 | + 'title' => '', |
|
30 | + 'value' => '', |
|
31 | + 'required' => false, |
|
32 | + 'size' => '', // sm, lg, small, large |
|
33 | + 'clear_icon' => '', // true will show a clear icon, can't be used with input_group_right |
|
34 | + 'label' => '', |
|
35 | + 'label_after' => false, |
|
36 | + 'label_class' => '', |
|
37 | + 'label_col' => '2', |
|
38 | + 'label_type' => '', // top, horizontal, empty = hidden |
|
39 | + 'label_force_left' => false, // used to force checkbox label left when using horizontal |
|
40 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
41 | + 'help_text' => '', |
|
42 | + 'validation_text' => '', |
|
43 | + 'validation_pattern' => '', |
|
44 | + 'no_wrap' => false, |
|
45 | + 'input_group_right' => '', |
|
46 | + 'input_group_left' => '', |
|
47 | + 'input_group_right_inside' => false, |
|
48 | + // forces the input group inside the input |
|
49 | + 'input_group_left_inside' => false, |
|
50 | + // forces the input group inside the input |
|
51 | + 'step' => '', |
|
52 | + 'switch' => false, |
|
53 | + // to show checkbox as a switch |
|
54 | + 'checked' => false, |
|
55 | + // set a checkbox or radio as selected |
|
56 | + 'password_toggle' => true, |
|
57 | + // toggle view/hide password |
|
58 | + 'element_require' => '', |
|
59 | + // [%element_id%] == "1" |
|
60 | + 'extra_attributes' => array(), |
|
61 | + // an array of extra attributes |
|
62 | + 'wrap_attributes' => array() |
|
63 | + ); |
|
64 | + |
|
65 | + /** |
|
66 | + * Parse incoming $args into an array and merge it with $defaults |
|
67 | + */ |
|
68 | + $args = wp_parse_args( $args, $defaults ); |
|
69 | + $output = ''; |
|
70 | + if ( ! empty( $args['type'] ) ) { |
|
71 | + // hidden label option needs to be empty |
|
72 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
73 | + |
|
74 | + $type = sanitize_html_class( $args['type'] ); |
|
75 | + |
|
76 | + $help_text = ''; |
|
77 | + $label = ''; |
|
78 | + $label_after = $args['label_after']; |
|
79 | + $label_args = array( |
|
80 | + 'title' => $args['label'], |
|
81 | + 'for' => $args['id'], |
|
82 | + 'class' => $args['label_class'] . " ", |
|
83 | + 'label_type' => $args['label_type'], |
|
84 | + 'label_col' => $args['label_col'] |
|
85 | + ); |
|
86 | + |
|
87 | + // floating labels need label after |
|
88 | + if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
89 | + $label_after = true; |
|
90 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
91 | + } |
|
92 | + |
|
93 | + // size |
|
94 | + $size = ''; |
|
95 | + if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
|
96 | + $size = 'lg'; |
|
97 | + $args['class'] .= ' form-control-lg'; |
|
98 | + }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
99 | + $size = 'sm'; |
|
100 | + $args['class'] .= ' form-control-sm'; |
|
101 | + } |
|
102 | + |
|
103 | + // clear function |
|
104 | + $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');'; |
|
105 | + |
|
106 | + // Some special sauce for files |
|
107 | + if ( $type == 'file' ) { |
|
108 | + $label_after = true; // if type file we need the label after |
|
109 | + $args['class'] .= ' custom-file-input '; |
|
110 | + } elseif ( $type == 'checkbox' ) { |
|
111 | + $label_after = true; // if type file we need the label after |
|
112 | + $args['class'] .= ' custom-control-input '; |
|
113 | + } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
114 | + $type = 'text'; |
|
115 | + $args['class'] .= ' bg-initial '; // @todo not sure why we have this? |
|
116 | + $clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');"; |
|
117 | + |
|
118 | + $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
119 | + |
|
120 | + // set a way to clear field if empty |
|
121 | + if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) { |
|
122 | + $args['input_group_right_inside'] = true; |
|
123 | + $args['clear_icon'] = true; |
|
124 | + } |
|
125 | + |
|
126 | + // enqueue the script |
|
127 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
128 | + $aui_settings->enqueue_flatpickr(); |
|
129 | + } elseif ( $type == 'iconpicker' ) { |
|
130 | + $type = 'text'; |
|
131 | + //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
132 | 132 | // $args['class'] .= ' bg-initial '; |
133 | 133 | |
134 | - $args['extra_attributes']['data-aui-init'] = 'iconpicker'; |
|
135 | - $args['extra_attributes']['data-placement'] = 'bottomRight'; |
|
134 | + $args['extra_attributes']['data-aui-init'] = 'iconpicker'; |
|
135 | + $args['extra_attributes']['data-placement'] = 'bottomRight'; |
|
136 | 136 | |
137 | - $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>'; |
|
137 | + $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>'; |
|
138 | 138 | // $args['input_group_right_inside'] = true; |
139 | - // enqueue the script |
|
140 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
141 | - $aui_settings->enqueue_iconpicker(); |
|
142 | - } |
|
143 | - |
|
144 | - if ( $type == 'checkbox' && !empty($args['name'] ) && strpos($args['name'], '[') === false ) { |
|
145 | - $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
146 | - } |
|
147 | - |
|
148 | - // allow clear icon |
|
149 | - if ( $args['input_group_right'] === '' && $args['clear_icon'] ) { |
|
150 | - $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' ); |
|
151 | - $args['input_group_right_inside'] = true; |
|
152 | - $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none" onclick="' . $clear_function . '"><span style="font-size: '.$font_size.'rem" aria-hidden="true" class="close">×</span></span>'; |
|
153 | - } |
|
154 | - |
|
155 | - // open/type |
|
156 | - $output .= '<input type="' . $type . '" '; |
|
157 | - |
|
158 | - // name |
|
159 | - if ( ! empty( $args['name'] ) ) { |
|
160 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
161 | - } |
|
162 | - |
|
163 | - // id |
|
164 | - if ( ! empty( $args['id'] ) ) { |
|
165 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
166 | - } |
|
167 | - |
|
168 | - // placeholder |
|
169 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
170 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
171 | - } |
|
172 | - |
|
173 | - // title |
|
174 | - if ( ! empty( $args['title'] ) ) { |
|
175 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
176 | - } |
|
177 | - |
|
178 | - // value |
|
179 | - if ( ! empty( $args['value'] ) ) { |
|
180 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
181 | - } |
|
182 | - |
|
183 | - // checked, for radio and checkboxes |
|
184 | - if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
185 | - $output .= ' checked '; |
|
186 | - } |
|
187 | - |
|
188 | - // validation text |
|
189 | - if ( ! empty( $args['validation_text'] ) ) { |
|
190 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
191 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
192 | - } |
|
193 | - |
|
194 | - // validation_pattern |
|
195 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
196 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
197 | - } |
|
198 | - |
|
199 | - // step (for numbers) |
|
200 | - if ( ! empty( $args['step'] ) ) { |
|
201 | - $output .= ' step="' . $args['step'] . '" '; |
|
202 | - } |
|
203 | - |
|
204 | - // required |
|
205 | - if ( ! empty( $args['required'] ) ) { |
|
206 | - $output .= ' required '; |
|
207 | - } |
|
208 | - |
|
209 | - // class |
|
210 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
211 | - $output .= ' class="form-control ' . $class . '" '; |
|
212 | - |
|
213 | - // data-attributes |
|
214 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
215 | - |
|
216 | - // extra attributes |
|
217 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
218 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
219 | - } |
|
220 | - |
|
221 | - // close |
|
222 | - $output .= ' >'; |
|
223 | - |
|
224 | - // help text |
|
225 | - if ( ! empty( $args['help_text'] ) ) { |
|
226 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
227 | - } |
|
228 | - |
|
229 | - // label |
|
230 | - if ( ! empty( $args['label'] ) ) { |
|
231 | - $label_base_class = ''; |
|
232 | - if ( $type == 'file' ) { |
|
233 | - $label_base_class = ' custom-file-label'; |
|
234 | - } elseif ( $type == 'checkbox' ) { |
|
235 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
236 | - $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
237 | - $help_text = ''; |
|
238 | - //$label_args['class'] .= ' d-inline '; |
|
239 | - $args['wrap_class'] .= ' align-items-center '; |
|
240 | - }else{ |
|
241 | - |
|
242 | - } |
|
243 | - |
|
244 | - $label_base_class = ' custom-control-label'; |
|
245 | - } |
|
246 | - $label_args['class'] .= $label_base_class; |
|
247 | - $temp_label_args = $label_args; |
|
248 | - if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
249 | - $label = self::label( $temp_label_args, $type ); |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - |
|
254 | - |
|
255 | - // set help text in the correct position |
|
256 | - if ( $label_after ) { |
|
257 | - $output .= $label . $help_text; |
|
258 | - } |
|
259 | - |
|
260 | - // some input types need a separate wrap |
|
261 | - if ( $type == 'file' ) { |
|
262 | - $output = self::wrap( array( |
|
263 | - 'content' => $output, |
|
264 | - 'class' => 'form-group custom-file' |
|
265 | - ) ); |
|
266 | - } elseif ( $type == 'checkbox' ) { |
|
267 | - |
|
268 | - $label_args['title'] = $args['label']; |
|
269 | - $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
270 | - $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
271 | - $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
272 | - $wrap_class = $args['switch'] ? 'custom-switch'.$switch_size_class : 'custom-checkbox'; |
|
273 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
274 | - $wrap_class .= ' d-flex align-content-center'; |
|
275 | - $label = str_replace("custom-control-label","", self::label( $label_args, 'cb' ) ); |
|
276 | - } |
|
277 | - $output = self::wrap( array( |
|
278 | - 'content' => $output, |
|
279 | - 'class' => 'custom-control ' . $wrap_class |
|
280 | - ) ); |
|
281 | - |
|
282 | - if ( $args['label_type'] == 'horizontal' ) { |
|
283 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
284 | - $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
|
285 | - } |
|
286 | - } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
287 | - |
|
288 | - |
|
289 | - // allow password field to toggle view |
|
290 | - $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
139 | + // enqueue the script |
|
140 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
141 | + $aui_settings->enqueue_iconpicker(); |
|
142 | + } |
|
143 | + |
|
144 | + if ( $type == 'checkbox' && !empty($args['name'] ) && strpos($args['name'], '[') === false ) { |
|
145 | + $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
146 | + } |
|
147 | + |
|
148 | + // allow clear icon |
|
149 | + if ( $args['input_group_right'] === '' && $args['clear_icon'] ) { |
|
150 | + $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' ); |
|
151 | + $args['input_group_right_inside'] = true; |
|
152 | + $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none" onclick="' . $clear_function . '"><span style="font-size: '.$font_size.'rem" aria-hidden="true" class="close">×</span></span>'; |
|
153 | + } |
|
154 | + |
|
155 | + // open/type |
|
156 | + $output .= '<input type="' . $type . '" '; |
|
157 | + |
|
158 | + // name |
|
159 | + if ( ! empty( $args['name'] ) ) { |
|
160 | + $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
161 | + } |
|
162 | + |
|
163 | + // id |
|
164 | + if ( ! empty( $args['id'] ) ) { |
|
165 | + $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
166 | + } |
|
167 | + |
|
168 | + // placeholder |
|
169 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
170 | + $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
171 | + } |
|
172 | + |
|
173 | + // title |
|
174 | + if ( ! empty( $args['title'] ) ) { |
|
175 | + $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
176 | + } |
|
177 | + |
|
178 | + // value |
|
179 | + if ( ! empty( $args['value'] ) ) { |
|
180 | + $output .= AUI_Component_Helper::value( $args['value'] ); |
|
181 | + } |
|
182 | + |
|
183 | + // checked, for radio and checkboxes |
|
184 | + if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
185 | + $output .= ' checked '; |
|
186 | + } |
|
187 | + |
|
188 | + // validation text |
|
189 | + if ( ! empty( $args['validation_text'] ) ) { |
|
190 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
191 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
192 | + } |
|
193 | + |
|
194 | + // validation_pattern |
|
195 | + if ( ! empty( $args['validation_pattern'] ) ) { |
|
196 | + $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
197 | + } |
|
198 | + |
|
199 | + // step (for numbers) |
|
200 | + if ( ! empty( $args['step'] ) ) { |
|
201 | + $output .= ' step="' . $args['step'] . '" '; |
|
202 | + } |
|
203 | + |
|
204 | + // required |
|
205 | + if ( ! empty( $args['required'] ) ) { |
|
206 | + $output .= ' required '; |
|
207 | + } |
|
208 | + |
|
209 | + // class |
|
210 | + $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
211 | + $output .= ' class="form-control ' . $class . '" '; |
|
212 | + |
|
213 | + // data-attributes |
|
214 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
215 | + |
|
216 | + // extra attributes |
|
217 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
218 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
219 | + } |
|
220 | + |
|
221 | + // close |
|
222 | + $output .= ' >'; |
|
223 | + |
|
224 | + // help text |
|
225 | + if ( ! empty( $args['help_text'] ) ) { |
|
226 | + $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
227 | + } |
|
228 | + |
|
229 | + // label |
|
230 | + if ( ! empty( $args['label'] ) ) { |
|
231 | + $label_base_class = ''; |
|
232 | + if ( $type == 'file' ) { |
|
233 | + $label_base_class = ' custom-file-label'; |
|
234 | + } elseif ( $type == 'checkbox' ) { |
|
235 | + if ( ! empty( $args['label_force_left'] ) ) { |
|
236 | + $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
237 | + $help_text = ''; |
|
238 | + //$label_args['class'] .= ' d-inline '; |
|
239 | + $args['wrap_class'] .= ' align-items-center '; |
|
240 | + }else{ |
|
241 | + |
|
242 | + } |
|
243 | + |
|
244 | + $label_base_class = ' custom-control-label'; |
|
245 | + } |
|
246 | + $label_args['class'] .= $label_base_class; |
|
247 | + $temp_label_args = $label_args; |
|
248 | + if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
249 | + $label = self::label( $temp_label_args, $type ); |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + |
|
254 | + |
|
255 | + // set help text in the correct position |
|
256 | + if ( $label_after ) { |
|
257 | + $output .= $label . $help_text; |
|
258 | + } |
|
259 | + |
|
260 | + // some input types need a separate wrap |
|
261 | + if ( $type == 'file' ) { |
|
262 | + $output = self::wrap( array( |
|
263 | + 'content' => $output, |
|
264 | + 'class' => 'form-group custom-file' |
|
265 | + ) ); |
|
266 | + } elseif ( $type == 'checkbox' ) { |
|
267 | + |
|
268 | + $label_args['title'] = $args['label']; |
|
269 | + $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
270 | + $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
271 | + $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
272 | + $wrap_class = $args['switch'] ? 'custom-switch'.$switch_size_class : 'custom-checkbox'; |
|
273 | + if ( ! empty( $args['label_force_left'] ) ) { |
|
274 | + $wrap_class .= ' d-flex align-content-center'; |
|
275 | + $label = str_replace("custom-control-label","", self::label( $label_args, 'cb' ) ); |
|
276 | + } |
|
277 | + $output = self::wrap( array( |
|
278 | + 'content' => $output, |
|
279 | + 'class' => 'custom-control ' . $wrap_class |
|
280 | + ) ); |
|
281 | + |
|
282 | + if ( $args['label_type'] == 'horizontal' ) { |
|
283 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
284 | + $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
|
285 | + } |
|
286 | + } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
287 | + |
|
288 | + |
|
289 | + // allow password field to toggle view |
|
290 | + $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
291 | 291 | onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\'); |
292 | 292 | var $eli = jQuery(this).parent().parent().find(\'input\'); |
293 | 293 | if($el.hasClass(\'fa-eye\')) |
294 | 294 | {$eli.attr(\'type\',\'text\');} |
295 | 295 | else{$eli.attr(\'type\',\'password\');}" |
296 | 296 | ><i class="far fa-fw fa-eye-slash"></i></span>'; |
297 | - } |
|
298 | - |
|
299 | - // input group wraps |
|
300 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
301 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
302 | - $group_size = $size == 'lg' ? ' input-group-lg' : ''; |
|
303 | - $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size; |
|
304 | - |
|
305 | - if ( $args['input_group_left'] ) { |
|
306 | - $output = self::wrap( array( |
|
307 | - 'content' => $output, |
|
308 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
309 | - 'input_group_left' => $args['input_group_left'], |
|
310 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
311 | - ) ); |
|
312 | - } |
|
313 | - if ( $args['input_group_right'] ) { |
|
314 | - $output = self::wrap( array( |
|
315 | - 'content' => $output, |
|
316 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
317 | - 'input_group_right' => $args['input_group_right'], |
|
318 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
319 | - ) ); |
|
320 | - } |
|
321 | - |
|
322 | - } |
|
323 | - |
|
324 | - if ( ! $label_after ) { |
|
325 | - $output .= $help_text; |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
330 | - $output = self::wrap( array( |
|
331 | - 'content' => $output, |
|
332 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
333 | - ) ); |
|
334 | - } |
|
335 | - |
|
336 | - if ( ! $label_after ) { |
|
337 | - $output = $label . $output; |
|
338 | - } |
|
339 | - |
|
340 | - // wrap |
|
341 | - if ( ! $args['no_wrap'] ) { |
|
342 | - $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
|
343 | - $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
344 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
345 | - $output = self::wrap( array( |
|
346 | - 'content' => $output, |
|
347 | - 'class' => $wrap_class, |
|
348 | - 'element_require' => $args['element_require'], |
|
349 | - 'argument_id' => $args['id'], |
|
350 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
351 | - ) ); |
|
352 | - } |
|
353 | - } |
|
354 | - |
|
355 | - return $output; |
|
356 | - } |
|
357 | - |
|
358 | - public static function label( $args = array(), $type = '' ) { |
|
359 | - //<label for="exampleInputEmail1">Email address</label> |
|
360 | - $defaults = array( |
|
361 | - 'title' => 'div', |
|
362 | - 'for' => '', |
|
363 | - 'class' => '', |
|
364 | - 'label_type' => '', // empty = hidden, top, horizontal |
|
365 | - 'label_col' => '', |
|
366 | - ); |
|
367 | - |
|
368 | - /** |
|
369 | - * Parse incoming $args into an array and merge it with $defaults |
|
370 | - */ |
|
371 | - $args = wp_parse_args( $args, $defaults ); |
|
372 | - $output = ''; |
|
373 | - |
|
374 | - if ( $args['title'] ) { |
|
375 | - |
|
376 | - // maybe hide labels //@todo set a global option for visibility class |
|
377 | - if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
378 | - $class = $args['class']; |
|
379 | - } else { |
|
380 | - $class = 'sr-only ' . $args['class']; |
|
381 | - } |
|
382 | - |
|
383 | - // maybe horizontal |
|
384 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
385 | - $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label'; |
|
386 | - } |
|
387 | - |
|
388 | - // open |
|
389 | - $output .= '<label '; |
|
390 | - |
|
391 | - // for |
|
392 | - if ( ! empty( $args['for'] ) ) { |
|
393 | - $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
394 | - } |
|
395 | - |
|
396 | - // class |
|
397 | - $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
398 | - $output .= ' class="' . $class . '" '; |
|
399 | - |
|
400 | - // close |
|
401 | - $output .= '>'; |
|
402 | - |
|
403 | - |
|
404 | - // title, don't escape fully as can contain html |
|
405 | - if ( ! empty( $args['title'] ) ) { |
|
406 | - $output .= wp_kses_post( $args['title'] ); |
|
407 | - } |
|
408 | - |
|
409 | - // close wrap |
|
410 | - $output .= '</label>'; |
|
411 | - |
|
412 | - |
|
413 | - } |
|
414 | - |
|
415 | - |
|
416 | - return $output; |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * Wrap some content in a HTML wrapper. |
|
421 | - * |
|
422 | - * @param array $args |
|
423 | - * |
|
424 | - * @return string |
|
425 | - */ |
|
426 | - public static function wrap( $args = array() ) { |
|
427 | - $defaults = array( |
|
428 | - 'type' => 'div', |
|
429 | - 'class' => 'form-group', |
|
430 | - 'content' => '', |
|
431 | - 'input_group_left' => '', |
|
432 | - 'input_group_right' => '', |
|
433 | - 'input_group_left_inside' => false, |
|
434 | - 'input_group_right_inside' => false, |
|
435 | - 'element_require' => '', |
|
436 | - 'argument_id' => '', |
|
437 | - 'wrap_attributes' => array() |
|
438 | - ); |
|
439 | - |
|
440 | - /** |
|
441 | - * Parse incoming $args into an array and merge it with $defaults |
|
442 | - */ |
|
443 | - $args = wp_parse_args( $args, $defaults ); |
|
444 | - $output = ''; |
|
445 | - if ( $args['type'] ) { |
|
446 | - |
|
447 | - // open |
|
448 | - $output .= '<' . sanitize_html_class( $args['type'] ); |
|
449 | - |
|
450 | - // element require |
|
451 | - if ( ! empty( $args['element_require'] ) ) { |
|
452 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
453 | - $args['class'] .= " aui-conditional-field"; |
|
454 | - } |
|
455 | - |
|
456 | - // argument_id |
|
457 | - if ( ! empty( $args['argument_id'] ) ) { |
|
458 | - $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
459 | - } |
|
460 | - |
|
461 | - // class |
|
462 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
463 | - $output .= ' class="' . $class . '" '; |
|
464 | - |
|
465 | - // Attributes |
|
466 | - if ( ! empty( $args['wrap_attributes'] ) ) { |
|
467 | - $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
468 | - } |
|
469 | - |
|
470 | - // close wrap |
|
471 | - $output .= ' >'; |
|
472 | - |
|
473 | - |
|
474 | - // Input group left |
|
475 | - if ( ! empty( $args['input_group_left'] ) ) { |
|
476 | - $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
477 | - $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
478 | - $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
479 | - } |
|
480 | - |
|
481 | - // content |
|
482 | - $output .= $args['content']; |
|
483 | - |
|
484 | - // Input group right |
|
485 | - if ( ! empty( $args['input_group_right'] ) ) { |
|
486 | - $position_class = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : ''; |
|
487 | - $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
488 | - $output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
|
489 | - } |
|
490 | - |
|
491 | - |
|
492 | - // close wrap |
|
493 | - $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
494 | - |
|
495 | - |
|
496 | - } else { |
|
497 | - $output = $args['content']; |
|
498 | - } |
|
499 | - |
|
500 | - return $output; |
|
501 | - } |
|
502 | - |
|
503 | - /** |
|
504 | - * Build the component. |
|
505 | - * |
|
506 | - * @param array $args |
|
507 | - * |
|
508 | - * @return string The rendered component. |
|
509 | - */ |
|
510 | - public static function textarea( $args = array() ) { |
|
511 | - $defaults = array( |
|
512 | - 'name' => '', |
|
513 | - 'class' => '', |
|
514 | - 'wrap_class' => '', |
|
515 | - 'id' => '', |
|
516 | - 'placeholder' => '', |
|
517 | - 'title' => '', |
|
518 | - 'value' => '', |
|
519 | - 'required' => false, |
|
520 | - 'label' => '', |
|
521 | - 'label_after' => false, |
|
522 | - 'label_class' => '', |
|
523 | - 'label_type' => '', |
|
524 | - 'label_col' => '', |
|
525 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
526 | - 'input_group_right' => '', |
|
527 | - 'input_group_left' => '', |
|
528 | - 'input_group_right_inside' => false, |
|
529 | - 'help_text' => '', |
|
530 | - 'validation_text' => '', |
|
531 | - 'validation_pattern' => '', |
|
532 | - 'no_wrap' => false, |
|
533 | - 'rows' => '', |
|
534 | - 'wysiwyg' => false, |
|
535 | - 'allow_tags' => false, |
|
536 | - // Allow HTML tags |
|
537 | - 'element_require' => '', |
|
538 | - // [%element_id%] == "1" |
|
539 | - 'extra_attributes' => array(), |
|
540 | - // an array of extra attributes |
|
541 | - 'wrap_attributes' => array(), |
|
542 | - ); |
|
543 | - |
|
544 | - /** |
|
545 | - * Parse incoming $args into an array and merge it with $defaults |
|
546 | - */ |
|
547 | - $args = wp_parse_args( $args, $defaults ); |
|
548 | - $output = ''; |
|
549 | - |
|
550 | - // hidden label option needs to be empty |
|
551 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
552 | - |
|
553 | - // floating labels don't work with wysiwyg so set it as top |
|
554 | - if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
555 | - $args['label_type'] = 'top'; |
|
556 | - } |
|
557 | - |
|
558 | - $label_after = $args['label_after']; |
|
559 | - |
|
560 | - // floating labels need label after |
|
561 | - if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
562 | - $label_after = true; |
|
563 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
564 | - } |
|
565 | - |
|
566 | - // label |
|
567 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
568 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
569 | - $label_args = array( |
|
570 | - 'title' => $args['label'], |
|
571 | - 'for' => $args['id'], |
|
572 | - 'class' => $args['label_class'] . " ", |
|
573 | - 'label_type' => $args['label_type'], |
|
574 | - 'label_col' => $args['label_col'] |
|
575 | - ); |
|
576 | - $output .= self::label( $label_args ); |
|
577 | - } |
|
578 | - |
|
579 | - // maybe horizontal label |
|
580 | - if ( $args['label_type'] == 'horizontal' ) { |
|
581 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
582 | - $output .= '<div class="' . $input_col . '">'; |
|
583 | - } |
|
584 | - |
|
585 | - if ( ! empty( $args['wysiwyg'] ) ) { |
|
586 | - ob_start(); |
|
587 | - $content = $args['value']; |
|
588 | - $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
589 | - $settings = array( |
|
590 | - 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
591 | - 'quicktags' => false, |
|
592 | - 'media_buttons' => false, |
|
593 | - 'editor_class' => 'form-control', |
|
594 | - 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
595 | - 'teeny' => true, |
|
596 | - ); |
|
597 | - |
|
598 | - // maybe set settings if array |
|
599 | - if ( is_array( $args['wysiwyg'] ) ) { |
|
600 | - $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
601 | - } |
|
602 | - |
|
603 | - wp_editor( $content, $editor_id, $settings ); |
|
604 | - $output .= ob_get_clean(); |
|
605 | - } else { |
|
606 | - |
|
607 | - // open |
|
608 | - $output .= '<textarea '; |
|
609 | - |
|
610 | - // name |
|
611 | - if ( ! empty( $args['name'] ) ) { |
|
612 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
613 | - } |
|
614 | - |
|
615 | - // id |
|
616 | - if ( ! empty( $args['id'] ) ) { |
|
617 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
618 | - } |
|
619 | - |
|
620 | - // placeholder |
|
621 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
622 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
623 | - } |
|
624 | - |
|
625 | - // title |
|
626 | - if ( ! empty( $args['title'] ) ) { |
|
627 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
628 | - } |
|
629 | - |
|
630 | - // validation text |
|
631 | - if ( ! empty( $args['validation_text'] ) ) { |
|
632 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
633 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
634 | - } |
|
635 | - |
|
636 | - // validation_pattern |
|
637 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
638 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
639 | - } |
|
640 | - |
|
641 | - // required |
|
642 | - if ( ! empty( $args['required'] ) ) { |
|
643 | - $output .= ' required '; |
|
644 | - } |
|
645 | - |
|
646 | - // rows |
|
647 | - if ( ! empty( $args['rows'] ) ) { |
|
648 | - $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
649 | - } |
|
650 | - |
|
651 | - |
|
652 | - // class |
|
653 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
654 | - $output .= ' class="form-control ' . $class . '" '; |
|
655 | - |
|
656 | - // extra attributes |
|
657 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
658 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
659 | - } |
|
660 | - |
|
661 | - // close tag |
|
662 | - $output .= ' >'; |
|
663 | - |
|
664 | - // value |
|
665 | - if ( ! empty( $args['value'] ) ) { |
|
666 | - if ( ! empty( $args['allow_tags'] ) ) { |
|
667 | - $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
668 | - } else { |
|
669 | - $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] ); |
|
670 | - } |
|
671 | - } |
|
672 | - |
|
673 | - // closing tag |
|
674 | - $output .= '</textarea>'; |
|
675 | - |
|
676 | - |
|
677 | - // input group wraps |
|
678 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
679 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
680 | - if ( $args['input_group_left'] ) { |
|
681 | - $output = self::wrap( array( |
|
682 | - 'content' => $output, |
|
683 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
684 | - 'input_group_left' => $args['input_group_left'], |
|
685 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
686 | - ) ); |
|
687 | - } |
|
688 | - if ( $args['input_group_right'] ) { |
|
689 | - $output = self::wrap( array( |
|
690 | - 'content' => $output, |
|
691 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
692 | - 'input_group_right' => $args['input_group_right'], |
|
693 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
694 | - ) ); |
|
695 | - } |
|
696 | - |
|
697 | - } |
|
698 | - |
|
699 | - |
|
700 | - } |
|
701 | - |
|
702 | - if ( ! empty( $args['label'] ) && $label_after ) { |
|
703 | - $label_args = array( |
|
704 | - 'title' => $args['label'], |
|
705 | - 'for' => $args['id'], |
|
706 | - 'class' => $args['label_class'] . " ", |
|
707 | - 'label_type' => $args['label_type'], |
|
708 | - 'label_col' => $args['label_col'] |
|
709 | - ); |
|
710 | - $output .= self::label( $label_args ); |
|
711 | - } |
|
712 | - |
|
713 | - // help text |
|
714 | - if ( ! empty( $args['help_text'] ) ) { |
|
715 | - $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
716 | - } |
|
717 | - |
|
718 | - // maybe horizontal label |
|
719 | - if ( $args['label_type'] == 'horizontal' ) { |
|
720 | - $output .= '</div>'; |
|
721 | - } |
|
722 | - |
|
723 | - |
|
724 | - // wrap |
|
725 | - if ( ! $args['no_wrap'] ) { |
|
726 | - $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : 'form-group'; |
|
727 | - $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
728 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
729 | - $output = self::wrap( array( |
|
730 | - 'content' => $output, |
|
731 | - 'class' => $wrap_class, |
|
732 | - 'element_require' => $args['element_require'], |
|
733 | - 'argument_id' => $args['id'], |
|
734 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
735 | - ) ); |
|
736 | - } |
|
737 | - |
|
738 | - |
|
739 | - return $output; |
|
740 | - } |
|
741 | - |
|
742 | - /** |
|
743 | - * Build the component. |
|
744 | - * |
|
745 | - * @param array $args |
|
746 | - * |
|
747 | - * @return string The rendered component. |
|
748 | - */ |
|
749 | - public static function select( $args = array() ) { |
|
750 | - $defaults = array( |
|
751 | - 'class' => '', |
|
752 | - 'wrap_class' => '', |
|
753 | - 'id' => '', |
|
754 | - 'title' => '', |
|
755 | - 'value' => '', |
|
756 | - // can be an array or a string |
|
757 | - 'required' => false, |
|
758 | - 'label' => '', |
|
759 | - 'label_after' => false, |
|
760 | - 'label_type' => '', |
|
761 | - 'label_col' => '', |
|
762 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
763 | - 'label_class' => '', |
|
764 | - 'help_text' => '', |
|
765 | - 'placeholder' => '', |
|
766 | - 'options' => array(), |
|
767 | - // array or string |
|
768 | - 'icon' => '', |
|
769 | - 'multiple' => false, |
|
770 | - 'select2' => false, |
|
771 | - 'no_wrap' => false, |
|
772 | - 'input_group_right' => '', |
|
773 | - 'input_group_left' => '', |
|
774 | - 'input_group_right_inside' => false, // forces the input group inside the input |
|
775 | - 'input_group_left_inside' => false, // forces the input group inside the input |
|
776 | - 'element_require' => '', |
|
777 | - // [%element_id%] == "1" |
|
778 | - 'extra_attributes' => array(), |
|
779 | - // an array of extra attributes |
|
780 | - 'wrap_attributes' => array(), |
|
781 | - ); |
|
782 | - |
|
783 | - /** |
|
784 | - * Parse incoming $args into an array and merge it with $defaults |
|
785 | - */ |
|
786 | - $args = wp_parse_args( $args, $defaults ); |
|
787 | - $output = ''; |
|
788 | - |
|
789 | - // for now lets hide floating labels |
|
790 | - if ( $args['label_type'] == 'floating' ) { |
|
791 | - $args['label_type'] = 'hidden'; |
|
792 | - } |
|
793 | - |
|
794 | - // hidden label option needs to be empty |
|
795 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
796 | - |
|
797 | - |
|
798 | - $label_after = $args['label_after']; |
|
799 | - |
|
800 | - // floating labels need label after |
|
801 | - if ( $args['label_type'] == 'floating' ) { |
|
802 | - $label_after = true; |
|
803 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
804 | - } |
|
805 | - |
|
806 | - // Maybe setup select2 |
|
807 | - $is_select2 = false; |
|
808 | - if ( ! empty( $args['select2'] ) ) { |
|
809 | - $args['class'] .= ' aui-select2'; |
|
810 | - $is_select2 = true; |
|
811 | - } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
812 | - $is_select2 = true; |
|
813 | - } |
|
814 | - |
|
815 | - // select2 tags |
|
816 | - if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
817 | - $args['data-tags'] = 'true'; |
|
818 | - $args['data-token-separators'] = "[',']"; |
|
819 | - $args['multiple'] = true; |
|
820 | - } |
|
821 | - |
|
822 | - // select2 placeholder |
|
823 | - if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
824 | - $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
825 | - $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
826 | - } |
|
827 | - |
|
828 | - // Set hidden input to save empty value for multiselect. |
|
829 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
830 | - $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>'; |
|
831 | - } |
|
832 | - |
|
833 | - // open/type |
|
834 | - $output .= '<select '; |
|
835 | - |
|
836 | - // style |
|
837 | - if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
838 | - $output .= " style='width:100%;' "; |
|
839 | - } |
|
840 | - |
|
841 | - // element require |
|
842 | - if ( ! empty( $args['element_require'] ) ) { |
|
843 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
844 | - $args['class'] .= " aui-conditional-field"; |
|
845 | - } |
|
846 | - |
|
847 | - // class |
|
848 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
849 | - $output .= AUI_Component_Helper::class_attr( 'custom-select ' . $class ); |
|
850 | - |
|
851 | - // name |
|
852 | - if ( ! empty( $args['name'] ) ) { |
|
853 | - $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
854 | - } |
|
855 | - |
|
856 | - // id |
|
857 | - if ( ! empty( $args['id'] ) ) { |
|
858 | - $output .= AUI_Component_Helper::id( $args['id'] ); |
|
859 | - } |
|
860 | - |
|
861 | - // title |
|
862 | - if ( ! empty( $args['title'] ) ) { |
|
863 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
864 | - } |
|
865 | - |
|
866 | - // data-attributes |
|
867 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
868 | - |
|
869 | - // aria-attributes |
|
870 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
871 | - |
|
872 | - // extra attributes |
|
873 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
874 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
875 | - } |
|
876 | - |
|
877 | - // required |
|
878 | - if ( ! empty( $args['required'] ) ) { |
|
879 | - $output .= ' required '; |
|
880 | - } |
|
881 | - |
|
882 | - // multiple |
|
883 | - if ( ! empty( $args['multiple'] ) ) { |
|
884 | - $output .= ' multiple '; |
|
885 | - } |
|
886 | - |
|
887 | - // close opening tag |
|
888 | - $output .= ' >'; |
|
889 | - |
|
890 | - // placeholder |
|
891 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
892 | - $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
893 | - } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
894 | - $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
895 | - } |
|
896 | - |
|
897 | - // Options |
|
898 | - if ( ! empty( $args['options'] ) ) { |
|
899 | - |
|
900 | - if ( ! is_array( $args['options'] ) ) { |
|
901 | - $output .= $args['options']; // not the preferred way but an option |
|
902 | - } else { |
|
903 | - foreach ( $args['options'] as $val => $name ) { |
|
904 | - $selected = ''; |
|
905 | - if ( is_array( $name ) ) { |
|
906 | - if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
907 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
908 | - |
|
909 | - $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
910 | - } else { |
|
911 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
912 | - $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
913 | - $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
914 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
915 | - $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
916 | - } elseif ( ! empty( $args['value'] ) ) { |
|
917 | - $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
918 | - } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) { |
|
919 | - $selected = selected( $option_value, $args['value'], false ); |
|
920 | - } |
|
921 | - |
|
922 | - $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
923 | - } |
|
924 | - } else { |
|
925 | - if ( ! empty( $args['value'] ) ) { |
|
926 | - if ( is_array( $args['value'] ) ) { |
|
927 | - $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
928 | - } elseif ( ! empty( $args['value'] ) ) { |
|
929 | - $selected = selected( $args['value'], $val, false ); |
|
930 | - } |
|
931 | - } elseif ( $args['value'] === $val ) { |
|
932 | - $selected = selected( $args['value'], $val, false ); |
|
933 | - } |
|
934 | - $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
935 | - } |
|
936 | - } |
|
937 | - } |
|
938 | - |
|
939 | - } |
|
940 | - |
|
941 | - // closing tag |
|
942 | - $output .= '</select>'; |
|
943 | - |
|
944 | - $label = ''; |
|
945 | - $help_text = ''; |
|
946 | - // label |
|
947 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
948 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
949 | - $label_args = array( |
|
950 | - 'title' => $args['label'], |
|
951 | - 'for' => $args['id'], |
|
952 | - 'class' => $args['label_class'] . " ", |
|
953 | - 'label_type' => $args['label_type'], |
|
954 | - 'label_col' => $args['label_col'] |
|
955 | - ); |
|
956 | - $label = self::label( $label_args ); |
|
957 | - } |
|
958 | - |
|
959 | - // help text |
|
960 | - if ( ! empty( $args['help_text'] ) ) { |
|
961 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
962 | - } |
|
963 | - |
|
964 | - // input group wraps |
|
965 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
966 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
967 | - if ( $args['input_group_left'] ) { |
|
968 | - $output = self::wrap( array( |
|
969 | - 'content' => $output, |
|
970 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
971 | - 'input_group_left' => $args['input_group_left'], |
|
972 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
973 | - ) ); |
|
974 | - } |
|
975 | - if ( $args['input_group_right'] ) { |
|
976 | - $output = self::wrap( array( |
|
977 | - 'content' => $output, |
|
978 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
979 | - 'input_group_right' => $args['input_group_right'], |
|
980 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
981 | - ) ); |
|
982 | - } |
|
983 | - |
|
984 | - } |
|
985 | - |
|
986 | - if ( ! $label_after ) { |
|
987 | - $output .= $help_text; |
|
988 | - } |
|
989 | - |
|
990 | - |
|
991 | - if ( $args['label_type'] == 'horizontal' ) { |
|
992 | - $output = self::wrap( array( |
|
993 | - 'content' => $output, |
|
994 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
995 | - ) ); |
|
996 | - } |
|
997 | - |
|
998 | - if ( ! $label_after ) { |
|
999 | - $output = $label . $output; |
|
1000 | - } |
|
1001 | - |
|
1002 | - // maybe horizontal label |
|
297 | + } |
|
298 | + |
|
299 | + // input group wraps |
|
300 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
301 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
302 | + $group_size = $size == 'lg' ? ' input-group-lg' : ''; |
|
303 | + $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size; |
|
304 | + |
|
305 | + if ( $args['input_group_left'] ) { |
|
306 | + $output = self::wrap( array( |
|
307 | + 'content' => $output, |
|
308 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
309 | + 'input_group_left' => $args['input_group_left'], |
|
310 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
311 | + ) ); |
|
312 | + } |
|
313 | + if ( $args['input_group_right'] ) { |
|
314 | + $output = self::wrap( array( |
|
315 | + 'content' => $output, |
|
316 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
317 | + 'input_group_right' => $args['input_group_right'], |
|
318 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
319 | + ) ); |
|
320 | + } |
|
321 | + |
|
322 | + } |
|
323 | + |
|
324 | + if ( ! $label_after ) { |
|
325 | + $output .= $help_text; |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
330 | + $output = self::wrap( array( |
|
331 | + 'content' => $output, |
|
332 | + 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
333 | + ) ); |
|
334 | + } |
|
335 | + |
|
336 | + if ( ! $label_after ) { |
|
337 | + $output = $label . $output; |
|
338 | + } |
|
339 | + |
|
340 | + // wrap |
|
341 | + if ( ! $args['no_wrap'] ) { |
|
342 | + $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
|
343 | + $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
344 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
345 | + $output = self::wrap( array( |
|
346 | + 'content' => $output, |
|
347 | + 'class' => $wrap_class, |
|
348 | + 'element_require' => $args['element_require'], |
|
349 | + 'argument_id' => $args['id'], |
|
350 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
351 | + ) ); |
|
352 | + } |
|
353 | + } |
|
354 | + |
|
355 | + return $output; |
|
356 | + } |
|
357 | + |
|
358 | + public static function label( $args = array(), $type = '' ) { |
|
359 | + //<label for="exampleInputEmail1">Email address</label> |
|
360 | + $defaults = array( |
|
361 | + 'title' => 'div', |
|
362 | + 'for' => '', |
|
363 | + 'class' => '', |
|
364 | + 'label_type' => '', // empty = hidden, top, horizontal |
|
365 | + 'label_col' => '', |
|
366 | + ); |
|
367 | + |
|
368 | + /** |
|
369 | + * Parse incoming $args into an array and merge it with $defaults |
|
370 | + */ |
|
371 | + $args = wp_parse_args( $args, $defaults ); |
|
372 | + $output = ''; |
|
373 | + |
|
374 | + if ( $args['title'] ) { |
|
375 | + |
|
376 | + // maybe hide labels //@todo set a global option for visibility class |
|
377 | + if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
378 | + $class = $args['class']; |
|
379 | + } else { |
|
380 | + $class = 'sr-only ' . $args['class']; |
|
381 | + } |
|
382 | + |
|
383 | + // maybe horizontal |
|
384 | + if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
385 | + $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label'; |
|
386 | + } |
|
387 | + |
|
388 | + // open |
|
389 | + $output .= '<label '; |
|
390 | + |
|
391 | + // for |
|
392 | + if ( ! empty( $args['for'] ) ) { |
|
393 | + $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
394 | + } |
|
395 | + |
|
396 | + // class |
|
397 | + $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
398 | + $output .= ' class="' . $class . '" '; |
|
399 | + |
|
400 | + // close |
|
401 | + $output .= '>'; |
|
402 | + |
|
403 | + |
|
404 | + // title, don't escape fully as can contain html |
|
405 | + if ( ! empty( $args['title'] ) ) { |
|
406 | + $output .= wp_kses_post( $args['title'] ); |
|
407 | + } |
|
408 | + |
|
409 | + // close wrap |
|
410 | + $output .= '</label>'; |
|
411 | + |
|
412 | + |
|
413 | + } |
|
414 | + |
|
415 | + |
|
416 | + return $output; |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * Wrap some content in a HTML wrapper. |
|
421 | + * |
|
422 | + * @param array $args |
|
423 | + * |
|
424 | + * @return string |
|
425 | + */ |
|
426 | + public static function wrap( $args = array() ) { |
|
427 | + $defaults = array( |
|
428 | + 'type' => 'div', |
|
429 | + 'class' => 'form-group', |
|
430 | + 'content' => '', |
|
431 | + 'input_group_left' => '', |
|
432 | + 'input_group_right' => '', |
|
433 | + 'input_group_left_inside' => false, |
|
434 | + 'input_group_right_inside' => false, |
|
435 | + 'element_require' => '', |
|
436 | + 'argument_id' => '', |
|
437 | + 'wrap_attributes' => array() |
|
438 | + ); |
|
439 | + |
|
440 | + /** |
|
441 | + * Parse incoming $args into an array and merge it with $defaults |
|
442 | + */ |
|
443 | + $args = wp_parse_args( $args, $defaults ); |
|
444 | + $output = ''; |
|
445 | + if ( $args['type'] ) { |
|
446 | + |
|
447 | + // open |
|
448 | + $output .= '<' . sanitize_html_class( $args['type'] ); |
|
449 | + |
|
450 | + // element require |
|
451 | + if ( ! empty( $args['element_require'] ) ) { |
|
452 | + $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
453 | + $args['class'] .= " aui-conditional-field"; |
|
454 | + } |
|
455 | + |
|
456 | + // argument_id |
|
457 | + if ( ! empty( $args['argument_id'] ) ) { |
|
458 | + $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
459 | + } |
|
460 | + |
|
461 | + // class |
|
462 | + $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
463 | + $output .= ' class="' . $class . '" '; |
|
464 | + |
|
465 | + // Attributes |
|
466 | + if ( ! empty( $args['wrap_attributes'] ) ) { |
|
467 | + $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
468 | + } |
|
469 | + |
|
470 | + // close wrap |
|
471 | + $output .= ' >'; |
|
472 | + |
|
473 | + |
|
474 | + // Input group left |
|
475 | + if ( ! empty( $args['input_group_left'] ) ) { |
|
476 | + $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
477 | + $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
478 | + $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
479 | + } |
|
480 | + |
|
481 | + // content |
|
482 | + $output .= $args['content']; |
|
483 | + |
|
484 | + // Input group right |
|
485 | + if ( ! empty( $args['input_group_right'] ) ) { |
|
486 | + $position_class = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : ''; |
|
487 | + $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
488 | + $output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
|
489 | + } |
|
490 | + |
|
491 | + |
|
492 | + // close wrap |
|
493 | + $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
494 | + |
|
495 | + |
|
496 | + } else { |
|
497 | + $output = $args['content']; |
|
498 | + } |
|
499 | + |
|
500 | + return $output; |
|
501 | + } |
|
502 | + |
|
503 | + /** |
|
504 | + * Build the component. |
|
505 | + * |
|
506 | + * @param array $args |
|
507 | + * |
|
508 | + * @return string The rendered component. |
|
509 | + */ |
|
510 | + public static function textarea( $args = array() ) { |
|
511 | + $defaults = array( |
|
512 | + 'name' => '', |
|
513 | + 'class' => '', |
|
514 | + 'wrap_class' => '', |
|
515 | + 'id' => '', |
|
516 | + 'placeholder' => '', |
|
517 | + 'title' => '', |
|
518 | + 'value' => '', |
|
519 | + 'required' => false, |
|
520 | + 'label' => '', |
|
521 | + 'label_after' => false, |
|
522 | + 'label_class' => '', |
|
523 | + 'label_type' => '', |
|
524 | + 'label_col' => '', |
|
525 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
526 | + 'input_group_right' => '', |
|
527 | + 'input_group_left' => '', |
|
528 | + 'input_group_right_inside' => false, |
|
529 | + 'help_text' => '', |
|
530 | + 'validation_text' => '', |
|
531 | + 'validation_pattern' => '', |
|
532 | + 'no_wrap' => false, |
|
533 | + 'rows' => '', |
|
534 | + 'wysiwyg' => false, |
|
535 | + 'allow_tags' => false, |
|
536 | + // Allow HTML tags |
|
537 | + 'element_require' => '', |
|
538 | + // [%element_id%] == "1" |
|
539 | + 'extra_attributes' => array(), |
|
540 | + // an array of extra attributes |
|
541 | + 'wrap_attributes' => array(), |
|
542 | + ); |
|
543 | + |
|
544 | + /** |
|
545 | + * Parse incoming $args into an array and merge it with $defaults |
|
546 | + */ |
|
547 | + $args = wp_parse_args( $args, $defaults ); |
|
548 | + $output = ''; |
|
549 | + |
|
550 | + // hidden label option needs to be empty |
|
551 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
552 | + |
|
553 | + // floating labels don't work with wysiwyg so set it as top |
|
554 | + if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
555 | + $args['label_type'] = 'top'; |
|
556 | + } |
|
557 | + |
|
558 | + $label_after = $args['label_after']; |
|
559 | + |
|
560 | + // floating labels need label after |
|
561 | + if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
562 | + $label_after = true; |
|
563 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
564 | + } |
|
565 | + |
|
566 | + // label |
|
567 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
568 | + } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
569 | + $label_args = array( |
|
570 | + 'title' => $args['label'], |
|
571 | + 'for' => $args['id'], |
|
572 | + 'class' => $args['label_class'] . " ", |
|
573 | + 'label_type' => $args['label_type'], |
|
574 | + 'label_col' => $args['label_col'] |
|
575 | + ); |
|
576 | + $output .= self::label( $label_args ); |
|
577 | + } |
|
578 | + |
|
579 | + // maybe horizontal label |
|
580 | + if ( $args['label_type'] == 'horizontal' ) { |
|
581 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
582 | + $output .= '<div class="' . $input_col . '">'; |
|
583 | + } |
|
584 | + |
|
585 | + if ( ! empty( $args['wysiwyg'] ) ) { |
|
586 | + ob_start(); |
|
587 | + $content = $args['value']; |
|
588 | + $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
589 | + $settings = array( |
|
590 | + 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
591 | + 'quicktags' => false, |
|
592 | + 'media_buttons' => false, |
|
593 | + 'editor_class' => 'form-control', |
|
594 | + 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
595 | + 'teeny' => true, |
|
596 | + ); |
|
597 | + |
|
598 | + // maybe set settings if array |
|
599 | + if ( is_array( $args['wysiwyg'] ) ) { |
|
600 | + $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
601 | + } |
|
602 | + |
|
603 | + wp_editor( $content, $editor_id, $settings ); |
|
604 | + $output .= ob_get_clean(); |
|
605 | + } else { |
|
606 | + |
|
607 | + // open |
|
608 | + $output .= '<textarea '; |
|
609 | + |
|
610 | + // name |
|
611 | + if ( ! empty( $args['name'] ) ) { |
|
612 | + $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
613 | + } |
|
614 | + |
|
615 | + // id |
|
616 | + if ( ! empty( $args['id'] ) ) { |
|
617 | + $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
618 | + } |
|
619 | + |
|
620 | + // placeholder |
|
621 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
622 | + $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
623 | + } |
|
624 | + |
|
625 | + // title |
|
626 | + if ( ! empty( $args['title'] ) ) { |
|
627 | + $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
628 | + } |
|
629 | + |
|
630 | + // validation text |
|
631 | + if ( ! empty( $args['validation_text'] ) ) { |
|
632 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
633 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
634 | + } |
|
635 | + |
|
636 | + // validation_pattern |
|
637 | + if ( ! empty( $args['validation_pattern'] ) ) { |
|
638 | + $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
639 | + } |
|
640 | + |
|
641 | + // required |
|
642 | + if ( ! empty( $args['required'] ) ) { |
|
643 | + $output .= ' required '; |
|
644 | + } |
|
645 | + |
|
646 | + // rows |
|
647 | + if ( ! empty( $args['rows'] ) ) { |
|
648 | + $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
649 | + } |
|
650 | + |
|
651 | + |
|
652 | + // class |
|
653 | + $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
654 | + $output .= ' class="form-control ' . $class . '" '; |
|
655 | + |
|
656 | + // extra attributes |
|
657 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
658 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
659 | + } |
|
660 | + |
|
661 | + // close tag |
|
662 | + $output .= ' >'; |
|
663 | + |
|
664 | + // value |
|
665 | + if ( ! empty( $args['value'] ) ) { |
|
666 | + if ( ! empty( $args['allow_tags'] ) ) { |
|
667 | + $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
668 | + } else { |
|
669 | + $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] ); |
|
670 | + } |
|
671 | + } |
|
672 | + |
|
673 | + // closing tag |
|
674 | + $output .= '</textarea>'; |
|
675 | + |
|
676 | + |
|
677 | + // input group wraps |
|
678 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
679 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
680 | + if ( $args['input_group_left'] ) { |
|
681 | + $output = self::wrap( array( |
|
682 | + 'content' => $output, |
|
683 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
684 | + 'input_group_left' => $args['input_group_left'], |
|
685 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
686 | + ) ); |
|
687 | + } |
|
688 | + if ( $args['input_group_right'] ) { |
|
689 | + $output = self::wrap( array( |
|
690 | + 'content' => $output, |
|
691 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
692 | + 'input_group_right' => $args['input_group_right'], |
|
693 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
694 | + ) ); |
|
695 | + } |
|
696 | + |
|
697 | + } |
|
698 | + |
|
699 | + |
|
700 | + } |
|
701 | + |
|
702 | + if ( ! empty( $args['label'] ) && $label_after ) { |
|
703 | + $label_args = array( |
|
704 | + 'title' => $args['label'], |
|
705 | + 'for' => $args['id'], |
|
706 | + 'class' => $args['label_class'] . " ", |
|
707 | + 'label_type' => $args['label_type'], |
|
708 | + 'label_col' => $args['label_col'] |
|
709 | + ); |
|
710 | + $output .= self::label( $label_args ); |
|
711 | + } |
|
712 | + |
|
713 | + // help text |
|
714 | + if ( ! empty( $args['help_text'] ) ) { |
|
715 | + $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
716 | + } |
|
717 | + |
|
718 | + // maybe horizontal label |
|
719 | + if ( $args['label_type'] == 'horizontal' ) { |
|
720 | + $output .= '</div>'; |
|
721 | + } |
|
722 | + |
|
723 | + |
|
724 | + // wrap |
|
725 | + if ( ! $args['no_wrap'] ) { |
|
726 | + $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : 'form-group'; |
|
727 | + $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
728 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
729 | + $output = self::wrap( array( |
|
730 | + 'content' => $output, |
|
731 | + 'class' => $wrap_class, |
|
732 | + 'element_require' => $args['element_require'], |
|
733 | + 'argument_id' => $args['id'], |
|
734 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
735 | + ) ); |
|
736 | + } |
|
737 | + |
|
738 | + |
|
739 | + return $output; |
|
740 | + } |
|
741 | + |
|
742 | + /** |
|
743 | + * Build the component. |
|
744 | + * |
|
745 | + * @param array $args |
|
746 | + * |
|
747 | + * @return string The rendered component. |
|
748 | + */ |
|
749 | + public static function select( $args = array() ) { |
|
750 | + $defaults = array( |
|
751 | + 'class' => '', |
|
752 | + 'wrap_class' => '', |
|
753 | + 'id' => '', |
|
754 | + 'title' => '', |
|
755 | + 'value' => '', |
|
756 | + // can be an array or a string |
|
757 | + 'required' => false, |
|
758 | + 'label' => '', |
|
759 | + 'label_after' => false, |
|
760 | + 'label_type' => '', |
|
761 | + 'label_col' => '', |
|
762 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
763 | + 'label_class' => '', |
|
764 | + 'help_text' => '', |
|
765 | + 'placeholder' => '', |
|
766 | + 'options' => array(), |
|
767 | + // array or string |
|
768 | + 'icon' => '', |
|
769 | + 'multiple' => false, |
|
770 | + 'select2' => false, |
|
771 | + 'no_wrap' => false, |
|
772 | + 'input_group_right' => '', |
|
773 | + 'input_group_left' => '', |
|
774 | + 'input_group_right_inside' => false, // forces the input group inside the input |
|
775 | + 'input_group_left_inside' => false, // forces the input group inside the input |
|
776 | + 'element_require' => '', |
|
777 | + // [%element_id%] == "1" |
|
778 | + 'extra_attributes' => array(), |
|
779 | + // an array of extra attributes |
|
780 | + 'wrap_attributes' => array(), |
|
781 | + ); |
|
782 | + |
|
783 | + /** |
|
784 | + * Parse incoming $args into an array and merge it with $defaults |
|
785 | + */ |
|
786 | + $args = wp_parse_args( $args, $defaults ); |
|
787 | + $output = ''; |
|
788 | + |
|
789 | + // for now lets hide floating labels |
|
790 | + if ( $args['label_type'] == 'floating' ) { |
|
791 | + $args['label_type'] = 'hidden'; |
|
792 | + } |
|
793 | + |
|
794 | + // hidden label option needs to be empty |
|
795 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
796 | + |
|
797 | + |
|
798 | + $label_after = $args['label_after']; |
|
799 | + |
|
800 | + // floating labels need label after |
|
801 | + if ( $args['label_type'] == 'floating' ) { |
|
802 | + $label_after = true; |
|
803 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
804 | + } |
|
805 | + |
|
806 | + // Maybe setup select2 |
|
807 | + $is_select2 = false; |
|
808 | + if ( ! empty( $args['select2'] ) ) { |
|
809 | + $args['class'] .= ' aui-select2'; |
|
810 | + $is_select2 = true; |
|
811 | + } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
812 | + $is_select2 = true; |
|
813 | + } |
|
814 | + |
|
815 | + // select2 tags |
|
816 | + if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
817 | + $args['data-tags'] = 'true'; |
|
818 | + $args['data-token-separators'] = "[',']"; |
|
819 | + $args['multiple'] = true; |
|
820 | + } |
|
821 | + |
|
822 | + // select2 placeholder |
|
823 | + if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
824 | + $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
825 | + $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
826 | + } |
|
827 | + |
|
828 | + // Set hidden input to save empty value for multiselect. |
|
829 | + if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
830 | + $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>'; |
|
831 | + } |
|
832 | + |
|
833 | + // open/type |
|
834 | + $output .= '<select '; |
|
835 | + |
|
836 | + // style |
|
837 | + if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
838 | + $output .= " style='width:100%;' "; |
|
839 | + } |
|
840 | + |
|
841 | + // element require |
|
842 | + if ( ! empty( $args['element_require'] ) ) { |
|
843 | + $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
844 | + $args['class'] .= " aui-conditional-field"; |
|
845 | + } |
|
846 | + |
|
847 | + // class |
|
848 | + $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
849 | + $output .= AUI_Component_Helper::class_attr( 'custom-select ' . $class ); |
|
850 | + |
|
851 | + // name |
|
852 | + if ( ! empty( $args['name'] ) ) { |
|
853 | + $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
854 | + } |
|
855 | + |
|
856 | + // id |
|
857 | + if ( ! empty( $args['id'] ) ) { |
|
858 | + $output .= AUI_Component_Helper::id( $args['id'] ); |
|
859 | + } |
|
860 | + |
|
861 | + // title |
|
862 | + if ( ! empty( $args['title'] ) ) { |
|
863 | + $output .= AUI_Component_Helper::title( $args['title'] ); |
|
864 | + } |
|
865 | + |
|
866 | + // data-attributes |
|
867 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
868 | + |
|
869 | + // aria-attributes |
|
870 | + $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
871 | + |
|
872 | + // extra attributes |
|
873 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
874 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
875 | + } |
|
876 | + |
|
877 | + // required |
|
878 | + if ( ! empty( $args['required'] ) ) { |
|
879 | + $output .= ' required '; |
|
880 | + } |
|
881 | + |
|
882 | + // multiple |
|
883 | + if ( ! empty( $args['multiple'] ) ) { |
|
884 | + $output .= ' multiple '; |
|
885 | + } |
|
886 | + |
|
887 | + // close opening tag |
|
888 | + $output .= ' >'; |
|
889 | + |
|
890 | + // placeholder |
|
891 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
892 | + $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
893 | + } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
894 | + $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
895 | + } |
|
896 | + |
|
897 | + // Options |
|
898 | + if ( ! empty( $args['options'] ) ) { |
|
899 | + |
|
900 | + if ( ! is_array( $args['options'] ) ) { |
|
901 | + $output .= $args['options']; // not the preferred way but an option |
|
902 | + } else { |
|
903 | + foreach ( $args['options'] as $val => $name ) { |
|
904 | + $selected = ''; |
|
905 | + if ( is_array( $name ) ) { |
|
906 | + if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
907 | + $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
908 | + |
|
909 | + $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
910 | + } else { |
|
911 | + $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
912 | + $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
913 | + $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
914 | + if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
915 | + $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
916 | + } elseif ( ! empty( $args['value'] ) ) { |
|
917 | + $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
918 | + } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) { |
|
919 | + $selected = selected( $option_value, $args['value'], false ); |
|
920 | + } |
|
921 | + |
|
922 | + $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
923 | + } |
|
924 | + } else { |
|
925 | + if ( ! empty( $args['value'] ) ) { |
|
926 | + if ( is_array( $args['value'] ) ) { |
|
927 | + $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
928 | + } elseif ( ! empty( $args['value'] ) ) { |
|
929 | + $selected = selected( $args['value'], $val, false ); |
|
930 | + } |
|
931 | + } elseif ( $args['value'] === $val ) { |
|
932 | + $selected = selected( $args['value'], $val, false ); |
|
933 | + } |
|
934 | + $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
935 | + } |
|
936 | + } |
|
937 | + } |
|
938 | + |
|
939 | + } |
|
940 | + |
|
941 | + // closing tag |
|
942 | + $output .= '</select>'; |
|
943 | + |
|
944 | + $label = ''; |
|
945 | + $help_text = ''; |
|
946 | + // label |
|
947 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
948 | + } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
949 | + $label_args = array( |
|
950 | + 'title' => $args['label'], |
|
951 | + 'for' => $args['id'], |
|
952 | + 'class' => $args['label_class'] . " ", |
|
953 | + 'label_type' => $args['label_type'], |
|
954 | + 'label_col' => $args['label_col'] |
|
955 | + ); |
|
956 | + $label = self::label( $label_args ); |
|
957 | + } |
|
958 | + |
|
959 | + // help text |
|
960 | + if ( ! empty( $args['help_text'] ) ) { |
|
961 | + $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
962 | + } |
|
963 | + |
|
964 | + // input group wraps |
|
965 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
966 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
967 | + if ( $args['input_group_left'] ) { |
|
968 | + $output = self::wrap( array( |
|
969 | + 'content' => $output, |
|
970 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
971 | + 'input_group_left' => $args['input_group_left'], |
|
972 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
973 | + ) ); |
|
974 | + } |
|
975 | + if ( $args['input_group_right'] ) { |
|
976 | + $output = self::wrap( array( |
|
977 | + 'content' => $output, |
|
978 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
979 | + 'input_group_right' => $args['input_group_right'], |
|
980 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
981 | + ) ); |
|
982 | + } |
|
983 | + |
|
984 | + } |
|
985 | + |
|
986 | + if ( ! $label_after ) { |
|
987 | + $output .= $help_text; |
|
988 | + } |
|
989 | + |
|
990 | + |
|
991 | + if ( $args['label_type'] == 'horizontal' ) { |
|
992 | + $output = self::wrap( array( |
|
993 | + 'content' => $output, |
|
994 | + 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
995 | + ) ); |
|
996 | + } |
|
997 | + |
|
998 | + if ( ! $label_after ) { |
|
999 | + $output = $label . $output; |
|
1000 | + } |
|
1001 | + |
|
1002 | + // maybe horizontal label |
|
1003 | 1003 | // if ( $args['label_type'] == 'horizontal' ) { |
1004 | 1004 | // $output .= '</div>'; |
1005 | 1005 | // } |
1006 | 1006 | |
1007 | 1007 | |
1008 | - // wrap |
|
1009 | - if ( ! $args['no_wrap'] ) { |
|
1010 | - $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
1011 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1012 | - $output = self::wrap( array( |
|
1013 | - 'content' => $output, |
|
1014 | - 'class' => $wrap_class, |
|
1015 | - 'element_require' => $args['element_require'], |
|
1016 | - 'argument_id' => $args['id'], |
|
1017 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
1018 | - ) ); |
|
1019 | - } |
|
1020 | - |
|
1021 | - |
|
1022 | - return $output; |
|
1023 | - } |
|
1024 | - |
|
1025 | - /** |
|
1026 | - * Build the component. |
|
1027 | - * |
|
1028 | - * @param array $args |
|
1029 | - * |
|
1030 | - * @return string The rendered component. |
|
1031 | - */ |
|
1032 | - public static function radio( $args = array() ) { |
|
1033 | - $defaults = array( |
|
1034 | - 'class' => '', |
|
1035 | - 'wrap_class' => '', |
|
1036 | - 'id' => '', |
|
1037 | - 'title' => '', |
|
1038 | - 'horizontal' => false, |
|
1039 | - // sets the lable horizontal |
|
1040 | - 'value' => '', |
|
1041 | - 'label' => '', |
|
1042 | - 'label_class' => '', |
|
1043 | - 'label_type' => '', |
|
1044 | - 'label_col' => '', |
|
1045 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
1046 | - 'help_text' => '', |
|
1047 | - 'inline' => true, |
|
1048 | - 'required' => false, |
|
1049 | - 'options' => array(), |
|
1050 | - 'icon' => '', |
|
1051 | - 'no_wrap' => false, |
|
1052 | - 'element_require' => '', |
|
1053 | - // [%element_id%] == "1" |
|
1054 | - 'extra_attributes' => array(), |
|
1055 | - // an array of extra attributes |
|
1056 | - 'wrap_attributes' => array() |
|
1057 | - ); |
|
1058 | - |
|
1059 | - /** |
|
1060 | - * Parse incoming $args into an array and merge it with $defaults |
|
1061 | - */ |
|
1062 | - $args = wp_parse_args( $args, $defaults ); |
|
1063 | - |
|
1064 | - // for now lets use horizontal for floating |
|
1065 | - if ( $args['label_type'] == 'floating' ) { |
|
1066 | - $args['label_type'] = 'horizontal'; |
|
1067 | - } |
|
1068 | - |
|
1069 | - $label_args = array( |
|
1070 | - 'title' => $args['label'], |
|
1071 | - 'class' => $args['label_class'] . " pt-0 ", |
|
1072 | - 'label_type' => $args['label_type'], |
|
1073 | - 'label_col' => $args['label_col'] |
|
1074 | - ); |
|
1075 | - |
|
1076 | - $output = ''; |
|
1077 | - |
|
1078 | - |
|
1079 | - // label before |
|
1080 | - if ( ! empty( $args['label'] ) ) { |
|
1081 | - $output .= self::label( $label_args, 'radio' ); |
|
1082 | - } |
|
1083 | - |
|
1084 | - // maybe horizontal label |
|
1085 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1086 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
1087 | - $output .= '<div class="' . $input_col . '">'; |
|
1088 | - } |
|
1089 | - |
|
1090 | - if ( ! empty( $args['options'] ) ) { |
|
1091 | - $count = 0; |
|
1092 | - foreach ( $args['options'] as $value => $label ) { |
|
1093 | - $option_args = $args; |
|
1094 | - $option_args['value'] = $value; |
|
1095 | - $option_args['label'] = $label; |
|
1096 | - $option_args['checked'] = $value == $args['value'] ? true : false; |
|
1097 | - $output .= self::radio_option( $option_args, $count ); |
|
1098 | - $count ++; |
|
1099 | - } |
|
1100 | - } |
|
1101 | - |
|
1102 | - // help text |
|
1103 | - $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
1104 | - $output .= $help_text; |
|
1105 | - |
|
1106 | - // maybe horizontal label |
|
1107 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1108 | - $output .= '</div>'; |
|
1109 | - } |
|
1110 | - |
|
1111 | - // wrap |
|
1112 | - $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
1113 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1114 | - $output = self::wrap( array( |
|
1115 | - 'content' => $output, |
|
1116 | - 'class' => $wrap_class, |
|
1117 | - 'element_require' => $args['element_require'], |
|
1118 | - 'argument_id' => $args['id'], |
|
1119 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
1120 | - ) ); |
|
1121 | - |
|
1122 | - |
|
1123 | - return $output; |
|
1124 | - } |
|
1125 | - |
|
1126 | - /** |
|
1127 | - * Build the component. |
|
1128 | - * |
|
1129 | - * @param array $args |
|
1130 | - * |
|
1131 | - * @return string The rendered component. |
|
1132 | - */ |
|
1133 | - public static function radio_option( $args = array(), $count = '' ) { |
|
1134 | - $defaults = array( |
|
1135 | - 'class' => '', |
|
1136 | - 'id' => '', |
|
1137 | - 'title' => '', |
|
1138 | - 'value' => '', |
|
1139 | - 'required' => false, |
|
1140 | - 'inline' => true, |
|
1141 | - 'label' => '', |
|
1142 | - 'options' => array(), |
|
1143 | - 'icon' => '', |
|
1144 | - 'no_wrap' => false, |
|
1145 | - 'extra_attributes' => array() // an array of extra attributes |
|
1146 | - ); |
|
1147 | - |
|
1148 | - /** |
|
1149 | - * Parse incoming $args into an array and merge it with $defaults |
|
1150 | - */ |
|
1151 | - $args = wp_parse_args( $args, $defaults ); |
|
1152 | - |
|
1153 | - $output = ''; |
|
1154 | - |
|
1155 | - // open/type |
|
1156 | - $output .= '<input type="radio"'; |
|
1157 | - |
|
1158 | - // class |
|
1159 | - $output .= ' class="form-check-input" '; |
|
1160 | - |
|
1161 | - // name |
|
1162 | - if ( ! empty( $args['name'] ) ) { |
|
1163 | - $output .= AUI_Component_Helper::name( $args['name'] ); |
|
1164 | - } |
|
1165 | - |
|
1166 | - // id |
|
1167 | - if ( ! empty( $args['id'] ) ) { |
|
1168 | - $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
1169 | - } |
|
1170 | - |
|
1171 | - // title |
|
1172 | - if ( ! empty( $args['title'] ) ) { |
|
1173 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
1174 | - } |
|
1175 | - |
|
1176 | - // value |
|
1177 | - if ( isset( $args['value'] ) ) { |
|
1178 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
1179 | - } |
|
1180 | - |
|
1181 | - // checked, for radio and checkboxes |
|
1182 | - if ( $args['checked'] ) { |
|
1183 | - $output .= ' checked '; |
|
1184 | - } |
|
1185 | - |
|
1186 | - // data-attributes |
|
1187 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
1188 | - |
|
1189 | - // aria-attributes |
|
1190 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
1191 | - |
|
1192 | - // extra attributes |
|
1193 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
1194 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
1195 | - } |
|
1196 | - |
|
1197 | - // required |
|
1198 | - if ( ! empty( $args['required'] ) ) { |
|
1199 | - $output .= ' required '; |
|
1200 | - } |
|
1201 | - |
|
1202 | - // close opening tag |
|
1203 | - $output .= ' >'; |
|
1204 | - |
|
1205 | - // label |
|
1206 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1207 | - } elseif ( ! empty( $args['label'] ) ) { |
|
1208 | - $output .= self::label( array( |
|
1209 | - 'title' => $args['label'], |
|
1210 | - 'for' => $args['id'] . $count, |
|
1211 | - 'class' => 'form-check-label' |
|
1212 | - ), 'radio' ); |
|
1213 | - } |
|
1214 | - |
|
1215 | - // wrap |
|
1216 | - if ( ! $args['no_wrap'] ) { |
|
1217 | - $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1218 | - |
|
1219 | - // Unique wrap class |
|
1220 | - $uniq_class = 'fwrap'; |
|
1221 | - if ( ! empty( $args['name'] ) ) { |
|
1222 | - $uniq_class .= '-' . $args['name']; |
|
1223 | - } else if ( ! empty( $args['id'] ) ) { |
|
1224 | - $uniq_class .= '-' . $args['id']; |
|
1225 | - } |
|
1226 | - |
|
1227 | - if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
1228 | - $uniq_class .= '-' . $args['value']; |
|
1229 | - } else { |
|
1230 | - $uniq_class .= '-' . $count; |
|
1231 | - } |
|
1232 | - $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
1233 | - |
|
1234 | - $output = self::wrap( array( |
|
1235 | - 'content' => $output, |
|
1236 | - 'class' => $wrap_class |
|
1237 | - ) ); |
|
1238 | - } |
|
1239 | - |
|
1240 | - return $output; |
|
1241 | - } |
|
1008 | + // wrap |
|
1009 | + if ( ! $args['no_wrap'] ) { |
|
1010 | + $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
1011 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1012 | + $output = self::wrap( array( |
|
1013 | + 'content' => $output, |
|
1014 | + 'class' => $wrap_class, |
|
1015 | + 'element_require' => $args['element_require'], |
|
1016 | + 'argument_id' => $args['id'], |
|
1017 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
1018 | + ) ); |
|
1019 | + } |
|
1020 | + |
|
1021 | + |
|
1022 | + return $output; |
|
1023 | + } |
|
1024 | + |
|
1025 | + /** |
|
1026 | + * Build the component. |
|
1027 | + * |
|
1028 | + * @param array $args |
|
1029 | + * |
|
1030 | + * @return string The rendered component. |
|
1031 | + */ |
|
1032 | + public static function radio( $args = array() ) { |
|
1033 | + $defaults = array( |
|
1034 | + 'class' => '', |
|
1035 | + 'wrap_class' => '', |
|
1036 | + 'id' => '', |
|
1037 | + 'title' => '', |
|
1038 | + 'horizontal' => false, |
|
1039 | + // sets the lable horizontal |
|
1040 | + 'value' => '', |
|
1041 | + 'label' => '', |
|
1042 | + 'label_class' => '', |
|
1043 | + 'label_type' => '', |
|
1044 | + 'label_col' => '', |
|
1045 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
1046 | + 'help_text' => '', |
|
1047 | + 'inline' => true, |
|
1048 | + 'required' => false, |
|
1049 | + 'options' => array(), |
|
1050 | + 'icon' => '', |
|
1051 | + 'no_wrap' => false, |
|
1052 | + 'element_require' => '', |
|
1053 | + // [%element_id%] == "1" |
|
1054 | + 'extra_attributes' => array(), |
|
1055 | + // an array of extra attributes |
|
1056 | + 'wrap_attributes' => array() |
|
1057 | + ); |
|
1058 | + |
|
1059 | + /** |
|
1060 | + * Parse incoming $args into an array and merge it with $defaults |
|
1061 | + */ |
|
1062 | + $args = wp_parse_args( $args, $defaults ); |
|
1063 | + |
|
1064 | + // for now lets use horizontal for floating |
|
1065 | + if ( $args['label_type'] == 'floating' ) { |
|
1066 | + $args['label_type'] = 'horizontal'; |
|
1067 | + } |
|
1068 | + |
|
1069 | + $label_args = array( |
|
1070 | + 'title' => $args['label'], |
|
1071 | + 'class' => $args['label_class'] . " pt-0 ", |
|
1072 | + 'label_type' => $args['label_type'], |
|
1073 | + 'label_col' => $args['label_col'] |
|
1074 | + ); |
|
1075 | + |
|
1076 | + $output = ''; |
|
1077 | + |
|
1078 | + |
|
1079 | + // label before |
|
1080 | + if ( ! empty( $args['label'] ) ) { |
|
1081 | + $output .= self::label( $label_args, 'radio' ); |
|
1082 | + } |
|
1083 | + |
|
1084 | + // maybe horizontal label |
|
1085 | + if ( $args['label_type'] == 'horizontal' ) { |
|
1086 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
1087 | + $output .= '<div class="' . $input_col . '">'; |
|
1088 | + } |
|
1089 | + |
|
1090 | + if ( ! empty( $args['options'] ) ) { |
|
1091 | + $count = 0; |
|
1092 | + foreach ( $args['options'] as $value => $label ) { |
|
1093 | + $option_args = $args; |
|
1094 | + $option_args['value'] = $value; |
|
1095 | + $option_args['label'] = $label; |
|
1096 | + $option_args['checked'] = $value == $args['value'] ? true : false; |
|
1097 | + $output .= self::radio_option( $option_args, $count ); |
|
1098 | + $count ++; |
|
1099 | + } |
|
1100 | + } |
|
1101 | + |
|
1102 | + // help text |
|
1103 | + $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
1104 | + $output .= $help_text; |
|
1105 | + |
|
1106 | + // maybe horizontal label |
|
1107 | + if ( $args['label_type'] == 'horizontal' ) { |
|
1108 | + $output .= '</div>'; |
|
1109 | + } |
|
1110 | + |
|
1111 | + // wrap |
|
1112 | + $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
1113 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1114 | + $output = self::wrap( array( |
|
1115 | + 'content' => $output, |
|
1116 | + 'class' => $wrap_class, |
|
1117 | + 'element_require' => $args['element_require'], |
|
1118 | + 'argument_id' => $args['id'], |
|
1119 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
1120 | + ) ); |
|
1121 | + |
|
1122 | + |
|
1123 | + return $output; |
|
1124 | + } |
|
1125 | + |
|
1126 | + /** |
|
1127 | + * Build the component. |
|
1128 | + * |
|
1129 | + * @param array $args |
|
1130 | + * |
|
1131 | + * @return string The rendered component. |
|
1132 | + */ |
|
1133 | + public static function radio_option( $args = array(), $count = '' ) { |
|
1134 | + $defaults = array( |
|
1135 | + 'class' => '', |
|
1136 | + 'id' => '', |
|
1137 | + 'title' => '', |
|
1138 | + 'value' => '', |
|
1139 | + 'required' => false, |
|
1140 | + 'inline' => true, |
|
1141 | + 'label' => '', |
|
1142 | + 'options' => array(), |
|
1143 | + 'icon' => '', |
|
1144 | + 'no_wrap' => false, |
|
1145 | + 'extra_attributes' => array() // an array of extra attributes |
|
1146 | + ); |
|
1147 | + |
|
1148 | + /** |
|
1149 | + * Parse incoming $args into an array and merge it with $defaults |
|
1150 | + */ |
|
1151 | + $args = wp_parse_args( $args, $defaults ); |
|
1152 | + |
|
1153 | + $output = ''; |
|
1154 | + |
|
1155 | + // open/type |
|
1156 | + $output .= '<input type="radio"'; |
|
1157 | + |
|
1158 | + // class |
|
1159 | + $output .= ' class="form-check-input" '; |
|
1160 | + |
|
1161 | + // name |
|
1162 | + if ( ! empty( $args['name'] ) ) { |
|
1163 | + $output .= AUI_Component_Helper::name( $args['name'] ); |
|
1164 | + } |
|
1165 | + |
|
1166 | + // id |
|
1167 | + if ( ! empty( $args['id'] ) ) { |
|
1168 | + $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
1169 | + } |
|
1170 | + |
|
1171 | + // title |
|
1172 | + if ( ! empty( $args['title'] ) ) { |
|
1173 | + $output .= AUI_Component_Helper::title( $args['title'] ); |
|
1174 | + } |
|
1175 | + |
|
1176 | + // value |
|
1177 | + if ( isset( $args['value'] ) ) { |
|
1178 | + $output .= AUI_Component_Helper::value( $args['value'] ); |
|
1179 | + } |
|
1180 | + |
|
1181 | + // checked, for radio and checkboxes |
|
1182 | + if ( $args['checked'] ) { |
|
1183 | + $output .= ' checked '; |
|
1184 | + } |
|
1185 | + |
|
1186 | + // data-attributes |
|
1187 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
1188 | + |
|
1189 | + // aria-attributes |
|
1190 | + $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
1191 | + |
|
1192 | + // extra attributes |
|
1193 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
1194 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
1195 | + } |
|
1196 | + |
|
1197 | + // required |
|
1198 | + if ( ! empty( $args['required'] ) ) { |
|
1199 | + $output .= ' required '; |
|
1200 | + } |
|
1201 | + |
|
1202 | + // close opening tag |
|
1203 | + $output .= ' >'; |
|
1204 | + |
|
1205 | + // label |
|
1206 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1207 | + } elseif ( ! empty( $args['label'] ) ) { |
|
1208 | + $output .= self::label( array( |
|
1209 | + 'title' => $args['label'], |
|
1210 | + 'for' => $args['id'] . $count, |
|
1211 | + 'class' => 'form-check-label' |
|
1212 | + ), 'radio' ); |
|
1213 | + } |
|
1214 | + |
|
1215 | + // wrap |
|
1216 | + if ( ! $args['no_wrap'] ) { |
|
1217 | + $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1218 | + |
|
1219 | + // Unique wrap class |
|
1220 | + $uniq_class = 'fwrap'; |
|
1221 | + if ( ! empty( $args['name'] ) ) { |
|
1222 | + $uniq_class .= '-' . $args['name']; |
|
1223 | + } else if ( ! empty( $args['id'] ) ) { |
|
1224 | + $uniq_class .= '-' . $args['id']; |
|
1225 | + } |
|
1226 | + |
|
1227 | + if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
1228 | + $uniq_class .= '-' . $args['value']; |
|
1229 | + } else { |
|
1230 | + $uniq_class .= '-' . $count; |
|
1231 | + } |
|
1232 | + $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
1233 | + |
|
1234 | + $output = self::wrap( array( |
|
1235 | + 'content' => $output, |
|
1236 | + 'class' => $wrap_class |
|
1237 | + ) ); |
|
1238 | + } |
|
1239 | + |
|
1240 | + return $output; |
|
1241 | + } |
|
1242 | 1242 | |
1243 | 1243 | } |
1244 | 1244 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
3 | +if (!defined('ABSPATH')) { |
|
4 | 4 | exit; // Exit if accessed directly |
5 | 5 | } |
6 | 6 | |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @return string The rendered component. |
20 | 20 | */ |
21 | - public static function input( $args = array() ) { |
|
21 | + public static function input($args = array()) { |
|
22 | 22 | $defaults = array( |
23 | 23 | 'type' => 'text', |
24 | 24 | 'name' => '', |
@@ -65,13 +65,13 @@ discard block |
||
65 | 65 | /** |
66 | 66 | * Parse incoming $args into an array and merge it with $defaults |
67 | 67 | */ |
68 | - $args = wp_parse_args( $args, $defaults ); |
|
68 | + $args = wp_parse_args($args, $defaults); |
|
69 | 69 | $output = ''; |
70 | - if ( ! empty( $args['type'] ) ) { |
|
70 | + if (!empty($args['type'])) { |
|
71 | 71 | // hidden label option needs to be empty |
72 | 72 | $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
73 | 73 | |
74 | - $type = sanitize_html_class( $args['type'] ); |
|
74 | + $type = sanitize_html_class($args['type']); |
|
75 | 75 | |
76 | 76 | $help_text = ''; |
77 | 77 | $label = ''; |
@@ -85,17 +85,17 @@ discard block |
||
85 | 85 | ); |
86 | 86 | |
87 | 87 | // floating labels need label after |
88 | - if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
88 | + if ($args['label_type'] == 'floating' && $type != 'checkbox') { |
|
89 | 89 | $label_after = true; |
90 | 90 | $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
91 | 91 | } |
92 | 92 | |
93 | 93 | // size |
94 | 94 | $size = ''; |
95 | - if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
|
95 | + if ($args['size'] == 'lg' || $args['size'] == 'large') { |
|
96 | 96 | $size = 'lg'; |
97 | 97 | $args['class'] .= ' form-control-lg'; |
98 | - }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
98 | + }elseif ($args['size'] == 'sm' || $args['size'] == 'small') { |
|
99 | 99 | $size = 'sm'; |
100 | 100 | $args['class'] .= ' form-control-sm'; |
101 | 101 | } |
@@ -104,21 +104,21 @@ discard block |
||
104 | 104 | $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');'; |
105 | 105 | |
106 | 106 | // Some special sauce for files |
107 | - if ( $type == 'file' ) { |
|
107 | + if ($type == 'file') { |
|
108 | 108 | $label_after = true; // if type file we need the label after |
109 | 109 | $args['class'] .= ' custom-file-input '; |
110 | - } elseif ( $type == 'checkbox' ) { |
|
110 | + } elseif ($type == 'checkbox') { |
|
111 | 111 | $label_after = true; // if type file we need the label after |
112 | 112 | $args['class'] .= ' custom-control-input '; |
113 | - } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
113 | + } elseif ($type == 'datepicker' || $type == 'timepicker') { |
|
114 | 114 | $type = 'text'; |
115 | 115 | $args['class'] .= ' bg-initial '; // @todo not sure why we have this? |
116 | - $clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');"; |
|
116 | + $clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr($args['name']) . "\']').trigger('change');"; |
|
117 | 117 | |
118 | 118 | $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
119 | 119 | |
120 | 120 | // set a way to clear field if empty |
121 | - if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) { |
|
121 | + if ($args['input_group_right'] === '' && $args['clear_icon'] !== false) { |
|
122 | 122 | $args['input_group_right_inside'] = true; |
123 | 123 | $args['clear_icon'] = true; |
124 | 124 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | // enqueue the script |
127 | 127 | $aui_settings = AyeCode_UI_Settings::instance(); |
128 | 128 | $aui_settings->enqueue_flatpickr(); |
129 | - } elseif ( $type == 'iconpicker' ) { |
|
129 | + } elseif ($type == 'iconpicker') { |
|
130 | 130 | $type = 'text'; |
131 | 131 | //$args['class'] .= ' aui-flatpickr bg-initial '; |
132 | 132 | // $args['class'] .= ' bg-initial '; |
@@ -141,103 +141,103 @@ discard block |
||
141 | 141 | $aui_settings->enqueue_iconpicker(); |
142 | 142 | } |
143 | 143 | |
144 | - if ( $type == 'checkbox' && !empty($args['name'] ) && strpos($args['name'], '[') === false ) { |
|
145 | - $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
144 | + if ($type == 'checkbox' && !empty($args['name']) && strpos($args['name'], '[') === false) { |
|
145 | + $output .= '<input type="hidden" name="' . esc_attr($args['name']) . '" value="0" />'; |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | // allow clear icon |
149 | - if ( $args['input_group_right'] === '' && $args['clear_icon'] ) { |
|
150 | - $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' ); |
|
149 | + if ($args['input_group_right'] === '' && $args['clear_icon']) { |
|
150 | + $font_size = $size == 'sm' ? '1.3' : ($size == 'lg' ? '1.65' : '1.5'); |
|
151 | 151 | $args['input_group_right_inside'] = true; |
152 | - $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none" onclick="' . $clear_function . '"><span style="font-size: '.$font_size.'rem" aria-hidden="true" class="close">×</span></span>'; |
|
152 | + $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none" onclick="' . $clear_function . '"><span style="font-size: ' . $font_size . 'rem" aria-hidden="true" class="close">×</span></span>'; |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | // open/type |
156 | 156 | $output .= '<input type="' . $type . '" '; |
157 | 157 | |
158 | 158 | // name |
159 | - if ( ! empty( $args['name'] ) ) { |
|
160 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
159 | + if (!empty($args['name'])) { |
|
160 | + $output .= ' name="' . esc_attr($args['name']) . '" '; |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | // id |
164 | - if ( ! empty( $args['id'] ) ) { |
|
165 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
164 | + if (!empty($args['id'])) { |
|
165 | + $output .= ' id="' . sanitize_html_class($args['id']) . '" '; |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | // placeholder |
169 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
170 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
169 | + if (isset($args['placeholder']) && '' != $args['placeholder']) { |
|
170 | + $output .= ' placeholder="' . esc_attr($args['placeholder']) . '" '; |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | // title |
174 | - if ( ! empty( $args['title'] ) ) { |
|
175 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
174 | + if (!empty($args['title'])) { |
|
175 | + $output .= ' title="' . esc_attr($args['title']) . '" '; |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | // value |
179 | - if ( ! empty( $args['value'] ) ) { |
|
180 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
179 | + if (!empty($args['value'])) { |
|
180 | + $output .= AUI_Component_Helper::value($args['value']); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | // checked, for radio and checkboxes |
184 | - if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
184 | + if (($type == 'checkbox' || $type == 'radio') && $args['checked']) { |
|
185 | 185 | $output .= ' checked '; |
186 | 186 | } |
187 | 187 | |
188 | 188 | // validation text |
189 | - if ( ! empty( $args['validation_text'] ) ) { |
|
190 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
189 | + if (!empty($args['validation_text'])) { |
|
190 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr($args['validation_text']) . '\')" '; |
|
191 | 191 | $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
192 | 192 | } |
193 | 193 | |
194 | 194 | // validation_pattern |
195 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
196 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
195 | + if (!empty($args['validation_pattern'])) { |
|
196 | + $output .= ' pattern="' . esc_attr($args['validation_pattern']) . '" '; |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | // step (for numbers) |
200 | - if ( ! empty( $args['step'] ) ) { |
|
200 | + if (!empty($args['step'])) { |
|
201 | 201 | $output .= ' step="' . $args['step'] . '" '; |
202 | 202 | } |
203 | 203 | |
204 | 204 | // required |
205 | - if ( ! empty( $args['required'] ) ) { |
|
205 | + if (!empty($args['required'])) { |
|
206 | 206 | $output .= ' required '; |
207 | 207 | } |
208 | 208 | |
209 | 209 | // class |
210 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
210 | + $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes($args['class']) : ''; |
|
211 | 211 | $output .= ' class="form-control ' . $class . '" '; |
212 | 212 | |
213 | 213 | // data-attributes |
214 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
214 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
215 | 215 | |
216 | 216 | // extra attributes |
217 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
218 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
217 | + if (!empty($args['extra_attributes'])) { |
|
218 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | // close |
222 | 222 | $output .= ' >'; |
223 | 223 | |
224 | 224 | // help text |
225 | - if ( ! empty( $args['help_text'] ) ) { |
|
226 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
225 | + if (!empty($args['help_text'])) { |
|
226 | + $help_text = AUI_Component_Helper::help_text($args['help_text']); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | // label |
230 | - if ( ! empty( $args['label'] ) ) { |
|
230 | + if (!empty($args['label'])) { |
|
231 | 231 | $label_base_class = ''; |
232 | - if ( $type == 'file' ) { |
|
232 | + if ($type == 'file') { |
|
233 | 233 | $label_base_class = ' custom-file-label'; |
234 | - } elseif ( $type == 'checkbox' ) { |
|
235 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
236 | - $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
234 | + } elseif ($type == 'checkbox') { |
|
235 | + if (!empty($args['label_force_left'])) { |
|
236 | + $label_args['title'] = wp_kses_post($args['help_text']); |
|
237 | 237 | $help_text = ''; |
238 | 238 | //$label_args['class'] .= ' d-inline '; |
239 | 239 | $args['wrap_class'] .= ' align-items-center '; |
240 | - }else{ |
|
240 | + } else { |
|
241 | 241 | |
242 | 242 | } |
243 | 243 | |
@@ -245,45 +245,45 @@ discard block |
||
245 | 245 | } |
246 | 246 | $label_args['class'] .= $label_base_class; |
247 | 247 | $temp_label_args = $label_args; |
248 | - if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
249 | - $label = self::label( $temp_label_args, $type ); |
|
248 | + if (!empty($args['label_force_left'])) {$temp_label_args['class'] = $label_base_class . " text-muted"; } |
|
249 | + $label = self::label($temp_label_args, $type); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | |
253 | 253 | |
254 | 254 | |
255 | 255 | // set help text in the correct position |
256 | - if ( $label_after ) { |
|
256 | + if ($label_after) { |
|
257 | 257 | $output .= $label . $help_text; |
258 | 258 | } |
259 | 259 | |
260 | 260 | // some input types need a separate wrap |
261 | - if ( $type == 'file' ) { |
|
262 | - $output = self::wrap( array( |
|
261 | + if ($type == 'file') { |
|
262 | + $output = self::wrap(array( |
|
263 | 263 | 'content' => $output, |
264 | 264 | 'class' => 'form-group custom-file' |
265 | - ) ); |
|
266 | - } elseif ( $type == 'checkbox' ) { |
|
265 | + )); |
|
266 | + } elseif ($type == 'checkbox') { |
|
267 | 267 | |
268 | 268 | $label_args['title'] = $args['label']; |
269 | - $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
270 | - $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
271 | - $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
272 | - $wrap_class = $args['switch'] ? 'custom-switch'.$switch_size_class : 'custom-checkbox'; |
|
273 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
269 | + $label_col = AUI_Component_Helper::get_column_class($args['label_col'], 'label'); |
|
270 | + $label = !empty($args['label_force_left']) ? self::label($label_args, 'cb') : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
271 | + $switch_size_class = $args['switch'] && !is_bool($args['switch']) ? ' custom-switch-' . esc_attr($args['switch']) : ''; |
|
272 | + $wrap_class = $args['switch'] ? 'custom-switch' . $switch_size_class : 'custom-checkbox'; |
|
273 | + if (!empty($args['label_force_left'])) { |
|
274 | 274 | $wrap_class .= ' d-flex align-content-center'; |
275 | - $label = str_replace("custom-control-label","", self::label( $label_args, 'cb' ) ); |
|
275 | + $label = str_replace("custom-control-label", "", self::label($label_args, 'cb')); |
|
276 | 276 | } |
277 | - $output = self::wrap( array( |
|
277 | + $output = self::wrap(array( |
|
278 | 278 | 'content' => $output, |
279 | 279 | 'class' => 'custom-control ' . $wrap_class |
280 | - ) ); |
|
280 | + )); |
|
281 | 281 | |
282 | - if ( $args['label_type'] == 'horizontal' ) { |
|
283 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
282 | + if ($args['label_type'] == 'horizontal') { |
|
283 | + $input_col = AUI_Component_Helper::get_column_class($args['label_col'], 'input'); |
|
284 | 284 | $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
285 | 285 | } |
286 | - } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
286 | + } elseif ($type == 'password' && $args['password_toggle'] && !$args['input_group_right']) { |
|
287 | 287 | |
288 | 288 | |
289 | 289 | // allow password field to toggle view |
@@ -297,65 +297,65 @@ discard block |
||
297 | 297 | } |
298 | 298 | |
299 | 299 | // input group wraps |
300 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
301 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
300 | + if ($args['input_group_left'] || $args['input_group_right']) { |
|
301 | + $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : ''; |
|
302 | 302 | $group_size = $size == 'lg' ? ' input-group-lg' : ''; |
303 | 303 | $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size; |
304 | 304 | |
305 | - if ( $args['input_group_left'] ) { |
|
306 | - $output = self::wrap( array( |
|
305 | + if ($args['input_group_left']) { |
|
306 | + $output = self::wrap(array( |
|
307 | 307 | 'content' => $output, |
308 | 308 | 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
309 | 309 | 'input_group_left' => $args['input_group_left'], |
310 | 310 | 'input_group_left_inside' => $args['input_group_left_inside'] |
311 | - ) ); |
|
311 | + )); |
|
312 | 312 | } |
313 | - if ( $args['input_group_right'] ) { |
|
314 | - $output = self::wrap( array( |
|
313 | + if ($args['input_group_right']) { |
|
314 | + $output = self::wrap(array( |
|
315 | 315 | 'content' => $output, |
316 | 316 | 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
317 | 317 | 'input_group_right' => $args['input_group_right'], |
318 | 318 | 'input_group_right_inside' => $args['input_group_right_inside'] |
319 | - ) ); |
|
319 | + )); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | } |
323 | 323 | |
324 | - if ( ! $label_after ) { |
|
324 | + if (!$label_after) { |
|
325 | 325 | $output .= $help_text; |
326 | 326 | } |
327 | 327 | |
328 | 328 | |
329 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
330 | - $output = self::wrap( array( |
|
329 | + if ($args['label_type'] == 'horizontal' && $type != 'checkbox') { |
|
330 | + $output = self::wrap(array( |
|
331 | 331 | 'content' => $output, |
332 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
333 | - ) ); |
|
332 | + 'class' => AUI_Component_Helper::get_column_class($args['label_col'], 'input') |
|
333 | + )); |
|
334 | 334 | } |
335 | 335 | |
336 | - if ( ! $label_after ) { |
|
336 | + if (!$label_after) { |
|
337 | 337 | $output = $label . $output; |
338 | 338 | } |
339 | 339 | |
340 | 340 | // wrap |
341 | - if ( ! $args['no_wrap'] ) { |
|
341 | + if (!$args['no_wrap']) { |
|
342 | 342 | $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
343 | 343 | $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
344 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
345 | - $output = self::wrap( array( |
|
344 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
345 | + $output = self::wrap(array( |
|
346 | 346 | 'content' => $output, |
347 | 347 | 'class' => $wrap_class, |
348 | 348 | 'element_require' => $args['element_require'], |
349 | 349 | 'argument_id' => $args['id'], |
350 | 350 | 'wrap_attributes' => $args['wrap_attributes'], |
351 | - ) ); |
|
351 | + )); |
|
352 | 352 | } |
353 | 353 | } |
354 | 354 | |
355 | 355 | return $output; |
356 | 356 | } |
357 | 357 | |
358 | - public static function label( $args = array(), $type = '' ) { |
|
358 | + public static function label($args = array(), $type = '') { |
|
359 | 359 | //<label for="exampleInputEmail1">Email address</label> |
360 | 360 | $defaults = array( |
361 | 361 | 'title' => 'div', |
@@ -368,33 +368,33 @@ discard block |
||
368 | 368 | /** |
369 | 369 | * Parse incoming $args into an array and merge it with $defaults |
370 | 370 | */ |
371 | - $args = wp_parse_args( $args, $defaults ); |
|
371 | + $args = wp_parse_args($args, $defaults); |
|
372 | 372 | $output = ''; |
373 | 373 | |
374 | - if ( $args['title'] ) { |
|
374 | + if ($args['title']) { |
|
375 | 375 | |
376 | 376 | // maybe hide labels //@todo set a global option for visibility class |
377 | - if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
377 | + if ($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type'])) { |
|
378 | 378 | $class = $args['class']; |
379 | 379 | } else { |
380 | 380 | $class = 'sr-only ' . $args['class']; |
381 | 381 | } |
382 | 382 | |
383 | 383 | // maybe horizontal |
384 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
385 | - $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label'; |
|
384 | + if ($args['label_type'] == 'horizontal' && $type != 'checkbox') { |
|
385 | + $class .= ' ' . AUI_Component_Helper::get_column_class($args['label_col'], 'label') . ' col-form-label'; |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | // open |
389 | 389 | $output .= '<label '; |
390 | 390 | |
391 | 391 | // for |
392 | - if ( ! empty( $args['for'] ) ) { |
|
393 | - $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
392 | + if (!empty($args['for'])) { |
|
393 | + $output .= ' for="' . esc_attr($args['for']) . '" '; |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | // class |
397 | - $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
397 | + $class = $class ? AUI_Component_Helper::esc_classes($class) : ''; |
|
398 | 398 | $output .= ' class="' . $class . '" '; |
399 | 399 | |
400 | 400 | // close |
@@ -402,8 +402,8 @@ discard block |
||
402 | 402 | |
403 | 403 | |
404 | 404 | // title, don't escape fully as can contain html |
405 | - if ( ! empty( $args['title'] ) ) { |
|
406 | - $output .= wp_kses_post( $args['title'] ); |
|
405 | + if (!empty($args['title'])) { |
|
406 | + $output .= wp_kses_post($args['title']); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | // close wrap |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | * |
424 | 424 | * @return string |
425 | 425 | */ |
426 | - public static function wrap( $args = array() ) { |
|
426 | + public static function wrap($args = array()) { |
|
427 | 427 | $defaults = array( |
428 | 428 | 'type' => 'div', |
429 | 429 | 'class' => 'form-group', |
@@ -440,31 +440,31 @@ discard block |
||
440 | 440 | /** |
441 | 441 | * Parse incoming $args into an array and merge it with $defaults |
442 | 442 | */ |
443 | - $args = wp_parse_args( $args, $defaults ); |
|
443 | + $args = wp_parse_args($args, $defaults); |
|
444 | 444 | $output = ''; |
445 | - if ( $args['type'] ) { |
|
445 | + if ($args['type']) { |
|
446 | 446 | |
447 | 447 | // open |
448 | - $output .= '<' . sanitize_html_class( $args['type'] ); |
|
448 | + $output .= '<' . sanitize_html_class($args['type']); |
|
449 | 449 | |
450 | 450 | // element require |
451 | - if ( ! empty( $args['element_require'] ) ) { |
|
452 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
451 | + if (!empty($args['element_require'])) { |
|
452 | + $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
453 | 453 | $args['class'] .= " aui-conditional-field"; |
454 | 454 | } |
455 | 455 | |
456 | 456 | // argument_id |
457 | - if ( ! empty( $args['argument_id'] ) ) { |
|
458 | - $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
457 | + if (!empty($args['argument_id'])) { |
|
458 | + $output .= ' data-argument="' . esc_attr($args['argument_id']) . '"'; |
|
459 | 459 | } |
460 | 460 | |
461 | 461 | // class |
462 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
462 | + $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes($args['class']) : ''; |
|
463 | 463 | $output .= ' class="' . $class . '" '; |
464 | 464 | |
465 | 465 | // Attributes |
466 | - if ( ! empty( $args['wrap_attributes'] ) ) { |
|
467 | - $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
466 | + if (!empty($args['wrap_attributes'])) { |
|
467 | + $output .= AUI_Component_Helper::extra_attributes($args['wrap_attributes']); |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | // close wrap |
@@ -472,9 +472,9 @@ discard block |
||
472 | 472 | |
473 | 473 | |
474 | 474 | // Input group left |
475 | - if ( ! empty( $args['input_group_left'] ) ) { |
|
476 | - $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
477 | - $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
475 | + if (!empty($args['input_group_left'])) { |
|
476 | + $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
477 | + $input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
478 | 478 | $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
479 | 479 | } |
480 | 480 | |
@@ -482,15 +482,15 @@ discard block |
||
482 | 482 | $output .= $args['content']; |
483 | 483 | |
484 | 484 | // Input group right |
485 | - if ( ! empty( $args['input_group_right'] ) ) { |
|
486 | - $position_class = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : ''; |
|
487 | - $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
485 | + if (!empty($args['input_group_right'])) { |
|
486 | + $position_class = !empty($args['input_group_right_inside']) ? 'position-absolute h-100' : ''; |
|
487 | + $input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
488 | 488 | $output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
489 | 489 | } |
490 | 490 | |
491 | 491 | |
492 | 492 | // close wrap |
493 | - $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
493 | + $output .= '</' . sanitize_html_class($args['type']) . '>'; |
|
494 | 494 | |
495 | 495 | |
496 | 496 | } else { |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | * |
508 | 508 | * @return string The rendered component. |
509 | 509 | */ |
510 | - public static function textarea( $args = array() ) { |
|
510 | + public static function textarea($args = array()) { |
|
511 | 511 | $defaults = array( |
512 | 512 | 'name' => '', |
513 | 513 | 'class' => '', |
@@ -544,28 +544,28 @@ discard block |
||
544 | 544 | /** |
545 | 545 | * Parse incoming $args into an array and merge it with $defaults |
546 | 546 | */ |
547 | - $args = wp_parse_args( $args, $defaults ); |
|
547 | + $args = wp_parse_args($args, $defaults); |
|
548 | 548 | $output = ''; |
549 | 549 | |
550 | 550 | // hidden label option needs to be empty |
551 | 551 | $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
552 | 552 | |
553 | 553 | // floating labels don't work with wysiwyg so set it as top |
554 | - if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
554 | + if ($args['label_type'] == 'floating' && !empty($args['wysiwyg'])) { |
|
555 | 555 | $args['label_type'] = 'top'; |
556 | 556 | } |
557 | 557 | |
558 | 558 | $label_after = $args['label_after']; |
559 | 559 | |
560 | 560 | // floating labels need label after |
561 | - if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
561 | + if ($args['label_type'] == 'floating' && empty($args['wysiwyg'])) { |
|
562 | 562 | $label_after = true; |
563 | 563 | $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
564 | 564 | } |
565 | 565 | |
566 | 566 | // label |
567 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
568 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
567 | + if (!empty($args['label']) && is_array($args['label'])) { |
|
568 | + } elseif (!empty($args['label']) && !$label_after) { |
|
569 | 569 | $label_args = array( |
570 | 570 | 'title' => $args['label'], |
571 | 571 | 'for' => $args['id'], |
@@ -573,34 +573,34 @@ discard block |
||
573 | 573 | 'label_type' => $args['label_type'], |
574 | 574 | 'label_col' => $args['label_col'] |
575 | 575 | ); |
576 | - $output .= self::label( $label_args ); |
|
576 | + $output .= self::label($label_args); |
|
577 | 577 | } |
578 | 578 | |
579 | 579 | // maybe horizontal label |
580 | - if ( $args['label_type'] == 'horizontal' ) { |
|
581 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
580 | + if ($args['label_type'] == 'horizontal') { |
|
581 | + $input_col = AUI_Component_Helper::get_column_class($args['label_col'], 'input'); |
|
582 | 582 | $output .= '<div class="' . $input_col . '">'; |
583 | 583 | } |
584 | 584 | |
585 | - if ( ! empty( $args['wysiwyg'] ) ) { |
|
585 | + if (!empty($args['wysiwyg'])) { |
|
586 | 586 | ob_start(); |
587 | 587 | $content = $args['value']; |
588 | - $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
588 | + $editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor'; |
|
589 | 589 | $settings = array( |
590 | - 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
590 | + 'textarea_rows' => !empty(absint($args['rows'])) ? absint($args['rows']) : 4, |
|
591 | 591 | 'quicktags' => false, |
592 | 592 | 'media_buttons' => false, |
593 | 593 | 'editor_class' => 'form-control', |
594 | - 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
594 | + 'textarea_name' => !empty($args['name']) ? sanitize_html_class($args['name']) : sanitize_html_class($args['id']), |
|
595 | 595 | 'teeny' => true, |
596 | 596 | ); |
597 | 597 | |
598 | 598 | // maybe set settings if array |
599 | - if ( is_array( $args['wysiwyg'] ) ) { |
|
600 | - $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
599 | + if (is_array($args['wysiwyg'])) { |
|
600 | + $settings = wp_parse_args($args['wysiwyg'], $settings); |
|
601 | 601 | } |
602 | 602 | |
603 | - wp_editor( $content, $editor_id, $settings ); |
|
603 | + wp_editor($content, $editor_id, $settings); |
|
604 | 604 | $output .= ob_get_clean(); |
605 | 605 | } else { |
606 | 606 | |
@@ -608,65 +608,65 @@ discard block |
||
608 | 608 | $output .= '<textarea '; |
609 | 609 | |
610 | 610 | // name |
611 | - if ( ! empty( $args['name'] ) ) { |
|
612 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
611 | + if (!empty($args['name'])) { |
|
612 | + $output .= ' name="' . esc_attr($args['name']) . '" '; |
|
613 | 613 | } |
614 | 614 | |
615 | 615 | // id |
616 | - if ( ! empty( $args['id'] ) ) { |
|
617 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
616 | + if (!empty($args['id'])) { |
|
617 | + $output .= ' id="' . sanitize_html_class($args['id']) . '" '; |
|
618 | 618 | } |
619 | 619 | |
620 | 620 | // placeholder |
621 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
622 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
621 | + if (isset($args['placeholder']) && '' != $args['placeholder']) { |
|
622 | + $output .= ' placeholder="' . esc_attr($args['placeholder']) . '" '; |
|
623 | 623 | } |
624 | 624 | |
625 | 625 | // title |
626 | - if ( ! empty( $args['title'] ) ) { |
|
627 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
626 | + if (!empty($args['title'])) { |
|
627 | + $output .= ' title="' . esc_attr($args['title']) . '" '; |
|
628 | 628 | } |
629 | 629 | |
630 | 630 | // validation text |
631 | - if ( ! empty( $args['validation_text'] ) ) { |
|
632 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
631 | + if (!empty($args['validation_text'])) { |
|
632 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr($args['validation_text']) . '\')" '; |
|
633 | 633 | $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
634 | 634 | } |
635 | 635 | |
636 | 636 | // validation_pattern |
637 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
638 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
637 | + if (!empty($args['validation_pattern'])) { |
|
638 | + $output .= ' pattern="' . esc_attr($args['validation_pattern']) . '" '; |
|
639 | 639 | } |
640 | 640 | |
641 | 641 | // required |
642 | - if ( ! empty( $args['required'] ) ) { |
|
642 | + if (!empty($args['required'])) { |
|
643 | 643 | $output .= ' required '; |
644 | 644 | } |
645 | 645 | |
646 | 646 | // rows |
647 | - if ( ! empty( $args['rows'] ) ) { |
|
648 | - $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
647 | + if (!empty($args['rows'])) { |
|
648 | + $output .= ' rows="' . absint($args['rows']) . '" '; |
|
649 | 649 | } |
650 | 650 | |
651 | 651 | |
652 | 652 | // class |
653 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
653 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
654 | 654 | $output .= ' class="form-control ' . $class . '" '; |
655 | 655 | |
656 | 656 | // extra attributes |
657 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
658 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
657 | + if (!empty($args['extra_attributes'])) { |
|
658 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | // close tag |
662 | 662 | $output .= ' >'; |
663 | 663 | |
664 | 664 | // value |
665 | - if ( ! empty( $args['value'] ) ) { |
|
666 | - if ( ! empty( $args['allow_tags'] ) ) { |
|
667 | - $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
665 | + if (!empty($args['value'])) { |
|
666 | + if (!empty($args['allow_tags'])) { |
|
667 | + $output .= AUI_Component_Helper::sanitize_html_field($args['value'], $args); // Sanitize HTML. |
|
668 | 668 | } else { |
669 | - $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] ); |
|
669 | + $output .= AUI_Component_Helper::sanitize_textarea_field($args['value']); |
|
670 | 670 | } |
671 | 671 | } |
672 | 672 | |
@@ -675,23 +675,23 @@ discard block |
||
675 | 675 | |
676 | 676 | |
677 | 677 | // input group wraps |
678 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
679 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
680 | - if ( $args['input_group_left'] ) { |
|
681 | - $output = self::wrap( array( |
|
678 | + if ($args['input_group_left'] || $args['input_group_right']) { |
|
679 | + $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : ''; |
|
680 | + if ($args['input_group_left']) { |
|
681 | + $output = self::wrap(array( |
|
682 | 682 | 'content' => $output, |
683 | 683 | 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
684 | 684 | 'input_group_left' => $args['input_group_left'], |
685 | 685 | 'input_group_left_inside' => $args['input_group_left_inside'] |
686 | - ) ); |
|
686 | + )); |
|
687 | 687 | } |
688 | - if ( $args['input_group_right'] ) { |
|
689 | - $output = self::wrap( array( |
|
688 | + if ($args['input_group_right']) { |
|
689 | + $output = self::wrap(array( |
|
690 | 690 | 'content' => $output, |
691 | 691 | 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
692 | 692 | 'input_group_right' => $args['input_group_right'], |
693 | 693 | 'input_group_right_inside' => $args['input_group_right_inside'] |
694 | - ) ); |
|
694 | + )); |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | } |
@@ -699,7 +699,7 @@ discard block |
||
699 | 699 | |
700 | 700 | } |
701 | 701 | |
702 | - if ( ! empty( $args['label'] ) && $label_after ) { |
|
702 | + if (!empty($args['label']) && $label_after) { |
|
703 | 703 | $label_args = array( |
704 | 704 | 'title' => $args['label'], |
705 | 705 | 'for' => $args['id'], |
@@ -707,32 +707,32 @@ discard block |
||
707 | 707 | 'label_type' => $args['label_type'], |
708 | 708 | 'label_col' => $args['label_col'] |
709 | 709 | ); |
710 | - $output .= self::label( $label_args ); |
|
710 | + $output .= self::label($label_args); |
|
711 | 711 | } |
712 | 712 | |
713 | 713 | // help text |
714 | - if ( ! empty( $args['help_text'] ) ) { |
|
715 | - $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
714 | + if (!empty($args['help_text'])) { |
|
715 | + $output .= AUI_Component_Helper::help_text($args['help_text']); |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | // maybe horizontal label |
719 | - if ( $args['label_type'] == 'horizontal' ) { |
|
719 | + if ($args['label_type'] == 'horizontal') { |
|
720 | 720 | $output .= '</div>'; |
721 | 721 | } |
722 | 722 | |
723 | 723 | |
724 | 724 | // wrap |
725 | - if ( ! $args['no_wrap'] ) { |
|
725 | + if (!$args['no_wrap']) { |
|
726 | 726 | $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : 'form-group'; |
727 | 727 | $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
728 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
729 | - $output = self::wrap( array( |
|
728 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
729 | + $output = self::wrap(array( |
|
730 | 730 | 'content' => $output, |
731 | 731 | 'class' => $wrap_class, |
732 | 732 | 'element_require' => $args['element_require'], |
733 | 733 | 'argument_id' => $args['id'], |
734 | 734 | 'wrap_attributes' => $args['wrap_attributes'], |
735 | - ) ); |
|
735 | + )); |
|
736 | 736 | } |
737 | 737 | |
738 | 738 | |
@@ -746,7 +746,7 @@ discard block |
||
746 | 746 | * |
747 | 747 | * @return string The rendered component. |
748 | 748 | */ |
749 | - public static function select( $args = array() ) { |
|
749 | + public static function select($args = array()) { |
|
750 | 750 | $defaults = array( |
751 | 751 | 'class' => '', |
752 | 752 | 'wrap_class' => '', |
@@ -783,11 +783,11 @@ discard block |
||
783 | 783 | /** |
784 | 784 | * Parse incoming $args into an array and merge it with $defaults |
785 | 785 | */ |
786 | - $args = wp_parse_args( $args, $defaults ); |
|
786 | + $args = wp_parse_args($args, $defaults); |
|
787 | 787 | $output = ''; |
788 | 788 | |
789 | 789 | // for now lets hide floating labels |
790 | - if ( $args['label_type'] == 'floating' ) { |
|
790 | + if ($args['label_type'] == 'floating') { |
|
791 | 791 | $args['label_type'] = 'hidden'; |
792 | 792 | } |
793 | 793 | |
@@ -798,89 +798,89 @@ discard block |
||
798 | 798 | $label_after = $args['label_after']; |
799 | 799 | |
800 | 800 | // floating labels need label after |
801 | - if ( $args['label_type'] == 'floating' ) { |
|
801 | + if ($args['label_type'] == 'floating') { |
|
802 | 802 | $label_after = true; |
803 | 803 | $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
804 | 804 | } |
805 | 805 | |
806 | 806 | // Maybe setup select2 |
807 | 807 | $is_select2 = false; |
808 | - if ( ! empty( $args['select2'] ) ) { |
|
808 | + if (!empty($args['select2'])) { |
|
809 | 809 | $args['class'] .= ' aui-select2'; |
810 | 810 | $is_select2 = true; |
811 | - } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
811 | + } elseif (strpos($args['class'], 'aui-select2') !== false) { |
|
812 | 812 | $is_select2 = true; |
813 | 813 | } |
814 | 814 | |
815 | 815 | // select2 tags |
816 | - if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
816 | + if (!empty($args['select2']) && $args['select2'] === 'tags') { // triple equals needed here for some reason |
|
817 | 817 | $args['data-tags'] = 'true'; |
818 | 818 | $args['data-token-separators'] = "[',']"; |
819 | 819 | $args['multiple'] = true; |
820 | 820 | } |
821 | 821 | |
822 | 822 | // select2 placeholder |
823 | - if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
824 | - $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
825 | - $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
823 | + if ($is_select2 && isset($args['placeholder']) && '' != $args['placeholder'] && empty($args['data-placeholder'])) { |
|
824 | + $args['data-placeholder'] = esc_attr($args['placeholder']); |
|
825 | + $args['data-allow-clear'] = isset($args['data-allow-clear']) ? (bool) $args['data-allow-clear'] : true; |
|
826 | 826 | } |
827 | 827 | |
828 | 828 | // Set hidden input to save empty value for multiselect. |
829 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
830 | - $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>'; |
|
829 | + if (!empty($args['multiple']) && !empty($args['name'])) { |
|
830 | + $output .= '<input type="hidden" ' . AUI_Component_Helper::name($args['name']) . ' value="" data-ignore-rule/>'; |
|
831 | 831 | } |
832 | 832 | |
833 | 833 | // open/type |
834 | 834 | $output .= '<select '; |
835 | 835 | |
836 | 836 | // style |
837 | - if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
837 | + if ($is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
838 | 838 | $output .= " style='width:100%;' "; |
839 | 839 | } |
840 | 840 | |
841 | 841 | // element require |
842 | - if ( ! empty( $args['element_require'] ) ) { |
|
843 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
842 | + if (!empty($args['element_require'])) { |
|
843 | + $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
844 | 844 | $args['class'] .= " aui-conditional-field"; |
845 | 845 | } |
846 | 846 | |
847 | 847 | // class |
848 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
849 | - $output .= AUI_Component_Helper::class_attr( 'custom-select ' . $class ); |
|
848 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
849 | + $output .= AUI_Component_Helper::class_attr('custom-select ' . $class); |
|
850 | 850 | |
851 | 851 | // name |
852 | - if ( ! empty( $args['name'] ) ) { |
|
853 | - $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
852 | + if (!empty($args['name'])) { |
|
853 | + $output .= AUI_Component_Helper::name($args['name'], $args['multiple']); |
|
854 | 854 | } |
855 | 855 | |
856 | 856 | // id |
857 | - if ( ! empty( $args['id'] ) ) { |
|
858 | - $output .= AUI_Component_Helper::id( $args['id'] ); |
|
857 | + if (!empty($args['id'])) { |
|
858 | + $output .= AUI_Component_Helper::id($args['id']); |
|
859 | 859 | } |
860 | 860 | |
861 | 861 | // title |
862 | - if ( ! empty( $args['title'] ) ) { |
|
863 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
862 | + if (!empty($args['title'])) { |
|
863 | + $output .= AUI_Component_Helper::title($args['title']); |
|
864 | 864 | } |
865 | 865 | |
866 | 866 | // data-attributes |
867 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
867 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
868 | 868 | |
869 | 869 | // aria-attributes |
870 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
870 | + $output .= AUI_Component_Helper::aria_attributes($args); |
|
871 | 871 | |
872 | 872 | // extra attributes |
873 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
874 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
873 | + if (!empty($args['extra_attributes'])) { |
|
874 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
875 | 875 | } |
876 | 876 | |
877 | 877 | // required |
878 | - if ( ! empty( $args['required'] ) ) { |
|
878 | + if (!empty($args['required'])) { |
|
879 | 879 | $output .= ' required '; |
880 | 880 | } |
881 | 881 | |
882 | 882 | // multiple |
883 | - if ( ! empty( $args['multiple'] ) ) { |
|
883 | + if (!empty($args['multiple'])) { |
|
884 | 884 | $output .= ' multiple '; |
885 | 885 | } |
886 | 886 | |
@@ -888,50 +888,50 @@ discard block |
||
888 | 888 | $output .= ' >'; |
889 | 889 | |
890 | 890 | // placeholder |
891 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
892 | - $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
893 | - } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
891 | + if (isset($args['placeholder']) && '' != $args['placeholder'] && !$is_select2) { |
|
892 | + $output .= '<option value="" disabled selected hidden>' . esc_attr($args['placeholder']) . '</option>'; |
|
893 | + } elseif ($is_select2 && !empty($args['placeholder'])) { |
|
894 | 894 | $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
895 | 895 | } |
896 | 896 | |
897 | 897 | // Options |
898 | - if ( ! empty( $args['options'] ) ) { |
|
898 | + if (!empty($args['options'])) { |
|
899 | 899 | |
900 | - if ( ! is_array( $args['options'] ) ) { |
|
900 | + if (!is_array($args['options'])) { |
|
901 | 901 | $output .= $args['options']; // not the preferred way but an option |
902 | 902 | } else { |
903 | - foreach ( $args['options'] as $val => $name ) { |
|
903 | + foreach ($args['options'] as $val => $name) { |
|
904 | 904 | $selected = ''; |
905 | - if ( is_array( $name ) ) { |
|
906 | - if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
907 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
905 | + if (is_array($name)) { |
|
906 | + if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) { |
|
907 | + $option_label = isset($name['label']) ? $name['label'] : ''; |
|
908 | 908 | |
909 | - $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
909 | + $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>'; |
|
910 | 910 | } else { |
911 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
912 | - $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
913 | - $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
914 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
915 | - $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
916 | - } elseif ( ! empty( $args['value'] ) ) { |
|
917 | - $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
918 | - } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) { |
|
919 | - $selected = selected( $option_value, $args['value'], false ); |
|
911 | + $option_label = isset($name['label']) ? $name['label'] : ''; |
|
912 | + $option_value = isset($name['value']) ? $name['value'] : ''; |
|
913 | + $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes($name['extra_attributes']) : ''; |
|
914 | + if (!empty($args['multiple']) && !empty($args['value']) && is_array($args['value'])) { |
|
915 | + $selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : ""; |
|
916 | + } elseif (!empty($args['value'])) { |
|
917 | + $selected = selected($option_value, stripslashes_deep($args['value']), false); |
|
918 | + } elseif (empty($args['value']) && $args['value'] === $option_value) { |
|
919 | + $selected = selected($option_value, $args['value'], false); |
|
920 | 920 | } |
921 | 921 | |
922 | - $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
922 | + $output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . ' ' . $extra_attributes . '>' . $option_label . '</option>'; |
|
923 | 923 | } |
924 | 924 | } else { |
925 | - if ( ! empty( $args['value'] ) ) { |
|
926 | - if ( is_array( $args['value'] ) ) { |
|
927 | - $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
928 | - } elseif ( ! empty( $args['value'] ) ) { |
|
929 | - $selected = selected( $args['value'], $val, false ); |
|
925 | + if (!empty($args['value'])) { |
|
926 | + if (is_array($args['value'])) { |
|
927 | + $selected = in_array($val, $args['value']) ? 'selected="selected"' : ''; |
|
928 | + } elseif (!empty($args['value'])) { |
|
929 | + $selected = selected($args['value'], $val, false); |
|
930 | 930 | } |
931 | - } elseif ( $args['value'] === $val ) { |
|
932 | - $selected = selected( $args['value'], $val, false ); |
|
931 | + } elseif ($args['value'] === $val) { |
|
932 | + $selected = selected($args['value'], $val, false); |
|
933 | 933 | } |
934 | - $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
934 | + $output .= '<option value="' . esc_attr($val) . '" ' . $selected . '>' . esc_attr($name) . '</option>'; |
|
935 | 935 | } |
936 | 936 | } |
937 | 937 | } |
@@ -944,8 +944,8 @@ discard block |
||
944 | 944 | $label = ''; |
945 | 945 | $help_text = ''; |
946 | 946 | // label |
947 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
948 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
947 | + if (!empty($args['label']) && is_array($args['label'])) { |
|
948 | + } elseif (!empty($args['label']) && !$label_after) { |
|
949 | 949 | $label_args = array( |
950 | 950 | 'title' => $args['label'], |
951 | 951 | 'for' => $args['id'], |
@@ -953,49 +953,49 @@ discard block |
||
953 | 953 | 'label_type' => $args['label_type'], |
954 | 954 | 'label_col' => $args['label_col'] |
955 | 955 | ); |
956 | - $label = self::label( $label_args ); |
|
956 | + $label = self::label($label_args); |
|
957 | 957 | } |
958 | 958 | |
959 | 959 | // help text |
960 | - if ( ! empty( $args['help_text'] ) ) { |
|
961 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
960 | + if (!empty($args['help_text'])) { |
|
961 | + $help_text = AUI_Component_Helper::help_text($args['help_text']); |
|
962 | 962 | } |
963 | 963 | |
964 | 964 | // input group wraps |
965 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
966 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
967 | - if ( $args['input_group_left'] ) { |
|
968 | - $output = self::wrap( array( |
|
965 | + if ($args['input_group_left'] || $args['input_group_right']) { |
|
966 | + $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : ''; |
|
967 | + if ($args['input_group_left']) { |
|
968 | + $output = self::wrap(array( |
|
969 | 969 | 'content' => $output, |
970 | 970 | 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
971 | 971 | 'input_group_left' => $args['input_group_left'], |
972 | 972 | 'input_group_left_inside' => $args['input_group_left_inside'] |
973 | - ) ); |
|
973 | + )); |
|
974 | 974 | } |
975 | - if ( $args['input_group_right'] ) { |
|
976 | - $output = self::wrap( array( |
|
975 | + if ($args['input_group_right']) { |
|
976 | + $output = self::wrap(array( |
|
977 | 977 | 'content' => $output, |
978 | 978 | 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
979 | 979 | 'input_group_right' => $args['input_group_right'], |
980 | 980 | 'input_group_right_inside' => $args['input_group_right_inside'] |
981 | - ) ); |
|
981 | + )); |
|
982 | 982 | } |
983 | 983 | |
984 | 984 | } |
985 | 985 | |
986 | - if ( ! $label_after ) { |
|
986 | + if (!$label_after) { |
|
987 | 987 | $output .= $help_text; |
988 | 988 | } |
989 | 989 | |
990 | 990 | |
991 | - if ( $args['label_type'] == 'horizontal' ) { |
|
992 | - $output = self::wrap( array( |
|
991 | + if ($args['label_type'] == 'horizontal') { |
|
992 | + $output = self::wrap(array( |
|
993 | 993 | 'content' => $output, |
994 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
995 | - ) ); |
|
994 | + 'class' => AUI_Component_Helper::get_column_class($args['label_col'], 'input') |
|
995 | + )); |
|
996 | 996 | } |
997 | 997 | |
998 | - if ( ! $label_after ) { |
|
998 | + if (!$label_after) { |
|
999 | 999 | $output = $label . $output; |
1000 | 1000 | } |
1001 | 1001 | |
@@ -1006,16 +1006,16 @@ discard block |
||
1006 | 1006 | |
1007 | 1007 | |
1008 | 1008 | // wrap |
1009 | - if ( ! $args['no_wrap'] ) { |
|
1009 | + if (!$args['no_wrap']) { |
|
1010 | 1010 | $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
1011 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1012 | - $output = self::wrap( array( |
|
1011 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1012 | + $output = self::wrap(array( |
|
1013 | 1013 | 'content' => $output, |
1014 | 1014 | 'class' => $wrap_class, |
1015 | 1015 | 'element_require' => $args['element_require'], |
1016 | 1016 | 'argument_id' => $args['id'], |
1017 | 1017 | 'wrap_attributes' => $args['wrap_attributes'], |
1018 | - ) ); |
|
1018 | + )); |
|
1019 | 1019 | } |
1020 | 1020 | |
1021 | 1021 | |
@@ -1029,7 +1029,7 @@ discard block |
||
1029 | 1029 | * |
1030 | 1030 | * @return string The rendered component. |
1031 | 1031 | */ |
1032 | - public static function radio( $args = array() ) { |
|
1032 | + public static function radio($args = array()) { |
|
1033 | 1033 | $defaults = array( |
1034 | 1034 | 'class' => '', |
1035 | 1035 | 'wrap_class' => '', |
@@ -1059,10 +1059,10 @@ discard block |
||
1059 | 1059 | /** |
1060 | 1060 | * Parse incoming $args into an array and merge it with $defaults |
1061 | 1061 | */ |
1062 | - $args = wp_parse_args( $args, $defaults ); |
|
1062 | + $args = wp_parse_args($args, $defaults); |
|
1063 | 1063 | |
1064 | 1064 | // for now lets use horizontal for floating |
1065 | - if ( $args['label_type'] == 'floating' ) { |
|
1065 | + if ($args['label_type'] == 'floating') { |
|
1066 | 1066 | $args['label_type'] = 'horizontal'; |
1067 | 1067 | } |
1068 | 1068 | |
@@ -1077,47 +1077,47 @@ discard block |
||
1077 | 1077 | |
1078 | 1078 | |
1079 | 1079 | // label before |
1080 | - if ( ! empty( $args['label'] ) ) { |
|
1081 | - $output .= self::label( $label_args, 'radio' ); |
|
1080 | + if (!empty($args['label'])) { |
|
1081 | + $output .= self::label($label_args, 'radio'); |
|
1082 | 1082 | } |
1083 | 1083 | |
1084 | 1084 | // maybe horizontal label |
1085 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1086 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
1085 | + if ($args['label_type'] == 'horizontal') { |
|
1086 | + $input_col = AUI_Component_Helper::get_column_class($args['label_col'], 'input'); |
|
1087 | 1087 | $output .= '<div class="' . $input_col . '">'; |
1088 | 1088 | } |
1089 | 1089 | |
1090 | - if ( ! empty( $args['options'] ) ) { |
|
1090 | + if (!empty($args['options'])) { |
|
1091 | 1091 | $count = 0; |
1092 | - foreach ( $args['options'] as $value => $label ) { |
|
1092 | + foreach ($args['options'] as $value => $label) { |
|
1093 | 1093 | $option_args = $args; |
1094 | 1094 | $option_args['value'] = $value; |
1095 | 1095 | $option_args['label'] = $label; |
1096 | 1096 | $option_args['checked'] = $value == $args['value'] ? true : false; |
1097 | - $output .= self::radio_option( $option_args, $count ); |
|
1098 | - $count ++; |
|
1097 | + $output .= self::radio_option($option_args, $count); |
|
1098 | + $count++; |
|
1099 | 1099 | } |
1100 | 1100 | } |
1101 | 1101 | |
1102 | 1102 | // help text |
1103 | - $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
1103 | + $help_text = !empty($args['help_text']) ? AUI_Component_Helper::help_text($args['help_text']) : ''; |
|
1104 | 1104 | $output .= $help_text; |
1105 | 1105 | |
1106 | 1106 | // maybe horizontal label |
1107 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1107 | + if ($args['label_type'] == 'horizontal') { |
|
1108 | 1108 | $output .= '</div>'; |
1109 | 1109 | } |
1110 | 1110 | |
1111 | 1111 | // wrap |
1112 | 1112 | $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
1113 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1114 | - $output = self::wrap( array( |
|
1113 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1114 | + $output = self::wrap(array( |
|
1115 | 1115 | 'content' => $output, |
1116 | 1116 | 'class' => $wrap_class, |
1117 | 1117 | 'element_require' => $args['element_require'], |
1118 | 1118 | 'argument_id' => $args['id'], |
1119 | 1119 | 'wrap_attributes' => $args['wrap_attributes'], |
1120 | - ) ); |
|
1120 | + )); |
|
1121 | 1121 | |
1122 | 1122 | |
1123 | 1123 | return $output; |
@@ -1130,7 +1130,7 @@ discard block |
||
1130 | 1130 | * |
1131 | 1131 | * @return string The rendered component. |
1132 | 1132 | */ |
1133 | - public static function radio_option( $args = array(), $count = '' ) { |
|
1133 | + public static function radio_option($args = array(), $count = '') { |
|
1134 | 1134 | $defaults = array( |
1135 | 1135 | 'class' => '', |
1136 | 1136 | 'id' => '', |
@@ -1148,7 +1148,7 @@ discard block |
||
1148 | 1148 | /** |
1149 | 1149 | * Parse incoming $args into an array and merge it with $defaults |
1150 | 1150 | */ |
1151 | - $args = wp_parse_args( $args, $defaults ); |
|
1151 | + $args = wp_parse_args($args, $defaults); |
|
1152 | 1152 | |
1153 | 1153 | $output = ''; |
1154 | 1154 | |
@@ -1159,43 +1159,43 @@ discard block |
||
1159 | 1159 | $output .= ' class="form-check-input" '; |
1160 | 1160 | |
1161 | 1161 | // name |
1162 | - if ( ! empty( $args['name'] ) ) { |
|
1163 | - $output .= AUI_Component_Helper::name( $args['name'] ); |
|
1162 | + if (!empty($args['name'])) { |
|
1163 | + $output .= AUI_Component_Helper::name($args['name']); |
|
1164 | 1164 | } |
1165 | 1165 | |
1166 | 1166 | // id |
1167 | - if ( ! empty( $args['id'] ) ) { |
|
1168 | - $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
1167 | + if (!empty($args['id'])) { |
|
1168 | + $output .= AUI_Component_Helper::id($args['id'] . $count); |
|
1169 | 1169 | } |
1170 | 1170 | |
1171 | 1171 | // title |
1172 | - if ( ! empty( $args['title'] ) ) { |
|
1173 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
1172 | + if (!empty($args['title'])) { |
|
1173 | + $output .= AUI_Component_Helper::title($args['title']); |
|
1174 | 1174 | } |
1175 | 1175 | |
1176 | 1176 | // value |
1177 | - if ( isset( $args['value'] ) ) { |
|
1178 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
1177 | + if (isset($args['value'])) { |
|
1178 | + $output .= AUI_Component_Helper::value($args['value']); |
|
1179 | 1179 | } |
1180 | 1180 | |
1181 | 1181 | // checked, for radio and checkboxes |
1182 | - if ( $args['checked'] ) { |
|
1182 | + if ($args['checked']) { |
|
1183 | 1183 | $output .= ' checked '; |
1184 | 1184 | } |
1185 | 1185 | |
1186 | 1186 | // data-attributes |
1187 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
1187 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
1188 | 1188 | |
1189 | 1189 | // aria-attributes |
1190 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
1190 | + $output .= AUI_Component_Helper::aria_attributes($args); |
|
1191 | 1191 | |
1192 | 1192 | // extra attributes |
1193 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
1194 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
1193 | + if (!empty($args['extra_attributes'])) { |
|
1194 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
1195 | 1195 | } |
1196 | 1196 | |
1197 | 1197 | // required |
1198 | - if ( ! empty( $args['required'] ) ) { |
|
1198 | + if (!empty($args['required'])) { |
|
1199 | 1199 | $output .= ' required '; |
1200 | 1200 | } |
1201 | 1201 | |
@@ -1203,38 +1203,38 @@ discard block |
||
1203 | 1203 | $output .= ' >'; |
1204 | 1204 | |
1205 | 1205 | // label |
1206 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1207 | - } elseif ( ! empty( $args['label'] ) ) { |
|
1208 | - $output .= self::label( array( |
|
1206 | + if (!empty($args['label']) && is_array($args['label'])) { |
|
1207 | + } elseif (!empty($args['label'])) { |
|
1208 | + $output .= self::label(array( |
|
1209 | 1209 | 'title' => $args['label'], |
1210 | 1210 | 'for' => $args['id'] . $count, |
1211 | 1211 | 'class' => 'form-check-label' |
1212 | - ), 'radio' ); |
|
1212 | + ), 'radio'); |
|
1213 | 1213 | } |
1214 | 1214 | |
1215 | 1215 | // wrap |
1216 | - if ( ! $args['no_wrap'] ) { |
|
1216 | + if (!$args['no_wrap']) { |
|
1217 | 1217 | $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
1218 | 1218 | |
1219 | 1219 | // Unique wrap class |
1220 | 1220 | $uniq_class = 'fwrap'; |
1221 | - if ( ! empty( $args['name'] ) ) { |
|
1221 | + if (!empty($args['name'])) { |
|
1222 | 1222 | $uniq_class .= '-' . $args['name']; |
1223 | - } else if ( ! empty( $args['id'] ) ) { |
|
1223 | + } else if (!empty($args['id'])) { |
|
1224 | 1224 | $uniq_class .= '-' . $args['id']; |
1225 | 1225 | } |
1226 | 1226 | |
1227 | - if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
1227 | + if (isset($args['value']) || $args['value'] !== "") { |
|
1228 | 1228 | $uniq_class .= '-' . $args['value']; |
1229 | 1229 | } else { |
1230 | 1230 | $uniq_class .= '-' . $count; |
1231 | 1231 | } |
1232 | - $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
1232 | + $wrap_class .= ' ' . sanitize_html_class($uniq_class); |
|
1233 | 1233 | |
1234 | - $output = self::wrap( array( |
|
1234 | + $output = self::wrap(array( |
|
1235 | 1235 | 'content' => $output, |
1236 | 1236 | 'class' => $wrap_class |
1237 | - ) ); |
|
1237 | + )); |
|
1238 | 1238 | } |
1239 | 1239 | |
1240 | 1240 | return $output; |
@@ -16,202 +16,202 @@ |
||
16 | 16 | |
17 | 17 | // If this file is called directly, abort. |
18 | 18 | if ( ! defined( 'WPINC' ) ) { |
19 | - die; |
|
19 | + die; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | class AyeCode_UI_Plugin { |
23 | 23 | |
24 | - /** |
|
25 | - * AUI Plugin constructor. |
|
26 | - * |
|
27 | - * @since 1.0.0 |
|
28 | - */ |
|
29 | - public function __construct() { |
|
30 | - |
|
31 | - // load AUI |
|
32 | - require_once( dirname( __FILE__ ) . '/ayecode-ui-loader.php' ); |
|
33 | - |
|
34 | - // Maybe show example page |
|
35 | - add_action( 'template_redirect', array( $this,'maybe_show_examples' ) ); |
|
36 | - } |
|
37 | - |
|
38 | - public function maybe_show_examples(){ |
|
39 | - if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
40 | - echo "<head>"; |
|
41 | - wp_head(); |
|
42 | - echo "</head>"; |
|
43 | - echo "<body class='bsui'>"; |
|
44 | - echo $this->get_examples(); |
|
45 | - wp_footer(); |
|
46 | - echo "</body>"; |
|
47 | - exit; |
|
48 | - } |
|
49 | - } |
|
50 | - |
|
51 | - public function get_examples(){ |
|
52 | - $output = ''; |
|
53 | - |
|
54 | - |
|
55 | - // open form |
|
56 | - $output .= "<form class='p-5 m-5 border rounded'>"; |
|
57 | - |
|
58 | - $output .= aui()->input( |
|
59 | - array( |
|
60 | - 'type' => 'datepicker', |
|
61 | - 'id' => 'wpinv_discount_start', |
|
62 | - 'size' => 'sm', |
|
63 | - 'name' => 'wpinv_discount_start', |
|
64 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
65 | - 'placeholder' => 'YYYY-MM-DD 00:00', |
|
66 | - 'value' => '', |
|
67 | - 'extra_attributes' => array( |
|
68 | - 'data-enable-time' => 'true', |
|
69 | - 'data-time_24hr' => 'true', |
|
70 | - 'data-allow-input' => 'true', |
|
71 | - ), |
|
72 | - ), |
|
73 | - ); |
|
74 | - |
|
75 | - $output .= aui()->input( |
|
76 | - array( |
|
77 | - 'type' => 'datepicker', |
|
78 | - 'id' => 'wpinv_discount_start', |
|
79 | - //'size' => 'smx', |
|
80 | - 'name' => 'wpinv_discount_start', |
|
81 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
82 | - 'placeholder' => 'YYYY-MM-DD 00:00', |
|
83 | - 'value' => '', |
|
84 | - 'extra_attributes' => array( |
|
85 | - 'data-enable-time' => 'true', |
|
86 | - 'data-time_24hr' => 'true', |
|
87 | - 'data-allow-input' => 'true', |
|
88 | - ), |
|
89 | - ), |
|
90 | - ); |
|
91 | - $output .= aui()->input( |
|
92 | - array( |
|
93 | - 'type' => 'datepicker', |
|
94 | - 'id' => 'wpinv_discount_start', |
|
95 | - 'size' => 'lg', |
|
96 | - 'name' => 'wpinv_discount_start', |
|
97 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
98 | - 'placeholder' => 'YYYY-MM-DD 00:00', |
|
99 | - 'value' => '', |
|
100 | - 'extra_attributes' => array( |
|
101 | - 'data-enable-time' => 'true', |
|
102 | - 'data-time_24hr' => 'true', |
|
103 | - //'data-allow-input' => 'true', |
|
104 | - ), |
|
105 | - ) |
|
106 | - ); |
|
107 | - |
|
108 | - |
|
109 | - // input example |
|
110 | - $output .= aui()->input(array( |
|
111 | - 'type' => 'text', |
|
112 | - 'id' => 'text-example', |
|
113 | - 'size' => 'sm', |
|
114 | - //'clear_icon' => true, |
|
115 | - 'name' => 'text-example', |
|
116 | - 'placeholder' => 'text placeholder', |
|
117 | - 'title' => 'Text input example', |
|
118 | - 'value' => '', |
|
119 | - 'required' => false, |
|
120 | - 'help_text' => 'help text', |
|
121 | - 'label' => 'Text input example label', |
|
122 | - 'label_type' => 'top' |
|
123 | - )); |
|
124 | - |
|
125 | - $output .= aui()->input(array( |
|
126 | - 'type' => 'search', |
|
127 | - 'id' => 'text-example', |
|
128 | - 'size' => 'sm', |
|
129 | - //'clear_icon' => true, |
|
130 | - 'name' => 'text-example', |
|
131 | - 'placeholder' => 'text placeholder', |
|
132 | - 'title' => 'Text input example', |
|
133 | - 'value' => '', |
|
134 | - 'required' => false, |
|
135 | - 'help_text' => 'help text', |
|
136 | - 'label' => 'Text input example label', |
|
137 | - 'label_type' => 'top' |
|
138 | - )); |
|
139 | - |
|
140 | - // input example |
|
141 | - $output .= aui()->input(array( |
|
142 | - 'type' => 'url', |
|
143 | - 'id' => 'text-example2', |
|
144 | - 'name' => 'text-example', |
|
145 | - 'placeholder' => 'url placeholder', |
|
146 | - 'title' => 'Text input example', |
|
147 | - 'value' => '', |
|
148 | - 'required' => false, |
|
149 | - 'help_text' => 'help text', |
|
150 | - 'label' => 'Text input example label' |
|
151 | - )); |
|
152 | - |
|
153 | - // checkbox example |
|
154 | - $output .= aui()->input(array( |
|
155 | - 'type' => 'checkbox', |
|
156 | - 'id' => 'checkbox-example', |
|
157 | - 'name' => 'checkbox-example', |
|
158 | - 'placeholder' => 'checkbox-example', |
|
159 | - 'title' => 'Checkbox example', |
|
160 | - 'value' => '1', |
|
161 | - 'checked' => true, |
|
162 | - 'required' => false, |
|
163 | - 'help_text' => 'help text', |
|
164 | - 'label' => 'Checkbox checked' |
|
165 | - )); |
|
166 | - |
|
167 | - // checkbox example |
|
168 | - $output .= aui()->input(array( |
|
169 | - 'type' => 'checkbox', |
|
170 | - 'id' => 'checkbox-example2', |
|
171 | - 'name' => 'checkbox-example2', |
|
172 | - 'placeholder' => 'checkbox-example', |
|
173 | - 'title' => 'Checkbox example', |
|
174 | - 'value' => '1', |
|
175 | - 'checked' => false, |
|
176 | - 'required' => false, |
|
177 | - 'help_text' => 'help text', |
|
178 | - 'label' => 'Checkbox un-checked' |
|
179 | - )); |
|
180 | - |
|
181 | - // switch example |
|
182 | - $output .= aui()->input(array( |
|
183 | - 'type' => 'checkbox', |
|
184 | - 'id' => 'switch-example', |
|
185 | - 'name' => 'switch-example', |
|
186 | - 'placeholder' => 'checkbox-example', |
|
187 | - 'title' => 'Switch example', |
|
188 | - 'value' => '1', |
|
189 | - 'checked' => true, |
|
190 | - 'switch' => true, |
|
191 | - 'required' => false, |
|
192 | - 'help_text' => 'help text', |
|
193 | - 'label' => 'Switch on' |
|
194 | - )); |
|
195 | - |
|
196 | - // switch example |
|
197 | - $output .= aui()->input(array( |
|
198 | - 'type' => 'checkbox', |
|
199 | - 'id' => 'switch-example2', |
|
200 | - 'name' => 'switch-example2', |
|
201 | - 'placeholder' => 'checkbox-example', |
|
202 | - 'title' => 'Switch example', |
|
203 | - 'value' => '1', |
|
204 | - 'checked' => false, |
|
205 | - 'switch' => true, |
|
206 | - 'required' => false, |
|
207 | - 'help_text' => 'help text', |
|
208 | - 'label' => 'Switch off' |
|
209 | - )); |
|
210 | - |
|
211 | - // close form |
|
212 | - $output .= "</form>"; |
|
213 | - |
|
214 | - return $output; |
|
215 | - } |
|
24 | + /** |
|
25 | + * AUI Plugin constructor. |
|
26 | + * |
|
27 | + * @since 1.0.0 |
|
28 | + */ |
|
29 | + public function __construct() { |
|
30 | + |
|
31 | + // load AUI |
|
32 | + require_once( dirname( __FILE__ ) . '/ayecode-ui-loader.php' ); |
|
33 | + |
|
34 | + // Maybe show example page |
|
35 | + add_action( 'template_redirect', array( $this,'maybe_show_examples' ) ); |
|
36 | + } |
|
37 | + |
|
38 | + public function maybe_show_examples(){ |
|
39 | + if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
40 | + echo "<head>"; |
|
41 | + wp_head(); |
|
42 | + echo "</head>"; |
|
43 | + echo "<body class='bsui'>"; |
|
44 | + echo $this->get_examples(); |
|
45 | + wp_footer(); |
|
46 | + echo "</body>"; |
|
47 | + exit; |
|
48 | + } |
|
49 | + } |
|
50 | + |
|
51 | + public function get_examples(){ |
|
52 | + $output = ''; |
|
53 | + |
|
54 | + |
|
55 | + // open form |
|
56 | + $output .= "<form class='p-5 m-5 border rounded'>"; |
|
57 | + |
|
58 | + $output .= aui()->input( |
|
59 | + array( |
|
60 | + 'type' => 'datepicker', |
|
61 | + 'id' => 'wpinv_discount_start', |
|
62 | + 'size' => 'sm', |
|
63 | + 'name' => 'wpinv_discount_start', |
|
64 | + 'label' => __( 'Start Date', 'invoicing' ), |
|
65 | + 'placeholder' => 'YYYY-MM-DD 00:00', |
|
66 | + 'value' => '', |
|
67 | + 'extra_attributes' => array( |
|
68 | + 'data-enable-time' => 'true', |
|
69 | + 'data-time_24hr' => 'true', |
|
70 | + 'data-allow-input' => 'true', |
|
71 | + ), |
|
72 | + ), |
|
73 | + ); |
|
74 | + |
|
75 | + $output .= aui()->input( |
|
76 | + array( |
|
77 | + 'type' => 'datepicker', |
|
78 | + 'id' => 'wpinv_discount_start', |
|
79 | + //'size' => 'smx', |
|
80 | + 'name' => 'wpinv_discount_start', |
|
81 | + 'label' => __( 'Start Date', 'invoicing' ), |
|
82 | + 'placeholder' => 'YYYY-MM-DD 00:00', |
|
83 | + 'value' => '', |
|
84 | + 'extra_attributes' => array( |
|
85 | + 'data-enable-time' => 'true', |
|
86 | + 'data-time_24hr' => 'true', |
|
87 | + 'data-allow-input' => 'true', |
|
88 | + ), |
|
89 | + ), |
|
90 | + ); |
|
91 | + $output .= aui()->input( |
|
92 | + array( |
|
93 | + 'type' => 'datepicker', |
|
94 | + 'id' => 'wpinv_discount_start', |
|
95 | + 'size' => 'lg', |
|
96 | + 'name' => 'wpinv_discount_start', |
|
97 | + 'label' => __( 'Start Date', 'invoicing' ), |
|
98 | + 'placeholder' => 'YYYY-MM-DD 00:00', |
|
99 | + 'value' => '', |
|
100 | + 'extra_attributes' => array( |
|
101 | + 'data-enable-time' => 'true', |
|
102 | + 'data-time_24hr' => 'true', |
|
103 | + //'data-allow-input' => 'true', |
|
104 | + ), |
|
105 | + ) |
|
106 | + ); |
|
107 | + |
|
108 | + |
|
109 | + // input example |
|
110 | + $output .= aui()->input(array( |
|
111 | + 'type' => 'text', |
|
112 | + 'id' => 'text-example', |
|
113 | + 'size' => 'sm', |
|
114 | + //'clear_icon' => true, |
|
115 | + 'name' => 'text-example', |
|
116 | + 'placeholder' => 'text placeholder', |
|
117 | + 'title' => 'Text input example', |
|
118 | + 'value' => '', |
|
119 | + 'required' => false, |
|
120 | + 'help_text' => 'help text', |
|
121 | + 'label' => 'Text input example label', |
|
122 | + 'label_type' => 'top' |
|
123 | + )); |
|
124 | + |
|
125 | + $output .= aui()->input(array( |
|
126 | + 'type' => 'search', |
|
127 | + 'id' => 'text-example', |
|
128 | + 'size' => 'sm', |
|
129 | + //'clear_icon' => true, |
|
130 | + 'name' => 'text-example', |
|
131 | + 'placeholder' => 'text placeholder', |
|
132 | + 'title' => 'Text input example', |
|
133 | + 'value' => '', |
|
134 | + 'required' => false, |
|
135 | + 'help_text' => 'help text', |
|
136 | + 'label' => 'Text input example label', |
|
137 | + 'label_type' => 'top' |
|
138 | + )); |
|
139 | + |
|
140 | + // input example |
|
141 | + $output .= aui()->input(array( |
|
142 | + 'type' => 'url', |
|
143 | + 'id' => 'text-example2', |
|
144 | + 'name' => 'text-example', |
|
145 | + 'placeholder' => 'url placeholder', |
|
146 | + 'title' => 'Text input example', |
|
147 | + 'value' => '', |
|
148 | + 'required' => false, |
|
149 | + 'help_text' => 'help text', |
|
150 | + 'label' => 'Text input example label' |
|
151 | + )); |
|
152 | + |
|
153 | + // checkbox example |
|
154 | + $output .= aui()->input(array( |
|
155 | + 'type' => 'checkbox', |
|
156 | + 'id' => 'checkbox-example', |
|
157 | + 'name' => 'checkbox-example', |
|
158 | + 'placeholder' => 'checkbox-example', |
|
159 | + 'title' => 'Checkbox example', |
|
160 | + 'value' => '1', |
|
161 | + 'checked' => true, |
|
162 | + 'required' => false, |
|
163 | + 'help_text' => 'help text', |
|
164 | + 'label' => 'Checkbox checked' |
|
165 | + )); |
|
166 | + |
|
167 | + // checkbox example |
|
168 | + $output .= aui()->input(array( |
|
169 | + 'type' => 'checkbox', |
|
170 | + 'id' => 'checkbox-example2', |
|
171 | + 'name' => 'checkbox-example2', |
|
172 | + 'placeholder' => 'checkbox-example', |
|
173 | + 'title' => 'Checkbox example', |
|
174 | + 'value' => '1', |
|
175 | + 'checked' => false, |
|
176 | + 'required' => false, |
|
177 | + 'help_text' => 'help text', |
|
178 | + 'label' => 'Checkbox un-checked' |
|
179 | + )); |
|
180 | + |
|
181 | + // switch example |
|
182 | + $output .= aui()->input(array( |
|
183 | + 'type' => 'checkbox', |
|
184 | + 'id' => 'switch-example', |
|
185 | + 'name' => 'switch-example', |
|
186 | + 'placeholder' => 'checkbox-example', |
|
187 | + 'title' => 'Switch example', |
|
188 | + 'value' => '1', |
|
189 | + 'checked' => true, |
|
190 | + 'switch' => true, |
|
191 | + 'required' => false, |
|
192 | + 'help_text' => 'help text', |
|
193 | + 'label' => 'Switch on' |
|
194 | + )); |
|
195 | + |
|
196 | + // switch example |
|
197 | + $output .= aui()->input(array( |
|
198 | + 'type' => 'checkbox', |
|
199 | + 'id' => 'switch-example2', |
|
200 | + 'name' => 'switch-example2', |
|
201 | + 'placeholder' => 'checkbox-example', |
|
202 | + 'title' => 'Switch example', |
|
203 | + 'value' => '1', |
|
204 | + 'checked' => false, |
|
205 | + 'switch' => true, |
|
206 | + 'required' => false, |
|
207 | + 'help_text' => 'help text', |
|
208 | + 'label' => 'Switch off' |
|
209 | + )); |
|
210 | + |
|
211 | + // close form |
|
212 | + $output .= "</form>"; |
|
213 | + |
|
214 | + return $output; |
|
215 | + } |
|
216 | 216 | } |
217 | 217 | new AyeCode_UI_Plugin(); |
218 | 218 | \ No newline at end of file |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | */ |
16 | 16 | |
17 | 17 | // If this file is called directly, abort. |
18 | -if ( ! defined( 'WPINC' ) ) { |
|
18 | +if (!defined('WPINC')) { |
|
19 | 19 | die; |
20 | 20 | } |
21 | 21 | |
@@ -29,14 +29,14 @@ discard block |
||
29 | 29 | public function __construct() { |
30 | 30 | |
31 | 31 | // load AUI |
32 | - require_once( dirname( __FILE__ ) . '/ayecode-ui-loader.php' ); |
|
32 | + require_once(dirname(__FILE__) . '/ayecode-ui-loader.php'); |
|
33 | 33 | |
34 | 34 | // Maybe show example page |
35 | - add_action( 'template_redirect', array( $this,'maybe_show_examples' ) ); |
|
35 | + add_action('template_redirect', array($this, 'maybe_show_examples')); |
|
36 | 36 | } |
37 | 37 | |
38 | - public function maybe_show_examples(){ |
|
39 | - if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
38 | + public function maybe_show_examples() { |
|
39 | + if (current_user_can('manage_options') && isset($_REQUEST['preview-aui'])) { |
|
40 | 40 | echo "<head>"; |
41 | 41 | wp_head(); |
42 | 42 | echo "</head>"; |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
51 | - public function get_examples(){ |
|
51 | + public function get_examples() { |
|
52 | 52 | $output = ''; |
53 | 53 | |
54 | 54 | |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | 'id' => 'wpinv_discount_start', |
62 | 62 | 'size' => 'sm', |
63 | 63 | 'name' => 'wpinv_discount_start', |
64 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
64 | + 'label' => __('Start Date', 'invoicing'), |
|
65 | 65 | 'placeholder' => 'YYYY-MM-DD 00:00', |
66 | 66 | 'value' => '', |
67 | 67 | 'extra_attributes' => array( |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | 'id' => 'wpinv_discount_start', |
79 | 79 | //'size' => 'smx', |
80 | 80 | 'name' => 'wpinv_discount_start', |
81 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
81 | + 'label' => __('Start Date', 'invoicing'), |
|
82 | 82 | 'placeholder' => 'YYYY-MM-DD 00:00', |
83 | 83 | 'value' => '', |
84 | 84 | 'extra_attributes' => array( |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | 'id' => 'wpinv_discount_start', |
95 | 95 | 'size' => 'lg', |
96 | 96 | 'name' => 'wpinv_discount_start', |
97 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
97 | + 'label' => __('Start Date', 'invoicing'), |
|
98 | 98 | 'placeholder' => 'YYYY-MM-DD 00:00', |
99 | 99 | 'value' => '', |
100 | 100 | 'extra_attributes' => array( |
@@ -12,473 +12,473 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Paypal_Gateway_IPN_Handler { |
14 | 14 | |
15 | - /** |
|
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - protected $id = 'paypal'; |
|
21 | - |
|
22 | - /** |
|
23 | - * Payment method object. |
|
24 | - * |
|
25 | - * @var GetPaid_Paypal_Gateway |
|
26 | - */ |
|
27 | - protected $gateway; |
|
28 | - |
|
29 | - /** |
|
30 | - * Class constructor. |
|
31 | - * |
|
32 | - * @param GetPaid_Paypal_Gateway $gateway |
|
33 | - */ |
|
34 | - public function __construct( $gateway ) { |
|
35 | - $this->gateway = $gateway; |
|
36 | - $this->verify_ipn(); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Processes ipns and marks payments as complete. |
|
41 | - * |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - public function verify_ipn() { |
|
45 | - |
|
46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
47 | - |
|
48 | - // Validate the IPN. |
|
49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
51 | - } |
|
52 | - |
|
53 | - // Process the IPN. |
|
54 | - $posted = wp_unslash( $_POST ); |
|
55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
56 | - |
|
57 | - // Abort if it was not paid by our gateway. |
|
58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | - wp_die( 'Invoice not paid via PayPal', 200 ); |
|
61 | - } |
|
62 | - |
|
63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
65 | - |
|
66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
68 | - |
|
69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | - wpinv_error_log( 'Done processing IPN', false ); |
|
72 | - wp_die( 'Processed', 200 ); |
|
73 | - } |
|
74 | - |
|
75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
77 | - |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Retrieves IPN Invoice. |
|
82 | - * |
|
83 | - * @param array $posted |
|
84 | - * @return WPInv_Invoice |
|
85 | - */ |
|
86 | - protected function get_ipn_invoice( $posted ) { |
|
87 | - |
|
88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
89 | - |
|
90 | - if ( ! empty( $posted['custom'] ) ) { |
|
91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
92 | - |
|
93 | - if ( $invoice->exists() ) { |
|
94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
95 | - return $invoice; |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
100 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Check PayPal IPN validity. |
|
105 | - */ |
|
106 | - protected function validate_ipn() { |
|
107 | - |
|
108 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
109 | - |
|
110 | - // Retrieve the associated invoice. |
|
111 | - $posted = wp_unslash( $_POST ); |
|
112 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
113 | - |
|
114 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
115 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
116 | - } |
|
117 | - |
|
118 | - // Validate the IPN. |
|
119 | - $posted['cmd'] = '_notify-validate'; |
|
120 | - |
|
121 | - // Send back post vars to paypal. |
|
122 | - $params = array( |
|
123 | - 'body' => $posted, |
|
124 | - 'timeout' => 60, |
|
125 | - 'httpversion' => '1.1', |
|
126 | - 'compress' => false, |
|
127 | - 'decompress' => false, |
|
128 | - 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
129 | - ); |
|
130 | - |
|
131 | - // Post back to get a response. |
|
132 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
133 | - |
|
134 | - // Check to see if the request was valid. |
|
135 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
136 | - wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
137 | - return true; |
|
138 | - } |
|
139 | - |
|
140 | - if ( is_wp_error( $response ) ) { |
|
141 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
142 | - return false; |
|
143 | - } |
|
144 | - |
|
145 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
146 | - return false; |
|
147 | - |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Check currency from IPN matches the invoice. |
|
152 | - * |
|
153 | - * @param WPInv_Invoice $invoice Invoice object. |
|
154 | - * @param string $currency currency to validate. |
|
155 | - */ |
|
156 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
15 | + /** |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + protected $id = 'paypal'; |
|
21 | + |
|
22 | + /** |
|
23 | + * Payment method object. |
|
24 | + * |
|
25 | + * @var GetPaid_Paypal_Gateway |
|
26 | + */ |
|
27 | + protected $gateway; |
|
28 | + |
|
29 | + /** |
|
30 | + * Class constructor. |
|
31 | + * |
|
32 | + * @param GetPaid_Paypal_Gateway $gateway |
|
33 | + */ |
|
34 | + public function __construct( $gateway ) { |
|
35 | + $this->gateway = $gateway; |
|
36 | + $this->verify_ipn(); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Processes ipns and marks payments as complete. |
|
41 | + * |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + public function verify_ipn() { |
|
45 | + |
|
46 | + wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
47 | + |
|
48 | + // Validate the IPN. |
|
49 | + if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | + wp_die( 'PayPal IPN Request Failure', 500 ); |
|
51 | + } |
|
52 | + |
|
53 | + // Process the IPN. |
|
54 | + $posted = wp_unslash( $_POST ); |
|
55 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
56 | + |
|
57 | + // Abort if it was not paid by our gateway. |
|
58 | + if ( $this->id != $invoice->get_gateway() ) { |
|
59 | + wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | + wp_die( 'Invoice not paid via PayPal', 200 ); |
|
61 | + } |
|
62 | + |
|
63 | + $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | + $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
65 | + |
|
66 | + wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | + wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
68 | + |
|
69 | + if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | + call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | + wpinv_error_log( 'Done processing IPN', false ); |
|
72 | + wp_die( 'Processed', 200 ); |
|
73 | + } |
|
74 | + |
|
75 | + wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | + wp_die( 'Unsupported IPN type', 200 ); |
|
77 | + |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Retrieves IPN Invoice. |
|
82 | + * |
|
83 | + * @param array $posted |
|
84 | + * @return WPInv_Invoice |
|
85 | + */ |
|
86 | + protected function get_ipn_invoice( $posted ) { |
|
87 | + |
|
88 | + wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
89 | + |
|
90 | + if ( ! empty( $posted['custom'] ) ) { |
|
91 | + $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
92 | + |
|
93 | + if ( $invoice->exists() ) { |
|
94 | + wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
95 | + return $invoice; |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
100 | + wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Check PayPal IPN validity. |
|
105 | + */ |
|
106 | + protected function validate_ipn() { |
|
107 | + |
|
108 | + wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
109 | + |
|
110 | + // Retrieve the associated invoice. |
|
111 | + $posted = wp_unslash( $_POST ); |
|
112 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
113 | + |
|
114 | + if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
115 | + wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
116 | + } |
|
117 | + |
|
118 | + // Validate the IPN. |
|
119 | + $posted['cmd'] = '_notify-validate'; |
|
120 | + |
|
121 | + // Send back post vars to paypal. |
|
122 | + $params = array( |
|
123 | + 'body' => $posted, |
|
124 | + 'timeout' => 60, |
|
125 | + 'httpversion' => '1.1', |
|
126 | + 'compress' => false, |
|
127 | + 'decompress' => false, |
|
128 | + 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
129 | + ); |
|
130 | + |
|
131 | + // Post back to get a response. |
|
132 | + $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
133 | + |
|
134 | + // Check to see if the request was valid. |
|
135 | + if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
136 | + wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
137 | + return true; |
|
138 | + } |
|
139 | + |
|
140 | + if ( is_wp_error( $response ) ) { |
|
141 | + wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
142 | + return false; |
|
143 | + } |
|
144 | + |
|
145 | + wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
146 | + return false; |
|
147 | + |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Check currency from IPN matches the invoice. |
|
152 | + * |
|
153 | + * @param WPInv_Invoice $invoice Invoice object. |
|
154 | + * @param string $currency currency to validate. |
|
155 | + */ |
|
156 | + protected function validate_ipn_currency( $invoice, $currency ) { |
|
157 | 157 | |
158 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
158 | + if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
159 | 159 | |
160 | - /* translators: %s: currency code. */ |
|
161 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
160 | + /* translators: %s: currency code. */ |
|
161 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
162 | 162 | |
163 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
164 | - } |
|
163 | + wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
164 | + } |
|
165 | 165 | |
166 | - wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
167 | - } |
|
166 | + wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
167 | + } |
|
168 | 168 | |
169 | - /** |
|
170 | - * Check payment amount from IPN matches the invoice. |
|
171 | - * |
|
172 | - * @param WPInv_Invoice $invoice Invoice object. |
|
173 | - * @param float $amount amount to validate. |
|
174 | - */ |
|
175 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
176 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
169 | + /** |
|
170 | + * Check payment amount from IPN matches the invoice. |
|
171 | + * |
|
172 | + * @param WPInv_Invoice $invoice Invoice object. |
|
173 | + * @param float $amount amount to validate. |
|
174 | + */ |
|
175 | + protected function validate_ipn_amount( $invoice, $amount ) { |
|
176 | + if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
177 | 177 | |
178 | - /* translators: %s: Amount. */ |
|
179 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
178 | + /* translators: %s: Amount. */ |
|
179 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
180 | 180 | |
181 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
182 | - } |
|
181 | + wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
182 | + } |
|
183 | 183 | |
184 | - wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
185 | - } |
|
184 | + wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
185 | + } |
|
186 | 186 | |
187 | - /** |
|
188 | - * Verify receiver email from PayPal. |
|
189 | - * |
|
190 | - * @param WPInv_Invoice $invoice Invoice object. |
|
191 | - * @param string $receiver_email Email to validate. |
|
192 | - */ |
|
193 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
194 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
187 | + /** |
|
188 | + * Verify receiver email from PayPal. |
|
189 | + * |
|
190 | + * @param WPInv_Invoice $invoice Invoice object. |
|
191 | + * @param string $receiver_email Email to validate. |
|
192 | + */ |
|
193 | + protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
194 | + $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
195 | 195 | |
196 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
197 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
196 | + if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
197 | + wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
198 | 198 | |
199 | - /* translators: %s: email address . */ |
|
200 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
199 | + /* translators: %s: email address . */ |
|
200 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
201 | 201 | |
202 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
203 | - } |
|
202 | + return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
203 | + } |
|
204 | 204 | |
205 | - wpinv_error_log( 'Validated PayPal Email', false ); |
|
206 | - } |
|
205 | + wpinv_error_log( 'Validated PayPal Email', false ); |
|
206 | + } |
|
207 | 207 | |
208 | - /** |
|
209 | - * Handles one time payments. |
|
210 | - * |
|
211 | - * @param WPInv_Invoice $invoice Invoice object. |
|
212 | - * @param array $posted Posted data. |
|
213 | - */ |
|
214 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
208 | + /** |
|
209 | + * Handles one time payments. |
|
210 | + * |
|
211 | + * @param WPInv_Invoice $invoice Invoice object. |
|
212 | + * @param array $posted Posted data. |
|
213 | + */ |
|
214 | + protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
215 | 215 | |
216 | - // Collect payment details |
|
217 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
218 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
216 | + // Collect payment details |
|
217 | + $payment_status = strtolower( $posted['payment_status'] ); |
|
218 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
219 | 219 | |
220 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
221 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
220 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
221 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
222 | 222 | |
223 | - // Update the transaction id. |
|
224 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
225 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
226 | - $invoice->save(); |
|
227 | - } |
|
223 | + // Update the transaction id. |
|
224 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
225 | + $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
226 | + $invoice->save(); |
|
227 | + } |
|
228 | 228 | |
229 | - $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
229 | + $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
230 | 230 | |
231 | - // Process a refund. |
|
232 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
231 | + // Process a refund. |
|
232 | + if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
233 | 233 | |
234 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
234 | + update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
235 | 235 | |
236 | - if ( ! $invoice->is_refunded() ) { |
|
237 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
238 | - } |
|
236 | + if ( ! $invoice->is_refunded() ) { |
|
237 | + $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
238 | + } |
|
239 | 239 | |
240 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
241 | - } |
|
240 | + return wpinv_error_log( $posted['reason_code'], false ); |
|
241 | + } |
|
242 | 242 | |
243 | - // Process payments. |
|
244 | - if ( $payment_status == 'completed' ) { |
|
243 | + // Process payments. |
|
244 | + if ( $payment_status == 'completed' ) { |
|
245 | 245 | |
246 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
247 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
248 | - } |
|
246 | + if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
247 | + return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
248 | + } |
|
249 | 249 | |
250 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
250 | + $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
251 | 251 | |
252 | - $note = ''; |
|
252 | + $note = ''; |
|
253 | 253 | |
254 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
255 | - $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
256 | - } |
|
254 | + if ( ! empty( $posted['mc_fee'] ) ) { |
|
255 | + $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
256 | + } |
|
257 | 257 | |
258 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
259 | - $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
260 | - } |
|
258 | + if ( ! empty( $posted['payer_status'] ) ) { |
|
259 | + $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
260 | + } |
|
261 | 261 | |
262 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
263 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
262 | + $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
263 | + return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
264 | 264 | |
265 | - } |
|
265 | + } |
|
266 | 266 | |
267 | - // Pending payments. |
|
268 | - if ( $payment_status == 'pending' ) { |
|
267 | + // Pending payments. |
|
268 | + if ( $payment_status == 'pending' ) { |
|
269 | 269 | |
270 | - /* translators: %s: pending reason. */ |
|
271 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
270 | + /* translators: %s: pending reason. */ |
|
271 | + $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
272 | 272 | |
273 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
274 | - } |
|
273 | + return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
274 | + } |
|
275 | 275 | |
276 | - /* translators: %s: payment status. */ |
|
277 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
276 | + /* translators: %s: payment status. */ |
|
277 | + $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
278 | 278 | |
279 | - } |
|
279 | + } |
|
280 | 280 | |
281 | - /** |
|
282 | - * Handles one time payments. |
|
283 | - * |
|
284 | - * @param WPInv_Invoice $invoice Invoice object. |
|
285 | - * @param array $posted Posted data. |
|
286 | - */ |
|
287 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
288 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
289 | - } |
|
281 | + /** |
|
282 | + * Handles one time payments. |
|
283 | + * |
|
284 | + * @param WPInv_Invoice $invoice Invoice object. |
|
285 | + * @param array $posted Posted data. |
|
286 | + */ |
|
287 | + protected function ipn_txn_cart( $invoice, $posted ) { |
|
288 | + $this->ipn_txn_web_accept( $invoice, $posted ); |
|
289 | + } |
|
290 | 290 | |
291 | - /** |
|
292 | - * Handles subscription sign ups. |
|
293 | - * |
|
294 | - * @param WPInv_Invoice $invoice Invoice object. |
|
295 | - * @param array $posted Posted data. |
|
296 | - */ |
|
297 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
291 | + /** |
|
292 | + * Handles subscription sign ups. |
|
293 | + * |
|
294 | + * @param WPInv_Invoice $invoice Invoice object. |
|
295 | + * @param array $posted Posted data. |
|
296 | + */ |
|
297 | + protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
298 | 298 | |
299 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
299 | + wpinv_error_log( 'Processing subscription signup', false ); |
|
300 | 300 | |
301 | - // Make sure the invoice has a subscription. |
|
302 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
301 | + // Make sure the invoice has a subscription. |
|
302 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
303 | 303 | |
304 | - if ( empty( $subscription ) ) { |
|
305 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
306 | - } |
|
304 | + if ( empty( $subscription ) ) { |
|
305 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
306 | + } |
|
307 | 307 | |
308 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
308 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
309 | 309 | |
310 | - // Validate the IPN. |
|
311 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
312 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
313 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
310 | + // Validate the IPN. |
|
311 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
312 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
313 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
314 | 314 | |
315 | - // Activate the subscription. |
|
316 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
317 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
318 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
319 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
320 | - $subscription->activate(); |
|
315 | + // Activate the subscription. |
|
316 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
317 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
318 | + $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
319 | + $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
320 | + $subscription->activate(); |
|
321 | 321 | |
322 | - // Set the transaction id. |
|
323 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
324 | - $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
325 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
326 | - } |
|
322 | + // Set the transaction id. |
|
323 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
324 | + $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
325 | + $invoice->set_transaction_id( $posted['txn_id'] ); |
|
326 | + } |
|
327 | 327 | |
328 | - // Update the payment status. |
|
329 | - $invoice->mark_paid(); |
|
328 | + // Update the payment status. |
|
329 | + $invoice->mark_paid(); |
|
330 | 330 | |
331 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
331 | + $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
332 | 332 | |
333 | - wpinv_error_log( 'Subscription started.', false ); |
|
334 | - } |
|
333 | + wpinv_error_log( 'Subscription started.', false ); |
|
334 | + } |
|
335 | 335 | |
336 | - /** |
|
337 | - * Handles subscription renewals. |
|
338 | - * |
|
339 | - * @param WPInv_Invoice $invoice Invoice object. |
|
340 | - * @param array $posted Posted data. |
|
341 | - */ |
|
342 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
336 | + /** |
|
337 | + * Handles subscription renewals. |
|
338 | + * |
|
339 | + * @param WPInv_Invoice $invoice Invoice object. |
|
340 | + * @param array $posted Posted data. |
|
341 | + */ |
|
342 | + protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
343 | 343 | |
344 | - // Make sure the invoice has a subscription. |
|
345 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
344 | + // Make sure the invoice has a subscription. |
|
345 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
346 | 346 | |
347 | - if ( empty( $subscription ) ) { |
|
348 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
349 | - } |
|
347 | + if ( empty( $subscription ) ) { |
|
348 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
349 | + } |
|
350 | 350 | |
351 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
351 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
352 | 352 | |
353 | - // PayPal sends a subscr_payment for the first payment too. |
|
354 | - $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
355 | - $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
356 | - $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
357 | - $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
358 | - $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
359 | - $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
353 | + // PayPal sends a subscr_payment for the first payment too. |
|
354 | + $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
355 | + $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
356 | + $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
357 | + $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
358 | + $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
359 | + $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
360 | 360 | |
361 | - foreach ( $dates as $date ) { |
|
361 | + foreach ( $dates as $date ) { |
|
362 | 362 | |
363 | - if ( $date !== $today_date && $date !== $payment_date ) { |
|
364 | - continue; |
|
365 | - } |
|
363 | + if ( $date !== $today_date && $date !== $payment_date ) { |
|
364 | + continue; |
|
365 | + } |
|
366 | 366 | |
367 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
368 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
369 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
370 | - } |
|
367 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
368 | + $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
369 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
370 | + } |
|
371 | 371 | |
372 | - return $invoice->mark_paid(); |
|
373 | - |
|
374 | - } |
|
372 | + return $invoice->mark_paid(); |
|
373 | + |
|
374 | + } |
|
375 | 375 | |
376 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
377 | - |
|
378 | - // Abort if the payment is already recorded. |
|
379 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
380 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false ); |
|
381 | - } |
|
382 | - |
|
383 | - $args = array( |
|
384 | - 'transaction_id' => $posted['txn_id'], |
|
385 | - 'gateway' => $this->id, |
|
386 | - ); |
|
387 | - |
|
388 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
376 | + wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
377 | + |
|
378 | + // Abort if the payment is already recorded. |
|
379 | + if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
380 | + return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false ); |
|
381 | + } |
|
382 | + |
|
383 | + $args = array( |
|
384 | + 'transaction_id' => $posted['txn_id'], |
|
385 | + 'gateway' => $this->id, |
|
386 | + ); |
|
387 | + |
|
388 | + $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
389 | 389 | |
390 | - if ( empty( $invoice ) ) { |
|
391 | - return; |
|
392 | - } |
|
390 | + if ( empty( $invoice ) ) { |
|
391 | + return; |
|
392 | + } |
|
393 | 393 | |
394 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
395 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
394 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
395 | + $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
396 | 396 | |
397 | - $subscription->renew(); |
|
398 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
397 | + $subscription->renew(); |
|
398 | + wpinv_error_log( 'Subscription renewed.', false ); |
|
399 | 399 | |
400 | - } |
|
400 | + } |
|
401 | 401 | |
402 | - /** |
|
403 | - * Handles subscription cancelations. |
|
404 | - * |
|
405 | - * @param WPInv_Invoice $invoice Invoice object. |
|
406 | - */ |
|
407 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
402 | + /** |
|
403 | + * Handles subscription cancelations. |
|
404 | + * |
|
405 | + * @param WPInv_Invoice $invoice Invoice object. |
|
406 | + */ |
|
407 | + protected function ipn_txn_subscr_cancel( $invoice ) { |
|
408 | 408 | |
409 | - // Make sure the invoice has a subscription. |
|
410 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
411 | - |
|
412 | - if ( empty( $subscription ) ) { |
|
413 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
414 | - } |
|
415 | - |
|
416 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
417 | - $subscription->cancel(); |
|
418 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
409 | + // Make sure the invoice has a subscription. |
|
410 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
411 | + |
|
412 | + if ( empty( $subscription ) ) { |
|
413 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
414 | + } |
|
415 | + |
|
416 | + wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
417 | + $subscription->cancel(); |
|
418 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
419 | 419 | |
420 | - } |
|
420 | + } |
|
421 | 421 | |
422 | - /** |
|
423 | - * Handles subscription completions. |
|
424 | - * |
|
425 | - * @param WPInv_Invoice $invoice Invoice object. |
|
426 | - * @param array $posted Posted data. |
|
427 | - */ |
|
428 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
422 | + /** |
|
423 | + * Handles subscription completions. |
|
424 | + * |
|
425 | + * @param WPInv_Invoice $invoice Invoice object. |
|
426 | + * @param array $posted Posted data. |
|
427 | + */ |
|
428 | + protected function ipn_txn_subscr_eot( $invoice ) { |
|
429 | 429 | |
430 | - // Make sure the invoice has a subscription. |
|
431 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
430 | + // Make sure the invoice has a subscription. |
|
431 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
432 | 432 | |
433 | - if ( empty( $subscription ) ) { |
|
434 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
435 | - } |
|
433 | + if ( empty( $subscription ) ) { |
|
434 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
435 | + } |
|
436 | 436 | |
437 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
438 | - $subscription->complete(); |
|
439 | - wpinv_error_log( 'Subscription completed.', false ); |
|
437 | + wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
438 | + $subscription->complete(); |
|
439 | + wpinv_error_log( 'Subscription completed.', false ); |
|
440 | 440 | |
441 | - } |
|
441 | + } |
|
442 | 442 | |
443 | - /** |
|
444 | - * Handles subscription fails. |
|
445 | - * |
|
446 | - * @param WPInv_Invoice $invoice Invoice object. |
|
447 | - * @param array $posted Posted data. |
|
448 | - */ |
|
449 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
443 | + /** |
|
444 | + * Handles subscription fails. |
|
445 | + * |
|
446 | + * @param WPInv_Invoice $invoice Invoice object. |
|
447 | + * @param array $posted Posted data. |
|
448 | + */ |
|
449 | + protected function ipn_txn_subscr_failed( $invoice ) { |
|
450 | 450 | |
451 | - // Make sure the invoice has a subscription. |
|
452 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
451 | + // Make sure the invoice has a subscription. |
|
452 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
453 | 453 | |
454 | - if ( empty( $subscription ) ) { |
|
455 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
456 | - } |
|
454 | + if ( empty( $subscription ) ) { |
|
455 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
456 | + } |
|
457 | 457 | |
458 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
459 | - $subscription->failing(); |
|
460 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
458 | + wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
459 | + $subscription->failing(); |
|
460 | + wpinv_error_log( 'Subscription marked as failing.', false ); |
|
461 | 461 | |
462 | - } |
|
462 | + } |
|
463 | 463 | |
464 | - /** |
|
465 | - * Handles subscription suspensions. |
|
466 | - * |
|
467 | - * @param WPInv_Invoice $invoice Invoice object. |
|
468 | - * @param array $posted Posted data. |
|
469 | - */ |
|
470 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
464 | + /** |
|
465 | + * Handles subscription suspensions. |
|
466 | + * |
|
467 | + * @param WPInv_Invoice $invoice Invoice object. |
|
468 | + * @param array $posted Posted data. |
|
469 | + */ |
|
470 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
471 | 471 | |
472 | - // Make sure the invoice has a subscription. |
|
473 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
472 | + // Make sure the invoice has a subscription. |
|
473 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
474 | 474 | |
475 | - if ( empty( $subscription ) ) { |
|
476 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
477 | - } |
|
478 | - |
|
479 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
480 | - $subscription->cancel(); |
|
481 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
482 | - } |
|
475 | + if ( empty( $subscription ) ) { |
|
476 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
477 | + } |
|
478 | + |
|
479 | + wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
480 | + $subscription->cancel(); |
|
481 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
482 | + } |
|
483 | 483 | |
484 | 484 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Paypal Payment Gateway IPN handler class. |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @param GetPaid_Paypal_Gateway $gateway |
33 | 33 | */ |
34 | - public function __construct( $gateway ) { |
|
34 | + public function __construct($gateway) { |
|
35 | 35 | $this->gateway = $gateway; |
36 | 36 | $this->verify_ipn(); |
37 | 37 | } |
@@ -43,37 +43,37 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function verify_ipn() { |
45 | 45 | |
46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
46 | + wpinv_error_log('GetPaid PayPal IPN Handler', false); |
|
47 | 47 | |
48 | 48 | // Validate the IPN. |
49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
49 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
50 | + wp_die('PayPal IPN Request Failure', 500); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | // Process the IPN. |
54 | - $posted = wp_unslash( $_POST ); |
|
55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
54 | + $posted = wp_unslash($_POST); |
|
55 | + $invoice = $this->get_ipn_invoice($posted); |
|
56 | 56 | |
57 | 57 | // Abort if it was not paid by our gateway. |
58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | - wp_die( 'Invoice not paid via PayPal', 200 ); |
|
58 | + if ($this->id != $invoice->get_gateway()) { |
|
59 | + wpinv_error_log('Aborting, Invoice was not paid via PayPal', false); |
|
60 | + wp_die('Invoice not paid via PayPal', 200); |
|
61 | 61 | } |
62 | 62 | |
63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
63 | + $posted['payment_status'] = isset($posted['payment_status']) ? sanitize_key(strtolower($posted['payment_status'])) : ''; |
|
64 | + $posted['txn_type'] = sanitize_key(strtolower($posted['txn_type'])); |
|
65 | 65 | |
66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
66 | + wpinv_error_log('Payment status:' . $posted['payment_status'], false); |
|
67 | + wpinv_error_log('IPN Type:' . $posted['txn_type'], false); |
|
68 | 68 | |
69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | - wpinv_error_log( 'Done processing IPN', false ); |
|
72 | - wp_die( 'Processed', 200 ); |
|
69 | + if (method_exists($this, 'ipn_txn_' . $posted['txn_type'])) { |
|
70 | + call_user_func(array($this, 'ipn_txn_' . $posted['txn_type']), $invoice, $posted); |
|
71 | + wpinv_error_log('Done processing IPN', false); |
|
72 | + wp_die('Processed', 200); |
|
73 | 73 | } |
74 | 74 | |
75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
75 | + wpinv_error_log('Aborting, Unsupported IPN type:' . $posted['txn_type'], false); |
|
76 | + wp_die('Unsupported IPN type', 200); |
|
77 | 77 | |
78 | 78 | } |
79 | 79 | |
@@ -83,21 +83,21 @@ discard block |
||
83 | 83 | * @param array $posted |
84 | 84 | * @return WPInv_Invoice |
85 | 85 | */ |
86 | - protected function get_ipn_invoice( $posted ) { |
|
86 | + protected function get_ipn_invoice($posted) { |
|
87 | 87 | |
88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
88 | + wpinv_error_log('Retrieving PayPal IPN Response Invoice', false); |
|
89 | 89 | |
90 | - if ( ! empty( $posted['custom'] ) ) { |
|
91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
90 | + if (!empty($posted['custom'])) { |
|
91 | + $invoice = new WPInv_Invoice($posted['custom']); |
|
92 | 92 | |
93 | - if ( $invoice->exists() ) { |
|
94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
93 | + if ($invoice->exists()) { |
|
94 | + wpinv_error_log('Found invoice #' . $invoice->get_number(), false); |
|
95 | 95 | return $invoice; |
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
99 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
100 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
99 | + wpinv_error_log('Could not retrieve the associated invoice.', false); |
|
100 | + wp_die('Could not retrieve the associated invoice.', 200); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -105,14 +105,14 @@ discard block |
||
105 | 105 | */ |
106 | 106 | protected function validate_ipn() { |
107 | 107 | |
108 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
108 | + wpinv_error_log('Validating PayPal IPN response', false); |
|
109 | 109 | |
110 | 110 | // Retrieve the associated invoice. |
111 | - $posted = wp_unslash( $_POST ); |
|
112 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
111 | + $posted = wp_unslash($_POST); |
|
112 | + $invoice = $this->get_ipn_invoice($posted); |
|
113 | 113 | |
114 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
115 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
114 | + if ($this->gateway->is_sandbox($invoice)) { |
|
115 | + wpinv_error_log($posted, 'Invoice was processed in sandbox hence logging the posted data', false); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | // Validate the IPN. |
@@ -129,20 +129,20 @@ discard block |
||
129 | 129 | ); |
130 | 130 | |
131 | 131 | // Post back to get a response. |
132 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
132 | + $response = wp_safe_remote_post($this->gateway->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params); |
|
133 | 133 | |
134 | 134 | // Check to see if the request was valid. |
135 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
136 | - wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
135 | + if (!is_wp_error($response) && $response['response']['code'] < 300 && strstr($response['body'], 'VERIFIED')) { |
|
136 | + wpinv_error_log('Received valid response from PayPal IPN: ' . $response['body'], false); |
|
137 | 137 | return true; |
138 | 138 | } |
139 | 139 | |
140 | - if ( is_wp_error( $response ) ) { |
|
141 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
140 | + if (is_wp_error($response)) { |
|
141 | + wpinv_error_log($response->get_error_message(), 'Received invalid response from PayPal IPN'); |
|
142 | 142 | return false; |
143 | 143 | } |
144 | 144 | |
145 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
145 | + wpinv_error_log($response['body'], 'Received invalid response from PayPal IPN'); |
|
146 | 146 | return false; |
147 | 147 | |
148 | 148 | } |
@@ -153,17 +153,17 @@ discard block |
||
153 | 153 | * @param WPInv_Invoice $invoice Invoice object. |
154 | 154 | * @param string $currency currency to validate. |
155 | 155 | */ |
156 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
156 | + protected function validate_ipn_currency($invoice, $currency) { |
|
157 | 157 | |
158 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
158 | + if (strtolower($invoice->get_currency()) !== strtolower($currency)) { |
|
159 | 159 | |
160 | 160 | /* translators: %s: currency code. */ |
161 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
161 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal currencies do not match (code %s).', 'invoicing'), $currency)); |
|
162 | 162 | |
163 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
163 | + wpinv_error_log("Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true); |
|
164 | 164 | } |
165 | 165 | |
166 | - wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
166 | + wpinv_error_log($currency, 'Validated IPN Currency', false); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -172,16 +172,16 @@ discard block |
||
172 | 172 | * @param WPInv_Invoice $invoice Invoice object. |
173 | 173 | * @param float $amount amount to validate. |
174 | 174 | */ |
175 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
176 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
175 | + protected function validate_ipn_amount($invoice, $amount) { |
|
176 | + if (number_format($invoice->get_total(), 2, '.', '') !== number_format($amount, 2, '.', '')) { |
|
177 | 177 | |
178 | 178 | /* translators: %s: Amount. */ |
179 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
179 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal amounts do not match (gross %s).', 'invoicing'), $amount)); |
|
180 | 180 | |
181 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
181 | + wpinv_error_log("Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true); |
|
182 | 182 | } |
183 | 183 | |
184 | - wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
184 | + wpinv_error_log($amount, 'Validated IPN Amount', false); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -190,19 +190,19 @@ discard block |
||
190 | 190 | * @param WPInv_Invoice $invoice Invoice object. |
191 | 191 | * @param string $receiver_email Email to validate. |
192 | 192 | */ |
193 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
194 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
193 | + protected function validate_ipn_receiver_email($invoice, $receiver_email) { |
|
194 | + $paypal_email = wpinv_get_option('paypal_email'); |
|
195 | 195 | |
196 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
197 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
196 | + if (strcasecmp(trim($receiver_email), trim($paypal_email)) !== 0) { |
|
197 | + wpinv_record_gateway_error('IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}"); |
|
198 | 198 | |
199 | 199 | /* translators: %s: email address . */ |
200 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
200 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal IPN response from a different email address (%s).', 'invoicing'), $receiver_email)); |
|
201 | 201 | |
202 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
202 | + return wpinv_error_log("IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true); |
|
203 | 203 | } |
204 | 204 | |
205 | - wpinv_error_log( 'Validated PayPal Email', false ); |
|
205 | + wpinv_error_log('Validated PayPal Email', false); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -211,70 +211,70 @@ discard block |
||
211 | 211 | * @param WPInv_Invoice $invoice Invoice object. |
212 | 212 | * @param array $posted Posted data. |
213 | 213 | */ |
214 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
214 | + protected function ipn_txn_web_accept($invoice, $posted) { |
|
215 | 215 | |
216 | 216 | // Collect payment details |
217 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
218 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
217 | + $payment_status = strtolower($posted['payment_status']); |
|
218 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
219 | 219 | |
220 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
221 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
220 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
221 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
222 | 222 | |
223 | 223 | // Update the transaction id. |
224 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
225 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
224 | + if (!empty($posted['txn_id'])) { |
|
225 | + $invoice->set_transaction_id(wpinv_clean($posted['txn_id'])); |
|
226 | 226 | $invoice->save(); |
227 | 227 | } |
228 | 228 | |
229 | - $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
229 | + $invoice->add_system_note(__('Processing invoice IPN', 'invoicing')); |
|
230 | 230 | |
231 | 231 | // Process a refund. |
232 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
232 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
233 | 233 | |
234 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
234 | + update_post_meta($invoice->get_id(), 'refunded_remotely', 1); |
|
235 | 235 | |
236 | - if ( ! $invoice->is_refunded() ) { |
|
237 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
236 | + if (!$invoice->is_refunded()) { |
|
237 | + $invoice->update_status('wpi-refunded', $posted['reason_code']); |
|
238 | 238 | } |
239 | 239 | |
240 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
240 | + return wpinv_error_log($posted['reason_code'], false); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | // Process payments. |
244 | - if ( $payment_status == 'completed' ) { |
|
244 | + if ($payment_status == 'completed') { |
|
245 | 245 | |
246 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
247 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
246 | + if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) { |
|
247 | + return wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false); |
|
248 | 248 | } |
249 | 249 | |
250 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
250 | + $this->validate_ipn_amount($invoice, $posted['mc_gross']); |
|
251 | 251 | |
252 | 252 | $note = ''; |
253 | 253 | |
254 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
255 | - $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
254 | + if (!empty($posted['mc_fee'])) { |
|
255 | + $note = sprintf(__('PayPal Transaction Fee %s.', 'invoicing'), sanitize_text_field($posted['mc_fee'])); |
|
256 | 256 | } |
257 | 257 | |
258 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
259 | - $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
258 | + if (!empty($posted['payer_status'])) { |
|
259 | + $note = ' ' . sprintf(__('Buyer status %s.', 'invoicing'), sanitize_text_field($posted['payer_status'])); |
|
260 | 260 | } |
261 | 261 | |
262 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
263 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
262 | + $invoice->mark_paid((!empty($posted['txn_id']) ? sanitize_text_field($posted['txn_id']) : ''), trim($note)); |
|
263 | + return wpinv_error_log('Invoice marked as paid.', false); |
|
264 | 264 | |
265 | 265 | } |
266 | 266 | |
267 | 267 | // Pending payments. |
268 | - if ( $payment_status == 'pending' ) { |
|
268 | + if ($payment_status == 'pending') { |
|
269 | 269 | |
270 | 270 | /* translators: %s: pending reason. */ |
271 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
271 | + $invoice->update_status('wpi-onhold', sprintf(__('Payment pending (%s).', 'invoicing'), $posted['pending_reason'])); |
|
272 | 272 | |
273 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
273 | + return wpinv_error_log('Invoice marked as "payment held".', false); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /* translators: %s: payment status. */ |
277 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
277 | + $invoice->update_status('wpi-failed', sprintf(__('Payment %s via IPN.', 'invoicing'), sanitize_text_field($posted['payment_status']))); |
|
278 | 278 | |
279 | 279 | } |
280 | 280 | |
@@ -284,8 +284,8 @@ discard block |
||
284 | 284 | * @param WPInv_Invoice $invoice Invoice object. |
285 | 285 | * @param array $posted Posted data. |
286 | 286 | */ |
287 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
288 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
287 | + protected function ipn_txn_cart($invoice, $posted) { |
|
288 | + $this->ipn_txn_web_accept($invoice, $posted); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
@@ -294,43 +294,43 @@ discard block |
||
294 | 294 | * @param WPInv_Invoice $invoice Invoice object. |
295 | 295 | * @param array $posted Posted data. |
296 | 296 | */ |
297 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
297 | + protected function ipn_txn_subscr_signup($invoice, $posted) { |
|
298 | 298 | |
299 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
299 | + wpinv_error_log('Processing subscription signup', false); |
|
300 | 300 | |
301 | 301 | // Make sure the invoice has a subscription. |
302 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
302 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
303 | 303 | |
304 | - if ( empty( $subscription ) ) { |
|
305 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
304 | + if (empty($subscription)) { |
|
305 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
306 | 306 | } |
307 | 307 | |
308 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
308 | + wpinv_error_log('Found subscription #' . $subscription->get_id(), false); |
|
309 | 309 | |
310 | 310 | // Validate the IPN. |
311 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
312 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
313 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
311 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
312 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
313 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
314 | 314 | |
315 | 315 | // Activate the subscription. |
316 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
317 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
318 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
319 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
316 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
317 | + $subscription->set_date_created(current_time('mysql')); |
|
318 | + $subscription->set_expiration(date('Y-m-d H:i:s', (current_time('timestamp') + $duration))); |
|
319 | + $subscription->set_profile_id(sanitize_text_field($posted['subscr_id'])); |
|
320 | 320 | $subscription->activate(); |
321 | 321 | |
322 | 322 | // Set the transaction id. |
323 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
324 | - $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
325 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
323 | + if (!empty($posted['txn_id'])) { |
|
324 | + $invoice->add_note(sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
325 | + $invoice->set_transaction_id($posted['txn_id']); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | // Update the payment status. |
329 | 329 | $invoice->mark_paid(); |
330 | 330 | |
331 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
331 | + $invoice->add_note(sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
332 | 332 | |
333 | - wpinv_error_log( 'Subscription started.', false ); |
|
333 | + wpinv_error_log('Subscription started.', false); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
@@ -339,45 +339,45 @@ discard block |
||
339 | 339 | * @param WPInv_Invoice $invoice Invoice object. |
340 | 340 | * @param array $posted Posted data. |
341 | 341 | */ |
342 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
342 | + protected function ipn_txn_subscr_payment($invoice, $posted) { |
|
343 | 343 | |
344 | 344 | // Make sure the invoice has a subscription. |
345 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
345 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
346 | 346 | |
347 | - if ( empty( $subscription ) ) { |
|
348 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
347 | + if (empty($subscription)) { |
|
348 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
349 | 349 | } |
350 | 350 | |
351 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
351 | + wpinv_error_log('Found subscription #' . $subscription->get_id(), false); |
|
352 | 352 | |
353 | 353 | // PayPal sends a subscr_payment for the first payment too. |
354 | - $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
355 | - $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
356 | - $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
357 | - $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
358 | - $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
359 | - $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
354 | + $date_completed = getpaid_format_date($invoice->get_date_completed()); |
|
355 | + $date_created = getpaid_format_date($invoice->get_date_created()); |
|
356 | + $today_date = getpaid_format_date(current_time('mysql')); |
|
357 | + $payment_date = getpaid_format_date($posted['payment_date']); |
|
358 | + $subscribe_date = getpaid_format_date($subscription->get_date_created()); |
|
359 | + $dates = array_filter(compact('date_completed', 'date_created', 'subscribe_date')); |
|
360 | 360 | |
361 | - foreach ( $dates as $date ) { |
|
361 | + foreach ($dates as $date) { |
|
362 | 362 | |
363 | - if ( $date !== $today_date && $date !== $payment_date ) { |
|
363 | + if ($date !== $today_date && $date !== $payment_date) { |
|
364 | 364 | continue; |
365 | 365 | } |
366 | 366 | |
367 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
368 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
369 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
367 | + if (!empty($posted['txn_id'])) { |
|
368 | + $invoice->set_transaction_id(sanitize_text_field($posted['txn_id'])); |
|
369 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), sanitize_text_field($posted['txn_id'])), false, false, true); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | return $invoice->mark_paid(); |
373 | 373 | |
374 | 374 | } |
375 | 375 | |
376 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
376 | + wpinv_error_log('Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false); |
|
377 | 377 | |
378 | 378 | // Abort if the payment is already recorded. |
379 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
380 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false ); |
|
379 | + if (wpinv_get_id_by_transaction_id($posted['txn_id'])) { |
|
380 | + return wpinv_error_log('Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | $args = array( |
@@ -385,17 +385,17 @@ discard block |
||
385 | 385 | 'gateway' => $this->id, |
386 | 386 | ); |
387 | 387 | |
388 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
388 | + $invoice = wpinv_get_invoice($subscription->add_payment($args)); |
|
389 | 389 | |
390 | - if ( empty( $invoice ) ) { |
|
390 | + if (empty($invoice)) { |
|
391 | 391 | return; |
392 | 392 | } |
393 | 393 | |
394 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
395 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
394 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
395 | + $invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
396 | 396 | |
397 | 397 | $subscription->renew(); |
398 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
398 | + wpinv_error_log('Subscription renewed.', false); |
|
399 | 399 | |
400 | 400 | } |
401 | 401 | |
@@ -404,18 +404,18 @@ discard block |
||
404 | 404 | * |
405 | 405 | * @param WPInv_Invoice $invoice Invoice object. |
406 | 406 | */ |
407 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
407 | + protected function ipn_txn_subscr_cancel($invoice) { |
|
408 | 408 | |
409 | 409 | // Make sure the invoice has a subscription. |
410 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
410 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
411 | 411 | |
412 | - if ( empty( $subscription ) ) { |
|
413 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
412 | + if (empty($subscription)) { |
|
413 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
414 | 414 | } |
415 | 415 | |
416 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
416 | + wpinv_error_log('Processing subscription cancellation for the invoice ' . $invoice->get_id(), false); |
|
417 | 417 | $subscription->cancel(); |
418 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
418 | + wpinv_error_log('Subscription cancelled.', false); |
|
419 | 419 | |
420 | 420 | } |
421 | 421 | |
@@ -425,18 +425,18 @@ discard block |
||
425 | 425 | * @param WPInv_Invoice $invoice Invoice object. |
426 | 426 | * @param array $posted Posted data. |
427 | 427 | */ |
428 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
428 | + protected function ipn_txn_subscr_eot($invoice) { |
|
429 | 429 | |
430 | 430 | // Make sure the invoice has a subscription. |
431 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
431 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
432 | 432 | |
433 | - if ( empty( $subscription ) ) { |
|
434 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
433 | + if (empty($subscription)) { |
|
434 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
435 | 435 | } |
436 | 436 | |
437 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
437 | + wpinv_error_log('Processing subscription end of life for the invoice ' . $invoice->get_id(), false); |
|
438 | 438 | $subscription->complete(); |
439 | - wpinv_error_log( 'Subscription completed.', false ); |
|
439 | + wpinv_error_log('Subscription completed.', false); |
|
440 | 440 | |
441 | 441 | } |
442 | 442 | |
@@ -446,18 +446,18 @@ discard block |
||
446 | 446 | * @param WPInv_Invoice $invoice Invoice object. |
447 | 447 | * @param array $posted Posted data. |
448 | 448 | */ |
449 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
449 | + protected function ipn_txn_subscr_failed($invoice) { |
|
450 | 450 | |
451 | 451 | // Make sure the invoice has a subscription. |
452 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
452 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
453 | 453 | |
454 | - if ( empty( $subscription ) ) { |
|
455 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
454 | + if (empty($subscription)) { |
|
455 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
456 | 456 | } |
457 | 457 | |
458 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
458 | + wpinv_error_log('Processing subscription payment failure for the invoice ' . $invoice->get_id(), false); |
|
459 | 459 | $subscription->failing(); |
460 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
460 | + wpinv_error_log('Subscription marked as failing.', false); |
|
461 | 461 | |
462 | 462 | } |
463 | 463 | |
@@ -467,18 +467,18 @@ discard block |
||
467 | 467 | * @param WPInv_Invoice $invoice Invoice object. |
468 | 468 | * @param array $posted Posted data. |
469 | 469 | */ |
470 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
470 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment($invoice) { |
|
471 | 471 | |
472 | 472 | // Make sure the invoice has a subscription. |
473 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
473 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
474 | 474 | |
475 | - if ( empty( $subscription ) ) { |
|
476 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
475 | + if (empty($subscription)) { |
|
476 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
477 | 477 | } |
478 | 478 | |
479 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
479 | + wpinv_error_log('Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false); |
|
480 | 480 | $subscription->cancel(); |
481 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
481 | + wpinv_error_log('Subscription cancelled.', false); |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | } |