Completed
Push — issues/1408 ( 65fa1b...2687ff )
by Ravinder
19:17
created

template.php ➔ give_get_form_content_placement()   C

Complexity

Conditions 7
Paths 6

Size

Total Lines 27
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 14
nc 6
nop 2
dl 0
loc 27
rs 6.7272
c 0
b 0
f 0
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
				( isset( $args['show_title'] ) && $args['show_title'] == true )
104
				&& ! doing_action( 'give_single_form_summary' )
105
			) {
106
				echo $form_title;
107
			}
108
109
			/**
110
			 * Fires while outputing donation form, before the form.
111
			 *
112
			 * @since 1.0
113
			 *
114
			 * @param int   $form_id The form ID.
115
			 * @param array $args    An array of form arguments.
116
			 */
117
			do_action( 'give_pre_form', $form->ID, $args );
118
			?>
119
120
			<form id="give-form-<?php echo $form_id; ?>" class="<?php echo $form_classes; ?>"
121
			      action="<?php echo esc_url_raw( $form_action ); ?>" method="post">
122
				<input type="hidden" name="give-form-id" value="<?php echo $form->ID; ?>"/>
123
				<input type="hidden" name="give-form-title" value="<?php echo htmlentities( $form->post_title ); ?>"/>
124
				<input type="hidden" name="give-current-url"
125
				       value="<?php echo htmlspecialchars( give_get_current_page_url() ); ?>"/>
126
				<input type="hidden" name="give-form-url"
127
				       value="<?php echo htmlspecialchars( give_get_current_page_url() ); ?>"/>
128
				<input type="hidden" name="give-form-minimum"
129
				       value="<?php echo give_format_amount( give_get_form_minimum_price( $form->ID ) ); ?>"/>
130
131
				<!-- The following field is for robots only, invisible to humans: -->
132
				<span class="give-hidden" style="display: none !important;">
133
					<label for="give-form-honeypot-<?php echo $form_id; ?>"></label>
134
					<input id="give-form-honeypot-<?php echo $form_id; ?>" type="text" name="give-honeypot"
135
					       class="give-honeypot give-hidden"/>
136
				</span>
137
138
				<?php
139
140
				//Price ID hidden field for variable (mult-level) donation forms.
141
				if ( give_has_variable_prices( $form_id ) ) {
142
					//get default selected price ID.
143
					$prices   = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $form_id ), $form_id );
144
					$price_id = 0;
145
					//loop through prices.
146
					foreach ( $prices as $price ) {
147
						if ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) {
148
							$price_id = $price['_give_id']['level_id'];
149
						};
150
					}
151
					?>
152
					<input type="hidden" name="give-price-id" value="<?php echo $price_id; ?>"/>
153
				<?php }
154
155
				/**
156
				 * Fires while outputing donation form, before all other fields.
157
				 *
158
				 * @since 1.0
159
				 *
160
				 * @param int   $form_id The form ID.
161
				 * @param array $args    An array of form arguments.
162
				 */
163
				do_action( 'give_checkout_form_top', $form->ID, $args );
164
165
				/**
166
				 * Fires while outputing donation form, for payment gatways fields.
167
				 *
168
				 * @since 1.7
169
				 *
170
				 * @param int   $form_id The form ID.
171
				 * @param array $args    An array of form arguments.
172
				 */
173
				do_action( 'give_payment_mode_select', $form->ID, $args );
174
175
				/**
176
				 * Fires while outputing donation form, after all other fields.
177
				 *
178
				 * @since 1.0
179
				 *
180
				 * @param int   $form_id The form ID.
181
				 * @param array $args    An array of form arguments.
182
				 */
183
				do_action( 'give_checkout_form_bottom', $form->ID, $args );
184
185
				?>
186
			</form>
187
188
			<?php
189
			/**
190
			 * Fires while outputing donation form, after the form.
191
			 *
192
			 * @since 1.0
193
			 *
194
			 * @param int   $form_id The form ID.
195
			 * @param array $args    An array of form arguments.
196
			 */
197
			do_action( 'give_post_form', $form->ID, $args );
198
199
		}
200
		?>
201
202
	</div><!--end #give-form-<?php echo absint( $form->ID ); ?>-->
203
	<?php
204
205
	/**
206
	 * Fires while outputing donation form, after the form wapper div.
207
	 *
208
	 * @since 1.0
209
	 *
210
	 * @param int   $form_id The form ID.
211
	 * @param array $args    An array of form arguments.
212
	 */
213
	do_action( 'give_post_form_output', $form->ID, $args );
214
215
	$final_output = ob_get_clean();
216
217
	echo apply_filters( 'give_donate_form', $final_output, $args );
218
}
219
220
/**
221
 * Give Show Donation Form.
222
 *
223
 * Renders the Donation Form, hooks are provided to add to the checkout form.
224
 * The default Donation Form rendered displays a list of the enabled payment
225
 * gateways, a user registration form (if enable) and a credit card info form
226
 * if credit cards are enabled.
227
 *
228
 * @since  1.0
229
 *
230
 * @param  int $form_id The form ID.
231
 *
232
 * @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...
233
 */
234
function give_show_purchase_form( $form_id ) {
235
236
	$payment_mode = give_get_chosen_gateway( $form_id );
237
238
	if ( ! isset( $form_id ) && isset( $_POST['give_form_id'] ) ) {
239
		$form_id = $_POST['give_form_id'];
240
	}
241
242
	/**
243
	 * Fire before donation form render.
244
	 *
245
	 * @since 1.7
246
	 */
247
	do_action( 'give_donation_form_top', $form_id );
248
249
	if ( give_can_checkout() && isset( $form_id ) ) {
250
251
		/**
252
		 * Fires while displaying donation form, before registration login.
253
		 *
254
		 * @since 1.7
255
		 */
256
		do_action( 'give_donation_form_before_register_login', $form_id );
257
258
		/**
259
		 * Fire when register/login form fields render.
260
		 *
261
		 * @since 1.7
262
		 */
263
		do_action( 'give_donation_form_register_login_fields', $form_id );
264
265
		/**
266
		 * Fire when credit card form fields render.
267
		 *
268
		 * @since 1.7
269
		 */
270
		do_action( 'give_donation_form_before_cc_form', $form_id );
271
272
		// Load the credit card form and allow gateways to load their own if they wish.
273
		if ( has_action( 'give_' . $payment_mode . '_cc_form' ) ) {
274
			/**
275
			 * Fires while displaying donation form, credit card form fields for a given gateway.
276
			 *
277
			 * @since 1.0
278
			 *
279
			 * @param int $form_id The form ID.
280
			 */
281
			do_action( "give_{$payment_mode}_cc_form", $form_id );
282
		} else {
283
			/**
284
			 * Fires while displaying donation form, credit card form fields.
285
			 *
286
			 * @since 1.0
287
			 *
288
			 * @param int $form_id The form ID.
289
			 */
290
			do_action( 'give_cc_form', $form_id );
291
		}
292
293
		/**
294
		 * Fire after credit card form fields render.
295
		 *
296
		 * @since 1.7
297
		 */
298
		do_action( 'give_donation_form_after_cc_form', $form_id );
299
300
	} else {
301
		/**
302
		 * Fire if user can not donate.
303
		 *
304
		 * @since 1.7
305
		 */
306
		do_action( 'give_donation_form_no_access', $form_id );
307
308
	}
309
310
	/**
311
	 * Fire after donation form rendered.
312
	 *
313
	 * @since 1.7
314
	 */
315
	do_action( 'give_donation_form_bottom', $form_id );
316
}
317
318
add_action( 'give_donation_form', 'give_show_purchase_form' );
319
320
/**
321
 * Give Show Login/Register Form Fields.
322
 *
323
 * @since  1.4.1
324
 *
325
 * @param  int $form_id The form ID.
326
 *
327
 * @return void
328
 */
329
function give_show_register_login_fields( $form_id ) {
330
331
	$show_register_form = give_show_login_register_option( $form_id );
332
333
	if ( ( $show_register_form === 'registration' || ( $show_register_form === 'both' && ! isset( $_GET['login'] ) ) ) && ! is_user_logged_in() ) :
334
		?>
335
		<div id="give-checkout-login-register-<?php echo $form_id; ?>">
336
			<?php
337
			/**
338
			 * Fire if user registration form render.
339
			 *
340
			 * @since 1.7
341
			 */
342
			do_action( 'give_donation_form_register_fields', $form_id );
343
			?>
344
		</div>
345
		<?php
346
	elseif ( ( $show_register_form === 'login' || ( $show_register_form === 'both' && isset( $_GET['login'] ) ) ) && ! is_user_logged_in() ) :
347
		?>
348
		<div id="give-checkout-login-register-<?php echo $form_id; ?>">
349
			<?php
350
			/**
351
			 * Fire if user login form render.
352
			 *
353
			 * @since 1.7
354
			 */
355
			do_action( 'give_donation_form_login_fields', $form_id );
356
			?>
357
		</div>
358
		<?php
359
	endif;
360
361
	if ( ( ! isset( $_GET['login'] ) && is_user_logged_in() ) || ! isset( $show_register_form ) || 'none' === $show_register_form || 'login' === $show_register_form ) {
362
		/**
363
		 * Fire when user info render.
364
		 *
365
		 * @since 1.7
366
		 */
367
		do_action( 'give_donation_form_after_user_info', $form_id );
368
	}
369
}
370
371
add_action( 'give_donation_form_register_login_fields', 'give_show_register_login_fields' );
372
373
/**
374
 * Donation Amount Field.
375
 *
376
 * 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.
377
 *
378
 * @since  1.0
379
 *
380
 * @param  int   $form_id The form ID.
381
 * @param  array $args    An array of form arguments.
382
 *
383
 * @return void
384
 */
