Completed
Push — master ( 0af146...28843d )
by Ravinder
21:08
created

template.php ➔ give_terms_agreement()   C

Complexity

Conditions 8
Paths 10

Size

Total Lines 64
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 35
nc 10
nop 1
dl 0
loc 64
rs 6.8232
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 26 and the first side effect is on line 14.

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.

Loading history...
2
/**
3
 * Give Form Template
4
 *
5
 * @package     Give
6
 * @subpackage  Forms
7
 * @copyright   Copyright (c) 2016, WordImpress
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
 * @since  1.0
21
 *
22
 * @param  array $args An array of form arguments.
23
 *
24
 * @return string Donation form.
0 ignored issues
show
Documentation introduced by
Should the return type not be false|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
25
 */
26
function give_get_donation_form( $args = array() ) {
27
28
	global $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
29
30
	$form_id = is_object( $post ) ? $post->ID : 0;
31
32
	if ( isset( $args['id'] ) ) {
33
		$form_id = $args['id'];
34
	}
35
36
	$defaults = apply_filters( 'give_form_args_defaults', array(
37
		'form_id' => $form_id,
38
	) );
39
40
	$args = wp_parse_args( $args, $defaults );
41
42
	$form = new Give_Donate_Form( $args['form_id'] );
43
44
	//bail if no form ID.
45
	if ( empty( $form->ID ) ) {
46
		return false;
47
	}
48
49
	$payment_mode = give_get_chosen_gateway( $form->ID );
50
51
	$form_action = add_query_arg( apply_filters( 'give_form_action_args', array(
52
		'payment-mode' => $payment_mode,
53
	) ),
54
		give_get_current_page_url()
55
	);
56
57
	//Sanity Check: Donation form not published or user doesn't have permission to view drafts.
58
	if (
59
		( 'publish' !== $form->post_status && ! current_user_can( 'edit_give_forms', $form->ID ) )
60
		|| ( 'trash' === $form->post_status )
61
	) {
62
		return false;
63
	}
64
65
	//Get the form wrap CSS classes.
66
	$form_wrap_classes = $form->get_form_wrap_classes( $args );
67
68
	//Get the <form> tag wrap CSS classes.
69
	$form_classes = $form->get_form_classes( $args );
70
71
	ob_start();
72
73
	/**
74
	 * Fires while outputting donation form, before the form wrapper div.
75
	 *
76
	 * @since 1.0
77
	 *
78
	 * @param int   $form_id The form ID.
79
	 * @param array $args    An array of form arguments.
80
	 */
81
	do_action( 'give_pre_form_output', $form->ID, $args );
82
83
	?>
84
	<div id="give-form-<?php echo $form->ID; ?>-wrap" class="<?php echo $form_wrap_classes; ?>">
85
86
		<?php if ( $form->is_close_donation_form() ) {
87
88
			//Get Goal thank you message.
89
			$display_thankyou_message = get_post_meta( $form->ID, '_give_form_goal_achieved_message', true );
90
			$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' );
91
92
			//Print thank you message.
93
			echo apply_filters( 'give_goal_closed_output', give_output_error( $display_thankyou_message, false, 'success' ), $form->ID );
94
95
		} else {
96
			/**
97
			 * Show form title:
98
			 * 1. if show_title params set to true
99
			 * 2. if admin set form display_style to button
100
			 */
101
			$form_title = apply_filters( 'give_form_title', '<h2 class="give-form-title">' . get_the_title( $form_id ) . '</h2>' );
102
			if (
103
				(
104
					( isset( $args['show_title'] ) && $args['show_title'] == true )
105
					|| ( 'button' === get_post_meta( $form_id, '_give_payment_display', true ) )
106
				)
107
				&& ! doing_action( 'give_single_form_summary' )
108
			) {
109
				echo $form_title;
110
			}
111
112
			/**
113
			 * Fires while outputing donation form, before the form.
114
			 *
115
			 * @since 1.0
116
			 *
117
			 * @param int   $form_id The form ID.
118
			 * @param array $args    An array of form arguments.
119
			 */
120
			do_action( 'give_pre_form', $form->ID, $args );
121
			?>
122
123
			<form id="give-form-<?php echo $form_id; ?>" class="<?php echo $form_classes; ?>"
124
			      action="<?php echo esc_url_raw( $form_action ); ?>" method="post">
125
				<input type="hidden" name="give-form-id" value="<?php echo $form->ID; ?>"/>
126
				<input type="hidden" name="give-form-title" value="<?php echo htmlentities( $form->post_title ); ?>"/>
127
				<input type="hidden" name="give-current-url"
128
				       value="<?php echo htmlspecialchars( give_get_current_page_url() ); ?>"/>
129
				<input type="hidden" name="give-form-url"
130
				       value="<?php echo htmlspecialchars( give_get_current_page_url() ); ?>"/>
131
				<input type="hidden" name="give-form-minimum"
132
				       value="<?php echo give_format_amount( give_get_form_minimum_price( $form->ID ) ); ?>"/>
133
134
				<!-- The following field is for robots only, invisible to humans: -->
135
				<span class="give-hidden" style="display: none !important;">
136
					<label for="give-form-honeypot-<?php echo $form_id; ?>"></label>
137
					<input id="give-form-honeypot-<?php echo $form_id; ?>" type="text" name="give-honeypot"
138
					       class="give-honeypot give-hidden"/>
139
				</span>
140
141
				<?php
142
143
				//Price ID hidden field for variable (mult-level) donation forms.
144
				if ( give_has_variable_prices( $form_id ) ) {
145
					//get default selected price ID.
146
					$prices   = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $form_id ), $form_id );
147
					$price_id = 0;
148
					//loop through prices.
149
					foreach ( $prices as $price ) {
150
						if ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) {
151
							$price_id = $price['_give_id']['level_id'];
152
						};
153
					}
154
					?>
155
					<input type="hidden" name="give-price-id" value="<?php echo $price_id; ?>"/>
156
				<?php }
157
158
				/**
159
				 * Fires while outputing donation form, before all other fields.
160
				 *
161
				 * @since 1.0
162
				 *
163
				 * @param int   $form_id The form ID.
164
				 * @param array $args    An array of form arguments.
165
				 */
166
				do_action( 'give_checkout_form_top', $form->ID, $args );
167
168
				/**
169
				 * Fires while outputing donation form, for payment gatways fields.
170
				 *
171
				 * @since 1.7
172
				 *
173
				 * @param int   $form_id The form ID.
174
				 * @param array $args    An array of form arguments.
175
				 */
176
				do_action( 'give_payment_mode_select', $form->ID, $args );
177
178
				/**
179
				 * Fires while outputing donation form, after all other fields.
180
				 *
181
				 * @since 1.0
182
				 *
183
				 * @param int   $form_id The form ID.
184
				 * @param array $args    An array of form arguments.
185
				 */
186
				do_action( 'give_checkout_form_bottom', $form->ID, $args );
187
188
				?>
189
			</form>
190
191
			<?php
192
			/**
193
			 * Fires while outputing donation form, after the form.
194
			 *
195
			 * @since 1.0
196
			 *
197
			 * @param int   $form_id The form ID.
198
			 * @param array $args    An array of form arguments.
199
			 */
200
			do_action( 'give_post_form', $form->ID, $args );
201
202
		}
203
		?>
204
205
	</div><!--end #give-form-<?php echo absint( $form->ID ); ?>-->
206
	<?php
207
208
	/**
209
	 * Fires while outputing donation form, after the form wapper div.
210
	 *
211
	 * @since 1.0
212
	 *
213
	 * @param int   $form_id The form ID.
214
	 * @param array $args    An array of form arguments.
215
	 */
216
	do_action( 'give_post_form_output', $form->ID, $args );
217
218
	$final_output = ob_get_clean();
219
220
	echo apply_filters( 'give_donate_form', $final_output, $args );
221
}
222
223
/**
224
 * Give Show Donation Form.
225
 *
226
 * Renders the Donation Form, hooks are provided to add to the checkout form.
227
 * The default Donation Form rendered displays a list of the enabled payment
228
 * gateways, a user registration form (if enable) and a credit card info form
229
 * if credit cards are enabled.
230
 *
231
 * @since  1.0
232
 *
233
 * @param  int $form_id The form ID.
234
 *
235
 * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
236
 */
