Completed
Pull Request — master (#1055)
by Rami
19:01
created

template.php ➔ give_terms_agreement()   C

Complexity

Conditions 7
Paths 13

Size

Total Lines 51
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 23.2584

Importance

Changes 0
Metric Value
cc 7
eloc 23
nc 13
nop 1
dl 0
loc 51
ccs 4
cts 13
cp 0.3076
crap 23.2584
rs 6.9743
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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

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

Commonly applied refactorings include:

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

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Give Form Template
4
 *
5
 * @package     Give
6
 * @subpackage  Forms
7
 * @copyright   Copyright (c) 2016, WordImpress
8
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
9
 * @since       1.0
10
 */
11
12
// Exit if accessed directly
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * Get Donation Form.
19
 *
20
 * @since  1.0
21
 *
22
 * @param  array  $args An array of form arguments.
23
 *
24
 * @return string Donation form.
25
 */
26
function give_get_donation_form( $args = array() ) {
27
28 1
	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 1
	$form_id = is_object( $post ) ? $post->ID : 0;
31
32 1
	if ( isset( $args['id'] ) ) {
33 1
		$form_id = $args['id'];
34 1
	}
35
36 1
	$defaults = apply_filters( 'give_form_args_defaults', array(
37
		'form_id' => $form_id
38 1
	) );
39
40 1
	$args = wp_parse_args( $args, $defaults );
41
42 1
	$form = new Give_Donate_Form( $args['form_id'] );
43
44
	//bail if no form ID
45 1
	if ( empty( $form->ID ) ) {
46
		return false;
47
	}
48
49 1
	$payment_mode = give_get_chosen_gateway( $form->ID );
50
51 1
	$form_action = esc_url( add_query_arg( apply_filters( 'give_form_action_args', array(
52 1
		'payment-mode' => $payment_mode,
53 1
	) ),
54 1
		give_get_current_page_url()
55 1
	) );
56
57
	//Sanity Check: Donation form not published or user doesn't have permission to view drafts
58 1
	if ( 'publish' !== $form->post_status && ! current_user_can( 'edit_give_forms', $form->ID ) ) {
59
		return false;
60
	}
61
62 1
	//Get the form wrap CSS classes.
63 1
	$form_wrap_classes       = $form->get_form_wrap_classes($args);
64 1
65
	//Get the <form> tag wrap CSS classes.
66 1
	$form_classes       = $form->get_form_classes($args);
67 1
68 1
	ob_start();
69
70
	/**
71 1
	 * Fires while outputing donation form, before the form wapper div.
72 1
	 *
73
	 * @since 1.0
74 1
	 *
75 1
	 * @param int   $form_id The form ID.
76
	 * @param array $args    An array of form arguments.
77
	 */
78 1
	do_action( 'give_pre_form_output', $form->ID, $args );
79 1
80 1
	?>
81
	<div id="give-form-<?php echo $form->ID; ?>-wrap" class="<?php echo $form_wrap_classes; ?>">
82 1
83 1
		<?php if ( $form->is_close_donation_form() ) {
84
85
			//Get Goal thank you message.
86 1
			$display_thankyou_message = get_post_meta( $form->ID, '_give_form_goal_achieved_message', true );
87
			$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' );
88
89
			//Print thank you message.
90
			apply_filters( 'give_goal_closed_output', give_output_error( $display_thankyou_message, true, 'success' ) );
91
92
		} else {
93
94
			if ( isset( $args['show_title'] ) && $args['show_title'] == true ) {
95
96
				echo apply_filters( 'give_form_title', '<h2 class="give-form-title">' . get_the_title( $form_id ) . '</h2>' );
97
98
			}
99
100
			/**
101
			 * Fires while outputing donation form, before the form.
102
			 *
103
			 * @since 1.0
104
			 *
105
			 * @param int   $form_id The form ID.
106
			 * @param array $args    An array of form arguments.
107
			 */
108
			do_action( 'give_pre_form', $form->ID, $args );
109
			?>
110
111 1
			<form id="give-form-<?php echo $form_id; ?>" class="<?php echo $form_classes; ?>" action="<?php echo $form_action; ?>" method="post">
112
				<input type="hidden" name="give-form-id" value="<?php echo $form->ID; ?>"/>
113
				<input type="hidden" name="give-form-title" value="<?php echo htmlentities( $form->post_title ); ?>"/>
114
				<input type="hidden" name="give-current-url" value="<?php echo htmlspecialchars( give_get_current_page_url() ); ?>"/>
115
				<input type="hidden" name="give-form-url" value="<?php echo htmlspecialchars( give_get_current_page_url() ); ?>"/>
116
				<input type="hidden" name="give-form-minimum" value="<?php echo give_format_amount( give_get_form_minimum_price( $form->ID ) ); ?>"/>
117
118
				<!-- The following field is for robots only, invisible to humans: -->
119
				<span class="give-hidden" style="display: none !important;">
120
					<label for="give-form-honeypot-<?php echo $form_id; ?>"></label>
121
					<input id="give-form-honeypot-<?php echo $form_id; ?>" type="text" name="give-honeypot" class="give-honeypot give-hidden"/>
122
				</span>
123
124
				<?php
125
126
				//Price ID hidden field for variable (mult-level) donation forms
127
				if ( give_has_variable_prices( $form_id ) ) {
128
					//get default selected price ID
129
					$prices   = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $form_id ), $form_id );
130
					$price_id = 0;
131
					//loop through prices
132
					foreach ( $prices as $price ) {
133
						if ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) {
134
							$price_id = $price['_give_id']['level_id'];
135 1
						};
136
					}
137 1
					?>
138 1
					<input type="hidden" name="give-price-id" value="<?php echo $price_id; ?>"/>
139
				<?php }
140 1
141 1
				/**
142 1
				 * Fires while outputing donation form, before all other fields.
143 1
				 *
144 1
				 * @since 1.0
145
				 *
146
				 * @param int   $form_id The form ID.
147
				 * @param array $args    An array of form arguments.
148
				 */
149 1
				do_action( 'give_checkout_form_top', $form->ID, $args );
150
151 1
				/**
152
				 * Fires while outputing donation form, for payment gatways fields.
153 1
				 *
154
				 * @since 1.7
155
				 *
156
				 * @param int   $form_id The form ID.
157
				 * @param array $args    An array of form arguments.
158
				 */
159
				do_action( 'give_donation_mode_select', $form->ID, $args );
160
161
				/**
162
				 * Fires while outputing donation form, after all other fields.
163
				 *
164
				 * @since 1.0
165
				 *
166
				 * @param int   $form_id The form ID.
167
				 * @param array $args    An array of form arguments.
168
				 */
169
				do_action( 'give_checkout_form_bottom', $form->ID, $args );
170
171
				?>
172
			</form>
173 1
174
			<?php
175 1
			/**
176
			 * Fires while outputing donation form, after the form.
177 1
			 *
178 1
			 * @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_post_form', $form->ID, $args );
184
185
		}
186
		?>
187
188
	</div><!--end #give-form-<?php echo absint( $form->ID ); ?>-->
189
	<?php
190
191
	/**
192
	 * Fires while outputing donation form, after the form wapper div.
193
	 *
194
	 * @since 1.0
195
	 *
196
	 * @param int   $form_id The form ID.
197
	 * @param array $args    An array of form arguments.
198
	 */
199 1
	do_action( 'give_post_form_output', $form->ID, $args );
200
201 1
	$final_output = ob_get_clean();
202
203
	echo apply_filters( 'give_donate_form', $final_output, $args );
204
}
205 1
206
/**
207 1
 * Give Show Donation Form.
208
 *
209 1
 * Renders the Donation Form, hooks are provided to add to the checkout form.
210
 * The default Donation Form rendered displays a list of the enabled payment
211 1
 * gateways, a user registration form (if enable) and a credit card info form
212
 * if credit cards are enabled.
213 1
 *
214
 * @since  1.0
215
 *
216 1
 * @param  int    $form_id The form ID.
217 1
 *
218 1
 * @return string
219
 */