385
function give_output_donation_amount_top( $form_id = 0, $args = array() ) {
386
387
	$give_options        = give_get_settings();
388
	$variable_pricing    = give_has_variable_prices( $form_id );
389
	$allow_custom_amount = get_post_meta( $form_id, '_give_custom_amount', true );
390
	$currency_position   = isset( $give_options['currency_position'] ) ? $give_options['currency_position'] : 'before';
391
	$symbol              = give_currency_symbol( give_get_currency() );
392
	$currency_output     = '<span class="give-currency-symbol give-currency-position-' . $currency_position . '">' . $symbol . '</span>';
393
	$default_amount      = give_format_amount( give_get_default_form_amount( $form_id ) );
394
	$custom_amount_text  = get_post_meta( $form_id, '_give_custom_amount_text', true );
395
396
	/**
397
	 * Fires while displaying donation form, before donation level fields.
398
	 *
399
	 * @since 1.0
400
	 *
401
	 * @param int   $form_id The form ID.
402
	 * @param array $args    An array of form arguments.
403
	 */
404
	do_action( 'give_before_donation_levels', $form_id, $args );
405
406
	//Set Price, No Custom Amount Allowed means hidden price field
407
	if ( ! give_is_setting_enabled( $allow_custom_amount ) ) {
408
		?>
409
		<label class="give-hidden" for="give-amount-hidden"><?php esc_html_e( 'Donation Amount:', 'give' ); ?></label>
410
		<input id="give-amount" class="give-amount-hidden" type="hidden" name="give-amount"
411
		       value="<?php echo $default_amount; ?>" required aria-required="true"/>
412
		<div class="set-price give-donation-amount form-row-wide">
413
			<?php if ( $currency_position == 'before' ) {
414
				echo $currency_output;
415
			} ?>
416
			<span id="give-amount-text" class="give-text-input give-amount-top"><?php echo $default_amount; ?></span>
417
			<?php if ( $currency_position == 'after' ) {
418
				echo $currency_output;
419
			} ?>
420
		</div>
421
		<?php
422
	} else {
423
		//Custom Amount Allowed.
424
		?>
425
		<div class="give-total-wrap">
426
			<div class="give-donation-amount form-row-wide">
427
				<?php if ( $currency_position == 'before' ) {
428
					echo $currency_output;
429
				} ?>
430
				<label class="give-hidden" for="give-amount"><?php esc_html_e( 'Donation Amount:', 'give' ); ?></label>
431
				<input class="give-text-input give-amount-top" id="give-amount" name="give-amount" type="tel"
432
				       placeholder="" value="<?php echo $default_amount; ?>" autocomplete="off">
433
				<?php if ( $currency_position == 'after' ) {
434
					echo $currency_output;
435
				} ?>
436
			</div>
437
		</div>
438
	<?php }
439
440
	/**
441
	 * Fires while displaying donation form, after donation amounf field(s).
442
	 *
443
	 * @since 1.0
444
	 *
445
	 * @param int   $form_id The form ID.
446
	 * @param array $args    An array of form arguments.
447
	 */
448
	do_action( 'give_after_donation_amount', $form_id, $args );
449
450
	//Custom Amount Text
451
	if ( ! $variable_pricing &&  give_is_setting_enabled( $allow_custom_amount ) && ! empty( $custom_amount_text ) ) { ?>
452
		<p class="give-custom-amount-text"><?php echo $custom_amount_text; ?></p>
453
	<?php }
454
455
	//Output Variable Pricing Levels.
456
	if ( $variable_pricing ) {
457
		give_output_levels( $form_id );
458
	}
459
460
	/**
461
	 * Fires while displaying donation form, after donation level fields.
462
	 *
463
	 * @since 1.0
464
	 *
465
	 * @param int   $form_id The form ID.
466
	 * @param array $args    An array of form arguments.
467
	 */
468
	do_action( 'give_after_donation_levels', $form_id, $args );
469
}
470
471
add_action( 'give_checkout_form_top', 'give_output_donation_amount_top', 10, 2 );
472
473
/**
474
 * Outputs the Donation Levels in various formats such as dropdown, radios, and buttons.
475
 *
476
 * @since  1.0
477
 *
478
 * @param  int $form_id The form ID.
479
 *
480
 * @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...
481
 */
482
function give_output_levels( $form_id ) {
483
484
	//Get variable pricing.
485
	$prices             = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $form_id ), $form_id );
486
	$display_style      = get_post_meta( $form_id, '_give_display_style', true );
487
	$custom_amount      = get_post_meta( $form_id, '_give_custom_amount', true );
488
	$custom_amount_text = get_post_meta( $form_id, '_give_custom_amount_text', true );
489
	if ( empty( $custom_amount_text ) ) {
490
		$custom_amount_text = esc_html__( 'Give a Custom Amount', 'give' );
491
	}
492
493
	$output  = '';
494
	$counter = 0;
495
496
	switch ( $display_style ) {
497
		case 'buttons':
498
499
			$output .= '<ul id="give-donation-level-button-wrap" class="give-donation-levels-wrap give-list-inline">';
500
501
			foreach ( $prices as $price ) {
502
				$counter ++;
503
				$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 );
504
				$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 );
505
506
				$output .= '<li>';
507
				$output .= '<button type="button" data-price-id="' . $price['_give_id']['level_id'] . '" class=" ' . $level_classes . '" value="' . give_format_amount( $price['_give_amount'] ) . '">';
508
				$output .= $level_text;
509
				$output .= '</button>';
510
				$output .= '</li>';
511
512
			}
513
514
			//Custom Amount.
515
			if ( give_is_setting_enabled( $custom_amount ) && ! empty( $custom_amount_text ) ) {
516
				$output .= '<li>';
517
				$output .= '<button type="button" data-price-id="custom" class="give-donation-level-btn give-btn give-btn-level-custom" value="custom">';
518
				$output .= $custom_amount_text;
519
				$output .= '</button>';
520
				$output .= '</li>';
521
			}
522
523
			$output .= '</ul>';
524
525
			break;
526
527
		case 'radios':
528
529
			$output .= '<ul id="give-donation-level-radio-list" class="give-donation-levels-wrap">';
530
531
			foreach ( $prices as $price ) {
532
				$counter ++;
533
				$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 );
534
				$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 );
535
536
				$output .= '<li>';
537
				$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'] ) . '">';
538
				$output .= '<label for="give-radio-level-' . $counter . '">' . $level_text . '</label>';
539
				$output .= '</li>';
540
541
			}
542
543
			//Custom Amount.
544
			if ( give_is_setting_enabled( $custom_amount ) && ! empty( $custom_amount_text ) ) {
545
				$output .= '<li>';
546
				$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">';
547
				$output .= '<label for="give-radio-level-custom">' . $custom_amount_text . '</label>';
548
				$output .= '</li>';
549
			}
550
551
			$output .= '</ul>';
552
553
			break;
554
555
		case 'dropdown':
556
557
			$output .= '<label for="give-donation-level" class="give-hidden">' . esc_html__( 'Choose Your Donation Amount', 'give' ) . ':</label>';
558
			$output .= '<select id="give-donation-level-' . $form_id . '" class="give-select give-select-level give-donation-levels-wrap">';
559
560
			//first loop through prices.
561
			foreach ( $prices as $price ) {
562
				$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 );
563
				$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 );
564
565
				$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'] ) . '">';
566
				$output .= $level_text;
567
				$output .= '</option>';
568
569
			}
570
571
			//Custom Amount.
572
			if ( give_is_setting_enabled( $custom_amount ) && ! empty( $custom_amount_text ) ) {
573
				$output .= '<option data-price-id="custom" class="give-donation-level-custom" value="custom">' . $custom_amount_text . '</option>';
574
			}
575
576
			$output .= '</select>';
577
578
			break;
579
	}
580
581
	echo apply_filters( 'give_form_level_output', $output, $form_id );
582
}
583
584
/**
585
 * Display Reveal & Lightbox Button.
586
 *
587
 * Outputs a button to reveal form fields.
588
 *
589
 * @since  1.0
590
 *
591
 * @param  int   $form_id The form ID.
592
 * @param  array $args    An array of form arguments.
593
 *
594
 * @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...
595
 */