237
function give_show_purchase_form( $form_id ) {
238
239
	$payment_mode = give_get_chosen_gateway( $form_id );
240
241
	if ( ! isset( $form_id ) && isset( $_POST['give_form_id'] ) ) {
242
		$form_id = $_POST['give_form_id'];
243
	}
244
245
	/**
246
	 * Fire before donation form render.
247
	 *
248
	 * @since 1.7
249
	 */
250
	do_action( 'give_donation_form_top', $form_id );
251
252
	if ( give_can_checkout() && isset( $form_id ) ) {
253
254
		/**
255
		 * Fires while displaying donation form, before registration login.
256
		 *
257
		 * @since 1.7
258
		 */
259
		do_action( 'give_donation_form_before_register_login', $form_id );
260
261
		/**
262
		 * Fire when register/login form fields render.
263
		 *
264
		 * @since 1.7
265
		 */
266
		do_action( 'give_donation_form_register_login_fields', $form_id );
267
268
		/**
269
		 * Fire when credit card form fields render.
270
		 *
271
		 * @since 1.7
272
		 */
273
		do_action( 'give_donation_form_before_cc_form', $form_id );
274
275
		// Load the credit card form and allow gateways to load their own if they wish.
276
		if ( has_action( 'give_' . $payment_mode . '_cc_form' ) ) {
277
			/**
278
			 * Fires while displaying donation form, credit card form fields for a given gateway.
279
			 *
280
			 * @since 1.0
281
			 *
282
			 * @param int $form_id The form ID.
283
			 */
284
			do_action( "give_{$payment_mode}_cc_form", $form_id );
285
		} else {
286
			/**
287
			 * Fires while displaying donation form, credit card form fields.
288
			 *
289
			 * @since 1.0
290
			 *
291
			 * @param int $form_id The form ID.
292
			 */
293
			do_action( 'give_cc_form', $form_id );
294
		}
295
296
		/**
297
		 * Fire after credit card form fields render.
298
		 *
299
		 * @since 1.7
300
		 */
301
		do_action( 'give_donation_form_after_cc_form', $form_id );
302
303
	} else {
304
		/**
305
		 * Fire if user can not donate.
306
		 *
307
		 * @since 1.7
308
		 */
309
		do_action( 'give_donation_form_no_access', $form_id );
310
311
	}
312
313
	/**
314
	 * Fire after donation form rendered.
315
	 *
316
	 * @since 1.7
317
	 */
318
	do_action( 'give_donation_form_bottom', $form_id );
319
}
320
321
add_action( 'give_donation_form', 'give_show_purchase_form' );
322
323
/**
324
 * Give Show Login/Register Form Fields.
325
 *
326
 * @since  1.4.1
327
 *
328
 * @param  int $form_id The form ID.
329
 *
330
 * @return void
331
 */
332
function give_show_register_login_fields( $form_id ) {
333
334
	$show_register_form = give_show_login_register_option( $form_id );
335
336
	if ( ( $show_register_form === 'registration' || ( $show_register_form === 'both' && ! isset( $_GET['login'] ) ) ) && ! is_user_logged_in() ) :
337
		?>
338
		<div id="give-checkout-login-register-<?php echo $form_id; ?>">
339
			<?php
340
			/**
341
			 * Fire if user registration form render.
342
			 *
343
			 * @since 1.7
344
			 */
345
			do_action( 'give_donation_form_register_fields', $form_id );
346
			?>
347
		</div>
348
		<?php
349
	elseif ( ( $show_register_form === 'login' || ( $show_register_form === 'both' && isset( $_GET['login'] ) ) ) && ! is_user_logged_in() ) :
350
		?>
351
		<div id="give-checkout-login-register-<?php echo $form_id; ?>">
352
			<?php
353
			/**
354
			 * Fire if user login form render.
355
			 *
356
			 * @since 1.7
357
			 */
358
			do_action( 'give_donation_form_login_fields', $form_id );
359
			?>
360
		</div>
361
		<?php
362
	endif;
363
364
	if ( ( ! isset( $_GET['login'] ) && is_user_logged_in() ) || ! isset( $show_register_form ) || 'none' === $show_register_form || 'login' === $show_register_form ) {
365
		/**
366
		 * Fire when user info render.
367
		 *
368
		 * @since 1.7
369
		 */
370
		do_action( 'give_donation_form_after_user_info', $form_id );
371
	}
372
}
373
374
add_action( 'give_donation_form_register_login_fields', 'give_show_register_login_fields' );
375
376
/**
377
 * Donation Amount Field.
378
 *
379
 * 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.
380
 *
381
 * @since  1.0
382
 *
383
 * @param  int   $form_id The form ID.
384
 * @param  array $args    An array of form arguments.
385
 *
386
 * @return void
387
 */
388
function give_output_donation_amount_top( $form_id = 0, $args = array() ) {
389
390
	$give_options        = give_get_settings();
391
	$variable_pricing    = give_has_variable_prices( $form_id );
392
	$allow_custom_amount = get_post_meta( $form_id, '_give_custom_amount', true );
393
	$currency_position   = isset( $give_options['currency_position'] ) ? $give_options['currency_position'] : 'before';
394
	$symbol              = give_currency_symbol( give_get_currency() );
395
	$currency_output     = '<span class="give-currency-symbol give-currency-position-' . $currency_position . '">' . $symbol . '</span>';
396
	$default_amount      = give_format_amount( give_get_default_form_amount( $form_id ) );
397
	$custom_amount_text  = get_post_meta( $form_id, '_give_custom_amount_text', true );
398
399
	/**
400
	 * Fires while displaying donation form, before donation level fields.
401
	 *
402
	 * @since 1.0
403
	 *
404
	 * @param int   $form_id The form ID.
405
	 * @param array $args    An array of form arguments.
406
	 */
407
	do_action( 'give_before_donation_levels', $form_id, $args );
408
409
	//Set Price, No Custom Amount Allowed means hidden price field
410
	if ( ! give_is_setting_enabled( $allow_custom_amount ) ) {
411
		?>
412
		<label class="give-hidden" for="give-amount-hidden"><?php esc_html_e( 'Donation Amount:', 'give' ); ?></label>
413
		<input id="give-amount" class="give-amount-hidden" type="hidden" name="give-amount"
414
		       value="<?php echo $default_amount; ?>" required aria-required="true"/>
415
		<div class="set-price give-donation-amount form-row-wide">
416
			<?php if ( $currency_position == 'before' ) {
417
				echo $currency_output;
418
			} ?>
419
			<span id="give-amount-text" class="give-text-input give-amount-top"><?php echo $default_amount; ?></span>
420
			<?php if ( $currency_position == 'after' ) {
421
				echo $currency_output;
422
			} ?>
423
		</div>
424
		<?php
425
	} else {
426
		//Custom Amount Allowed.
427
		?>
428
		<div class="give-total-wrap">
429
			<div class="give-donation-amount form-row-wide">
430
				<?php if ( $currency_position == 'before' ) {
431
					echo $currency_output;
432
				} ?>
433
				<label class="give-hidden" for="give-amount"><?php esc_html_e( 'Donation Amount:', 'give' ); ?></label>
434
				<input class="give-text-input give-amount-top" id="give-amount" name="give-amount" type="tel"
435
				       placeholder="" value="<?php echo $default_amount; ?>" autocomplete="off">
436
				<?php if ( $currency_position == 'after' ) {
437
					echo $currency_output;
438
				} ?>
439
			</div>
440
		</div>
441
	<?php }
442
443
	/**
444
	 * Fires while displaying donation form, after donation amounf field(s).
445
	 *
446
	 * @since 1.0
447
	 *
448
	 * @param int   $form_id The form ID.
449
	 * @param array $args    An array of form arguments.
450
	 */
451
	do_action( 'give_after_donation_amount', $form_id, $args );
452
453
	//Custom Amount Text
454
	if ( ! $variable_pricing &&  give_is_setting_enabled( $allow_custom_amount ) && ! empty( $custom_amount_text ) ) { ?>
455
		<p class="give-custom-amount-text"><?php echo $custom_amount_text; ?></p>
456
	<?php }
457
458
	//Output Variable Pricing Levels.
459
	if ( $variable_pricing ) {
460
		give_output_levels( $form_id );
461
	}
462
463
	/**
464
	 * Fires while displaying donation form, after donation level fields.
465
	 *
466
	 * @since 1.0
467
	 *
468
	 * @param int   $form_id The form ID.
469
	 * @param array $args    An array of form arguments.
470
	 */
471
	do_action( 'give_after_donation_levels', $form_id, $args );
472
}
473
474
add_action( 'give_checkout_form_top', 'give_output_donation_amount_top', 10, 2 );
475
476
/**
477
 * Outputs the Donation Levels in various formats such as dropdown, radios, and buttons.
478
 *
479
 * @since  1.0
480
 *
481
 * @param  int $form_id The form ID.
482
 *
483
 * @return string Donation levels.
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
484
 */
485
function give_output_levels( $form_id ) {
486
487
	//Get variable pricing.
488
	$prices             = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $form_id ), $form_id );
489
	$display_style      = get_post_meta( $form_id, '_give_display_style', true );
490
	$custom_amount      = get_post_meta( $form_id, '_give_custom_amount', true );
491
	$custom_amount_text = get_post_meta( $form_id, '_give_custom_amount_text', true );
492
	if ( empty( $custom_amount_text ) ) {
493
		$custom_amount_text = esc_html__( 'Give a Custom Amount', 'give' );
494
	}
495
496
	$output  = '';
497
	$counter = 0;
498
499
	switch ( $display_style ) {
500
		case 'buttons':
501
502
			$output .= '<ul id="give-donation-level-button-wrap" class="give-donation-levels-wrap give-list-inline">';
503
504
			foreach ( $prices as $price ) {
505
				$counter ++;
506
				$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 );
507
				$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 );
508
509
				$output .= '<li>';
510
				$output .= '<button type="button" data-price-id="' . $price['_give_id']['level_id'] . '" class=" ' . $level_classes . '" value="' . give_format_amount( $price['_give_amount'] ) . '">';
511
				$output .= $level_text;
512
				$output .= '</button>';
513
				$output .= '</li>';
514
515
			}
516
517
			//Custom Amount.
518
			if ( give_is_setting_enabled( $custom_amount ) && ! empty( $custom_amount_text ) ) {
519
				$output .= '<li>';
520
				$output .= '<button type="button" data-price-id="custom" class="give-donation-level-btn give-btn give-btn-level-custom" value="custom">';
521
				$output .= $custom_amount_text;
522
				$output .= '</button>';
523
				$output .= '</li>';
524
			}
525
526
			$output .= '</ul>';