220
function give_show_purchase_form( $form_id ) {
221
222 1
	$payment_mode = give_get_chosen_gateway( $form_id );
223
224 1
	if ( ! isset( $form_id ) && isset( $_POST['give_form_id'] ) ) {
225
		$form_id = $_POST['give_form_id'];
226
	}
227
228
	/**
229
	 * Fire before donation form render.
230 1
	 *
231 1
	 * @since 1.7
232
	 */
233
	do_action( 'give_donation_form_top', $form_id );
234
235
	if ( give_can_checkout() && isset( $form_id ) ) {
236
237
		/**
238
		 * Fires while displaying donation form, before registration login.
239
		 *
240
		 * @since 1.7
241
		 */
242
		do_action( 'give_donation_form_before_register_login', $form_id );
243
244
		/**
245
		 * Fire when register/login form fields render.
246
		 *
247 1
		 * @since 1.7
248
		 */
249
		do_action( 'give_donation_form_register_login_fields', $form_id );
250
251
		/**
252
		 * Fire when credit card form fields render.
253
		 *
254
		 * @since 1.7
255
		 */
256
		do_action( 'give_donation_form_before_cc_form', $form_id );
257
258
		// Load the credit card form and allow gateways to load their own if they wish
259
		if ( has_action( 'give_' . $payment_mode . '_cc_form' ) ) {
260
			/**
261
			 * Fires while displaying donation form, credit card form fields for a given gateway.
262 1
			 *
263
			 * @since 1.0
264
			 *
265
			 * @param int $form_id The form ID.
266
			 */
267
			do_action( "give_{$payment_mode}_cc_form", $form_id );
268
		} else {
269
			/**
270
			 * Fires while displaying donation form, credit card form fields.
271
			 *
272
			 * @since 1.0
273
			 *
274
			 * @param int $form_id The form ID.
275
			 */
276
			do_action( 'give_cc_form', $form_id );
277
		}
278
279
		/**
280 1
		 * Fire after credit card form fields render.
281
		 *
282 1
		 * @since 1.7
283 1
		 */
284 1
		do_action( 'give_donation_form_after_cc_form', $form_id );
285 1
286 1
	} else {
287 1
		/**
288 1
		 * Fire if user can not donate.
289
		 *
290 1
		 * @since 1.7
291
		 */
292
		do_action( 'give_donation_form_no_access', $form_id );
293 1
294
	}
295
296
	/**
297
	 * Fire after donation form rendered.
298
	 *
299
	 * @since 1.7
300
	 */
301
	do_action( 'give_donation_form_bottom', $form_id );
302
}
303
304
add_action( 'give_donation_form', 'give_show_purchase_form' );
305
306
/**
307
 * Give Show Login/Register Form Fields.
308
 *
309
 * @since  1.4.1
310
 *
311
 * @param  int  $form_id The form ID.
312
 *
313
 * @return void
314
 */
315 1
function give_show_register_login_fields( $form_id ) {
316
317
	$show_register_form = give_show_login_register_option( $form_id );
318
319
	if ( ( $show_register_form === 'registration' || ( $show_register_form === 'both' && ! isset( $_GET['login'] ) ) ) && ! is_user_logged_in() ) :
320
		?>
321
		<div id="give-checkout-login-register-<?php echo $form_id; ?>">
322
			<?php
323
			/**
324
			 * Fire if user registration form render.
325
			 *
326 1
			 * @since 1.7
327
			 */
328
			do_action( 'give_donation_form_register_fields', $form_id );
329
			?>
330
		</div>
331
		<?php
332
	elseif ( ( $show_register_form === 'login' || ( $show_register_form === 'both' && isset( $_GET['login'] ) ) ) && ! is_user_logged_in() ) :
333
		?>
334 1
		<div id="give-checkout-login-register-<?php echo $form_id; ?>">
335 1
			<?php
336 1
			/**
337
			 * Fire if user login form render.
338 1
			 *
339 1
			 * @since 1.7
340
			 */
341
			do_action( 'give_donation_form_login_fields', $form_id );
342
			?>
343
		</div>
344
		<?php
345
	endif;
346
347
	if ( ( ! isset( $_GET['login'] ) && is_user_logged_in() ) || ! isset( $show_register_form ) || 'none' === $show_register_form || 'login' === $show_register_form ) {
348
		/**
349
		 * Fire when user info render.
350
		 *
351
		 * @since 1.7
352
		 */
353
		do_action( 'give_donation_form_after_user_info', $form_id );
354
	}
355
}
356 1
357 1
add_action( 'give_donation_form_register_login_fields', 'give_show_register_login_fields' );
358 1
359 1
/**
360 1
 * Donation Amount Field.
361 1
 *
362 1
 * 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.
363
 *
364 1
 * @since  1.0
365 1
 *
366
 * @param  int   $form_id The form ID.
367
 * @param  array $args    An array of form arguments.
368 1
 *
369
 * @return void
370 1
 */
371
function give_output_donation_amount_top( $form_id = 0, $args = array() ) {
372 1
373 1
	$give_options        = give_get_settings();
374 1
	$variable_pricing    = give_has_variable_prices( $form_id );
375 1
	$allow_custom_amount = get_post_meta( $form_id, '_give_custom_amount', true );
376
	$currency_position   = isset( $give_options['currency_position'] ) ? $give_options['currency_position'] : 'before';
377 1
	$symbol              = give_currency_symbol( give_get_currency() );
378 1
	$currency_output     = '<span class="give-currency-symbol give-currency-position-' . $currency_position . '">' . $symbol . '</span>';
379 1
	$default_amount      = give_format_amount( give_get_default_form_amount( $form_id ) );
380 1
	$custom_amount_text  = get_post_meta( $form_id, '_give_custom_amount_text', true );
381 1
382
	/**
383 1
	 * Fires while displaying donation form, before donation level fields.
384
	 *
385
	 * @since 1.0
386 1
	 *
387
	 * @param int   $form_id The form ID.
388
	 * @param array $args    An array of form arguments.
389
	 */
390
	do_action( 'give_before_donation_levels', $form_id, $args );
391
392
	//Set Price, No Custom Amount Allowed means hidden price field
393
	if ( $allow_custom_amount == 'no' ) {
394 1
		?>
395
		<label class="give-hidden" for="give-amount-hidden"><?php esc_html_e( 'Donation Amount:', 'give' ); ?></label>
396 1
		<input id="give-amount" class="give-amount-hidden" type="hidden" name="give-amount" value="<?php echo $default_amount; ?>" required>
397
		<div class="set-price give-donation-amount form-row-wide">
398
			<?php if ( $currency_position == 'before' ) {
399
				echo $currency_output;
400
			} ?>
401
			<span id="give-amount-text" class="give-text-input give-amount-top"><?php echo $default_amount; ?></span>
402
			<?php if ( $currency_position == 'after' ) {
403
				echo $currency_output;
404
			} ?>
405
		</div>
406
		<?php
407
	} else {
408
		//Custom Amount Allowed
409
		?>
410
		<div class="give-total-wrap">
411
			<div class="give-donation-amount form-row-wide">
412
				<?php if ( $currency_position == 'before' ) {
413
					echo $currency_output;
414
				} ?>
415
				<label class="give-hidden" for="give-amount"><?php esc_html_e( 'Donation Amount:', 'give' ); ?></label>
416
				<input class="give-text-input give-amount-top" id="give-amount" name="give-amount" type="tel" placeholder="" value="<?php echo $default_amount; ?>" autocomplete="off">
417
				<?php if ( $currency_position == 'after' ) {
418
					echo $currency_output;
419
				} ?>
420
			</div>
421
		</div>
422
	<?php }
423
424
	/**
425
	 * Fires while displaying donation form, after donation amounf field(s).
426
	 *
427
	 * @since 1.0
428
	 *
429
	 * @param int   $form_id The form ID.
430
	 * @param array $args    An array of form arguments.
431
	 */
432
	do_action( 'give_after_donation_amount', $form_id, $args );
433
434
	//Custom Amount Text
435
	if ( ! $variable_pricing && $allow_custom_amount == 'yes' && ! empty( $custom_amount_text ) ) { ?>
436
		<p class="give-custom-amount-text"><?php echo $custom_amount_text; ?></p>
437
	<?php }
438
439
	//Output Variable Pricing Levels
440
	if ( $variable_pricing ) {
441
		give_output_levels( $form_id );
442
	}
443
444
	/**
445
	 * Fires while displaying donation form, after donation level fields.
446
	 *
447
	 * @since 1.0
448
	 *
449
	 * @param int   $form_id The form ID.
450
	 * @param array $args    An array of form arguments.
451
	 */
452 1
	do_action( 'give_after_donation_levels', $form_id, $args );
453 1
}
454
455
add_action( 'give_checkout_form_top', 'give_output_donation_amount_top', 10, 2 );
456
457
/**
458
 * Outputs the Donation Levels in various formats such as dropdown, radios, and buttons.
459
 *
460
 * @since  1.0
461
 *
462
 * @param  int   $form_id The form ID.
463
 *
464
 * @return string Donation levels.
465
 */
466 1
function give_output_levels( $form_id ) {
467 1
468 1
	//Get variable pricing
469
	$prices             = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $form_id ), $form_id );
470
	$display_style      = get_post_meta( $form_id, '_give_display_style', true );
471 1
	$custom_amount      = get_post_meta( $form_id, '_give_custom_amount', true );
472
	$custom_amount_text = get_post_meta( $form_id, '_give_custom_amount_text', true );
473
	if ( empty( $custom_amount_text ) ) {
474
		$custom_amount_text = esc_html__( 'Give a Custom Amount', 'give' );
475 1
	}
476 1
477
	$output  = '';
478 1
	$counter = 0;