596
function give_display_checkout_button( $form_id, $args ) {
597
598
	$display_option = ( isset( $args['display_style'] ) && ! empty( $args['display_style'] ) )
599
		? $args['display_style']
600
		: get_post_meta( $form_id, '_give_payment_display', true );
601
602
	if( 'button' === $display_option ) {
603
		$display_option = 'modal';
604
	}elseif ( $display_option === 'onpage' ) {
605
		return '';
606
	}
607
608
	$display_label_field = get_post_meta( $form_id, '_give_reveal_label', true );
609
	$display_label       = ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) );
610
611
	$output = '<button type="button" class="give-btn give-btn-' . $display_option . '">' . $display_label . '</button>';
612
613
	echo apply_filters( 'give_display_checkout_button', $output );
614
}
615
616
add_action( 'give_after_donation_levels', 'give_display_checkout_button', 10, 2 );
617
618
/**
619
 * Shows the User Info fields in the Personal Info box, more fields can be added via the hooks provided.
620
 *
621
 * @since  1.0
622
 *
623
 * @param  int $form_id The form ID.
624
 *
625
 * @return void
626
 */
627
function give_user_info_fields( $form_id ) {
628
	// Get user info.
629
	$give_user_info = _give_get_prefill_form_field_values( $form_id );
630
631
	/**
632
	 * Fire before user personal information fields
633
	 *
634
	 * @since 1.7
635
	 */
636
	do_action( 'give_donation_form_before_personal_info', $form_id );
637
	?>
638
	<fieldset id="give_checkout_user_info">
639
		<legend><?php echo apply_filters( 'give_checkout_personal_info_text', esc_html__( 'Personal Info', 'give' ) ); ?></legend>
640
		<p id="give-first-name-wrap" class="form-row form-row-first">
641
			<label class="give-label" for="give-first">
642
				<?php esc_html_e( 'First Name', 'give' ); ?>
643
				<?php if ( give_field_is_required( 'give_first', $form_id ) ) : ?>
644
					<span class="give-required-indicator">*</span>
645
				<?php endif ?>
646
				<span class="give-tooltip give-icon give-icon-question"
647
				      data-tooltip="<?php esc_attr_e( 'We will use this to personalize your account experience.', 'give' ); ?>"></span>
648
			</label>
649
			<input
650
				class="give-input required"
651
				type="text"
652
				name="give_first"
653
				placeholder="<?php esc_attr_e( 'First Name', 'give' ); ?>"
654
				id="give-first"
655
				value="<?php echo isset( $give_user_info['give_first'] ) ? $give_user_info['give_first'] : ''; ?>"
656
				<?php echo( give_field_is_required( 'give_first', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
657
			/>
658
		</p>
659
660
		<p id="give-last-name-wrap" class="form-row form-row-last">
661
			<label class="give-label" for="give-last">
662
				<?php esc_html_e( 'Last Name', 'give' ); ?>
663
				<?php if ( give_field_is_required( 'give_last', $form_id ) ) : ?>
664
					<span class="give-required-indicator">*</span>
665
				<?php endif ?>
666
				<span class="give-tooltip give-icon give-icon-question"
667
				      data-tooltip="<?php esc_attr_e( 'We will use this as well to personalize your account experience.', 'give' ); ?>"></span>
668
			</label>
669
670
			<input
671
				class="give-input<?php echo( give_field_is_required( 'give_last', $form_id ) ? ' required' : '' ); ?>"
672
				type="text"
673
				name="give_last"
674
				id="give-last"
675
				placeholder="<?php esc_attr_e( 'Last Name', 'give' ); ?>"
676
				value="<?php echo isset( $give_user_info['give_last'] ) ? $give_user_info['give_last'] : ''; ?>"
677
				<?php echo( give_field_is_required( 'give_last', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
678
			/>
679
		</p>
680
681
		<?php
682
		/**
683
		 * Fire before user email field
684
		 *
685
		 * @since 1.7
686
		 */
687
		do_action( 'give_donation_form_before_email', $form_id );
688
		?>
689
		<p id="give-email-wrap" class="form-row form-row-wide">
690
			<label class="give-label" for="give-email">
691
				<?php esc_html_e( 'Email Address', 'give' ); ?>
692
				<?php if ( give_field_is_required( 'give_email', $form_id ) ) { ?>
693
					<span class="give-required-indicator">*</span>
694
				<?php } ?>
695
				<span class="give-tooltip give-icon give-icon-question"
696
				      data-tooltip="<?php esc_attr_e( 'We will send the donation receipt to this address.', 'give' ); ?>"></span>
697
			</label>
698
699
			<input
700
				class="give-input required"
701
				type="email"
702
				name="give_email"
703
				placeholder="<?php esc_attr_e( 'Email Address', 'give' ); ?>"
704
				id="give-email"
705
				value="<?php echo isset( $give_user_info['give_email'] ) ? $give_user_info['give_email'] : ''; ?>"
706
				<?php echo( give_field_is_required( 'give_email', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
707
			/>
708
709
		</p>
710
		<?php
711
		/**
712
		 * Fire after user email field
713
		 *
714
		 * @since 1.7
715
		 */
716
		do_action( 'give_donation_form_after_email', $form_id );
717
718
		/**
719
		 * Fire after personal email field
720
		 *
721
		 * @since 1.7
722
		 */
723
		do_action( 'give_donation_form_user_info', $form_id );
724
		?>
725
	</fieldset>
726
	<?php
727
	/**
728
	 * Fire after user personal information fields
729
	 *
730
	 * @since 1.7
731
	 */
732
	do_action( 'give_donation_form_after_personal_info', $form_id );
733
}
734
735
add_action( 'give_donation_form_after_user_info', 'give_user_info_fields' );
736
add_action( 'give_register_fields_before', 'give_user_info_fields' );
737
738
/**
739
 * Renders the credit card info form.
740
 *
741
 * @since  1.0
742
 *
743
 * @param  int $form_id The form ID.
744
 *
745
 * @return void
746
 */
747
function give_get_cc_form( $form_id ) {
748
749
	ob_start();
750
751
	/**
752
	 * Fires while rendering credit card info form, before the fields.
753
	 *
754
	 * @since 1.0
755
	 *
756
	 * @param int $form_id The form ID.
757
	 */
758
	do_action( 'give_before_cc_fields', $form_id );
759
	?>
760
	<fieldset id="give_cc_fields-<?php echo $form_id ?>" class="give-do-validate">
761
		<legend><?php echo apply_filters( 'give_credit_card_fieldset_heading', esc_html__( 'Credit Card Info', 'give' ) ); ?></legend>
762
		<?php if ( is_ssl() ) : ?>
763
			<div id="give_secure_site_wrapper-<?php echo $form_id ?>">
764
				<span class="give-icon padlock"></span>
765
				<span><?php esc_html_e( 'This is a secure SSL encrypted payment.', 'give' ); ?></span>
766
			</div>
767
		<?php endif; ?>
768
		<p id="give-card-number-wrap-<?php echo $form_id ?>" class="form-row form-row-two-thirds">
769
			<label for="card_number-<?php echo $form_id ?>" class="give-label">
770
				<?php esc_html_e( 'Card Number', 'give' ); ?>
771
				<span class="give-required-indicator">*</span>
772
				<span class="give-tooltip give-icon give-icon-question"
773
				      data-tooltip="<?php esc_attr_e( 'The (typically) 16 digits on the front of your credit card.', 'give' ); ?>"></span>
774
				<span class="card-type"></span>
775
			</label>
776
777
			<input type="tel" autocomplete="off" name="card_number" id="card_number-<?php echo $form_id ?>"
778
			       class="card-number give-input required" placeholder="<?php esc_attr_e( 'Card number', 'give' ); ?>"
779
			       required aria-required="true"/>
780
		</p>
781
782
		<p id="give-card-cvc-wrap-<?php echo $form_id ?>" class="form-row form-row-one-third">
783
			<label for="card_cvc-<?php echo $form_id ?>" class="give-label">
784
				<?php esc_html_e( 'CVC', 'give' ); ?>
785
				<span class="give-required-indicator">*</span>
786
				<span class="give-tooltip give-icon give-icon-question"
787
				      data-tooltip="<?php esc_attr_e( 'The 3 digit (back) or 4 digit (front) value on your card.', 'give' ); ?>"></span>
788
			</label>
789
790
			<input type="tel" size="4" autocomplete="off" name="card_cvc" id="card_cvc-<?php echo $form_id ?>"
791
			       class="card-cvc give-input required" placeholder="<?php esc_attr_e( 'Security code', 'give' ); ?>"
792
			       required aria-required="true"/>
793
		</p>
794
795
		<p id="give-card-name-wrap-<?php echo $form_id ?>" class="form-row form-row-two-thirds">
796
			<label for="card_name-<?php echo $form_id ?>" class="give-label">
797
				<?php esc_html_e( 'Name on the Card', 'give' ); ?>
798
				<span class="give-required-indicator">*</span>
799
				<span class="give-tooltip give-icon give-icon-question"
800
				      data-tooltip="<?php esc_attr_e( 'The name printed on the front of your credit card.', 'give' ); ?>"></span>
801
			</label>
802
803
			<input type="text" autocomplete="off" name="card_name" id="card_name-<?php echo $form_id ?>"
804
			       class="card-name give-input required" placeholder="<?php esc_attr_e( 'Card name', 'give' ); ?>"
805
			       required aria-required="true"/>
806
		</p>
807
		<?php
808
		/**
809
		 * Fires while rendering credit card info form, before expiration fields.
810
		 *
811
		 * @since 1.0
812
		 *
813
		 * @param int $form_id The form ID.
814
		 */
815
		do_action( 'give_before_cc_expiration' );
816
		?>
817
		<p class="card-expiration form-row form-row-one-third">
818
			<label for="card_expiry-<?php echo $form_id ?>" class="give-label">
819
				<?php esc_html_e( 'Expiration', 'give' ); ?>
820
				<span class="give-required-indicator">*</span>
821
				<span class="give-tooltip give-icon give-icon-question"
822
				      data-tooltip="<?php esc_attr_e( 'The date your credit card expires, typically on the front of the card.', 'give' ); ?>"></span>
823
			</label>
824
825
			<input type="hidden" id="card_exp_month-<?php echo $form_id ?>" name="card_exp_month"
826
			       class="card-expiry-month"/>
827
			<input type="hidden" id="card_exp_year-<?php echo $form_id ?>" name="card_exp_year"
828
			       class="card-expiry-year"/>
829
830
			<input type="tel" autocomplete="off" name="card_expiry" id="card_expiry-<?php echo $form_id ?>"
831
			       class="card-expiry give-input required" placeholder="<?php esc_attr_e( 'MM / YY', 'give' ); ?>"
832
			       required aria-required="true"/>
833
		</p>
834
		<?php
835
		/**
836
		 * Fires while rendering credit card info form, after expiration fields.
837
		 *
838
		 * @since 1.0
839
		 *
840
		 * @param int $form_id The form ID.
841
		 */
842
		do_action( 'give_after_cc_expiration', $form_id );
843
		?>
844
	</fieldset>
845
	<?php
846
	/**
847
	 * Fires while rendering credit card info form, before the fields.
848
	 *
849
	 * @since 1.0
850
	 *
851
	 * @param int $form_id The form ID.
852
	 */
853
	do_action( 'give_after_cc_fields', $form_id );
854
855
	echo ob_get_clean();
856
}
857
858
add_action( 'give_cc_form', 'give_get_cc_form' );
859
860
/**
861
 * Outputs the default credit card address fields.
862
 *
863
 * @since  1.0
864
 *
865
 * @param  int $form_id The form ID.
866
 *
867
 * @return void
868
 */
869
function give_default_cc_address_fields( $form_id ) {
870
	// Get user info.
871
	$give_user_info = _give_get_prefill_form_field_values( $form_id );
872
873
	$logged_in = is_user_logged_in();
874
875
	if ( $logged_in ) {
876
		$user_address = get_user_meta( get_current_user_id(), '_give_user_address', true );
877
	}
878
	$line1 = $logged_in && ! empty( $user_address['line1'] ) ? $user_address['line1'] : '';
879
	$line2 = $logged_in && ! empty( $user_address['line2'] ) ? $user_address['line2'] : '';
880
	$city  = $logged_in && ! empty( $user_address['city'] ) ? $user_address['city'] : '';
881
	$zip   = $logged_in && ! empty( $user_address['zip'] ) ? $user_address['zip'] : '';
882
883
	ob_start();
884
	?>
885
	<fieldset id="give_cc_address" class="cc-address">
886
		<legend><?php echo apply_filters( 'give_billing_details_fieldset_heading', esc_html__( 'Billing Details', 'give' ) ); ?></legend>
887
		<?php
888
		/**
889
		 * Fires while rendering credit card billing form, before address fields.
890
		 *
891
		 * @since 1.0
892
		 *
893
		 * @param int $form_id The form ID.
894
		 */
895
		do_action( 'give_cc_billing_top' );
896
		?>
897
		<p id="give-card-address-wrap" class="form-row form-row-two-thirds">
898
			<label for="card_address" class="give-label">
899
				<?php esc_html_e( 'Address 1', 'give' ); ?>
900
				<?php
901
				if ( give_field_is_required( 'card_address', $form_id ) ) : ?>
902
					<span class="give-required-indicator">*</span>
903
				<?php endif; ?>
904
				<span class="give-tooltip give-icon give-icon-question"
905
				      data-tooltip="<?php esc_attr_e( 'The primary billing address for your credit card.', 'give' ); ?>"></span>
906
			</label>
907
908
			<input
909
				type="text"
910
				id="card_address"
911
				name="card_address"
912
				class="card-address give-input<?php echo( give_field_is_required( 'card_address', $form_id ) ? ' required' : '' ); ?>"
913
				placeholder="<?php esc_attr_e( 'Address line 1', 'give' ); ?>"
914
				value="<?php echo isset( $give_user_info['card_address'] ) ? $give_user_info['card_address'] : ''; ?>"
915
				<?php echo( give_field_is_required( 'card_address', $form_id ) ? '  required aria-required="true" ' : '' ); ?>
916
			/>
917
		</p>
918
919
		<p id="give-card-address-2-wrap" class="form-row form-row-one-third">
920
			<label for="card_address_2" class="give-label">
921
				<?php esc_html_e( 'Address 2', 'give' ); ?>
922
				<?php if ( give_field_is_required( 'card_address_2', $form_id ) ) : ?>
923
					<span class="give-required-indicator">*</span>
924
				<?php endif; ?>
925
				<span class="give-tooltip give-icon give-icon-question"
926
				      data-tooltip="<?php esc_attr_e( '(optional) The suite, apt no, PO box, etc, associated with your billing address.', 'give' ); ?>"></span>
927
			</label>
928
929
			<input
930
				type="text"
931
				id="card_address_2"
932
				name="card_address_2"
933
				class="card-address-2 give-input<?php echo( give_field_is_required( 'card_address_2', $form_id ) ? ' required' : '' ); ?>"
934
				placeholder="<?php esc_attr_e( 'Address line 2', 'give' ); ?>"
935
				value="<?php echo isset( $give_user_info['card_address_2'] ) ? $give_user_info['card_address_2'] : ''; ?>"
936
				<?php echo( give_field_is_required( 'card_address_2', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
937
			/>
938
		</p>
939
940
		<p id="give-card-city-wrap" class="form-row form-row-two-thirds">
941
			<label for="card_city" class="give-label">
942
				<?php esc_html_e( 'City', 'give' ); ?>
943
				<?php if ( give_field_is_required( 'card_city', $form_id ) ) : ?>
944
					<span class="give-required-indicator">*</span>
945
				<?php endif; ?>
946
				<span class="give-tooltip give-icon give-icon-question"
947
				      data-tooltip="<?php esc_attr_e( 'The city for your billing address.', 'give' ); ?>"></span>
948
			</label>
949
			<input
950
				type="text"
951
				id="card_city"
952
				name="card_city"
953
				class="card-city give-input<?php echo( give_field_is_required( 'card_city', $form_id ) ? ' required' : '' ); ?>"
954
				placeholder="<?php esc_attr_e( 'City', 'give' ); ?>"
955
				value="<?php echo isset( $give_user_info['card_city'] ) ? $give_user_info['card_city'] : ''; ?>"
956
				<?php echo( give_field_is_required( 'card_city', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
957
			/>
958
		</p>
959
960
		<p id="give-card-zip-wrap" class="form-row form-row-one-third">
961
			<label for="card_zip" class="give-label">
962
				<?php esc_html_e( 'Zip / Postal Code', 'give' ); ?>
963
				<?php if ( give_field_is_required( 'card_zip', $form_id ) ) : ?>
964
					<span class="give-required-indicator">*</span>
965
				<?php endif; ?>
966
				<span class="give-tooltip give-icon give-icon-question"
967
				      data-tooltip="<?php esc_attr_e( 'The zip or postal code for your billing address.', 'give' ); ?>"></span>
968
			</label>
969
970
			<input
971
				type="text"
972
				size="4"
973
				id="card_zip"
974
				name="card_zip"
975
				class="card-zip give-input<?php echo( give_field_is_required( 'card_zip', $form_id ) ? ' required' : '' ); ?>"
976
				placeholder="<?php esc_attr_e( 'Zip / Postal Code', 'give' ); ?>"
977
				value="<?php echo isset( $give_user_info['card_zip'] ) ? $give_user_info['card_zip'] : ''; ?>"
978
				<?php echo( give_field_is_required( 'card_zip', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
979
			/>
980
		</p>
981
982
		<p id="give-card-country-wrap" class="form-row form-row-first">
983
			<label for="billing_country" class="give-label">
984
				<?php esc_html_e( 'Country', 'give' ); ?>
985
				<?php if ( give_field_is_required( 'billing_country', $form_id ) ) : ?>
986
					<span class="give-required-indicator">*</span>
987
				<?php endif; ?>
988
				<span class="give-tooltip give-icon give-icon-question"
989
				      data-tooltip="<?php esc_attr_e( 'The country for your billing address.', 'give' ); ?>"></span>
990
			</label>
991
992
			<select
993
				name="billing_country"
994
				id="billing_country"
995
				class="billing-country billing_country give-select<?php echo( give_field_is_required( 'billing_country', $form_id ) ? ' required' : '' ); ?>"
996
				<?php echo( give_field_is_required( 'billing_country', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
997
			>
998
				<?php
999
1000
				$selected_country = give_get_country();
1001
1002
				if ( ! empty( $give_user_info['billing_country'] ) && '*' !== $give_user_info['billing_country'] ) {
1003
					$selected_country = $give_user_info['billing_country'];
1004
				}
1005
1006
				$countries = give_get_country_list();
1007
				foreach ( $countries as $country_code => $country ) {
1008
					echo '<option value="' . esc_attr( $country_code ) . '"' . selected( $country_code, $selected_country, false ) . '>' . $country . '</option>';
1009
				}
1010
				?>
1011
			</select>
1012
		</p>
1013
1014
		<p id="give-card-state-wrap" class="form-row form-row-last">
1015
			<label for="card_state" class="give-label">
1016
				<?php esc_html_e( 'State / Province', 'give' ); ?>
1017
				<?php if ( give_field_is_required( 'card_state', $form_id ) ) : ?>
1018
					<span class="give-required-indicator">*</span>
1019
				<?php endif; ?>
1020
				<span class="give-tooltip give-icon give-icon-question"
1021
				      data-tooltip="<?php esc_attr_e( 'The state or province for your billing address.', 'give' ); ?>"></span>
1022
			</label>
1023
1024
			<?php
1025
			$selected_state = give_get_state();
1026
			$states         = give_get_states( $selected_country );
1027
1028
			if ( ! empty( $give_user_info['card_state'] ) ) {
1029
				$selected_state = $give_user_info['card_state'];
1030
			}
1031
1032
			if ( ! empty( $states ) ) : ?>
1033
				<select
1034
					name="card_state"
1035
					id="card_state"
1036
					class="card_state give-select<?php echo( give_field_is_required( 'card_state', $form_id ) ? ' required' : '' ); ?>"
1037
					<?php echo( give_field_is_required( 'card_state', $form_id ) ? ' required aria-required="true" ' : '' ); ?>>
1038
					<?php
1039
					foreach ( $states as $state_code => $state ) {
1040
						echo '<option value="' . $state_code . '"' . selected( $state_code, $selected_state, false ) . '>' . $state . '</option>';
1041
					}
1042
					?>
1043
				</select>
1044
			<?php else : ?>
1045
				<input type="text" size="6" name="card_state" id="card_state" class="card_state give-input"
1046
				       placeholder="<?php esc_attr_e( 'State / Province', 'give' ); ?>"/>
1047
			<?php endif; ?>
1048
		</p>
1049
		<?php
1050
		/**
1051
		 * Fires while rendering credit card billing form, after address fields.
1052
		 *
1053
		 * @since 1.0
1054
		 *
1055
		 * @param int $form_id The form ID.
1056
		 */
1057
		do_action( 'give_cc_billing_bottom' );
1058
		?>
1059
	</fieldset>
1060
	<?php
1061
	echo ob_get_clean();
1062
}
1063
1064
add_action( 'give_after_cc_fields', 'give_default_cc_address_fields' );
1065
1066
1067
/**
1068
 * 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.
1069
 *
1070
 * @since  1.0
1071
 *
1072
 * @param  int $form_id The form ID.
1073
 *
1074
 * @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...
1075
 */
1076
function give_get_register_fields( $form_id ) {
1077
1078
	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...
1079
1080
	if ( is_user_logged_in() ) {
1081
		$user_data = get_userdata( $user_ID );
1082
	}
1083
1084
	$show_register_form = give_show_login_register_option( $form_id );
1085
1086
	ob_start(); ?>
1087
	<fieldset id="give-register-fields-<?php echo $form_id; ?>">
1088
1089
		<?php if ( $show_register_form == 'both' ) { ?>
1090
			<div class="give-login-account-wrap">
1091
				<p class="give-login-message"><?php esc_html_e( 'Already have an account?', 'give' ); ?>&nbsp;
1092
					<a href="<?php echo esc_url( add_query_arg( 'login', 1 ) ); ?>" class="give-checkout-login"
1093
					   data-action="give_checkout_login"><?php esc_html_e( 'Login', 'give' ); ?></a>
1094
				</p>
1095
				<p class="give-loading-text">
1096
					<span class="give-loading-animation"></span> <?php esc_html_e( 'Loading...', 'give' ); ?></p>
1097
			</div>
1098
		<?php } ?>
1099
1100
		<?php
1101
		/**
1102
		 * Fires while rendering user registration form, before registration fields.
1103
		 *
1104
		 * @since 1.0
1105
		 *
1106
		 * @param int $form_id The form ID.
1107
		 */
1108
		do_action( 'give_register_fields_before', $form_id );
1109
		?>
1110
1111
		<fieldset id="give-register-account-fields-<?php echo $form_id; ?>">
1112
			<legend>
1113
				<?php
1114
				echo apply_filters( 'give_create_account_fieldset_heading', esc_html__( 'Create an account', 'give' ) );
1115
				if ( ! give_logged_in_only( $form_id ) ) {
1116
					echo ' <span class="sub-text">' . esc_html__( '(optional)', 'give' ) . '</span>';
1117
				}
1118
				?>
1119
			</legend>
1120
			<?php
1121
			/**
1122
			 * Fires while rendering user registration form, before account fields.
1123
			 *
1124
			 * @since 1.0
1125
			 *
1126
			 * @param int $form_id The form ID.
1127
			 */
1128
			do_action( 'give_register_account_fields_before', $form_id );
1129
			?>
1130
			<div id="give-user-login-wrap-<?php echo $form_id; ?>" class="form-row form-row-one-third form-row-first">
1131
				<label for="give-user-login-<?php echo $form_id; ?>">
1132
					<?php esc_html_e( 'Username', 'give' ); ?>
1133
					<?php if ( give_logged_in_only( $form_id ) ) { ?>
1134
						<span class="give-required-indicator">*</span>
1135
					<?php } ?>
1136
					<span class="give-tooltip give-icon give-icon-question"
1137
					      data-tooltip="<?php esc_attr_e( 'The username you will use to log into your account.', 'give' ); ?>"></span>
1138
				</label>
1139
1140
				<input name="give_user_login" id="give-user-login-<?php echo $form_id; ?>" class="give-input"
1141
				       type="text"
1142
				       placeholder="<?php esc_attr_e( 'Username', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/>
1143
			</div>
1144
1145
			<div id="give-user-pass-wrap-<?php echo $form_id; ?>" class="form-row form-row-one-third">
1146
				<label for="give-user-pass-<?php echo $form_id; ?>">
1147
					<?php esc_html_e( 'Password', 'give' ); ?>
1148
					<?php if ( give_logged_in_only( $form_id ) ) { ?>
1149
						<span class="give-required-indicator">*</span>
1150
					<?php } ?>
1151
					<span class="give-tooltip give-icon give-icon-question"
1152
					      data-tooltip="<?php esc_attr_e( 'The password used to access your account.', 'give' ); ?>"></span>
1153
				</label>
1154
1155
				<input name="give_user_pass" id="give-user-pass-<?php echo $form_id; ?>" class="give-input"
1156
				       placeholder="<?php esc_attr_e( 'Password', 'give' ); ?>"
1157
				       type="password"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/>
1158
			</div>
1159
1160
			<div id="give-user-pass-confirm-wrap-<?php echo $form_id; ?>"
1161
			     class="give-register-password form-row form-row-one-third">
1162
				<label for="give-user-pass-confirm-<?php echo $form_id; ?>">
1163
					<?php esc_html_e( 'Confirm PW', 'give' ); ?>
1164
					<?php if ( give_logged_in_only( $form_id ) ) { ?>
1165
						<span class="give-required-indicator">*</span>
1166
					<?php } ?>
1167
					<span class="give-tooltip give-icon give-icon-question"
1168
					      data-tooltip="<?php esc_attr_e( 'Please retype your password to confirm.', 'give' ); ?>"></span>
1169
				</label>
1170
1171
				<input name="give_user_pass_confirm" id="give-user-pass-confirm-<?php echo $form_id; ?>"
1172
				       class="give-input" placeholder="<?php esc_attr_e( 'Confirm password', 'give' ); ?>"
1173
				       type="password"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/>
1174
			</div>
1175
			<?php
1176
			/**
1177
			 * Fires while rendering user registration form, after account fields.
1178
			 *
1179
			 * @since 1.0
1180
			 *
1181
			 * @param int $form_id The form ID.
1182
			 */
1183
			do_action( 'give_register_account_fields_after', $form_id );
1184
			?>
1185
		</fieldset>
1186
1187
		<?php
1188
		/**
1189
		 * Fires while rendering user registration form, after registration fields.
1190
		 *
1191
		 * @since 1.0
1192
		 *
1193
		 * @param int $form_id The form ID.
1194
		 */
1195
		do_action( 'give_register_fields_after', $form_id );
1196
		?>
1197
1198
		<input type="hidden" name="give-purchase-var" value="needs-to-register"/>
1199
1200
		<?php
1201
		/**
1202
		 * Fire after register or login form render
1203
		 *
1204
		 * @since 1.7
1205
		 */
1206
		do_action( 'give_donation_form_user_info', $form_id );
1207
		?>
1208
1209
	</fieldset>
1210
	<?php
1211
	echo ob_get_clean();
1212
}
1213
1214
add_action( 'give_donation_form_register_fields', 'give_get_register_fields' );
1215
1216
/**
1217
 * Gets the login fields for the login form on the checkout. This function hooks
1218
 * on the give_donation_form_login_fields to display the login form if a user already
1219
 * had an account.
1220
 *
1221
 * @since  1.0
1222
 *
1223
 * @param  int $form_id The form ID.
1224
 *
1225
 * @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...
1226
 */
1227
function give_get_login_fields( $form_id ) {
1228
1229
	$form_id            = isset( $_POST['form_id'] ) ? $_POST['form_id'] : $form_id;
1230
	$show_register_form = give_show_login_register_option( $form_id );
1231
1232
	ob_start();
1233
	?>
1234
	<fieldset id="give-login-fields-<?php echo $form_id; ?>">
1235
		<legend><?php echo apply_filters( 'give_account_login_fieldset_heading', esc_html__( 'Login to Your Account', 'give' ) );
1236
			if ( ! give_logged_in_only( $form_id ) ) {
1237
				echo ' <span class="sub-text">' . esc_html__( '(optional)', 'give' ) . '</span>';
1238
			} ?>
1239
		</legend>
1240
		<?php if ( $show_register_form == 'both' ) { ?>
1241
			<p class="give-new-account-link">
1242
				<?php esc_html_e( 'Need to create an account?', 'give' ); ?>&nbsp;
1243
				<a href="<?php echo remove_query_arg( 'login' ); ?>" class="give-checkout-register-cancel"
1244
				   data-action="give_checkout_register">
1245
					<?php esc_html_e( 'Register', 'give' );
1246
					if ( ! give_logged_in_only( $form_id ) ) {
1247
						echo ' ' . esc_html__( 'or checkout as a guest &raquo;', 'give' );
1248
					} ?>
1249
				</a>
1250
			</p>
1251
			<p class="give-loading-text">
1252
				<span class="give-loading-animation"></span> <?php esc_html_e( 'Loading...', 'give' ); ?> </p>
1253
		<?php } ?>
1254
		<?php
1255
		/**
1256
		 * Fires while rendering checkout login form, before the fields.
1257
		 *
1258
		 * @since 1.0
1259
		 *
1260
		 * @param int $form_id The form ID.
1261
		 */
1262
		do_action( 'give_checkout_login_fields_before', $form_id );
1263
		?>
1264
		<div id="give-user-login-wrap-<?php echo $form_id; ?>" class="form-row form-row-first">
1265
			<label class="give-label" for="give-user-login-<?php echo $form_id; ?>">
1266
				<?php esc_html_e( 'Username', 'give' ); ?>
1267
				<?php if ( give_logged_in_only( $form_id ) ) { ?>
1268
					<span class="give-required-indicator">*</span>
1269
				<?php } ?>
1270
			</label>
1271
1272
			<input class="give-input<?php echo ( give_logged_in_only( $form_id ) ) ? ' required' : ''; ?>" type="text"
1273
			       name="give_user_login" id="give-user-login-<?php echo $form_id; ?>" value=""
1274
			       placeholder="<?php esc_attr_e( 'Your username', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/>
1275
		</div>
1276
1277
		<div id="give-user-pass-wrap-<?php echo $form_id; ?>" class="give_login_password form-row form-row-last">
1278
			<label class="give-label" for="give-user-pass-<?php echo $form_id; ?>">
1279
				<?php esc_html_e( 'Password', 'give' ); ?>
1280
				<?php if ( give_logged_in_only( $form_id ) ) { ?>
1281
					<span class="give-required-indicator">*</span>
1282
				<?php } ?>
1283
			</label>
1284
			<input class="give-input<?php echo ( give_logged_in_only( $form_id ) ) ? ' required' : ''; ?>"
1285
			       type="password" name="give_user_pass" id="give-user-pass-<?php echo $form_id; ?>"
1286
			       placeholder="<?php esc_attr_e( 'Your password', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/>
1287
			<input type="hidden" name="give-purchase-var" value="needs-to-login"/>
1288
		</div>
1289
1290
		<div id="give-forgot-password-wrap-<?php echo $form_id; ?>" class="give_login_forgot_password">
1291
			 <span class="give-forgot-password ">
1292
				 <a href="<?php echo wp_lostpassword_url() ?>"
1293
				    target="_blank"><?php esc_html_e( 'Reset Password', 'give' ) ?></a>
1294
			 </span>
1295
		</div>
1296
1297
		<div id="give-user-login-submit-<?php echo $form_id; ?>" class="give-clearfix">
1298
			<input type="submit" class="give-submit give-btn button" name="give_login_submit"
1299
			       value="<?php esc_attr_e( 'Login', 'give' ); ?>"/>
1300
			<?php if ( $show_register_form !== 'login' ) { ?>
1301
				<input type="button" data-action="give_cancel_login"
1302
				       class="give-cancel-login give-checkout-register-cancel give-btn button" name="give_login_cancel"
1303
				       value="<?php esc_attr_e( 'Cancel', 'give' ); ?>"/>
1304
			<?php } ?>
1305
			<span class="give-loading-animation"></span>
1306
		</div>
1307
		<?php
1308
		/**
1309
		 * Fires while rendering checkout login form, after the fields.
1310
		 *
1311
		 * @since 1.0
1312
		 *
1313
		 * @param int $form_id The form ID.
1314
		 */
1315
		do_action( 'give_checkout_login_fields_after', $form_id );
1316
		?>
1317
	</fieldset><!--end #give-login-fields-->
1318
	<?php
1319
	echo ob_get_clean();
1320
}
1321
1322
add_action( 'give_donation_form_login_fields', 'give_get_login_fields', 10, 1 );
1323
1324
/**
1325
 * Payment Mode Select.
1326
 *
1327
 * Renders the payment mode form by getting all the enabled payment gateways and
1328
 * outputting them as radio buttons for the user to choose the payment gateway. If
1329
 * a default payment gateway has been chosen from the Give Settings, it will be
1330
 * automatically selected.
1331
 *
1332
 * @since  1.0
1333
 *
1334
 * @param  int $form_id The form ID.
1335
 *
1336
 * @return void
1337
 */
1338
function give_payment_mode_select( $form_id ) {
1339
1340
	$gateways = give_get_enabled_payment_gateways( $form_id );
1341
1342
	/**
1343
	 * Fires while selecting payment gateways, before the fields.
1344
	 *
1345
	 * @since 1.7
1346
	 *
1347
	 * @param int $form_id The form ID.
1348
	 */
1349
	do_action( 'give_payment_mode_top', $form_id );
1350
	?>
1351
1352
	<fieldset id="give-payment-mode-select" <?php if ( count( $gateways ) <= 1 ) {
1353
		echo 'style="display: none;"';
1354
	} ?>>
1355
		<?php
1356
		/**
1357
		 * Fires while selecting payment gateways, before the wrap div.
1358
		 *
1359
		 * @since 1.7
1360
		 *
1361
		 * @param int $form_id The form ID.
1362
		 */
1363
		do_action( 'give_payment_mode_before_gateways_wrap' );
1364
		?>
1365
		<legend
1366
			class="give-payment-mode-label"><?php echo apply_filters( 'give_checkout_payment_method_text', esc_html__( 'Select Payment Method', 'give' ) ); ?></legend>
1367
1368
		<div id="give-payment-mode-wrap">
1369
			<span class="give-loading-text"><span
1370
					class="give-loading-animation"></span> <?php esc_html_e( 'Loading...', 'give' ); ?></span>
1371
1372
			<?php
1373
			/**
1374
			 * Fires while selecting payment gateways, befire the gateways list.
1375
			 *
1376
			 * @since 1.7
1377
			 */
1378
			do_action( 'give_payment_mode_before_gateways' )
1379
			?>
1380
			<ul id="give-gateway-radio-list">
1381
				<?php
1382
				/**
1383
				 * Loop through the active payment gateways.
1384
				 */
1385
				$selected_gateway = give_get_chosen_gateway( $form_id );
1386
1387
				foreach ( $gateways as $gateway_id => $gateway ) :
1388
					//Determine the default gateway.
1389
					$checked       = checked( $gateway_id, $selected_gateway, false );
1390
					$checked_class = $checked ? ' class="give-gateway-option-selected"' : ''; ?>
1391
					<li<?php echo $checked_class?>>
1392
						<input type="radio" name="payment-mode" class="give-gateway"
1393
						       id="give-gateway-<?php echo esc_attr( $gateway_id ) . '-' . $form_id; ?>"
1394
						       value="<?php echo esc_attr( $gateway_id ); ?>"<?php echo $checked; ?>>
1395
						<label for="give-gateway-<?php echo esc_attr( $gateway_id ) . '-' . $form_id; ?>"
1396
						       class="give-gateway-option"
1397
						       id="give-gateway-option-<?php echo esc_attr( $gateway_id ); ?>"> <?php echo esc_html( $gateway['checkout_label'] ); ?></label>
1398
					</li>
1399
					<?php
1400
				endforeach;
1401
				?>
1402
			</ul>
1403
			<?php
1404
			/**
1405
			 * Fires while selecting payment gateways, before the gateways list.
1406
			 *
1407
			 * @since 1.7
1408
			 */
1409
			do_action( 'give_payment_mode_after_gateways' );
1410
			?>
1411
		</div>
1412
		<?php
1413
		/**
1414
		 * Fires while selecting payment gateways, after the wrap div.
1415
		 *
1416
		 * @since 1.7
1417
		 *
1418
		 * @param int $form_id The form ID.
1419
		 */
1420
		do_action( 'give_payment_mode_after_gateways_wrap' );
1421
		?>
1422
	</fieldset>
1423
1424
	<?php
1425
	/**
1426
	 * Fires while selecting payment gateways, after the fields.
1427
	 *
1428
	 * @since 1.7
1429
	 *
1430
	 * @param int $form_id The form ID.
1431
	 */
1432
	do_action( 'give_payment_mode_bottom', $form_id );
1433
	?>
1434
1435
	<div id="give_purchase_form_wrap">
1436
1437
		<?php
1438
		/**
1439
		 * Fire after payment field render.
1440
		 *
1441
		 * @since 1.7
1442
		 */
1443
		do_action( 'give_donation_form', $form_id );
1444
		?>
1445
1446
	</div>
1447
1448
	<?php
1449
	/**
1450
	 * Fire after donation form render.
1451
	 *
1452
	 * @since 1.7
1453
	 */
1454
	do_action( 'give_donation_form_wrap_bottom', $form_id );
1455
}
1456
1457
add_action( 'give_payment_mode_select', 'give_payment_mode_select' );
1458
1459
/**
1460
 * Renders the Checkout Agree to Terms, this displays a checkbox for users to
1461
 * agree the T&Cs set in the Give Settings. This is only displayed if T&Cs are
1462
 * set in the Give Settings.
1463
 *
1464
 * @since  1.0
1465
 *
1466
 * @param  int $form_id The form ID.
1467
 *
1468
 * @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...
1469
 */
1470
function give_terms_agreement( $form_id ) {
1471
	$form_option = get_post_meta( $form_id, '_give_terms_option', true );
1472
1473
	// Bailout if per form and global term and conditions is not setup.
1474
	if (
1475
		give_is_setting_enabled( $form_option, 'global' )
1476
		&& give_is_setting_enabled( give_get_option( 'terms' ) )
1477
	) {
1478
		$label         = give_get_option( 'agree_to_terms_label', esc_html__( 'Agree to Terms?', 'give' ) );
1479
		$terms         = $terms = give_get_option( 'agreement_text', '' );
1480
		$edit_term_url = admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=display&section=term-and-conditions' );
1481
1482
	} elseif ( give_is_setting_enabled( $form_option ) ) {
1483
		$label         = ( $label = get_post_meta( $form_id, '_give_agree_label', true ) ) ? stripslashes( $label ) : esc_html__( 'Agree to Terms?', 'give' );
1484
		$terms         = get_post_meta( $form_id, '_give_agree_text', true );
1485
		$edit_term_url = admin_url( 'post.php?post=' . $form_id . '&action=edit#form_terms_options' );
1486
1487
	} else {
1488
		return false;
1489
	}
1490
1491
	// Bailout: Check if term and conditions text is empty or not.
1492
	if ( empty( $terms ) ) {
1493
		if ( is_user_logged_in() && current_user_can( 'edit_give_forms' ) ) {
1494
			echo sprintf( __( 'Please enter valid terms and conditions in <a href="%s">this form\'s settings</a>.', 'give' ), $edit_term_url );
1495
		}
1496
1497
		return false;
1498
	}
1499
1500
	?>
1501
	<fieldset id="give_terms_agreement">
1502
		<legend><?php echo apply_filters( 'give_terms_agreement_text', esc_html__( 'Terms', 'give' ) ); ?></legend>
1503
		<div id="give_terms" class="give_terms-<?php echo $form_id; ?>" style="display:none;">
1504
			<?php
1505
			/**
1506
			 * Fires while rendering terms of agreement, before the fields.
1507
			 *
1508
			 * @since 1.0
1509
			 */
1510
			do_action( 'give_before_terms' );
1511
1512
			echo wpautop( stripslashes( $terms ) );
1513
			/**
1514
			 * Fires while rendering terms of agreement, after the fields.
1515
			 *
1516
			 * @since 1.0
1517
			 */
1518
			do_action( 'give_after_terms' );
1519
			?>
1520
		</div>
1521
		<div id="give_show_terms">
1522
			<a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button"
1523
			   aria-controls="give_terms"><?php esc_html_e( 'Show Terms', 'give' ); ?></a>
1524
			<a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button"
1525
			   aria-controls="give_terms" style="display:none;"><?php esc_html_e( 'Hide Terms', 'give' ); ?></a>
1526
		</div>
1527
1528
		<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" />
1529
		<label for="give_agree_to_terms-<?php echo $form_id; ?>"><?php echo $label; ?></label>
1530
1531
	</fieldset>
1532
	<?php
1533
}
1534
1535
add_action( 'give_donation_form_after_cc_form', 'give_terms_agreement', 8888, 1 );
1536
1537
/**
1538
 * Checkout Final Total.
1539
 *
1540
 * Shows the final donation total at the bottom of the checkout page.
1541
 *
1542
 * @since  1.0
1543
 *
1544
 * @param  int $form_id The form ID.
1545
 *
1546
 * @return void
1547
 */
1548
function give_checkout_final_total( $form_id ) {
1549
1550
	if ( isset( $_POST['give_total'] ) ) {
1551
		$total = apply_filters( 'give_donation_total', $_POST['give_total'] );
1552
	} else {
1553
		//default total.
1554
		$total = give_get_default_form_amount( $form_id );
1555
	}
1556
	//Only proceed if give_total available.
1557
	if ( empty( $total ) ) {
1558
		return;
1559
	}
1560
	?>
1561
	<p id="give-final-total-wrap" class="form-wrap ">
1562
		<span
1563
			class="give-donation-total-label"><?php echo apply_filters( 'give_donation_total_label', esc_html__( 'Donation Total:', 'give' ) ); ?></span>
1564
		<span class="give-final-total-amount"
1565
		      data-total="<?php echo give_format_amount( $total ); ?>"><?php echo give_currency_filter( give_format_amount( $total ) ); ?></span>
1566
	</p>
1567
	<?php
1568
}
1569
1570
add_action( 'give_donation_form_before_submit', 'give_checkout_final_total', 999 );
1571
1572
/**
1573
 * Renders the Checkout Submit section.
1574
 *
1575
 * @since  1.0
1576
 *
1577
 * @param  int $form_id The form ID.
1578
 *
1579
 * @return void
1580
 */
1581
function give_checkout_submit( $form_id ) {
1582
	?>
1583
	<fieldset id="give_purchase_submit">
1584
		<?php
1585
		/**
1586
		 * Fire before donation form submit.
1587
		 *
1588
		 * @since 1.7
1589
		 */
1590
		do_action( 'give_donation_form_before_submit', $form_id );
1591
1592
		give_checkout_hidden_fields( $form_id );
1593
1594
		echo give_checkout_button_purchase( $form_id );
1595
1596
		/**
1597
		 * Fire after donation form submit.
1598
		 *
1599
		 * @since 1.7
1600
		 */
1601
		do_action( 'give_donation_form_after_submit', $form_id );
1602
		?>
1603
	</fieldset>
1604
	<?php
1605
}
1606
1607
add_action( 'give_donation_form_after_cc_form', 'give_checkout_submit', 9999 );
1608
1609
/**
1610
 * Give Checkout Button.
1611
 *
1612
 * Renders the button on the Checkout.
1613
 *
1614
 * @since  1.0
1615
 *
1616
 * @param  int $form_id The form ID.
1617
 *
1618
 * @return string
1619
 */
1620
function give_checkout_button_purchase( $form_id ) {
1621
1622
	$display_label_field = get_post_meta( $form_id, '_give_checkout_label', true );
1623
	$display_label       = ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) );
1624
	ob_start(); ?>
1625
	<div class="give-submit-button-wrap give-clearfix">
1626
		<input type="submit" class="give-submit give-btn" id="give-purchase-button" name="give-purchase"
1627
		       value="<?php echo $display_label; ?>"/>
1628
		<span class="give-loading-animation"></span>
1629
	</div>
1630
	<?php
1631
	return apply_filters( 'give_checkout_button_purchase', ob_get_clean(), $form_id );
1632
}
1633
1634
/**
1635
 * Give Agree to Terms.
1636
 *
1637
 * Outputs the JavaScript code for the Agree to Terms section to toggle the T&Cs text.
1638
 *
1639
 * @since  1.0
1640
 *
1641
 * @param  int $form_id The form ID.
1642
 *
1643
 * @return void
1644
 */
1645
function give_agree_to_terms_js( $form_id ) {
1646
1647
	$form_option = get_post_meta( $form_id, '_give_terms_option', true );
1648
1649
	if ( give_is_setting_enabled( $form_option, array( 'enabled', 'global' ) ) ) {
1650
		?>
1651
		<script type="text/javascript">
1652
			jQuery(document).ready(function ($) {
1653
				$('body').on('click', '.give_terms_links-<?php echo $form_id;?>', function (e) {
1654
					e.preventDefault();
1655
					$('.give_terms-<?php echo $form_id;?>').slideToggle();
1656
					$('.give_terms_links-<?php echo $form_id;?>').toggle();
1657
					return false;
1658
				});
1659
			});
1660
		</script>
1661
		<?php
1662
	}
1663
}
1664
1665
add_action( 'give_checkout_form_top', 'give_agree_to_terms_js', 10, 2 );
1666
1667
/**
1668
 * Show Give Goals.
1669
 *
1670
 * @since  1.0
1671
 * @since  1.6   Add template for Give Goals Shortcode.
1672
 *               More info is on https://github.com/WordImpress/Give/issues/411
1673
 *
1674
 * @param  int   $form_id The form ID.
1675
 * @param  array $args    An array of form arguments.
1676
 *
1677
 * @return mixed
1678
 */
1679
function give_show_goal_progress( $form_id, $args ) {
1680
1681
	ob_start();
1682
	give_get_template( 'shortcode-goal', array( 'form_id' => $form_id, 'args' => $args ) );
1683
1684
	echo apply_filters( 'give_goal_output', ob_get_clean() );
1685
1686
	return true;
1687
}
1688
1689
add_action( 'give_pre_form', 'give_show_goal_progress', 10, 2 );
1690
1691
1692
/**
1693
 * Get form content position.
1694
 *
1695
 * @since  1.8
1696
 * @param  $form_id
1697
 * @param  $args
1698
 * @return mixed|string
1699
 */
1700
function give_get_form_content_placement( $form_id, $args ) {
1701
	$show_content = '';
1702
1703
	if ( isset( $args['show_content'] ) && ! empty( $args['show_content'] ) ) {
1704
		// Content positions.
1705
		$content_placement = array(
1706
			'above' => 'give_pre_form',
1707
			'below' => 'give_post_form',
1708
		);
1709
1710
		// Check if content position already decoded.
1711
		if ( in_array( $args['show_content'], $content_placement ) ) {
1712
			return $args['show_content'];
1713
		}
1714
1715
		$show_content = ( 'none' !== $args['show_content'] ? $content_placement[ $args['show_content'] ] : '' );
1716
1717
	} elseif ( give_is_setting_enabled( get_post_meta( $form_id, '_give_display_content', true ) ) ) {
1718
		$show_content = get_post_meta( $form_id, '_give_content_placement', true );
1719
1720
	} elseif ( 'none' !== get_post_meta( $form_id, '_give_content_option', true ) ) {
1721
		// Backward compatibility for _give_content_option for v18.
1722
		$show_content = get_post_meta( $form_id, '_give_content_option', true );
1723
	}
1724
1725
	return $show_content;
1726
}
1727
1728
/**
1729
 * Adds Actions to Render Form Content.
1730
 *
1731
 * @since  1.0
1732
 *
1733
 * @param  int   $form_id The form ID.
1734
 * @param  array $args    An array of form arguments.
1735
 *
1736
 * @return void|bool
1737
 */
1738
function give_form_content( $form_id, $args ) {
1739
1740
	$show_content = give_get_form_content_placement( $form_id, $args );
1741
1742
	// Bailout.
1743
	if( empty( $show_content ) ) {
1744
		return false;
1745
	}
1746
1747
	// Add action according to value.
1748
	add_action( $show_content, 'give_form_display_content', 10, 2 );
1749
}
1750
1751
add_action( 'give_pre_form_output', 'give_form_content', 10, 2 );
1752
1753
/**
1754
 * Renders Post Form Content.
1755
 *
1756
 * Displays content for Give forms; fired by action from give_form_content.
1757
 *
1758
 * @since  1.0
1759
 *
1760
 * @param  int   $form_id The form ID.
1761
 * @param  array $args    An array of form arguments.
1762
 *
1763
 * @return void
1764
 */
1765
function give_form_display_content( $form_id, $args ) {
1766
1767
	$content      = wpautop( get_post_meta( $form_id, '_give_form_content', true ) );
1768
	$show_content = give_get_form_content_placement( $form_id, $args );
1769
1770
	if ( give_is_setting_enabled( give_get_option( 'the_content_filter' ) ) ) {
1771
		$content = apply_filters( 'the_content', $content );
1772
	}
1773
1774
	$output = '<div id="give-form-content-' . $form_id . '" class="give-form-content-wrap ' . $show_content . '-content">' . $content . '</div>';
1775
1776
	echo apply_filters( 'give_form_content_output', $output );
1777
1778
	//remove action to prevent content output on addition forms on page.
1779
	//@see: https://github.com/WordImpress/Give/issues/634.
1780
	remove_action( $show_content, 'give_form_display_content' );
1781
}
1782
1783
/**
1784
 * Renders the hidden Checkout fields.
1785
 *
1786
 * @since 1.0
1787
 *
1788
 * @param  int $form_id The form ID.
1789
 *
1790
 * @return void
1791
 */
1792
function give_checkout_hidden_fields( $form_id ) {
1793
1794
	/**
1795
	 * Fires while rendering hidden checkout fields, before the fields.
1796
	 *
1797
	 * @since 1.0
1798
	 *
1799
	 * @param int $form_id The form ID.
1800
	 */
1801
	do_action( 'give_hidden_fields_before', $form_id );
1802
1803
	if ( is_user_logged_in() ) { ?>
1804
		<input type="hidden" name="give-user-id" value="<?php echo get_current_user_id(); ?>"/>
1805
	<?php } ?>
1806
	<input type="hidden" name="give_action" value="purchase"/>
1807
	<input type="hidden" name="give-gateway" value="<?php echo give_get_chosen_gateway( $form_id ); ?>"/>
1808
	<?php
1809
	/**
1810
	 * Fires while rendering hidden checkout fields, after the fields.
1811
	 *
1812
	 * @since 1.0
1813
	 *
1814
	 * @param int $form_id The form ID.
1815
	 */
1816
	do_action( 'give_hidden_fields_after', $form_id );
1817
1818
}
1819
1820
/**
1821
 * Filter Success Page Content.
1822
 *
1823
 * Applies filters to the success page content.
1824
 *
1825
 * @since 1.0
1826
 *
1827
 * @param  string $content Content before filters.
1828
 *
1829
 * @return string $content Filtered content.
1830
 */
1831
function give_filter_success_page_content( $content ) {
1832
1833
	$give_options = give_get_settings();
1834
1835
	if ( isset( $give_options['success_page'] ) && isset( $_GET['payment-confirmation'] ) && is_page( $give_options['success_page'] ) ) {
1836
		if ( has_filter( 'give_payment_confirm_' . $_GET['payment-confirmation'] ) ) {
1837
			$content = apply_filters( 'give_payment_confirm_' . $_GET['payment-confirmation'], $content );
1838
		}
1839
	}
1840
1841
	return $content;
1842
}
1843
1844
add_filter( 'the_content', 'give_filter_success_page_content' );
1845
1846
/**
1847
 * Test Mode Frontend Warning.
1848
 *
1849
 * Displays a notice on the frontend for donation forms.
1850
 *
1851
 * @since 1.1
1852
 */
1853
function give_test_mode_frontend_warning() {
1854
1855
	if ( give_is_test_mode() ) {
1856
		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>';
1857
	}
1858
}
1859
1860
add_action( 'give_pre_form', 'give_test_mode_frontend_warning', 10 );
1861
1862
/**
1863
 * Members-only Form.
1864
 *
1865
 * If "Disable Guest Donations" and "Display Register / Login" is set to none.
1866
 *
1867
 * @since  1.4.1
1868
 *
1869
 * @param  string $final_output
1870
 * @param  array  $args
1871
 *
1872
 * @return string
1873
 */
1874
function give_members_only_form( $final_output, $args ) {
1875
1876
	$form_id = isset( $args['form_id'] ) ? $args['form_id'] : 0;
1877
1878
	//Sanity Check: Must have form_id & not be logged in.
1879
	if ( empty( $form_id ) || is_user_logged_in() ) {
1880
		return $final_output;
1881
	}
1882
1883
	//Logged in only and Register / Login set to none.
1884
	if ( give_logged_in_only( $form_id ) && give_show_login_register_option( $form_id ) == 'none' ) {
1885
1886
		$final_output = give_output_error( esc_html__( 'Please log in in order to complete your donation.', 'give' ), false );
1887
1888
		return apply_filters( 'give_members_only_output', $final_output, $form_id );
1889
1890
	}
1891
1892
	return $final_output;
1893
1894
}
1895
1896
add_filter( 'give_donate_form', 'give_members_only_form', 10, 2 );
1897