Test Failed
Push — master ( f5256c...25a383 )
by Devin
07:02
created

template.php ➔ give_user_info_fields()   F

Complexity

Conditions 32
Paths > 20000

Size

Total Lines 209

Duplication

Lines 41
Ratio 19.62 %

Code Coverage

Tests 0
CRAP Score 1056

Importance

Changes 0
Metric Value
cc 32
nc 69120
nop 1
dl 41
loc 209
ccs 0
cts 40
cp 0
crap 1056
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

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
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
 * @param array $args An array of form arguments.
21
 *
22
 * @since 1.0
23
 *
24
 * @return string Donation form.
25
 */
26
function give_get_donation_form( $args = array() ) {
27
28 1
	global $post;
29
	static $count = 1;
30 1
31
	$form_id = is_object( $post ) ? $post->ID : 0;
32 1
33 1
	if ( isset( $args['id'] ) ) {
34 1
		$form_id = $args['id'];
35
	}
36 1
37
	$defaults = apply_filters( 'give_form_args_defaults', array(
38 1
		'form_id' => $form_id,
39
	) );
40 1
41
	$args = wp_parse_args( $args, $defaults );
42 1
43
	$form = new Give_Donate_Form( $args['form_id'] );
44
45 1
	// Bail out, if no form ID.
46
	if ( empty( $form->ID ) ) {
47
		return false;
48
	}
49 1
50
	$args['id_prefix'] = "{$form_id}-{$count}";
51 1
	$payment_mode      = give_get_chosen_gateway( $form->ID );
52 1
53 1
	$form_action = add_query_arg(
54 1
		apply_filters( 'give_form_action_args', array(
55 1
				'payment-mode' => $payment_mode,
56
			)
57
		),
58 1
		give_get_current_page_url()
59
	);
60
61
	// Sanity Check: Donation form not published or user doesn't have permission to view drafts.
62 1
	if (
63 1
		( 'publish' !== $form->post_status && ! current_user_can( 'edit_give_forms', $form->ID ) )
64 1
		|| ( 'trash' === $form->post_status )
65
	) {
66 1
		return false;
67 1
	}
68 1
69
	// Get the form wrap CSS classes.
70
	$form_wrap_classes = $form->get_form_wrap_classes( $args );
71 1
72 1
	// Get the <form> tag wrap CSS classes.
73
	$form_classes = $form->get_form_classes( $args );
74 1
75 1
	ob_start();
76
77
	/**
78 1
	 * Fires while outputting donation form, before the form wrapper div.
79 1
	 *
80 1
	 * @since 1.0
81
	 *
82 1
	 * @param int   $form_id The form ID.
83 1
	 * @param array $args    An array of form arguments.
84
	 */
85
	do_action( 'give_pre_form_output', $form->ID, $args, $form );
86 1
87
	?>
88
	<div id="give-form-<?php echo $form->ID; ?>-wrap" class="<?php echo $form_wrap_classes; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$form_wrap_classes'
Loading history...
89
		<?php
90
		if ( $form->is_close_donation_form() ) {
91
92
			$form_title = ! is_singular( 'give_forms' ) ? apply_filters( 'give_form_title', '<h2 class="give-form-title">' . get_the_title( $form_id ) . '</h2>' ) : '';
93
94
			// Get Goal thank you message.
95
			$goal_achieved_message = get_post_meta( $form->ID, '_give_form_goal_achieved_message', true );
96
			$goal_achieved_message = ! empty( $goal_achieved_message ) ? $form_title . apply_filters( 'the_content', $goal_achieved_message ) : '';
97
98
			// Print thank you message.
99
			echo apply_filters( 'give_goal_closed_output', $goal_achieved_message, $form->ID, $form );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
100
101
		} else {
102
			/**
103
			 * Show form title:
104
			 * 1. if show_title params set to true
105
			 * 2. if admin set form display_style to button
106
			 */
107
			$form_title = apply_filters( 'give_form_title', '<h2 class="give-form-title">' . get_the_title( $form_id ) . '</h2>' );
108
			if (
0 ignored issues
show
introduced by
Found "== true". Use Yoda Condition checks, you must
Loading history...
109
				(
110
					( isset( $args['show_title'] ) && $args['show_title'] == true )
111 1
					|| ( 'button' === get_post_meta( $form_id, '_give_payment_display', true ) )
112
				)
113
				&& ! doing_action( 'give_single_form_summary' )
114
			) {
115
				echo $form_title;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_title'
Loading history...
116
			}
117
118
			/**
119
			 * Fires while outputting donation form, before the form.
120
			 *
121
			 * @since 1.0
122
			 *
123
			 * @param int              $form_id The form ID.
124
			 * @param array            $args    An array of form arguments.
125
			 * @param Give_Donate_Form $form    Form object.
126
			 */
127
			do_action( 'give_pre_form', $form->ID, $args, $form );
128
129
			// Set form html tags.
130
			$form_html_tags = array(
131
				'id'      => "give-form-{$args['id_prefix']}",
132
				'class'   => $form_classes,
133
				'action'  => esc_url_raw( $form_action ),
134
				'data-id' => $args['id_prefix'],
135 1
			);
136
137 1
			/**
138 1
			 * Filter the form html tags.
139
			 *
140 1
			 * @since 1.8.17
141 1
			 *
142 1
			 * @param array            $form_html_tags Array of form html tags.
143 1
			 * @param Give_Donate_Form $form           Form object.
144 1
			 */
145
			$form_html_tags = apply_filters( 'give_form_html_tags', (array) $form_html_tags, $form );
146
			?>
147
			<form <?php echo give_get_attribute_str( $form_html_tags ); ?> method="post">
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_attribute_str'
Loading history...
148
				<!-- The following field is for robots only, invisible to humans: -->
149 1
				<span class="give-hidden" style="display: none !important;">
150
					<label for="give-form-honeypot-<?php echo $form_id; ?>"></label>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
151 1
					<input id="give-form-honeypot-<?php echo $form_id; ?>" type="text" name="give-honeypot"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
152
						   class="give-honeypot give-hidden"/>
153 1
				</span>
154
155
				<?php
156
				/**
157
				 * Fires while outputting donation form, before all other fields.
158
				 *
159
				 * @since 1.0
160
				 *
161
				 * @param int              $form_id The form ID.
162
				 * @param array            $args    An array of form arguments.
163
				 * @param Give_Donate_Form $form    Form object.
164
				 */
165
				do_action( 'give_donation_form_top', $form->ID, $args, $form );
166
167
				/**
168
				 * Fires while outputting donation form, for payment gateway fields.
169
				 *
170
				 * @since 1.7
171
				 *
172
				 * @param int              $form_id The form ID.
173 1
				 * @param array            $args    An array of form arguments.
174
				 * @param Give_Donate_Form $form    Form object.
175 1
				 */
176
				do_action( 'give_payment_mode_select', $form->ID, $args, $form );
177 1
178 1
				/**
179
				 * Fires while outputting donation form, after all other fields.
180
				 *
181
				 * @since 1.0
182
				 *
183
				 * @param int              $form_id The form ID.
184
				 * @param array            $args    An array of form arguments.
185
				 * @param Give_Donate_Form $form    Form object.
186
				 */
187
				do_action( 'give_donation_form_bottom', $form->ID, $args, $form );
188
189
				?>
190
			</form>
191
192
			<?php
193
			/**
194
			 * Fires while outputting donation form, after the form.
195
			 *
196
			 * @since 1.0
197
			 *
198
			 * @param int              $form_id The form ID.
199 1
			 * @param array            $args    An array of form arguments.
200
			 * @param Give_Donate_Form $form    Form object.
201 1
			 */
202
			do_action( 'give_post_form', $form->ID, $args, $form );
203
204
		}
205 1
		?>
206
207 1
	</div><!--end #give-form-<?php echo absint( $form->ID ); ?>-->
208
	<?php
209 1
210
	/**
211 1
	 * Fires while outputting donation form, after the form wrapper div.
212
	 *
213 1
	 * @since 1.0
214
	 *
215
	 * @param int   $form_id The form ID.
216 1
	 * @param array $args    An array of form arguments.
217 1
	 */
218 1
	do_action( 'give_post_form_output', $form->ID, $args );
219
220
	$final_output = ob_get_clean();
221
	$count ++;
222 1
223
	echo apply_filters( 'give_donate_form', $final_output, $args );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
224 1
}
225
226
/**
227
 * Give Show Donation Form.
228
 *
229
 * Renders the Donation Form, hooks are provided to add to the checkout form.
230 1
 * The default Donation Form rendered displays a list of the enabled payment
231 1
 * gateways, a user registration form (if enable) and a credit card info form
232
 * if credit cards are enabled.
233
 *
234
 * @since  1.0
235
 *
236
 * @param  int $form_id The form ID.
237
 *
238
 * @return string
239
 */
240
function give_show_purchase_form( $form_id, $args ) {
241
242
	$payment_mode = give_get_chosen_gateway( $form_id );
243
244
	if ( ! isset( $form_id ) && isset( $_POST['give_form_id'] ) ) {
245
		$form_id = $_POST['give_form_id'];
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
246
	}
247 1
248
	/**
249
	 * Fire before donation form render.
250
	 *
251
	 * @since 1.7
252
	 */
253
	do_action( 'give_payment_fields_top', $form_id );
254
255
	if ( give_can_checkout() && isset( $form_id ) ) {
256
257
		/**
258
		 * Fires while displaying donation form, before registration login.
259
		 *
260
		 * @since 1.7
261
		 */
262 1
		do_action( 'give_donation_form_before_register_login', $form_id, $args );
263
264
		/**
265
		 * Fire when register/login form fields render.
266
		 *
267
		 * @since 1.7
268
		 */
269
		do_action( 'give_donation_form_register_login_fields', $form_id, $args );
270
271
		/**
272
		 * Fire when credit card form fields render.
273
		 *
274
		 * @since 1.7
275
		 */
276
		do_action( 'give_donation_form_before_cc_form', $form_id, $args );
277
278
		// Load the credit card form and allow gateways to load their own if they wish.
279
		if ( has_action( 'give_' . $payment_mode . '_cc_form' ) ) {
280 1
			/**
281
			 * Fires while displaying donation form, credit card form fields for a given gateway.
282 1
			 *
283 1
			 * @since 1.0
284 1
			 *
285 1
			 * @param int $form_id The form ID.
286 1
			 */
287 1
			do_action( "give_{$payment_mode}_cc_form", $form_id, $args );
288 1
		} else {
289
			/**
290 1
			 * Fires while displaying donation form, credit card form fields.
291
			 *
292
			 * @since 1.0
293 1
			 *
294
			 * @param int $form_id The form ID.
295
			 */
296
			do_action( 'give_cc_form', $form_id, $args );
297
		}
298
299
		/**
300
		 * Fire after credit card form fields render.
301
		 *
302
		 * @since 1.7
303
		 */
304
		do_action( 'give_donation_form_after_cc_form', $form_id, $args );
305
306
	} else {
307
		/**
308
		 * Fire if user can not donate.
309
		 *
310
		 * @since 1.7
311
		 */
312
		do_action( 'give_donation_form_no_access', $form_id );
313
314
	}
315 1
316
	/**
317
	 * Fire after donation form rendered.
318
	 *
319
	 * @since 1.7
320
	 */
321
	do_action( 'give_payment_fields_bottom', $form_id, $args );
322
}
323
324
add_action( 'give_donation_form', 'give_show_purchase_form', 10, 2 );
325
326 1
/**
327
 * Give Show Login/Register Form Fields.
328
 *
329
 * @since  1.4.1
330
 *
331
 * @param  int $form_id The form ID.
332
 *
333
 * @return void
334 1
 */