479
480 1
	switch ( $display_style ) {
481 1
		case 'buttons':
482
483
			$output .= '<ul id="give-donation-level-button-wrap" class="give-donation-levels-wrap give-list-inline">';
484
485
			foreach ( $prices as $price ) {
486
				$counter ++;
487
				$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 );
488
				$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 );
489
490
				$output .= '<li>';
491
				$output .= '<button type="button" data-price-id="' . $price['_give_id']['level_id'] . '" class=" ' . $level_classes . '" value="' . give_format_amount( $price['_give_amount'] ) . '">';
492
				$output .= $level_text;
493
				$output .= '</button>';
494
				$output .= '</li>';
495
496
			}
497
498
			//Custom Amount
499
			if ( $custom_amount === 'yes' && ! empty( $custom_amount_text ) ) {
500
				$output .= '<li>';
501
				$output .= '<button type="button" data-price-id="custom" class="give-donation-level-btn give-btn give-btn-level-custom" value="custom">';
502
				$output .= $custom_amount_text;
503
				$output .= '</button>';
504
				$output .= '</li>';
505
			}
506
507
			$output .= '</ul>';
508
509
			break;
510
511
		case 'radios':
512
513
			$output .= '<ul id="give-donation-level-radio-list" class="give-donation-levels-wrap">';
514
515
			foreach ( $prices as $price ) {
516
				$counter ++;
517
				$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 );
518
				$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 );
519
520
				$output .= '<li>';
521
				$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'] ) . '">';
522
				$output .= '<label for="give-radio-level-' . $counter . '">' . $level_text . '</label>';
523
				$output .= '</li>';
524
525
			}
526
527
			//Custom Amount
528
			if ( $custom_amount === 'yes' && ! empty( $custom_amount_text ) ) {
529
				$output .= '<li>';
530
				$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">';
531
				$output .= '<label for="give-radio-level-custom">' . $custom_amount_text . '</label>';
532
				$output .= '</li>';
533
			}
534
535
			$output .= '</ul>';
536
537
			break;
538
539
		case 'dropdown':
540
541
			$output .= '<label for="give-donation-level" class="give-hidden">' . esc_html__( 'Choose Your Donation Amount', 'give' ) . ':</label>';
542
			$output .= '<select id="give-donation-level-' . $form_id . '" class="give-select give-select-level give-donation-levels-wrap">';
543
544
			//first loop through prices
545
			foreach ( $prices as $price ) {
546
				$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 );
547
				$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 );
548
549
				$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'] ) . '">';
550
				$output .= $level_text;
551
				$output .= '</option>';
552
553
			}
554
555
			//Custom Amount
556
			if ( $custom_amount === 'yes' && ! empty( $custom_amount_text ) ) {
557
				$output .= '<option data-price-id="custom" class="give-donation-level-custom" value="custom">' . $custom_amount_text . '</option>';
558
			}
559
560
			$output .= '</select>';
561
562
			break;
563
	}
564
565
	echo apply_filters( 'give_form_level_output', $output, $form_id );
566
}
567
568
/**
569
 * Display Reveal & Lightbox Button.
570
 *
571
 * Outputs a button to reveal form fields.
572
 *
573
 * @since  1.0
574
 *
575
 * @param  int   $form_id The form ID.
576
 * @param  array $args    An array of form arguments.
577
 *
578
 * @return string Checkout button.
579
 */
580
function give_display_checkout_button( $form_id, $args ) {
581
582
	$display_option = ( isset( $args['display_style'] ) && ! empty( $args['display_style'] ) )
583
		? $args['display_style']
584
		: get_post_meta( $form_id, '_give_payment_display', true );
585
586
	//no btn for onpage
587
	if ( $display_option === 'onpage' ) {
588
		return;
589
	}
590
591
	$display_label_field = get_post_meta( $form_id, '_give_reveal_label', true );
592
	$display_label       = ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) );
593
594
	$output = '<button type="button" class="give-btn give-btn-' . $display_option . '">' . $display_label . '</button>';
595
596
	echo apply_filters( 'give_display_checkout_button', $output );
597
}
598
599
add_action( 'give_after_donation_levels', 'give_display_checkout_button', 10, 2 );
600
601
/**
602
 * Shows the User Info fields in the Personal Info box, more fields can be added via the hooks provided.
603
 *
604
 * @since  1.0
605
 *
606
 * @param  int  $form_id The form ID.
607
 *
608
 * @return void
609
 */
610
function give_user_info_fields( $form_id ) {
611
612
	if ( is_user_logged_in() ) :
613
		$user_data = get_userdata( get_current_user_id() );
614
	endif;
615
616
	/**
617
	 * Fire before user personal information fields
618
	 *
619
	 * @since 1.7
620
	 */
621
	do_action( 'give_donation_form_before_personal_info', $form_id );
622
	?>
623
	<fieldset id="give_checkout_user_info">
624
		<legend><?php echo apply_filters( 'give_checkout_personal_info_text', esc_html__( 'Personal Info', 'give' ) ); ?></legend>
625
		<p id="give-first-name-wrap" class="form-row form-row-first">
626
			<label class="give-label" for="give-first">
627
				<?php esc_html_e( 'First Name', 'give' ); ?>
628
				<?php if ( give_field_is_required( 'give_first', $form_id ) ) { ?>
629
					<span class="give-required-indicator">*</span>
630
				<?php } ?>
631
				<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_attr_e( 'We will use this to personalize your account experience.', 'give' ); ?>"></span>
632
			</label>
633
			<input class="give-input required" type="text" name="give_first" placeholder="<?php esc_attr_e( 'First Name', 'give' ); ?>" id="give-first" value="<?php echo is_user_logged_in() ? $user_data->first_name : ''; ?>"<?php if ( give_field_is_required( 'give_first', $form_id ) ) {
0 ignored issues
show
Bug introduced by
The variable $user_data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
634
				echo ' required ';
635
			} ?>/>
636
		</p>
637
638
		<p id="give-last-name-wrap" class="form-row form-row-last">
639
			<label class="give-label" for="give-last">
640
				<?php esc_html_e( 'Last Name', 'give' ); ?>
641
				<?php if ( give_field_is_required( 'give_last', $form_id ) ) { ?>
642
					<span class="give-required-indicator">*</span>
643
				<?php } ?>
644
				<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_attr_e( 'We will use this as well to personalize your account experience.', 'give' ); ?>"></span>
645
			</label>
646
647
			<input class="give-input<?php if ( give_field_is_required( 'give_last', $form_id ) ) {
648
				echo ' required';
649
			} ?>" type="text" name="give_last" id="give-last" placeholder="<?php esc_attr_e( 'Last Name', 'give' ); ?>" value="<?php echo is_user_logged_in() ? $user_data->last_name : ''; ?>"<?php if ( give_field_is_required( 'give_last', $form_id ) ) {
650
				echo ' required ';
651
			} ?> />
652
		</p>
653
654
		<?php
655
		/**
656
		 * Fire before user email field
657
		 *
658
		 * @since 1.7
659
		 */
660
		do_action( 'give_donation_form_before_email', $form_id );
661
		?>
662
		<p id="give-email-wrap" class="form-row form-row-wide">
663
			<label class="give-label" for="give-email">
664
				<?php esc_html_e( 'Email Address', 'give' ); ?>
665
				<?php if ( give_field_is_required( 'give_email', $form_id ) ) { ?>
666
					<span class="give-required-indicator">*</span>
667
				<?php } ?>
668
				<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_attr_e( 'We will send the donation receipt to this address.', 'give' ); ?>"></span>
669
			</label>
670
671
			<input class="give-input required" type="email" name="give_email" placeholder="<?php esc_attr_e( 'Email Address', 'give' ); ?>" id="give-email" value="<?php echo is_user_logged_in() ? $user_data->user_email : ''; ?>"<?php if ( give_field_is_required( 'give_email', $form_id ) ) {
672
				echo ' required ';
673
			} ?>/>
674
675
		</p>
676
		<?php
677
		/**
678
		 * Fire after user email field
679
		 *
680
		 * @since 1.7
681
		 */
682
		do_action( 'give_donation_form_after_email', $form_id );
683
684
		/**
685
		 * Fire after personal email field
686
		 *
687
		 * @since 1.7
688
		 */
689
		do_action( 'give_donation_form_user_info', $form_id );
690
		?>
691
	</fieldset>
692
	<?php
693
	/**
694
	 * Fire after user personal information fields
695
	 *
696
	 * @since 1.7
697
	 */
698
	do_action( 'give_donation_form_after_personal_info', $form_id );
699
}
700
701
add_action( 'give_donation_form_after_user_info', 'give_user_info_fields' );
702
add_action( 'give_register_fields_before', 'give_user_info_fields' );
703
704
/**
705
 * Renders the credit card info form.
706
 *
707
 * @since  1.0
708
 *
709
 * @param  int  $form_id The form ID.
710
 *
711
 * @return void
712
 */
