Completed
Push — issues/1132 ( 716ec5...9a1477 )
by Ravinder
16:46
created

template.php ➔ give_checkout_button_purchase()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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