335 1
function give_show_register_login_fields( $form_id ) {
336 1
337
	$show_register_form = give_show_login_register_option( $form_id );
338 1
339 1
	if ( ( $show_register_form === 'registration' || ( $show_register_form === 'both' && ! isset( $_GET['login'] ) ) ) && ! is_user_logged_in() ) :
0 ignored issues
show
introduced by
Found "=== '". Use Yoda Condition checks, you must
Loading history...
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
340
		?>
341
		<div id="give-checkout-login-register-<?php echo $form_id; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
342
			<?php
343
			/**
344
			 * Fire if user registration form render.
345
			 *
346
			 * @since 1.7
347
			 */
348
			do_action( 'give_donation_form_register_fields', $form_id );
349
			?>
350
		</div>
351
		<?php
352
	elseif ( ( $show_register_form === 'login' || ( $show_register_form === 'both' && isset( $_GET['login'] ) ) ) && ! is_user_logged_in() ) :
0 ignored issues
show
introduced by
Found "=== '". Use Yoda Condition checks, you must
Loading history...
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
353
		?>
354
		<div id="give-checkout-login-register-<?php echo $form_id; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
355
			<?php
356 1
			/**
357 1
			 * Fire if user login form render.
358 1
			 *
359 1
			 * @since 1.7
360 1
			 */
361 1
			do_action( 'give_donation_form_login_fields', $form_id );
362 1
			?>
363
		</div>
364 1
		<?php
365 1
	endif;
366
367
	if ( ( ! isset( $_GET['login'] ) && is_user_logged_in() ) || ! isset( $show_register_form ) || 'none' === $show_register_form || 'login' === $show_register_form ) {
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
368 1
		/**
369
		 * Fire when user info render.
370 1
		 *
371
		 * @since 1.7
372 1
		 */
373 1
		do_action( 'give_donation_form_after_user_info', $form_id );
374 1
	}
375 1
}
376
377 1
add_action( 'give_donation_form_register_login_fields', 'give_show_register_login_fields' );
378 1
379 1
/**
380 1
 * Donation Amount Field.
381 1
 *
382
 * Outputs the donation amount field that appears at the top of the donation forms. If the user has custom amount
383 1
 * enabled the field will output as a customizable input.
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
 * @return void
391
 */
392
function give_output_donation_amount_top( $form_id = 0, $args = array() ) {
393
394 1
	$give_options        = give_get_settings();
395
	$variable_pricing    = give_has_variable_prices( $form_id );
396 1
	$allow_custom_amount = give_get_meta( $form_id, '_give_custom_amount', true );
397
	$currency_position   = isset( $give_options['currency_position'] ) ? $give_options['currency_position'] : 'before';
398
	$symbol              = give_currency_symbol( give_get_currency( $form_id, $args ) );
399
	$currency_output     = '<span class="give-currency-symbol give-currency-position-' . $currency_position . '">' . $symbol . '</span>';
400
	$default_amount      = give_format_amount( give_get_default_form_amount( $form_id ), array( 'sanitize' => false, 'currency' => give_get_currency( $form_id ) ) );
401
	$custom_amount_text  = give_get_meta( $form_id, '_give_custom_amount_text', true );
402
403
	/**
404
	 * Fires while displaying donation form, before donation level fields.
405
	 *
406
	 * @since 1.0
407
	 *
408
	 * @param int   $form_id The form ID.
409
	 * @param array $args    An array of form arguments.
410
	 */
411
	do_action( 'give_before_donation_levels', $form_id, $args );
412
413
	// Set Price, No Custom Amount Allowed means hidden price field.
414
	if ( ! give_is_setting_enabled( $allow_custom_amount ) ) {
415
		?>
416
		<label class="give-hidden" for="give-amount-hidden"><?php esc_html_e( 'Donation Amount:', 'give' ); ?></label>
417
		<input id="give-amount" class="give-amount-hidden" type="hidden" name="give-amount"
418
			   value="<?php echo $default_amount; ?>" required aria-required="true"/>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$default_amount'
Loading history...
419
		<div class="set-price give-donation-amount form-row-wide">
420
			<?php if ( $currency_position == 'before' ) {
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
421
				echo $currency_output;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$currency_output'
Loading history...
422
			} ?>
423
			<span id="give-amount-text" class="give-text-input give-amount-top"><?php echo $default_amount; ?></span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$default_amount'
Loading history...
424
			<?php if ( $currency_position == 'after' ) {
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
425
				echo $currency_output;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$currency_output'
Loading history...
426
			} ?>
427
		</div>
428
		<?php
429
	} else {
430
		// Custom Amount Allowed.
431
		?>
432
		<div class="give-total-wrap">
433
			<div class="give-donation-amount form-row-wide">
434
				<?php if ( $currency_position == 'before' ) {
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
435
					echo $currency_output;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$currency_output'
Loading history...
436
				} ?>
437
				<label class="give-hidden" for="give-amount"><?php esc_html_e( 'Donation Amount:', 'give' ); ?></label>
438
				<input class="give-text-input give-amount-top" id="give-amount" name="give-amount" type="tel"
439
					   placeholder="" value="<?php echo $default_amount; ?>" autocomplete="off">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$default_amount'
Loading history...
440
				<?php if ( $currency_position == 'after' ) {
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
441
					echo $currency_output;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$currency_output'
Loading history...
442
				} ?>
443
			</div>
444
		</div>
445
	<?php }
446
447
	/**
448
	 * Fires while displaying donation form, after donation amounf field(s).
449
	 *
450
	 * @since 1.0
451
	 *
452 1
	 * @param int   $form_id The form ID.
453 1
	 * @param array $args    An array of form arguments.
454
	 */
455
	do_action( 'give_after_donation_amount', $form_id, $args );
456
457
	// Custom Amount Text
458
	if ( ! $variable_pricing && give_is_setting_enabled( $allow_custom_amount ) && ! empty( $custom_amount_text ) ) { ?>
459
		<p class="give-custom-amount-text"><?php echo $custom_amount_text; ?></p>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$custom_amount_text'
Loading history...
460
	<?php }
461
462
	// Output Variable Pricing Levels.
463
	if ( $variable_pricing ) {
464
		give_output_levels( $form_id );
465
	}
466 1
467 1
	/**
468 1
	 * Fires while displaying donation form, after donation level fields.
469
	 *
470
	 * @since 1.0
471 1
	 *
472
	 * @param int   $form_id The form ID.
473
	 * @param array $args    An array of form arguments.
474
	 */
475 1
	do_action( 'give_after_donation_levels', $form_id, $args );
476 1
}
477
478 1
add_action( 'give_donation_form_top', 'give_output_donation_amount_top', 10, 2 );
479
480 1
/**
481 1
 * Outputs the Donation Levels in various formats such as dropdown, radios, and buttons.
482
 *
483
 * @since  1.0
484
 *
485
 * @param  int $form_id The form ID.
486
 *
487
 * @return string Donation levels.
488
 */
489
function give_output_levels( $form_id ) {
490
491
	/**
492
	 * Filter the variable pricing
493
	 *
494
	 *
495
	 * @since      1.0
496
	 * @deprecated 2.2 Use give_get_donation_levels filter instead of give_form_variable_prices.
497
	 *                 Check Give_Donate_Form::get_prices().
498
	 *
499
	 * @param array $prices Array of variable prices.
500
	 * @param int   $form   Form ID.
501
	 */
502
	$prices = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $form_id ), $form_id );
503
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
504
505
	$display_style      = give_get_meta( $form_id, '_give_display_style', true );
506
	$custom_amount      = give_get_meta( $form_id, '_give_custom_amount', true );
507
	$custom_amount_text = give_get_meta( $form_id, '_give_custom_amount_text', true );
508
509
	if ( empty( $custom_amount_text ) ) {
510
		$custom_amount_text = esc_html__( 'Give a Custom Amount', 'give' );
511
	}
512
513
	$output = '';
514
515
	switch ( $display_style ) {
516 View Code Duplication
		case 'buttons':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
517
518
			$output .= '<ul id="give-donation-level-button-wrap" class="give-donation-levels-wrap give-list-inline">';
519
520
			foreach ( $prices as $price ) {
521
				$level_text    = apply_filters( 'give_form_level_text', ! empty( $price['_give_text'] ) ? $price['_give_text'] : give_currency_filter( give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ), array( 'currency_code' => give_get_currency( $form_id ) ) ), $form_id, $price );
522
				$level_classes = apply_filters( 'give_form_level_classes', 'give-donation-level-btn give-btn give-btn-level-' . $price['_give_id']['level_id'] . ' ' . ( give_is_default_level_id( $price ) ? 'give-default-level' : '' ), $form_id, $price );
523
524
				$formatted_amount = give_format_amount( $price['_give_amount'], array(
525
					'sanitize' => false,
526
					'currency' => give_get_currency( $form_id ),
527
				) );
528
529
				$output .= sprintf(
530
					'<li><button type="button" data-price-id="%1$s" class="%2$s" value="%3$s" data-default="%4$s">%5$s</button></li>',
531
					$price['_give_id']['level_id'],
532
					$level_classes,
533
					$formatted_amount,
534
					array_key_exists( '_give_default', $price ) ? 1 : 0,
535
					$level_text
536
				);
537
			}
538
539
			// Custom Amount.
540
			if (
541
				give_is_setting_enabled( $custom_amount )
542
				&& ! empty( $custom_amount_text )
543
			) {
544
545
				$output .= sprintf(
546
					'<li><button type="button" data-price-id="custom" class="give-donation-level-btn give-btn give-btn-level-custom" value="custom">%1$s</button></li>',
547
					$custom_amount_text
548
				);
549
			}
550
551
			$output .= '</ul>';
552
553
			break;
554
555 View Code Duplication
		case 'radios':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
556
557
			$output .= '<ul id="give-donation-level-radio-list" class="give-donation-levels-wrap">';
558
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'], array( 'sanitize' => false ) ), array( 'currency_code' => give_get_currency( $form_id ) ) ), $form_id, $price );
561
				$level_classes = apply_filters( 'give_form_level_classes', 'give-radio-input give-radio-input-level give-radio-level-' . $price['_give_id']['level_id'] . ( give_is_default_level_id( $price ) ? ' give-default-level' : '' ), $form_id, $price );
562
563
				$formatted_amount = give_format_amount( $price['_give_amount'], array(
564
					'sanitize' => false,
565
					'currency' => give_get_currency( $form_id ),
566
				) );
567
568
				$output .= sprintf(
569
					'<li><input type="radio" data-price-id="%1$s" class="%2$s" value="%3$s" name="give-radio-donation-level" id="give-radio-level-%1$s" %4$s data-default="%5$s"><label for="give-radio-level-%1$s">%6$s</label></li>',
570
					$price['_give_id']['level_id'],
571
					$level_classes,
572
					$formatted_amount,
573
					( give_is_default_level_id( $price ) ? 'checked="checked"' : '' ),
574
					array_key_exists( '_give_default', $price ) ? 1 : 0,
575
					$level_text
576
				);
577
			}
578
579
			// Custom Amount.
580
			if (
581
				give_is_setting_enabled( $custom_amount )
582
				&& ! empty( $custom_amount_text )
583
			) {
584
				$output .= sprintf(
585
					'<li><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"><label for="give-radio-level-custom">%1$s</label></li>',
586
					$custom_amount_text
587
				);
588
			}
589
590
			$output .= '</ul>';
591
592
			break;
593
594
		case 'dropdown':
595
596
			$output .= '<label for="give-donation-level-select-' . $form_id . '" class="give-hidden">' . esc_html__( 'Choose Your Donation Amount', 'give' ) . ':</label>';
597
			$output .= '<select id="give-donation-level-select-' . $form_id . '" class="give-select give-select-level give-donation-levels-wrap">';
598
599
			// first loop through prices.
600
			foreach ( $prices as $price ) {
601
				$level_text    = apply_filters( 'give_form_level_text', ! empty( $price['_give_text'] ) ? $price['_give_text'] : give_currency_filter( give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ), array( 'currency_code' => give_get_currency( $form_id ) ) ), $form_id, $price );
602
				$level_classes = apply_filters( 'give_form_level_classes', 'give-donation-level-' . $price['_give_id']['level_id'] . ( give_is_default_level_id( $price ) ? ' give-default-level' : '' ), $form_id,
603
				$price );