713
function give_get_cc_form( $form_id ) {
714
715
	ob_start();
716
717
	/**
718
	 * Fires while rendering credit card info form, before the fields.
719
	 *
720
	 * @since 1.0
721
	 *
722
	 * @param int $form_id The form ID.
723
	 */
724
	do_action( 'give_before_cc_fields', $form_id );
725
	?>
726
	<fieldset id="give_cc_fields-<?php echo $form_id ?>" class="give-do-validate">
727
		<legend><?php echo apply_filters( 'give_credit_card_fieldset_heading', esc_html__( 'Credit Card Info', 'give' ) ); ?></legend>
728
		<?php if ( is_ssl() ) : ?>
729
			<div id="give_secure_site_wrapper-<?php echo $form_id ?>">
730
				<span class="give-icon padlock"></span>
731
				<span><?php esc_html_e( 'This is a secure SSL encrypted payment.', 'give' ); ?></span>
732
			</div>
733
		<?php endif; ?>
734
		<p id="give-card-number-wrap-<?php echo $form_id ?>" class="form-row form-row-two-thirds">
735
			<label for="card_number-<?php echo $form_id ?>" class="give-label">
736
				<?php esc_html_e( 'Card Number', 'give' ); ?>
737
				<span class="give-required-indicator">*</span>
738
				<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_attr_e( 'The (typically) 16 digits on the front of your credit card.', 'give' ); ?>"></span>
739
				<span class="card-type"></span>
740
			</label>
741
742
			<input type="tel" autocomplete="off" name="card_number" id="card_number-<?php echo $form_id ?>" class="card-number give-input required" placeholder="<?php esc_attr_e( 'Card number', 'give' ); ?>" required/>
743
		</p>
744
745
		<p id="give-card-cvc-wrap-<?php echo $form_id ?>" class="form-row form-row-one-third">
746
			<label for="card_cvc-<?php echo $form_id ?>" class="give-label">
747
				<?php esc_html_e( 'CVC', 'give' ); ?>
748
				<span class="give-required-indicator">*</span>
749
				<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_attr_e( 'The 3 digit (back) or 4 digit (front) value on your card.', 'give' ); ?>"></span>
750
			</label>
751
752
			<input type="tel" size="4" autocomplete="off" name="card_cvc" id="card_cvc-<?php echo $form_id ?>" class="card-cvc give-input required" placeholder="<?php esc_attr_e( 'Security code', 'give' ); ?>" required/>
753
		</p>
754
755
		<p id="give-card-name-wrap-<?php echo $form_id ?>" class="form-row form-row-two-thirds">
756
			<label for="card_name-<?php echo $form_id ?>" class="give-label">
757
				<?php esc_html_e( 'Name on the Card', 'give' ); ?>
758
				<span class="give-required-indicator">*</span>
759
				<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_attr_e( 'The name printed on the front of your credit card.', 'give' ); ?>"></span>
760
			</label>
761
762
			<input type="text" autocomplete="off" name="card_name" id="card_name-<?php echo $form_id ?>" class="card-name give-input required" placeholder="<?php esc_attr_e( 'Card name', 'give' ); ?>" required/>
763
		</p>
764
		<?php
765
		/**
766
		 * Fires while rendering credit card info form, before expiration fields.
767
		 *
768
		 * @since 1.0
769
		 *
770
		 * @param int $form_id The form ID.
771
		 */
772
		do_action( 'give_before_cc_expiration' );
773
		?>
774
		<p class="card-expiration form-row form-row-one-third">
775
			<label for="card_expiry-<?php echo $form_id ?>" class="give-label">
776
				<?php esc_html_e( 'Expiration', 'give' ); ?>
777
				<span class="give-required-indicator">*</span>
778
				<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_attr_e( 'The date your credit card expires, typically on the front of the card.', 'give' ); ?>"></span>
779
			</label>
780
781
			<input type="hidden" id="card_exp_month-<?php echo $form_id ?>" name="card_exp_month" class="card-expiry-month"/>
782
			<input type="hidden" id="card_exp_year-<?php echo $form_id ?>" name="card_exp_year" class="card-expiry-year"/>
783
784
			<input type="tel" autocomplete="off" name="card_expiry" id="card_expiry-<?php echo $form_id ?>" class="card-expiry give-input required" placeholder="<?php esc_attr_e( 'MM / YY', 'give' ); ?>" required/>
785
		</p>
786
		<?php
787
		/**
788
		 * Fires while rendering credit card info form, after expiration fields.
789
		 *
790
		 * @since 1.0
791
		 *
792
		 * @param int $form_id The form ID.
793
		 */
794
		do_action( 'give_after_cc_expiration', $form_id );
795
		?>
796
	</fieldset>
797
	<?php
798
	/**
799
	 * Fires while rendering credit card info form, before the fields.
800
	 *
801
	 * @since 1.0
802
	 *
803
	 * @param int $form_id The form ID.
804
	 */
805
	do_action( 'give_after_cc_fields', $form_id );
806
807
	echo ob_get_clean();
808
}
809
810
add_action( 'give_cc_form', 'give_get_cc_form' );
811
812
/**
813
 * Outputs the default credit card address fields.
814
 *
815
 * @since  1.0
816
 *
817
 * @param  int  $form_id The form ID.
818
 *
819
 * @return void
820
 */
821
function give_default_cc_address_fields( $form_id ) {
822
823
	$logged_in = is_user_logged_in();
824
825
	if ( $logged_in ) {
826
		$user_address = get_user_meta( get_current_user_id(), '_give_user_address', true );
827
	}
828
	$line1 = $logged_in && ! empty( $user_address['line1'] ) ? $user_address['line1'] : '';
829
	$line2 = $logged_in && ! empty( $user_address['line2'] ) ? $user_address['line2'] : '';
830
	$city  = $logged_in && ! empty( $user_address['city'] ) ? $user_address['city'] : '';
831
	$zip   = $logged_in && ! empty( $user_address['zip'] ) ? $user_address['zip'] : '';
832
833
	ob_start();
834
	?>
835
	<fieldset id="give_cc_address" class="cc-address">
836
		<legend><?php echo apply_filters( 'give_billing_details_fieldset_heading', esc_html__( 'Billing Details', 'give' ) ); ?></legend>
837
		<?php
838
		/**
839
		 * Fires while rendering credit card billing form, before address fields.
840
		 *
841
		 * @since 1.0
842
		 *
843
		 * @param int $form_id The form ID.
844
		 */
845
		do_action( 'give_cc_billing_top' );
846
		?>
847
		<p id="give-card-address-wrap" class="form-row form-row-two-thirds">
848
			<label for="card_address" class="give-label">
849
				<?php esc_html_e( 'Address 1', 'give' ); ?>
850
				<?php
851
				if ( give_field_is_required( 'card_address', $form_id ) ) { ?>
852
					<span class="give-required-indicator">*</span>
853
				<?php } ?>
854
				<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_attr_e( 'The primary billing address for your credit card.', 'give' ); ?>"></span>
855
			</label>
856
857
			<input type="text" id="card_address" name="card_address" class="card-address give-input<?php if ( give_field_is_required( 'card_address', $form_id ) ) {
858
				echo ' required';
859
			} ?>" placeholder="<?php esc_attr_e( 'Address line 1', 'give' ); ?>" value="<?php echo $line1; ?>"<?php if ( give_field_is_required( 'card_address', $form_id ) ) {
860
				echo '  required ';
861
			} ?>/>
862
		</p>
863
864
		<p id="give-card-address-2-wrap" class="form-row form-row-one-third">
865
			<label for="card_address_2" class="give-label">
866
				<?php esc_html_e( 'Address 2', 'give' ); ?>
867
				<?php if ( give_field_is_required( 'card_address_2', $form_id ) ) { ?>
868
					<span class="give-required-indicator">*</span>
869
				<?php } ?>
870
				<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_attr_e( '(optional) The suite, apt no, PO box, etc, associated with your billing address.', 'give' ); ?>"></span>
871
			</label>
872
873
			<input type="text" id="card_address_2" name="card_address_2" class="card-address-2 give-input<?php if ( give_field_is_required( 'card_address_2', $form_id ) ) {
874
				echo ' required';
875
			} ?>" placeholder="<?php esc_attr_e( 'Address line 2', 'give' ); ?>" value="<?php echo $line2; ?>"<?php if ( give_field_is_required( 'card_address_2', $form_id ) ) {
876
				echo ' required ';
877
			} ?>/>
878
		</p>
879
880
		<p id="give-card-city-wrap" class="form-row form-row-two-thirds">
881
			<label for="card_city" class="give-label">
882
				<?php esc_html_e( 'City', 'give' ); ?>
883
				<?php if ( give_field_is_required( 'card_city', $form_id ) ) { ?>
884
					<span class="give-required-indicator">*</span>
885
				<?php } ?>
886
				<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_attr_e( 'The city for your billing address.', 'give' ); ?>"></span>
887
			</label>
888
			<input type="text" id="card_city" name="card_city" class="card-city give-input<?php if ( give_field_is_required( 'card_city', $form_id ) ) {