527
528
			break;
529
530
		case 'radios':
531
532
			$output .= '<ul id="give-donation-level-radio-list" class="give-donation-levels-wrap">';
533
534
			foreach ( $prices as $price ) {
535
				$counter ++;
536
				$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 );
537
				$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 );
538
539
				$output .= '<li>';
540
				$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'] ) . '">';
541
				$output .= '<label for="give-radio-level-' . $counter . '">' . $level_text . '</label>';
542
				$output .= '</li>';
543
544
			}
545
546
			//Custom Amount.
547
			if ( give_is_setting_enabled( $custom_amount ) && ! empty( $custom_amount_text ) ) {
548
				$output .= '<li>';
549
				$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">';
550
				$output .= '<label for="give-radio-level-custom">' . $custom_amount_text . '</label>';
551
				$output .= '</li>';
552
			}
553
554
			$output .= '</ul>';
555
556
			break;
557
558
		case 'dropdown':
559
560
			$output .= '<label for="give-donation-level" class="give-hidden">' . esc_html__( 'Choose Your Donation Amount', 'give' ) . ':</label>';
561
			$output .= '<select id="give-donation-level-' . $form_id . '" class="give-select give-select-level give-donation-levels-wrap">';
562
563
			//first loop through prices.
564
			foreach ( $prices as $price ) {
565
				$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 );
566
				$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 );
567
568
				$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'] ) . '">';
569
				$output .= $level_text;
570
				$output .= '</option>';
571
572
			}
573
574
			//Custom Amount.
575
			if ( give_is_setting_enabled( $custom_amount ) && ! empty( $custom_amount_text ) ) {
576
				$output .= '<option data-price-id="custom" class="give-donation-level-custom" value="custom">' . $custom_amount_text . '</option>';
577
			}
578
579
			$output .= '</select>';
580
581
			break;
582
	}
583
584
	echo apply_filters( 'give_form_level_output', $output, $form_id );
585
}
586
587
/**
588
 * Display Reveal & Lightbox Button.
589
 *
590
 * Outputs a button to reveal form fields.
591
 *
592
 * @since  1.0
593
 *
594
 * @param  int   $form_id The form ID.
595
 * @param  array $args    An array of form arguments.
596
 *
597
 * @return string Checkout button.
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
598
 */
599
function give_display_checkout_button( $form_id, $args ) {
600
601
	$display_option = ( isset( $args['display_style'] ) && ! empty( $args['display_style'] ) )
602
		? $args['display_style']
603
		: get_post_meta( $form_id, '_give_payment_display', true );
604
605
	if( 'button' === $display_option ) {
606
		$display_option = 'modal';
607
	}elseif ( $display_option === 'onpage' ) {
608
		return '';
609
	}
610
611
	$display_label_field = get_post_meta( $form_id, '_give_reveal_label', true );
612
	$display_label       = ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) );
613
614
	$output = '<button type="button" class="give-btn give-btn-' . $display_option . '">' . $display_label . '</button>';
615
616
	echo apply_filters( 'give_display_checkout_button', $output );
617
}
618
619
add_action( 'give_after_donation_levels', 'give_display_checkout_button', 10, 2 );
620
621
/**
622
 * Shows the User Info fields in the Personal Info box, more fields can be added via the hooks provided.
623
 *
624
 * @since  1.0
625
 *
626
 * @param  int $form_id The form ID.
627
 *
628
 * @return void
629
 */