604
605
				$formatted_amount = give_format_amount( $price['_give_amount'], array(
606
					'sanitize' => false,
607
					'currency' => give_get_currency( $form_id ),
608
				) );
609
610
				$output .= sprintf(
611
					'<option data-price-id="%1$s" class="%2$s" value="%3$s" %4$s data-default="%5$s">%6$s</option>',
612
					$price['_give_id']['level_id'],
613
					$level_classes,
614
					$formatted_amount,
615
					( give_is_default_level_id( $price ) ? 'selected="selected"' : '' ),
616
					array_key_exists( '_give_default', $price ) ? 1 : 0,
617
					$level_text
618
				);
619
			}
620
621
			// Custom Amount.
622
			if ( give_is_setting_enabled( $custom_amount ) && ! empty( $custom_amount_text ) ) {
623
				$output .= sprintf(
624
					'<option data-price-id="custom" class="give-donation-level-custom" value="custom">%1$s</option>',
625
					$custom_amount_text
626
				);
627
			}
628
629
			$output .= '</select>';
630
631
			break;
632
	}
633
634
	echo apply_filters( 'give_form_level_output', $output, $form_id );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
635
}
636
637
/**
638
 * Display Reveal & Lightbox Button.
639
 *
640
 * Outputs a button to reveal form fields.
641
 *
642
 * @since  1.0
643
 *
644
 * @param  int   $form_id The form ID.
645
 * @param  array $args    An array of form arguments.
646
 *
647
 * @return string Checkout button.
648
 */
649
function give_display_checkout_button( $form_id, $args ) {
650
651
	$display_option = ( isset( $args['display_style'] ) && ! empty( $args['display_style'] ) )
652
		? $args['display_style']
653
		: give_get_meta( $form_id, '_give_payment_display', true );
654
655
	if ( 'button' === $display_option ) {
656
		$display_option = 'modal';
657
	} elseif ( $display_option === 'onpage' ) {
0 ignored issues
show
introduced by
Found "=== '". Use Yoda Condition checks, you must
Loading history...
658
		return '';
659
	}
660
661
	$display_label_field = give_get_meta( $form_id, '_give_reveal_label', true );
662
	$display_label       = ! empty( $args['continue_button_title'] ) ? $args['continue_button_title'] : ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) );
663
664
	$output = '<button type="button" class="give-btn give-btn-' . $display_option . '">' . $display_label . '</button>';
665
666
	echo apply_filters( 'give_display_checkout_button', $output );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
667
}
668
669
add_action( 'give_after_donation_levels', 'give_display_checkout_button', 10, 2 );
670
671
/**
672
 * Shows the User Info fields in the Personal Info box, more fields can be added via the hooks provided.
673
 *
674
 * @since  1.0
675
 *
676
 * @param  int $form_id The form ID.
677
 *
678
 * @see For Pattern Attribute: https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Form_validation
679
 *
680
 * @return void
681
 */