889
				echo ' required';
890
			} ?>" placeholder="<?php esc_attr_e( 'City', 'give' ); ?>" value="<?php echo $city; ?>"<?php if ( give_field_is_required( 'card_city', $form_id ) ) {
891
				echo ' required ';
892
			} ?>/>
893
		</p>
894
895
		<p id="give-card-zip-wrap" class="form-row form-row-one-third">
896
			<label for="card_zip" class="give-label">
897
				<?php esc_html_e( 'Zip / Postal Code', 'give' ); ?>
898
				<?php if ( give_field_is_required( 'card_zip', $form_id ) ) { ?>
899
					<span class="give-required-indicator">*</span>
900
				<?php } ?>
901
				<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_attr_e( 'The zip or postal code for your billing address.', 'give' ); ?>"></span>
902
			</label>
903
904
			<input type="text" size="4" id="card_zip" name="card_zip" class="card-zip give-input<?php if ( give_field_is_required( 'card_zip', $form_id ) ) {
905
				echo ' required';
906
			} ?>" placeholder="<?php esc_attr_e( 'Zip / Postal Code', 'give' ); ?>" value="<?php echo $zip; ?>" <?php if ( give_field_is_required( 'card_zip', $form_id ) ) {
907
				echo ' required ';
908
			} ?>/>
909
		</p>
910
911
		<p id="give-card-country-wrap" class="form-row form-row-first">
912
			<label for="billing_country" class="give-label">
913
				<?php esc_html_e( 'Country', 'give' ); ?>
914
				<?php if ( give_field_is_required( 'billing_country', $form_id ) ) { ?>
915
					<span class="give-required-indicator">*</span>
916
				<?php } ?>
917
				<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_attr_e( 'The country for your billing address.', 'give' ); ?>"></span>
918
			</label>
919
920
			<select name="billing_country" id="billing_country" class="billing-country billing_country give-select<?php if ( give_field_is_required( 'billing_country', $form_id ) ) {
921
				echo ' required';
922
			} ?>"<?php if ( give_field_is_required( 'billing_country', $form_id ) ) {
923
				echo ' required ';
924
			} ?>>
925
				<?php
926
927
				$selected_country = give_get_country();
928
929
				if ( $logged_in && ! empty( $user_address['country'] ) && '*' !== $user_address['country'] ) {
930
					$selected_country = $user_address['country'];
931
				}
932
933
				$countries = give_get_country_list();
934
				foreach ( $countries as $country_code => $country ) {
935
					echo '<option value="' . esc_attr( $country_code ) . '"' . selected( $country_code, $selected_country, false ) . '>' . $country . '</option>';
936
				}
937
				?>
938
			</select>
939
		</p>
940
941
		<p id="give-card-state-wrap" class="form-row form-row-last">
942
			<label for="card_state" class="give-label">
943
				<?php esc_html_e( 'State / Province', 'give' ); ?>
944
				<?php if ( give_field_is_required( 'card_state', $form_id ) ) { ?>
945
					<span class="give-required-indicator">*</span>
946
				<?php } ?>
947
				<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_attr_e( 'The state or province for your billing address.', 'give' ); ?>"></span>
948
			</label>
949
950
			<?php
951
			$selected_state = give_get_state();
952
			$states         = give_get_states( $selected_country );
953
954
			if ( $logged_in && ! empty( $user_address['state'] ) ) {
955
				$selected_state = $user_address['state'];
956
			}
957
958
			if ( ! empty( $states ) ) {
959
				?>
960
				<select name="card_state" id="card_state" class="card_state give-select<?php if ( give_field_is_required( 'card_state', $form_id ) ) {
961
					echo ' required';
962
				} ?>"<?php if ( give_field_is_required( 'card_state', $form_id ) ) {
963
					echo ' required ';
964
				} ?>>
965
					<?php
966
					foreach ( $states as $state_code => $state ) {
967
						echo '<option value="' . $state_code . '"' . selected( $state_code, $selected_state, false ) . '>' . $state . '</option>';
968
					}
969
					?>
970
				</select>
971
				<?php
972
			} else {
973
				?>
974
				<input type="text" size="6" name="card_state" id="card_state" class="card_state give-input" placeholder="<?php esc_attr_e( 'State / Province', 'give' ); ?>"/>
975
				<?php
976
			}
977
			?>
978
		</p>
979
		<?php
980
		/**
981
		 * Fires while rendering credit card billing form, after address fields.
982
		 *
983
		 * @since 1.0
984
		 *
985
		 * @param int $form_id The form ID.
986
		 */
987
		do_action( 'give_cc_billing_bottom' );
988
		?>
989
	</fieldset>
990
	<?php
991
	echo ob_get_clean();
992
}
993
994
add_action( 'give_after_cc_fields', 'give_default_cc_address_fields' );
995 1
996
997
/**
998
 * 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.
999
 *
1000
 * @since  1.0
1001
 *
1002
 * @param  int   $form_id The form ID.
1003
 *
1004
 * @return string
1005
 */
1006
function give_get_register_fields( $form_id ) {
1007
1008
	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...
1009
1010
	if ( is_user_logged_in() ) {
1011 1
		$user_data = get_userdata( $user_ID );
1012 1
	}
1013 1
1014 1
	$show_register_form = give_show_login_register_option( $form_id );
1015 1
1016
	ob_start(); ?>
1017
	<fieldset id="give-register-fields-<?php echo $form_id; ?>">
1018
1019
		<?php if ( $show_register_form == 'both' ) { ?>
1020
			<div class="give-login-account-wrap">
1021
				<p class="give-login-message"><?php esc_html_e( 'Already have an account?', 'give' ); ?>&nbsp;
1022
					<a href="<?php echo esc_url( add_query_arg( 'login', 1 ) ); ?>" class="give-checkout-login" data-action="give_checkout_login"><?php esc_html_e( 'Login', 'give' ); ?></a>
1023
				</p>
1024
				<p class="give-loading-text">
1025
					<span class="give-loading-animation"></span> <?php esc_html_e( 'Loading...', 'give' ); ?></p>
1026
			</div>
1027
		<?php } ?>
1028
1029
		<?php
1030
		/**
1031
		 * Fires while rendering user registration form, before registration fields.
1032
		 *
1033 1
		 * @since 1.0
1034
		 *
1035
		 * @param int $form_id The form ID.
1036
		 */
1037
		do_action( 'give_register_fields_before', $form_id );
1038
		?>
1039
1040
		<fieldset id="give-register-account-fields-<?php echo $form_id; ?>">
1041
			<legend>
1042
				<?php
1043
				echo apply_filters( 'give_create_account_fieldset_heading', esc_html__( 'Create an account', 'give' ) );
1044
				if ( ! give_logged_in_only( $form_id ) ) {
1045
					echo ' <span class="sub-text">' . esc_html__( '(optional)', 'give' ) . '</span>';
1046
				}
1047
				?>
1048
			</legend>
1049
			<?php
1050
			/**
1051
			 * Fires while rendering user registration form, before account fields.
1052 1
			 *
1053 1
			 * @since 1.0
1054 1
			 *
1055
			 * @param int $form_id The form ID.
1056
			 */
1057
			do_action( 'give_register_account_fields_before', $form_id );
1058
			?>
1059
			<div id="give-user-login-wrap-<?php echo $form_id; ?>" class="form-row form-row-one-third form-row-first">
1060
				<label for="give-user-login-<?php echo $form_id; ?>">
1061
					<?php esc_html_e( 'Username', 'give' ); ?>
1062
					<?php if ( give_logged_in_only( $form_id ) ) { ?>
1063
						<span class="give-required-indicator">*</span>
1064
					<?php } ?>
1065
					<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_attr_e( 'The username you will use to log into your account.', 'give' ); ?>"></span>
1066
				</label>
1067
1068
				<input name="give_user_login" id="give-user-login-<?php echo $form_id; ?>" class="give-input" type="text" placeholder="<?php esc_attr_e( 'Username', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required ' : ''; ?>/>
1069
			</div>
1070
1071
			<div id="give-user-pass-wrap-<?php echo $form_id; ?>" class="form-row form-row-one-third">
1072
				<label for="give-user-pass-<?php echo $form_id; ?>">
1073
					<?php esc_html_e( 'Password', 'give' ); ?>
1074
					<?php if ( give_logged_in_only( $form_id ) ) { ?>
1075
						<span class="give-required-indicator">*</span>
1076
					<?php } ?>
1077 1
					<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_attr_e( 'The password used to access your account.', 'give' ); ?>"></span>
1078
				</label>
1079
1080
				<input name="give_user_pass" id="give-user-pass-<?php echo $form_id; ?>" class="give-input" placeholder="<?php esc_attr_e( 'Password', 'give' ); ?>" type="password"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required ' : ''; ?>/>
1081
			</div>
1082
1083
			<div id="give-user-pass-confirm-wrap-<?php echo $form_id; ?>" class="give-register-password form-row form-row-one-third">
1084
				<label for="give-user-pass-confirm-<?php echo $form_id; ?>">
1085
					<?php esc_html_e( 'Confirm PW', 'give' ); ?>
1086
					<?php if ( give_logged_in_only( $form_id ) ) { ?>
1087
						<span class="give-required-indicator">*</span>
1088
					<?php } ?>
1089
					<span class="give-tooltip give-icon give-icon-question" data-tooltip="<?php esc_attr_e( 'Please retype your password to confirm.', 'give' ); ?>"></span>
1090
				</label>
1091
1092
				<input name="give_user_pass_confirm" id="give-user-pass-confirm-<?php echo $form_id; ?>" class="give-input" placeholder="<?php esc_attr_e( 'Confirm password', 'give' ); ?>" type="password"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required ' : ''; ?>/>
1093 1
			</div>
1094
			<?php
1095
			/**
1096
			 * Fires while rendering user registration form, after account fields.
1097 1
			 *
1098
			 * @since 1.0
1099
			 *
1100 1
			 * @param int $form_id The form ID.
1101
			 */
1102
			do_action( 'give_register_account_fields_after', $form_id );
1103
			?>
1104
		</fieldset>
1105
1106
		<?php
1107
		/**
1108
		 * Fires while rendering user registration form, after registration fields.
1109 1
		 *
1110
		 * @since 1.0
1111
		 *
1112
		 * @param int $form_id The form ID.
1113
		 */
1114
		do_action( 'give_register_fields_after', $form_id );
1115
		?>
1116
1117
		<input type="hidden" name="give-purchase-var" value="needs-to-register"/>
1118
1119
		<?php
1120
		/**
1121
		 * Fire after register or login form render
1122
		 *
1123
		 * @since 1.7
1124
		 */
1125
		do_action( 'give_donation_form_user_info', $form_id );
1126
		?>
1127
1128
	</fieldset>
1129
	<?php
1130
	echo ob_get_clean();
1131
}
1132
1133
add_action( 'give_purchase_form_register_fields', 'give_get_register_fields' );
1134
1135
/**
1136 1
 * Gets the login fields for the login form on the checkout. This function hooks
1137
 * on the give_purchase_form_login_fields to display the login form if a user already
1138
 * had an account.
1139
 *
1140
 * @since  1.0
1141
 *
1142
 * @param  int   $form_id The form ID.
1143
 *
1144
 * @return string
1145
 */