630
function give_user_info_fields( $form_id ) {
631
	// Get user info.
632
	$give_user_info = _give_get_prefill_form_field_values( $form_id );
633
634
	/**
635
	 * Fire before user personal information fields
636
	 *
637
	 * @since 1.7
638
	 */
639
	do_action( 'give_donation_form_before_personal_info', $form_id );
640
	?>
641
	<fieldset id="give_checkout_user_info">
642
		<legend><?php echo apply_filters( 'give_checkout_personal_info_text', esc_html__( 'Personal Info', 'give' ) ); ?></legend>
643
		<p id="give-first-name-wrap" class="form-row form-row-first">
644
			<label class="give-label" for="give-first">
645
				<?php esc_html_e( 'First Name', 'give' ); ?>
646
				<?php if ( give_field_is_required( 'give_first', $form_id ) ) : ?>
647
					<span class="give-required-indicator">*</span>
648
				<?php endif ?>
649
				<span class="give-tooltip give-icon give-icon-question"
650
				      data-tooltip="<?php esc_attr_e( 'We will use this to personalize your account experience.', 'give' ); ?>"></span>
651
			</label>
652
			<input
653
				class="give-input required"
654
				type="text"
655
				name="give_first"
656
				placeholder="<?php esc_attr_e( 'First Name', 'give' ); ?>"
657
				id="give-first"
658
				value="<?php echo isset( $give_user_info['give_first'] ) ? $give_user_info['give_first'] : ''; ?>"
659
				<?php echo( give_field_is_required( 'give_first', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
660
			/>
661
		</p>
662
663
		<p id="give-last-name-wrap" class="form-row form-row-last">
664
			<label class="give-label" for="give-last">
665
				<?php esc_html_e( 'Last Name', 'give' ); ?>
666
				<?php if ( give_field_is_required( 'give_last', $form_id ) ) : ?>
667
					<span class="give-required-indicator">*</span>
668
				<?php endif ?>
669
				<span class="give-tooltip give-icon give-icon-question"
670
				      data-tooltip="<?php esc_attr_e( 'We will use this as well to personalize your account experience.', 'give' ); ?>"></span>
671
			</label>
672
673
			<input
674
				class="give-input<?php echo( give_field_is_required( 'give_last', $form_id ) ? ' required' : '' ); ?>"
675
				type="text"
676
				name="give_last"
677
				id="give-last"
678
				placeholder="<?php esc_attr_e( 'Last Name', 'give' ); ?>"
679
				value="<?php echo isset( $give_user_info['give_last'] ) ? $give_user_info['give_last'] : ''; ?>"
680
				<?php echo( give_field_is_required( 'give_last', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
681
			/>
682
		</p>
683
684
		<?php
685
		/**
686
		 * Fire before user email field
687
		 *
688
		 * @since 1.7
689
		 */
690
		do_action( 'give_donation_form_before_email', $form_id );
691
		?>
692
		<p id="give-email-wrap" class="form-row form-row-wide">
693
			<label class="give-label" for="give-email">
694
				<?php esc_html_e( 'Email Address', 'give' ); ?>
695
				<?php if ( give_field_is_required( 'give_email', $form_id ) ) { ?>
696
					<span class="give-required-indicator">*</span>
697
				<?php } ?>
698
				<span class="give-tooltip give-icon give-icon-question"
699
				      data-tooltip="<?php esc_attr_e( 'We will send the donation receipt to this address.', 'give' ); ?>"></span>
700
			</label>
701
702
			<input
703
				class="give-input required"
704
				type="email"
705
				name="give_email"
706
				placeholder="<?php esc_attr_e( 'Email Address', 'give' ); ?>"
707
				id="give-email"
708
				value="<?php echo isset( $give_user_info['give_email'] ) ? $give_user_info['give_email'] : ''; ?>"
709
				<?php echo( give_field_is_required( 'give_email', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
710
			/>
711
712
		</p>
713
		<?php
714
		/**
715
		 * Fire after user email field
716
		 *
717
		 * @since 1.7
718
		 */
719
		do_action( 'give_donation_form_after_email', $form_id );
720
721
		/**
722
		 * Fire after personal email field
723
		 *
724
		 * @since 1.7
725
		 */
726
		do_action( 'give_donation_form_user_info', $form_id );
727
		?>
728
	</fieldset>
729
	<?php
730
	/**
731
	 * Fire after user personal information fields
732
	 *
733
	 * @since 1.7
734
	 */
735
	do_action( 'give_donation_form_after_personal_info', $form_id );
736
}
737
738
add_action( 'give_donation_form_after_user_info', 'give_user_info_fields' );
739
add_action( 'give_register_fields_before', 'give_user_info_fields' );
740
741
/**
742
 * Renders the credit card info form.
743
 *
744
 * @since  1.0
745
 *
746
 * @param  int $form_id The form ID.
747
 *
748
 * @return void
749
 */
750
function give_get_cc_form( $form_id ) {
751
752
	ob_start();
753
754
	/**
755
	 * Fires while rendering credit card info form, before the fields.
756
	 *
757
	 * @since 1.0
758
	 *
759
	 * @param int $form_id The form ID.
760
	 */
761
	do_action( 'give_before_cc_fields', $form_id );
762
	?>
763
	<fieldset id="give_cc_fields-<?php echo $form_id ?>" class="give-do-validate">
764
		<legend><?php echo apply_filters( 'give_credit_card_fieldset_heading', esc_html__( 'Credit Card Info', 'give' ) ); ?></legend>
765
		<?php if ( is_ssl() ) : ?>
766
			<div id="give_secure_site_wrapper-<?php echo $form_id ?>">
767
				<span class="give-icon padlock"></span>
768
				<span><?php esc_html_e( 'This is a secure SSL encrypted payment.', 'give' ); ?></span>
769
			</div>
770
		<?php endif; ?>
771
		<p id="give-card-number-wrap-<?php echo $form_id ?>" class="form-row form-row-two-thirds">
772
			<label for="card_number-<?php echo $form_id ?>" class="give-label">
773
				<?php esc_html_e( 'Card Number', 'give' ); ?>
774
				<span class="give-required-indicator">*</span>
775
				<span class="give-tooltip give-icon give-icon-question"
776
				      data-tooltip="<?php esc_attr_e( 'The (typically) 16 digits on the front of your credit card.', 'give' ); ?>"></span>
777
				<span class="card-type"></span>
778
			</label>
779
780
			<input type="tel" autocomplete="off" name="card_number" id="card_number-<?php echo $form_id ?>"
781
			       class="card-number give-input required" placeholder="<?php esc_attr_e( 'Card number', 'give' ); ?>"
782
			       required aria-required="true"/>
783
		</p>
784
785
		<p id="give-card-cvc-wrap-<?php echo $form_id ?>" class="form-row form-row-one-third">
786
			<label for="card_cvc-<?php echo $form_id ?>" class="give-label">
787
				<?php esc_html_e( 'CVC', 'give' ); ?>
788
				<span class="give-required-indicator">*</span>
789
				<span class="give-tooltip give-icon give-icon-question"
790
				      data-tooltip="<?php esc_attr_e( 'The 3 digit (back) or 4 digit (front) value on your card.', 'give' ); ?>"></span>
791
			</label>
792
793
			<input type="tel" size="4" autocomplete="off" name="card_cvc" id="card_cvc-<?php echo $form_id ?>"
794
			       class="card-cvc give-input required" placeholder="<?php esc_attr_e( 'Security code', 'give' ); ?>"
795
			       required aria-required="true"/>
796
		</p>
797
798
		<p id="give-card-name-wrap-<?php echo $form_id ?>" class="form-row form-row-two-thirds">
799
			<label for="card_name-<?php echo $form_id ?>" class="give-label">
800
				<?php esc_html_e( 'Name on the Card', 'give' ); ?>
801
				<span class="give-required-indicator">*</span>
802
				<span class="give-tooltip give-icon give-icon-question"
803
				      data-tooltip="<?php esc_attr_e( 'The name printed on the front of your credit card.', 'give' ); ?>"></span>
804
			</label>
805
806
			<input type="text" autocomplete="off" name="card_name" id="card_name-<?php echo $form_id ?>"
807
			       class="card-name give-input required" placeholder="<?php esc_attr_e( 'Card name', 'give' ); ?>"
808
			       required aria-required="true"/>
809
		</p>
810
		<?php
811
		/**
812
		 * Fires while rendering credit card info form, before expiration fields.
813
		 *
814
		 * @since 1.0
815
		 *
816
		 * @param int $form_id The form ID.
817
		 */
818
		do_action( 'give_before_cc_expiration' );
819
		?>
820
		<p class="card-expiration form-row form-row-one-third">
821
			<label for="card_expiry-<?php echo $form_id ?>" class="give-label">
822
				<?php esc_html_e( 'Expiration', 'give' ); ?>
823
				<span class="give-required-indicator">*</span>
824
				<span class="give-tooltip give-icon give-icon-question"
825
				      data-tooltip="<?php esc_attr_e( 'The date your credit card expires, typically on the front of the card.', 'give' ); ?>"></span>
826
			</label>
827
828
			<input type="hidden" id="card_exp_month-<?php echo $form_id ?>" name="card_exp_month"
829
			       class="card-expiry-month"/>
830
			<input type="hidden" id="card_exp_year-<?php echo $form_id ?>" name="card_exp_year"
831
			       class="card-expiry-year"/>
832
833
			<input type="tel" autocomplete="off" name="card_expiry" id="card_expiry-<?php echo $form_id ?>"
834
			       class="card-expiry give-input required" placeholder="<?php esc_attr_e( 'MM / YY', 'give' ); ?>"
835
			       required aria-required="true"/>
836
		</p>
837
		<?php
838
		/**
839
		 * Fires while rendering credit card info form, after expiration fields.
840
		 *
841
		 * @since 1.0
842
		 *
843
		 * @param int $form_id The form ID.
844
		 */
845
		do_action( 'give_after_cc_expiration', $form_id );
846
		?>
847
	</fieldset>
848
	<?php
849
	/**
850
	 * Fires while rendering credit card info form, before the fields.
851
	 *
852
	 * @since 1.0
853
	 *
854
	 * @param int $form_id The form ID.
855
	 */
856
	do_action( 'give_after_cc_fields', $form_id );
857
858
	echo ob_get_clean();
859
}
860
861
add_action( 'give_cc_form', 'give_get_cc_form' );
862
863
/**
864
 * Outputs the default credit card address fields.
865
 *
866
 * @since  1.0
867
 *
868
 * @param  int $form_id The form ID.
869
 *
870
 * @return void
871
 */
872
function give_default_cc_address_fields( $form_id ) {
873
	// Get user info.
874
	$give_user_info = _give_get_prefill_form_field_values( $form_id );
875
876
	$logged_in = is_user_logged_in();
877
878
	if ( $logged_in ) {
879
		$user_address = get_user_meta( get_current_user_id(), '_give_user_address', true );
880
	}
881
	$line1 = $logged_in && ! empty( $user_address['line1'] ) ? $user_address['line1'] : '';
882
	$line2 = $logged_in && ! empty( $user_address['line2'] ) ? $user_address['line2'] : '';
883
	$city  = $logged_in && ! empty( $user_address['city'] ) ? $user_address['city'] : '';
884
	$zip   = $logged_in && ! empty( $user_address['zip'] ) ? $user_address['zip'] : '';
885
886
	ob_start();
887
	?>
888
	<fieldset id="give_cc_address" class="cc-address">
889
		<legend><?php echo apply_filters( 'give_billing_details_fieldset_heading', esc_html__( 'Billing Details', 'give' ) ); ?></legend>
890
		<?php
891
		/**
892
		 * Fires while rendering credit card billing form, before address fields.
893
		 *
894
		 * @since 1.0
895
		 *
896
		 * @param int $form_id The form ID.
897
		 */
898
		do_action( 'give_cc_billing_top' );
899
		?>
900
		<p id="give-card-address-wrap" class="form-row form-row-two-thirds">
901
			<label for="card_address" class="give-label">
902
				<?php esc_html_e( 'Address 1', 'give' ); ?>
903
				<?php
904
				if ( give_field_is_required( 'card_address', $form_id ) ) : ?>
905
					<span class="give-required-indicator">*</span>
906
				<?php endif; ?>
907
				<span class="give-tooltip give-icon give-icon-question"
908
				      data-tooltip="<?php esc_attr_e( 'The primary billing address for your credit card.', 'give' ); ?>"></span>
909
			</label>
910
911
			<input
912
				type="text"
913
				id="card_address"
914
				name="card_address"
915
				class="card-address give-input<?php echo( give_field_is_required( 'card_address', $form_id ) ? ' required' : '' ); ?>"
916
				placeholder="<?php esc_attr_e( 'Address line 1', 'give' ); ?>"
917
				value="<?php echo isset( $give_user_info['card_address'] ) ? $give_user_info['card_address'] : ''; ?>"
918
				<?php echo( give_field_is_required( 'card_address', $form_id ) ? '  required aria-required="true" ' : '' ); ?>
919
			/>
920
		</p>
921
922
		<p id="give-card-address-2-wrap" class="form-row form-row-one-third">
923
			<label for="card_address_2" class="give-label">
924
				<?php esc_html_e( 'Address 2', 'give' ); ?>
925
				<?php if ( give_field_is_required( 'card_address_2', $form_id ) ) : ?>
926
					<span class="give-required-indicator">*</span>
927
				<?php endif; ?>
928
				<span class="give-tooltip give-icon give-icon-question"
929
				      data-tooltip="<?php esc_attr_e( '(optional) The suite, apt no, PO box, etc, associated with your billing address.', 'give' ); ?>"></span>
930
			</label>
931
932
			<input
933
				type="text"
934
				id="card_address_2"
935
				name="card_address_2"
936
				class="card-address-2 give-input<?php echo( give_field_is_required( 'card_address_2', $form_id ) ? ' required' : '' ); ?>"
937
				placeholder="<?php esc_attr_e( 'Address line 2', 'give' ); ?>"
938
				value="<?php echo isset( $give_user_info['card_address_2'] ) ? $give_user_info['card_address_2'] : ''; ?>"
939
				<?php echo( give_field_is_required( 'card_address_2', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
940
			/>
941
		</p>
942
943
		<p id="give-card-city-wrap" class="form-row form-row-two-thirds">
944
			<label for="card_city" class="give-label">
945
				<?php esc_html_e( 'City', 'give' ); ?>
946
				<?php if ( give_field_is_required( 'card_city', $form_id ) ) : ?>
947
					<span class="give-required-indicator">*</span>
948
				<?php endif; ?>
949
				<span class="give-tooltip give-icon give-icon-question"
950
				      data-tooltip="<?php esc_attr_e( 'The city for your billing address.', 'give' ); ?>"></span>
951
			</label>
952
			<input
953
				type="text"
954
				id="card_city"
955
				name="card_city"
956
				class="card-city give-input<?php echo( give_field_is_required( 'card_city', $form_id ) ? ' required' : '' ); ?>"
957
				placeholder="<?php esc_attr_e( 'City', 'give' ); ?>"
958
				value="<?php echo isset( $give_user_info['card_city'] ) ? $give_user_info['card_city'] : ''; ?>"
959
				<?php echo( give_field_is_required( 'card_city', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
960
			/>
961
		</p>
962
963
		<p id="give-card-zip-wrap" class="form-row form-row-one-third">
964
			<label for="card_zip" class="give-label">
965
				<?php esc_html_e( 'Zip / Postal Code', 'give' ); ?>
966
				<?php if ( give_field_is_required( 'card_zip', $form_id ) ) : ?>
967
					<span class="give-required-indicator">*</span>
968
				<?php endif; ?>
969
				<span class="give-tooltip give-icon give-icon-question"
970
				      data-tooltip="<?php esc_attr_e( 'The zip or postal code for your billing address.', 'give' ); ?>"></span>
971
			</label>
972
973
			<input
974
				type="text"
975
				size="4"
976
				id="card_zip"
977
				name="card_zip"
978
				class="card-zip give-input<?php echo( give_field_is_required( 'card_zip', $form_id ) ? ' required' : '' ); ?>"
979
				placeholder="<?php esc_attr_e( 'Zip / Postal Code', 'give' ); ?>"
980
				value="<?php echo isset( $give_user_info['card_zip'] ) ? $give_user_info['card_zip'] : ''; ?>"
981
				<?php echo( give_field_is_required( 'card_zip', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
982
			/>
983
		</p>
984
985
		<p id="give-card-country-wrap" class="form-row form-row-first">
986
			<label for="billing_country" class="give-label">
987
				<?php esc_html_e( 'Country', 'give' ); ?>
988
				<?php if ( give_field_is_required( 'billing_country', $form_id ) ) : ?>
989
					<span class="give-required-indicator">*</span>
990
				<?php endif; ?>
991
				<span class="give-tooltip give-icon give-icon-question"
992
				      data-tooltip="<?php esc_attr_e( 'The country for your billing address.', 'give' ); ?>"></span>
993
			</label>
994
995
			<select
996
				name="billing_country"
997
				id="billing_country"
998
				class="billing-country billing_country give-select<?php echo( give_field_is_required( 'billing_country', $form_id ) ? ' required' : '' ); ?>"
999
				<?php echo( give_field_is_required( 'billing_country', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
1000
			>
1001
				<?php
1002
1003
				$selected_country = give_get_country();
1004
1005
				if ( ! empty( $give_user_info['billing_country'] ) && '*' !== $give_user_info['billing_country'] ) {
1006
					$selected_country = $give_user_info['billing_country'];
1007
				}
1008
1009
				$countries = give_get_country_list();
1010
				foreach ( $countries as $country_code => $country ) {
1011
					echo '<option value="' . esc_attr( $country_code ) . '"' . selected( $country_code, $selected_country, false ) . '>' . $country . '</option>';
1012
				}
1013
				?>
1014
			</select>
1015
		</p>
1016
1017
		<p id="give-card-state-wrap" class="form-row form-row-last">
1018
			<label for="card_state" class="give-label">
1019
				<?php esc_html_e( 'State / Province', 'give' ); ?>
1020
				<?php if ( give_field_is_required( 'card_state', $form_id ) ) : ?>
1021
					<span class="give-required-indicator">*</span>
1022
				<?php endif; ?>
1023
				<span class="give-tooltip give-icon give-icon-question"
1024
				      data-tooltip="<?php esc_attr_e( 'The state or province for your billing address.', 'give' ); ?>"></span>
1025
			</label>
1026
1027
			<?php
1028
			$selected_state = give_get_state();
1029
			$states         = give_get_states( $selected_country );
1030
1031
			if ( ! empty( $give_user_info['card_state'] ) ) {
1032
				$selected_state = $give_user_info['card_state'];
1033
			}
1034
1035
			if ( ! empty( $states ) ) : ?>
1036
				<select
1037
					name="card_state"
1038
					id="card_state"
1039
					class="card_state give-select<?php echo( give_field_is_required( 'card_state', $form_id ) ? ' required' : '' ); ?>"
1040
					<?php echo( give_field_is_required( 'card_state', $form_id ) ? ' required aria-required="true" ' : '' ); ?>>
1041
					<?php
1042
					foreach ( $states as $state_code => $state ) {
1043
						echo '<option value="' . $state_code . '"' . selected( $state_code, $selected_state, false ) . '>' . $state . '</option>';
1044
					}
1045
					?>
1046
				</select>
1047
			<?php else : ?>
1048
				<input type="text" size="6" name="card_state" id="card_state" class="card_state give-input"
1049
				       placeholder="<?php esc_attr_e( 'State / Province', 'give' ); ?>"/>
1050
			<?php endif; ?>
1051
		</p>
1052
		<?php
1053
		/**
1054
		 * Fires while rendering credit card billing form, after address fields.
1055
		 *
1056
		 * @since 1.0
1057
		 *
1058
		 * @param int $form_id The form ID.
1059
		 */
1060
		do_action( 'give_cc_billing_bottom' );
1061
		?>
1062
	</fieldset>
1063
	<?php
1064
	echo ob_get_clean();
1065
}
1066
1067
add_action( 'give_after_cc_fields', 'give_default_cc_address_fields' );
1068
1069
1070
/**
1071
 * 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.
1072
 *
1073
 * @since  1.0
1074
 *
1075
 * @param  int $form_id The form ID.
1076
 *
1077
 * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
1078
 */
1079
function give_get_register_fields( $form_id ) {
1080
1081
	global $user_ID;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1082
1083
	if ( is_user_logged_in() ) {
1084
		$user_data = get_userdata( $user_ID );
1085
	}
1086
1087
	$show_register_form = give_show_login_register_option( $form_id );
1088
1089
	ob_start(); ?>
1090
	<fieldset id="give-register-fields-<?php echo $form_id; ?>">
1091
1092
		<?php if ( $show_register_form == 'both' ) { ?>
1093
			<div class="give-login-account-wrap">
1094
				<p class="give-login-message"><?php esc_html_e( 'Already have an account?', 'give' ); ?>&nbsp;
1095
					<a href="<?php echo esc_url( add_query_arg( 'login', 1 ) ); ?>" class="give-checkout-login"
1096
					   data-action="give_checkout_login"><?php esc_html_e( 'Login', 'give' ); ?></a>
1097
				</p>
1098
				<p class="give-loading-text">
1099
					<span class="give-loading-animation"></span> <?php esc_html_e( 'Loading...', 'give' ); ?></p>
1100
			</div>
1101
		<?php } ?>
1102
1103
		<?php
1104
		/**
1105
		 * Fires while rendering user registration form, before registration fields.
1106
		 *
1107
		 * @since 1.0
1108
		 *
1109
		 * @param int $form_id The form ID.
1110
		 */
1111
		do_action( 'give_register_fields_before', $form_id );
1112
		?>
1113
1114
		<fieldset id="give-register-account-fields-<?php echo $form_id; ?>">
1115
			<legend>
1116
				<?php
1117
				echo apply_filters( 'give_create_account_fieldset_heading', esc_html__( 'Create an account', 'give' ) );
1118
				if ( ! give_logged_in_only( $form_id ) ) {
1119
					echo ' <span class="sub-text">' . esc_html__( '(optional)', 'give' ) . '</span>';
1120
				}
1121
				?>
1122
			</legend>
1123
			<?php
1124
			/**
1125
			 * Fires while rendering user registration form, before account fields.
1126
			 *
1127
			 * @since 1.0
1128
			 *
1129
			 * @param int $form_id The form ID.
1130
			 */
1131
			do_action( 'give_register_account_fields_before', $form_id );
1132
			?>
1133
			<div id="give-user-login-wrap-<?php echo $form_id; ?>" class="form-row form-row-one-third form-row-first">
1134
				<label for="give-user-login-<?php echo $form_id; ?>">
1135
					<?php esc_html_e( 'Username', 'give' ); ?>
1136
					<?php if ( give_logged_in_only( $form_id ) ) { ?>
1137
						<span class="give-required-indicator">*</span>
1138
					<?php } ?>
1139
					<span class="give-tooltip give-icon give-icon-question"
1140
					      data-tooltip="<?php esc_attr_e( 'The username you will use to log into your account.', 'give' ); ?>"></span>
1141
				</label>
1142
1143
				<input name="give_user_login" id="give-user-login-<?php echo $form_id; ?>" class="give-input"
1144
				       type="text"
1145
				       placeholder="<?php esc_attr_e( 'Username', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/>
1146
			</div>
1147
1148
			<div id="give-user-pass-wrap-<?php echo $form_id; ?>" class="form-row form-row-one-third">
1149
				<label for="give-user-pass-<?php echo $form_id; ?>">
1150
					<?php esc_html_e( 'Password', 'give' ); ?>
1151
					<?php if ( give_logged_in_only( $form_id ) ) { ?>
1152
						<span class="give-required-indicator">*</span>
1153
					<?php } ?>
1154
					<span class="give-tooltip give-icon give-icon-question"
1155
					      data-tooltip="<?php esc_attr_e( 'The password used to access your account.', 'give' ); ?>"></span>
1156
				</label>
1157
1158
				<input name="give_user_pass" id="give-user-pass-<?php echo $form_id; ?>" class="give-input"
1159
				       placeholder="<?php esc_attr_e( 'Password', 'give' ); ?>"
1160
				       type="password"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/>
1161
			</div>
1162
1163
			<div id="give-user-pass-confirm-wrap-<?php echo $form_id; ?>"
1164
			     class="give-register-password form-row form-row-one-third">
1165
				<label for="give-user-pass-confirm-<?php echo $form_id; ?>">
1166
					<?php esc_html_e( 'Confirm PW', 'give' ); ?>
1167
					<?php if ( give_logged_in_only( $form_id ) ) { ?>
1168
						<span class="give-required-indicator">*</span>
1169
					<?php } ?>
1170
					<span class="give-tooltip give-icon give-icon-question"
1171
					      data-tooltip="<?php esc_attr_e( 'Please retype your password to confirm.', 'give' ); ?>"></span>
1172
				</label>
1173
1174
				<input name="give_user_pass_confirm" id="give-user-pass-confirm-<?php echo $form_id; ?>"
1175
				       class="give-input" placeholder="<?php esc_attr_e( 'Confirm password', 'give' ); ?>"
1176
				       type="password"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/>
1177
			</div>
1178
			<?php
1179
			/**
1180
			 * Fires while rendering user registration form, after account fields.
1181
			 *
1182
			 * @since 1.0
1183
			 *
1184
			 * @param int $form_id The form ID.
1185
			 */
1186
			do_action( 'give_register_account_fields_after', $form_id );
1187
			?>
1188
		</fieldset>
1189
1190
		<?php
1191
		/**
1192
		 * Fires while rendering user registration form, after registration fields.
1193
		 *
1194
		 * @since 1.0
1195
		 *
1196
		 * @param int $form_id The form ID.
1197
		 */
1198
		do_action( 'give_register_fields_after', $form_id );
1199
		?>
1200
1201
		<input type="hidden" name="give-purchase-var" value="needs-to-register"/>
1202
1203
		<?php
1204
		/**
1205
		 * Fire after register or login form render
1206
		 *
1207
		 * @since 1.7
1208
		 */
1209
		do_action( 'give_donation_form_user_info', $form_id );
1210
		?>
1211
1212
	</fieldset>
1213
	<?php
1214
	echo ob_get_clean();
1215
}
1216
1217
add_action( 'give_donation_form_register_fields', 'give_get_register_fields' );
1218
1219
/**
1220
 * Gets the login fields for the login form on the checkout. This function hooks
1221
 * on the give_donation_form_login_fields to display the login form if a user already
1222
 * had an account.
1223
 *
1224
 * @since  1.0
1225
 *
1226
 * @param  int $form_id The form ID.
1227
 *
1228
 * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
1229
 */
1230
function give_get_login_fields( $form_id ) {
1231
1232
	$form_id            = isset( $_POST['form_id'] ) ? $_POST['form_id'] : $form_id;
1233
	$show_register_form = give_show_login_register_option( $form_id );
1234
1235
	ob_start();
1236
	?>
1237
	<fieldset id="give-login-fields-<?php echo $form_id; ?>">
1238
		<legend><?php echo apply_filters( 'give_account_login_fieldset_heading', esc_html__( 'Login to Your Account', 'give' ) );
1239
			if ( ! give_logged_in_only( $form_id ) ) {
1240
				echo ' <span class="sub-text">' . esc_html__( '(optional)', 'give' ) . '</span>';
1241
			} ?>
1242
		</legend>
1243
		<?php if ( $show_register_form == 'both' ) { ?>
1244
			<p class="give-new-account-link">
1245
				<?php esc_html_e( 'Need to create an account?', 'give' ); ?>&nbsp;
1246
				<a href="<?php echo remove_query_arg( 'login' ); ?>" class="give-checkout-register-cancel"
1247
				   data-action="give_checkout_register">
1248
					<?php esc_html_e( 'Register', 'give' );
1249
					if ( ! give_logged_in_only( $form_id ) ) {
1250
						echo ' ' . esc_html__( 'or checkout as a guest &raquo;', 'give' );
1251
					} ?>
1252
				</a>
1253
			</p>
1254
			<p class="give-loading-text">
1255
				<span class="give-loading-animation"></span> <?php esc_html_e( 'Loading...', 'give' ); ?> </p>
1256
		<?php } ?>
1257
		<?php
1258
		/**
1259
		 * Fires while rendering checkout login form, before the fields.
1260
		 *
1261
		 * @since 1.0
1262
		 *
1263
		 * @param int $form_id The form ID.
1264
		 */
1265
		do_action( 'give_checkout_login_fields_before', $form_id );
1266
		?>
1267
		<div id="give-user-login-wrap-<?php echo $form_id; ?>" class="form-row form-row-first">
1268
			<label class="give-label" for="give-user-login-<?php echo $form_id; ?>">
1269
				<?php esc_html_e( 'Username', 'give' ); ?>
1270
				<?php if ( give_logged_in_only( $form_id ) ) { ?>
1271
					<span class="give-required-indicator">*</span>
1272
				<?php } ?>
1273
			</label>
1274
1275
			<input class="give-input<?php echo ( give_logged_in_only( $form_id ) ) ? ' required' : ''; ?>" type="text"
1276
			       name="give_user_login" id="give-user-login-<?php echo $form_id; ?>" value=""
1277
			       placeholder="<?php esc_attr_e( 'Your username', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/>
1278
		</div>
1279
1280
		<div id="give-user-pass-wrap-<?php echo $form_id; ?>" class="give_login_password form-row form-row-last">
1281
			<label class="give-label" for="give-user-pass-<?php echo $form_id; ?>">
1282
				<?php esc_html_e( 'Password', 'give' ); ?>
1283
				<?php if ( give_logged_in_only( $form_id ) ) { ?>
1284
					<span class="give-required-indicator">*</span>
1285
				<?php } ?>
1286
			</label>
1287
			<input class="give-input<?php echo ( give_logged_in_only( $form_id ) ) ? ' required' : ''; ?>"
1288
			       type="password" name="give_user_pass" id="give-user-pass-<?php echo $form_id; ?>"
1289
			       placeholder="<?php esc_attr_e( 'Your password', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/>
1290
			<input type="hidden" name="give-purchase-var" value="needs-to-login"/>
1291
		</div>
1292
1293
		<div id="give-forgot-password-wrap-<?php echo $form_id; ?>" class="give_login_forgot_password">
1294
			 <span class="give-forgot-password ">
1295
				 <a href="<?php echo wp_lostpassword_url() ?>"
1296
				    target="_blank"><?php esc_html_e( 'Reset Password', 'give' ) ?></a>
1297
			 </span>
1298
		</div>
1299
1300
		<div id="give-user-login-submit-<?php echo $form_id; ?>" class="give-clearfix">
1301
			<input type="submit" class="give-submit give-btn button" name="give_login_submit"
1302
			       value="<?php esc_attr_e( 'Login', 'give' ); ?>"/>
1303
			<?php if ( $show_register_form !== 'login' ) { ?>
1304
				<input type="button" data-action="give_cancel_login"
1305
				       class="give-cancel-login give-checkout-register-cancel give-btn button" name="give_login_cancel"
1306
				       value="<?php esc_attr_e( 'Cancel', 'give' ); ?>"/>
1307
			<?php } ?>
1308
			<span class="give-loading-animation"></span>
1309
		</div>
1310
		<?php
1311
		/**
1312
		 * Fires while rendering checkout login form, after the fields.
1313
		 *
1314
		 * @since 1.0
1315
		 *
1316
		 * @param int $form_id The form ID.
1317
		 */
1318
		do_action( 'give_checkout_login_fields_after', $form_id );
1319
		?>
1320
	</fieldset><!--end #give-login-fields-->
1321
	<?php
1322
	echo ob_get_clean();
1323
}
1324
1325
add_action( 'give_donation_form_login_fields', 'give_get_login_fields', 10, 1 );
1326
1327
/**
1328
 * Payment Mode Select.
1329
 *
1330
 * Renders the payment mode form by getting all the enabled payment gateways and
1331
 * outputting them as radio buttons for the user to choose the payment gateway. If
1332
 * a default payment gateway has been chosen from the Give Settings, it will be
1333
 * automatically selected.
1334
 *
1335
 * @since  1.0
1336
 *
1337
 * @param  int $form_id The form ID.
1338
 *
1339
 * @return void
1340
 */
1341
function give_payment_mode_select( $form_id ) {
1342
1343
	$gateways = give_get_enabled_payment_gateways( $form_id );
1344
1345
	/**
1346
	 * Fires while selecting payment gateways, before the fields.
1347
	 *
1348
	 * @since 1.7
1349
	 *
1350
	 * @param int $form_id The form ID.
1351
	 */
1352
	do_action( 'give_payment_mode_top', $form_id );
1353
	?>
1354
1355
	<fieldset id="give-payment-mode-select" <?php if ( count( $gateways ) <= 1 ) {
1356
		echo 'style="display: none;"';
1357
	} ?>>
1358
		<?php
1359
		/**
1360
		 * Fires while selecting payment gateways, before the wrap div.
1361
		 *
1362
		 * @since 1.7
1363
		 *
1364
		 * @param int $form_id The form ID.
1365
		 */
1366
		do_action( 'give_payment_mode_before_gateways_wrap' );
1367
		?>
1368
		<legend
1369
			class="give-payment-mode-label"><?php echo apply_filters( 'give_checkout_payment_method_text', esc_html__( 'Select Payment Method', 'give' ) ); ?></legend>
1370
1371
		<div id="give-payment-mode-wrap">
1372
			<span class="give-loading-text"><span
1373
					class="give-loading-animation"></span> <?php esc_html_e( 'Loading...', 'give' ); ?></span>
1374
1375
			<?php
1376
			/**
1377
			 * Fires while selecting payment gateways, befire the gateways list.
1378
			 *
1379
			 * @since 1.7
1380
			 */
1381
			do_action( 'give_payment_mode_before_gateways' )
1382
			?>
1383
			<ul id="give-gateway-radio-list">
1384
				<?php
1385
				/**
1386
				 * Loop through the active payment gateways.
1387
				 */
1388
				$selected_gateway = give_get_chosen_gateway( $form_id );
1389
1390
				foreach ( $gateways as $gateway_id => $gateway ) :
1391
					//Determine the default gateway.
1392
					$checked       = checked( $gateway_id, $selected_gateway, false );
1393
					$checked_class = $checked ? ' class="give-gateway-option-selected"' : ''; ?>
1394
					<li<?php echo $checked_class?>>
1395
						<input type="radio" name="payment-mode" class="give-gateway"
1396
						       id="give-gateway-<?php echo esc_attr( $gateway_id ) . '-' . $form_id; ?>"
1397
						       value="<?php echo esc_attr( $gateway_id ); ?>"<?php echo $checked; ?>>
1398
						<label for="give-gateway-<?php echo esc_attr( $gateway_id ) . '-' . $form_id; ?>"
1399
						       class="give-gateway-option"
1400
						       id="give-gateway-option-<?php echo esc_attr( $gateway_id ); ?>"> <?php echo esc_html( $gateway['checkout_label'] ); ?></label>
1401
					</li>
1402
					<?php
1403
				endforeach;
1404
				?>
1405
			</ul>
1406
			<?php
1407
			/**
1408
			 * Fires while selecting payment gateways, before the gateways list.
1409
			 *
1410
			 * @since 1.7
1411
			 */
1412
			do_action( 'give_payment_mode_after_gateways' );
1413
			?>
1414
		</div>
1415
		<?php
1416
		/**
1417
		 * Fires while selecting payment gateways, after the wrap div.
1418
		 *
1419
		 * @since 1.7
1420
		 *
1421
		 * @param int $form_id The form ID.
1422
		 */
1423
		do_action( 'give_payment_mode_after_gateways_wrap' );
1424
		?>
1425
	</fieldset>
1426
1427
	<?php
1428
	/**
1429
	 * Fires while selecting payment gateways, after the fields.
1430
	 *
1431
	 * @since 1.7
1432
	 *
1433
	 * @param int $form_id The form ID.
1434
	 */
1435
	do_action( 'give_payment_mode_bottom', $form_id );
1436
	?>
1437
1438
	<div id="give_purchase_form_wrap">
1439
1440
		<?php
1441
		/**
1442
		 * Fire after payment field render.
1443
		 *
1444
		 * @since 1.7
1445
		 */
1446
		do_action( 'give_donation_form', $form_id );
1447
		?>
1448
1449
	</div>
1450
1451
	<?php
1452
	/**
1453
	 * Fire after donation form render.
1454
	 *
1455
	 * @since 1.7
1456
	 */
1457
	do_action( 'give_donation_form_wrap_bottom', $form_id );
1458
}
1459
1460
add_action( 'give_payment_mode_select', 'give_payment_mode_select' );
1461
1462
/**
1463
 * Renders the Checkout Agree to Terms, this displays a checkbox for users to
1464
 * agree the T&Cs set in the Give Settings. This is only displayed if T&Cs are
1465
 * set in the Give Settings.
1466
 *
1467
 * @since  1.0
1468
 *
1469
 * @param  int $form_id The form ID.
1470
 *
1471
 * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be false|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
1472
 */
1473
function give_terms_agreement( $form_id ) {
1474
	$form_option = get_post_meta( $form_id, '_give_terms_option', true );
1475
1476
	// Bailout if per form and global term and conditions is not setup.
1477
	if (
1478
		give_is_setting_enabled( $form_option, 'global' )
1479
		&& give_is_setting_enabled( give_get_option( 'terms' ) )
1480
	) {
1481
		$label         = give_get_option( 'agree_to_terms_label', esc_html__( 'Agree to Terms?', 'give' ) );
1482
		$terms         = $terms = give_get_option( 'agreement_text', '' );
1483
		$edit_term_url = admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=display&section=term-and-conditions' );
1484
1485
	} elseif ( give_is_setting_enabled( $form_option ) ) {
1486
		$label         = ( $label = get_post_meta( $form_id, '_give_agree_label', true ) ) ? stripslashes( $label ) : esc_html__( 'Agree to Terms?', 'give' );
1487
		$terms         = get_post_meta( $form_id, '_give_agree_text', true );
1488
		$edit_term_url = admin_url( 'post.php?post=' . $form_id . '&action=edit#form_terms_options' );
1489
1490
	} else {
1491
		return false;
1492
	}
1493
1494
	// Bailout: Check if term and conditions text is empty or not.
1495
	if ( empty( $terms ) ) {
1496
		if ( is_user_logged_in() && current_user_can( 'edit_give_forms' ) ) {
1497
			echo sprintf( __( 'Please enter valid terms and conditions in <a href="%s">this form\'s settings</a>.', 'give' ), $edit_term_url );
1498
		}
1499
1500
		return false;
1501
	}
1502
1503
	?>
1504
	<fieldset id="give_terms_agreement">
1505
		<legend><?php echo apply_filters( 'give_terms_agreement_text', esc_html__( 'Terms', 'give' ) ); ?></legend>
1506
		<div id="give_terms" class="give_terms-<?php echo $form_id; ?>" style="display:none;">
1507
			<?php
1508
			/**
1509
			 * Fires while rendering terms of agreement, before the fields.
1510
			 *
1511
			 * @since 1.0
1512
			 */
1513
			do_action( 'give_before_terms' );
1514
1515
			echo wpautop( stripslashes( $terms ) );
1516
			/**
1517
			 * Fires while rendering terms of agreement, after the fields.
1518
			 *
1519
			 * @since 1.0
1520
			 */
1521
			do_action( 'give_after_terms' );
1522
			?>
1523
		</div>
1524
		<div id="give_show_terms">
1525
			<a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button"
1526
			   aria-controls="give_terms"><?php esc_html_e( 'Show Terms', 'give' ); ?></a>
1527
			<a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button"
1528
			   aria-controls="give_terms" style="display:none;"><?php esc_html_e( 'Hide Terms', 'give' ); ?></a>
1529
		</div>
1530
1531
		<input name="give_agree_to_terms" class="required" type="checkbox" id="give_agree_to_terms-<?php echo $form_id; ?>" value="1" required aria-required="true" />
1532
		<label for="give_agree_to_terms-<?php echo $form_id; ?>"><?php echo $label; ?></label>
1533
1534
	</fieldset>
1535
	<?php
1536
}
1537
1538
add_action( 'give_donation_form_after_cc_form', 'give_terms_agreement', 8888, 1 );
1539
1540
/**
1541
 * Checkout Final Total.
1542
 *
1543
 * Shows the final donation total at the bottom of the checkout page.
1544
 *
1545
 * @since  1.0
1546
 *
1547
 * @param  int $form_id The form ID.
1548
 *
1549
 * @return void
1550
 */
1551
function give_checkout_final_total( $form_id ) {
1552
1553
	if ( isset( $_POST['give_total'] ) ) {
1554
		$total = apply_filters( 'give_donation_total', $_POST['give_total'] );
1555
	} else {
1556
		//default total.
1557
		$total = give_get_default_form_amount( $form_id );
1558
	}
1559
	//Only proceed if give_total available.
1560
	if ( empty( $total ) ) {
1561
		return;
1562
	}
1563
	?>
1564
	<p id="give-final-total-wrap" class="form-wrap ">
1565
		<span
1566
			class="give-donation-total-label"><?php echo apply_filters( 'give_donation_total_label', esc_html__( 'Donation Total:', 'give' ) ); ?></span>
1567
		<span class="give-final-total-amount"
1568
		      data-total="<?php echo give_format_amount( $total ); ?>"><?php echo give_currency_filter( give_format_amount( $total ) ); ?></span>
1569
	</p>
1570
	<?php
1571
}
1572
1573
add_action( 'give_donation_form_before_submit', 'give_checkout_final_total', 999 );
1574
1575
/**
1576
 * Renders the Checkout Submit section.
1577
 *
1578
 * @since  1.0
1579
 *
1580
 * @param  int $form_id The form ID.
1581
 *
1582
 * @return void
1583
 */
1584
function give_checkout_submit( $form_id ) {
1585
	?>
1586
	<fieldset id="give_purchase_submit">
1587
		<?php
1588
		/**
1589
		 * Fire before donation form submit.
1590
		 *
1591
		 * @since 1.7
1592
		 */
1593
		do_action( 'give_donation_form_before_submit', $form_id );
1594
1595
		give_checkout_hidden_fields( $form_id );
1596
1597
		echo give_checkout_button_purchase( $form_id );
1598
1599
		/**
1600
		 * Fire after donation form submit.
1601
		 *
1602
		 * @since 1.7
1603
		 */
1604
		do_action( 'give_donation_form_after_submit', $form_id );
1605
		?>
1606
	</fieldset>
1607
	<?php
1608
}
1609
1610
add_action( 'give_donation_form_after_cc_form', 'give_checkout_submit', 9999 );
1611
1612
/**
1613
 * Give Checkout Button.
1614
 *
1615
 * Renders the button on the Checkout.
1616
 *
1617
 * @since  1.0
1618
 *
1619
 * @param  int $form_id The form ID.
1620
 *
1621
 * @return string
1622
 */
1623
function give_checkout_button_purchase( $form_id ) {
1624
1625
	$display_label_field = get_post_meta( $form_id, '_give_checkout_label', true );
1626
	$display_label       = ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) );
1627
	ob_start(); ?>
1628
	<div class="give-submit-button-wrap give-clearfix">
1629
		<input type="submit" class="give-submit give-btn" id="give-purchase-button" name="give-purchase"
1630
		       value="<?php echo $display_label; ?>"/>
1631
		<span class="give-loading-animation"></span>
1632
	</div>
1633
	<?php
1634
	return apply_filters( 'give_checkout_button_purchase', ob_get_clean(), $form_id );
1635
}
1636
1637
/**
1638
 * Give Agree to Terms.
1639
 *
1640
 * Outputs the JavaScript code for the Agree to Terms section to toggle the T&Cs text.
1641
 *
1642
 * @since  1.0
1643
 *
1644
 * @param  int $form_id The form ID.
1645
 *
1646
 * @return void
1647
 */
1648
function give_agree_to_terms_js( $form_id ) {
1649
1650
	$form_option = get_post_meta( $form_id, '_give_terms_option', true );
1651
1652
	if ( give_is_setting_enabled( $form_option, array( 'enabled', 'global' ) ) ) {
1653
		?>
1654
		<script type="text/javascript">
1655
			jQuery(document).ready(function ($) {
1656
				$('body').on('click', '.give_terms_links-<?php echo $form_id;?>', function (e) {
1657
					e.preventDefault();
1658
					$('.give_terms-<?php echo $form_id;?>').slideToggle();
1659
					$('.give_terms_links-<?php echo $form_id;?>').toggle();
1660
					return false;
1661
				});
1662
			});
1663
		</script>
1664
		<?php
1665
	}
1666
}
1667
1668
add_action( 'give_checkout_form_top', 'give_agree_to_terms_js', 10, 2 );
1669
1670
/**
1671
 * Show Give Goals.
1672
 *
1673
 * @since  1.0
1674
 * @since  1.6   Add template for Give Goals Shortcode.
1675
 *               More info is on https://github.com/WordImpress/Give/issues/411
1676
 *
1677
 * @param  int   $form_id The form ID.
1678
 * @param  array $args    An array of form arguments.
1679
 *
1680
 * @return mixed
1681
 */
1682
function give_show_goal_progress( $form_id, $args ) {
1683
1684
	ob_start();
1685
	give_get_template( 'shortcode-goal', array( 'form_id' => $form_id, 'args' => $args ) );
1686
1687
	echo apply_filters( 'give_goal_output', ob_get_clean() );
1688
1689
	return true;
1690
}
1691
1692
add_action( 'give_pre_form', 'give_show_goal_progress', 10, 2 );
1693
1694
1695
/**
1696
 * Get form content position.
1697
 *
1698
 * @since  1.8
1699
 * @param  $form_id
1700
 * @param  $args
1701
 * @return mixed|string
1702
 */
1703
function give_get_form_content_placement( $form_id, $args ) {
1704
	$show_content = '';
1705
1706
	if ( isset( $args['show_content'] ) && ! empty( $args['show_content'] ) ) {
1707
		// Content positions.
1708
		$content_placement = array(
1709
			'above' => 'give_pre_form',
1710
			'below' => 'give_post_form',
1711
		);
1712
1713
		// Check if content position already decoded.
1714
		if ( in_array( $args['show_content'], $content_placement ) ) {
1715
			return $args['show_content'];
1716
		}
1717
1718
		$show_content = ( 'none' !== $args['show_content'] ? $content_placement[ $args['show_content'] ] : '' );
1719
	} elseif ( give_is_setting_enabled( get_post_meta( $form_id, '_give_display_content', true ) ) ) {
1720
		$show_content = get_post_meta( $form_id, '_give_content_placement', true );
1721
	}
1722
1723
	return $show_content;
1724
}
1725
1726
/**
1727
 * Adds Actions to Render Form Content.
1728
 *
1729
 * @since  1.0
1730
 *
1731
 * @param  int   $form_id The form ID.
1732
 * @param  array $args    An array of form arguments.
1733
 *
1734
 * @return void|bool
1735
 */
1736
function give_form_content( $form_id, $args ) {
1737
1738
	$show_content = give_get_form_content_placement( $form_id, $args );
1739
1740
	// Bailout.
1741
	if( empty( $show_content ) ) {
1742
		return false;
1743
	}
1744
1745
	// Add action according to value.
1746
	add_action( $show_content, 'give_form_display_content', 10, 2 );
1747
}
1748
1749
add_action( 'give_pre_form_output', 'give_form_content', 10, 2 );
1750
1751
/**
1752
 * Renders Post Form Content.
1753
 *
1754
 * Displays content for Give forms; fired by action from give_form_content.
1755
 *
1756
 * @since  1.0
1757
 *
1758
 * @param  int   $form_id The form ID.
1759
 * @param  array $args    An array of form arguments.
1760
 *
1761
 * @return void
1762
 */
1763
function give_form_display_content( $form_id, $args ) {
1764
1765
	$content      = wpautop( get_post_meta( $form_id, '_give_form_content', true ) );
1766
	$show_content = give_get_form_content_placement( $form_id, $args );
1767
1768
	if ( give_is_setting_enabled( give_get_option( 'the_content_filter' ) ) ) {
1769
		$content = apply_filters( 'the_content', $content );
1770
	}
1771
1772
	$output = '<div id="give-form-content-' . $form_id . '" class="give-form-content-wrap ' . $show_content . '-content">' . $content . '</div>';
1773
1774
	echo apply_filters( 'give_form_content_output', $output );
1775
1776
	//remove action to prevent content output on addition forms on page.
1777
	//@see: https://github.com/WordImpress/Give/issues/634.
1778
	remove_action( $show_content, 'give_form_display_content' );
1779
}
1780
1781
/**
1782
 * Renders the hidden Checkout fields.
1783
 *
1784
 * @since 1.0
1785
 *
1786
 * @param  int $form_id The form ID.
1787
 *
1788
 * @return void
1789
 */
1790
function give_checkout_hidden_fields( $form_id ) {
1791
1792
	/**
1793
	 * Fires while rendering hidden checkout fields, before the fields.
1794
	 *
1795
	 * @since 1.0
1796
	 *
1797
	 * @param int $form_id The form ID.
1798
	 */
1799
	do_action( 'give_hidden_fields_before', $form_id );
1800
1801
	if ( is_user_logged_in() ) { ?>
1802
		<input type="hidden" name="give-user-id" value="<?php echo get_current_user_id(); ?>"/>
1803
	<?php } ?>
1804
	<input type="hidden" name="give_action" value="purchase"/>
1805
	<input type="hidden" name="give-gateway" value="<?php echo give_get_chosen_gateway( $form_id ); ?>"/>
1806
	<?php
1807
	/**
1808
	 * Fires while rendering hidden checkout fields, after the fields.
1809
	 *
1810
	 * @since 1.0
1811
	 *
1812
	 * @param int $form_id The form ID.
1813
	 */
1814
	do_action( 'give_hidden_fields_after', $form_id );
1815
1816
}
1817
1818
/**
1819
 * Filter Success Page Content.
1820
 *
1821
 * Applies filters to the success page content.
1822
 *
1823
 * @since 1.0
1824
 *
1825
 * @param  string $content Content before filters.
1826
 *
1827
 * @return string $content Filtered content.
1828
 */
1829
function give_filter_success_page_content( $content ) {
1830
1831
	$give_options = give_get_settings();
1832
1833
	if ( isset( $give_options['success_page'] ) && isset( $_GET['payment-confirmation'] ) && is_page( $give_options['success_page'] ) ) {
1834
		if ( has_filter( 'give_payment_confirm_' . $_GET['payment-confirmation'] ) ) {
1835
			$content = apply_filters( 'give_payment_confirm_' . $_GET['payment-confirmation'], $content );
1836
		}
1837
	}
1838
1839
	return $content;
1840
}
1841
1842
add_filter( 'the_content', 'give_filter_success_page_content' );
1843
1844
/**
1845
 * Test Mode Frontend Warning.
1846
 *
1847
 * Displays a notice on the frontend for donation forms.
1848
 *
1849
 * @since 1.1
1850
 */
1851
function give_test_mode_frontend_warning() {
1852
1853
	if ( give_is_test_mode() ) {
1854
		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>';
1855
	}
1856
}
1857
1858
add_action( 'give_pre_form', 'give_test_mode_frontend_warning', 10 );
1859
1860
/**
1861
 * Members-only Form.
1862
 *
1863
 * If "Disable Guest Donations" and "Display Register / Login" is set to none.
1864
 *
1865
 * @since  1.4.1
1866
 *
1867
 * @param  string $final_output
1868
 * @param  array  $args
1869
 *
1870
 * @return string
1871
 */
1872
function give_members_only_form( $final_output, $args ) {
1873
1874
	$form_id = isset( $args['form_id'] ) ? $args['form_id'] : 0;
1875
1876
	//Sanity Check: Must have form_id & not be logged in.
1877
	if ( empty( $form_id ) || is_user_logged_in() ) {
1878
		return $final_output;
1879
	}
1880
1881
	//Logged in only and Register / Login set to none.
1882
	if ( give_logged_in_only( $form_id ) && give_show_login_register_option( $form_id ) == 'none' ) {
1883
1884
		$final_output = give_output_error( esc_html__( 'Please log in in order to complete your donation.', 'give' ), false );
1885
1886
		return apply_filters( 'give_members_only_output', $final_output, $form_id );
1887
1888
	}
1889
1890
	return $final_output;
1891
1892
}
1893
1894
add_filter( 'give_donate_form', 'give_members_only_form', 10, 2 );
1895