1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* Give Form Template |
4
|
|
|
* |
5
|
|
|
* @package Give |
6
|
|
|
* @subpackage Forms |
7
|
|
|
* @copyright Copyright (c) 2016, WordImpress |
8
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php 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
|
|
|
* @since 1.0 |
21
|
|
|
* |
22
|
|
|
* @param array $args Arguments for display |
23
|
|
|
* |
24
|
|
|
* @return string $purchase_form |
25
|
|
|
*/ |
26
|
|
|
function give_get_donation_form( $args = array() ) { |
27
|
|
|
|
28
|
1 |
|
global $post; |
|
|
|
|
29
|
|
|
|
30
|
1 |
|
$form_id = is_object( $post ) ? $post->ID : 0; |
31
|
|
|
|
32
|
1 |
|
if ( isset( $args['id'] ) ) { |
33
|
1 |
|
$form_id = $args['id']; |
34
|
1 |
|
} |
35
|
|
|
|
36
|
1 |
|
$defaults = apply_filters( 'give_form_args_defaults', array( |
37
|
|
|
'form_id' => $form_id |
38
|
1 |
|
) ); |
39
|
|
|
|
40
|
1 |
|
$args = wp_parse_args( $args, $defaults ); |
41
|
|
|
|
42
|
1 |
|
$form = new Give_Donate_Form( $args['form_id'] ); |
43
|
|
|
|
44
|
|
|
//bail if no form ID |
45
|
1 |
|
if ( empty( $form->ID ) ) { |
46
|
|
|
return false; |
47
|
|
|
} |
48
|
|
|
|
49
|
1 |
|
$payment_mode = give_get_chosen_gateway( $form->ID ); |
50
|
|
|
|
51
|
1 |
|
$form_action = esc_url( add_query_arg( apply_filters( 'give_form_action_args', array( |
52
|
1 |
|
'payment-mode' => $payment_mode, |
53
|
1 |
|
) ), |
54
|
1 |
|
give_get_current_page_url() |
55
|
1 |
|
) ); |
56
|
|
|
|
57
|
|
|
//Sanity Check: Donation form not published or user doesn't have permission to view drafts |
58
|
1 |
|
if ( 'publish' !== $form->post_status && ! current_user_can( 'edit_give_forms', $form->ID ) ) { |
59
|
|
|
return false; |
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
//Get the form wrap CSS classes. |
63
|
1 |
|
$form_wrap_classes = $form->get_form_wrap_classes($args); |
64
|
1 |
|
|
65
|
|
|
//Get the <form> tag wrap CSS classes. |
66
|
1 |
|
$form_classes = $form->get_form_classes($args); |
67
|
1 |
|
|
68
|
1 |
|
ob_start(); |
69
|
|
|
|
70
|
|
|
/** |
71
|
1 |
|
* Fires before the post form outputs. |
72
|
1 |
|
* |
73
|
|
|
* @since 1.0 |
74
|
1 |
|
* |
75
|
1 |
|
* @param int $form ->ID The current form ID |
76
|
|
|
* @param array $args An array of form args |
77
|
|
|
*/ |
78
|
1 |
|
do_action( 'give_pre_form_output', $form->ID, $args ); ?> |
79
|
1 |
|
|
80
|
1 |
|
<div id="give-form-<?php echo $form->ID; ?>-wrap" class="<?php echo $form_wrap_classes; ?>"> |
81
|
|
|
|
82
|
1 |
|
<?php if ( $form->is_close_donation_form() ) { |
83
|
1 |
|
|
84
|
|
|
//Get Goal thank you message. |
85
|
|
|
$display_thankyou_message = get_post_meta( $form->ID, '_give_form_goal_achieved_message', true ); |
86
|
1 |
|
$display_thankyou_message = ! empty( $display_thankyou_message ) ? $display_thankyou_message : esc_html__( 'Thank you to all our donors, we have met our fundraising goal.', 'give' ); |
87
|
|
|
|
88
|
|
|
//Print thank you message. |
89
|
|
|
apply_filters( 'give_goal_closed_output', give_output_error( $display_thankyou_message, true, 'success' ) ); |
90
|
|
|
|
91
|
|
|
} else { |
92
|
|
|
|
93
|
|
|
if ( isset( $args['show_title'] ) && $args['show_title'] == true ) { |
94
|
|
|
|
95
|
|
|
echo apply_filters( 'give_form_title', '<h2 class="give-form-title">' . get_the_title( $form_id ) . '</h2>' ); |
96
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
do_action( 'give_pre_form', $form->ID, $args ); ?> |
100
|
|
|
|
101
|
|
|
<form id="give-form-<?php echo $form_id; ?>" class="<?php echo $form_classes; ?>" action="<?php echo $form_action; ?>" method="post"> |
102
|
|
|
<input type="hidden" name="give-form-id" value="<?php echo $form->ID; ?>"/> |
103
|
|
|
<input type="hidden" name="give-form-title" value="<?php echo htmlentities( $form->post_title ); ?>"/> |
104
|
|
|
<input type="hidden" name="give-current-url" value="<?php echo htmlspecialchars( give_get_current_page_url() ); ?>"/> |
105
|
|
|
<input type="hidden" name="give-form-url" value="<?php echo htmlspecialchars( give_get_current_page_url() ); ?>"/> |
106
|
|
|
<input type="hidden" name="give-form-minimum" value="<?php echo give_format_amount( give_get_form_minimum_price( $form->ID ) ); ?>"/> |
107
|
|
|
|
108
|
|
|
<!-- The following field is for robots only, invisible to humans: --> |
109
|
|
|
<span class="give-hidden" style="display: none !important;"> |
110
|
|
|
<label for="give-form-honeypot-<?php echo $form_id; ?>"></label> |
111
|
1 |
|
<input id="give-form-honeypot-<?php echo $form_id; ?>" type="text" name="give-honeypot" class="give-honeypot give-hidden"/> |
112
|
|
|
</span> |
113
|
|
|
|
114
|
|
|
<?php |
115
|
|
|
|
116
|
|
|
//Price ID hidden field for variable (mult-level) donation forms |
117
|
|
|
if ( give_has_variable_prices( $form_id ) ) { |
118
|
|
|
//get default selected price ID |
119
|
|
|
$prices = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $form_id ), $form_id ); |
120
|
|
|
$price_id = 0; |
121
|
|
|
//loop through prices |
122
|
|
|
foreach ( $prices as $price ) { |
123
|
|
|
if ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) { |
124
|
|
|
$price_id = $price['_give_id']['level_id']; |
125
|
|
|
}; |
126
|
|
|
} |
127
|
|
|
?> |
128
|
|
|
<input type="hidden" name="give-price-id" value="<?php echo $price_id; ?>"/> |
129
|
|
|
<?php } |
130
|
|
|
|
131
|
|
|
do_action( 'give_checkout_form_top', $form->ID, $args ); |
132
|
|
|
|
133
|
|
|
do_action( 'give_payment_mode_select', $form->ID, $args ); |
134
|
|
|
|
135
|
1 |
|
do_action( 'give_checkout_form_bottom', $form->ID, $args ); |
136
|
|
|
|
137
|
1 |
|
?> |
138
|
1 |
|
</form> |
139
|
|
|
|
140
|
1 |
|
<?php do_action( 'give_post_form', $form->ID, $args ); ?> |
141
|
1 |
|
|
142
|
1 |
|
<?php } ?> |
143
|
1 |
|
|
144
|
1 |
|
<!--end #give-form-<?php echo absint( $form->ID ); ?>--></div> |
145
|
|
|
<?php |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Fires after the post form outputs. |
149
|
1 |
|
* |
150
|
|
|
* @since 1.0 |
151
|
1 |
|
* |
152
|
|
|
* @param int $form ->ID The current form ID |
153
|
1 |
|
* @param array $args An array of form args |
154
|
|
|
*/ |
155
|
|
|
do_action( 'give_post_form_output', $form->ID, $args ); |
156
|
|
|
|
157
|
|
|
$final_output = ob_get_clean(); |
158
|
|
|
|
159
|
|
|
echo apply_filters( 'give_donate_form', $final_output, $args ); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* |
165
|
|
|
* Give Show Purchase Form |
166
|
|
|
* |
167
|
|
|
* Renders the Donation Form, hooks are provided to add to the checkout form. |
168
|
|
|
* The default Donation Form rendered displays a list of the enabled payment |
169
|
|
|
* gateways, a user registration form (if enable) and a credit card info form |
170
|
|
|
* if credit cards are enabled |
171
|
|
|
* |
172
|
|
|
* @since 1.0 |
173
|
1 |
|
* |
174
|
|
|
* @param int $form_id ID of the Give Form |
175
|
1 |
|
* |
176
|
|
|
* @return string |
177
|
1 |
|
*/ |
178
|
1 |
|
function give_show_purchase_form( $form_id ) { |
179
|
|
|
|
180
|
|
|
$payment_mode = give_get_chosen_gateway( $form_id ); |
181
|
|
|
|
182
|
|
|
if ( ! isset( $form_id ) && isset( $_POST['give_form_id'] ) ) { |
183
|
|
|
$form_id = $_POST['give_form_id']; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
do_action( 'give_purchase_form_top', $form_id ); |
187
|
|
|
|
188
|
|
|
if ( give_can_checkout() && isset( $form_id ) ) { |
189
|
|
|
|
190
|
|
|
do_action( 'give_purchase_form_before_register_login', $form_id ); |
191
|
|
|
|
192
|
|
|
do_action( 'give_purchase_form_register_login_fields', $form_id ); |
193
|
|
|
|
194
|
|
|
do_action( 'give_purchase_form_before_cc_form', $form_id ); |
195
|
|
|
|
196
|
|
|
// Load the credit card form and allow gateways to load their own if they wish |
197
|
|
|
if ( has_action( 'give_' . $payment_mode . '_cc_form' ) ) { |
198
|
|
|
do_action( 'give_' . $payment_mode . '_cc_form', $form_id ); |
199
|
1 |
|
} else { |
200
|
|
|
do_action( 'give_cc_form', $form_id ); |
201
|
1 |
|
} |
202
|
|
|
|
203
|
|
|
do_action( 'give_purchase_form_after_cc_form', $form_id ); |
204
|
|
|
|
205
|
1 |
|
} else { |
206
|
|
|
// Can't checkout |
207
|
1 |
|
do_action( 'give_purchase_form_no_access', $form_id ); |
208
|
|
|
|
209
|
1 |
|
} |
210
|
|
|
|
211
|
1 |
|
do_action( 'give_purchase_form_bottom', $form_id ); |
212
|
|
|
} |
213
|
1 |
|
|
214
|
|
|
add_action( 'give_purchase_form', 'give_show_purchase_form' ); |
215
|
|
|
|
216
|
1 |
|
/** |
217
|
1 |
|
* |
218
|
1 |
|
* Give Show Login/Register Form Fields |
219
|
|
|
* |
220
|
|
|
* @since 1.4.1 |
221
|
|
|
* |
222
|
1 |
|
* @param int $form_id ID of the Give Form |
223
|
|
|
* |
224
|
1 |
|
* @return void |
225
|
|
|
*/ |
226
|
|
|
function give_show_register_login_fields( $form_id ) { |
227
|
|
|
|
228
|
|
|
$show_register_form = give_show_login_register_option( $form_id ); |
229
|
|
|
|
230
|
1 |
|
if ( ( $show_register_form === 'registration' || ( $show_register_form === 'both' && ! isset( $_GET['login'] ) ) ) && ! is_user_logged_in() ) : ?> |
231
|
1 |
|
<div id="give-checkout-login-register-<?php echo $form_id; ?>"> |
232
|
|
|
<?php do_action( 'give_purchase_form_register_fields', $form_id ); ?> |
233
|
|
|
</div> |
234
|
|
|
<?php elseif ( ( $show_register_form === 'login' || ( $show_register_form === 'both' && isset( $_GET['login'] ) ) ) && ! is_user_logged_in() ) : ?> |
235
|
|
|
<div id="give-checkout-login-register-<?php echo $form_id; ?>"> |
236
|
|
|
<?php do_action( 'give_purchase_form_login_fields', $form_id ); ?> |
237
|
|
|
</div> |
238
|
|
|
<?php endif; ?> |
239
|
|
|
|
240
|
|
|
<?php if ( ( ! isset( $_GET['login'] ) && is_user_logged_in() ) || ! isset( $show_register_form ) || 'none' === $show_register_form || 'login' === $show_register_form ) { |
241
|
|
|
do_action( 'give_purchase_form_after_user_info', $form_id ); |
242
|
|
|
} |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
add_action( 'give_purchase_form_register_login_fields', 'give_show_register_login_fields' ); |
246
|
|
|
|
247
|
1 |
|
/** |
248
|
|
|
* Donation Amount Field |
249
|
|
|
* |
250
|
|
|
* Outputs the donation amount field that appears at the top of the donation forms. If the user has custom amount enabled the field will output as a customizable input |
251
|
|
|
* |
252
|
|
|
* @since 1.0 |
253
|
|
|
* |
254
|
|
|
* @param int $form_id Give Form ID |
255
|
|
|
* @param array $args |
256
|
|
|
* |
257
|
|
|
* @return void |
258
|
|
|
*/ |
259
|
|
|
function give_output_donation_amount_top( $form_id = 0, $args = array() ) { |
260
|
|
|
|
261
|
|
|
global $give_options; |
|
|
|
|
262
|
1 |
|
|
263
|
|
|
$variable_pricing = give_has_variable_prices( $form_id ); |
264
|
|
|
$allow_custom_amount = get_post_meta( $form_id, '_give_custom_amount', true ); |
265
|
|
|
$currency_position = isset( $give_options['currency_position'] ) ? $give_options['currency_position'] : 'before'; |
266
|
|
|
$symbol = give_currency_symbol( give_get_currency() ); |
267
|
|
|
$currency_output = '<span class="give-currency-symbol give-currency-position-' . $currency_position . '">' . $symbol . '</span>'; |
268
|
|
|
$default_amount = give_format_amount( give_get_default_form_amount( $form_id ) ); |
269
|
|
|
$custom_amount_text = get_post_meta( $form_id, '_give_custom_amount_text', true ); |
270
|
|
|
|
271
|
|
|
do_action( 'give_before_donation_levels', $form_id, $args ); |
272
|
|
|
|
273
|
|
|
//Set Price, No Custom Amount Allowed means hidden price field |
274
|
|
|
if ( $allow_custom_amount == 'no' ) { |
275
|
|
|
?> |
276
|
|
|
|
277
|
|
|
<label class="give-hidden" for="give-amount-hidden"><?php echo esc_html__( 'Donation Amount:', 'give' ); ?></label> |
278
|
|
|
<input id="give-amount" class="give-amount-hidden" type="hidden" name="give-amount" |
279
|
|
|
value="<?php echo $default_amount; ?>" required> |
280
|
1 |
|
<div class="set-price give-donation-amount form-row-wide"> |
281
|
|
|
<?php if ( $currency_position == 'before' ) { |
282
|
1 |
|
echo $currency_output; |
283
|
1 |
|
} ?> |
284
|
1 |
|
<span id="give-amount-text" class="give-text-input give-amount-top"><?php echo $default_amount; ?></span> |
285
|
1 |
|
<?php if ( $currency_position == 'after' ) { |
286
|
1 |
|
echo $currency_output; |
287
|
1 |
|
} ?> |
288
|
1 |
|
</div> |
289
|
|
|
<?php |
290
|
1 |
|
} else { |
291
|
|
|
//Custom Amount Allowed |
292
|
|
|
?> |
293
|
1 |
|
<div class="give-total-wrap"> |
294
|
|
|
<div class="give-donation-amount form-row-wide"> |
295
|
|
|
<?php if ( $currency_position == 'before' ) { |
296
|
|
|
echo $currency_output; |
297
|
|
|
} ?> |
298
|
|
|
<label class="give-hidden" for="give-amount"><?php echo esc_html__( 'Donation Amount:', 'give' ); ?></label> |
299
|
|
|
<input class="give-text-input give-amount-top" id="give-amount" name="give-amount" type="tel" placeholder="" value="<?php echo $default_amount; ?>" autocomplete="off"> |
300
|
|
|
<?php if ( $currency_position == 'after' ) { |
301
|
|
|
echo $currency_output; |
302
|
|
|
} ?> |
303
|
|
|
</div> |
304
|
|
|
</div> |
305
|
|
|
<?php } |
306
|
|
|
|
307
|
|
|
do_action( 'give_after_donation_amount', $form_id, $args ); |
308
|
|
|
|
309
|
|
|
//Custom Amount Text |
310
|
|
|
if ( ! $variable_pricing && $allow_custom_amount == 'yes' && ! empty( $custom_amount_text ) ) { ?> |
311
|
|
|
<p class="give-custom-amount-text"><?php echo $custom_amount_text; ?></p> |
312
|
|
|
<?php } |
313
|
|
|
|
314
|
|
|
//Output Variable Pricing Levels |
315
|
1 |
|
if ( $variable_pricing ) { |
316
|
|
|
give_output_levels( $form_id ); |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
do_action( 'give_after_donation_levels', $form_id, $args ); |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
add_action( 'give_checkout_form_top', 'give_output_donation_amount_top', 10, 2 ); |
323
|
|
|
|
324
|
|
|
|
325
|
|
|
/** |
326
|
1 |
|
* Outputs the Donation Levels in various formats such as dropdown, radios, and buttons |
327
|
|
|
* |
328
|
|
|
* @since 1.0 |
329
|
|
|
* |
330
|
|
|
* @param int $form_id Give Form ID |
331
|
|
|
* |
332
|
|
|
* @return string |
333
|
|
|
*/ |
334
|
1 |
|
function give_output_levels( $form_id ) { |
335
|
1 |
|
|
336
|
1 |
|
//Get variable pricing |
337
|
|
|
$prices = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $form_id ), $form_id ); |
338
|
1 |
|
$display_style = get_post_meta( $form_id, '_give_display_style', true ); |
339
|
1 |
|
$custom_amount = get_post_meta( $form_id, '_give_custom_amount', true ); |
340
|
|
|
$custom_amount_text = get_post_meta( $form_id, '_give_custom_amount_text', true ); |
341
|
|
|
if ( empty( $custom_amount_text ) ) { |
342
|
|
|
$custom_amount_text = esc_html__( 'Give a Custom Amount', 'give' ); |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
$output = ''; |
346
|
|
|
$counter = 0; |
347
|
|
|
|
348
|
|
|
switch ( $display_style ) { |
349
|
|
|
case 'buttons': |
350
|
|
|
|
351
|
|
|
$output .= '<ul id="give-donation-level-button-wrap" class="give-donation-levels-wrap give-list-inline">'; |
352
|
|
|
|
353
|
|
|
foreach ( $prices as $price ) { |
354
|
|
|
$counter ++; |
355
|
|
|
$level_text = apply_filters( 'give_form_level_text', ! empty( $price['_give_text'] ) ? $price['_give_text'] : give_currency_filter( give_format_amount( $price['_give_amount'] ) ), $form_id, $price ); |
356
|
1 |
|
$level_classes = apply_filters( 'give_form_level_classes', 'give-donation-level-btn give-btn give-btn-level-' . $counter . ' ' . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? 'give-default-level' : '' ), $form_id, $price ); |
357
|
1 |
|
|
358
|
1 |
|
$output .= '<li>'; |
359
|
1 |
|
$output .= '<button type="button" data-price-id="' . $price['_give_id']['level_id'] . '" class=" ' . $level_classes . '" value="' . give_format_amount( $price['_give_amount'] ) . '">'; |
360
|
1 |
|
$output .= $level_text; |
361
|
1 |
|
$output .= '</button>'; |
362
|
1 |
|
$output .= '</li>'; |
363
|
|
|
|
364
|
1 |
|
} |
365
|
1 |
|
|
366
|
|
|
//Custom Amount |
367
|
|
|
if ( $custom_amount === 'yes' && ! empty( $custom_amount_text ) ) { |
368
|
1 |
|
$output .= '<li>'; |
369
|
|
|
$output .= '<button type="button" data-price-id="custom" class="give-donation-level-btn give-btn give-btn-level-custom" value="custom">'; |
370
|
1 |
|
$output .= $custom_amount_text; |
371
|
|
|
$output .= '</button>'; |
372
|
1 |
|
$output .= '</li>'; |
373
|
1 |
|
} |
374
|
1 |
|
|
375
|
1 |
|
$output .= '</ul>'; |
376
|
|
|
|
377
|
1 |
|
break; |
378
|
1 |
|
|
379
|
1 |
|
case 'radios': |
380
|
1 |
|
|
381
|
1 |
|
$output .= '<ul id="give-donation-level-radio-list" class="give-donation-levels-wrap">'; |
382
|
|
|
|
383
|
1 |
|
foreach ( $prices as $price ) { |
384
|
|
|
$counter ++; |
385
|
|
|
$level_text = apply_filters( 'give_form_level_text', ! empty( $price['_give_text'] ) ? $price['_give_text'] : give_currency_filter( give_format_amount( $price['_give_amount'] ) ), $form_id, $price ); |
386
|
1 |
|
$level_classes = apply_filters( 'give_form_level_classes', 'give-radio-input give-radio-input-level give-radio-level-' . $counter . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? ' give-default-level' : '' ), $form_id, $price ); |
387
|
|
|
|
388
|
|
|
$output .= '<li>'; |
389
|
|
|
$output .= '<input type="radio" data-price-id="' . $price['_give_id']['level_id'] . '" class="' . $level_classes . '" name="give-radio-donation-level" id="give-radio-level-' . $counter . '" ' . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? 'checked="checked"' : '' ) . ' value="' . give_format_amount( $price['_give_amount'] ) . '">'; |
390
|
|
|
$output .= '<label for="give-radio-level-' . $counter . '">' . $level_text . '</label>'; |
391
|
|
|
$output .= '</li>'; |
392
|
|
|
|
393
|
|
|
} |
394
|
1 |
|
|
395
|
|
|
//Custom Amount |
396
|
1 |
|
if ( $custom_amount === 'yes' && ! empty( $custom_amount_text ) ) { |
397
|
|
|
$output .= '<li>'; |
398
|
|
|
$output .= '<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">'; |
399
|
|
|
$output .= '<label for="give-radio-level-custom">' . $custom_amount_text . '</label>'; |
400
|
|
|
$output .= '</li>'; |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
$output .= '</ul>'; |
404
|
|
|
|
405
|
|
|
break; |
406
|
|
|
|
407
|
|
|
case 'dropdown': |
408
|
|
|
|
409
|
|
|
$output .= '<label for="give-donation-level" class="give-hidden">' . esc_html__( 'Choose Your Donation Amount', 'give' ) . ':</label>'; |
410
|
|
|
$output .= '<select id="give-donation-level-' . $form_id . '" class="give-select give-select-level give-donation-levels-wrap">'; |
411
|
|
|
|
412
|
|
|
//first loop through prices |
413
|
|
|
foreach ( $prices as $price ) { |
414
|
|
|
$level_text = apply_filters( 'give_form_level_text', ! empty( $price['_give_text'] ) ? $price['_give_text'] : give_currency_filter( give_format_amount( $price['_give_amount'] ) ), $form_id, $price ); |
415
|
|
|
$level_classes = apply_filters( 'give_form_level_classes', 'give-donation-level-' . $form_id . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? ' give-default-level' : '' ), $form_id, $price ); |
416
|
|
|
|
417
|
|
|
$output .= '<option data-price-id="' . $price['_give_id']['level_id'] . '" class="' . $level_classes . '" ' . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? 'selected="selected"' : '' ) . ' value="' . give_format_amount( $price['_give_amount'] ) . '">'; |
418
|
|
|
$output .= $level_text; |
419
|
|
|
$output .= '</option>'; |
420
|
|
|
|
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
//Custom Amount |
424
|
|
|
if ( $custom_amount === 'yes' && ! empty( $custom_amount_text ) ) { |
425
|
|
|
$output .= '<option data-price-id="custom" class="give-donation-level-custom" value="custom">' . $custom_amount_text . '</option>'; |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
$output .= '</select>'; |
429
|
|
|
|
430
|
|
|
break; |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
echo apply_filters( 'give_form_level_output', $output, $form_id ); |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
/** |
437
|
|
|
* Display Reveal & Lightbox Button |
438
|
|
|
* |
439
|
|
|
* Outputs a button to reveal form fields |
440
|
|
|
* |
441
|
|
|
* @param int $form_id |
442
|
|
|
* @param array $args |
443
|
|
|
* |
444
|
|
|
*/ |
445
|
|
|
function give_display_checkout_button( $form_id, $args ) { |
446
|
|
|
|
447
|
|
|
$display_option = ( isset( $args['display_style'] ) && ! empty( $args['display_style'] ) ) |
448
|
|
|
? $args['display_style'] |
449
|
|
|
: get_post_meta( $form_id, '_give_payment_display', true ); |
450
|
|
|
|
451
|
|
|
//no btn for onpage |
452
|
1 |
|
if ( $display_option === 'onpage' ) { |
453
|
1 |
|
return; |
454
|
|
|
} |
455
|
|
|
|
456
|
|
|
$display_label_field = get_post_meta( $form_id, '_give_reveal_label', true ); |
457
|
|
|
$display_label = ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) ); |
458
|
|
|
|
459
|
|
|
$output = '<button type="button" class="give-btn give-btn-' . $display_option . '">' . $display_label . '</button>'; |
460
|
|
|
|
461
|
|
|
echo apply_filters( 'give_display_checkout_button', $output ); |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
add_action( 'give_after_donation_levels', 'give_display_checkout_button', 10, 2 ); |
465
|
|
|
|
466
|
1 |
|
/** |
467
|
1 |
|
* Shows the User Info fields in the Personal Info box, more fields can be added via the hooks provided. |
468
|
1 |
|
* |
469
|
|
|
* @since 1.0 |
470
|
|
|
* |
471
|
1 |
|
* @param int $form_id |
472
|
|
|
* |
473
|
|
|
* @return void |
474
|
|
|
*/ |
475
|
1 |
|
function give_user_info_fields( $form_id ) { |
476
|
1 |
|
|
477
|
|
|
if ( is_user_logged_in() ) : |
478
|
1 |
|
$user_data = get_userdata( get_current_user_id() ); |
479
|
|
|
endif; |
480
|
1 |
|
|
481
|
1 |
|
do_action( 'give_purchase_form_before_personal_info', $form_id ); |
482
|
|
|
?> |
483
|
|
|
<fieldset id="give_checkout_user_info"> |
484
|
|
|
<legend><?php echo apply_filters( 'give_checkout_personal_info_text', esc_html__( 'Personal Info', 'give' ) ); ?></legend> |
485
|
|
|
<p id="give-first-name-wrap" class="form-row form-row-first"> |
486
|
|
|
<label class="give-label" for="give-first"> |
487
|
|
|
<?php esc_html_e( 'First Name', 'give' ); ?> |
488
|
|
|
<?php if ( give_field_is_required( 'give_first', $form_id ) ) { ?> |
489
|
|
|
<span class="give-required-indicator">*</span> |
490
|
|
|
<?php } ?> |
491
|
|
|
<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_html_e( 'We will use this to personalize your account experience.', 'give' ); ?>"></span> |
492
|
|
|
</label> |
493
|
|
|
<input class="give-input required" type="text" name="give_first" placeholder="<?php esc_html_e( 'First Name', 'give' ); ?>" id="give-first" value="<?php echo is_user_logged_in() ? $user_data->first_name : ''; ?>"<?php if ( give_field_is_required( 'give_first', $form_id ) ) { |
|
|
|
|
494
|
|
|
echo ' required '; |
495
|
|
|
} ?>/> |
496
|
|
|
</p> |
497
|
|
|
|
498
|
|
|
<p id="give-last-name-wrap" class="form-row form-row-last"> |
499
|
|
|
<label class="give-label" for="give-last"> |
500
|
|
|
<?php esc_html_e( 'Last Name', 'give' ); ?> |
501
|
|
|
<?php if ( give_field_is_required( 'give_last', $form_id ) ) { ?> |
502
|
|
|
<span class="give-required-indicator">*</span> |
503
|
|
|
<?php } ?> |
504
|
|
|
<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_html_e( 'We will use this as well to personalize your account experience.', 'give' ); ?>"></span> |
505
|
|
|
</label> |
506
|
|
|
|
507
|
|
|
<input class="give-input<?php if ( give_field_is_required( 'give_last', $form_id ) ) { |
508
|
|
|
echo ' required'; |
509
|
|
|
} ?>" type="text" name="give_last" id="give-last" placeholder="<?php esc_html_e( 'Last Name', 'give' ); ?>" value="<?php echo is_user_logged_in() ? $user_data->last_name : ''; ?>"<?php if ( give_field_is_required( 'give_last', $form_id ) ) { |
510
|
|
|
echo ' required '; |
511
|
|
|
} ?> /> |
512
|
|
|
</p> |
513
|
|
|
|
514
|
|
|
<?php do_action( 'give_purchase_form_before_email', $form_id ); ?> |
515
|
|
|
<p id="give-email-wrap" class="form-row form-row-wide"> |
516
|
|
|
<label class="give-label" for="give-email"> |
517
|
|
|
<?php esc_html_e( 'Email Address', 'give' ); ?> |
518
|
|
|
<?php if ( give_field_is_required( 'give_email', $form_id ) ) { ?> |
519
|
|
|
<span class="give-required-indicator">*</span> |
520
|
|
|
<?php } ?> |
521
|
|
|
<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_html_e( 'We will send the purchase receipt to this address.', 'give' ); ?>"></span> |
522
|
|
|
</label> |
523
|
|
|
|
524
|
|
|
<input class="give-input required" type="email" name="give_email" placeholder="<?php esc_html_e( 'Email address', 'give' ); ?>" id="give-email" value="<?php echo is_user_logged_in() ? $user_data->user_email : ''; ?>"<?php if ( give_field_is_required( 'give_email', $form_id ) ) { |
525
|
|
|
echo ' required '; |
526
|
|
|
} ?>/> |
527
|
|
|
|
528
|
|
|
</p> |
529
|
|
|
<?php do_action( 'give_purchase_form_after_email', $form_id ); ?> |
530
|
|
|
|
531
|
|
|
<?php do_action( 'give_purchase_form_user_info', $form_id ); ?> |
532
|
|
|
</fieldset> |
533
|
|
|
<?php |
534
|
|
|
do_action( 'give_purchase_form_after_personal_info', $form_id ); |
535
|
|
|
|
536
|
|
|
} |
537
|
|
|
|
538
|
|
|
add_action( 'give_purchase_form_after_user_info', 'give_user_info_fields' ); |
539
|
|
|
add_action( 'give_register_fields_before', 'give_user_info_fields' ); |
540
|
|
|
|
541
|
|
|
/** |
542
|
|
|
* Renders the credit card info form. |
543
|
|
|
* |
544
|
|
|
* @since 1.0 |
545
|
|
|
* |
546
|
|
|
* @param int $form_id |
547
|
|
|
* |
548
|
|
|
* @return void |
549
|
|
|
*/ |
550
|
|
|
function give_get_cc_form( $form_id ) { |
551
|
|
|
|
552
|
|
|
ob_start(); |
553
|
|
|
|
554
|
|
|
do_action( 'give_before_cc_fields', $form_id ); ?> |
555
|
|
|
|
556
|
|
|
<fieldset id="give_cc_fields-<?php echo $form_id ?>" class="give-do-validate"> |
557
|
|
|
<legend><?php echo apply_filters( 'give_credit_card_fieldset_heading', esc_html__( 'Credit Card Info', 'give' ) ); ?></legend> |
558
|
|
|
<?php if ( is_ssl() ) : ?> |
559
|
|
|
<div id="give_secure_site_wrapper-<?php echo $form_id ?>"> |
560
|
|
|
<span class="give-icon padlock"></span> |
561
|
|
|
<span><?php esc_html_e( 'This is a secure SSL encrypted payment.', 'give' ); ?></span> |
562
|
|
|
</div> |
563
|
|
|
<?php endif; ?> |
564
|
|
|
<p id="give-card-number-wrap-<?php echo $form_id ?>" class="form-row form-row-two-thirds"> |
565
|
|
|
<label for="card_number-<?php echo $form_id ?>" class="give-label"> |
566
|
|
|
<?php esc_html_e( 'Card Number', 'give' ); ?> |
567
|
|
|
<span class="give-required-indicator">*</span> |
568
|
|
|
<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_html_e( 'The (typically) 16 digits on the front of your credit card.', 'give' ); ?>"></span> |
569
|
|
|
<span class="card-type"></span> |
570
|
|
|
</label> |
571
|
|
|
|
572
|
|
|
<input type="tel" autocomplete="off" name="card_number" id="card_number-<?php echo $form_id ?>" class="card-number give-input required" placeholder="<?php esc_html_e( 'Card number', 'give' ); ?>" required/> |
573
|
|
|
</p> |
574
|
|
|
|
575
|
|
|
<p id="give-card-cvc-wrap-<?php echo $form_id ?>" class="form-row form-row-one-third"> |
576
|
|
|
<label for="card_cvc-<?php echo $form_id ?>" class="give-label"> |
577
|
|
|
<?php esc_html_e( 'CVC', 'give' ); ?> |
578
|
|
|
<span class="give-required-indicator">*</span> |
579
|
|
|
<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_html_e( 'The 3 digit (back) or 4 digit (front) value on your card.', 'give' ); ?>"></span> |
580
|
|
|
</label> |
581
|
|
|
|
582
|
|
|
<input type="tel" size="4" autocomplete="off" name="card_cvc" id="card_cvc-<?php echo $form_id ?>" class="card-cvc give-input required" placeholder="<?php esc_html_e( 'Security code', 'give' ); ?>" required/> |
583
|
|
|
</p> |
584
|
|
|
|
585
|
|
|
<p id="give-card-name-wrap-<?php echo $form_id ?>" class="form-row form-row-two-thirds"> |
586
|
|
|
<label for="card_name-<?php echo $form_id ?>" class="give-label"> |
587
|
|
|
<?php esc_html_e( 'Name on the Card', 'give' ); ?> |
588
|
|
|
<span class="give-required-indicator">*</span> |
589
|
|
|
<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_html_e( 'The name printed on the front of your credit card.', 'give' ); ?>"></span> |
590
|
|
|
</label> |
591
|
|
|
|
592
|
|
|
<input type="text" autocomplete="off" name="card_name" id="card_name-<?php echo $form_id ?>" class="card-name give-input required" placeholder="<?php esc_html_e( 'Card name', 'give' ); ?>" required/> |
593
|
|
|
</p> |
594
|
|
|
<?php do_action( 'give_before_cc_expiration' ); ?> |
595
|
|
|
<p class="card-expiration form-row form-row-one-third"> |
596
|
|
|
<label for="card_expiry-<?php echo $form_id ?>" class="give-label"> |
597
|
|
|
<?php esc_html_e( 'Expiration', 'give' ); ?> |
598
|
|
|
<span class="give-required-indicator">*</span> |
599
|
|
|
<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_html_e( 'The date your credit card expires, typically on the front of the card.', 'give' ); ?>"></span> |
600
|
|
|
</label> |
601
|
|
|
|
602
|
|
|
<input type="hidden" id="card_exp_month-<?php echo $form_id ?>" name="card_exp_month" class="card-expiry-month"/> |
603
|
|
|
<input type="hidden" id="card_exp_year-<?php echo $form_id ?>" name="card_exp_year" class="card-expiry-year"/> |
604
|
|
|
|
605
|
|
|
<input type="tel" autocomplete="off" name="card_expiry" id="card_expiry-<?php echo $form_id ?>" class="card-expiry give-input required" placeholder="<?php esc_html_e( 'MM / YY', 'give' ); ?>" required/> |
606
|
|
|
</p> |
607
|
|
|
<?php do_action( 'give_after_cc_expiration', $form_id ); ?> |
608
|
|
|
|
609
|
|
|
</fieldset> |
610
|
|
|
<?php |
611
|
|
|
do_action( 'give_after_cc_fields', $form_id ); |
612
|
|
|
|
613
|
|
|
echo ob_get_clean(); |
614
|
|
|
} |
615
|
|
|
|
616
|
|
|
add_action( 'give_cc_form', 'give_get_cc_form' ); |
617
|
|
|
|
618
|
|
|
/** |
619
|
|
|
* Outputs the default credit card address fields |
620
|
|
|
* |
621
|
|
|
* @since 1.0 |
622
|
|
|
* |
623
|
|
|
* @param int $form_id |
624
|
|
|
* |
625
|
|
|
* @return void |
626
|
|
|
*/ |
627
|
|
|
function give_default_cc_address_fields( $form_id ) { |
628
|
|
|
|
629
|
|
|
$logged_in = is_user_logged_in(); |
630
|
|
|
|
631
|
|
|
if ( $logged_in ) { |
632
|
|
|
$user_address = get_user_meta( get_current_user_id(), '_give_user_address', true ); |
633
|
|
|
} |
634
|
|
|
$line1 = $logged_in && ! empty( $user_address['line1'] ) ? $user_address['line1'] : ''; |
635
|
|
|
$line2 = $logged_in && ! empty( $user_address['line2'] ) ? $user_address['line2'] : ''; |
636
|
|
|
$city = $logged_in && ! empty( $user_address['city'] ) ? $user_address['city'] : ''; |
637
|
|
|
$zip = $logged_in && ! empty( $user_address['zip'] ) ? $user_address['zip'] : ''; |
638
|
|
|
ob_start(); ?> |
639
|
|
|
<fieldset id="give_cc_address" class="cc-address"> |
640
|
|
|
<legend><?php echo apply_filters( 'give_billing_details_fieldset_heading', esc_html__( 'Billing Details', 'give' ) ); ?></legend> |
641
|
|
|
<?php do_action( 'give_cc_billing_top' ); ?> |
642
|
|
|
<p id="give-card-address-wrap" class="form-row form-row-two-thirds"> |
643
|
|
|
<label for="card_address" class="give-label"> |
644
|
|
|
<?php esc_html_e( 'Address', 'give' ); ?> |
645
|
|
|
<?php |
646
|
|
|
if ( give_field_is_required( 'card_address', $form_id ) ) { ?> |
647
|
|
|
<span class="give-required-indicator">*</span> |
648
|
|
|
<?php } ?> |
649
|
|
|
<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_html_e( 'The primary billing address for your credit card.', 'give' ); ?>"></span> |
650
|
|
|
</label> |
651
|
|
|
|
652
|
|
|
<input type="text" id="card_address" name="card_address" class="card-address give-input<?php if ( give_field_is_required( 'card_address', $form_id ) ) { |
653
|
|
|
echo ' required'; |
654
|
|
|
} ?>" placeholder="<?php esc_html_e( 'Address line 1', 'give' ); ?>" value="<?php echo $line1; ?>"<?php if ( give_field_is_required( 'card_address', $form_id ) ) { |
655
|
|
|
echo ' required '; |
656
|
|
|
} ?>/> |
657
|
|
|
</p> |
658
|
|
|
|
659
|
|
|
<p id="give-card-address-2-wrap" class="form-row form-row-one-third"> |
660
|
|
|
<label for="card_address_2" class="give-label"> |
661
|
|
|
<?php esc_html_e( 'Address Line 2', 'give' ); ?> |
662
|
|
|
<?php if ( give_field_is_required( 'card_address_2', $form_id ) ) { ?> |
663
|
|
|
<span class="give-required-indicator">*</span> |
664
|
|
|
<?php } ?> |
665
|
|
|
<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_html_e( '(optional) The suite, apt no, PO box, etc, associated with your billing address.', 'give' ); ?>"></span> |
666
|
|
|
</label> |
667
|
|
|
|
668
|
|
|
<input type="text" id="card_address_2" name="card_address_2" class="card-address-2 give-input<?php if ( give_field_is_required( 'card_address_2', $form_id ) ) { |
669
|
|
|
echo ' required'; |
670
|
|
|
} ?>" placeholder="<?php esc_html_e( 'Address line 2', 'give' ); ?>" value="<?php echo $line2; ?>"<?php if ( give_field_is_required( 'card_address_2', $form_id ) ) { |
671
|
|
|
echo ' required '; |
672
|
|
|
} ?>/> |
673
|
|
|
</p> |
674
|
|
|
|
675
|
|
|
<p id="give-card-city-wrap" class="form-row form-row-two-thirds"> |
676
|
|
|
<label for="card_city" class="give-label"> |
677
|
|
|
<?php esc_html_e( 'City', 'give' ); ?> |
678
|
|
|
<?php if ( give_field_is_required( 'card_city', $form_id ) ) { ?> |
679
|
|
|
<span class="give-required-indicator">*</span> |
680
|
|
|
<?php } ?> |
681
|
|
|
<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_html_e( 'The city for your billing address.', 'give' ); ?>"></span> |
682
|
|
|
</label> |
683
|
|
|
<input type="text" id="card_city" name="card_city" class="card-city give-input<?php if ( give_field_is_required( 'card_city', $form_id ) ) { |
684
|
|
|
echo ' required'; |
685
|
|
|
} ?>" placeholder="<?php esc_html_e( 'City', 'give' ); ?>" value="<?php echo $city; ?>"<?php if ( give_field_is_required( 'card_city', $form_id ) ) { |
686
|
|
|
echo ' required '; |
687
|
|
|
} ?>/> |
688
|
|
|
</p> |
689
|
|
|
|
690
|
|
|
<p id="give-card-zip-wrap" class="form-row form-row-one-third"> |
691
|
|
|
<label for="card_zip" class="give-label"> |
692
|
|
|
<?php esc_html_e( 'Zip / Postal Code', 'give' ); ?> |
693
|
|
|
<?php if ( give_field_is_required( 'card_zip', $form_id ) ) { ?> |
694
|
|
|
<span class="give-required-indicator">*</span> |
695
|
|
|
<?php } ?> |
696
|
|
|
<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_html_e( 'The zip or postal code for your billing address.', 'give' ); ?>"></span> |
697
|
|
|
</label> |
698
|
|
|
|
699
|
|
|
<input type="text" size="4" id="card_zip" name="card_zip" class="card-zip give-input<?php if ( give_field_is_required( 'card_zip', $form_id ) ) { |
700
|
|
|
echo ' required'; |
701
|
|
|
} ?>" placeholder="<?php esc_html_e( 'Zip / Postal Code', 'give' ); ?>" value="<?php echo $zip; ?>" <?php if ( give_field_is_required( 'card_zip', $form_id ) ) { |
702
|
|
|
echo ' required '; |
703
|
|
|
} ?>/> |
704
|
|
|
</p> |
705
|
|
|
|
706
|
|
|
<p id="give-card-country-wrap" class="form-row form-row-first"> |
707
|
|
|
<label for="billing_country" class="give-label"> |
708
|
|
|
<?php esc_html_e( 'Country', 'give' ); ?> |
709
|
|
|
<?php if ( give_field_is_required( 'billing_country', $form_id ) ) { ?> |
710
|
|
|
<span class="give-required-indicator">*</span> |
711
|
|
|
<?php } ?> |
712
|
|
|
<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_html_e( 'The country for your billing address.', 'give' ); ?>"></span> |
713
|
|
|
</label> |
714
|
|
|
|
715
|
|
|
<select name="billing_country" id="billing_country" class="billing-country billing_country give-select<?php if ( give_field_is_required( 'billing_country', $form_id ) ) { |
716
|
|
|
echo ' required'; |
717
|
|
|
} ?>"<?php if ( give_field_is_required( 'billing_country', $form_id ) ) { |
718
|
|
|
echo ' required '; |
719
|
|
|
} ?>> |
720
|
|
|
<?php |
721
|
|
|
|
722
|
|
|
$selected_country = give_get_country(); |
723
|
|
|
|
724
|
|
|
if ( $logged_in && ! empty( $user_address['country'] ) && '*' !== $user_address['country'] ) { |
725
|
|
|
$selected_country = $user_address['country']; |
726
|
|
|
} |
727
|
|
|
|
728
|
|
|
$countries = give_get_country_list(); |
729
|
|
|
foreach ( $countries as $country_code => $country ) { |
730
|
|
|
echo '<option value="' . esc_attr( $country_code ) . '"' . selected( $country_code, $selected_country, false ) . '>' . $country . '</option>'; |
731
|
|
|
} |
732
|
|
|
?> |
733
|
|
|
</select> |
734
|
|
|
</p> |
735
|
|
|
|
736
|
|
|
<p id="give-card-state-wrap" class="form-row form-row-last"> |
737
|
|
|
<label for="card_state" class="give-label"> |
738
|
|
|
<?php esc_html_e( 'State / Province', 'give' ); ?> |
739
|
|
|
<?php if ( give_field_is_required( 'card_state', $form_id ) ) { ?> |
740
|
|
|
<span class="give-required-indicator">*</span> |
741
|
|
|
<?php } ?> |
742
|
|
|
<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_html_e( 'The state or province for your billing address.', 'give' ); ?>"></span> |
743
|
|
|
</label> |
744
|
|
|
|
745
|
|
|
<?php |
746
|
|
|
$selected_state = give_get_state(); |
747
|
|
|
$states = give_get_states( $selected_country ); |
748
|
|
|
|
749
|
|
|
if ( $logged_in && ! empty( $user_address['state'] ) ) { |
750
|
|
|
$selected_state = $user_address['state']; |
751
|
|
|
} |
752
|
|
|
|
753
|
|
|
if ( ! empty( $states ) ) : ?> |
754
|
|
|
<select name="card_state" id="card_state" class="card_state give-select<?php if ( give_field_is_required( 'card_state', $form_id ) ) { |
755
|
|
|
echo ' required'; |
756
|
|
|
} ?>"<?php if ( give_field_is_required( 'card_state', $form_id ) ) { |
757
|
|
|
echo ' required '; |
758
|
|
|
} ?>> |
759
|
|
|
<?php |
760
|
|
|
foreach ( $states as $state_code => $state ) { |
761
|
|
|
echo '<option value="' . $state_code . '"' . selected( $state_code, $selected_state, false ) . '>' . $state . '</option>'; |
762
|
|
|
} |
763
|
|
|
?> |
764
|
|
|
</select> |
765
|
|
|
<?php else : ?> |
766
|
|
|
<input type="text" size="6" name="card_state" id="card_state" class="card_state give-input" placeholder="<?php esc_html_e( 'State / Province', 'give' ); ?>"/> |
767
|
|
|
<?php endif; ?> |
768
|
|
|
</p> |
769
|
|
|
<?php do_action( 'give_cc_billing_bottom' ); ?> |
770
|
|
|
</fieldset> |
771
|
|
|
<?php |
772
|
|
|
echo ob_get_clean(); |
773
|
|
|
} |
774
|
|
|
|
775
|
|
|
add_action( 'give_after_cc_fields', 'give_default_cc_address_fields' ); |
776
|
|
|
|
777
|
|
|
|
778
|
|
|
/** |
779
|
|
|
* Renders the user registration fields. If the user is logged in, a login form is displayed other a registration form is provided for the user to create an account. |
780
|
|
|
* |
781
|
|
|
* @since 1.0 |
782
|
|
|
* |
783
|
|
|
* @param int $form_id |
784
|
|
|
* |
785
|
|
|
* @return string |
786
|
|
|
*/ |
787
|
|
|
function give_get_register_fields( $form_id ) { |
788
|
|
|
|
789
|
|
|
global $user_ID; |
|
|
|
|
790
|
|
|
|
791
|
|
|
if ( is_user_logged_in() ) { |
792
|
|
|
$user_data = get_userdata( $user_ID ); |
793
|
|
|
} |
794
|
|
|
|
795
|
|
|
$show_register_form = give_show_login_register_option( $form_id ); |
796
|
|
|
|
797
|
|
|
ob_start(); ?> |
798
|
|
|
<fieldset id="give-register-fields-<?php echo $form_id; ?>"> |
799
|
|
|
|
800
|
|
|
<?php if ( $show_register_form == 'both' ) { ?> |
801
|
|
|
<div class="give-login-account-wrap"> |
802
|
|
|
<p class="give-login-message"><?php esc_html_e( 'Already have an account?', 'give' ); ?> |
803
|
|
|
<a href="<?php echo esc_url( add_query_arg( 'login', 1 ) ); ?>" class="give-checkout-login" data-action="give_checkout_login"><?php esc_html_e( 'Login', 'give' ); ?></a> |
804
|
|
|
</p> |
805
|
|
|
<p class="give-loading-text"> |
806
|
|
|
<span class="give-loading-animation"></span> <?php esc_html_e( 'Loading...', 'give' ); ?></p> |
807
|
|
|
</div> |
808
|
|
|
<?php } ?> |
809
|
|
|
|
810
|
|
|
<?php do_action( 'give_register_fields_before', $form_id ); ?> |
811
|
|
|
|
812
|
|
|
<fieldset id="give-register-account-fields-<?php echo $form_id; ?>"> |
813
|
|
|
<legend><?php echo apply_filters( 'give_create_account_fieldset_heading', esc_html__( 'Create an account', 'give' ) ); |
814
|
|
|
if ( ! give_logged_in_only( $form_id ) ) { |
815
|
|
|
echo ' <span class="sub-text">' . esc_html__( '(optional)', 'give' ) . '</span>'; |
816
|
|
|
} ?></legend> |
817
|
|
|
<?php do_action( 'give_register_account_fields_before', $form_id ); ?> |
818
|
|
|
<div id="give-user-login-wrap-<?php echo $form_id; ?>" class="form-row form-row-one-third form-row-first"> |
819
|
|
|
<label for="give-user-login-<?php echo $form_id; ?>"> |
820
|
|
|
<?php esc_html_e( 'Username', 'give' ); ?> |
821
|
|
|
<?php if ( give_logged_in_only( $form_id ) ) { ?> |
822
|
|
|
<span class="give-required-indicator">*</span> |
823
|
|
|
<?php } ?> |
824
|
|
|
<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_html_e( 'The username you will use to log into your account.', 'give' ); ?>"></span> |
825
|
|
|
</label> |
826
|
|
|
|
827
|
|
|
<input name="give_user_login" id="give-user-login-<?php echo $form_id; ?>" class="<?php if ( give_logged_in_only( $form_id ) ) { |
828
|
|
|
echo 'required '; |
829
|
|
|
} ?>give-input" type="text" placeholder="<?php esc_html_e( 'Username', 'give' ); ?>" title="<?php esc_html_e( 'Username', 'give' ); ?>"/> |
830
|
|
|
</div> |
831
|
|
|
|
832
|
|
|
<div id="give-user-pass-wrap-<?php echo $form_id; ?>" class="form-row form-row-one-third"> |
833
|
|
|
<label for="give-user-pass-<?php echo $form_id; ?>"> |
834
|
|
|
<?php esc_html_e( 'Password', 'give' ); ?> |
835
|
|
|
<?php if ( give_logged_in_only( $form_id ) ) { ?> |
836
|
|
|
<span class="give-required-indicator">*</span> |
837
|
|
|
<?php } ?> |
838
|
|
|
<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_html_e( 'The password used to access your account.', 'give' ); ?>"></span> |
839
|
|
|
</label> |
840
|
|
|
|
841
|
|
|
<input name="give_user_pass" id="give-user-pass-<?php echo $form_id; ?>" class="<?php if ( give_logged_in_only( $form_id ) ) { |
842
|
|
|
echo 'required '; |
843
|
|
|
} ?>give-input" placeholder="<?php esc_html_e( 'Password', 'give' ); ?>" type="password"/> |
844
|
|
|
</div> |
845
|
|
|
|
846
|
|
|
<div id="give-user-pass-confirm-wrap-<?php echo $form_id; ?>" class="give-register-password form-row form-row-one-third"> |
847
|
|
|
<label for="give-user-pass-confirm-<?php echo $form_id; ?>"> |
848
|
|
|
<?php esc_html_e( 'Confirm PW', 'give' ); ?> |
849
|
|
|
<?php if ( give_logged_in_only( $form_id ) ) { ?> |
850
|
|
|
<span class="give-required-indicator">*</span> |
851
|
|
|
<?php } ?> |
852
|
|
|
<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_html_e( 'Please retype your password to confirm.', 'give' ); ?>"></span> |
853
|
|
|
</label> |
854
|
|
|
|
855
|
|
|
<input name="give_user_pass_confirm" id="give-user-pass-confirm-<?php echo $form_id; ?>" class="<?php if ( give_logged_in_only( $form_id ) ) { |
856
|
|
|
echo 'required '; |
857
|
|
|
} ?>give-input" placeholder="<?php esc_html_e( 'Confirm password', 'give' ); ?>" type="password"/> |
858
|
|
|
</div> |
859
|
|
|
<?php do_action( 'give_register_account_fields_after', $form_id ); ?> |
860
|
|
|
</fieldset> |
861
|
|
|
|
862
|
|
|
<?php do_action( 'give_register_fields_after', $form_id ); ?> |
863
|
|
|
|
864
|
|
|
<input type="hidden" name="give-purchase-var" value="needs-to-register"/> |
865
|
|
|
|
866
|
|
|
<?php do_action( 'give_purchase_form_user_info', $form_id ); ?> |
867
|
|
|
|
868
|
|
|
</fieldset> |
869
|
|
|
<?php |
870
|
|
|
echo ob_get_clean(); |
871
|
|
|
} |
872
|
|
|
|
873
|
|
|
add_action( 'give_purchase_form_register_fields', 'give_get_register_fields' ); |
874
|
|
|
|
875
|
|
|
/** |
876
|
|
|
* Gets the login fields for the login form on the checkout. This function hooks |
877
|
|
|
* on the give_purchase_form_login_fields to display the login form if a user already |
878
|
|
|
* had an account. |
879
|
|
|
* |
880
|
|
|
* @since 1.0 |
881
|
|
|
* |
882
|
|
|
* @param int $form_id |
883
|
|
|
* |
884
|
|
|
* @return string |
885
|
|
|
*/ |
886
|
|
|
function give_get_login_fields( $form_id ) { |
887
|
|
|
|
888
|
|
|
$form_id = isset( $_POST['form_id'] ) ? $_POST['form_id'] : $form_id; |
889
|
|
|
$show_register_form = give_show_login_register_option( $form_id ); |
890
|
|
|
|
891
|
|
|
ob_start(); |
892
|
|
|
?> |
893
|
|
|
<fieldset id="give-login-fields-<?php echo $form_id; ?>"> |
894
|
|
|
<legend><?php echo apply_filters( 'give_account_login_fieldset_heading', esc_html__( 'Login to Your Account', 'give' ) ); |
895
|
|
|
if ( ! give_logged_in_only( $form_id ) ) { |
896
|
|
|
echo ' <span class="sub-text">' . esc_html__( '(optional)', 'give' ) . '</span>'; |
897
|
|
|
} ?> |
898
|
|
|
</legend> |
899
|
|
|
<?php if ( $show_register_form == 'both' ) { ?> |
900
|
|
|
<p class="give-new-account-link"> |
901
|
|
|
<?php esc_html_e( 'Need to create an account?', 'give' ); ?> |
902
|
|
|
<a href="<?php echo remove_query_arg( 'login' ); ?>" class="give-checkout-register-cancel" data-action="give_checkout_register"> |
903
|
|
|
<?php esc_html_e( 'Register', 'give' ); |
904
|
|
|
if ( ! give_logged_in_only( $form_id ) ) { |
905
|
|
|
echo ' ' . esc_html__( 'or checkout as a guest »', 'give' ); |
906
|
|
|
} ?> |
907
|
|
|
</a> |
908
|
|
|
</p> |
909
|
|
|
<p class="give-loading-text"> |
910
|
|
|
<span class="give-loading-animation"></span> <?php esc_html_e( 'Loading...', 'give' ); ?> </p> |
911
|
|
|
<?php } ?> |
912
|
|
|
<?php do_action( 'give_checkout_login_fields_before', $form_id ); ?> |
913
|
|
|
<div id="give-user-login-wrap-<?php echo $form_id; ?>" class="form-row form-row-first"> |
914
|
|
|
<label class="give-label" for="give-user-login-<?php echo $form_id; ?>"> |
915
|
|
|
<?php esc_html_e( 'Username', 'give' ); ?> |
916
|
|
|
<?php if ( give_logged_in_only( $form_id ) ) { ?> |
917
|
|
|
<span class="give-required-indicator">*</span> |
918
|
|
|
<?php } ?> |
919
|
|
|
</label> |
920
|
|
|
|
921
|
|
|
<input class="<?php if ( give_logged_in_only( $form_id ) ) { |
922
|
|
|
echo 'required '; |
923
|
|
|
} ?>give-input" type="text" name="give_user_login" id="give-user-login-<?php echo $form_id; ?>" value="" placeholder="<?php esc_html_e( 'Your username', 'give' ); ?>"/> |
924
|
|
|
</div> |
925
|
|
|
|
926
|
|
|
<div id="give-user-pass-wrap-<?php echo $form_id; ?>" class="give_login_password form-row form-row-last"> |
927
|
|
|
<label class="give-label" for="give-user-pass-<?php echo $form_id; ?>"> |
928
|
|
|
<?php esc_html_e( 'Password', 'give' ); ?> |
929
|
|
|
<?php if ( give_logged_in_only( $form_id ) ) { ?> |
930
|
|
|
<span class="give-required-indicator">*</span> |
931
|
|
|
<?php } ?> |
932
|
|
|
</label> |
933
|
|
|
<input class="<?php if ( give_logged_in_only( $form_id ) ) { |
934
|
|
|
echo 'required '; |
935
|
|
|
} ?>give-input" type="password" name="give_user_pass" id="give-user-pass-<?php echo $form_id; ?>" placeholder="<?php esc_html_e( 'Your password', 'give' ); ?>"/> |
936
|
|
|
<input type="hidden" name="give-purchase-var" value="needs-to-login"/> |
937
|
|
|
</div> |
938
|
|
|
|
939
|
|
|
<div id="give-forgot-password-wrap-<?php echo $form_id; ?>" class="give_login_forgot_password"> |
940
|
|
|
<span class="give-forgot-password "> |
941
|
|
|
<a href="<?php echo wp_lostpassword_url() ?>" target="_blank"><?php esc_html_e( 'Reset password?' ) ?></a> |
942
|
|
|
</span> |
943
|
|
|
</div> |
944
|
|
|
|
945
|
|
|
<div id="give-user-login-submit-<?php echo $form_id; ?>" class="give-clearfix"> |
946
|
|
|
<input type="submit" class="give-submit give-btn button" name="give_login_submit" value="<?php esc_html_e( 'Login', 'give' ); ?>"/> |
947
|
|
|
<?php if ( $show_register_form !== 'login' ) { ?> |
948
|
|
|
<input type="button" data-action="give_cancel_login" class="give-cancel-login give-checkout-register-cancel give-btn button" name="give_login_cancel" value="<?php esc_html_e( 'Cancel', 'give' ); ?>"/> |
949
|
|
|
<?php } ?> |
950
|
|
|
<span class="give-loading-animation"></span> |
951
|
|
|
</div> |
952
|
|
|
<?php do_action( 'give_checkout_login_fields_after', $form_id ); ?> |
953
|
|
|
</fieldset><!--end #give-login-fields--> |
954
|
|
|
<?php |
955
|
|
|
echo ob_get_clean(); |
956
|
|
|
} |
957
|
|
|
|
958
|
|
|
add_action( 'give_purchase_form_login_fields', 'give_get_login_fields', 10, 1 ); |
959
|
|
|
|
960
|
|
|
/** |
961
|
|
|
* Payment Mode Select |
962
|
|
|
* |
963
|
|
|
* Renders the payment mode form by getting all the enabled payment gateways and |
964
|
|
|
* outputting them as radio buttons for the user to choose the payment gateway. If |
965
|
|
|
* a default payment gateway has been chosen from the Give Settings, it will be |
966
|
|
|
* automatically selected. |
967
|
|
|
* |
968
|
|
|
* @since 1.0 |
969
|
|
|
* |
970
|
|
|
* @param int $form_id |
971
|
|
|
* |
972
|
|
|
* @return void |
973
|
|
|
*/ |
974
|
|
|
function give_payment_mode_select( $form_id ) { |
975
|
|
|
|
976
|
|
|
$gateways = give_get_enabled_payment_gateways(); |
977
|
|
|
|
978
|
|
|
do_action( 'give_payment_mode_top', $form_id ); ?> |
979
|
|
|
|
980
|
|
|
<fieldset id="give-payment-mode-select"> |
981
|
|
|
<?php do_action( 'give_payment_mode_before_gateways_wrap' ); ?> |
982
|
|
|
<div id="give-payment-mode-wrap"> |
983
|
|
|
<legend class="give-payment-mode-label"><?php echo apply_filters( 'give_checkout_payment_method_text', esc_html__( 'Select Payment Method', 'give' ) ); ?> |
984
|
|
|
<span class="give-loading-text"><span class="give-loading-animation"></span> <?php esc_html_e( 'Loading...', 'give' ); ?></span> |
985
|
|
|
</legend> |
986
|
|
|
<?php |
987
|
|
|
|
988
|
|
|
do_action( 'give_payment_mode_before_gateways' ) ?> |
989
|
|
|
|
990
|
|
|
<ul id="give-gateway-radio-list"> |
991
|
|
|
<?php foreach ( $gateways as $gateway_id => $gateway ) : |
992
|
|
|
$checked = checked( $gateway_id, give_get_default_gateway( $form_id ), false ); |
993
|
|
|
$checked_class = $checked ? ' give-gateway-option-selected' : ''; |
994
|
|
|
echo '<li><label for="give-gateway-' . esc_attr( $gateway_id ) . '-' . $form_id . '" class="give-gateway-option' . $checked_class . '" id="give-gateway-option-' . esc_attr( $gateway_id ) . '">'; |
995
|
1 |
|
echo '<input type="radio" name="payment-mode" class="give-gateway" id="give-gateway-' . esc_attr( $gateway_id ) . '-' . $form_id . '" value="' . esc_attr( $gateway_id ) . '"' . $checked . '>' . esc_html( $gateway['checkout_label'] ); |
996
|
|
|
echo '</label></li>'; |
997
|
|
|
endforeach; ?> |
998
|
|
|
</ul> |
999
|
|
|
<?php do_action( 'give_payment_mode_after_gateways' ); ?> |
1000
|
|
|
</div> |
1001
|
|
|
<?php do_action( 'give_payment_mode_after_gateways_wrap' ); ?> |
1002
|
|
|
</fieldset> |
1003
|
|
|
|
1004
|
|
|
<?php do_action( 'give_payment_mode_bottom', $form_id ); ?> |
1005
|
|
|
|
1006
|
|
|
<div id="give_purchase_form_wrap"> |
1007
|
|
|
|
1008
|
|
|
<?php do_action( 'give_purchase_form', $form_id ); ?> |
1009
|
|
|
|
1010
|
|
|
</div><!-- the checkout fields are loaded into this--> |
1011
|
1 |
|
|
1012
|
1 |
|
<?php do_action( 'give_purchase_form_wrap_bottom', $form_id ); |
1013
|
1 |
|
|
1014
|
1 |
|
} |
1015
|
1 |
|
|
1016
|
|
|
add_action( 'give_payment_mode_select', 'give_payment_mode_select' ); |
1017
|
|
|
|
1018
|
|
|
|
1019
|
|
|
/** |
1020
|
|
|
* Renders the Checkout Agree to Terms, this displays a checkbox for users to |
1021
|
|
|
* agree the T&Cs set in the Give Settings. This is only displayed if T&Cs are |
1022
|
|
|
* set in the Give Settings. |
1023
|
|
|
* |
1024
|
|
|
* @since 1.0 |
1025
|
|
|
* |
1026
|
|
|
* @param int $form_id |
1027
|
|
|
* |
1028
|
|
|
* @return void |
1029
|
|
|
*/ |
1030
|
|
|
function give_terms_agreement( $form_id ) { |
1031
|
|
|
|
1032
|
|
|
$form_option = get_post_meta( $form_id, '_give_terms_option', true ); |
1033
|
1 |
|
$label = get_post_meta( $form_id, '_give_agree_label', true ); |
1034
|
|
|
$terms = get_post_meta( $form_id, '_give_agree_text', true ); |
1035
|
|
|
|
1036
|
|
|
if ( $form_option === 'yes' && ! empty( $terms ) ) { ?> |
1037
|
|
|
<fieldset id="give_terms_agreement"> |
1038
|
|
|
<div id="give_terms" class= "give_terms-<?php echo $form_id;?>" style="display:none;"> |
1039
|
|
|
<?php |
1040
|
|
|
do_action( 'give_before_terms' ); |
1041
|
|
|
echo wpautop( stripslashes( $terms ) ); |
1042
|
|
|
do_action( 'give_after_terms' ); |
1043
|
|
|
?> |
1044
|
|
|
</div> |
1045
|
|
|
<div id="give_show_terms"> |
1046
|
|
|
<a href="#" class="give_terms_links give_terms_links-<?php echo $form_id;?>"><?php esc_html_e( 'Show Terms', 'give' ); ?></a> |
1047
|
|
|
<a href="#" class="give_terms_links give_terms_links-<?php echo $form_id;?>" style="display:none;"><?php esc_html_e( 'Hide Terms', 'give' ); ?></a> |
1048
|
|
|
</div> |
1049
|
|
|
|
1050
|
|
|
<input name="give_agree_to_terms" class="required" type="checkbox" id="give_agree_to_terms" value="1"/> |
1051
|
|
|
<label |
1052
|
1 |
|
for="give_agree_to_terms"><?php echo ! empty( $label ) ? stripslashes( $label ) : esc_html__( 'Agree to Terms?', 'give' ); ?></label> |
1053
|
1 |
|
|
1054
|
1 |
|
</fieldset> |
1055
|
|
|
<?php |
1056
|
|
|
} |
1057
|
|
|
} |
1058
|
|
|
|
1059
|
|
|
add_action( 'give_purchase_form_before_submit', 'give_terms_agreement', 10, 1 ); |
1060
|
|
|
|
1061
|
|
|
/** |
1062
|
|
|
* Checkout Final Total |
1063
|
|
|
* |
1064
|
|
|
* Shows the final purchase total at the bottom of the checkout page |
1065
|
|
|
* |
1066
|
|
|
* @since 1.0 |
1067
|
|
|
* |
1068
|
|
|
* @param int $form_id |
1069
|
|
|
* |
1070
|
|
|
* @return void |
1071
|
|
|
*/ |
1072
|
|
|
function give_checkout_final_total( $form_id ) { |
1073
|
|
|
|
1074
|
|
|
if ( isset( $_POST['give_total'] ) ) { |
1075
|
|
|
$total = apply_filters( 'give_donation_total', $_POST['give_total'] ); |
1076
|
|
|
} else { |
1077
|
1 |
|
//default total |
1078
|
|
|
$total = give_get_default_form_amount( $form_id ); |
1079
|
|
|
} |
1080
|
|
|
//Only proceed if give_total available |
1081
|
|
|
if ( empty( $total ) ) { |
1082
|
|
|
return; |
1083
|
|
|
} |
1084
|
|
|
?> |
1085
|
|
|
<p id="give-final-total-wrap" class="form-wrap "> |
1086
|
|
|
<span class="give-donation-total-label"><?php echo apply_filters( 'give_donation_total_label', esc_html__( 'Donation Total:', 'give' ) ); ?></span> |
1087
|
|
|
<span class="give-final-total-amount" data-total="<?php echo give_format_amount( $total ); ?>"><?php echo give_currency_filter( give_format_amount( $total ) ); ?></span> |
1088
|
|
|
</p> |
1089
|
|
|
<?php |
1090
|
|
|
} |
1091
|
|
|
|
1092
|
|
|
add_action( 'give_purchase_form_before_submit', 'give_checkout_final_total', 999 ); |
1093
|
1 |
|
|
1094
|
|
|
|
1095
|
|
|
/** |
1096
|
|
|
* Renders the Checkout Submit section |
1097
|
1 |
|
* |
1098
|
|
|
* @since 1.0 |
1099
|
|
|
* |
1100
|
1 |
|
* @param int $form_id |
1101
|
|
|
* |
1102
|
|
|
* @return void |
1103
|
|
|
*/ |
1104
|
|
|
function give_checkout_submit( $form_id ) { |
1105
|
|
|
?> |
1106
|
|
|
<fieldset id="give_purchase_submit"> |
1107
|
|
|
<?php do_action( 'give_purchase_form_before_submit', $form_id ); ?> |
1108
|
|
|
|
1109
|
1 |
|
<?php give_checkout_hidden_fields( $form_id ); ?> |
1110
|
|
|
|
1111
|
|
|
<?php echo give_checkout_button_purchase( $form_id ); ?> |
1112
|
|
|
|
1113
|
|
|
<?php do_action( 'give_purchase_form_after_submit', $form_id ); ?> |
1114
|
|
|
|
1115
|
|
|
</fieldset> |
1116
|
|
|
<?php |
1117
|
|
|
} |
1118
|
|
|
|
1119
|
|
|
add_action( 'give_purchase_form_after_cc_form', 'give_checkout_submit', 9999 ); |
1120
|
|
|
|
1121
|
|
|
|
1122
|
|
|
/** |
1123
|
|
|
* Give Checkout Button Purchase |
1124
|
|
|
* |
1125
|
|
|
* Renders the Purchase button on the Checkout |
1126
|
|
|
* @since 1.0 |
1127
|
|
|
* |
1128
|
|
|
* @param int $form_id |
1129
|
|
|
* |
1130
|
|
|
* @return string |
1131
|
|
|
*/ |
1132
|
|
|
function give_checkout_button_purchase( $form_id ) { |
1133
|
|
|
|
1134
|
|
|
$display_label_field = get_post_meta( $form_id, '_give_checkout_label', true ); |
1135
|
|
|
$display_label = ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) ); |
1136
|
1 |
|
ob_start(); ?> |
1137
|
|
|
<div class="give-submit-button-wrap give-clearfix"> |
1138
|
|
|
<input type="submit" class="give-submit give-btn" id="give-purchase-button" name="give-purchase" value="<?php echo $display_label; ?>"/> |
1139
|
|
|
<span class="give-loading-animation"></span> |
1140
|
|
|
</div> |
1141
|
|
|
<?php |
1142
|
|
|
return apply_filters( 'give_checkout_button_purchase', ob_get_clean(), $form_id ); |
1143
|
|
|
} |
1144
|
|
|
|
1145
|
|
|
/** |
1146
|
|
|
* Give Agree to Terms |
1147
|
|
|
* |
1148
|
|
|
* Outputs the JavaScript code for the Agree to Terms section to toggle the T&Cs text |
1149
|
|
|
* @since 1.0 |
1150
|
|
|
* |
1151
|
|
|
* @param int $form_id |
1152
|
|
|
* |
1153
|
1 |
|
* @return void |
1154
|
1 |
|
*/ |
1155
|
|
|
function give_agree_to_terms_js( $form_id ) { |
1156
|
|
|
|
1157
|
|
|
$form_option = get_post_meta( $form_id, '_give_terms_option', true ); |
1158
|
|
|
|
1159
|
|
|
if ( $form_option === 'yes' ) { |
1160
|
|
|
?> |
1161
|
1 |
|
<script type="text/javascript"> |
1162
|
|
|
jQuery(document).ready(function ($) { |
1163
|
|
|
$('body').on('click', '.give_terms_links-<?php echo $form_id;?>', function (e) { |
1164
|
|
|
e.preventDefault(); |
1165
|
|
|
$('.give_terms-<?php echo $form_id;?>').slideToggle(); |
1166
|
|
|
$('.give_terms_links-<?php echo $form_id;?>').toggle(); |
1167
|
|
|
return false; |
1168
|
|
|
}); |
1169
|
|
|
}); |
1170
|
|
|
</script> |
1171
|
|
|
<?php |
1172
|
|
|
} |
1173
|
|
|
} |
1174
|
|
|
|
1175
|
|
|
add_action( 'give_checkout_form_top', 'give_agree_to_terms_js', 10, 2 ); |
1176
|
1 |
|
|
1177
|
|
|
/** |
1178
|
1 |
|
* Show Give Goals |
1179
|
|
|
* |
1180
|
|
|
* @since 1.0 |
1181
|
|
|
* @since 1.6 Add template for Give Goals Shortcode. |
1182
|
|
|
* More info is on https://github.com/WordImpress/Give/issues/411 |
1183
|
|
|
* |
1184
|
|
|
* @param int $form_id |
1185
|
|
|
* @param array $args |
1186
|
|
|
* |
1187
|
|
|
* @return mixed |
1188
|
|
|
*/ |
1189
|
|
|
|
1190
|
|
|
function give_show_goal_progress( $form_id, $args ) { |
1191
|
|
|
|
1192
|
1 |
|
ob_start(); |
1193
|
|
|
give_get_template( 'shortcode-goal' , array( 'form_id' => $form_id, 'args' => $args ) ); |
1194
|
|
|
|
1195
|
|
|
echo apply_filters( 'give_goal_output', ob_get_clean() ); |
1196
|
|
|
|
1197
|
|
|
return true; |
1198
|
|
|
} |
1199
|
|
|
|
1200
|
|
|
add_action( 'give_pre_form', 'give_show_goal_progress', 10, 2 ); |
1201
|
|
|
|
1202
|
|
|
/** |
1203
|
|
|
* Adds Actions to Render Form Content |
1204
|
|
|
* |
1205
|
|
|
* @since 1.0 |
1206
|
|
|
* |
1207
|
|
|
* @param int $form_id |
1208
|
|
|
* @param array $args |
1209
|
1 |
|
* |
1210
|
1 |
|
* @return void |
1211
|
1 |
|
*/ |
1212
|
1 |
|
function give_form_content( $form_id, $args ) { |
1213
|
1 |
|
|
1214
|
1 |
|
$show_content = ( isset( $args['show_content'] ) && ! empty( $args['show_content'] ) ) |
1215
|
1 |
|
? $args['show_content'] |
1216
|
1 |
|
: get_post_meta( $form_id, '_give_content_option', true ); |
1217
|
|
|
|
1218
|
|
|
if ( $show_content !== 'none' ) { |
1219
|
1 |
|
//add action according to value |
1220
|
|
|
add_action( $show_content, 'give_form_display_content', 10, 2 ); |
1221
|
|
|
} |
1222
|
|
|
} |
1223
|
|
|
|
1224
|
1 |
|
add_action( 'give_pre_form_output', 'give_form_content', 10, 2 ); |
1225
|
1 |
|
|
1226
|
1 |
|
/** |
1227
|
1 |
|
* Renders Post Form Content |
1228
|
1 |
|
* |
1229
|
|
|
* Displays content for Give forms; fired by action from give_form_content |
1230
|
1 |
|
* |
1231
|
|
|
* @param int $form_id |
1232
|
|
|
* |
1233
|
|
|
* @return void |
1234
|
|
|
* @since 1.0 |
1235
|
|
|
*/ |
1236
|
|
|
function give_form_display_content( $form_id, $args ) { |
1237
|
|
|
|
1238
|
|
|
$content = wpautop( get_post_meta( $form_id, '_give_form_content', true ) ); |
1239
|
|
|
$show_content = ( isset( $args['show_content'] ) && ! empty( $args['show_content'] ) ) |
1240
|
|
|
? $args['show_content'] |
1241
|
|
|
: get_post_meta( $form_id, '_give_content_option', true ); |
1242
|
|
|
|
1243
|
|
|
if ( give_get_option( 'disable_the_content_filter' ) !== 'on' ) { |
1244
|
|
|
$content = apply_filters( 'the_content', $content ); |
1245
|
|
|
} |
1246
|
|
|
|
1247
|
|
|
$output = '<div id="give-form-content-' . $form_id . '" class="give-form-content-wrap" >' . $content . '</div>'; |
1248
|
|
|
|
1249
|
|
|
echo apply_filters( 'give_form_content_output', $output ); |
1250
|
|
|
|
1251
|
|
|
//remove action to prevent content output on addition forms on page |
1252
|
|
|
//@see: https://github.com/WordImpress/Give/issues/634 |
1253
|
|
|
remove_action( $show_content, 'give_form_display_content' ); |
1254
|
|
|
} |
1255
|
|
|
|
1256
|
|
|
|
1257
|
|
|
/** |
1258
|
|
|
* Renders the hidden Checkout fields |
1259
|
|
|
* |
1260
|
|
|
* @since 1.0 |
1261
|
|
|
* |
1262
|
|
|
* @param int $form_id |
1263
|
|
|
* |
1264
|
|
|
* @return void |
1265
|
|
|
*/ |
1266
|
|
|
function give_checkout_hidden_fields( $form_id ) { |
1267
|
|
|
|
1268
|
|
|
do_action( 'give_hidden_fields_before', $form_id ); |
1269
|
|
|
if ( is_user_logged_in() ) { ?> |
1270
|
|
|
<input type="hidden" name="give-user-id" value="<?php echo get_current_user_id(); ?>"/> |
1271
|
|
|
<?php } ?> |
1272
|
|
|
<input type="hidden" name="give_action" value="purchase"/> |
1273
|
|
|
<input type="hidden" name="give-gateway" value="<?php echo give_get_chosen_gateway( $form_id ); ?>"/> |
1274
|
|
|
<?php |
1275
|
|
|
do_action( 'give_hidden_fields_after', $form_id ); |
1276
|
|
|
|
1277
|
|
|
} |
1278
|
|
|
|
1279
|
|
|
/** |
1280
|
|
|
* Filter Success Page Content |
1281
|
|
|
* |
1282
|
|
|
* Applies filters to the success page content. |
1283
|
|
|
* |
1284
|
|
|
* @since 1.0 |
1285
|
|
|
* |
1286
|
|
|
* @param string $content Content before filters |
1287
|
|
|
* |
1288
|
|
|
* @return string $content Filtered content |
1289
|
|
|
*/ |
1290
|
|
|
function give_filter_success_page_content( $content ) { |
1291
|
|
|
|
1292
|
|
|
global $give_options; |
|
|
|
|
1293
|
|
|
|
1294
|
|
|
if ( isset( $give_options['success_page'] ) && isset( $_GET['payment-confirmation'] ) && is_page( $give_options['success_page'] ) ) { |
1295
|
|
|
if ( has_filter( 'give_payment_confirm_' . $_GET['payment-confirmation'] ) ) { |
1296
|
|
|
$content = apply_filters( 'give_payment_confirm_' . $_GET['payment-confirmation'], $content ); |
1297
|
|
|
} |
1298
|
|
|
} |
1299
|
|
|
|
1300
|
|
|
return $content; |
1301
|
|
|
} |
1302
|
1 |
|
|
1303
|
1 |
|
add_filter( 'the_content', 'give_filter_success_page_content' ); |
1304
|
1 |
|
|
1305
|
|
|
|
1306
|
1 |
|
/** |
1307
|
|
|
* Test Mode Frontend Warning |
1308
|
1 |
|
* |
1309
|
1 |
|
* Displays a notice on the frontend for donation forms |
1310
|
1 |
|
* @since 1.1 |
1311
|
|
|
*/ |
1312
|
|
|
|
1313
|
|
|
function give_test_mode_frontend_warning() { |
1314
|
|
|
|
1315
|
|
|
$test_mode = give_get_option( 'test_mode' ); |
1316
|
|
|
|
1317
|
|
|
if ( $test_mode == 'on' ) { |
1318
|
|
|
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 transactions are processed.', 'give' ) . '</p></div>'; |
1319
|
|
|
} |
1320
|
|
|
} |
1321
|
|
|
|
1322
|
|
|
add_action( 'give_pre_form', 'give_test_mode_frontend_warning', 10 ); |
1323
|
|
|
|
1324
|
|
|
|
1325
|
|
|
/** |
1326
|
|
|
* Members-only Form |
1327
|
|
|
* |
1328
|
|
|
* If "Disable Guest Donations" and "Display Register / Login" is set to none |
1329
|
|
|
* |
1330
|
|
|
* @since 1.4.1 |
1331
|
|
|
* |
1332
|
|
|
* @param string $final_output |
1333
|
|
|
* @param array $args |
1334
|
|
|
* |
1335
|
|
|
* @return string |
1336
|
|
|
*/ |
1337
|
|
|
|
1338
|
|
|
function give_members_only_form( $final_output, $args ) { |
1339
|
|
|
|
1340
|
|
|
$form_id = isset( $args['form_id'] ) ? $args['form_id'] : 0; |
1341
|
|
|
|
1342
|
|
|
//Sanity Check: Must have form_id & not be logged in |
1343
|
|
|
if ( empty( $form_id ) || is_user_logged_in() ) { |
1344
|
|
|
return $final_output; |
1345
|
|
|
} |
1346
|
|
|
|
1347
|
|
|
//Logged in only and Register / Login set to none |
1348
|
|
|
if ( give_logged_in_only( $form_id ) && give_show_login_register_option( $form_id ) == 'none' ) { |
1349
|
|
|
|
1350
|
|
|
$final_output = give_output_error( esc_html__( 'Please login in order to complete your donation.', 'give' ), false ); |
1351
|
|
|
|
1352
|
|
|
return apply_filters( 'give_members_only_output', $final_output, $form_id ); |
1353
|
|
|
|
1354
|
|
|
} |
1355
|
|
|
|
1356
|
1 |
|
return $final_output; |
1357
|
|
|
|
1358
|
|
|
} |
1359
|
|
|
|
1360
|
|
|
add_filter( 'give_donate_form', 'give_members_only_form', 10, 2 ); |
1361
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.