1146
function give_get_login_fields( $form_id ) {
1147
1148
	$form_id            = isset( $_POST['form_id'] ) ? $_POST['form_id'] : $form_id;
1149
	$show_register_form = give_show_login_register_option( $form_id );
1150
1151
	ob_start();
1152
	?>
1153 1
	<fieldset id="give-login-fields-<?php echo $form_id; ?>">
1154 1
		<legend><?php echo apply_filters( 'give_account_login_fieldset_heading', esc_html__( 'Login to Your Account', 'give' ) );
1155
			if ( ! give_logged_in_only( $form_id ) ) {
1156
				echo ' <span class="sub-text">' . esc_html__( '(optional)', 'give' ) . '</span>';
1157
			} ?>
1158
		</legend>
1159
		<?php if ( $show_register_form == 'both' ) { ?>
1160
			<p class="give-new-account-link">
1161 1
				<?php esc_html_e( 'Need to create an account?', 'give' ); ?>&nbsp;
1162
				<a href="<?php echo remove_query_arg( 'login' ); ?>" class="give-checkout-register-cancel" data-action="give_checkout_register">
1163
					<?php esc_html_e( 'Register', 'give' );
1164
					if ( ! give_logged_in_only( $form_id ) ) {
1165
						echo ' ' . esc_html__( 'or checkout as a guest &raquo;', 'give' );
1166
					} ?>
1167
				</a>
1168
			</p>
1169
			<p class="give-loading-text">
1170
				<span class="give-loading-animation"></span> <?php esc_html_e( 'Loading...', 'give' ); ?> </p>
1171
		<?php } ?>
1172
		<?php
1173
		/**
1174
		 * Fires while rendering checkout login form, before the fields.
1175
		 *
1176 1
		 * @since 1.0
1177
		 *
1178 1
		 * @param int $form_id The form ID.
1179
		 */
1180
		do_action( 'give_checkout_login_fields_before', $form_id );
1181
		?>
1182
		<div id="give-user-login-wrap-<?php echo $form_id; ?>" class="form-row form-row-first">
1183
			<label class="give-label" for="give-user-login-<?php echo $form_id; ?>">
1184
				<?php esc_html_e( 'Username', 'give' ); ?>
1185
				<?php if ( give_logged_in_only( $form_id ) ) { ?>
1186
					<span class="give-required-indicator">*</span>
1187
				<?php } ?>
1188
			</label>
1189
1190
			<input class="<?php if ( give_logged_in_only( $form_id ) ) {
1191
				echo 'required ';
1192 1
			} ?>give-input" type="text" name="give_user_login" id="give-user-login-<?php echo $form_id; ?>" value="" placeholder="<?php esc_attr_e( 'Your username', 'give' ); ?>"/>
1193
		</div>
1194
1195
		<div id="give-user-pass-wrap-<?php echo $form_id; ?>" class="give_login_password form-row form-row-last">
1196
			<label class="give-label" for="give-user-pass-<?php echo $form_id; ?>">
1197
				<?php esc_html_e( 'Password', 'give' ); ?>
1198
				<?php if ( give_logged_in_only( $form_id ) ) { ?>
1199
					<span class="give-required-indicator">*</span>
1200
				<?php } ?>
1201
			</label>
1202
			<input class="<?php if ( give_logged_in_only( $form_id ) ) {
1203
				echo 'required ';
1204
			} ?>give-input" type="password" name="give_user_pass" id="give-user-pass-<?php echo $form_id; ?>" placeholder="<?php esc_attr_e( 'Your password', 'give' ); ?>"/>
1205
			<input type="hidden" name="give-purchase-var" value="needs-to-login"/>
1206
		</div>
1207
1208
		<div id="give-forgot-password-wrap-<?php echo $form_id; ?>" class="give_login_forgot_password">
1209 1
			 <span class="give-forgot-password ">
1210 1
				 <a href="<?php echo wp_lostpassword_url() ?>" target="_blank"><?php esc_html_e( 'Reset Password', 'give' ) ?></a>
1211 1
			 </span>
1212 1
		</div>
1213 1
1214 1
		<div id="give-user-login-submit-<?php echo $form_id; ?>" class="give-clearfix">
1215 1
			<input type="submit" class="give-submit give-btn button" name="give_login_submit" value="<?php esc_attr_e( 'Login', 'give' ); ?>"/>
1216 1
			<?php if ( $show_register_form !== 'login' ) { ?>
1217
				<input type="button" data-action="give_cancel_login" class="give-cancel-login give-checkout-register-cancel give-btn button" name="give_login_cancel" value="<?php esc_attr_e( 'Cancel', 'give' ); ?>"/>
1218
			<?php } ?>
1219 1
			<span class="give-loading-animation"></span>
1220
		</div>
1221
		<?php
1222
		/**
1223
		 * Fires while rendering checkout login form, after the fields.
1224 1
		 *
1225 1
		 * @since 1.0
1226 1
		 *
1227 1
		 * @param int $form_id The form ID.
1228 1
		 */
1229
		do_action( 'give_checkout_login_fields_after', $form_id );
1230 1
		?>
1231
	</fieldset><!--end #give-login-fields-->
1232
	<?php
1233
	echo ob_get_clean();
1234
}
1235
1236
add_action( 'give_purchase_form_login_fields', 'give_get_login_fields', 10, 1 );
1237
1238
/**
1239
 * Payment Mode Select.
1240
 *
1241
 * Renders the payment mode form by getting all the enabled payment gateways and
1242
 * outputting them as radio buttons for the user to choose the payment gateway. If
1243
 * a default payment gateway has been chosen from the Give Settings, it will be
1244
 * automatically selected.
1245
 *
1246
 * @since  1.0
1247
 *
1248
 * @param  int  $form_id The form ID.
1249
 *
1250
 * @return void
1251
 */