682
function give_user_info_fields( $form_id ) {
683
684
	// Get user info.
685
	$give_user_info = _give_get_prefill_form_field_values( $form_id );
686
	$title          = ! empty( $give_user_info['give_title'] ) ? $give_user_info['give_title'] : '';
687
	$first_name     = ! empty( $give_user_info['give_first'] ) ? $give_user_info['give_first'] : '';
688
	$last_name      = ! empty( $give_user_info['give_last'] ) ? $give_user_info['give_last'] : '';
689
	$company_name   = ! empty( $give_user_info['company_name'] ) ? $give_user_info['company_name'] : '';
690
	$email          = ! empty( $give_user_info['give_email'] ) ? $give_user_info['give_email'] : '';
691
	$title_prefixes = give_get_name_title_prefixes( $form_id );
692
693
	/**
694
	 * Fire before user personal information fields
695
	 *
696
	 * @since 1.7
697
	 */
698
	do_action( 'give_donation_form_before_personal_info', $form_id );
699
700
	$title_prefix_classes = '';
701
	if ( give_is_name_title_prefix_enabled( $form_id ) ) {
702
		$title_prefix_classes = 'give-title-prefix-wrap';
703
	}
704
	?>
705
	<fieldset id="give_checkout_user_info" class="<?php echo esc_html( $title_prefix_classes ); ?>">
706
		<legend>
707
			<?php echo esc_html( apply_filters( 'give_checkout_personal_info_text', __( 'Personal Info', 'give' ) ) ); ?>
708
		</legend>
709
710
		<?php if ( give_is_name_title_prefix_enabled( $form_id ) && is_array( $title_prefixes ) && count( $title_prefixes ) > 0 ) { ?>
711
			<p id="give-title-wrap" class="form-row form-row-title form-row-responsive">
712
				<label class="give-label" for="give-title">
713
					<?php esc_attr_e( 'Title', 'give' ); ?>
714
					<?php if ( give_field_is_required( 'give_title', $form_id ) ) : ?>
715
						<span class="give-required-indicator">*</span>
716
					<?php endif ?>
717
					<?php echo Give()->tooltips->render_help( __( 'We will use this to personalize your account experience.', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
718
				</label>
719
				<select
720
						class="give-input required"
721
						type="text"
722
						name="give_title"
723
						id="give-title"
724
					<?php echo( give_field_is_required( 'give_title', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
725
				>
726
					<?php foreach ( $title_prefixes as $key => $value ) { ?>
727
						<option value="<?php echo esc_html( $value ); ?>" <?php selected( $value, $title, true ); ?>><?php echo esc_html( $value ); ?></option>
728
					<?php } ?>
729
				</select>
730
			</p>
731
		<?php } ?>
732
733
		<p id="give-first-name-wrap" class="form-row form-row-first form-row-responsive">
734
			<label class="give-label" for="give-first">
735
				<?php esc_attr_e( 'First Name', 'give' ); ?>
736
				<?php if ( give_field_is_required( 'give_first', $form_id ) ) : ?>
737
					<span class="give-required-indicator">*</span>
738
				<?php endif ?>
739
				<?php echo Give()->tooltips->render_help( __( 'We will use this to personalize your account experience.', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
740
			</label>
741
			<input
742
					class="give-input required"
743
					type="text"
744
					name="give_first"
745
					autocomplete="given-name"
746
					placeholder="<?php esc_attr_e( 'First Name', 'give' ); ?>"
747
					id="give-first"
748
					value="<?php echo esc_html( $first_name ); ?>"
749
				<?php echo( give_field_is_required( 'give_first', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
750
			/>
751
		</p>
752
753
		<p id="give-last-name-wrap" class="form-row form-row-last form-row-responsive">
754
			<label class="give-label" for="give-last">
755
				<?php esc_attr_e( 'Last Name', 'give' ); ?>
756
				<?php if ( give_field_is_required( 'give_last', $form_id ) ) : ?>
757
					<span class="give-required-indicator">*</span>
758
				<?php endif ?>
759
				<?php echo Give()->tooltips->render_help( __( 'We will use this as well to personalize your account experience.', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
760
			</label>
761
762
			<input
763
					class="give-input<?php echo( give_field_is_required( 'give_last', $form_id ) ? ' required' : '' ); ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
764
					type="text"
765
					name="give_last"
766
					autocomplete="family-name"
767
					id="give-last"
768
					placeholder="<?php esc_attr_e( 'Last Name', 'give' ); ?>"
769
					value="<?php echo esc_html( $last_name ); ?>"
770
				<?php echo( give_field_is_required( 'give_last', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
771
			/>
772
		</p>
773
774
		<?php if ( give_is_company_field_enabled( $form_id ) ) : ?>
775
			<?php $give_company = give_field_is_required( 'give_company_name', $form_id ); ?>
776
			<p id="give-company-wrap" class="form-row form-row-wide">
777
				<label class="give-label" for="give-company">
778
					<?php esc_attr_e( 'Company Name', 'give' ); ?>
779
					<?php if ( $give_company ) : ?>
780
						<span class="give-required-indicator">*</span>
781
					<?php endif; ?>
782
					<?php echo Give()->tooltips->render_help( __( 'Donate on behalf of Company', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
783
				</label>
784
				<input
785
					class="give-input<?php echo( $give_company ? ' required' : '' ); ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
786
					type="text"
787
					name="give_company_name"
788
					placeholder="<?php esc_attr_e( 'Company Name', 'give' ); ?>"
789
					id="give-company"
790
					value="<?php echo esc_html( $company_name ); ?>"
791
					<?php echo( $give_company ? ' required aria-required="true" ' : '' ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
792
				/>
793
			</p>
794
		<?php endif ?>
795
796
		<?php
797
		/**
798
		 * Fire before user email field
799
		 *
800
		 * @since 1.7
801
		 */
802
		do_action( 'give_donation_form_before_email', $form_id );
803
		?>
804
		<p id="give-email-wrap" class="form-row form-row-wide">
805
			<label class="give-label" for="give-email">
806
				<?php esc_attr_e( 'Email Address', 'give' ); ?>
807
				<?php if ( give_field_is_required( 'give_email', $form_id ) ) { ?>
808
					<span class="give-required-indicator">*</span>
809
				<?php } ?>
810
				<?php echo Give()->tooltips->render_help( __( 'We will send the donation receipt to this address.', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
811
			</label>
812
			<input
813
					class="give-input required"
814
					type="email"
815
					name="give_email"
816
					autocomplete="email"
817
					placeholder="<?php esc_attr_e( 'Email Address', 'give' ); ?>"
818
					id="give-email"
819
					value="<?php echo esc_html( $email ); ?>"
820
				<?php echo( give_field_is_required( 'give_email', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
821
			/>
822
823
		</p>
824
825 View Code Duplication
		<?php if ( give_is_anonymous_donation_field_enabled( $form_id ) ) : ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
826
			<?php $is_anonymous_donation = isset( $_POST['give_anonymous_donation'] ) ? absint( $_POST['give_anonymous_donation'] ) : 0; ?>
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
827
			<p id="give-anonymous-donation-wrap" class="form-row form-row-wide">
828
				<label class="give-label" for="give-anonymous-donation">
829
				<input
830
						type="checkbox"
831
						class="give-input required"
832
						name="give_anonymous_donation"
833
						id="give-anonymous-donation"
834
						value="1"
835
					<?php echo( give_field_is_required( 'give_anonymous_donation', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
836
					<?php checked( 1, $is_anonymous_donation ); ?>
837
				>
838
					<?php _e( 'Make this an anonymous donation', 'give' ); ?>
839
					<?php if ( give_field_is_required( 'give_comment', $form_id ) ) { ?>
840
						<span class="give-required-indicator">*</span>
841
					<?php } ?>
842
					<?php echo Give()->tooltips->render_help( esc_html__( 'Would you like to prevent this donation from being displayed publicy?', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
843
				</label>
844
			</p>
845
		<?php endif; ?>
846
847 View Code Duplication
		<?php if ( give_is_donor_comment_field_enabled( $form_id ) ) : ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
848
			<p id="give-comment-wrap" class="form-row form-row-wide">
849
				<label class="give-label" for="give-comment">
850
					<?php _e( 'Comment', 'give' ); ?>
851
					<?php if ( give_field_is_required( 'give_comment', $form_id ) ) { ?>
852
						<span class="give-required-indicator">*</span>
853
					<?php } ?>
854
					<?php echo Give()->tooltips->render_help( __( 'Would you like to add a comment to this donation?', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
855
				</label>
856
857
				<textarea
858
					class="give-input required"
859
					name="give_comment"
860
					placeholder="<?php _e( 'Leave a comment', 'give' ); ?>"
861
					id="give-comment"
862
					<?php echo( give_field_is_required( 'give_comment', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
863
				><?php echo isset( $_POST['give_comment'] ) ? give_clean( $_POST['give_comment'] ) : ''; ?></textarea>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'isset'
Loading history...
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
864
865
			</p>
866
		<?php endif; ?>
867
		<?php
868
		/**
869
		 * Fire after user email field
870
		 *
871
		 * @since 1.7
872
		 */
873
		do_action( 'give_donation_form_after_email', $form_id );
874
875
		/**
876
		 * Fire after personal email field
877
		 *
878
		 * @since 1.7
879
		 */
880
		do_action( 'give_donation_form_user_info', $form_id );
881
		?>
882
	</fieldset>
883
	<?php
884
	/**
885
	 * Fire after user personal information fields
886
	 *
887
	 * @since 1.7
888
	 */
889
	do_action( 'give_donation_form_after_personal_info', $form_id );
890
}
891
892
add_action( 'give_donation_form_after_user_info', 'give_user_info_fields' );
893
add_action( 'give_register_fields_before', 'give_user_info_fields' );
894
895
/**
896
 * Renders the credit card info form.
897
 *
898
 * @since  1.0
899
 *
900
 * @param  int $form_id The form ID.
901
 *
902
 * @return void
903
 */
904
function give_get_cc_form( $form_id ) {
905
906
	ob_start();
907
908
	/**
909
	 * Fires while rendering credit card info form, before the fields.
910
	 *
911
	 * @since 1.0
912
	 *
913
	 * @param int $form_id The form ID.
914
	 */
915
	do_action( 'give_before_cc_fields', $form_id );
916
	?>
917
	<fieldset id="give_cc_fields-<?php echo $form_id ?>" class="give-do-validate">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
918
		<legend><?php echo apply_filters( 'give_credit_card_fieldset_heading', esc_html__( 'Credit Card Info', 'give' ) ); ?></legend>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
919
		<?php if ( is_ssl() ) : ?>
920
			<div id="give_secure_site_wrapper-<?php echo $form_id ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
921
				<span class="give-icon padlock"></span>
922
				<span><?php _e( 'This is a secure SSL encrypted payment.', 'give' ); ?></span>
923
			</div>
924
		<?php endif; ?>
925
		<p id="give-card-number-wrap-<?php echo $form_id ?>" class="form-row form-row-two-thirds form-row-responsive">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
926
			<label for="card_number-<?php echo $form_id ?>" class="give-label">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
927
				<?php _e( 'Card Number', 'give' ); ?>
928
				<span class="give-required-indicator">*</span>
929
				<?php echo Give()->tooltips->render_help( __( 'The (typically) 16 digits on the front of your credit card.', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
930
				<span class="card-type"></span>
931
			</label>
932
933
			<input type="tel" autocomplete="off" name="card_number" id="card_number-<?php echo $form_id ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
934
				   class="card-number give-input required" placeholder="<?php _e( 'Card number', 'give' ); ?>"
935
				   required aria-required="true"/>
936
		</p>
937
938
		<p id="give-card-cvc-wrap-<?php echo $form_id ?>" class="form-row form-row-one-third form-row-responsive">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
939
			<label for="card_cvc-<?php echo $form_id ?>" class="give-label">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
940
				<?php _e( 'CVC', 'give' ); ?>
941
				<span class="give-required-indicator">*</span>
942
				<?php echo Give()->tooltips->render_help( __( 'The 3 digit (back) or 4 digit (front) value on your card.', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
943
			</label>
944
945
			<input type="tel" size="4" autocomplete="off" name="card_cvc" id="card_cvc-<?php echo $form_id ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
946
				   class="card-cvc give-input required" placeholder="<?php _e( 'Security code', 'give' ); ?>"
947
				   required aria-required="true"/>
948
		</p>
949
950
		<p id="give-card-name-wrap-<?php echo $form_id ?>" class="form-row form-row-two-thirds form-row-responsive">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
951
			<label for="card_name-<?php echo $form_id ?>" class="give-label">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
952
				<?php _e( 'Name on the Card', 'give' ); ?>
953
				<span class="give-required-indicator">*</span>
954
				<?php echo Give()->tooltips->render_help( __( 'The name printed on the front of your credit card.', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
955
			</label>
956
957
			<input type="text" autocomplete="off" name="card_name" id="card_name-<?php echo $form_id ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
958
				   class="card-name give-input required" placeholder="<?php esc_attr_e( 'Card name', 'give' ); ?>"
959
				   required aria-required="true"/>
960
		</p>
961
		<?php
962
		/**
963
		 * Fires while rendering credit card info form, before expiration fields.
964
		 *
965
		 * @since 1.0
966
		 *
967
		 * @param int $form_id The form ID.
968
		 */
969
		do_action( 'give_before_cc_expiration' );
970
		?>
971
		<p class="card-expiration form-row form-row-one-third form-row-responsive">
972
			<label for="card_expiry-<?php echo $form_id ?>" class="give-label">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
973
				<?php _e( 'Expiration', 'give' ); ?>
974
				<span class="give-required-indicator">*</span>
975
				<?php echo Give()->tooltips->render_help( __( 'The date your credit card expires, typically on the front of the card.', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
976
			</label>
977
978
			<input type="hidden" id="card_exp_month-<?php echo $form_id ?>" name="card_exp_month" class="card-expiry-month"/>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
979
			<input type="hidden" id="card_exp_year-<?php echo $form_id ?>" name="card_exp_year" class="card-expiry-year"/>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
980
981
			<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 aria-required="true"/>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
982
		</p>
983
		<?php
984
		/**
985
		 * Fires while rendering credit card info form, after expiration fields.
986
		 *
987
		 * @since 1.0
988
		 *
989
		 * @param int $form_id The form ID.
990
		 */
991
		do_action( 'give_after_cc_expiration', $form_id );
992
		?>
993
	</fieldset>
994
	<?php
995 1
	/**
996
	 * Fires while rendering credit card info form, before the fields.
997
	 *
998
	 * @since 1.0
999
	 *
1000
	 * @param int $form_id The form ID.
1001
	 */
1002
	do_action( 'give_after_cc_fields', $form_id );
1003
1004
	echo ob_get_clean();
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'ob_get_clean'
Loading history...
1005
}
1006
1007
add_action( 'give_cc_form', 'give_get_cc_form' );
1008
1009
/**
1010
 * Outputs the default credit card address fields.
1011 1
 *
1012 1
 * @since  1.0
1013 1
 *
1014 1
 * @param  int $form_id The form ID.
1015 1
 *
1016
 * @return void
1017
 */
1018
function give_default_cc_address_fields( $form_id ) {
1019
	// Get user info.
1020
	$give_user_info = _give_get_prefill_form_field_values( $form_id );
1021
1022
	$logged_in = is_user_logged_in();
1023
1024
	if ( $logged_in ) {
1025
		$user_address = give_get_donor_address( get_current_user_id() );
0 ignored issues
show
Unused Code introduced by
$user_address is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1026
	}
1027
1028
	ob_start();
1029
	?>
1030
	<fieldset id="give_cc_address" class="cc-address">
1031
		<legend><?php echo apply_filters( 'give_billing_details_fieldset_heading', esc_html__( 'Billing Details', 'give' ) ); ?></legend>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
1032
		<?php
1033 1
		/**
1034
		 * Fires while rendering credit card billing form, before address fields.
1035
		 *
1036
		 * @since 1.0
1037
		 *
1038
		 * @param int $form_id The form ID.
1039
		 */
1040
		do_action( 'give_cc_billing_top' );
1041
1042
		// For Country.
1043
		$selected_country = give_get_country();
1044 View Code Duplication
		if ( ! empty( $give_user_info['billing_country'] ) && '*' !== $give_user_info['billing_country'] ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1045
			$selected_country = $give_user_info['billing_country'];
1046
		}
1047
		$countries = give_get_country_list();
1048
1049
		// For state.
1050
		$selected_state = '';
1051
		if ( $selected_country === give_get_country() ) {
1052 1
			// Get default selected state by admin.
1053 1
			$selected_state = give_get_state();
1054 1
		}
1055
		// Get the last payment made by user states.
1056
		if ( ! empty( $give_user_info['card_state'] ) && '*' !== $give_user_info['card_state'] ) {
1057
			$selected_state = $give_user_info['card_state'];
1058
		}
1059
		// Get the country code.
1060 View Code Duplication
		if ( ! empty( $give_user_info['billing_country'] ) && '*' !== $give_user_info['billing_country'] ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1061
			$selected_country = $give_user_info['billing_country'];
1062
		}
1063
		$label        = __( 'State', 'give' );
1064
		$states_label = give_get_states_label();
1065
		// Check if $country code exists in the array key for states label.
1066
		if ( array_key_exists( $selected_country, $states_label ) ) {
1067
			$label = $states_label[ $selected_country ];
1068
		}
1069
		$states = give_get_states( $selected_country );
1070
		// Get the country list that do not have any states init.
1071
		$no_states_country = give_no_states_country_list();
1072
		// Get the country list that does not require states.
1073
		$states_not_required_country_list = give_states_not_required_country_list();
1074
		?>
1075
	    <p id="give-card-country-wrap" class="form-row form-row-wide">
1076
		    <label for="billing_country" class="give-label">
1077 1
			    <?php esc_html_e( 'Country', 'give' ); ?>
1078
			    <?php if ( give_field_is_required( 'billing_country', $form_id ) ) : ?>
1079
				    <span class="give-required-indicator">*</span>
1080
			    <?php endif; ?>
1081
			    <span class="give-tooltip give-icon give-icon-question"
1082
			          data-tooltip="<?php esc_attr_e( 'The country for your billing address.', 'give' ); ?>"></span>
1083
		    </label>
1084
1085
		    <select
1086
				    name="billing_country"
1087
				    autocomplete="country-name"
1088
				    id="billing_country"
1089
				    class="billing-country billing_country give-select<?php echo( give_field_is_required( 'billing_country', $form_id ) ? ' required' : '' ); ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1090
			    <?php echo( give_field_is_required( 'billing_country', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1091
		    >
1092
			    <?php
1093 1
			    foreach ( $countries as $country_code => $country ) {
1094
				    echo '<option value="' . esc_attr( $country_code ) . '"' . selected( $country_code, $selected_country, false ) . '>' . $country . '</option>';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$country'
Loading history...
1095
			    }
1096
			    ?>
1097 1
		    </select>
1098
	    </p>
1099
1100 1
		<p id="give-card-address-wrap" class="form-row form-row-wide">
1101
			<label for="card_address" class="give-label">
1102
				<?php _e( 'Address 1', 'give' ); ?>
1103
				<?php
1104
				if ( give_field_is_required( 'card_address', $form_id ) ) : ?>
1105
					<span class="give-required-indicator">*</span>
1106
				<?php endif; ?>
1107
				<?php echo Give()->tooltips->render_help( __( 'The primary billing address for your credit card.', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
1108
			</label>
1109 1
1110
			<input
1111
					type="text"
1112
					id="card_address"
1113
					name="card_address"
1114
					autocomplete="address-line1"
1115
					class="card-address give-input<?php echo( give_field_is_required( 'card_address', $form_id ) ? ' required' : '' ); ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1116
					placeholder="<?php _e( 'Address line 1', 'give' ); ?>"
1117
					value="<?php echo isset( $give_user_info['card_address'] ) ? $give_user_info['card_address'] : ''; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'isset'
Loading history...
1118
				<?php echo( give_field_is_required( 'card_address', $form_id ) ? '  required aria-required="true" ' : '' ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1119
			/>
1120
		</p>
1121
1122
		<p id="give-card-address-2-wrap" class="form-row form-row-wide">
1123
			<label for="card_address_2" class="give-label">
1124
				<?php _e( 'Address 2', 'give' ); ?>
1125
				<?php if ( give_field_is_required( 'card_address_2', $form_id ) ) : ?>
1126
					<span class="give-required-indicator">*</span>
1127
				<?php endif; ?>
1128
				<?php echo Give()->tooltips->render_help( __( '(optional) The suite, apartment number, post office box (etc) associated with your billing address.', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
1129
			</label>
1130
1131
			<input
1132
					type="text"
1133
					id="card_address_2"
1134
					name="card_address_2"
1135
					autocomplete="address-line2"
1136 1
					class="card-address-2 give-input<?php echo( give_field_is_required( 'card_address_2', $form_id ) ? ' required' : '' ); ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1137
					placeholder="<?php _e( 'Address line 2', 'give' ); ?>"
1138
					value="<?php echo isset( $give_user_info['card_address_2'] ) ? $give_user_info['card_address_2'] : ''; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'isset'
Loading history...
1139
				<?php echo( give_field_is_required( 'card_address_2', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1140
			/>
1141
		</p>
1142
1143
		<p id="give-card-city-wrap" class="form-row form-row-wide">
1144
			<label for="card_city" class="give-label">
1145
				<?php _e( 'City', 'give' ); ?>
1146
				<?php if ( give_field_is_required( 'card_city', $form_id ) ) : ?>
1147
					<span class="give-required-indicator">*</span>
1148
				<?php endif; ?>
1149
				<?php echo Give()->tooltips->render_help( __( 'The city for your billing address.', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
1150
			</label>
1151
			<input
1152
					type="text"
1153 1
					id="card_city"
1154 1
					name="card_city"
1155
					autocomplete="address-level3"
1156
					class="card-city give-input<?php echo( give_field_is_required( 'card_city', $form_id ) ? ' required' : '' ); ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1157
					placeholder="<?php _e( 'City', 'give' ); ?>"
1158
					value="<?php echo isset( $give_user_info['card_city'] ) ? $give_user_info['card_city'] : ''; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'isset'
Loading history...
1159
				<?php echo( give_field_is_required( 'card_city', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1160
			/>
1161 1
		</p>
1162
1163
	    <p id="give-card-state-wrap"
1164
	       class="form-row form-row-first form-row-responsive <?php echo ( ! empty( $selected_country ) && array_key_exists( $selected_country, $no_states_country ) ) ? 'give-hidden' : ''; ?> ">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1165
		    <label for="card_state" class="give-label">
1166
			    <span class="state-label-text"><?php echo $label; ?></span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$label'
Loading history...
1167
			    <?php if ( give_field_is_required( 'card_state', $form_id ) ) :
1168
				    ?>
1169
				    <span class="give-required-indicator <?php echo( array_key_exists( $selected_country, $states_not_required_country_list ) ? 'give-hidden' : '' ) ?> ">*</span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1170
			    <?php endif; ?>
1171
			    <span class="give-tooltip give-icon give-icon-question"
1172
			          data-tooltip="<?php esc_attr_e( 'The state, province, or county for your billing address.', 'give' ); ?>"></span>
1173
		    </label>
1174
		    <?php
1175
1176 1
		    if ( ! empty( $states ) ) : ?>
1177
			    <select
1178 1
					    name="card_state"
1179
					    autocomplete="address-level4"
1180
					    id="card_state"
1181
					    class="card_state give-select<?php echo( give_field_is_required( 'card_state', $form_id ) ? ' required' : '' ); ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1182
				    <?php echo( give_field_is_required( 'card_state', $form_id ) ? ' required aria-required="true" ' : '' ); ?>>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1183
				    <?php
1184
				    foreach ( $states as $state_code => $state ) {
1185
					    echo '<option value="' . $state_code . '"' . selected( $state_code, $selected_state, false ) . '>' . $state . '</option>';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$state_code'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$state'
Loading history...
1186
				    }
1187
				    ?>
1188
			    </select>
1189
		    <?php else : ?>
1190
			    <input type="text" size="6" name="card_state" id="card_state" class="card_state give-input"
1191
			           placeholder="<?php echo $label; ?>" value="<?php echo $selected_state; ?>"/>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$label'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$selected_state'
Loading history...
1192 1
		    <?php endif; ?>
1193
	    </p>
1194
1195
		<p id="give-card-zip-wrap" class="form-row form-row-last form-row-responsive">
1196
			<label for="card_zip" class="give-label">
1197
				<?php _e( 'Zip / Postal Code', 'give' ); ?>
1198
				<?php if ( give_field_is_required( 'card_zip', $form_id ) ) : ?>
1199
					<span class="give-required-indicator">*</span>
1200
				<?php endif; ?>
1201
				<?php echo Give()->tooltips->render_help( __( 'The ZIP Code or postal code for your billing address.', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
1202
			</label>
1203
1204
			<input
1205
					type="text"
1206
					size="4"
1207
					id="card_zip"
1208
					name="card_zip"
1209 1
					autocomplete="postal-code"
1210 1
					class="card-zip give-input<?php echo( give_field_is_required( 'card_zip', $form_id ) ? ' required' : '' ); ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1211 1
					placeholder="<?php _e( 'Zip / Postal Code', 'give' ); ?>"
1212 1
					value="<?php echo isset( $give_user_info['card_zip'] ) ? $give_user_info['card_zip'] : ''; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'isset'
Loading history...
1213 1
				<?php echo( give_field_is_required( 'card_zip', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1214 1
			/>
1215 1
		</p>
1216 1
		<?php
1217
		/**
1218
		 * Fires while rendering credit card billing form, after address fields.
1219 1
		 *
1220
		 * @since 1.0
1221
		 *
1222
		 * @param int $form_id The form ID.
1223
		 */
1224 1
		do_action( 'give_cc_billing_bottom' );
1225 1
		?>
1226 1
	</fieldset>
1227 1
	<?php
1228 1
	echo ob_get_clean();
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'ob_get_clean'
Loading history...
1229
}
1230 1
1231
add_action( 'give_after_cc_fields', 'give_default_cc_address_fields' );
1232
1233
1234
/**
1235
 * Renders the user registration fields. If the user is logged in, a login form is displayed other a registration form
1236
 * is provided for the user to create an account.
1237
 *
1238
 * @since  1.0
1239
 *
1240
 * @param  int $form_id The form ID.
1241
 *
1242
 * @return string
1243
 */
1244
function give_get_register_fields( $form_id ) {
1245
1246
	global $user_ID;
1247
1248
	if ( is_user_logged_in() ) {
1249
		$user_data = get_userdata( $user_ID );
0 ignored issues
show
Unused Code introduced by
$user_data is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1250
	}
1251
1252
	$show_register_form = give_show_login_register_option( $form_id );
1253
1254
	ob_start(); ?>
1255
	<fieldset id="give-register-fields-<?php echo $form_id; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1256
1257
		<?php
1258
		/**
1259
		 * Fires while rendering user registration form, before registration fields.
1260
		 *
1261
		 * @since 1.0
1262
		 *
1263
		 * @param int $form_id The form ID.
1264
		 */
1265
		do_action( 'give_register_fields_before', $form_id );
1266
		?>
1267
1268
		<fieldset id="give-register-account-fields-<?php echo $form_id; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1269
			<?php
1270
			/**
1271
			 * Fires while rendering user registration form, before account fields.
1272
			 *
1273
			 * @since 1.0
1274
			 *
1275
			 * @param int $form_id The form ID.
1276
			 */
1277
			do_action( 'give_register_account_fields_before', $form_id );
1278
1279
			$class = ( 'registration' === $show_register_form) ? 'form-row-wide' : 'form-row-first';
1280
			?>
1281
			<div id="give-create-account-wrap-<?php echo $form_id; ?>" class="form-row <?php echo esc_attr( $class ); ?> form-row-responsive">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1282
				<label for="give-create-account-<?php echo $form_id; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1283
					<?php
1284
					// Add attributes to checkbox, if Guest Checkout is disabled.
1285
					$is_guest_checkout = give_get_meta( $form_id, '_give_logged_in_only', true );
1286
					$id                = 'give-create-account-' . $form_id;
1287
					if ( ! give_is_setting_enabled( $is_guest_checkout ) ) {
1288
						echo Give()->tooltips->render(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
1289
							array(
1290
								'tag_content' => sprintf(
1291
									'<input type="checkbox" name="give_create_account" value="on" id="%s" class="give-input give-disabled" checked />',
1292
									$id
1293
								),
1294
								'label'       => __( 'Registration is required to donate.', 'give' ),
1295
							) );
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 24 spaces, but found 28.
Loading history...
1296
					} else {
1297
						?>
1298
						<input type="checkbox" name="give_create_account" value="on" id="<?php echo $id; ?>" class="give-input" />
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$id'
Loading history...
1299
						<?php
1300
					}
1301
1302 1
					_e( 'Create an account', 'give' );
1303 1
					echo Give()->tooltips->render_help( __( 'Create an account on the site to see and manage donation history.', 'give' ) );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
1304 1
					echo str_replace(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'str_replace'
Loading history...
1305
						'/>',
1306 1
						'data-time="' . time() . '" data-nonce-life="' . give_get_nonce_life() . '"/>',
1307
						give_get_nonce_field( "give_form_create_user_nonce_{$form_id}", 'give-form-user-register-hash', false )
1308 1
					);
1309 1
					?>
1310 1
				</label>
1311
			</div>
1312
1313
			<?php if ( 'both' === $show_register_form ) { ?>
1314
				<div class="give-login-account-wrap form-row form-row-last form-row-responsive">
1315
					<p class="give-login-message"><?php esc_html_e( 'Already have an account?', 'give' ); ?>&nbsp;
1316
						<a href="<?php echo esc_url( add_query_arg( 'login', 1 ) ); ?>" class="give-checkout-login"
1317
						   data-action="give_checkout_login"><?php esc_html_e( 'Login', 'give' ); ?></a>
1318
					</p>
1319
					<p class="give-loading-text">
1320
						<span class="give-loading-animation"></span>
1321
					</p>
1322
				</div>
1323
			<?php } ?>
1324
1325
			<?php
1326
			/**
1327
			 * Fires while rendering user registration form, after account fields.
1328
			 *
1329
			 * @since 1.0
1330
			 *
1331
			 * @param int $form_id The form ID.
1332
			 */
1333
			do_action( 'give_register_account_fields_after', $form_id );
1334
			?>
1335
		</fieldset>
1336
1337
		<?php
1338
		/**
1339
		 * Fires while rendering user registration form, after registration fields.
1340
		 *
1341
		 * @since 1.0
1342
		 *
1343
		 * @param int $form_id The form ID.
1344
		 */
1345
		do_action( 'give_register_fields_after', $form_id );
1346
		?>
1347
1348
		<input type="hidden" name="give-purchase-var" value="needs-to-register"/>
1349
1350
		<?php
1351
		/**
1352
		 * Fire after register or login form render
1353
		 *
1354
		 * @since 1.7
1355
		 */
1356 1
		do_action( 'give_donation_form_user_info', $form_id );
1357
		?>
1358
1359
	</fieldset>
1360
	<?php
1361
	echo ob_get_clean();
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'ob_get_clean'
Loading history...
1362
}
1363 1
1364
add_action( 'give_donation_form_register_fields', 'give_get_register_fields' );
1365 1
1366
/**
1367
 * Gets the login fields for the login form on the checkout. This function hooks
1368
 * on the give_donation_form_login_fields to display the login form if a user already
1369
 * had an account.
1370
 *
1371
 * @since  1.0
1372
 *
1373
 * @param  int $form_id The form ID.
1374
 *
1375
 * @return string
1376
 */
1377
function give_get_login_fields( $form_id ) {
1378
1379
	$form_id            = isset( $_POST['form_id'] ) ? $_POST['form_id'] : $form_id;
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
1380
	$show_register_form = give_show_login_register_option( $form_id );
1381
1382
	ob_start();
1383
	?>
1384
	<fieldset id="give-login-fields-<?php echo $form_id; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1385
		<legend><?php echo apply_filters( 'give_account_login_fieldset_heading', __( 'Login to Your Account', 'give' ) );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
1386
			if ( ! give_logged_in_only( $form_id ) ) {
1387
				echo ' <span class="sub-text">' . __( '(optional)', 'give' ) . '</span>';
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw '__'
Loading history...
1388
			} ?>
1389
		</legend>
1390
		<?php if ( $show_register_form == 'both' ) { ?>
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
1391
			<p class="give-new-account-link">
1392
				<?php _e( 'Don\'t have an account?', 'give' ); ?>&nbsp;
1393
				<a href="<?php echo remove_query_arg( 'login' ); ?>" class="give-checkout-register-cancel"
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'remove_query_arg'
Loading history...
1394
				   data-action="give_checkout_register">
1395
					<?php if ( give_logged_in_only( $form_id ) ) {
1396
					    _e( 'Register as a part of your donation &raquo;', 'give' );
1397
                    } else {
1398
						 _e( 'Register or donate as a guest &raquo;', 'give' );
1399
					} ?>
1400
				</a>
1401
			</p>
1402
			<p class="give-loading-text">
1403 1
				<span class="give-loading-animation"></span>
1404
			</p>
1405 1
		<?php } ?>
1406
		<?php
1407
		/**
1408 1
		 * Fires while rendering checkout login form, before the fields.
1409
		 *
1410
		 * @since 1.0
1411
		 *
1412
		 * @param int $form_id The form ID.
1413
		 */
1414
		// do_action( 'give_checkout_login_fields_before', $form_id );
1415
		?>
1416
		<div class="give-user-login-fields-container">
1417
			<div id="give-user-login-wrap-<?php echo $form_id; ?>" class="form-row form-row-first form-row-responsive">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1418
				<label class="give-label" for="give-user-login-<?php echo $form_id; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1419
					<?php _e( 'Username', 'give' ); ?>
1420
					<?php if ( give_logged_in_only( $form_id ) ) { ?>
1421
						<span class="give-required-indicator">*</span>
1422 1
					<?php } ?>
1423
				</label>
1424
1425 1
				<input class="give-input<?php echo ( give_logged_in_only( $form_id ) ) ? ' required' : ''; ?>" type="text"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1426
					   name="give_user_login" id="give-user-login-<?php echo $form_id; ?>" value=""
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1427
					   placeholder="<?php _e( 'Your username', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1428
			</div>
1429
1430 1
			<div id="give-user-pass-wrap-<?php echo $form_id; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1431
				 class="give_login_password form-row form-row-last form-row-responsive">
1432
				<label class="give-label" for="give-user-pass-<?php echo $form_id; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1433
					<?php _e( 'Password', 'give' ); ?>
1434
					<?php if ( give_logged_in_only( $form_id ) ) { ?>
1435
						<span class="give-required-indicator">*</span>
1436
					<?php } ?>
1437
				</label>
1438 1
				<input class="give-input<?php echo ( give_logged_in_only( $form_id ) ) ? ' required' : ''; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1439
					   type="password" name="give_user_pass" id="give-user-pass-<?php echo $form_id; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1440
					   placeholder="<?php _e( 'Your password', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1441
				<input type="hidden" name="give-purchase-var" value="needs-to-login"/>
1442
			</div>
1443
1444
			<div id="give-forgot-password-wrap-<?php echo $form_id; ?>" class="give_login_forgot_password">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1445
				 <span class="give-forgot-password ">
1446
					 <a href="<?php echo wp_lostpassword_url() ?>"
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'wp_lostpassword_url'
Loading history...
1447
						target="_blank"><?php _e( 'Reset Password', 'give' ) ?></a>
1448
				 </span>
1449
			</div>
1450
		</div>
1451
1452
1453
		<div id="give-user-login-submit-<?php echo $form_id; ?>" class="give-clearfix">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1454
			<input type="submit" class="give-submit give-btn button" name="give_login_submit"
1455
				   value="<?php _e( 'Login', 'give' ); ?>"/>
1456
			<?php if ( $show_register_form !== 'login' ) { ?>
0 ignored issues
show
introduced by
Found "!== '". Use Yoda Condition checks, you must
Loading history...
1457
				<input type="button" data-action="give_cancel_login"
1458
					   class="give-cancel-login give-checkout-register-cancel give-btn button" name="give_login_cancel"
1459
					   value="<?php _e( 'Cancel', 'give' ); ?>"/>
1460
			<?php } ?>
1461
			<span class="give-loading-animation"></span>
1462
		</div>
1463
		<?php
1464
		/**
1465
		 * Fires while rendering checkout login form, after the fields.
1466
		 *
1467
		 * @since 1.0
1468
		 *
1469
		 * @param int $form_id The form ID.
1470
		 */
1471
		do_action( 'give_checkout_login_fields_after', $form_id );
1472
		?>
1473
	</fieldset><!--end #give-login-fields-->
1474
	<?php
1475
	echo ob_get_clean();
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'ob_get_clean'
Loading history...
1476
}
1477
1478
add_action( 'give_donation_form_login_fields', 'give_get_login_fields', 10, 1 );
1479
1480
/**
1481
 * Payment Mode Select.
1482
 *
1483
 * Renders the payment mode form by getting all the enabled payment gateways and
1484
 * outputting them as radio buttons for the user to choose the payment gateway. If
1485
 * a default payment gateway has been chosen from the Give Settings, it will be
1486
 * automatically selected.
1487
 *
1488
 * @since  1.0
1489
 *
1490
 * @param  int $form_id The form ID.
1491
 *
1492
 * @return void
1493
 */
1494
function give_payment_mode_select( $form_id, $args ) {
1495
1496
	$gateways  = give_get_enabled_payment_gateways( $form_id );
1497
	$id_prefix = ! empty( $args['id_prefix'] ) ? $args['id_prefix'] : '';
1498
1499
	/**
1500
	 * Fires while selecting payment gateways, before the fields.
1501
	 *
1502
	 * @since 1.7
1503
	 *
1504
	 * @param int $form_id The form ID.
1505
	 */
1506
	do_action( 'give_payment_mode_top', $form_id );
1507
	?>
1508
1509
	<fieldset id="give-payment-mode-select" <?php if ( count( $gateways ) <= 1 ) {
1510
		echo 'style="display: none;"';
1511
	} ?>>
1512
		<?php
1513
		/**
1514
		 * Fires while selecting payment gateways, before the wrap div.
1515
		 *
1516
		 * @since 1.7
1517
		 *
1518
		 * @param int $form_id The form ID.
1519
		 */
1520
		do_action( 'give_payment_mode_before_gateways_wrap' );
1521
		?>
1522
		<legend
1523
				class="give-payment-mode-label"><?php echo apply_filters( 'give_checkout_payment_method_text', esc_html__( 'Select Payment Method', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
1524
			<span class="give-loading-text"><span
1525
						class="give-loading-animation"></span>
1526
            </span>
1527
		</legend>
1528
1529
		<div id="give-payment-mode-wrap">
1530
			<?php
1531
			/**
1532
			 * Fires while selecting payment gateways, before the gateways list.
1533
			 *
1534
			 * @since 1.7
1535
			 */
1536
			do_action( 'give_payment_mode_before_gateways' )
1537
			?>
1538
			<ul id="give-gateway-radio-list">
1539
				<?php
1540
				/**
1541
				 * Loop through the active payment gateways.
1542
				 */
1543
				$selected_gateway = give_get_chosen_gateway( $form_id );
1544
				$give_settings    = give_get_settings();
1545
				$gateways_label   = array_key_exists( 'gateways_label', $give_settings ) ?
1546
					$give_settings['gateways_label'] :
1547
					array();
1548
1549
				foreach ( $gateways as $gateway_id => $gateway ) :
1550
					//Determine the default gateway.
1551
					$checked = checked( $gateway_id, $selected_gateway, false );
1552
					$checked_class = $checked ? ' class="give-gateway-option-selected"' : ''; ?>
1553
					<li<?php echo $checked_class ?>>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$checked_class'
Loading history...
1554
						<input type="radio" name="payment-mode" class="give-gateway"
1555
							   id="give-gateway-<?php echo esc_attr( $gateway_id . '-' . $id_prefix ); ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$id_prefix'
Loading history...
1556
							   value="<?php echo esc_attr( $gateway_id ); ?>"<?php echo $checked; ?>>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$checked'
Loading history...
1557
1558
						<?php
1559
						$label = $gateway['checkout_label'];
1560
						if ( ! empty( $gateways_label[ $gateway_id  ] ) ) {
1561
							$label = $gateways_label[ $gateway_id ];
1562
						}
1563
						?>
1564
						<label for="give-gateway-<?php echo esc_attr( $gateway_id . '-' . $id_prefix ); ?>"
1565
							   class="give-gateway-option"
1566
							   id="give-gateway-option-<?php echo esc_attr( $gateway_id ); ?>"> <?php echo esc_html( $label ); ?></label>
1567
					</li>
1568
					<?php
1569
				endforeach;
1570
				?>
1571
			</ul>
1572
			<?php
1573
			/**
1574
			 * Fires while selecting payment gateways, before the gateways list.
1575
			 *
1576
			 * @since 1.7
1577
			 */
1578
			do_action( 'give_payment_mode_after_gateways' );
1579
			?>
1580
		</div>
1581
		<?php
1582
		/**
1583
		 * Fires while selecting payment gateways, after the wrap div.
1584
		 *
1585
		 * @since 1.7
1586
		 *
1587
		 * @param int $form_id The form ID.
1588
		 */
1589
		do_action( 'give_payment_mode_after_gateways_wrap' );
1590
		?>
1591
	</fieldset>
1592
1593
	<?php
1594
	/**
1595
	 * Fires while selecting payment gateways, after the fields.
1596
	 *
1597
	 * @since 1.7
1598
	 *
1599
	 * @param int $form_id The form ID.
1600
	 */
1601
	do_action( 'give_payment_mode_bottom', $form_id );
1602
	?>
1603
1604
	<div id="give_purchase_form_wrap">
1605
1606
		<?php
1607
		/**
1608
		 * Fire after payment field render.
1609
		 *
1610
		 * @since 1.7
1611
		 */
1612
		do_action( 'give_donation_form', $form_id, $args );
1613
		?>
1614
1615
	</div>
1616
1617
	<?php
1618
	/**
1619
	 * Fire after donation form render.
1620
	 *
1621
	 * @since 1.7
1622
	 */
1623
	do_action( 'give_donation_form_wrap_bottom', $form_id );
1624
}
1625
1626
add_action( 'give_payment_mode_select', 'give_payment_mode_select', 10, 2 );
1627
1628
/**
1629
 * Renders the Checkout Agree to Terms, this displays a checkbox for users to
1630
 * agree the T&Cs set in the Give Settings. This is only displayed if T&Cs are
1631
 * set in the Give Settings.
1632
 *
1633
 * @since  1.0
1634
 *
1635
 * @param  int $form_id The form ID.
1636
 *
1637
 * @return bool
1638
 */
1639
function give_terms_agreement( $form_id ) {
1640
	$form_option = give_get_meta( $form_id, '_give_terms_option', true );
1641
1642
	// Bailout if per form and global term and conditions is not setup.
1643
	if (
1644
		give_is_setting_enabled( $form_option, 'global' )
1645
		&& give_is_setting_enabled( give_get_option( 'terms' ) )
1646
	) {
1647
		$label         = give_get_option( 'agree_to_terms_label', esc_html__( 'Agree to Terms?', 'give' ) );
1648
		$terms         = $terms = give_get_option( 'agreement_text', '' );
1649
		$edit_term_url = admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=display&section=term-and-conditions' );
1650
1651
	} elseif ( give_is_setting_enabled( $form_option ) ) {
1652
		$label         = ( $label = give_get_meta( $form_id, '_give_agree_label', true ) ) ? stripslashes( $label ) : esc_html__( 'Agree to Terms?', 'give' );
1653
		$terms         = give_get_meta( $form_id, '_give_agree_text', true );
1654
		$edit_term_url = admin_url( 'post.php?post=' . $form_id . '&action=edit#form_terms_options' );
1655
1656
	} else {
1657
		return false;
1658
	}
1659
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
1660
1661
	// Bailout: Check if term and conditions text is empty or not.
1662
	if ( empty( $terms ) ) {
1663
		if ( is_user_logged_in() && current_user_can( 'edit_give_forms' ) ) {
1664
			echo sprintf( __( 'Please enter valid terms and conditions in <a href="%s">this form\'s settings</a>.', 'give' ), $edit_term_url );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'sprintf'
Loading history...
1665
		}
1666
1667
		return false;
1668
	}
1669
1670
	/**
1671
	 * Filter the form term content
1672
	 *
1673
	 * @since  2.1.5
1674
	 */
1675
	$terms = apply_filters( 'give_the_term_content',  wpautop( do_shortcode( $terms ) ), $terms, $form_id );
1676
1677
	?>
1678
	<fieldset id="give_terms_agreement">
1679
		<legend><?php echo apply_filters( 'give_terms_agreement_text', esc_html__( 'Terms', 'give' ) ); ?></legend>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
1680
		<div id="give_terms" class="give_terms-<?php echo $form_id; ?>" style="display:none;">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1681
			<?php
1682
			/**
1683
			 * Fires while rendering terms of agreement, before the fields.
1684
			 *
1685
			 * @since 1.0
1686
			 */
1687
			do_action( 'give_before_terms' );
1688
1689
			echo $terms;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$terms'
Loading history...
1690
			/**
1691
			 * Fires while rendering terms of agreement, after the fields.
1692
			 *
1693
			 * @since 1.0
1694
			 */
1695
			do_action( 'give_after_terms' );
1696
			?>
1697
		</div>
1698
		<div id="give_show_terms">
1699
			<a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1700
			   aria-controls="give_terms"><?php esc_html_e( 'Show Terms', 'give' ); ?></a>
1701
			<a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1702
			   aria-controls="give_terms" style="display:none;"><?php esc_html_e( 'Hide Terms', 'give' ); ?></a>
1703
		</div>
1704
1705
		<input name="give_agree_to_terms" class="required" type="checkbox"
1706
			   id="give_agree_to_terms-<?php echo $form_id; ?>" value="1" required aria-required="true"/>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1707
		<label for="give_agree_to_terms-<?php echo $form_id; ?>"><?php echo $label; ?></label>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$label'
Loading history...
1708
1709
	</fieldset>
1710
	<?php
1711
}
1712
1713
add_action( 'give_donation_form_after_cc_form', 'give_terms_agreement', 8888, 1 );
1714
1715
/**
1716
 * Checkout Final Total.
1717
 *
1718
 * Shows the final donation total at the bottom of the checkout page.
1719
 *
1720
 * @since  1.0
1721
 *
1722
 * @param  int $form_id The form ID.
1723
 *
1724
 * @return void
1725
 */
1726
function give_checkout_final_total( $form_id ) {
1727
1728
	$total = isset( $_POST['give_total'] ) ?
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
1729
		apply_filters( 'give_donation_total', give_maybe_sanitize_amount( $_POST['give_total'] ) ) :
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
1730
		give_get_default_form_amount( $form_id );
1731
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
1732
1733
	// Only proceed if give_total available.
1734
	if ( empty( $total ) ) {
1735
		return;
1736
	}
1737
	?>
1738
	<p id="give-final-total-wrap" class="form-wrap ">
1739
		<?php
1740
		/**
1741
		 * Fires before the donation total label
1742
		 *
1743
		 * @since 2.0.5
1744
		 */
1745
		do_action( 'give_donation_final_total_label_before', $form_id );
1746
		?>
1747
		<span class="give-donation-total-label">
1748
			<?php echo apply_filters( 'give_donation_total_label', esc_html__( 'Donation Total:', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
1749
		</span>
1750
		<span class="give-final-total-amount"
1751
			  data-total="<?php echo give_format_amount( $total, array( 'sanitize' => false ) ); ?>">
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_format_amount'
Loading history...
1752
			<?php
1753
			echo give_currency_filter( give_format_amount( $total, array(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_currency_filter'
Loading history...
1754
				'sanitize' => false,
1755
				'currency' => give_get_currency( $form_id ),
1756
			) ), array( 'currency_code' => give_get_currency( $form_id ) ) ); ?>
1757
		</span>
1758
		<?php
1759
		/**
1760
		 * Fires after the donation final total label
1761
		 *
1762
		 * @since 2.0.5
1763
		 */
1764
		do_action( 'give_donation_final_total_label_after', $form_id );
1765
		?>
1766
	</p>
1767
	<?php
1768
}
1769
1770
add_action( 'give_donation_form_before_submit', 'give_checkout_final_total', 999 );
1771
1772
/**
1773
 * Renders the Checkout Submit section.
1774
 *
1775
 * @since  1.0
1776
 *
1777
 * @param int   $form_id The donation form ID.
1778
 * @param array $args    List of arguments.
1779
 *
1780
 * @return void
1781
 */
1782
function give_checkout_submit( $form_id, $args ) {
1783
	?>
1784
	<fieldset id="give_purchase_submit" class="give-donation-submit">
1785
		<?php
1786
		/**
1787
		 * Fire before donation form submit.
1788
		 *
1789
		 * @since 1.7
1790
		 */
1791
		do_action( 'give_donation_form_before_submit', $form_id, $args );
1792
1793
		give_checkout_hidden_fields( $form_id );
1794
1795
		echo give_get_donation_form_submit_button( $form_id );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_donation_form_submit_button'
Loading history...
1796
1797
		/**
1798
		 * Fire after donation form submit.
1799
		 *
1800
		 * @since 1.7
1801
		 */
1802
		do_action( 'give_donation_form_after_submit', $form_id, $args );
1803
		?>
1804
	</fieldset>
1805
	<?php
1806
}
1807
1808
add_action( 'give_donation_form_after_cc_form', 'give_checkout_submit', 9999, 2 );
1809
1810
/**
1811
 * Give Donation form submit button.
1812
 *
1813
 * @since  1.8.8
1814
 *
1815
 * @param  int $form_id The form ID.
1816
 *
1817
 * @return string
1818
 */
1819
function give_get_donation_form_submit_button( $form_id ) {
1820
1821
	$display_label_field = give_get_meta( $form_id, '_give_checkout_label', true );
1822
	$display_label       = ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) );
1823
	ob_start();
1824
	?>
1825
	<div class="give-submit-button-wrap give-clearfix">
1826
		<input type="submit" class="give-submit give-btn" id="give-purchase-button" name="give-purchase"
1827
			   value="<?php echo $display_label; ?>" data-before-validation-label="<?php echo $display_label; ?>" />
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$display_label'
Loading history...
1828
		<span class="give-loading-animation"></span>
1829
	</div>
1830
	<?php
1831
	return apply_filters( 'give_donation_form_submit_button', ob_get_clean(), $form_id );
1832
}
1833
1834
/**
1835
 * Show Give Goals.
1836
 *
1837
 * @since  1.0
1838
 * @since  1.6   Add template for Give Goals Shortcode.
1839
 *               More info is on https://github.com/WordImpress/Give/issues/411
1840
 *
1841
 * @param  int   $form_id The form ID.
1842
 * @param  array $args    An array of form arguments.
1843
 *
1844
 * @return mixed
1845
 */
1846
function give_show_goal_progress( $form_id, $args = array() ) {
1847
1848
	ob_start();
1849
	give_get_template( 'shortcode-goal', array( 'form_id' => $form_id, 'args' => $args ) );
1850
1851
	/**
1852
	 * Filter progress bar output
1853
	 *
1854
	 * @since 2.0
1855
	 */
1856
	echo apply_filters( 'give_goal_output', ob_get_clean(), $form_id, $args );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
1857
1858
	return true;
1859
}
1860
1861
add_action( 'give_pre_form', 'give_show_goal_progress', 10, 2 );
1862
1863
/**
1864
 * Show Give Totals Progress.
1865
 *
1866
 * @since  2.1
1867
 *
1868
 * @param  int $total      Total amount based on shortcode parameter.
1869
 * @param  int $total_goal Total Goal amount passed by Admin.
1870
 *
1871
 * @return mixed
1872
 */
1873
function give_show_goal_totals_progress( $total, $total_goal ) {
1874
1875
	// Bail out if total goal is set as an array.
1876
	if ( isset( $total_goal ) && is_array( $total_goal ) ) {
1877
		return false;
1878
	}
1879
1880
	ob_start();
1881
	give_get_template( 'shortcode-totals-progress', array( 'total' => $total, 'total_goal' => $total_goal ) );
1882
1883
	echo apply_filters( 'give_total_progress_output', ob_get_clean() );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
1884
1885
	return true;
1886
}
1887
1888
add_action( 'give_pre_form', 'give_show_goal_totals_progress', 10, 2 );
1889
1890
/**
1891
 * Get form content position.
1892
 *
1893
 * @since  1.8
1894
 *
1895
 * @param  $form_id
1896
 * @param  $args
1897
 *
1898
 * @return mixed|string
1899
 */
1900
function give_get_form_content_placement( $form_id, $args ) {
1901
	$show_content = '';
1902
1903
	if ( isset( $args['show_content'] ) && ! empty( $args['show_content'] ) ) {
1904
		// Content positions.
1905
		$content_placement = array(
1906
			'above' => 'give_pre_form',
1907
			'below' => 'give_post_form',
1908
		);
1909
1910
		// Check if content position already decoded.
1911
		if ( in_array( $args['show_content'], $content_placement ) ) {
1912
			return $args['show_content'];
1913
		}
1914
1915
		$show_content = ( 'none' !== $args['show_content'] ? $content_placement[ $args['show_content'] ] : '' );
1916
1917
	} elseif ( give_is_setting_enabled( give_get_meta( $form_id, '_give_display_content', true ) ) ) {
1918
		$show_content = give_get_meta( $form_id, '_give_content_placement', true );
1919
1920
	} elseif ( 'none' !== give_get_meta( $form_id, '_give_content_option', true ) ) {
1921
		// Backward compatibility for _give_content_option for v18.
1922
		$show_content = give_get_meta( $form_id, '_give_content_option', true );
1923
	}
1924
1925
	return $show_content;
1926
}
1927
1928
/**
1929
 * Adds Actions to Render Form Content.
1930
 *
1931
 * @since  1.0
1932
 *
1933
 * @param  int   $form_id The form ID.
1934
 * @param  array $args    An array of form arguments.
1935
 *
1936
 * @return void|bool
1937
 */
1938
function give_form_content( $form_id, $args ) {
1939
1940
	$show_content = give_get_form_content_placement( $form_id, $args );
1941
1942
	// Bailout.
1943
	if ( empty( $show_content ) ) {
1944
		return false;
1945
	}
1946
1947
	// Add action according to value.
1948
	add_action( $show_content, 'give_form_display_content', 10, 2 );
1949
}
1950
1951
add_action( 'give_pre_form_output', 'give_form_content', 10, 2 );
1952
1953
/**
1954
 * Renders Post Form Content.
1955
 *
1956
 * Displays content for Give forms; fired by action from give_form_content.
1957
 *
1958
 * @since  1.0
1959
 *
1960
 * @param  int   $form_id The form ID.
1961
 * @param  array $args    An array of form arguments.
1962
 *
1963
 * @return void
1964
 */
1965
function give_form_display_content( $form_id, $args ) {
1966
	$content      = give_get_meta( $form_id, '_give_form_content', true );
1967
	$show_content = give_get_form_content_placement( $form_id, $args );
1968
1969
	if ( give_is_setting_enabled( give_get_option( 'the_content_filter' ) ) ) {
1970
		$content = apply_filters( 'the_content', $content );
1971
	} else{
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
1972
		$content = wpautop( do_shortcode( $content ) );
1973
	}
1974
1975
	$output = sprintf(
1976
		'<div id="give-form-content-%s" class="give-form-content-wrap %s-content">%s</div>',
1977
		$form_id,
1978
		$show_content,
1979
		$content
1980
	);
1981
1982
	/**
1983
	 * Filter form content html
1984
	 *
1985
	 * @since 1.0
1986
	 *
1987
	 * @param string $output
1988
	 * @param int    $form_id
1989
	 * @param array  $args
1990
	 */
1991
	echo apply_filters( 'give_form_content_output', $output, $form_id, $args );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
1992
1993
	// remove action to prevent content output on addition forms on page.
1994
	// @see: https://github.com/WordImpress/Give/issues/634.
1995
	remove_action( $show_content, 'give_form_display_content' );
1996
}
1997
1998
/**
1999
 * Renders the hidden Checkout fields.
2000
 *
2001
 * @since 1.0
2002
 *
2003
 * @param  int $form_id The form ID.
2004
 *
2005
 * @return void
2006
 */
2007
function give_checkout_hidden_fields( $form_id ) {
2008
2009
	/**
2010
	 * Fires while rendering hidden checkout fields, before the fields.
2011
	 *
2012
	 * @since 1.0
2013
	 *
2014
	 * @param int $form_id The form ID.
2015
	 */
2016
	do_action( 'give_hidden_fields_before', $form_id );
2017
2018
	if ( is_user_logged_in() ) { ?>
2019
		<input type="hidden" name="give-user-id" value="<?php echo get_current_user_id(); ?>"/>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'get_current_user_id'
Loading history...
2020
	<?php } ?>
2021
	<input type="hidden" name="give_action" value="purchase"/>
2022
	<input type="hidden" name="give-gateway" value="<?php echo give_get_chosen_gateway( $form_id ); ?>"/>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_chosen_gateway'
Loading history...
2023
	<?php
2024
	/**
2025
	 * Fires while rendering hidden checkout fields, after the fields.
2026
	 *
2027
	 * @since 1.0
2028
	 *
2029
	 * @param int $form_id The form ID.
2030
	 */
2031
	do_action( 'give_hidden_fields_after', $form_id );
2032
2033
}
2034
2035
/**
2036
 * Filter Success Page Content.
2037
 *
2038
 * Applies filters to the success page content.
2039
 *
2040
 * @since 1.0
2041
 *
2042
 * @param  string $content Content before filters.
2043
 *
2044
 * @return string $content Filtered content.
2045
 */
2046
function give_filter_success_page_content( $content ) {
2047
2048
	$give_options = give_get_settings();
2049
2050
	if ( isset( $give_options['success_page'] ) && isset( $_GET['payment-confirmation'] ) && is_page( $give_options['success_page'] ) ) {
2051
		if ( has_filter( 'give_payment_confirm_' . $_GET['payment-confirmation'] ) ) {
2052
			$content = apply_filters( 'give_payment_confirm_' . $_GET['payment-confirmation'], $content );
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
2053
		}
2054
	}
2055
2056
	return $content;
2057
}
2058
2059
add_filter( 'the_content', 'give_filter_success_page_content' );
2060
2061
/**
2062
 * Test Mode Frontend Warning.
2063
 *
2064
 * Displays a notice on the frontend for donation forms.
2065
 *
2066
 * @since 1.1
2067
 */
2068
function give_test_mode_frontend_warning() {
2069
2070
	if ( give_is_test_mode() ) {
2071
		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>';
2072
	}
2073
}
2074
2075
add_action( 'give_pre_form', 'give_test_mode_frontend_warning', 10 );
2076
2077
/**
2078
 * Members-only Form.
2079
 *
2080
 * If "Disable Guest Donations" and "Display Register / Login" is set to none.
2081
 *
2082
 * @since  1.4.1
2083
 *
2084
 * @param  string $final_output
2085
 * @param  array  $args
2086
 *
2087
 * @return string
2088
 */
2089
function give_members_only_form( $final_output, $args ) {
2090
2091
	$form_id = isset( $args['form_id'] ) ? $args['form_id'] : 0;
2092
2093
	//Sanity Check: Must have form_id & not be logged in.
2094
	if ( empty( $form_id ) || is_user_logged_in() ) {
2095
		return $final_output;
2096
	}
2097
2098
	//Logged in only and Register / Login set to none.
2099
	if ( give_logged_in_only( $form_id ) && give_show_login_register_option( $form_id ) == 'none' ) {
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
2100
2101
		$final_output = Give()->notices->print_frontend_notice( esc_html__( 'Please log in in order to complete your donation.', 'give' ), false );
2102
2103
		return apply_filters( 'give_members_only_output', $final_output, $form_id );
2104
2105
	}
2106
2107
	return $final_output;
2108
2109
}
2110
2111
add_filter( 'give_donate_form', 'give_members_only_form', 10, 2 );
2112
2113
2114
/**
2115
 * Add donation form hidden fields.
2116
 *
2117
 * @since 1.8.17
2118
 *
2119
 * @param int              $form_id
2120
 * @param array            $args
2121
 * @param Give_Donate_Form $form
2122
 */
2123
function __give_form_add_donation_hidden_field( $form_id, $args, $form ) {
2124
	$id_prefix = ! empty( $args['id_prefix'] ) ? $args['id_prefix'] : '';
2125
	?>
2126
	<input type="hidden" name="give-form-id-prefix" value="<?php echo $id_prefix; ?>"/>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$id_prefix'
Loading history...
2127
	<input type="hidden" name="give-form-id" value="<?php echo intval( $form_id ); ?>"/>
2128
	<input type="hidden" name="give-form-title" value="<?php echo esc_html( $form->post_title ); ?>"/>
2129
	<input type="hidden" name="give-current-url" value="<?php echo esc_url( give_get_current_page_url() ); ?>"/>
2130
	<input type="hidden" name="give-form-url" value="<?php echo esc_url( give_get_current_page_url() ); ?>"/>
2131
	<?php
2132
	// Get the custom option amount.
2133
	$custom_amount = give_get_meta( $form_id, '_give_custom_amount', true );
2134
2135
	// If custom amount enabled.
2136
	if ( give_is_setting_enabled( $custom_amount ) ) {
2137
		?>
2138
		<input type="hidden" name="give-form-minimum"
2139
		       value="<?php echo give_maybe_sanitize_amount( give_get_form_minimum_price( $form_id ) ); ?>"/>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_maybe_sanitize_amount'
Loading history...
2140
		<input type="hidden" name="give-form-maximum"
2141
		       value="<?php echo give_maybe_sanitize_amount( give_get_form_maximum_price( $form_id ) ); ?>"/>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_maybe_sanitize_amount'
Loading history...
2142
		<?php
2143
	}
2144
2145
	// WP nonce field.
2146
	echo str_replace(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'str_replace'
Loading history...
2147
		'/>',
2148
		'data-time="' . time() . '" data-nonce-life="' . give_get_nonce_life() . '"/>',
2149
		give_get_nonce_field( "give_donation_form_nonce_{$form_id}", 'give-form-hash', false )
2150
	);
2151
2152
	// Price ID hidden field for variable (multi-level) donation forms.
2153
	if ( give_has_variable_prices( $form_id ) ) {
2154
		// Get the default price ID.
2155
		$default_price = give_form_get_default_level( $form_id );
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $default_price is correct as give_form_get_default_level($form_id) (which targets give_form_get_default_level()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
2156
		$price_id      = isset( $default_price['_give_id']['level_id'] ) ? $default_price['_give_id']['level_id'] : 0;
2157
2158
		echo sprintf(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'sprintf'
Loading history...
2159
			'<input type="hidden" name="give-price-id" value="%s"/>',
2160
			$price_id
2161
		);
2162
	}
2163
}
2164
2165
add_action( 'give_donation_form_top', '__give_form_add_donation_hidden_field', 0, 3 );
2166
2167
/**
2168
 * Add currency settings on donation form.
2169
 *
2170
 * @since 1.8.17
2171
 *
2172
 * @param array            $form_html_tags
2173
 * @param Give_Donate_Form $form
2174
 *
2175
 * @return array
2176
 */
2177
function __give_form_add_currency_settings( $form_html_tags, $form ) {
2178
	$form_currency     = give_get_currency( $form->ID );
2179
	$currency_settings = give_get_currency_formatting_settings( $form_currency );
2180
2181
	// Check if currency exist.
2182
	if ( empty( $currency_settings ) ) {
2183
		return $form_html_tags;
2184
	}
2185
2186
	$form_html_tags['data-currency_symbol'] = give_currency_symbol( $form_currency );
2187
	$form_html_tags['data-currency_code']   = $form_currency;
2188
2189
	if ( ! empty( $currency_settings ) ) {
2190
		foreach ( $currency_settings as $key => $value ) {
2191
			$form_html_tags["data-{$key}"] = $value;
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
2192
		}
2193
	}
2194
2195
	return $form_html_tags;
2196
}
2197
2198
add_filter( 'give_form_html_tags', '__give_form_add_currency_settings', 0, 2 );
2199
2200
/**
2201
 * Adds classes to progress bar container.
2202
 *
2203
 * @since 2.1
2204
 *
2205
 * @param string $class_goal
2206
 *
2207
 * @return string
2208
 */
2209
function add_give_goal_progress_class( $class_goal ) {
0 ignored issues
show
Unused Code introduced by
The parameter $class_goal is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2210
	$class_goal = 'progress progress-striped active';
2211
2212
	return $class_goal;
2213
}
2214
2215
/**
2216
 * Adds classes to progress bar span tag.
2217
 *
2218
 * @since 2.1
2219
 *
2220
 * @param string $class_bar
2221
 *
2222
 * @return string
2223
 */
2224
function add_give_goal_progress_bar_class( $class_bar ) {
0 ignored issues
show
Unused Code introduced by
The parameter $class_bar is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2225
	$class_bar = 'bar';
2226
2227
	return $class_bar;
2228
}
2229
2230
/**
2231
 * Add a class to the form wrap on the grid page.
2232
 *
2233
 * @param array $class Array of form wrapper classes.
2234
 * @param int   $id    ID of the form.
2235
 * @param array $args  Additional args.
2236
 *
2237
 * @since 2.1
2238
 *
2239
 * @return array
2240
 */
2241
function add_class_for_form_grid( $class, $id, $args ) {
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2242
	$class[] = 'give-form-grid-wrap';
2243
2244
	foreach ( $class as $index => $item ) {
2245
		if( false !== strpos( $item, 'give-display-' ) ) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
2246
			unset( $class[$index] );
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
2247
		}
2248
	}
2249
2250
	return $class;
2251
}
2252
2253
/**
2254
 * Add hidden field to Form Grid page
2255
 *
2256
 * @param int              $form_id The form ID.
0 ignored issues
show
Bug introduced by
There is no parameter named $form_id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
2257
 * @param array            $args    An array of form arguments.
2258
 * @param Give_Donate_Form $form    Form object.
2259
 *
2260
 * @since 2.1
2261
 */
2262
function give_is_form_grid_page_hidden_field( $id, $args, $form ) {
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $form is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2263
	echo '<input type="hidden" name="is-form-grid" value="true" />';
2264
}
2265
2266
/**
2267
 * Redirect to the same paginated URL on the Form Grid page
2268
 * and adds query parameters to open the popup again after
2269
 * redirection.
2270
 *
2271
 * @param string $redirect URL for redirection.
2272
 * @param array  $args     Array of additional args.
2273
 *
2274
 * @since 2.1
2275
 * @return string
2276
 */
2277
function give_redirect_and_popup_form( $redirect, $args ) {
2278
2279
	// Check the page has Form Grid.
2280
	$is_form_grid = isset( $_POST['is-form-grid'] ) ? give_clean( $_POST['is-form-grid'] ) : '';
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
2281
2282
	if ( 'true' === $is_form_grid ) {
2283
2284
		$payment_mode = give_clean( $_POST['payment-mode'] );
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-validated input variable: $_POST
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
2285
		$form_id = $args['form-id'];
2286
2287
		// Get the URL without Query parameters.
2288
		$redirect = strtok( $redirect, '?' );
2289
2290
		// Add query parameters 'form-id' and 'payment-mode'.
2291
		$redirect = add_query_arg( array(
2292
			'form-id'      => $form_id,
2293
			'payment-mode' => $payment_mode,
2294
		), $redirect );
2295
	}
2296
2297
	// Return the modified URL.
2298
	return $redirect;
2299
}
2300
2301
add_filter( 'give_send_back_to_checkout', 'give_redirect_and_popup_form', 10, 2 );
2302