1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Give Form Template |
4
|
|
|
* |
5
|
|
|
* @package Give |
6
|
|
|
* @subpackage Forms |
7
|
|
|
* @copyright Copyright (c) 2016, GiveWP |
8
|
|
|
* @license https://opensource.org/licenses/gpl-license GNU Public License |
9
|
|
|
* @since 1.0 |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
// Exit if accessed directly. |
13
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
14
|
|
|
exit; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Get Donation Form. |
19
|
|
|
* |
20
|
|
|
* @param array $args An array of form arguments. |
21
|
|
|
* |
22
|
|
|
* @return string Donation form. |
23
|
|
|
* @since 1.0 |
24
|
|
|
* |
25
|
|
|
*/ |
26
|
|
|
function give_get_donation_form( $args = array() ) { |
27
|
|
|
|
28
|
|
|
global $post; |
29
|
|
|
static $count = 1; |
30
|
|
|
|
31
|
|
|
$args = wp_parse_args( $args, give_get_default_form_shortcode_args() ); |
32
|
|
|
|
33
|
|
|
// Backward compatibility for `form_id` function param. |
34
|
|
|
// If are calling this function directly with `form_id` the use `id` instead. |
35
|
|
|
$args['id'] = ! empty( $args['form_id'] ) ? absint( $args['form_id'] ) : $args['id']; |
36
|
|
|
|
37
|
|
|
// If `id` does not set then maybe we are single donation form page, so lets render form. |
38
|
|
|
if ( empty( $args['id'] ) && is_object( $post ) && $post->ID ) { |
39
|
|
|
$args['id'] = $post->ID; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
// set `form_id` for backward compatibility because many filter and function using it. |
43
|
|
|
$args['form_id'] = $args['id']; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Fire the filter |
47
|
|
|
* Note: we will deprecated this filter soon. Use give_get_default_form_shortcode_args instead |
48
|
|
|
* |
49
|
|
|
* @deprecated 2.4.1 |
50
|
|
|
*/ |
51
|
|
|
$args = apply_filters( 'give_form_args_defaults', $args ); |
52
|
|
|
|
53
|
|
|
$form = new Give_Donate_Form( $args['id'] ); |
54
|
|
|
|
55
|
|
|
// Bail out, if no form ID. |
56
|
|
|
if ( empty( $form->ID ) ) { |
57
|
|
|
return false; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$args['id_prefix'] = "{$form->ID}-{$count}"; |
61
|
|
|
$payment_mode = give_get_chosen_gateway( $form->ID ); |
62
|
|
|
|
63
|
|
|
$form_action = add_query_arg( |
64
|
|
|
apply_filters( |
65
|
|
|
'give_form_action_args', array( |
66
|
|
|
'payment-mode' => $payment_mode, |
67
|
|
|
) |
68
|
|
|
), |
69
|
|
|
give_get_current_page_url() |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
// Sanity Check: Donation form not published or user doesn't have permission to view drafts. |
73
|
|
|
if ( |
74
|
|
|
( 'publish' !== $form->post_status && ! current_user_can( 'edit_give_forms', $form->ID ) ) |
75
|
|
|
|| ( 'trash' === $form->post_status ) |
76
|
|
|
) { |
77
|
|
|
return false; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
// Get the form wrap CSS classes. |
81
|
|
|
$form_wrap_classes = $form->get_form_wrap_classes( $args ); |
82
|
|
|
|
83
|
|
|
// Get the <form> tag wrap CSS classes. |
84
|
|
|
$form_classes = $form->get_form_classes( $args ); |
85
|
|
|
|
86
|
|
|
ob_start(); |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Fires while outputting donation form, before the form wrapper div. |
90
|
|
|
* |
91
|
|
|
* @param int Give_Donate_Form::ID The form ID. |
92
|
|
|
* @param array $args An array of form arguments. |
93
|
|
|
* |
94
|
|
|
* @since 1.0 |
95
|
|
|
* |
96
|
|
|
*/ |
97
|
|
|
do_action( 'give_pre_form_output', $form->ID, $args, $form ); |
98
|
|
|
|
99
|
|
|
?> |
100
|
|
|
<div id="give-form-<?php echo $form->ID; ?>-wrap" class="<?php echo $form_wrap_classes; ?>"> |
101
|
|
|
<?php |
102
|
|
|
if ( $form->is_close_donation_form() ) { |
103
|
|
|
|
104
|
|
|
$form_title = ! is_singular( 'give_forms' ) ? apply_filters( 'give_form_title', '<h2 class="give-form-title">' . get_the_title( $form->ID ) . '</h2>' ) : ''; |
105
|
|
|
|
106
|
|
|
// Get Goal thank you message. |
107
|
|
|
$goal_achieved_message = get_post_meta( $form->ID, '_give_form_goal_achieved_message', true ); |
108
|
|
|
$goal_achieved_message = ! empty( $goal_achieved_message ) ? $form_title . apply_filters( 'the_content', $goal_achieved_message ) : ''; |
109
|
|
|
|
110
|
|
|
// Print thank you message. |
111
|
|
|
echo apply_filters( 'give_goal_closed_output', $goal_achieved_message, $form->ID, $form ); |
112
|
|
|
|
113
|
|
|
} else { |
114
|
|
|
/** |
115
|
|
|
* Show form title: |
116
|
|
|
* 1. if admin set form display_style to button or modal |
117
|
|
|
*/ |
118
|
|
|
$form_title = apply_filters( 'give_form_title', '<h2 class="give-form-title">' . get_the_title( $form->ID ) . '</h2>' ); |
119
|
|
|
|
120
|
|
|
if ( ! doing_action( 'give_single_form_summary' ) && true === $args['show_title'] ) { |
121
|
|
|
echo $form_title; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Fires while outputting donation form, before the form. |
126
|
|
|
* |
127
|
|
|
* @param int Give_Donate_Form::ID The form ID. |
128
|
|
|
* @param array $args An array of form arguments. |
129
|
|
|
* @param Give_Donate_Form $form Form object. |
130
|
|
|
* |
131
|
|
|
* @since 1.0 |
132
|
|
|
* |
133
|
|
|
*/ |
134
|
|
|
do_action( 'give_pre_form', $form->ID, $args, $form ); |
135
|
|
|
|
136
|
|
|
// Set form html tags. |
137
|
|
|
$form_html_tags = array( |
138
|
|
|
'id' => "give-form-{$args['id_prefix']}", |
139
|
|
|
'class' => $form_classes, |
140
|
|
|
'action' => esc_url_raw( $form_action ), |
141
|
|
|
'data-id' => $args['id_prefix'], |
142
|
|
|
); |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Filter the form html tags. |
146
|
|
|
* |
147
|
|
|
* @param array $form_html_tags Array of form html tags. |
148
|
|
|
* @param Give_Donate_Form $form Form object. |
149
|
|
|
* |
150
|
|
|
* @since 1.8.17 |
151
|
|
|
* |
152
|
|
|
*/ |
153
|
|
|
$form_html_tags = apply_filters( 'give_form_html_tags', (array) $form_html_tags, $form ); |
154
|
|
|
?> |
155
|
|
|
<form <?php echo give_get_attribute_str( $form_html_tags ); ?> method="post"> |
156
|
|
|
<!-- The following field is for robots only, invisible to humans: --> |
157
|
|
|
<span class="give-hidden" style="display: none !important;"> |
158
|
|
|
<label for="give-form-honeypot-<?php echo $form->ID; ?>"></label> |
159
|
|
|
<input id="give-form-honeypot-<?php echo $form->ID; ?>" type="text" name="give-honeypot" |
160
|
|
|
class="give-honeypot give-hidden"/> |
161
|
|
|
</span> |
162
|
|
|
|
163
|
|
|
<?php |
164
|
|
|
/** |
165
|
|
|
* Fires while outputting donation form, before all other fields. |
166
|
|
|
* |
167
|
|
|
* @param int Give_Donate_Form::ID The form ID. |
168
|
|
|
* @param array $args An array of form arguments. |
169
|
|
|
* @param Give_Donate_Form $form Form object. |
170
|
|
|
* |
171
|
|
|
* @since 1.0 |
172
|
|
|
* |
173
|
|
|
*/ |
174
|
|
|
do_action( 'give_donation_form_top', $form->ID, $args, $form ); |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Fires while outputting donation form, for payment gateway fields. |
178
|
|
|
* |
179
|
|
|
* @param int Give_Donate_Form::ID The form ID. |
180
|
|
|
* @param array $args An array of form arguments. |
181
|
|
|
* @param Give_Donate_Form $form Form object. |
182
|
|
|
* |
183
|
|
|
* @since 1.7 |
184
|
|
|
* |
185
|
|
|
*/ |
186
|
|
|
do_action( 'give_payment_mode_select', $form->ID, $args, $form ); |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Fires while outputting donation form, after all other fields. |
190
|
|
|
* |
191
|
|
|
* @param int Give_Donate_Form::ID The form ID. |
192
|
|
|
* @param array $args An array of form arguments. |
193
|
|
|
* @param Give_Donate_Form $form Form object. |
194
|
|
|
* |
195
|
|
|
* @since 1.0 |
196
|
|
|
* |
197
|
|
|
*/ |
198
|
|
|
do_action( 'give_donation_form_bottom', $form->ID, $args, $form ); |
199
|
|
|
|
200
|
|
|
?> |
201
|
|
|
</form> |
202
|
|
|
|
203
|
|
|
<?php |
204
|
|
|
/** |
205
|
|
|
* Fires while outputting donation form, after the form. |
206
|
|
|
* |
207
|
|
|
* @param int Give_Donate_Form::ID The form ID. |
208
|
|
|
* @param array $args An array of form arguments. |
209
|
|
|
* @param Give_Donate_Form $form Form object. |
210
|
|
|
* |
211
|
|
|
* @since 1.0 |
212
|
|
|
* |
213
|
|
|
*/ |
214
|
|
|
do_action( 'give_post_form', $form->ID, $args, $form ); |
215
|
|
|
|
216
|
|
|
} |
217
|
|
|
?> |
218
|
|
|
|
219
|
|
|
</div><!--end #give-form-<?php echo absint( $form->ID ); ?>--> |
220
|
|
|
<?php |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Fires while outputting donation form, after the form wrapper div. |
224
|
|
|
* |
225
|
|
|
* @param int Give_Donate_Form::ID The form ID. |
226
|
|
|
* @param array $args An array of form arguments. |
227
|
|
|
* |
228
|
|
|
* @since 1.0 |
229
|
|
|
* |
230
|
|
|
*/ |
231
|
|
|
do_action( 'give_post_form_output', $form->ID, $args ); |
232
|
|
|
|
233
|
|
|
$final_output = ob_get_clean(); |
234
|
|
|
$count ++; |
235
|
|
|
|
236
|
|
|
echo apply_filters( 'give_donate_form', $final_output, $args ); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Give Show Donation Form. |
241
|
|
|
* |
242
|
|
|
* Renders the Donation Form, hooks are provided to add to the checkout form. |
243
|
|
|
* The default Donation Form rendered displays a list of the enabled payment |
244
|
|
|
* gateways, a user registration form (if enable) and a credit card info form |
245
|
|
|
* if credit cards are enabled. |
246
|
|
|
* |
247
|
|
|
* @param int $form_id The form ID. |
248
|
|
|
* |
249
|
|
|
* @return string |
250
|
|
|
* @since 1.0 |
251
|
|
|
* |
252
|
|
|
*/ |
253
|
|
|
function give_show_purchase_form( $form_id, $args ) { |
254
|
|
|
|
255
|
|
|
$payment_mode = give_get_chosen_gateway( $form_id ); |
256
|
|
|
|
257
|
|
|
if ( ! isset( $form_id ) && isset( $_POST['give_form_id'] ) ) { |
258
|
|
|
$form_id = $_POST['give_form_id']; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* Fire before donation form render. |
263
|
|
|
* |
264
|
|
|
* @since 1.7 |
265
|
|
|
*/ |
266
|
|
|
do_action( 'give_payment_fields_top', $form_id ); |
267
|
|
|
|
268
|
|
|
if ( give_can_checkout() && isset( $form_id ) ) { |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* Fires while displaying donation form, before registration login. |
272
|
|
|
* |
273
|
|
|
* @since 1.7 |
274
|
|
|
*/ |
275
|
|
|
do_action( 'give_donation_form_before_register_login', $form_id, $args ); |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* Fire when register/login form fields render. |
279
|
|
|
* |
280
|
|
|
* @since 1.7 |
281
|
|
|
*/ |
282
|
|
|
do_action( 'give_donation_form_register_login_fields', $form_id, $args ); |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* Fire when credit card form fields render. |
286
|
|
|
* |
287
|
|
|
* @since 1.7 |
288
|
|
|
*/ |
289
|
|
|
do_action( 'give_donation_form_before_cc_form', $form_id, $args ); |
290
|
|
|
|
291
|
|
|
// Load the credit card form and allow gateways to load their own if they wish. |
292
|
|
|
if ( has_action( 'give_' . $payment_mode . '_cc_form' ) ) { |
293
|
|
|
/** |
294
|
|
|
* Fires while displaying donation form, credit card form fields for a given gateway. |
295
|
|
|
* |
296
|
|
|
* @param int $form_id The form ID. |
297
|
|
|
* |
298
|
|
|
* @since 1.0 |
299
|
|
|
* |
300
|
|
|
*/ |
301
|
|
|
do_action( "give_{$payment_mode}_cc_form", $form_id, $args ); |
302
|
|
|
} else { |
303
|
|
|
/** |
304
|
|
|
* Fires while displaying donation form, credit card form fields. |
305
|
|
|
* |
306
|
|
|
* @param int $form_id The form ID. |
307
|
|
|
* |
308
|
|
|
* @since 1.0 |
309
|
|
|
* |
310
|
|
|
*/ |
311
|
|
|
do_action( 'give_cc_form', $form_id, $args ); |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* Fire after credit card form fields render. |
316
|
|
|
* |
317
|
|
|
* @since 1.7 |
318
|
|
|
*/ |
319
|
|
|
do_action( 'give_donation_form_after_cc_form', $form_id, $args ); |
320
|
|
|
|
321
|
|
|
} else { |
322
|
|
|
/** |
323
|
|
|
* Fire if user can not donate. |
324
|
|
|
* |
325
|
|
|
* @since 1.7 |
326
|
|
|
*/ |
327
|
|
|
do_action( 'give_donation_form_no_access', $form_id ); |
328
|
|
|
|
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* Fire after donation form rendered. |
333
|
|
|
* |
334
|
|
|
* @since 1.7 |
335
|
|
|
*/ |
336
|
|
|
do_action( 'give_payment_fields_bottom', $form_id, $args ); |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
add_action( 'give_donation_form', 'give_show_purchase_form', 10, 2 ); |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* Give Show Login/Register Form Fields. |
343
|
|
|
* |
344
|
|
|
* @param int $form_id The form ID. |
345
|
|
|
* |
346
|
|
|
* @return void |
347
|
|
|
* @since 1.4.1 |
348
|
|
|
* |
349
|
|
|
*/ |
350
|
|
|
function give_show_register_login_fields( $form_id ) { |
351
|
|
|
|
352
|
|
|
$show_register_form = give_show_login_register_option( $form_id ); |
353
|
|
|
|
354
|
|
|
if ( ( $show_register_form === 'registration' || ( $show_register_form === 'both' && ! isset( $_GET['login'] ) ) ) && ! is_user_logged_in() ) : |
355
|
|
|
?> |
356
|
|
|
<div id="give-checkout-login-register-<?php echo $form_id; ?>"> |
357
|
|
|
<?php |
358
|
|
|
/** |
359
|
|
|
* Fire if user registration form render. |
360
|
|
|
* |
361
|
|
|
* @since 1.7 |
362
|
|
|
*/ |
363
|
|
|
do_action( 'give_donation_form_register_fields', $form_id ); |
364
|
|
|
?> |
365
|
|
|
</div> |
366
|
|
|
<?php |
367
|
|
|
elseif ( ( $show_register_form === 'login' || ( $show_register_form === 'both' && isset( $_GET['login'] ) ) ) && ! is_user_logged_in() ) : |
368
|
|
|
?> |
369
|
|
|
<div id="give-checkout-login-register-<?php echo $form_id; ?>"> |
370
|
|
|
<?php |
371
|
|
|
/** |
372
|
|
|
* Fire if user login form render. |
373
|
|
|
* |
374
|
|
|
* @since 1.7 |
375
|
|
|
*/ |
376
|
|
|
do_action( 'give_donation_form_login_fields', $form_id ); |
377
|
|
|
?> |
378
|
|
|
</div> |
379
|
|
|
<?php |
380
|
|
|
endif; |
381
|
|
|
|
382
|
|
|
if ( ( ! isset( $_GET['login'] ) && is_user_logged_in() ) || ! isset( $show_register_form ) || 'none' === $show_register_form || 'login' === $show_register_form ) { |
383
|
|
|
/** |
384
|
|
|
* Fire when user info render. |
385
|
|
|
* |
386
|
|
|
* @since 1.7 |
387
|
|
|
*/ |
388
|
|
|
do_action( 'give_donation_form_after_user_info', $form_id ); |
389
|
|
|
} |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
add_action( 'give_donation_form_register_login_fields', 'give_show_register_login_fields' ); |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* Donation Amount Field. |
396
|
|
|
* |
397
|
|
|
* Outputs the donation amount field that appears at the top of the donation forms. If the user has custom amount |
398
|
|
|
* enabled the field will output as a customizable input. |
399
|
|
|
* |
400
|
|
|
* @param int $form_id The form ID. |
401
|
|
|
* @param array $args An array of form arguments. |
402
|
|
|
* |
403
|
|
|
* @return void |
404
|
|
|
* @since 1.0 |
405
|
|
|
* |
406
|
|
|
*/ |
407
|
|
|
function give_output_donation_amount_top( $form_id = 0, $args = array() ) { |
408
|
|
|
|
409
|
|
|
$give_options = give_get_settings(); |
410
|
|
|
$variable_pricing = give_has_variable_prices( $form_id ); |
411
|
|
|
$allow_custom_amount = give_get_meta( $form_id, '_give_custom_amount', true ); |
412
|
|
|
$currency_position = isset( $give_options['currency_position'] ) ? $give_options['currency_position'] : 'before'; |
413
|
|
|
$symbol = give_currency_symbol( give_get_currency( $form_id, $args ) ); |
414
|
|
|
$currency_output = '<span class="give-currency-symbol give-currency-position-' . $currency_position . '">' . $symbol . '</span>'; |
415
|
|
|
$default_amount = give_format_amount( |
416
|
|
|
give_get_default_form_amount( $form_id ), array( |
417
|
|
|
'sanitize' => false, |
418
|
|
|
'currency' => give_get_currency( $form_id ), |
419
|
|
|
) |
420
|
|
|
); |
421
|
|
|
$custom_amount_text = give_get_meta( $form_id, '_give_custom_amount_text', true ); |
422
|
|
|
|
423
|
|
|
/** |
424
|
|
|
* Fires while displaying donation form, before donation level fields. |
425
|
|
|
* |
426
|
|
|
* @param int $form_id The form ID. |
427
|
|
|
* @param array $args An array of form arguments. |
428
|
|
|
* |
429
|
|
|
* @since 1.0 |
430
|
|
|
* |
431
|
|
|
*/ |
432
|
|
|
do_action( 'give_before_donation_levels', $form_id, $args ); |
433
|
|
|
|
434
|
|
|
// Set Price, No Custom Amount Allowed means hidden price field. |
435
|
|
|
if ( ! give_is_setting_enabled( $allow_custom_amount ) ) { |
436
|
|
|
?> |
437
|
|
|
<label class="give-hidden" for="give-amount"><?php esc_html_e( 'Donation Amount:', 'give' ); ?></label> |
438
|
|
|
<input id="give-amount" class="give-amount-hidden" type="hidden" name="give-amount" |
439
|
|
|
value="<?php echo $default_amount; ?>" required aria-required="true"/> |
440
|
|
|
<div class="set-price give-donation-amount form-row-wide"> |
441
|
|
|
<?php |
442
|
|
|
if ( 'before' === $currency_position ) { |
443
|
|
|
echo $currency_output; |
444
|
|
|
} |
445
|
|
|
?> |
446
|
|
|
<span id="give-amount-text" class="give-text-input give-amount-top"><?php echo $default_amount; ?></span> |
447
|
|
|
<?php |
448
|
|
|
if ( 'after' === $currency_position ) { |
449
|
|
|
echo $currency_output; |
450
|
|
|
} |
451
|
|
|
?> |
452
|
|
|
</div> |
453
|
|
|
<?php |
454
|
|
|
} else { |
455
|
|
|
// Custom Amount Allowed. |
456
|
|
|
?> |
457
|
|
|
<div class="give-total-wrap"> |
458
|
|
|
<div class="give-donation-amount form-row-wide"> |
459
|
|
|
<?php |
460
|
|
|
if ( 'before' === $currency_position ) { |
461
|
|
|
echo $currency_output; |
462
|
|
|
} |
463
|
|
|
?> |
464
|
|
|
<label class="give-hidden" for="give-amount"><?php esc_html_e( 'Donation Amount:', 'give' ); ?></label> |
465
|
|
|
<input class="give-text-input give-amount-top" id="give-amount" name="give-amount" type="tel" |
466
|
|
|
placeholder="" value="<?php echo $default_amount; ?>" autocomplete="off"> |
467
|
|
|
<?php |
468
|
|
|
if ( 'after' === $currency_position ) { |
469
|
|
|
echo $currency_output; |
470
|
|
|
} |
471
|
|
|
?> |
472
|
|
|
</div> |
473
|
|
|
</div> |
474
|
|
|
<?php |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
/** |
478
|
|
|
* Fires while displaying donation form, after donation amounf field(s). |
479
|
|
|
* |
480
|
|
|
* @param int $form_id The form ID. |
481
|
|
|
* @param array $args An array of form arguments. |
482
|
|
|
* |
483
|
|
|
* @since 1.0 |
484
|
|
|
* |
485
|
|
|
*/ |
486
|
|
|
do_action( 'give_after_donation_amount', $form_id, $args ); |
487
|
|
|
|
488
|
|
|
// Custom Amount Text |
489
|
|
|
if ( ! $variable_pricing && give_is_setting_enabled( $allow_custom_amount ) && ! empty( $custom_amount_text ) ) { |
490
|
|
|
?> |
491
|
|
|
<p class="give-custom-amount-text"><?php echo $custom_amount_text; ?></p> |
492
|
|
|
<?php |
493
|
|
|
} |
494
|
|
|
|
495
|
|
|
// Output Variable Pricing Levels. |
496
|
|
|
if ( $variable_pricing ) { |
497
|
|
|
give_output_levels( $form_id ); |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
/** |
501
|
|
|
* Fires while displaying donation form, after donation level fields. |
502
|
|
|
* |
503
|
|
|
* @param int $form_id The form ID. |
504
|
|
|
* @param array $args An array of form arguments. |
505
|
|
|
* |
506
|
|
|
* @since 1.0 |
507
|
|
|
* |
508
|
|
|
*/ |
509
|
|
|
do_action( 'give_after_donation_levels', $form_id, $args ); |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
add_action( 'give_donation_form_top', 'give_output_donation_amount_top', 10, 2 ); |
513
|
|
|
|
514
|
|
|
/** |
515
|
|
|
* Outputs the Donation Levels in various formats such as dropdown, radios, and buttons. |
516
|
|
|
* |
517
|
|
|
* @param int $form_id The form ID. |
518
|
|
|
* |
519
|
|
|
* @return string Donation levels. |
520
|
|
|
* @since 1.0 |
521
|
|
|
* |
522
|
|
|
*/ |
523
|
|
|
function give_output_levels( $form_id ) { |
524
|
|
|
|
525
|
|
|
/** |
526
|
|
|
* Filter the variable pricing |
527
|
|
|
* |
528
|
|
|
* @param array $prices Array of variable prices. |
529
|
|
|
* @param int $form Form ID. |
530
|
|
|
* |
531
|
|
|
* @since 1.0 |
532
|
|
|
* @deprecated 2.2 Use give_get_donation_levels filter instead of give_form_variable_prices. |
533
|
|
|
* Check Give_Donate_Form::get_prices(). |
534
|
|
|
* |
535
|
|
|
*/ |
536
|
|
|
$prices = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $form_id ), $form_id ); |
537
|
|
|
|
538
|
|
|
$display_style = give_get_meta( $form_id, '_give_display_style', true ); |
539
|
|
|
$custom_amount = give_get_meta( $form_id, '_give_custom_amount', true ); |
540
|
|
|
$custom_amount_text = give_get_meta( $form_id, '_give_custom_amount_text', true ); |
541
|
|
|
|
542
|
|
|
if ( empty( $custom_amount_text ) ) { |
543
|
|
|
$custom_amount_text = esc_html__( 'Give a Custom Amount', 'give' ); |
544
|
|
|
} |
545
|
|
|
|
546
|
|
|
$output = ''; |
547
|
|
|
|
548
|
|
|
switch ( $display_style ) { |
549
|
|
View Code Duplication |
case 'buttons': |
|
|
|
|
550
|
|
|
$output .= '<ul id="give-donation-level-button-wrap" class="give-donation-levels-wrap give-list-inline">'; |
551
|
|
|
|
552
|
|
|
foreach ( $prices as $price ) { |
553
|
|
|
$level_text = apply_filters( 'give_form_level_text', ! empty( $price['_give_text'] ) ? $price['_give_text'] : give_currency_filter( give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ), array( 'currency_code' => give_get_currency( $form_id ) ) ), $form_id, $price ); |
554
|
|
|
$level_classes = apply_filters( 'give_form_level_classes', 'give-donation-level-btn give-btn give-btn-level-' . $price['_give_id']['level_id'] . ' ' . ( give_is_default_level_id( $price ) ? 'give-default-level' : '' ), $form_id, $price ); |
555
|
|
|
|
556
|
|
|
$formatted_amount = give_format_amount( |
557
|
|
|
$price['_give_amount'], array( |
558
|
|
|
'sanitize' => false, |
559
|
|
|
'currency' => give_get_currency( $form_id ), |
560
|
|
|
) |
561
|
|
|
); |
562
|
|
|
|
563
|
|
|
$output .= sprintf( |
564
|
|
|
'<li><button type="button" data-price-id="%1$s" class="%2$s" value="%3$s" data-default="%4$s">%5$s</button></li>', |
565
|
|
|
$price['_give_id']['level_id'], |
566
|
|
|
$level_classes, |
567
|
|
|
$formatted_amount, |
568
|
|
|
array_key_exists( '_give_default', $price ) ? 1 : 0, |
569
|
|
|
$level_text |
570
|
|
|
); |
571
|
|
|
} |
572
|
|
|
|
573
|
|
|
// Custom Amount. |
574
|
|
|
if ( |
575
|
|
|
give_is_setting_enabled( $custom_amount ) |
576
|
|
|
&& ! empty( $custom_amount_text ) |
577
|
|
|
) { |
578
|
|
|
|
579
|
|
|
$output .= sprintf( |
580
|
|
|
'<li><button type="button" data-price-id="custom" class="give-donation-level-btn give-btn give-btn-level-custom" value="custom">%1$s</button></li>', |
581
|
|
|
$custom_amount_text |
582
|
|
|
); |
583
|
|
|
} |
584
|
|
|
|
585
|
|
|
$output .= '</ul>'; |
586
|
|
|
|
587
|
|
|
break; |
588
|
|
|
|
589
|
|
View Code Duplication |
case 'radios': |
|
|
|
|
590
|
|
|
$output .= '<ul id="give-donation-level-radio-list" class="give-donation-levels-wrap">'; |
591
|
|
|
|
592
|
|
|
foreach ( $prices as $price ) { |
593
|
|
|
$level_text = apply_filters( 'give_form_level_text', ! empty( $price['_give_text'] ) ? $price['_give_text'] : give_currency_filter( give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ), array( 'currency_code' => give_get_currency( $form_id ) ) ), $form_id, $price ); |
594
|
|
|
$level_classes = apply_filters( 'give_form_level_classes', 'give-radio-input give-radio-input-level give-radio-level-' . $price['_give_id']['level_id'] . ( give_is_default_level_id( $price ) ? ' give-default-level' : '' ), $form_id, $price ); |
595
|
|
|
|
596
|
|
|
$formatted_amount = give_format_amount( |
597
|
|
|
$price['_give_amount'], array( |
598
|
|
|
'sanitize' => false, |
599
|
|
|
'currency' => give_get_currency( $form_id ), |
600
|
|
|
) |
601
|
|
|
); |
602
|
|
|
|
603
|
|
|
$output .= sprintf( |
604
|
|
|
'<li><input type="radio" data-price-id="%1$s" class="%2$s" value="%3$s" name="give-radio-donation-level" id="give-radio-level-%1$s" %4$s data-default="%5$s"><label for="give-radio-level-%1$s">%6$s</label></li>', |
605
|
|
|
$price['_give_id']['level_id'], |
606
|
|
|
$level_classes, |
607
|
|
|
$formatted_amount, |
608
|
|
|
( give_is_default_level_id( $price ) ? 'checked="checked"' : '' ), |
609
|
|
|
array_key_exists( '_give_default', $price ) ? 1 : 0, |
610
|
|
|
$level_text |
611
|
|
|
); |
612
|
|
|
} |
613
|
|
|
|
614
|
|
|
// Custom Amount. |
615
|
|
|
if ( |
616
|
|
|
give_is_setting_enabled( $custom_amount ) |
617
|
|
|
&& ! empty( $custom_amount_text ) |
618
|
|
|
) { |
619
|
|
|
$output .= sprintf( |
620
|
|
|
'<li><input type="radio" data-price-id="custom" class="give-radio-input give-radio-input-level give-radio-level-custom" name="give-radio-donation-level" id="give-radio-level-custom" value="custom"><label for="give-radio-level-custom">%1$s</label></li>', |
621
|
|
|
$custom_amount_text |
622
|
|
|
); |
623
|
|
|
} |
624
|
|
|
|
625
|
|
|
$output .= '</ul>'; |
626
|
|
|
|
627
|
|
|
break; |
628
|
|
|
|
629
|
|
|
case 'dropdown': |
630
|
|
|
$output .= '<label for="give-donation-level-select-' . $form_id . '" class="give-hidden">' . esc_html__( 'Choose Your Donation Amount', 'give' ) . ':</label>'; |
631
|
|
|
$output .= '<select id="give-donation-level-select-' . $form_id . '" class="give-select give-select-level give-donation-levels-wrap">'; |
632
|
|
|
|
633
|
|
|
// first loop through prices. |
634
|
|
|
foreach ( $prices as $price ) { |
635
|
|
|
$level_text = apply_filters( 'give_form_level_text', ! empty( $price['_give_text'] ) ? $price['_give_text'] : give_currency_filter( give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ), array( 'currency_code' => give_get_currency( $form_id ) ) ), $form_id, $price ); |
636
|
|
|
$level_classes = apply_filters( |
637
|
|
|
'give_form_level_classes', 'give-donation-level-' . $price['_give_id']['level_id'] . ( give_is_default_level_id( $price ) ? ' give-default-level' : '' ), $form_id, |
638
|
|
|
$price |
639
|
|
|
); |
640
|
|
|
|
641
|
|
|
$formatted_amount = give_format_amount( |
642
|
|
|
$price['_give_amount'], array( |
643
|
|
|
'sanitize' => false, |
644
|
|
|
'currency' => give_get_currency( $form_id ), |
645
|
|
|
) |
646
|
|
|
); |
647
|
|
|
|
648
|
|
|
$output .= sprintf( |
649
|
|
|
'<option data-price-id="%1$s" class="%2$s" value="%3$s" %4$s data-default="%5$s">%6$s</option>', |
650
|
|
|
$price['_give_id']['level_id'], |
651
|
|
|
$level_classes, |
652
|
|
|
$formatted_amount, |
653
|
|
|
( give_is_default_level_id( $price ) ? 'selected="selected"' : '' ), |
654
|
|
|
array_key_exists( '_give_default', $price ) ? 1 : 0, |
655
|
|
|
$level_text |
656
|
|
|
); |
657
|
|
|
} |
658
|
|
|
|
659
|
|
|
// Custom Amount. |
660
|
|
|
if ( give_is_setting_enabled( $custom_amount ) && ! empty( $custom_amount_text ) ) { |
661
|
|
|
$output .= sprintf( |
662
|
|
|
'<option data-price-id="custom" class="give-donation-level-custom" value="custom">%1$s</option>', |
663
|
|
|
$custom_amount_text |
664
|
|
|
); |
665
|
|
|
} |
666
|
|
|
|
667
|
|
|
$output .= '</select>'; |
668
|
|
|
|
669
|
|
|
break; |
670
|
|
|
} |
671
|
|
|
|
672
|
|
|
echo apply_filters( 'give_form_level_output', $output, $form_id ); |
673
|
|
|
} |
674
|
|
|
|
675
|
|
|
/** |
676
|
|
|
* Display Reveal & Lightbox Button. |
677
|
|
|
* |
678
|
|
|
* Outputs a button to reveal form fields. |
679
|
|
|
* |
680
|
|
|
* @param int $form_id The form ID. |
681
|
|
|
* @param array $args An array of form arguments. |
682
|
|
|
* |
683
|
|
|
* @return string Checkout button. |
684
|
|
|
* @since 1.0 |
685
|
|
|
* |
686
|
|
|
*/ |
687
|
|
|
function give_display_checkout_button( $form_id, $args ) { |
688
|
|
|
|
689
|
|
|
$display_option = ( isset( $args['display_style'] ) && ! empty( $args['display_style'] ) ) |
690
|
|
|
? $args['display_style'] |
691
|
|
|
: give_get_meta( $form_id, '_give_payment_display', true ); |
692
|
|
|
|
693
|
|
|
if ( 'button' === $display_option ) { |
694
|
|
|
$display_option = 'modal'; |
695
|
|
|
} elseif ( $display_option === 'onpage' ) { |
696
|
|
|
return ''; |
697
|
|
|
} |
698
|
|
|
|
699
|
|
|
$display_label_field = give_get_meta( $form_id, '_give_reveal_label', true ); |
700
|
|
|
$display_label = ! empty( $args['continue_button_title'] ) ? $args['continue_button_title'] : ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) ); |
701
|
|
|
|
702
|
|
|
$output = '<button type="button" class="give-btn give-btn-' . $display_option . '">' . $display_label . '</button>'; |
703
|
|
|
|
704
|
|
|
echo apply_filters( 'give_display_checkout_button', $output ); |
705
|
|
|
} |
706
|
|
|
|
707
|
|
|
add_action( 'give_after_donation_levels', 'give_display_checkout_button', 10, 2 ); |
708
|
|
|
|
709
|
|
|
/** |
710
|
|
|
* Shows the User Info fields in the Personal Info box, more fields can be added via the hooks provided. |
711
|
|
|
* |
712
|
|
|
* @param int $form_id The form ID. |
713
|
|
|
* |
714
|
|
|
* @return void |
715
|
|
|
* @see For Pattern Attribute: https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Form_validation |
716
|
|
|
* |
717
|
|
|
* @since 1.0 |
718
|
|
|
* |
719
|
|
|
*/ |
720
|
|
|
function give_user_info_fields( $form_id ) { |
721
|
|
|
|
722
|
|
|
// Get user info. |
723
|
|
|
$give_user_info = _give_get_prefill_form_field_values( $form_id ); |
724
|
|
|
$title = ! empty( $give_user_info['give_title'] ) ? $give_user_info['give_title'] : ''; |
725
|
|
|
$first_name = ! empty( $give_user_info['give_first'] ) ? $give_user_info['give_first'] : ''; |
726
|
|
|
$last_name = ! empty( $give_user_info['give_last'] ) ? $give_user_info['give_last'] : ''; |
727
|
|
|
$company_name = ! empty( $give_user_info['company_name'] ) ? $give_user_info['company_name'] : ''; |
728
|
|
|
$email = ! empty( $give_user_info['give_email'] ) ? $give_user_info['give_email'] : ''; |
729
|
|
|
$title_prefixes = give_get_name_title_prefixes( $form_id ); |
730
|
|
|
|
731
|
|
|
/** |
732
|
|
|
* Fire before user personal information fields |
733
|
|
|
* |
734
|
|
|
* @since 1.7 |
735
|
|
|
*/ |
736
|
|
|
do_action( 'give_donation_form_before_personal_info', $form_id ); |
737
|
|
|
|
738
|
|
|
$title_prefix_classes = ''; |
739
|
|
|
if ( give_is_name_title_prefix_enabled( $form_id ) ) { |
740
|
|
|
$title_prefix_classes = 'give-title-prefix-wrap'; |
741
|
|
|
} |
742
|
|
|
?> |
743
|
|
|
<fieldset id="give_checkout_user_info" class="<?php echo esc_html( $title_prefix_classes ); ?>"> |
744
|
|
|
<legend> |
745
|
|
|
<?php echo esc_html( apply_filters( 'give_checkout_personal_info_text', __( 'Personal Info', 'give' ) ) ); ?> |
746
|
|
|
</legend> |
747
|
|
|
|
748
|
|
|
<?php if ( give_is_name_title_prefix_enabled( $form_id ) && is_array( $title_prefixes ) && count( $title_prefixes ) > 0 ) { ?> |
749
|
|
|
<p id="give-title-wrap" class="form-row form-row-title form-row-responsive"> |
750
|
|
|
<label class="give-label" for="give-title"> |
751
|
|
|
<?php esc_attr_e( 'Title', 'give' ); ?> |
752
|
|
|
<?php if ( give_field_is_required( 'give_title', $form_id ) ) : ?> |
753
|
|
|
<span class="give-required-indicator">*</span> |
754
|
|
|
<?php endif ?> |
755
|
|
|
<?php echo Give()->tooltips->render_help( __( 'Title is used to personalize your donation record..', 'give' ) ); ?> |
756
|
|
|
</label> |
757
|
|
|
<select |
758
|
|
|
class="give-input required" |
759
|
|
|
type="text" |
760
|
|
|
name="give_title" |
761
|
|
|
id="give-title" |
762
|
|
|
<?php echo( give_field_is_required( 'give_title', $form_id ) ? ' required aria-required="true" ' : '' ); ?> |
763
|
|
|
> |
764
|
|
|
<?php foreach ( $title_prefixes as $key => $value ) { ?> |
765
|
|
|
<option |
766
|
|
|
value="<?php echo esc_html( $value ); ?>" <?php selected( $value, $title, true ); ?>><?php echo esc_html( $value ); ?></option> |
767
|
|
|
<?php } ?> |
768
|
|
|
</select> |
769
|
|
|
</p> |
770
|
|
|
<?php } ?> |
771
|
|
|
|
772
|
|
|
<p id="give-first-name-wrap" class="form-row form-row-first form-row-responsive"> |
773
|
|
|
<label class="give-label" for="give-first"> |
774
|
|
|
<?php esc_attr_e( 'First Name', 'give' ); ?> |
775
|
|
|
<?php if ( give_field_is_required( 'give_first', $form_id ) ) : ?> |
776
|
|
|
<span class="give-required-indicator">*</span> |
777
|
|
|
<?php endif ?> |
778
|
|
|
<?php echo Give()->tooltips->render_help( __( 'First Name is used to personalize your donation record.', 'give' ) ); ?> |
779
|
|
|
</label> |
780
|
|
|
<input |
781
|
|
|
class="give-input required" |
782
|
|
|
type="text" |
783
|
|
|
name="give_first" |
784
|
|
|
autocomplete="given-name" |
785
|
|
|
placeholder="<?php esc_attr_e( 'First Name', 'give' ); ?>" |
786
|
|
|
id="give-first" |
787
|
|
|
value="<?php echo esc_html( $first_name ); ?>" |
788
|
|
|
<?php echo( give_field_is_required( 'give_first', $form_id ) ? ' required aria-required="true" ' : '' ); ?> |
789
|
|
|
/> |
790
|
|
|
</p> |
791
|
|
|
|
792
|
|
|
<p id="give-last-name-wrap" class="form-row form-row-last form-row-responsive"> |
793
|
|
|
<label class="give-label" for="give-last"> |
794
|
|
|
<?php esc_attr_e( 'Last Name', 'give' ); ?> |
795
|
|
|
<?php if ( give_field_is_required( 'give_last', $form_id ) ) : ?> |
796
|
|
|
<span class="give-required-indicator">*</span> |
797
|
|
|
<?php endif ?> |
798
|
|
|
<?php echo Give()->tooltips->render_help( __( 'Last Name is used to personalize your donation record.', 'give' ) ); ?> |
799
|
|
|
</label> |
800
|
|
|
|
801
|
|
|
<input |
802
|
|
|
class="give-input<?php echo( give_field_is_required( 'give_last', $form_id ) ? ' required' : '' ); ?>" |
803
|
|
|
type="text" |
804
|
|
|
name="give_last" |
805
|
|
|
autocomplete="family-name" |
806
|
|
|
id="give-last" |
807
|
|
|
placeholder="<?php esc_attr_e( 'Last Name', 'give' ); ?>" |
808
|
|
|
value="<?php echo esc_html( $last_name ); ?>" |
809
|
|
|
<?php echo( give_field_is_required( 'give_last', $form_id ) ? ' required aria-required="true" ' : '' ); ?> |
810
|
|
|
/> |
811
|
|
|
</p> |
812
|
|
|
|
813
|
|
|
<?php if ( give_is_company_field_enabled( $form_id ) ) : ?> |
814
|
|
|
<?php $give_company = give_field_is_required( 'give_company_name', $form_id ); ?> |
815
|
|
|
<p id="give-company-wrap" class="form-row form-row-wide"> |
816
|
|
|
<label class="give-label" for="give-company"> |
817
|
|
|
<?php esc_attr_e( 'Company Name', 'give' ); ?> |
818
|
|
|
<?php if ( $give_company ) : ?> |
819
|
|
|
<span class="give-required-indicator">*</span> |
820
|
|
|
<?php endif; ?> |
821
|
|
|
<?php echo Give()->tooltips->render_help( __( 'Donate on behalf of Company', 'give' ) ); ?> |
822
|
|
|
</label> |
823
|
|
|
<input |
824
|
|
|
class="give-input<?php echo( $give_company ? ' required' : '' ); ?>" |
825
|
|
|
type="text" |
826
|
|
|
name="give_company_name" |
827
|
|
|
placeholder="<?php esc_attr_e( 'Company Name', 'give' ); ?>" |
828
|
|
|
id="give-company" |
829
|
|
|
value="<?php echo esc_html( $company_name ); ?>" |
830
|
|
|
<?php echo( $give_company ? ' required aria-required="true" ' : '' ); ?> |
831
|
|
|
/> |
832
|
|
|
</p> |
833
|
|
|
<?php endif ?> |
834
|
|
|
|
835
|
|
|
<?php |
836
|
|
|
/** |
837
|
|
|
* Fire before user email field |
838
|
|
|
* |
839
|
|
|
* @since 1.7 |
840
|
|
|
*/ |
841
|
|
|
do_action( 'give_donation_form_before_email', $form_id ); |
842
|
|
|
?> |
843
|
|
|
<p id="give-email-wrap" class="form-row form-row-wide"> |
844
|
|
|
<label class="give-label" for="give-email"> |
845
|
|
|
<?php esc_attr_e( 'Email Address', 'give' ); ?> |
846
|
|
|
<?php if ( give_field_is_required( 'give_email', $form_id ) ) { ?> |
847
|
|
|
<span class="give-required-indicator">*</span> |
848
|
|
|
<?php } ?> |
849
|
|
|
<?php echo Give()->tooltips->render_help( __( 'We will send the donation receipt to this address.', 'give' ) ); ?> |
850
|
|
|
</label> |
851
|
|
|
<input |
852
|
|
|
class="give-input required" |
853
|
|
|
type="email" |
854
|
|
|
name="give_email" |
855
|
|
|
autocomplete="email" |
856
|
|
|
placeholder="<?php esc_attr_e( 'Email Address', 'give' ); ?>" |
857
|
|
|
id="give-email" |
858
|
|
|
value="<?php echo esc_html( $email ); ?>" |
859
|
|
|
<?php echo( give_field_is_required( 'give_email', $form_id ) ? ' required aria-required="true" ' : '' ); ?> |
860
|
|
|
/> |
861
|
|
|
|
862
|
|
|
</p> |
863
|
|
|
|
864
|
|
|
<?php if ( give_is_anonymous_donation_field_enabled( $form_id ) ) : ?> |
865
|
|
|
<?php $is_anonymous_donation = isset( $_POST['give_anonymous_donation'] ) ? absint( $_POST['give_anonymous_donation'] ) : 0; ?> |
866
|
|
|
<p id="give-anonymous-donation-wrap" class="form-row form-row-wide"> |
867
|
|
|
<label class="give-label" for="give-anonymous-donation"> |
868
|
|
|
<input |
869
|
|
|
type="checkbox" |
870
|
|
|
class="give-input<?php echo( give_field_is_required( 'give_anonymous_donation', $form_id ) ? ' required' : '' ); ?>" |
871
|
|
|
name="give_anonymous_donation" |
872
|
|
|
id="give-anonymous-donation" |
873
|
|
|
value="1" |
874
|
|
|
<?php echo( give_field_is_required( 'give_anonymous_donation', $form_id ) ? ' required aria-required="true" ' : '' ); ?> |
875
|
|
|
<?php checked( 1, $is_anonymous_donation ); ?> |
876
|
|
|
> |
877
|
|
|
<?php |
878
|
|
|
/** |
879
|
|
|
* Filters the checkbox label. |
880
|
|
|
* |
881
|
|
|
* @since 2.4.1 |
882
|
|
|
*/ |
883
|
|
|
echo apply_filters( 'give_anonymous_donation_checkbox_label', __( 'Make this an anonymous donation.', 'give' ), $form_id ); |
884
|
|
|
|
885
|
|
|
if ( give_field_is_required( 'give_comment', $form_id ) ) { |
886
|
|
|
?> |
887
|
|
|
<span class="give-required-indicator">*</span> |
888
|
|
|
<?php } ?> |
889
|
|
|
<?php |
890
|
|
|
// Conditional tooltip text when comments enabled: |
891
|
|
|
// https://github.com/impress-org/give/issues/3911 |
892
|
|
|
$anonymous_donation_tooltip = give_is_donor_comment_field_enabled( $form_id ) ? esc_html__( 'Would you like to prevent your name, image, and comment from being displayed publicly?', 'give' ) : esc_html__( 'Would you like to prevent your name and image from being displayed publicly?', 'give' ); |
893
|
|
|
|
894
|
|
|
echo Give()->tooltips->render_help( $anonymous_donation_tooltip ); |
895
|
|
|
?> |
896
|
|
|
|
897
|
|
|
</label> |
898
|
|
|
</p> |
899
|
|
|
<?php endif; ?> |
900
|
|
|
|
901
|
|
|
<?php if ( give_is_donor_comment_field_enabled( $form_id ) ) : ?> |
902
|
|
|
<p id="give-comment-wrap" class="form-row form-row-wide"> |
903
|
|
|
<label class="give-label" for="give-comment"> |
904
|
|
|
<?php _e( 'Comment', 'give' ); ?> |
905
|
|
|
<?php if ( give_field_is_required( 'give_comment', $form_id ) ) { ?> |
906
|
|
|
<span class="give-required-indicator">*</span> |
907
|
|
|
<?php } ?> |
908
|
|
|
<?php echo Give()->tooltips->render_help( __( 'Would you like to add a comment to this donation?', 'give' ) ); ?> |
909
|
|
|
</label> |
910
|
|
|
|
911
|
|
|
<textarea |
912
|
|
|
class="give-input<?php echo( give_field_is_required( 'give_comment', $form_id ) ? ' required' : '' ); ?>" |
913
|
|
|
name="give_comment" |
914
|
|
|
placeholder="<?php _e( 'Leave a comment', 'give' ); ?>" |
915
|
|
|
id="give-comment" |
916
|
|
|
<?php echo( give_field_is_required( 'give_comment', $form_id ) ? ' required aria-required="true" ' : '' ); ?> |
917
|
|
|
><?php echo isset( $_POST['give_comment'] ) ? give_clean( $_POST['give_comment'] ) : ''; ?></textarea> |
918
|
|
|
|
919
|
|
|
</p> |
920
|
|
|
<?php endif; ?> |
921
|
|
|
<?php |
922
|
|
|
/** |
923
|
|
|
* Fire after user email field |
924
|
|
|
* |
925
|
|
|
* @since 1.7 |
926
|
|
|
*/ |
927
|
|
|
do_action( 'give_donation_form_after_email', $form_id ); |
928
|
|
|
|
929
|
|
|
/** |
930
|
|
|
* Fire after personal email field |
931
|
|
|
* |
932
|
|
|
* @since 1.7 |
933
|
|
|
*/ |
934
|
|
|
do_action( 'give_donation_form_user_info', $form_id ); |
935
|
|
|
?> |
936
|
|
|
</fieldset> |
937
|
|
|
<?php |
938
|
|
|
/** |
939
|
|
|
* Fire after user personal information fields |
940
|
|
|
* |
941
|
|
|
* @since 1.7 |
942
|
|
|
*/ |
943
|
|
|
do_action( 'give_donation_form_after_personal_info', $form_id ); |
944
|
|
|
} |
945
|
|
|
|
946
|
|
|
add_action( 'give_donation_form_after_user_info', 'give_user_info_fields' ); |
947
|
|
|
add_action( 'give_register_fields_before', 'give_user_info_fields' ); |
948
|
|
|
|
949
|
|
|
/** |
950
|
|
|
* Renders the credit card info form. |
951
|
|
|
* |
952
|
|
|
* @param int $form_id The form ID. |
953
|
|
|
* |
954
|
|
|
* @return void |
955
|
|
|
* @since 1.0 |
956
|
|
|
* |
957
|
|
|
*/ |
958
|
|
|
function give_get_cc_form( $form_id ) { |
959
|
|
|
|
960
|
|
|
ob_start(); |
961
|
|
|
|
962
|
|
|
/** |
963
|
|
|
* Fires while rendering credit card info form, before the fields. |
964
|
|
|
* |
965
|
|
|
* @param int $form_id The form ID. |
966
|
|
|
* |
967
|
|
|
* @since 1.0 |
968
|
|
|
* |
969
|
|
|
*/ |
970
|
|
|
do_action( 'give_before_cc_fields', $form_id ); |
971
|
|
|
?> |
972
|
|
|
<fieldset id="give_cc_fields-<?php echo $form_id; ?>" class="give-do-validate"> |
973
|
|
|
<legend><?php echo apply_filters( 'give_credit_card_fieldset_heading', esc_html__( 'Credit Card Info', 'give' ) ); ?></legend> |
974
|
|
|
<?php if ( is_ssl() ) : ?> |
975
|
|
|
<div id="give_secure_site_wrapper-<?php echo $form_id; ?>"> |
976
|
|
|
<span class="give-icon padlock"></span> |
977
|
|
|
<span><?php _e( 'This is a secure SSL encrypted payment.', 'give' ); ?></span> |
978
|
|
|
</div> |
979
|
|
|
<?php endif; ?> |
980
|
|
|
<p id="give-card-number-wrap-<?php echo $form_id; ?>" class="form-row form-row-two-thirds form-row-responsive"> |
981
|
|
|
<label for="card_number-<?php echo $form_id; ?>" class="give-label"> |
982
|
|
|
<?php _e( 'Card Number', 'give' ); ?> |
983
|
|
|
<span class="give-required-indicator">*</span> |
984
|
|
|
<?php echo Give()->tooltips->render_help( __( 'The (typically) 16 digits on the front of your credit card.', 'give' ) ); ?> |
985
|
|
|
<span class="card-type"></span> |
986
|
|
|
</label> |
987
|
|
|
|
988
|
|
|
<input type="tel" autocomplete="off" name="card_number" id="card_number-<?php echo $form_id; ?>" |
989
|
|
|
class="card-number give-input required" placeholder="<?php _e( 'Card number', 'give' ); ?>" |
990
|
|
|
required aria-required="true"/> |
991
|
|
|
</p> |
992
|
|
|
|
993
|
|
|
<p id="give-card-cvc-wrap-<?php echo $form_id; ?>" class="form-row form-row-one-third form-row-responsive"> |
994
|
|
|
<label for="card_cvc-<?php echo $form_id; ?>" class="give-label"> |
995
|
|
|
<?php _e( 'CVC', 'give' ); ?> |
996
|
|
|
<span class="give-required-indicator">*</span> |
997
|
|
|
<?php echo Give()->tooltips->render_help( __( 'The 3 digit (back) or 4 digit (front) value on your card.', 'give' ) ); ?> |
998
|
|
|
</label> |
999
|
|
|
|
1000
|
|
|
<input type="tel" size="4" autocomplete="off" name="card_cvc" id="card_cvc-<?php echo $form_id; ?>" |
1001
|
|
|
class="card-cvc give-input required" placeholder="<?php _e( 'Security code', 'give' ); ?>" |
1002
|
|
|
required aria-required="true"/> |
1003
|
|
|
</p> |
1004
|
|
|
|
1005
|
|
|
<p id="give-card-name-wrap-<?php echo $form_id; ?>" class="form-row form-row-two-thirds form-row-responsive"> |
1006
|
|
|
<label for="card_name-<?php echo $form_id; ?>" class="give-label"> |
1007
|
|
|
<?php _e( 'Cardholder Name', 'give' ); ?> |
1008
|
|
|
<span class="give-required-indicator">*</span> |
1009
|
|
|
<?php echo Give()->tooltips->render_help( __( 'The name of the credit card account holder.', 'give' ) ); ?> |
1010
|
|
|
</label> |
1011
|
|
|
|
1012
|
|
|
<input type="text" autocomplete="off" name="card_name" id="card_name-<?php echo $form_id; ?>" |
1013
|
|
|
class="card-name give-input required" placeholder="<?php esc_attr_e( 'Cardholder Name', 'give' ); ?>" |
1014
|
|
|
required aria-required="true"/> |
1015
|
|
|
</p> |
1016
|
|
|
<?php |
1017
|
|
|
/** |
1018
|
|
|
* Fires while rendering credit card info form, before expiration fields. |
1019
|
|
|
* |
1020
|
|
|
* @param int $form_id The form ID. |
1021
|
|
|
* |
1022
|
|
|
* @since 1.0 |
1023
|
|
|
* |
1024
|
|
|
*/ |
1025
|
|
|
do_action( 'give_before_cc_expiration' ); |
1026
|
|
|
?> |
1027
|
|
|
<p class="card-expiration form-row form-row-one-third form-row-responsive"> |
1028
|
|
|
<label for="card_expiry-<?php echo $form_id; ?>" class="give-label"> |
1029
|
|
|
<?php _e( 'Expiration', 'give' ); ?> |
1030
|
|
|
<span class="give-required-indicator">*</span> |
1031
|
|
|
<?php echo Give()->tooltips->render_help( __( 'The date your credit card expires, typically on the front of the card.', 'give' ) ); ?> |
1032
|
|
|
</label> |
1033
|
|
|
|
1034
|
|
|
<input type="hidden" id="card_exp_month-<?php echo $form_id; ?>" name="card_exp_month" |
1035
|
|
|
class="card-expiry-month"/> |
1036
|
|
|
<input type="hidden" id="card_exp_year-<?php echo $form_id; ?>" name="card_exp_year" |
1037
|
|
|
class="card-expiry-year"/> |
1038
|
|
|
|
1039
|
|
|
<input type="tel" autocomplete="off" name="card_expiry" id="card_expiry-<?php echo $form_id; ?>" |
1040
|
|
|
class="card-expiry give-input required" placeholder="<?php esc_attr_e( 'MM / YY', 'give' ); ?>" |
1041
|
|
|
required aria-required="true"/> |
1042
|
|
|
</p> |
1043
|
|
|
<?php |
1044
|
|
|
/** |
1045
|
|
|
* Fires while rendering credit card info form, after expiration fields. |
1046
|
|
|
* |
1047
|
|
|
* @param int $form_id The form ID. |
1048
|
|
|
* |
1049
|
|
|
* @since 1.0 |
1050
|
|
|
* |
1051
|
|
|
*/ |
1052
|
|
|
do_action( 'give_after_cc_expiration', $form_id ); |
1053
|
|
|
?> |
1054
|
|
|
</fieldset> |
1055
|
|
|
<?php |
1056
|
|
|
/** |
1057
|
|
|
* Fires while rendering credit card info form, before the fields. |
1058
|
|
|
* |
1059
|
|
|
* @param int $form_id The form ID. |
1060
|
|
|
* |
1061
|
|
|
* @since 1.0 |
1062
|
|
|
* |
1063
|
|
|
*/ |
1064
|
|
|
do_action( 'give_after_cc_fields', $form_id ); |
1065
|
|
|
|
1066
|
|
|
echo ob_get_clean(); |
1067
|
|
|
} |
1068
|
|
|
|
1069
|
|
|
add_action( 'give_cc_form', 'give_get_cc_form' ); |
1070
|
|
|
|
1071
|
|
|
/** |
1072
|
|
|
* Outputs the default credit card address fields. |
1073
|
|
|
* |
1074
|
|
|
* @param int $form_id The form ID. |
1075
|
|
|
* |
1076
|
|
|
* @return void |
1077
|
|
|
* @since 1.0 |
1078
|
|
|
* |
1079
|
|
|
*/ |
1080
|
|
|
function give_default_cc_address_fields( $form_id ) { |
1081
|
|
|
// Get user info. |
1082
|
|
|
$give_user_info = _give_get_prefill_form_field_values( $form_id ); |
1083
|
|
|
|
1084
|
|
|
ob_start(); |
1085
|
|
|
?> |
1086
|
|
|
<fieldset id="give_cc_address" class="cc-address"> |
1087
|
|
|
<legend><?php echo apply_filters( 'give_billing_details_fieldset_heading', esc_html__( 'Billing Details', 'give' ) ); ?></legend> |
1088
|
|
|
<?php |
1089
|
|
|
/** |
1090
|
|
|
* Fires while rendering credit card billing form, before address fields. |
1091
|
|
|
* |
1092
|
|
|
* @param int $form_id The form ID. |
1093
|
|
|
* |
1094
|
|
|
* @since 1.0 |
1095
|
|
|
* |
1096
|
|
|
*/ |
1097
|
|
|
do_action( 'give_cc_billing_top' ); |
1098
|
|
|
|
1099
|
|
|
// For Country. |
1100
|
|
|
$selected_country = give_get_country(); |
1101
|
|
View Code Duplication |
if ( ! empty( $give_user_info['billing_country'] ) && '*' !== $give_user_info['billing_country'] ) { |
|
|
|
|
1102
|
|
|
$selected_country = $give_user_info['billing_country']; |
1103
|
|
|
} |
1104
|
|
|
$countries = give_get_country_list(); |
1105
|
|
|
|
1106
|
|
|
// For state. |
1107
|
|
|
$selected_state = ''; |
1108
|
|
|
if ( $selected_country === give_get_country() ) { |
1109
|
|
|
// Get default selected state by admin. |
1110
|
|
|
$selected_state = give_get_state(); |
1111
|
|
|
} |
1112
|
|
|
// Get the last payment made by user states. |
1113
|
|
|
if ( ! empty( $give_user_info['card_state'] ) && '*' !== $give_user_info['card_state'] ) { |
1114
|
|
|
$selected_state = $give_user_info['card_state']; |
1115
|
|
|
} |
1116
|
|
|
// Get the country code. |
1117
|
|
View Code Duplication |
if ( ! empty( $give_user_info['billing_country'] ) && '*' !== $give_user_info['billing_country'] ) { |
|
|
|
|
1118
|
|
|
$selected_country = $give_user_info['billing_country']; |
1119
|
|
|
} |
1120
|
|
|
|
1121
|
|
|
|
1122
|
|
|
// Get the country list that does not require city. |
1123
|
|
|
$city_required = ! array_key_exists( $selected_country, give_city_not_required_country_list() ); |
1124
|
|
|
|
1125
|
|
|
?> |
1126
|
|
|
<p id="give-card-country-wrap" class="form-row form-row-wide"> |
1127
|
|
|
<label for="billing_country" class="give-label"> |
1128
|
|
|
<?php esc_html_e( 'Country', 'give' ); ?> |
1129
|
|
|
<?php if ( give_field_is_required( 'billing_country', $form_id ) ) : ?> |
1130
|
|
|
<span class="give-required-indicator">*</span> |
1131
|
|
|
<?php endif; ?> |
1132
|
|
|
<span class="give-tooltip give-icon give-icon-question" |
1133
|
|
|
data-tooltip="<?php esc_attr_e( 'The country for your billing address.', 'give' ); ?>"></span> |
1134
|
|
|
</label> |
1135
|
|
|
|
1136
|
|
|
<select |
1137
|
|
|
name="billing_country" |
1138
|
|
|
autocomplete="country" |
1139
|
|
|
id="billing_country" |
1140
|
|
|
class="billing-country billing_country give-select<?php echo( give_field_is_required( 'billing_country', $form_id ) ? ' required' : '' ); ?>" |
1141
|
|
|
<?php echo( give_field_is_required( 'billing_country', $form_id ) ? ' required aria-required="true" ' : '' ); ?> |
1142
|
|
|
> |
1143
|
|
|
<?php |
1144
|
|
|
foreach ( $countries as $country_code => $country ) { |
1145
|
|
|
echo '<option value="' . esc_attr( $country_code ) . '"' . selected( $country_code, $selected_country, false ) . '>' . $country . '</option>'; |
1146
|
|
|
} |
1147
|
|
|
?> |
1148
|
|
|
</select> |
1149
|
|
|
</p> |
1150
|
|
|
|
1151
|
|
|
<p id="give-card-address-wrap" class="form-row form-row-wide"> |
1152
|
|
|
<label for="card_address" class="give-label"> |
1153
|
|
|
<?php _e( 'Address 1', 'give' ); ?> |
1154
|
|
|
<?php |
1155
|
|
|
if ( give_field_is_required( 'card_address', $form_id ) ) : |
1156
|
|
|
?> |
1157
|
|
|
<span class="give-required-indicator">*</span> |
1158
|
|
|
<?php endif; ?> |
1159
|
|
|
<?php echo Give()->tooltips->render_help( __( 'The primary billing address for your credit card.', 'give' ) ); ?> |
1160
|
|
|
</label> |
1161
|
|
|
|
1162
|
|
|
<input |
1163
|
|
|
type="text" |
1164
|
|
|
id="card_address" |
1165
|
|
|
name="card_address" |
1166
|
|
|
autocomplete="address-line1" |
1167
|
|
|
class="card-address give-input<?php echo( give_field_is_required( 'card_address', $form_id ) ? ' required' : '' ); ?>" |
1168
|
|
|
placeholder="<?php _e( 'Address line 1', 'give' ); ?>" |
1169
|
|
|
value="<?php echo isset( $give_user_info['card_address'] ) ? $give_user_info['card_address'] : ''; ?>" |
1170
|
|
|
<?php echo( give_field_is_required( 'card_address', $form_id ) ? ' required aria-required="true" ' : '' ); ?> |
1171
|
|
|
/> |
1172
|
|
|
</p> |
1173
|
|
|
|
1174
|
|
|
<p id="give-card-address-2-wrap" class="form-row form-row-wide"> |
1175
|
|
|
<label for="card_address_2" class="give-label"> |
1176
|
|
|
<?php _e( 'Address 2', 'give' ); ?> |
1177
|
|
|
<?php if ( give_field_is_required( 'card_address_2', $form_id ) ) : ?> |
1178
|
|
|
<span class="give-required-indicator">*</span> |
1179
|
|
|
<?php endif; ?> |
1180
|
|
|
<?php echo Give()->tooltips->render_help( __( '(optional) The suite, apartment number, post office box (etc) associated with your billing address.', 'give' ) ); ?> |
1181
|
|
|
</label> |
1182
|
|
|
|
1183
|
|
|
<input |
1184
|
|
|
type="text" |
1185
|
|
|
id="card_address_2" |
1186
|
|
|
name="card_address_2" |
1187
|
|
|
autocomplete="address-line2" |
1188
|
|
|
class="card-address-2 give-input<?php echo( give_field_is_required( 'card_address_2', $form_id ) ? ' required' : '' ); ?>" |
1189
|
|
|
placeholder="<?php _e( 'Address line 2', 'give' ); ?>" |
1190
|
|
|
value="<?php echo isset( $give_user_info['card_address_2'] ) ? $give_user_info['card_address_2'] : ''; ?>" |
1191
|
|
|
<?php echo( give_field_is_required( 'card_address_2', $form_id ) ? ' required aria-required="true" ' : '' ); ?> |
1192
|
|
|
/> |
1193
|
|
|
</p> |
1194
|
|
|
|
1195
|
|
|
<p id="give-card-city-wrap" class="form-row form-row-wide"> |
1196
|
|
|
<label for="card_city" class="give-label"> |
1197
|
|
|
<?php _e( 'City', 'give' ); ?> |
1198
|
|
|
<?php if ( give_field_is_required( 'card_city', $form_id ) ) : ?> |
1199
|
|
|
<span class="give-required-indicator <?php echo( $city_required ? '' : 'give-hidden' ); ?>">*</span> |
1200
|
|
|
<?php endif; ?> |
1201
|
|
|
<?php echo Give()->tooltips->render_help( __( 'The city for your billing address.', 'give' ) ); ?> |
1202
|
|
|
</label> |
1203
|
|
|
<input |
1204
|
|
|
type="text" |
1205
|
|
|
id="card_city" |
1206
|
|
|
name="card_city" |
1207
|
|
|
autocomplete="address-level2" |
1208
|
|
|
class="card-city give-input<?php echo( give_field_is_required( 'card_city', $form_id ) ? ' required' : '' ); ?>" |
1209
|
|
|
placeholder="<?php _e( 'City', 'give' ); ?>" |
1210
|
|
|
value="<?php echo( isset( $give_user_info['card_city'] ) ? $give_user_info['card_city'] : '' ); ?>" |
1211
|
|
|
<?php echo( give_field_is_required( 'card_city', $form_id ) && $city_required ? ' required aria-required="true" ' : '' ); ?> |
1212
|
|
|
/> |
1213
|
|
|
</p> |
1214
|
|
|
|
1215
|
|
|
<?php |
1216
|
|
|
/** |
1217
|
|
|
* State field logic. |
1218
|
|
|
*/ |
1219
|
|
|
$state_label = __( 'State', 'give' ); |
1220
|
|
|
$states_label = give_get_states_label(); |
1221
|
|
|
// Check if $country code exists in the array key for states label. |
1222
|
|
|
if ( array_key_exists( $selected_country, $states_label ) ) { |
1223
|
|
|
$state_label = $states_label[ $selected_country ]; |
1224
|
|
|
} |
1225
|
|
|
$states = give_get_states( $selected_country ); |
1226
|
|
|
// Get the country list that do not have any states. |
1227
|
|
|
$no_states_country = give_no_states_country_list(); |
1228
|
|
|
// Get the country list that does not require states. |
1229
|
|
|
$states_not_required_country_list = give_states_not_required_country_list(); |
1230
|
|
|
// Used to determine if state is required. |
1231
|
|
|
$require_state = ! array_key_exists( $selected_country, $no_states_country ) && give_field_is_required( 'card_state', $form_id ); |
1232
|
|
|
|
1233
|
|
|
?> |
1234
|
|
|
<p id="give-card-state-wrap" |
1235
|
|
|
class="form-row form-row-first form-row-responsive <?php echo ( ! empty( $selected_country ) && ! $require_state ) ? 'give-hidden' : ''; ?> "> |
1236
|
|
|
<label for="card_state" class="give-label"> |
1237
|
|
|
<span class="state-label-text"><?php echo $state_label; ?></span> |
1238
|
|
|
<span |
1239
|
|
|
class="give-required-indicator <?php echo array_key_exists( $selected_country, $states_not_required_country_list ) ? 'give-hidden' : ''; ?> ">*</span> |
1240
|
|
|
<span class="give-tooltip give-icon give-icon-question" |
1241
|
|
|
data-tooltip="<?php esc_attr_e( 'The state, province, or county for your billing address.', 'give' ); ?>"></span> |
1242
|
|
|
</label> |
1243
|
|
|
<?php |
1244
|
|
|
|
1245
|
|
|
if ( ! empty( $states ) ) : |
1246
|
|
|
?> |
1247
|
|
|
<select |
1248
|
|
|
name="card_state" |
1249
|
|
|
autocomplete="address-level1" |
1250
|
|
|
id="card_state" |
1251
|
|
|
class="card_state give-select<?php echo $require_state ? ' required' : ''; ?>" |
1252
|
|
|
<?php echo $require_state ? ' required aria-required="true" ' : ''; ?>> |
1253
|
|
|
<?php |
1254
|
|
|
foreach ( $states as $state_code => $state ) { |
1255
|
|
|
echo '<option value="' . $state_code . '"' . selected( $state_code, $selected_state, false ) . '>' . $state . '</option>'; |
1256
|
|
|
} |
1257
|
|
|
?> |
1258
|
|
|
</select> |
1259
|
|
|
<?php else : ?> |
1260
|
|
|
<input type="text" size="6" name="card_state" id="card_state" class="card_state give-input" |
1261
|
|
|
placeholder="<?php echo $state_label; ?>" value="<?php echo $selected_state; ?>" |
1262
|
|
|
<?php echo $require_state ? ' required aria-required="true" ' : ''; ?> |
1263
|
|
|
/> |
1264
|
|
|
<?php endif; ?> |
1265
|
|
|
</p> |
1266
|
|
|
|
1267
|
|
|
<p id="give-card-zip-wrap" class="form-row <?php echo $require_state ? 'form-row-last' : ''; ?> form-row-responsive"> |
1268
|
|
|
<label for="card_zip" class="give-label"> |
1269
|
|
|
<?php _e( 'Zip / Postal Code', 'give' ); ?> |
1270
|
|
|
<?php if ( give_field_is_required( 'card_zip', $form_id ) ) : ?> |
1271
|
|
|
<span class="give-required-indicator">*</span> |
1272
|
|
|
<?php endif; ?> |
1273
|
|
|
<?php echo Give()->tooltips->render_help( __( 'The zip or postal code for your billing address.', 'give' ) ); ?> |
1274
|
|
|
</label> |
1275
|
|
|
|
1276
|
|
|
<input |
1277
|
|
|
type="text" |
1278
|
|
|
size="4" |
1279
|
|
|
id="card_zip" |
1280
|
|
|
name="card_zip" |
1281
|
|
|
autocomplete="postal-code" |
1282
|
|
|
class="card-zip give-input<?php echo( give_field_is_required( 'card_zip', $form_id ) ? ' required' : '' ); ?>" |
1283
|
|
|
placeholder="<?php _e( 'Zip / Postal Code', 'give' ); ?>" |
1284
|
|
|
value="<?php echo isset( $give_user_info['card_zip'] ) ? $give_user_info['card_zip'] : ''; ?>" |
1285
|
|
|
<?php echo( give_field_is_required( 'card_zip', $form_id ) ? ' required aria-required="true" ' : '' ); ?> |
1286
|
|
|
/> |
1287
|
|
|
</p> |
1288
|
|
|
<?php |
1289
|
|
|
/** |
1290
|
|
|
* Fires while rendering credit card billing form, after address fields. |
1291
|
|
|
* |
1292
|
|
|
* @param int $form_id The form ID. |
1293
|
|
|
* |
1294
|
|
|
* @since 1.0 |
1295
|
|
|
* |
1296
|
|
|
*/ |
1297
|
|
|
do_action( 'give_cc_billing_bottom' ); |
1298
|
|
|
?> |
1299
|
|
|
</fieldset> |
1300
|
|
|
<?php |
1301
|
|
|
echo ob_get_clean(); |
1302
|
|
|
} |
1303
|
|
|
|
1304
|
|
|
add_action( 'give_after_cc_fields', 'give_default_cc_address_fields' ); |
1305
|
|
|
|
1306
|
|
|
|
1307
|
|
|
/** |
1308
|
|
|
* Renders the user registration fields. If the user is logged in, a login form is displayed other a registration form |
1309
|
|
|
* is provided for the user to create an account. |
1310
|
|
|
* |
1311
|
|
|
* @param int $form_id The form ID. |
1312
|
|
|
* |
1313
|
|
|
* @return string |
1314
|
|
|
* @since 1.0 |
1315
|
|
|
* |
1316
|
|
|
*/ |
1317
|
|
|
function give_get_register_fields( $form_id ) { |
1318
|
|
|
|
1319
|
|
|
global $user_ID; |
1320
|
|
|
|
1321
|
|
|
if ( is_user_logged_in() ) { |
1322
|
|
|
$user_data = get_userdata( $user_ID ); |
|
|
|
|
1323
|
|
|
} |
1324
|
|
|
|
1325
|
|
|
$show_register_form = give_show_login_register_option( $form_id ); |
1326
|
|
|
|
1327
|
|
|
ob_start(); |
1328
|
|
|
?> |
1329
|
|
|
<fieldset id="give-register-fields-<?php echo $form_id; ?>"> |
1330
|
|
|
|
1331
|
|
|
<?php |
1332
|
|
|
/** |
1333
|
|
|
* Fires while rendering user registration form, before registration fields. |
1334
|
|
|
* |
1335
|
|
|
* @param int $form_id The form ID. |
1336
|
|
|
* |
1337
|
|
|
* @since 1.0 |
1338
|
|
|
* |
1339
|
|
|
*/ |
1340
|
|
|
do_action( 'give_register_fields_before', $form_id ); |
1341
|
|
|
?> |
1342
|
|
|
|
1343
|
|
|
<fieldset id="give-register-account-fields-<?php echo $form_id; ?>"> |
1344
|
|
|
<?php |
1345
|
|
|
/** |
1346
|
|
|
* Fires while rendering user registration form, before account fields. |
1347
|
|
|
* |
1348
|
|
|
* @param int $form_id The form ID. |
1349
|
|
|
* |
1350
|
|
|
* @since 1.0 |
1351
|
|
|
* |
1352
|
|
|
*/ |
1353
|
|
|
do_action( 'give_register_account_fields_before', $form_id ); |
1354
|
|
|
|
1355
|
|
|
$class = ( 'registration' === $show_register_form ) ? 'form-row-wide' : 'form-row-first'; |
1356
|
|
|
?> |
1357
|
|
|
<div id="give-create-account-wrap-<?php echo $form_id; ?>" |
1358
|
|
|
class="form-row <?php echo esc_attr( $class ); ?> form-row-responsive"> |
1359
|
|
|
<label for="give-create-account-<?php echo $form_id; ?>"> |
1360
|
|
|
<?php |
1361
|
|
|
// Add attributes to checkbox, if Guest Checkout is disabled. |
1362
|
|
|
$is_guest_checkout = give_get_meta( $form_id, '_give_logged_in_only', true ); |
1363
|
|
|
$id = 'give-create-account-' . $form_id; |
1364
|
|
|
if ( ! give_is_setting_enabled( $is_guest_checkout ) ) { |
1365
|
|
|
echo Give()->tooltips->render( |
1366
|
|
|
array( |
1367
|
|
|
'tag_content' => sprintf( |
1368
|
|
|
'<input type="checkbox" name="give_create_account" value="on" id="%s" class="give-input give-disabled" checked />', |
1369
|
|
|
$id |
1370
|
|
|
), |
1371
|
|
|
'label' => __( 'Registration is required to donate.', 'give' ), |
1372
|
|
|
) |
1373
|
|
|
); |
1374
|
|
|
} else { |
1375
|
|
|
?> |
1376
|
|
|
<input type="checkbox" name="give_create_account" value="on" id="<?php echo $id; ?>" |
1377
|
|
|
class="give-input"/> |
1378
|
|
|
<?php |
1379
|
|
|
} |
1380
|
|
|
|
1381
|
|
|
_e( 'Create an account', 'give' ); |
1382
|
|
|
echo Give()->tooltips->render_help( __( 'Create an account on the site to see and manage donation history.', 'give' ) ); |
1383
|
|
|
echo str_replace( |
1384
|
|
|
'/>', |
1385
|
|
|
'data-time="' . time() . '" data-nonce-life="' . give_get_nonce_life() . '"/>', |
1386
|
|
|
give_get_nonce_field( "give_form_create_user_nonce_{$form_id}", 'give-form-user-register-hash', false ) |
1387
|
|
|
); |
1388
|
|
|
?> |
1389
|
|
|
</label> |
1390
|
|
|
</div> |
1391
|
|
|
|
1392
|
|
|
<?php if ( 'both' === $show_register_form ) { ?> |
1393
|
|
|
<div class="give-login-account-wrap form-row form-row-last form-row-responsive"> |
1394
|
|
|
<p class="give-login-message"><?php esc_html_e( 'Already have an account?', 'give' ); ?> |
1395
|
|
|
<a href="<?php echo esc_url( add_query_arg( 'login', 1 ) ); ?>" class="give-checkout-login" |
1396
|
|
|
data-action="give_checkout_login"><?php esc_html_e( 'Login', 'give' ); ?></a> |
1397
|
|
|
</p> |
1398
|
|
|
<p class="give-loading-text"> |
1399
|
|
|
<span class="give-loading-animation"></span> |
1400
|
|
|
</p> |
1401
|
|
|
</div> |
1402
|
|
|
<?php } ?> |
1403
|
|
|
|
1404
|
|
|
<?php |
1405
|
|
|
/** |
1406
|
|
|
* Fires while rendering user registration form, after account fields. |
1407
|
|
|
* |
1408
|
|
|
* @param int $form_id The form ID. |
1409
|
|
|
* |
1410
|
|
|
* @since 1.0 |
1411
|
|
|
* |
1412
|
|
|
*/ |
1413
|
|
|
do_action( 'give_register_account_fields_after', $form_id ); |
1414
|
|
|
?> |
1415
|
|
|
</fieldset> |
1416
|
|
|
|
1417
|
|
|
<?php |
1418
|
|
|
/** |
1419
|
|
|
* Fires while rendering user registration form, after registration fields. |
1420
|
|
|
* |
1421
|
|
|
* @param int $form_id The form ID. |
1422
|
|
|
* |
1423
|
|
|
* @since 1.0 |
1424
|
|
|
* |
1425
|
|
|
*/ |
1426
|
|
|
do_action( 'give_register_fields_after', $form_id ); |
1427
|
|
|
?> |
1428
|
|
|
|
1429
|
|
|
<input type="hidden" name="give-purchase-var" value="needs-to-register"/> |
1430
|
|
|
|
1431
|
|
|
<?php |
1432
|
|
|
/** |
1433
|
|
|
* Fire after register or login form render |
1434
|
|
|
* |
1435
|
|
|
* @since 1.7 |
1436
|
|
|
*/ |
1437
|
|
|
do_action( 'give_donation_form_user_info', $form_id ); |
1438
|
|
|
?> |
1439
|
|
|
|
1440
|
|
|
</fieldset> |
1441
|
|
|
<?php |
1442
|
|
|
echo ob_get_clean(); |
1443
|
|
|
} |
1444
|
|
|
|
1445
|
|
|
add_action( 'give_donation_form_register_fields', 'give_get_register_fields' ); |
1446
|
|
|
|
1447
|
|
|
/** |
1448
|
|
|
* Gets the login fields for the login form on the checkout. This function hooks |
1449
|
|
|
* on the give_donation_form_login_fields to display the login form if a user already |
1450
|
|
|
* had an account. |
1451
|
|
|
* |
1452
|
|
|
* @param int $form_id The form ID. |
1453
|
|
|
* |
1454
|
|
|
* @return string |
1455
|
|
|
* @since 1.0 |
1456
|
|
|
* |
1457
|
|
|
*/ |
1458
|
|
|
function give_get_login_fields( $form_id ) { |
1459
|
|
|
|
1460
|
|
|
$form_id = isset( $_POST['form_id'] ) ? $_POST['form_id'] : $form_id; |
1461
|
|
|
$show_register_form = give_show_login_register_option( $form_id ); |
1462
|
|
|
|
1463
|
|
|
ob_start(); |
1464
|
|
|
?> |
1465
|
|
|
<fieldset id="give-login-fields-<?php echo $form_id; ?>"> |
1466
|
|
|
<legend> |
1467
|
|
|
<?php |
1468
|
|
|
echo apply_filters( 'give_account_login_fieldset_heading', __( 'Log In to Your Account', 'give' ) ); |
1469
|
|
|
if ( ! give_logged_in_only( $form_id ) ) { |
1470
|
|
|
echo ' <span class="sub-text">' . __( '(optional)', 'give' ) . '</span>'; |
1471
|
|
|
} |
1472
|
|
|
?> |
1473
|
|
|
</legend> |
1474
|
|
|
<?php if ( $show_register_form == 'both' ) { ?> |
1475
|
|
|
<p class="give-new-account-link"> |
1476
|
|
|
<?php _e( 'Don\'t have an account?', 'give' ); ?> |
1477
|
|
|
<a href="<?php echo remove_query_arg( 'login' ); ?>" class="give-checkout-register-cancel" |
1478
|
|
|
data-action="give_checkout_register"> |
1479
|
|
|
<?php |
1480
|
|
|
if ( give_logged_in_only( $form_id ) ) { |
1481
|
|
|
_e( 'Register as a part of your donation »', 'give' ); |
1482
|
|
|
} else { |
1483
|
|
|
_e( 'Register or donate as a guest »', 'give' ); |
1484
|
|
|
} |
1485
|
|
|
?> |
1486
|
|
|
</a> |
1487
|
|
|
</p> |
1488
|
|
|
<p class="give-loading-text"> |
1489
|
|
|
<span class="give-loading-animation"></span> |
1490
|
|
|
</p> |
1491
|
|
|
<?php } ?> |
1492
|
|
|
<?php |
1493
|
|
|
/** |
1494
|
|
|
* Fires while rendering checkout login form, before the fields. |
1495
|
|
|
* |
1496
|
|
|
* @param int $form_id The form ID. |
1497
|
|
|
* |
1498
|
|
|
* @since 1.0 |
1499
|
|
|
* |
1500
|
|
|
*/ |
1501
|
|
|
do_action( 'give_donation_form_login_fields_before', $form_id ); |
1502
|
|
|
?> |
1503
|
|
|
<div class="give-user-login-fields-container"> |
1504
|
|
|
<div id="give-user-login-wrap-<?php echo $form_id; ?>" class="form-row form-row-first form-row-responsive"> |
1505
|
|
|
<label class="give-label" for="give-user-login-<?php echo $form_id; ?>"> |
1506
|
|
|
<?php _e( 'Username or Email Address', 'give' ); ?> |
1507
|
|
|
<?php if ( give_logged_in_only( $form_id ) ) { ?> |
1508
|
|
|
<span class="give-required-indicator">*</span> |
1509
|
|
|
<?php } ?> |
1510
|
|
|
</label> |
1511
|
|
|
|
1512
|
|
|
<input class="give-input<?php echo ( give_logged_in_only( $form_id ) ) ? ' required' : ''; ?>" |
1513
|
|
|
type="text" |
1514
|
|
|
name="give_user_login" id="give-user-login-<?php echo $form_id; ?>" value="" |
1515
|
|
|
placeholder="<?php _e( 'Your username or email', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/> |
1516
|
|
|
</div> |
1517
|
|
|
|
1518
|
|
|
<div id="give-user-pass-wrap-<?php echo $form_id; ?>" |
1519
|
|
|
class="give_login_password form-row form-row-last form-row-responsive"> |
1520
|
|
|
<label class="give-label" for="give-user-pass-<?php echo $form_id; ?>"> |
1521
|
|
|
<?php _e( 'Password', 'give' ); ?> |
1522
|
|
|
<?php if ( give_logged_in_only( $form_id ) ) { ?> |
1523
|
|
|
<span class="give-required-indicator">*</span> |
1524
|
|
|
<?php } ?> |
1525
|
|
|
</label> |
1526
|
|
|
<input class="give-input<?php echo ( give_logged_in_only( $form_id ) ) ? ' required' : ''; ?>" |
1527
|
|
|
type="password" name="give_user_pass" id="give-user-pass-<?php echo $form_id; ?>" |
1528
|
|
|
placeholder="<?php _e( 'Your password', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/> |
1529
|
|
|
<?php if ( give_logged_in_only( $form_id ) ) : ?> |
1530
|
|
|
<input type="hidden" name="give-purchase-var" value="needs-to-login"/> |
1531
|
|
|
<?php endif; ?> |
1532
|
|
|
</div> |
1533
|
|
|
|
1534
|
|
|
<div id="give-forgot-password-wrap-<?php echo $form_id; ?>" class="give_login_forgot_password"> |
1535
|
|
|
<span class="give-forgot-password "> |
1536
|
|
|
<a href="<?php echo wp_lostpassword_url(); ?>" |
1537
|
|
|
target="_blank"><?php _e( 'Reset Password', 'give' ); ?></a> |
1538
|
|
|
</span> |
1539
|
|
|
</div> |
1540
|
|
|
</div> |
1541
|
|
|
|
1542
|
|
|
|
1543
|
|
|
<div id="give-user-login-submit-<?php echo $form_id; ?>" class="give-clearfix"> |
1544
|
|
|
<input type="submit" class="give-submit give-btn button" name="give_login_submit" |
1545
|
|
|
value="<?php _e( 'Login', 'give' ); ?>"/> |
1546
|
|
|
<?php if ( $show_register_form !== 'login' ) { ?> |
1547
|
|
|
<input type="button" data-action="give_cancel_login" |
1548
|
|
|
class="give-cancel-login give-checkout-register-cancel give-btn button" name="give_login_cancel" |
1549
|
|
|
value="<?php _e( 'Cancel', 'give' ); ?>"/> |
1550
|
|
|
<?php } ?> |
1551
|
|
|
<span class="give-loading-animation"></span> |
1552
|
|
|
</div> |
1553
|
|
|
<?php |
1554
|
|
|
/** |
1555
|
|
|
* Fires while rendering checkout login form, after the fields. |
1556
|
|
|
* |
1557
|
|
|
* @param int $form_id The form ID. |
1558
|
|
|
* |
1559
|
|
|
* @since 1.0 |
1560
|
|
|
* |
1561
|
|
|
*/ |
1562
|
|
|
do_action( 'give_donation_form_login_fields_after', $form_id ); |
1563
|
|
|
?> |
1564
|
|
|
</fieldset><!--end #give-login-fields--> |
1565
|
|
|
<?php |
1566
|
|
|
echo ob_get_clean(); |
1567
|
|
|
} |
1568
|
|
|
|
1569
|
|
|
add_action( 'give_donation_form_login_fields', 'give_get_login_fields', 10, 1 ); |
1570
|
|
|
|
1571
|
|
|
/** |
1572
|
|
|
* Payment Mode Select. |
1573
|
|
|
* |
1574
|
|
|
* Renders the payment mode form by getting all the enabled payment gateways and |
1575
|
|
|
* outputting them as radio buttons for the user to choose the payment gateway. If |
1576
|
|
|
* a default payment gateway has been chosen from the Give Settings, it will be |
1577
|
|
|
* automatically selected. |
1578
|
|
|
* |
1579
|
|
|
* @param int $form_id The form ID. |
1580
|
|
|
* |
1581
|
|
|
* @return void |
1582
|
|
|
* @since 1.0 |
1583
|
|
|
* |
1584
|
|
|
*/ |
1585
|
|
|
function give_payment_mode_select( $form_id, $args ) { |
1586
|
|
|
|
1587
|
|
|
$gateways = give_get_enabled_payment_gateways( $form_id ); |
1588
|
|
|
$id_prefix = ! empty( $args['id_prefix'] ) ? $args['id_prefix'] : ''; |
1589
|
|
|
|
1590
|
|
|
/** |
1591
|
|
|
* Fires while selecting payment gateways, before the fields. |
1592
|
|
|
* |
1593
|
|
|
* @param int $form_id The form ID. |
1594
|
|
|
* |
1595
|
|
|
* @since 1.7 |
1596
|
|
|
* |
1597
|
|
|
*/ |
1598
|
|
|
do_action( 'give_payment_mode_top', $form_id ); |
1599
|
|
|
?> |
1600
|
|
|
|
1601
|
|
|
<fieldset id="give-payment-mode-select" |
1602
|
|
|
<?php |
1603
|
|
|
if ( count( $gateways ) <= 1 ) { |
1604
|
|
|
echo 'style="display: none;"'; |
1605
|
|
|
} |
1606
|
|
|
?> |
1607
|
|
|
> |
1608
|
|
|
<?php |
1609
|
|
|
/** |
1610
|
|
|
* Fires while selecting payment gateways, before the wrap div. |
1611
|
|
|
* |
1612
|
|
|
* @param int $form_id The form ID. |
1613
|
|
|
* |
1614
|
|
|
* @since 1.7 |
1615
|
|
|
* |
1616
|
|
|
*/ |
1617
|
|
|
do_action( 'give_payment_mode_before_gateways_wrap' ); |
1618
|
|
|
?> |
1619
|
|
|
<legend |
1620
|
|
|
class="give-payment-mode-label"><?php echo apply_filters( 'give_checkout_payment_method_text', esc_html__( 'Select Payment Method', 'give' ) ); ?> |
1621
|
|
|
<span class="give-loading-text"><span |
1622
|
|
|
class="give-loading-animation"></span> |
1623
|
|
|
</span> |
1624
|
|
|
</legend> |
1625
|
|
|
|
1626
|
|
|
<div id="give-payment-mode-wrap"> |
1627
|
|
|
<?php |
1628
|
|
|
/** |
1629
|
|
|
* Fires while selecting payment gateways, before the gateways list. |
1630
|
|
|
* |
1631
|
|
|
* @since 1.7 |
1632
|
|
|
*/ |
1633
|
|
|
do_action( 'give_payment_mode_before_gateways' ) |
1634
|
|
|
?> |
1635
|
|
|
<ul id="give-gateway-radio-list"> |
1636
|
|
|
<?php |
1637
|
|
|
/** |
1638
|
|
|
* Loop through the active payment gateways. |
1639
|
|
|
*/ |
1640
|
|
|
$selected_gateway = give_get_chosen_gateway( $form_id ); |
1641
|
|
|
$give_settings = give_get_settings(); |
1642
|
|
|
$gateways_label = array_key_exists( 'gateways_label', $give_settings ) ? |
1643
|
|
|
$give_settings['gateways_label'] : |
1644
|
|
|
array(); |
1645
|
|
|
|
1646
|
|
|
foreach ( $gateways as $gateway_id => $gateway ) : |
1647
|
|
|
// Determine the default gateway. |
1648
|
|
|
$checked = checked( $gateway_id, $selected_gateway, false ); |
1649
|
|
|
$checked_class = $checked ? ' class="give-gateway-option-selected"' : ''; |
1650
|
|
|
$is_payment_method_visible = isset( $gateway['is_visible'] ) ? $gateway['is_visible'] : true; |
1651
|
|
|
|
1652
|
|
|
if ( true === $is_payment_method_visible ) { |
1653
|
|
|
?> |
1654
|
|
|
<li<?php echo $checked_class; ?>> |
1655
|
|
|
<input type="radio" name="payment-mode" class="give-gateway" |
1656
|
|
|
id="give-gateway-<?php echo esc_attr( $gateway_id . '-' . $id_prefix ); ?>" |
1657
|
|
|
value="<?php echo esc_attr( $gateway_id ); ?>"<?php echo $checked; ?>> |
1658
|
|
|
|
1659
|
|
|
<?php |
1660
|
|
|
$label = $gateway['checkout_label']; |
1661
|
|
|
if ( ! empty( $gateways_label[ $gateway_id ] ) ) { |
1662
|
|
|
$label = $gateways_label[ $gateway_id ]; |
1663
|
|
|
} |
1664
|
|
|
?> |
1665
|
|
|
<label for="give-gateway-<?php echo esc_attr( $gateway_id . '-' . $id_prefix ); ?>" |
1666
|
|
|
class="give-gateway-option" |
1667
|
|
|
id="give-gateway-option-<?php echo esc_attr( $gateway_id ); ?>"> <?php echo esc_html( $label ); ?></label> |
1668
|
|
|
</li> |
1669
|
|
|
<?php |
1670
|
|
|
} |
1671
|
|
|
endforeach; |
1672
|
|
|
?> |
1673
|
|
|
</ul> |
1674
|
|
|
<?php |
1675
|
|
|
/** |
1676
|
|
|
* Fires while selecting payment gateways, before the gateways list. |
1677
|
|
|
* |
1678
|
|
|
* @since 1.7 |
1679
|
|
|
*/ |
1680
|
|
|
do_action( 'give_payment_mode_after_gateways' ); |
1681
|
|
|
?> |
1682
|
|
|
</div> |
1683
|
|
|
<?php |
1684
|
|
|
/** |
1685
|
|
|
* Fires while selecting payment gateways, after the wrap div. |
1686
|
|
|
* |
1687
|
|
|
* @param int $form_id The form ID. |
1688
|
|
|
* |
1689
|
|
|
* @since 1.7 |
1690
|
|
|
* |
1691
|
|
|
*/ |
1692
|
|
|
do_action( 'give_payment_mode_after_gateways_wrap' ); |
1693
|
|
|
?> |
1694
|
|
|
</fieldset> |
1695
|
|
|
|
1696
|
|
|
<?php |
1697
|
|
|
/** |
1698
|
|
|
* Fires while selecting payment gateways, after the fields. |
1699
|
|
|
* |
1700
|
|
|
* @param int $form_id The form ID. |
1701
|
|
|
* |
1702
|
|
|
* @since 1.7 |
1703
|
|
|
* |
1704
|
|
|
*/ |
1705
|
|
|
do_action( 'give_payment_mode_bottom', $form_id ); |
1706
|
|
|
?> |
1707
|
|
|
|
1708
|
|
|
<div id="give_purchase_form_wrap"> |
1709
|
|
|
|
1710
|
|
|
<?php |
1711
|
|
|
/** |
1712
|
|
|
* Fire after payment field render. |
1713
|
|
|
* |
1714
|
|
|
* @since 1.7 |
1715
|
|
|
*/ |
1716
|
|
|
do_action( 'give_donation_form', $form_id, $args ); |
1717
|
|
|
?> |
1718
|
|
|
|
1719
|
|
|
</div> |
1720
|
|
|
|
1721
|
|
|
<?php |
1722
|
|
|
/** |
1723
|
|
|
* Fire after donation form render. |
1724
|
|
|
* |
1725
|
|
|
* @since 1.7 |
1726
|
|
|
*/ |
1727
|
|
|
do_action( 'give_donation_form_wrap_bottom', $form_id ); |
1728
|
|
|
} |
1729
|
|
|
|
1730
|
|
|
add_action( 'give_payment_mode_select', 'give_payment_mode_select', 10, 2 ); |
1731
|
|
|
|
1732
|
|
|
/** |
1733
|
|
|
* Renders the Checkout Agree to Terms, this displays a checkbox for users to |
1734
|
|
|
* agree the T&Cs set in the Give Settings. This is only displayed if T&Cs are |
1735
|
|
|
* set in the Give Settings. |
1736
|
|
|
* |
1737
|
|
|
* @param int $form_id The form ID. |
1738
|
|
|
* |
1739
|
|
|
* @return bool |
1740
|
|
|
* @since 1.0 |
1741
|
|
|
* |
1742
|
|
|
*/ |
1743
|
|
|
function give_terms_agreement( $form_id ) { |
1744
|
|
|
$form_option = give_get_meta( $form_id, '_give_terms_option', true ); |
1745
|
|
|
|
1746
|
|
|
// Bailout if per form and global term and conditions is not setup. |
1747
|
|
|
if ( |
1748
|
|
|
give_is_setting_enabled( $form_option, 'global' ) |
1749
|
|
|
&& give_is_setting_enabled( give_get_option( 'terms' ) ) |
1750
|
|
|
) { |
1751
|
|
|
$label = give_get_option( 'agree_to_terms_label', esc_html__( 'Agree to Terms?', 'give' ) ); |
1752
|
|
|
$terms = $terms = give_get_option( 'agreement_text', '' ); |
1753
|
|
|
$edit_term_url = admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=display§ion=term-and-conditions' ); |
1754
|
|
|
|
1755
|
|
|
} elseif ( give_is_setting_enabled( $form_option ) ) { |
1756
|
|
|
$label = ( $label = give_get_meta( $form_id, '_give_agree_label', true ) ) ? stripslashes( $label ) : esc_html__( 'Agree to Terms?', 'give' ); |
1757
|
|
|
$terms = give_get_meta( $form_id, '_give_agree_text', true ); |
1758
|
|
|
$edit_term_url = admin_url( 'post.php?post=' . $form_id . '&action=edit#form_terms_options' ); |
1759
|
|
|
|
1760
|
|
|
} else { |
1761
|
|
|
return false; |
1762
|
|
|
} |
1763
|
|
|
|
1764
|
|
|
// Bailout: Check if term and conditions text is empty or not. |
1765
|
|
|
if ( empty( $terms ) ) { |
1766
|
|
|
if ( is_user_logged_in() && current_user_can( 'edit_give_forms' ) ) { |
1767
|
|
|
echo sprintf( __( 'Please enter valid terms and conditions in <a href="%s">this form\'s settings</a>.', 'give' ), $edit_term_url ); |
1768
|
|
|
} |
1769
|
|
|
|
1770
|
|
|
return false; |
1771
|
|
|
} |
1772
|
|
|
|
1773
|
|
|
/** |
1774
|
|
|
* Filter the form term content |
1775
|
|
|
* |
1776
|
|
|
* @since 2.1.5 |
1777
|
|
|
*/ |
1778
|
|
|
$terms = apply_filters( 'give_the_term_content', wpautop( do_shortcode( $terms ) ), $terms, $form_id ); |
1779
|
|
|
|
1780
|
|
|
?> |
1781
|
|
|
<fieldset id="give_terms_agreement"> |
1782
|
|
|
<legend><?php echo apply_filters( 'give_terms_agreement_text', esc_html__( 'Terms', 'give' ) ); ?></legend> |
1783
|
|
|
<div id="give_terms" class="give_terms-<?php echo $form_id; ?>" style="display:none;"> |
1784
|
|
|
<?php |
1785
|
|
|
/** |
1786
|
|
|
* Fires while rendering terms of agreement, before the fields. |
1787
|
|
|
* |
1788
|
|
|
* @since 1.0 |
1789
|
|
|
*/ |
1790
|
|
|
do_action( 'give_before_terms' ); |
1791
|
|
|
|
1792
|
|
|
echo $terms; |
1793
|
|
|
/** |
1794
|
|
|
* Fires while rendering terms of agreement, after the fields. |
1795
|
|
|
* |
1796
|
|
|
* @since 1.0 |
1797
|
|
|
*/ |
1798
|
|
|
do_action( 'give_after_terms' ); |
1799
|
|
|
?> |
1800
|
|
|
</div> |
1801
|
|
|
<div id="give_show_terms"> |
1802
|
|
|
<a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button" |
1803
|
|
|
aria-controls="give_terms"><?php esc_html_e( 'Show Terms', 'give' ); ?></a> |
1804
|
|
|
<a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button" |
1805
|
|
|
aria-controls="give_terms" style="display:none;"><?php esc_html_e( 'Hide Terms', 'give' ); ?></a> |
1806
|
|
|
</div> |
1807
|
|
|
|
1808
|
|
|
<input name="give_agree_to_terms" class="required" type="checkbox" |
1809
|
|
|
id="give_agree_to_terms-<?php echo $form_id; ?>" value="1" required aria-required="true"/> |
1810
|
|
|
<label for="give_agree_to_terms-<?php echo $form_id; ?>"><?php echo $label; ?></label> |
1811
|
|
|
|
1812
|
|
|
</fieldset> |
1813
|
|
|
<?php |
1814
|
|
|
} |
1815
|
|
|
|
1816
|
|
|
add_action( 'give_donation_form_after_cc_form', 'give_terms_agreement', 8888, 1 ); |
1817
|
|
|
|
1818
|
|
|
/** |
1819
|
|
|
* Checkout Final Total. |
1820
|
|
|
* |
1821
|
|
|
* Shows the final donation total at the bottom of the checkout page. |
1822
|
|
|
* |
1823
|
|
|
* @param int $form_id The form ID. |
1824
|
|
|
* |
1825
|
|
|
* @return void |
1826
|
|
|
* @since 1.0 |
1827
|
|
|
* |
1828
|
|
|
*/ |
1829
|
|
|
function give_checkout_final_total( $form_id ) { |
1830
|
|
|
|
1831
|
|
|
$total = isset( $_POST['give_total'] ) ? |
1832
|
|
|
apply_filters( 'give_donation_total', give_maybe_sanitize_amount( $_POST['give_total'] ) ) : |
1833
|
|
|
give_get_default_form_amount( $form_id ); |
1834
|
|
|
|
1835
|
|
|
// Only proceed if give_total available. |
1836
|
|
|
if ( empty( $total ) ) { |
1837
|
|
|
return; |
1838
|
|
|
} |
1839
|
|
|
?> |
1840
|
|
|
<p id="give-final-total-wrap" class="form-wrap "> |
1841
|
|
|
<?php |
1842
|
|
|
/** |
1843
|
|
|
* Fires before the donation total label |
1844
|
|
|
* |
1845
|
|
|
* @since 2.0.5 |
1846
|
|
|
*/ |
1847
|
|
|
do_action( 'give_donation_final_total_label_before', $form_id ); |
1848
|
|
|
?> |
1849
|
|
|
<span class="give-donation-total-label"> |
1850
|
|
|
<?php echo apply_filters( 'give_donation_total_label', esc_html__( 'Donation Total:', 'give' ) ); ?> |
1851
|
|
|
</span> |
1852
|
|
|
<span class="give-final-total-amount" |
1853
|
|
|
data-total="<?php echo give_format_amount( $total, array( 'sanitize' => false ) ); ?>"> |
1854
|
|
|
<?php |
1855
|
|
|
echo give_currency_filter( |
1856
|
|
|
give_format_amount( |
1857
|
|
|
$total, array( |
1858
|
|
|
'sanitize' => false, |
1859
|
|
|
'currency' => give_get_currency( $form_id ), |
1860
|
|
|
) |
1861
|
|
|
), array( 'currency_code' => give_get_currency( $form_id ) ) |
1862
|
|
|
); |
1863
|
|
|
?> |
1864
|
|
|
</span> |
1865
|
|
|
<?php |
1866
|
|
|
/** |
1867
|
|
|
* Fires after the donation final total label |
1868
|
|
|
* |
1869
|
|
|
* @since 2.0.5 |
1870
|
|
|
*/ |
1871
|
|
|
do_action( 'give_donation_final_total_label_after', $form_id ); |
1872
|
|
|
?> |
1873
|
|
|
</p> |
1874
|
|
|
<?php |
1875
|
|
|
} |
1876
|
|
|
|
1877
|
|
|
add_action( 'give_donation_form_before_submit', 'give_checkout_final_total', 999 ); |
1878
|
|
|
|
1879
|
|
|
/** |
1880
|
|
|
* Renders the Checkout Submit section. |
1881
|
|
|
* |
1882
|
|
|
* @param int $form_id The donation form ID. |
1883
|
|
|
* @param array $args List of arguments. |
1884
|
|
|
* |
1885
|
|
|
* @return void |
1886
|
|
|
* @since 1.0 |
1887
|
|
|
* |
1888
|
|
|
*/ |
1889
|
|
|
function give_checkout_submit( $form_id, $args ) { |
1890
|
|
|
?> |
1891
|
|
|
<fieldset id="give_purchase_submit" class="give-donation-submit"> |
1892
|
|
|
<?php |
1893
|
|
|
/** |
1894
|
|
|
* Fire before donation form submit. |
1895
|
|
|
* |
1896
|
|
|
* @since 1.7 |
1897
|
|
|
*/ |
1898
|
|
|
do_action( 'give_donation_form_before_submit', $form_id, $args ); |
1899
|
|
|
|
1900
|
|
|
give_checkout_hidden_fields( $form_id ); |
1901
|
|
|
|
1902
|
|
|
echo give_get_donation_form_submit_button( $form_id, $args ); |
1903
|
|
|
|
1904
|
|
|
/** |
1905
|
|
|
* Fire after donation form submit. |
1906
|
|
|
* |
1907
|
|
|
* @since 1.7 |
1908
|
|
|
*/ |
1909
|
|
|
do_action( 'give_donation_form_after_submit', $form_id, $args ); |
1910
|
|
|
?> |
1911
|
|
|
</fieldset> |
1912
|
|
|
<?php |
1913
|
|
|
} |
1914
|
|
|
|
1915
|
|
|
add_action( 'give_donation_form_after_cc_form', 'give_checkout_submit', 9999, 2 ); |
1916
|
|
|
|
1917
|
|
|
/** |
1918
|
|
|
* Give Donation form submit button. |
1919
|
|
|
* |
1920
|
|
|
* @param int $form_id The form ID. |
1921
|
|
|
* @param array $args |
1922
|
|
|
* |
1923
|
|
|
* @return string |
1924
|
|
|
* @since 1.8.8 |
1925
|
|
|
* |
1926
|
|
|
*/ |
1927
|
|
|
function give_get_donation_form_submit_button( $form_id, $args = array() ) { |
1928
|
|
|
|
1929
|
|
|
$display_label_field = give_get_meta( $form_id, '_give_checkout_label', true ); |
1930
|
|
|
$display_label = ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) ); |
1931
|
|
|
ob_start(); |
1932
|
|
|
?> |
1933
|
|
|
<div class="give-submit-button-wrap give-clearfix"> |
1934
|
|
|
<input type="submit" class="give-submit give-btn" id="give-purchase-button" name="give-purchase" |
1935
|
|
|
value="<?php echo $display_label; ?>" data-before-validation-label="<?php echo $display_label; ?>"/> |
1936
|
|
|
<span class="give-loading-animation"></span> |
1937
|
|
|
</div> |
1938
|
|
|
<?php |
1939
|
|
|
return apply_filters( 'give_donation_form_submit_button', ob_get_clean(), $form_id, $args ); |
1940
|
|
|
} |
1941
|
|
|
|
1942
|
|
|
/** |
1943
|
|
|
* Show Give Goals. |
1944
|
|
|
* |
1945
|
|
|
* @param int $form_id The form ID. |
1946
|
|
|
* @param array $args An array of form arguments. |
1947
|
|
|
* |
1948
|
|
|
* @return mixed |
1949
|
|
|
* @since 1.6 Add template for Give Goals Shortcode. |
1950
|
|
|
* More info is on https://github.com/impress-org/give/issues/411 |
1951
|
|
|
* |
1952
|
|
|
* @since 1.0 |
1953
|
|
|
*/ |
1954
|
|
|
function give_show_goal_progress( $form_id, $args = array() ) { |
1955
|
|
|
|
1956
|
|
|
ob_start(); |
1957
|
|
|
give_get_template( |
1958
|
|
|
'shortcode-goal', array( |
1959
|
|
|
'form_id' => $form_id, |
1960
|
|
|
'args' => $args, |
1961
|
|
|
) |
1962
|
|
|
); |
1963
|
|
|
|
1964
|
|
|
/** |
1965
|
|
|
* Filter progress bar output |
1966
|
|
|
* |
1967
|
|
|
* @since 2.0 |
1968
|
|
|
*/ |
1969
|
|
|
echo apply_filters( 'give_goal_output', ob_get_clean(), $form_id, $args ); |
1970
|
|
|
|
1971
|
|
|
return true; |
1972
|
|
|
} |
1973
|
|
|
|
1974
|
|
|
add_action( 'give_pre_form', 'give_show_goal_progress', 10, 2 ); |
1975
|
|
|
|
1976
|
|
|
/** |
1977
|
|
|
* Show Give Totals Progress. |
1978
|
|
|
* |
1979
|
|
|
* @param int $total Total amount based on shortcode parameter. |
1980
|
|
|
* @param int $total_goal Total Goal amount passed by Admin. |
1981
|
|
|
* |
1982
|
|
|
* @return mixed |
1983
|
|
|
* @since 2.1 |
1984
|
|
|
* |
1985
|
|
|
*/ |
1986
|
|
|
function give_show_goal_totals_progress( $total, $total_goal ) { |
1987
|
|
|
|
1988
|
|
|
// Bail out if total goal is set as an array. |
1989
|
|
|
if ( isset( $total_goal ) && is_array( $total_goal ) ) { |
1990
|
|
|
return false; |
1991
|
|
|
} |
1992
|
|
|
|
1993
|
|
|
ob_start(); |
1994
|
|
|
give_get_template( |
1995
|
|
|
'shortcode-totals-progress', array( |
1996
|
|
|
'total' => $total, |
1997
|
|
|
'total_goal' => $total_goal, |
1998
|
|
|
) |
1999
|
|
|
); |
2000
|
|
|
|
2001
|
|
|
echo apply_filters( 'give_total_progress_output', ob_get_clean() ); |
2002
|
|
|
|
2003
|
|
|
return true; |
2004
|
|
|
} |
2005
|
|
|
|
2006
|
|
|
add_action( 'give_pre_form', 'give_show_goal_totals_progress', 10, 2 ); |
2007
|
|
|
|
2008
|
|
|
/** |
2009
|
|
|
* Get form content position. |
2010
|
|
|
* |
2011
|
|
|
* @param $form_id |
2012
|
|
|
* @param $args |
2013
|
|
|
* |
2014
|
|
|
* @return mixed|string |
2015
|
|
|
* @since 1.8 |
2016
|
|
|
* |
2017
|
|
|
*/ |
2018
|
|
|
function give_get_form_content_placement( $form_id, $args ) { |
2019
|
|
|
$show_content = ''; |
2020
|
|
|
|
2021
|
|
|
if ( isset( $args['show_content'] ) && ! empty( $args['show_content'] ) ) { |
2022
|
|
|
// Content positions. |
2023
|
|
|
$content_placement = array( |
2024
|
|
|
'above' => 'give_pre_form', |
2025
|
|
|
'below' => 'give_post_form', |
2026
|
|
|
); |
2027
|
|
|
|
2028
|
|
|
// Check if content position already decoded. |
2029
|
|
|
if ( in_array( $args['show_content'], $content_placement ) ) { |
2030
|
|
|
return $args['show_content']; |
2031
|
|
|
} |
2032
|
|
|
|
2033
|
|
|
$show_content = ( 'none' !== $args['show_content'] ? $content_placement[ $args['show_content'] ] : '' ); |
2034
|
|
|
|
2035
|
|
|
} elseif ( give_is_setting_enabled( give_get_meta( $form_id, '_give_display_content', true ) ) ) { |
2036
|
|
|
$show_content = give_get_meta( $form_id, '_give_content_placement', true ); |
2037
|
|
|
|
2038
|
|
|
} |
2039
|
|
|
|
2040
|
|
|
return $show_content; |
2041
|
|
|
} |
2042
|
|
|
|
2043
|
|
|
/** |
2044
|
|
|
* Adds Actions to Render Form Content. |
2045
|
|
|
* |
2046
|
|
|
* @param int $form_id The form ID. |
2047
|
|
|
* @param array $args An array of form arguments. |
2048
|
|
|
* |
2049
|
|
|
* @return void|bool |
2050
|
|
|
* @since 1.0 |
2051
|
|
|
* |
2052
|
|
|
*/ |
2053
|
|
|
function give_form_content( $form_id, $args ) { |
2054
|
|
|
|
2055
|
|
|
$show_content = give_get_form_content_placement( $form_id, $args ); |
2056
|
|
|
|
2057
|
|
|
// Bailout. |
2058
|
|
|
if ( empty( $show_content ) ) { |
2059
|
|
|
return false; |
2060
|
|
|
} |
2061
|
|
|
|
2062
|
|
|
// Add action according to value. |
2063
|
|
|
add_action( $show_content, 'give_form_display_content', 10, 2 ); |
2064
|
|
|
} |
2065
|
|
|
|
2066
|
|
|
add_action( 'give_pre_form_output', 'give_form_content', 10, 2 ); |
2067
|
|
|
|
2068
|
|
|
/** |
2069
|
|
|
* Renders Post Form Content. |
2070
|
|
|
* |
2071
|
|
|
* Displays content for Give forms; fired by action from give_form_content. |
2072
|
|
|
* |
2073
|
|
|
* @param int $form_id The form ID. |
2074
|
|
|
* @param array $args An array of form arguments. |
2075
|
|
|
* |
2076
|
|
|
* @return void |
2077
|
|
|
* @since 1.0 |
2078
|
|
|
* |
2079
|
|
|
*/ |
2080
|
|
|
function give_form_display_content( $form_id, $args ) { |
2081
|
|
|
$content = give_get_meta( $form_id, '_give_form_content', true ); |
2082
|
|
|
$show_content = give_get_form_content_placement( $form_id, $args ); |
2083
|
|
|
|
2084
|
|
|
if ( give_is_setting_enabled( give_get_option( 'the_content_filter' ) ) ) { |
2085
|
|
|
|
2086
|
|
|
// Do not restore wpautop if we are still parsing blocks. |
2087
|
|
|
$priority = has_filter( 'the_content', '_restore_wpautop_hook' ); |
2088
|
|
|
if ( false !== $priority && doing_filter( 'the_content' ) ) { |
2089
|
|
|
remove_filter( 'the_content', '_restore_wpautop_hook', $priority ); |
2090
|
|
|
} |
2091
|
|
|
|
2092
|
|
|
$content = apply_filters( 'the_content', $content ); |
2093
|
|
|
|
2094
|
|
|
// Restore wpautop after done with blocks parsing. |
2095
|
|
|
if ( $priority ) { |
2096
|
|
|
// Run wpautop manually if parsing block |
2097
|
|
|
$content = wpautop( $content ); |
2098
|
|
|
|
2099
|
|
|
add_filter( 'the_content', '_restore_wpautop_hook', $priority ); |
2100
|
|
|
} |
2101
|
|
|
} else { |
2102
|
|
|
$content = wpautop( do_shortcode( $content ) ); |
2103
|
|
|
} |
2104
|
|
|
|
2105
|
|
|
$output = sprintf( |
2106
|
|
|
'<div id="give-form-content-%s" class="give-form-content-wrap %s-content">%s</div>', |
2107
|
|
|
$form_id, |
2108
|
|
|
$show_content, |
2109
|
|
|
$content |
2110
|
|
|
); |
2111
|
|
|
|
2112
|
|
|
/** |
2113
|
|
|
* Filter form content html |
2114
|
|
|
* |
2115
|
|
|
* @param string $output |
2116
|
|
|
* @param int $form_id |
2117
|
|
|
* @param array $args |
2118
|
|
|
* |
2119
|
|
|
* @since 1.0 |
2120
|
|
|
* |
2121
|
|
|
*/ |
2122
|
|
|
echo apply_filters( 'give_form_content_output', $output, $form_id, $args ); |
2123
|
|
|
|
2124
|
|
|
// remove action to prevent content output on addition forms on page. |
2125
|
|
|
// @see: https://github.com/impress-org/give/issues/634. |
2126
|
|
|
remove_action( $show_content, 'give_form_display_content' ); |
2127
|
|
|
} |
2128
|
|
|
|
2129
|
|
|
/** |
2130
|
|
|
* Renders the hidden Checkout fields. |
2131
|
|
|
* |
2132
|
|
|
* @param int $form_id The form ID. |
2133
|
|
|
* |
2134
|
|
|
* @return void |
2135
|
|
|
* @since 1.0 |
2136
|
|
|
* |
2137
|
|
|
*/ |
2138
|
|
|
function give_checkout_hidden_fields( $form_id ) { |
2139
|
|
|
|
2140
|
|
|
/** |
2141
|
|
|
* Fires while rendering hidden checkout fields, before the fields. |
2142
|
|
|
* |
2143
|
|
|
* @param int $form_id The form ID. |
2144
|
|
|
* |
2145
|
|
|
* @since 1.0 |
2146
|
|
|
* |
2147
|
|
|
*/ |
2148
|
|
|
do_action( 'give_hidden_fields_before', $form_id ); |
2149
|
|
|
|
2150
|
|
|
if ( is_user_logged_in() ) { |
2151
|
|
|
?> |
2152
|
|
|
<input type="hidden" name="give-user-id" value="<?php echo get_current_user_id(); ?>"/> |
2153
|
|
|
<?php } ?> |
2154
|
|
|
<input type="hidden" name="give_action" value="purchase"/> |
2155
|
|
|
<input type="hidden" name="give-gateway" value="<?php echo give_get_chosen_gateway( $form_id ); ?>"/> |
2156
|
|
|
<?php |
2157
|
|
|
/** |
2158
|
|
|
* Fires while rendering hidden checkout fields, after the fields. |
2159
|
|
|
* |
2160
|
|
|
* @param int $form_id The form ID. |
2161
|
|
|
* |
2162
|
|
|
* @since 1.0 |
2163
|
|
|
* |
2164
|
|
|
*/ |
2165
|
|
|
do_action( 'give_hidden_fields_after', $form_id ); |
2166
|
|
|
|
2167
|
|
|
} |
2168
|
|
|
|
2169
|
|
|
/** |
2170
|
|
|
* Filter Success Page Content. |
2171
|
|
|
* |
2172
|
|
|
* Applies filters to the success page content. |
2173
|
|
|
* |
2174
|
|
|
* @param string $content Content before filters. |
2175
|
|
|
* |
2176
|
|
|
* @return string $content Filtered content. |
2177
|
|
|
* @since 1.0 |
2178
|
|
|
* |
2179
|
|
|
*/ |
2180
|
|
|
function give_filter_success_page_content( $content ) { |
2181
|
|
|
|
2182
|
|
|
$give_options = give_get_settings(); |
2183
|
|
|
|
2184
|
|
|
if ( isset( $give_options['success_page'] ) && isset( $_GET['payment-confirmation'] ) && is_page( $give_options['success_page'] ) ) { |
2185
|
|
|
if ( has_filter( 'give_payment_confirm_' . $_GET['payment-confirmation'] ) ) { |
2186
|
|
|
$content = apply_filters( 'give_payment_confirm_' . $_GET['payment-confirmation'], $content ); |
2187
|
|
|
} |
2188
|
|
|
} |
2189
|
|
|
|
2190
|
|
|
return $content; |
2191
|
|
|
} |
2192
|
|
|
|
2193
|
|
|
add_filter( 'the_content', 'give_filter_success_page_content' ); |
2194
|
|
|
|
2195
|
|
|
/** |
2196
|
|
|
* Test Mode Frontend Warning. |
2197
|
|
|
* |
2198
|
|
|
* Displays a notice on the frontend for donation forms. |
2199
|
|
|
* |
2200
|
|
|
* @since 1.1 |
2201
|
|
|
*/ |
2202
|
|
|
function give_test_mode_frontend_warning() { |
2203
|
|
|
|
2204
|
|
|
if ( give_is_test_mode() ) { |
2205
|
|
|
echo '<div class="give_error give_warning" id="give_error_test_mode"><p><strong>' . esc_html__( 'Notice:', 'give' ) . '</strong> ' . esc_html__( 'Test mode is enabled. While in test mode no live donations are processed.', 'give' ) . '</p></div>'; |
2206
|
|
|
} |
2207
|
|
|
} |
2208
|
|
|
|
2209
|
|
|
add_action( 'give_pre_form', 'give_test_mode_frontend_warning', 10 ); |
2210
|
|
|
|
2211
|
|
|
/** |
2212
|
|
|
* Members-only Form. |
2213
|
|
|
* |
2214
|
|
|
* If "Disable Guest Donations" and "Display Register / Login" is set to none. |
2215
|
|
|
* |
2216
|
|
|
* @param string $final_output |
2217
|
|
|
* @param array $args |
2218
|
|
|
* |
2219
|
|
|
* @return string |
2220
|
|
|
* @since 1.4.1 |
2221
|
|
|
* |
2222
|
|
|
*/ |
2223
|
|
|
function give_members_only_form( $final_output, $args ) { |
2224
|
|
|
|
2225
|
|
|
$form_id = isset( $args['form_id'] ) ? $args['form_id'] : 0; |
2226
|
|
|
|
2227
|
|
|
// Sanity Check: Must have form_id & not be logged in. |
2228
|
|
|
if ( empty( $form_id ) || is_user_logged_in() ) { |
2229
|
|
|
return $final_output; |
2230
|
|
|
} |
2231
|
|
|
|
2232
|
|
|
// Logged in only and Register / Login set to none. |
2233
|
|
|
if ( give_logged_in_only( $form_id ) && give_show_login_register_option( $form_id ) == 'none' ) { |
2234
|
|
|
|
2235
|
|
|
$final_output = Give_Notices::print_frontend_notice( esc_html__( 'Please log in in order to complete your donation.', 'give' ), false ); |
2236
|
|
|
|
2237
|
|
|
return apply_filters( 'give_members_only_output', $final_output, $form_id ); |
2238
|
|
|
|
2239
|
|
|
} |
2240
|
|
|
|
2241
|
|
|
return $final_output; |
2242
|
|
|
|
2243
|
|
|
} |
2244
|
|
|
|
2245
|
|
|
add_filter( 'give_donate_form', 'give_members_only_form', 10, 2 ); |
2246
|
|
|
|
2247
|
|
|
|
2248
|
|
|
/** |
2249
|
|
|
* Add donation form hidden fields. |
2250
|
|
|
* |
2251
|
|
|
* @param int $form_id |
2252
|
|
|
* @param array $args |
2253
|
|
|
* @param Give_Donate_Form $form |
2254
|
|
|
* |
2255
|
|
|
* @since 1.8.17 |
2256
|
|
|
* |
2257
|
|
|
*/ |
2258
|
|
|
function __give_form_add_donation_hidden_field( $form_id, $args, $form ) { |
2259
|
|
|
$id_prefix = ! empty( $args['id_prefix'] ) ? $args['id_prefix'] : ''; |
2260
|
|
|
?> |
2261
|
|
|
<input type="hidden" name="give-form-id-prefix" value="<?php echo $id_prefix; ?>"/> |
2262
|
|
|
<input type="hidden" name="give-form-id" value="<?php echo intval( $form_id ); ?>"/> |
2263
|
|
|
<input type="hidden" name="give-form-title" value="<?php echo esc_html( $form->post_title ); ?>"/> |
2264
|
|
|
<input type="hidden" name="give-current-url" value="<?php echo esc_url( give_get_current_page_url() ); ?>"/> |
2265
|
|
|
<input type="hidden" name="give-form-url" value="<?php echo esc_url( give_get_current_page_url() ); ?>"/> |
2266
|
|
|
<?php |
2267
|
|
|
// Get the custom option amount. |
2268
|
|
|
$custom_amount = give_get_meta( $form_id, '_give_custom_amount', true ); |
2269
|
|
|
|
2270
|
|
|
// If custom amount enabled. |
2271
|
|
|
if ( give_is_setting_enabled( $custom_amount ) ) { |
2272
|
|
|
?> |
2273
|
|
|
<input type="hidden" name="give-form-minimum" |
2274
|
|
|
value="<?php echo give_maybe_sanitize_amount( give_get_form_minimum_price( $form_id ) ); ?>"/> |
2275
|
|
|
<input type="hidden" name="give-form-maximum" |
2276
|
|
|
value="<?php echo give_maybe_sanitize_amount( give_get_form_maximum_price( $form_id ) ); ?>"/> |
2277
|
|
|
<?php |
2278
|
|
|
} |
2279
|
|
|
|
2280
|
|
|
$data_attr = sprintf( |
2281
|
|
|
'data-time="%1$s" data-nonce-life="%2$s" data-donor-session="%3$s"', |
2282
|
|
|
time(), |
2283
|
|
|
give_get_nonce_life(), |
2284
|
|
|
absint( Give()->session->has_session() ) |
2285
|
|
|
); |
2286
|
|
|
|
2287
|
|
|
// WP nonce field. |
2288
|
|
|
echo str_replace( |
2289
|
|
|
'/>', |
2290
|
|
|
"{$data_attr}/>", |
2291
|
|
|
give_get_nonce_field( "give_donation_form_nonce_{$form_id}", 'give-form-hash', false ) |
2292
|
|
|
); |
2293
|
|
|
|
2294
|
|
|
// Price ID hidden field for variable (multi-level) donation forms. |
2295
|
|
|
if ( give_has_variable_prices( $form_id ) ) { |
2296
|
|
|
// Get the default price ID. |
2297
|
|
|
$default_price = give_form_get_default_level( $form_id ); |
|
|
|
|
2298
|
|
|
$price_id = isset( $default_price['_give_id']['level_id'] ) ? $default_price['_give_id']['level_id'] : 0; |
2299
|
|
|
|
2300
|
|
|
echo sprintf( |
2301
|
|
|
'<input type="hidden" name="give-price-id" value="%s"/>', |
2302
|
|
|
$price_id |
2303
|
|
|
); |
2304
|
|
|
} |
2305
|
|
|
} |
2306
|
|
|
|
2307
|
|
|
add_action( 'give_donation_form_top', '__give_form_add_donation_hidden_field', 0, 3 ); |
2308
|
|
|
|
2309
|
|
|
/** |
2310
|
|
|
* Add currency settings on donation form. |
2311
|
|
|
* |
2312
|
|
|
* @param array $form_html_tags |
2313
|
|
|
* @param Give_Donate_Form $form |
2314
|
|
|
* |
2315
|
|
|
* @return array |
2316
|
|
|
* @since 1.8.17 |
2317
|
|
|
* |
2318
|
|
|
*/ |
2319
|
|
|
function __give_form_add_currency_settings( $form_html_tags, $form ) { |
2320
|
|
|
$form_currency = give_get_currency( $form->ID ); |
2321
|
|
|
$currency_settings = give_get_currency_formatting_settings( $form_currency ); |
2322
|
|
|
|
2323
|
|
|
// Check if currency exist. |
2324
|
|
|
if ( empty( $currency_settings ) ) { |
2325
|
|
|
return $form_html_tags; |
2326
|
|
|
} |
2327
|
|
|
|
2328
|
|
|
$form_html_tags['data-currency_symbol'] = give_currency_symbol( $form_currency ); |
2329
|
|
|
$form_html_tags['data-currency_code'] = $form_currency; |
2330
|
|
|
|
2331
|
|
|
if ( ! empty( $currency_settings ) ) { |
2332
|
|
|
foreach ( $currency_settings as $key => $value ) { |
2333
|
|
|
$form_html_tags["data-{$key}"] = $value; |
2334
|
|
|
} |
2335
|
|
|
} |
2336
|
|
|
|
2337
|
|
|
return $form_html_tags; |
2338
|
|
|
} |
2339
|
|
|
|
2340
|
|
|
add_filter( 'give_form_html_tags', '__give_form_add_currency_settings', 0, 2 ); |
2341
|
|
|
|
2342
|
|
|
/** |
2343
|
|
|
* Adds classes to progress bar container. |
2344
|
|
|
* |
2345
|
|
|
* @param string $class_goal |
2346
|
|
|
* |
2347
|
|
|
* @return string |
2348
|
|
|
* @since 2.1 |
2349
|
|
|
* |
2350
|
|
|
*/ |
2351
|
|
|
function add_give_goal_progress_class( $class_goal ) { |
|
|
|
|
2352
|
|
|
$class_goal = 'progress progress-striped active'; |
2353
|
|
|
|
2354
|
|
|
return $class_goal; |
2355
|
|
|
} |
2356
|
|
|
|
2357
|
|
|
/** |
2358
|
|
|
* Adds classes to progress bar span tag. |
2359
|
|
|
* |
2360
|
|
|
* @param string $class_bar |
2361
|
|
|
* |
2362
|
|
|
* @return string |
2363
|
|
|
* @since 2.1 |
2364
|
|
|
* |
2365
|
|
|
*/ |
2366
|
|
|
function add_give_goal_progress_bar_class( $class_bar ) { |
|
|
|
|
2367
|
|
|
$class_bar = 'bar'; |
2368
|
|
|
|
2369
|
|
|
return $class_bar; |
2370
|
|
|
} |
2371
|
|
|
|
2372
|
|
|
/** |
2373
|
|
|
* Add a class to the form wrap on the grid page. |
2374
|
|
|
* |
2375
|
|
|
* @param array $class Array of form wrapper classes. |
2376
|
|
|
* @param int $id ID of the form. |
2377
|
|
|
* @param array $args Additional args. |
2378
|
|
|
* |
2379
|
|
|
* @return array |
2380
|
|
|
* @since 2.1 |
2381
|
|
|
* |
2382
|
|
|
*/ |
2383
|
|
|
function add_class_for_form_grid( $class, $id, $args ) { |
|
|
|
|
2384
|
|
|
$class[] = 'give-form-grid-wrap'; |
2385
|
|
|
|
2386
|
|
|
foreach ( $class as $index => $item ) { |
2387
|
|
|
if ( false !== strpos( $item, 'give-display-' ) ) { |
2388
|
|
|
unset( $class[ $index ] ); |
2389
|
|
|
} |
2390
|
|
|
} |
2391
|
|
|
|
2392
|
|
|
return $class; |
2393
|
|
|
} |
2394
|
|
|
|
2395
|
|
|
/** |
2396
|
|
|
* Add hidden field to Form Grid page |
2397
|
|
|
* |
2398
|
|
|
* @param int $form_id The form ID. |
|
|
|
|
2399
|
|
|
* @param array $args An array of form arguments. |
2400
|
|
|
* @param Give_Donate_Form $form Form object. |
2401
|
|
|
* |
2402
|
|
|
* @since 2.1 |
2403
|
|
|
*/ |
2404
|
|
|
function give_is_form_grid_page_hidden_field( $id, $args, $form ) { |
|
|
|
|
2405
|
|
|
echo '<input type="hidden" name="is-form-grid" value="true" />'; |
2406
|
|
|
} |
2407
|
|
|
|
2408
|
|
|
/** |
2409
|
|
|
* Redirect to the same paginated URL on the Form Grid page |
2410
|
|
|
* and adds query parameters to open the popup again after |
2411
|
|
|
* redirection. |
2412
|
|
|
* |
2413
|
|
|
* @param string $redirect URL for redirection. |
2414
|
|
|
* @param array $args Array of additional args. |
2415
|
|
|
* |
2416
|
|
|
* @return string |
2417
|
|
|
* @since 2.1 |
2418
|
|
|
*/ |
2419
|
|
|
function give_redirect_and_popup_form( $redirect, $args ) { |
2420
|
|
|
|
2421
|
|
|
// Check the page has Form Grid. |
2422
|
|
|
$is_form_grid = isset( $_POST['is-form-grid'] ) ? give_clean( $_POST['is-form-grid'] ) : ''; |
2423
|
|
|
|
2424
|
|
|
if ( 'true' === $is_form_grid ) { |
2425
|
|
|
|
2426
|
|
|
$payment_mode = give_clean( $_POST['payment-mode'] ); |
2427
|
|
|
$form_id = $args['form-id']; |
2428
|
|
|
|
2429
|
|
|
// Get the URL without Query parameters. |
2430
|
|
|
$redirect = strtok( $redirect, '?' ); |
2431
|
|
|
|
2432
|
|
|
// Add query parameters 'form-id' and 'payment-mode'. |
2433
|
|
|
$redirect = add_query_arg( |
2434
|
|
|
array( |
2435
|
|
|
'form-id' => $form_id, |
2436
|
|
|
'payment-mode' => $payment_mode, |
2437
|
|
|
), $redirect |
2438
|
|
|
); |
2439
|
|
|
} |
2440
|
|
|
|
2441
|
|
|
// Return the modified URL. |
2442
|
|
|
return $redirect; |
2443
|
|
|
} |
2444
|
|
|
|
2445
|
|
|
add_filter( 'give_send_back_to_checkout', 'give_redirect_and_popup_form', 10, 2 ); |
2446
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.