1252
function give_payment_mode_select( $form_id ) {
1253
1254
	$gateways = give_get_enabled_payment_gateways();
1255
1256
	/**
1257
	 * Fires while selecting payment gateways, before the fields.
1258
	 *
1259
	 * @since 1.7
1260
	 *
1261
	 * @param int $form_id The form ID.
1262
	 */
1263
	do_action( 'give_donation_mode_top', $form_id ); ?>
1264
1265
	<fieldset id="give-payment-mode-select">
1266
		<?php
1267
		/**
1268
		 * Fires while selecting payment gateways, before the wrap div.
1269
		 *
1270
		 * @since 1.7
1271
		 *
1272
		 * @param int $form_id The form ID.
1273
		 */
1274
		do_action( 'give_donation_mode_before_gateways_wrap' );
1275
		?>
1276
		<div id="give-payment-mode-wrap">
1277
			<legend class="give-payment-mode-label"><?php echo apply_filters( 'give_checkout_payment_method_text', esc_html__( 'Select Payment Method', 'give' ) ); ?>
1278
				<span class="give-loading-text"><span class="give-loading-animation"></span> <?php esc_html_e( 'Loading...', 'give' ); ?></span>
1279
			</legend>
1280
			<?php
1281
			/**
1282
			 * Fires while selecting payment gateways, befire the gateways list.
1283
			 *
1284
			 * @since 1.7
1285
			 */
1286
			do_action( 'give_donation_mode_before_gateways' )
1287
			?>
1288
			<ul id="give-gateway-radio-list">
1289
				<?php foreach ( $gateways as $gateway_id => $gateway ) :
1290
					$checked       = checked( $gateway_id, give_get_default_gateway( $form_id ), false );
1291
					$checked_class = $checked ? ' give-gateway-option-selected' : '';
1292
					echo '<li><label for="give-gateway-' . esc_attr( $gateway_id ) . '-' . $form_id . '" class="give-gateway-option' . $checked_class . '" id="give-gateway-option-' . esc_attr( $gateway_id ) . '">';
1293
					echo '<input type="radio" name="payment-mode" class="give-gateway" id="give-gateway-' . esc_attr( $gateway_id ) . '-' . $form_id . '" value="' . esc_attr( $gateway_id ) . '"' . $checked . '>' . esc_html( $gateway['checkout_label'] );
1294
					echo '</label></li>';
1295
				endforeach; ?>
1296
			</ul>
1297
			<?php
1298
			/**
1299
			 * Fires while selecting payment gateways, befire the gateways list.
1300
			 *
1301
			 * @since 1.7
1302 1
			 */
1303 1
			do_action( 'give_donation_mode_after_gateways' );
1304 1
			?>
1305
		</div>
1306 1
		<?php
1307
		/**
1308 1
		 * Fires while selecting payment gateways, after the wrap div.
1309 1
		 *
1310 1
		 * @since 1.7
1311
		 *
1312
		 * @param int $form_id The form ID.
1313
		 */
1314
		do_action( 'give_donation_mode_after_gateways_wrap' );
1315
		?>
1316
	</fieldset>
1317
1318
	<?php
1319
	/**
1320
	 * Fires while selecting payment gateways, after the fields.
1321
	 *
1322
	 * @since 1.7
1323
	 *
1324
	 * @param int $form_id The form ID.
1325
	 */
1326
	do_action( 'give_donation_mode_bottom', $form_id );
1327
	?>
1328
1329
	<div id="give_purchase_form_wrap">
1330
1331
		<?php
1332
		/**
1333
		 * Fire after payment field render.
1334
		 *
1335
		 * @since 1.7
1336
		 */
1337
		do_action( 'give_donation_form', $form_id );
1338
		?>
1339
1340
	</div>
1341
1342
	<?php
1343
	/**
1344
	 * Fire after donation form render.
1345
	 *
1346
	 * @since 1.7
1347
	 */
1348
	do_action( 'give_donation_form_wrap_bottom', $form_id );
1349
}
1350
1351
add_action( 'give_payment_mode_select', 'give_payment_mode_select' );
1352
1353
/**
1354
 * Renders the Checkout Agree to Terms, this displays a checkbox for users to
1355
 * agree the T&Cs set in the Give Settings. This is only displayed if T&Cs are
1356 1
 * set in the Give Settings.
1357
 *
1358
 * @since  1.0
1359
 *
1360
 * @param  int  $form_id The form ID.
1361
 *
1362
 * @return void|bool
1363 1
 */
1364
function give_terms_agreement( $form_id ) {
1365 1
	$form_option = get_post_meta( $form_id, '_give_terms_option', true );
1366
1367
	// Bailout if per form and global term and conditions is not setup
1368
	if( 'yes' !== $form_option ) {
1369
		return false;
1370
	}
1371
1372
	// Set term and conditions label and text on basis of per form and global setting.
1373
	$label = ( $label = get_post_meta( $form_id, '_give_agree_label', true ) ) ? stripslashes( $label ) : give_get_option( 'agree_to_terms_label', esc_html__( 'Agree to Terms?', 'give' ) );
1374
	$terms = ( $terms = get_post_meta( $form_id, '_give_agree_text', true ) ) ? $terms : give_get_option( 'agreement_text', '' );
1375
1376
	// Bailout: Check if term and conditions text is empty or not.
1377
	if( empty( $terms ) ) {
1378
		if( is_user_logged_in() && current_user_can( 'manage_options' ) ) {
1379
			echo sprintf( __( 'Please enter term and conditions in <a href="%s">this form\'s settings</a>.', 'give' ), admin_url( 'post.php?post=' . $form_id . '&action=edit' ) );
1380
		}
1381
		return false;
1382
	}
1383
1384
	?>
1385
	<fieldset id="give_terms_agreement">
1386
		<div id="give_terms" class= "give_terms-<?php echo $form_id;?>" style="display:none;">
1387
			<?php
1388
			/**
1389
			 * Fires while rendering terms of agreement, before the fields.
1390
			 *
1391
			 * @since 1.0
1392
			 */
1393
			do_action( 'give_before_terms' );
1394
1395
			echo wpautop( stripslashes( $terms ) );
1396
			/**
1397
			 * Fires while rendering terms of agreement, after the fields.
1398
			 *
1399
			 * @since 1.0
1400
			 */
1401
			do_action( 'give_after_terms' );
1402
			?>
1403 1
		</div>
1404
		<div id="give_show_terms">
1405 1
			<a href="#" class="give_terms_links give_terms_links-<?php echo $form_id;?>"><?php esc_html_e( 'Show Terms', 'give' ); ?></a>
1406
			<a href="#" class="give_terms_links give_terms_links-<?php echo $form_id;?>" style="display:none;"><?php esc_html_e( 'Hide Terms', 'give' ); ?></a>
1407
		</div>
1408 1
1409
		<input name="give_agree_to_terms" class="required" type="checkbox" id="give_agree_to_terms" value="1"/>
1410
		<label for="give_agree_to_terms"><?php echo $label; ?></label>
1411
1412
	</fieldset>
1413
	<?php
1414
}
1415
1416
add_action( 'give_donation_form_before_submit', 'give_terms_agreement', 10, 1 );
1417
1418
/**
1419
 * Checkout Final Total.
1420
 *
1421
 * Shows the final donation total at the bottom of the checkout page.
1422 1
 *
1423
 * @since  1.0
1424
 *
1425 1
 * @param  int  $form_id The form ID.
1426
 *
1427
 * @return void
1428
 */
1429
function give_checkout_final_total( $form_id ) {
1430 1
1431
	if ( isset( $_POST['give_total'] ) ) {
1432
		$total = apply_filters( 'give_donation_total', $_POST['give_total'] );
1433
	} else {
1434
		//default total
1435
		$total = give_get_default_form_amount( $form_id );
1436
	}
1437
	//Only proceed if give_total available
1438 1
	if ( empty( $total ) ) {
1439
		return;
1440
	}
1441
	?>
1442
	<p id="give-final-total-wrap" class="form-wrap ">
1443
		<span class="give-donation-total-label"><?php echo apply_filters( 'give_donation_total_label', esc_html__( 'Donation Total:', 'give' ) ); ?></span>
1444
		<span class="give-final-total-amount" data-total="<?php echo give_format_amount( $total ); ?>"><?php echo give_currency_filter( give_format_amount( $total ) ); ?></span>
1445
	</p>
1446
	<?php
1447
}
1448
1449
add_action( 'give_donation_form_before_submit', 'give_checkout_final_total', 999 );
1450
1451
/**
1452
 * Renders the Checkout Submit section.
1453
 *
1454
 * @since  1.0
1455
 *
1456
 * @param  int  $form_id The form ID.
1457
 *
1458
 * @return void
1459
 */
1460
function give_checkout_submit( $form_id ) {
1461
	?>
1462
	<fieldset id="give_purchase_submit">
1463
		<?php
1464
		/**
1465
		 * Fire before donation form submit.
1466
		 *
1467
		 * @since 1.7
1468
		 */
1469
		do_action( 'give_donation_form_before_submit', $form_id );
1470
1471
		give_checkout_hidden_fields( $form_id );
1472
1473
		echo give_checkout_button_purchase( $form_id );
1474
1475
		/**
1476
		 * Fire after donation form submit.
1477
		 *
1478
		 * @since 1.7
1479
		 */
1480
		do_action( 'give_donation_form_after_submit', $form_id );
1481
		?>
1482
	</fieldset>
1483
	<?php
1484
}
1485
1486
add_action( 'give_donation_form_after_cc_form', 'give_checkout_submit', 9999 );
1487
1488
/**
1489
 * Give Checkout Button.
1490
 *
1491
 * Renders the button on the Checkout.
1492
 *
1493
 * @since  1.0
1494
 *
1495
 * @param  int   $form_id The form ID.
1496
 *
1497
 * @return string
1498
 */
1499
function give_checkout_button_purchase( $form_id ) {
1500
1501
	$display_label_field = get_post_meta( $form_id, '_give_checkout_label', true );
1502
	$display_label       = ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) );
1503
	ob_start(); ?>
1504
	<div class="give-submit-button-wrap give-clearfix">
1505
		<input type="submit" class="give-submit give-btn" id="give-purchase-button" name="give-purchase" value="<?php echo $display_label; ?>"/>
1506
		<span class="give-loading-animation"></span>
1507
	</div>
1508
	<?php
1509
	return apply_filters( 'give_checkout_button_purchase', ob_get_clean(), $form_id );
1510
}
1511
1512
/**
1513
 * Give Agree to Terms.
1514
 *
1515
 * Outputs the JavaScript code for the Agree to Terms section to toggle the T&Cs text.
1516
 *
1517
 * @since  1.0
1518
 *
1519
 * @param  int  $form_id The form ID.
1520
 *
1521
 * @return void
1522
 */
1523
function give_agree_to_terms_js( $form_id ) {
1524
1525
	$form_option = get_post_meta( $form_id, '_give_terms_option', true );
1526
1527
	if ( $form_option === 'yes' ) {
1528
		?>
1529
		<script type="text/javascript">
1530
			jQuery(document).ready(function ($) {
1531
				$('body').on('click', '.give_terms_links-<?php echo $form_id;?>', function (e) {
1532
					e.preventDefault();
1533
					$('.give_terms-<?php echo $form_id;?>').slideToggle();
1534
					$('.give_terms_links-<?php echo $form_id;?>').toggle();
1535
					return false;
1536
				});
1537
			});
1538
		</script>
1539
		<?php
1540
	}
1541
}
1542
1543
add_action( 'give_checkout_form_top', 'give_agree_to_terms_js', 10, 2 );
1544
1545
/**
1546
 * Show Give Goals.
1547
 *
1548
 * @since  1.0
1549
 * @since  1.6   Add template for Give Goals Shortcode.
1550
 *               More info is on https://github.com/WordImpress/Give/issues/411
1551
 *
1552
 * @param  int   $form_id The form ID.
1553
 * @param  array $args    An array of form arguments.
1554
 *
1555
 * @return mixed
1556
 */
1557
function give_show_goal_progress( $form_id, $args ) {
1558
1559
    ob_start();
1560
    give_get_template( 'shortcode-goal' , array( 'form_id' => $form_id, 'args' => $args ) );
1561
1562
    echo apply_filters( 'give_goal_output', ob_get_clean() );
1563
1564
	return true;
1565
}
1566
1567
add_action( 'give_pre_form', 'give_show_goal_progress', 10, 2 );
1568
1569
/**
1570
 * Adds Actions to Render Form Content.
1571
 *
1572
 * @since  1.0
1573
 *
1574
 * @param  int   $form_id The form ID.
1575
 * @param  array $args    An array of form arguments.
1576
 *
1577
 * @return void
1578
 */
1579
function give_form_content( $form_id, $args ) {
1580
1581
	$show_content = ( isset( $args['show_content'] ) && ! empty( $args['show_content'] ) )
1582
		? $args['show_content']
1583
		: get_post_meta( $form_id, '_give_content_option', true );
1584
1585
	if ( $show_content !== 'none' ) {
1586
		//add action according to value
1587
		add_action( $show_content, 'give_form_display_content', 10, 2 );
1588
	}
1589
}
1590
1591
add_action( 'give_pre_form_output', 'give_form_content', 10, 2 );
1592
1593
/**
1594
 * Renders Post Form Content.
1595
 *
1596
 * Displays content for Give forms; fired by action from give_form_content.
1597
 *
1598
 * @since  1.0
1599
 *
1600
 * @param  int   $form_id The form ID.
1601
 * @param  array $args    An array of form arguments.
1602
 *
1603
 * @return void
1604
 */
1605
function give_form_display_content( $form_id, $args ) {
1606
1607
	$content      = wpautop( get_post_meta( $form_id, '_give_form_content', true ) );
1608
	$show_content = ( isset( $args['show_content'] ) && ! empty( $args['show_content'] ) )
1609
		? $args['show_content']
1610
		: get_post_meta( $form_id, '_give_content_option', true );
1611
1612
	if ( give_get_option( 'disable_the_content_filter' ) !== 'on' ) {
1613
		$content = apply_filters( 'the_content', $content );
1614
	}
1615
1616
	$output = '<div id="give-form-content-' . $form_id . '" class="give-form-content-wrap" >' . $content . '</div>';
1617
1618
	echo apply_filters( 'give_form_content_output', $output );
1619
1620
	//remove action to prevent content output on addition forms on page
1621
	//@see: https://github.com/WordImpress/Give/issues/634
1622
	remove_action( $show_content, 'give_form_display_content' );
1623
}
1624
1625
/**
1626
 * Renders the hidden Checkout fields.
1627
 *
1628
 * @since 1.0
1629
 *
1630
 * @param  int   $form_id The form ID.
1631
 *
1632
 * @return void
1633
 */
1634
function give_checkout_hidden_fields( $form_id ) {
1635
1636
	/**
1637
	 * Fires while rendering hidden checkout fields, before the fields.
1638
	 *
1639
	 * @since 1.0
1640
	 *
1641
	 * @param int $form_id The form ID.
1642
	 */
1643
	do_action( 'give_hidden_fields_before', $form_id );
1644
1645
	if ( is_user_logged_in() ) { ?>
1646
		<input type="hidden" name="give-user-id" value="<?php echo get_current_user_id(); ?>"/>
1647
	<?php } ?>
1648
	<input type="hidden" name="give_action" value="purchase"/>
1649
	<input type="hidden" name="give-gateway" value="<?php echo give_get_chosen_gateway( $form_id ); ?>"/>
1650
	<?php
1651
	/**
1652
	 * Fires while rendering hidden checkout fields, after the fields.
1653
	 *
1654
	 * @since 1.0
1655
	 *
1656
	 * @param int $form_id The form ID.
1657
	 */
1658
	do_action( 'give_hidden_fields_after', $form_id );
1659
1660
}
1661
1662
/**
1663
 * Filter Success Page Content.
1664
 *
1665
 * Applies filters to the success page content.
1666
 *
1667
 * @since 1.0
1668
 *
1669
 * @param  string $content Content before filters.
1670
 *
1671
 * @return string $content Filtered content.
1672
 */
1673
function give_filter_success_page_content( $content ) {
1674
1675
	$give_options = give_get_settings();
1676
1677
	if ( isset( $give_options['success_page'] ) && isset( $_GET['payment-confirmation'] ) && is_page( $give_options['success_page'] ) ) {
1678
		if ( has_filter( 'give_donation_confirm_' . $_GET['payment-confirmation'] ) ) {
1679
			$content = apply_filters( 'give_donation_confirm_' . $_GET['payment-confirmation'], $content );
1680
		}
1681
	}
1682
1683
	return $content;
1684
}
1685
1686
add_filter( 'the_content', 'give_filter_success_page_content' );
1687
1688
/**
1689
 * Test Mode Frontend Warning.
1690
 *
1691
 * Displays a notice on the frontend for donation forms.
1692
 *
1693
 * @since 1.1
1694
 */
1695
function give_test_mode_frontend_warning() {
1696
1697
	$test_mode = give_get_option( 'test_mode' );
1698
1699
	if ( $test_mode == 'on' ) {
1700
		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>';
1701
	}
1702
}
1703
1704
add_action( 'give_pre_form', 'give_test_mode_frontend_warning', 10 );
1705
1706
/**
1707
 * Members-only Form.
1708
 *
1709
 * If "Disable Guest Donations" and "Display Register / Login" is set to none.
1710
 *
1711
 * @since  1.4.1
1712
 *
1713
 * @param  string $final_output
1714
 * @param  array  $args
1715
 *
1716
 * @return string
1717
 */
1718
function give_members_only_form( $final_output, $args ) {
1719
1720
	$form_id = isset( $args['form_id'] ) ? $args['form_id'] : 0;
1721
1722
	//Sanity Check: Must have form_id & not be logged in
1723
	if ( empty( $form_id ) || is_user_logged_in() ) {
1724
		return $final_output;
1725
	}
1726
1727
	//Logged in only and Register / Login set to none
1728
	if ( give_logged_in_only( $form_id ) && give_show_login_register_option( $form_id ) == 'none' ) {
1729
1730
		$final_output = give_output_error( esc_html__( 'Please log in in order to complete your donation.', 'give' ), false );
1731
1732
		return apply_filters( 'give_members_only_output', $final_output, $form_id );
1733
1734
	}
1735
1736
	return $final_output;
1737
1738
}
1739
1740
add_filter( 'give_donate_form', 'give_members_only_form', 10, 2 );
1741