template.php ➔ give_user_info_fields()   F
last analyzed

Complexity

Conditions 34
Paths > 20000

Size

Total Lines 210

Duplication

Lines 41
Ratio 19.52 %

Code Coverage

Tests 0
CRAP Score 1190

Importance

Changes 0
Metric Value
cc 34
nc 69120
nop 1
dl 41
loc 210
ccs 0
cts 40
cp 0
crap 1190
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(
38 1
		'give_form_args_defaults', array(
39
			'form_id' => $form_id,
40 1
		)
41
	);
42 1
43
	$args = wp_parse_args( $args, $defaults );
44
45 1
	$form = new Give_Donate_Form( $args['form_id'] );
46
47
	// Bail out, if no form ID.
48
	if ( empty( $form->ID ) ) {
49 1
		return false;
50
	}
51 1
52 1
	$args['id_prefix'] = "{$form_id}-{$count}";
53 1
	$payment_mode      = give_get_chosen_gateway( $form->ID );
54 1
55 1
	$form_action = add_query_arg(
56
		apply_filters(
57
			'give_form_action_args', array(
58 1
				'payment-mode' => $payment_mode,
59
			)
60
		),
61
		give_get_current_page_url()
62 1
	);
63 1
64 1
	// Sanity Check: Donation form not published or user doesn't have permission to view drafts.
65
	if (
66 1
		( 'publish' !== $form->post_status && ! current_user_can( 'edit_give_forms', $form->ID ) )
67 1
		|| ( 'trash' === $form->post_status )
68 1
	) {
69
		return false;
70
	}
71 1
72 1
	// Get the form wrap CSS classes.
73
	$form_wrap_classes = $form->get_form_wrap_classes( $args );
74 1
75 1
	// Get the <form> tag wrap CSS classes.
76
	$form_classes = $form->get_form_classes( $args );
77
78 1
	ob_start();
79 1
80 1
	/**
81
	 * Fires while outputting donation form, before the form wrapper div.
82 1
	 *
83 1
	 * @since 1.0
84
	 *
85
	 * @param int   $form_id The form ID.
86 1
	 * @param array $args    An array of form arguments.
87
	 */
88
	do_action( 'give_pre_form_output', $form->ID, $args, $form );
89
90
	?>
91
	<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...
92
		<?php
93
		if ( $form->is_close_donation_form() ) {
94
95
			$form_title = ! is_singular( 'give_forms' ) ? apply_filters( 'give_form_title', '<h2 class="give-form-title">' . get_the_title( $form_id ) . '</h2>' ) : '';
96
97
			// Get Goal thank you message.
98
			$goal_achieved_message = get_post_meta( $form->ID, '_give_form_goal_achieved_message', true );
99
			$goal_achieved_message = ! empty( $goal_achieved_message ) ? $form_title . apply_filters( 'the_content', $goal_achieved_message ) : '';
100
101
			// Print thank you message.
102
			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...
103
104
		} else {
105
			/**
106
			 * Show form title:
107
			 * 1. if show_title params set to true
108
			 * 2. if admin set form display_style to button
109
			 */
110
			$form_title = apply_filters( 'give_form_title', '<h2 class="give-form-title">' . get_the_title( $form_id ) . '</h2>' );
111 1
			if (
0 ignored issues
show
introduced by
Found "== true". Use Yoda Condition checks, you must
Loading history...
112
				(
113
					( isset( $args['show_title'] ) && $args['show_title'] == true )
114
					|| ( 'button' === get_post_meta( $form_id, '_give_payment_display', true ) )
115
				)
116
				&& ! doing_action( 'give_single_form_summary' )
117
			) {
118
				echo $form_title;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_title'
Loading history...
119
			}
120
121
			/**
122
			 * Fires while outputting donation form, before the form.
123
			 *
124
			 * @since 1.0
125
			 *
126
			 * @param int              $form_id The form ID.
127
			 * @param array            $args    An array of form arguments.
128
			 * @param Give_Donate_Form $form    Form object.
129
			 */
130
			do_action( 'give_pre_form', $form->ID, $args, $form );
131
132
			// Set form html tags.
133
			$form_html_tags = array(
134
				'id'      => "give-form-{$args['id_prefix']}",
135 1
				'class'   => $form_classes,
136
				'action'  => esc_url_raw( $form_action ),
137 1
				'data-id' => $args['id_prefix'],
138 1
			);
139
140 1
			/**
141 1
			 * Filter the form html tags.
142 1
			 *
143 1
			 * @since 1.8.17
144 1
			 *
145
			 * @param array            $form_html_tags Array of form html tags.
146
			 * @param Give_Donate_Form $form           Form object.
147
			 */
148
			$form_html_tags = apply_filters( 'give_form_html_tags', (array) $form_html_tags, $form );
149 1
			?>
150
			<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...
151 1
				<!-- The following field is for robots only, invisible to humans: -->
152
				<span class="give-hidden" style="display: none !important;">
153 1
					<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...
154
					<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...
155
					       class="give-honeypot give-hidden"/>
156
				</span>
157
158
				<?php
159
				/**
160
				 * Fires while outputting donation form, before all other fields.
161
				 *
162
				 * @since 1.0
163
				 *
164
				 * @param int              $form_id The form ID.
165
				 * @param array            $args    An array of form arguments.
166
				 * @param Give_Donate_Form $form    Form object.
167
				 */
168
				do_action( 'give_donation_form_top', $form->ID, $args, $form );
169
170
				/**
171
				 * Fires while outputting donation form, for payment gateway fields.
172
				 *
173 1
				 * @since 1.7
174
				 *
175 1
				 * @param int              $form_id The form ID.
176
				 * @param array            $args    An array of form arguments.
177 1
				 * @param Give_Donate_Form $form    Form object.
178 1
				 */
179
				do_action( 'give_payment_mode_select', $form->ID, $args, $form );
180
181
				/**
182
				 * Fires while outputting donation form, after all other fields.
183
				 *
184
				 * @since 1.0
185
				 *
186
				 * @param int              $form_id The form ID.
187
				 * @param array            $args    An array of form arguments.
188
				 * @param Give_Donate_Form $form    Form object.
189
				 */
190
				do_action( 'give_donation_form_bottom', $form->ID, $args, $form );
191
192
				?>
193
			</form>
194
195
			<?php
196
			/**
197
			 * Fires while outputting donation form, after the form.
198
			 *
199 1
			 * @since 1.0
200
			 *
201 1
			 * @param int              $form_id The form ID.
202
			 * @param array            $args    An array of form arguments.
203
			 * @param Give_Donate_Form $form    Form object.
204
			 */
205 1
			do_action( 'give_post_form', $form->ID, $args, $form );
206
207 1
		}
208
		?>
209 1
210
	</div><!--end #give-form-<?php echo absint( $form->ID ); ?>-->
211 1
	<?php
212
213 1
	/**
214
	 * Fires while outputting donation form, after the form wrapper div.
215
	 *
216 1
	 * @since 1.0
217 1
	 *
218 1
	 * @param int   $form_id The form ID.
219
	 * @param array $args    An array of form arguments.
220
	 */
221
	do_action( 'give_post_form_output', $form->ID, $args );
222 1
223
	$final_output = ob_get_clean();
224 1
	$count ++;
225
226
	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...
227
}
228
229
/**
230 1
 * Give Show Donation Form.
231 1
 *
232
 * Renders the Donation Form, hooks are provided to add to the checkout form.
233
 * The default Donation Form rendered displays a list of the enabled payment
234
 * gateways, a user registration form (if enable) and a credit card info form
235
 * if credit cards are enabled.
236
 *
237
 * @since  1.0
238
 *
239
 * @param  int $form_id The form ID.
240
 *
241
 * @return string
242
 */
243
function give_show_purchase_form( $form_id, $args ) {
244
245
	$payment_mode = give_get_chosen_gateway( $form_id );
246
247 1
	if ( ! isset( $form_id ) && isset( $_POST['give_form_id'] ) ) {
248
		$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...
249
	}
250
251
	/**
252
	 * Fire before donation form render.
253
	 *
254
	 * @since 1.7
255
	 */
256
	do_action( 'give_payment_fields_top', $form_id );
257
258
	if ( give_can_checkout() && isset( $form_id ) ) {
259
260
		/**
261
		 * Fires while displaying donation form, before registration login.
262 1
		 *
263
		 * @since 1.7
264
		 */
265
		do_action( 'give_donation_form_before_register_login', $form_id, $args );
266
267
		/**
268
		 * Fire when register/login form fields render.
269
		 *
270
		 * @since 1.7
271
		 */
272
		do_action( 'give_donation_form_register_login_fields', $form_id, $args );
273
274
		/**
275
		 * Fire when credit card form fields render.
276
		 *
277
		 * @since 1.7
278
		 */
279
		do_action( 'give_donation_form_before_cc_form', $form_id, $args );
280 1
281
		// Load the credit card form and allow gateways to load their own if they wish.
282 1
		if ( has_action( 'give_' . $payment_mode . '_cc_form' ) ) {
283 1
			/**
284 1
			 * Fires while displaying donation form, credit card form fields for a given gateway.
285 1
			 *
286 1
			 * @since 1.0
287 1
			 *
288 1
			 * @param int $form_id The form ID.
289
			 */
290 1
			do_action( "give_{$payment_mode}_cc_form", $form_id, $args );
291
		} else {
292
			/**
293 1
			 * Fires while displaying donation form, credit card form fields.
294
			 *
295
			 * @since 1.0
296
			 *
297
			 * @param int $form_id The form ID.
298
			 */
299
			do_action( 'give_cc_form', $form_id, $args );
300
		}
301
302
		/**
303
		 * Fire after credit card form fields render.
304
		 *
305
		 * @since 1.7
306
		 */
307
		do_action( 'give_donation_form_after_cc_form', $form_id, $args );
308
309
	} else {
310
		/**
311
		 * Fire if user can not donate.
312
		 *
313
		 * @since 1.7
314
		 */
315 1
		do_action( 'give_donation_form_no_access', $form_id );
316
317
	}
318
319
	/**
320
	 * Fire after donation form rendered.
321
	 *
322
	 * @since 1.7
323
	 */
324
	do_action( 'give_payment_fields_bottom', $form_id, $args );
325
}
326 1
327
add_action( 'give_donation_form', 'give_show_purchase_form', 10, 2 );
328
329
/**
330
 * Give Show Login/Register Form Fields.
331
 *
332
 * @since  1.4.1
333
 *
334 1
 * @param  int $form_id The form ID.
335 1
 *
336 1
 * @return void
337
 */
338 1
function give_show_register_login_fields( $form_id ) {
339 1
340
	$show_register_form = give_show_login_register_option( $form_id );
341
342
	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...
343
		?>
344
		<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...
345
			<?php
346
			/**
347
			 * Fire if user registration form render.
348
			 *
349
			 * @since 1.7
350
			 */
351
			do_action( 'give_donation_form_register_fields', $form_id );
352
			?>
353
		</div>
354
	<?php
355
	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...
356 1
		?>
357 1
		<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...
358 1
			<?php
359 1
			/**
360 1
			 * Fire if user login form render.
361 1
			 *
362 1
			 * @since 1.7
363
			 */
364 1
			do_action( 'give_donation_form_login_fields', $form_id );
365 1
			?>
366
		</div>
367
	<?php
368 1
	endif;
369
370 1
	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...
371
		/**
372 1
		 * Fire when user info render.
373 1
		 *
374 1
		 * @since 1.7
375 1
		 */
376
		do_action( 'give_donation_form_after_user_info', $form_id );
377 1
	}
378 1
}
379 1
380 1
add_action( 'give_donation_form_register_login_fields', 'give_show_register_login_fields' );
381 1
382
/**
383 1
 * Donation Amount Field.
384
 *
385
 * Outputs the donation amount field that appears at the top of the donation forms. If the user has custom amount
386 1
 * enabled the field will output as a customizable input.
387
 *
388
 * @since  1.0
389
 *
390
 * @param  int   $form_id The form ID.
391
 * @param  array $args    An array of form arguments.
392
 *
393
 * @return void
394 1
 */
395
function give_output_donation_amount_top( $form_id = 0, $args = array() ) {
396 1
397
	$give_options        = give_get_settings();
398
	$variable_pricing    = give_has_variable_prices( $form_id );
399
	$allow_custom_amount = give_get_meta( $form_id, '_give_custom_amount', true );
400
	$currency_position   = isset( $give_options['currency_position'] ) ? $give_options['currency_position'] : 'before';
401
	$symbol              = give_currency_symbol( give_get_currency( $form_id, $args ) );
402
	$currency_output     = '<span class="give-currency-symbol give-currency-position-' . $currency_position . '">' . $symbol . '</span>';
403
	$default_amount      = give_format_amount(
404
		give_get_default_form_amount( $form_id ), array(
405
			'sanitize' => false,
406
			'currency' => give_get_currency( $form_id ),
407
		)
408
	);
409
	$custom_amount_text  = give_get_meta( $form_id, '_give_custom_amount_text', true );
410
411
	/**
412
	 * Fires while displaying donation form, before donation level fields.
413
	 *
414
	 * @since 1.0
415
	 *
416
	 * @param int   $form_id The form ID.
417
	 * @param array $args    An array of form arguments.
418
	 */
419
	do_action( 'give_before_donation_levels', $form_id, $args );
420
421
	// Set Price, No Custom Amount Allowed means hidden price field.
422
	if ( ! give_is_setting_enabled( $allow_custom_amount ) ) {
423
		?>
424
		<label class="give-hidden" for="give-amount-hidden"><?php esc_html_e( 'Donation Amount:', 'give' ); ?></label>
425
		<input id="give-amount" class="give-amount-hidden" type="hidden" name="give-amount"
426
		       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...
427
		<div class="set-price give-donation-amount form-row-wide">
428
			<?php
429
			if ( 'before' === $currency_position ) {
430
				echo $currency_output;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$currency_output'
Loading history...
431
			}
432
			?>
433
			<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...
434
			<?php
435
			if ( 'after' === $currency_position ) {
436
				echo $currency_output;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$currency_output'
Loading history...
437
			}
438
			?>
439
		</div>
440
		<?php
441
	} else {
442
		// Custom Amount Allowed.
443
		?>
444
		<div class="give-total-wrap">
445
			<div class="give-donation-amount form-row-wide">
446
				<?php
447
				if ( 'before' === $currency_position ) {
448
					echo $currency_output;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$currency_output'
Loading history...
449
				}
450
				?>
451
				<label class="give-hidden" for="give-amount"><?php esc_html_e( 'Donation Amount:', 'give' ); ?></label>
452 1
				<input class="give-text-input give-amount-top" id="give-amount" name="give-amount" type="tel"
453 1
				       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...
454
				<?php
455
				if ( 'after' === $currency_position ) {
456
					echo $currency_output;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$currency_output'
Loading history...
457
				}
458
				?>
459
			</div>
460
		</div>
461
		<?php
462
	}
463
464
	/**
465
	 * Fires while displaying donation form, after donation amounf field(s).
466 1
	 *
467 1
	 * @since 1.0
468 1
	 *
469
	 * @param int   $form_id The form ID.
470
	 * @param array $args    An array of form arguments.
471 1
	 */
472
	do_action( 'give_after_donation_amount', $form_id, $args );
473
474
	// Custom Amount Text
475 1
	if ( ! $variable_pricing && give_is_setting_enabled( $allow_custom_amount ) && ! empty( $custom_amount_text ) ) {
476 1
		?>
477
		<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...
478 1
		<?php
479
	}
480 1
481 1
	// Output Variable Pricing Levels.
482
	if ( $variable_pricing ) {
483
		give_output_levels( $form_id );
484
	}
485
486
	/**
487
	 * Fires while displaying donation form, after donation level fields.
488
	 *
489
	 * @since 1.0
490
	 *
491
	 * @param int   $form_id The form ID.
492
	 * @param array $args    An array of form arguments.
493
	 */
494
	do_action( 'give_after_donation_levels', $form_id, $args );
495
}
496
497
add_action( 'give_donation_form_top', 'give_output_donation_amount_top', 10, 2 );
498
499
/**
500
 * Outputs the Donation Levels in various formats such as dropdown, radios, and buttons.
501
 *
502
 * @since  1.0
503
 *
504
 * @param  int $form_id The form ID.
505
 *
506
 * @return string Donation levels.
507
 */
508
function give_output_levels( $form_id ) {
509
510
	/**
511
	 * Filter the variable pricing
512
	 *
513
	 * @since      1.0
514
	 * @deprecated 2.2 Use give_get_donation_levels filter instead of give_form_variable_prices.
515
	 *                 Check Give_Donate_Form::get_prices().
516
	 *
517
	 * @param array $prices Array of variable prices.
518
	 * @param int   $form   Form ID.
519
	 */
520
	$prices = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $form_id ), $form_id );
521
522
	$display_style      = give_get_meta( $form_id, '_give_display_style', true );
523
	$custom_amount      = give_get_meta( $form_id, '_give_custom_amount', true );
524
	$custom_amount_text = give_get_meta( $form_id, '_give_custom_amount_text', true );
525
526
	if ( empty( $custom_amount_text ) ) {
527
		$custom_amount_text = esc_html__( 'Give a Custom Amount', 'give' );
528
	}
529
530
	$output = '';
531
532
	switch ( $display_style ) {
533 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...
534
			$output .= '<ul id="give-donation-level-button-wrap" class="give-donation-levels-wrap give-list-inline">';
535
536
			foreach ( $prices as $price ) {
537
				$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 );
538
				$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 );
539
540
				$formatted_amount = give_format_amount(
541
					$price['_give_amount'], array(
542
						'sanitize' => false,
543
						'currency' => give_get_currency( $form_id ),
544
					)
545
				);
546
547
				$output .= sprintf(
548
					'<li><button type="button" data-price-id="%1$s" class="%2$s" value="%3$s" data-default="%4$s">%5$s</button></li>',
549
					$price['_give_id']['level_id'],
550
					$level_classes,
551
					$formatted_amount,
552
					array_key_exists( '_give_default', $price ) ? 1 : 0,
553
					$level_text
554
				);
555
			}
556
557
			// Custom Amount.
558
			if (
559
				give_is_setting_enabled( $custom_amount )
560
				&& ! empty( $custom_amount_text )
561
			) {
562
563
				$output .= sprintf(
564
					'<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>',
565
					$custom_amount_text
566
				);
567
			}
568
569
			$output .= '</ul>';
570
571
			break;
572
573 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...
574
			$output .= '<ul id="give-donation-level-radio-list" class="give-donation-levels-wrap">';
575
576
			foreach ( $prices as $price ) {
577
				$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 );
578
				$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 );
579
580
				$formatted_amount = give_format_amount(
581
					$price['_give_amount'], array(
582
						'sanitize' => false,
583
						'currency' => give_get_currency( $form_id ),
584
					)
585
				);
586
587
				$output .= sprintf(
588
					'<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>',
589
					$price['_give_id']['level_id'],
590
					$level_classes,
591
					$formatted_amount,
592
					( give_is_default_level_id( $price ) ? 'checked="checked"' : '' ),
593
					array_key_exists( '_give_default', $price ) ? 1 : 0,
594
					$level_text
595
				);
596
			}
597
598
			// Custom Amount.
599
			if (
600
				give_is_setting_enabled( $custom_amount )
601
				&& ! empty( $custom_amount_text )
602
			) {
603
				$output .= sprintf(
604
					'<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>',
605
					$custom_amount_text
606
				);
607
			}
608
609
			$output .= '</ul>';
610
611
			break;
612
613
		case 'dropdown':
614
			$output .= '<label for="give-donation-level-select-' . $form_id . '" class="give-hidden">' . esc_html__( 'Choose Your Donation Amount', 'give' ) . ':</label>';
615
			$output .= '<select id="give-donation-level-select-' . $form_id . '" class="give-select give-select-level give-donation-levels-wrap">';
616
617
			// first loop through prices.
618
			foreach ( $prices as $price ) {
619
				$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 );
620
				$level_classes = apply_filters(
621
					'give_form_level_classes', 'give-donation-level-' . $price['_give_id']['level_id'] . ( give_is_default_level_id( $price ) ? ' give-default-level' : '' ), $form_id,
622
					$price
623
				);
624
625
				$formatted_amount = give_format_amount(
626
					$price['_give_amount'], array(
627
						'sanitize' => false,
628
						'currency' => give_get_currency( $form_id ),
629
					)
630
				);
631
632
				$output .= sprintf(
633
					'<option data-price-id="%1$s" class="%2$s" value="%3$s" %4$s data-default="%5$s">%6$s</option>',
634
					$price['_give_id']['level_id'],
635
					$level_classes,
636
					$formatted_amount,
637
					( give_is_default_level_id( $price ) ? 'selected="selected"' : '' ),
638
					array_key_exists( '_give_default', $price ) ? 1 : 0,
639
					$level_text
640
				);
641
			}
642
643
			// Custom Amount.
644
			if ( give_is_setting_enabled( $custom_amount ) && ! empty( $custom_amount_text ) ) {
645
				$output .= sprintf(
646
					'<option data-price-id="custom" class="give-donation-level-custom" value="custom">%1$s</option>',
647
					$custom_amount_text
648
				);
649
			}
650
651
			$output .= '</select>';
652
653
			break;
654
	}
655
656
	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...
657
}
658
659
/**
660
 * Display Reveal & Lightbox Button.
661
 *
662
 * Outputs a button to reveal form fields.
663
 *
664
 * @since  1.0
665
 *
666
 * @param  int   $form_id The form ID.
667
 * @param  array $args    An array of form arguments.
668
 *
669
 * @return string Checkout button.
670
 */
671
function give_display_checkout_button( $form_id, $args ) {
672
673
	$display_option = ( isset( $args['display_style'] ) && ! empty( $args['display_style'] ) )
674
		? $args['display_style']
675
		: give_get_meta( $form_id, '_give_payment_display', true );
676
677
	if ( 'button' === $display_option ) {
678
		$display_option = 'modal';
679
	} elseif ( $display_option === 'onpage' ) {
0 ignored issues
show
introduced by
Found "=== '". Use Yoda Condition checks, you must
Loading history...
680
		return '';
681
	}
682
683
	$display_label_field = give_get_meta( $form_id, '_give_reveal_label', true );
684
	$display_label       = ! empty( $args['continue_button_title'] ) ? $args['continue_button_title'] : ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) );
685
686
	$output = '<button type="button" class="give-btn give-btn-' . $display_option . '">' . $display_label . '</button>';
687
688
	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...
689
}
690
691
add_action( 'give_after_donation_levels', 'give_display_checkout_button', 10, 2 );
692
693
/**
694
 * Shows the User Info fields in the Personal Info box, more fields can be added via the hooks provided.
695
 *
696
 * @since  1.0
697
 *
698
 * @param  int $form_id The form ID.
699
 *
700
 * @see    For Pattern Attribute: https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Form_validation
701
 *
702
 * @return void
703
 */
704
function give_user_info_fields( $form_id ) {
705
706
	// Get user info.
707
	$give_user_info = _give_get_prefill_form_field_values( $form_id );
708
	$title          = ! empty( $give_user_info['give_title'] ) ? $give_user_info['give_title'] : '';
709
	$first_name     = ! empty( $give_user_info['give_first'] ) ? $give_user_info['give_first'] : '';
710
	$last_name      = ! empty( $give_user_info['give_last'] ) ? $give_user_info['give_last'] : '';
711
	$company_name   = ! empty( $give_user_info['company_name'] ) ? $give_user_info['company_name'] : '';
712
	$email          = ! empty( $give_user_info['give_email'] ) ? $give_user_info['give_email'] : '';
713
	$title_prefixes = give_get_name_title_prefixes( $form_id );
714
715
	/**
716
	 * Fire before user personal information fields
717
	 *
718
	 * @since 1.7
719
	 */
720
	do_action( 'give_donation_form_before_personal_info', $form_id );
721
722
	$title_prefix_classes = '';
723
	if ( give_is_name_title_prefix_enabled( $form_id ) ) {
724
		$title_prefix_classes = 'give-title-prefix-wrap';
725
	}
726
	?>
727
	<fieldset id="give_checkout_user_info" class="<?php echo esc_html( $title_prefix_classes ); ?>">
728
		<legend>
729
			<?php echo esc_html( apply_filters( 'give_checkout_personal_info_text', __( 'Personal Info', 'give' ) ) ); ?>
730
		</legend>
731
732
		<?php if ( give_is_name_title_prefix_enabled( $form_id ) && is_array( $title_prefixes ) && count( $title_prefixes ) > 0 ) { ?>
733
			<p id="give-title-wrap" class="form-row form-row-title form-row-responsive">
734
				<label class="give-label" for="give-title">
735
					<?php esc_attr_e( 'Title', 'give' ); ?>
736
					<?php if ( give_field_is_required( 'give_title', $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
				<select
742
					class="give-input required"
743
					type="text"
744
					name="give_title"
745
					id="give-title"
746
					<?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...
747
				>
748
					<?php foreach ( $title_prefixes as $key => $value ) { ?>
749
						<option
750
							value="<?php echo esc_html( $value ); ?>" <?php selected( $value, $title, true ); ?>><?php echo esc_html( $value ); ?></option>
751
					<?php } ?>
752
				</select>
753
			</p>
754
		<?php } ?>
755
756
		<p id="give-first-name-wrap" class="form-row form-row-first form-row-responsive">
757
			<label class="give-label" for="give-first">
758
				<?php esc_attr_e( 'First Name', 'give' ); ?>
759
				<?php if ( give_field_is_required( 'give_first', $form_id ) ) : ?>
760
					<span class="give-required-indicator">*</span>
761
				<?php endif ?>
762
				<?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...
763
			</label>
764
			<input
765
				class="give-input required"
766
				type="text"
767
				name="give_first"
768
				autocomplete="given-name"
769
				placeholder="<?php esc_attr_e( 'First Name', 'give' ); ?>"
770
				id="give-first"
771
				value="<?php echo esc_html( $first_name ); ?>"
772
				<?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...
773
			/>
774
		</p>
775
776
		<p id="give-last-name-wrap" class="form-row form-row-last form-row-responsive">
777
			<label class="give-label" for="give-last">
778
				<?php esc_attr_e( 'Last Name', 'give' ); ?>
779
				<?php if ( give_field_is_required( 'give_last', $form_id ) ) : ?>
780
					<span class="give-required-indicator">*</span>
781
				<?php endif ?>
782
				<?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...
783
			</label>
784
785
			<input
786
				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...
787
				type="text"
788
				name="give_last"
789
				autocomplete="family-name"
790
				id="give-last"
791
				placeholder="<?php esc_attr_e( 'Last Name', 'give' ); ?>"
792
				value="<?php echo esc_html( $last_name ); ?>"
793
				<?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...
794
			/>
795
		</p>
796
797
		<?php if ( give_is_company_field_enabled( $form_id ) ) : ?>
798
			<?php $give_company = give_field_is_required( 'give_company_name', $form_id ); ?>
799
			<p id="give-company-wrap" class="form-row form-row-wide">
800
				<label class="give-label" for="give-company">
801
					<?php esc_attr_e( 'Company Name', 'give' ); ?>
802
					<?php if ( $give_company ) : ?>
803
						<span class="give-required-indicator">*</span>
804
					<?php endif; ?>
805
					<?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...
806
				</label>
807
				<input
808
					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...
809
					type="text"
810
					name="give_company_name"
811
					placeholder="<?php esc_attr_e( 'Company Name', 'give' ); ?>"
812
					id="give-company"
813
					value="<?php echo esc_html( $company_name ); ?>"
814
					<?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...
815
				/>
816
			</p>
817
		<?php endif ?>
818
819
		<?php
820
		/**
821
		 * Fire before user email field
822
		 *
823
		 * @since 1.7
824
		 */
825
		do_action( 'give_donation_form_before_email', $form_id );
826
		?>
827
		<p id="give-email-wrap" class="form-row form-row-wide">
828
			<label class="give-label" for="give-email">
829
				<?php esc_attr_e( 'Email Address', 'give' ); ?>
830
				<?php if ( give_field_is_required( 'give_email', $form_id ) ) { ?>
831
					<span class="give-required-indicator">*</span>
832
				<?php } ?>
833
				<?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...
834
			</label>
835
			<input
836
				class="give-input required"
837
				type="email"
838
				name="give_email"
839
				autocomplete="email"
840
				placeholder="<?php esc_attr_e( 'Email Address', 'give' ); ?>"
841
				id="give-email"
842
				value="<?php echo esc_html( $email ); ?>"
843
				<?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...
844
			/>
845
846
		</p>
847
848 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...
849
			<?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...
850
			<p id="give-anonymous-donation-wrap" class="form-row form-row-wide">
851
				<label class="give-label" for="give-anonymous-donation">
852
					<input
853
						type="checkbox"
854
						class="give-input<?php echo( give_field_is_required( 'give_anonymous_donation', $form_id ) ? ' required' : '' ); ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
855
						name="give_anonymous_donation"
856
						id="give-anonymous-donation"
857
						value="1"
858
						<?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...
859
						<?php checked( 1, $is_anonymous_donation ); ?>
860
					>
861
					<?php _e( 'Make this an anonymous donation', 'give' ); ?>
862
					<?php if ( give_field_is_required( 'give_comment', $form_id ) ) { ?>
863
						<span class="give-required-indicator">*</span>
864
					<?php } ?>
865
					<?php echo Give()->tooltips->render_help( esc_html__( 'Would you like to prevent this donation from being displayed publicly?', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
866
				</label>
867
			</p>
868
		<?php endif; ?>
869
870 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...
871
			<p id="give-comment-wrap" class="form-row form-row-wide">
872
				<label class="give-label" for="give-comment">
873
					<?php _e( 'Comment', 'give' ); ?>
874
					<?php if ( give_field_is_required( 'give_comment', $form_id ) ) { ?>
875
						<span class="give-required-indicator">*</span>
876
					<?php } ?>
877
					<?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...
878
				</label>
879
880
				<textarea
881
					class="give-input<?php echo( give_field_is_required( 'give_comment', $form_id ) ? ' required' : '' ); ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
882
					name="give_comment"
883
					placeholder="<?php _e( 'Leave a comment', 'give' ); ?>"
884
					id="give-comment"
885
					<?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...
886
				><?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...
887
888
			</p>
889
		<?php endif; ?>
890
		<?php
891
		/**
892
		 * Fire after user email field
893
		 *
894
		 * @since 1.7
895
		 */
896
		do_action( 'give_donation_form_after_email', $form_id );
897
898
		/**
899
		 * Fire after personal email field
900
		 *
901
		 * @since 1.7
902
		 */
903
		do_action( 'give_donation_form_user_info', $form_id );
904
		?>
905
	</fieldset>
906
	<?php
907
	/**
908
	 * Fire after user personal information fields
909
	 *
910
	 * @since 1.7
911
	 */
912
	do_action( 'give_donation_form_after_personal_info', $form_id );
913
}
914
915
add_action( 'give_donation_form_after_user_info', 'give_user_info_fields' );
916
add_action( 'give_register_fields_before', 'give_user_info_fields' );
917
918
/**
919
 * Renders the credit card info form.
920
 *
921
 * @since  1.0
922
 *
923
 * @param  int $form_id The form ID.
924
 *
925
 * @return void
926
 */
927
function give_get_cc_form( $form_id ) {
928
929
	ob_start();
930
931
	/**
932
	 * Fires while rendering credit card info form, before the fields.
933
	 *
934
	 * @since 1.0
935
	 *
936
	 * @param int $form_id The form ID.
937
	 */
938
	do_action( 'give_before_cc_fields', $form_id );
939
	?>
940
	<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...
941
		<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...
942
		<?php if ( is_ssl() ) : ?>
943
			<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...
944
				<span class="give-icon padlock"></span>
945
				<span><?php _e( 'This is a secure SSL encrypted payment.', 'give' ); ?></span>
946
			</div>
947
		<?php endif; ?>
948
		<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...
949
			<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...
950
				<?php _e( 'Card Number', 'give' ); ?>
951
				<span class="give-required-indicator">*</span>
952
				<?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...
953
				<span class="card-type"></span>
954
			</label>
955
956
			<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...
957
			       class="card-number give-input required" placeholder="<?php _e( 'Card number', 'give' ); ?>"
958
			       required aria-required="true"/>
959
		</p>
960
961
		<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...
962
			<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...
963
				<?php _e( 'CVC', 'give' ); ?>
964
				<span class="give-required-indicator">*</span>
965
				<?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...
966
			</label>
967
968
			<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...
969
			       class="card-cvc give-input required" placeholder="<?php _e( 'Security code', 'give' ); ?>"
970
			       required aria-required="true"/>
971
		</p>
972
973
		<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...
974
			<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...
975
				<?php _e( 'Name on the Card', 'give' ); ?>
976
				<span class="give-required-indicator">*</span>
977
				<?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...
978
			</label>
979
980
			<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...
981
			       class="card-name give-input required" placeholder="<?php esc_attr_e( 'Card name', 'give' ); ?>"
982
			       required aria-required="true"/>
983
		</p>
984
		<?php
985
		/**
986
		 * Fires while rendering credit card info form, before expiration fields.
987
		 *
988
		 * @since 1.0
989
		 *
990
		 * @param int $form_id The form ID.
991
		 */
992
		do_action( 'give_before_cc_expiration' );
993
		?>
994
		<p class="card-expiration form-row form-row-one-third form-row-responsive">
995 1
			<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...
996
				<?php _e( 'Expiration', 'give' ); ?>
997
				<span class="give-required-indicator">*</span>
998
				<?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...
999
			</label>
1000
1001
			<input type="hidden" id="card_exp_month-<?php echo $form_id; ?>" name="card_exp_month"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1002
			       class="card-expiry-month"/>
1003
			<input type="hidden" id="card_exp_year-<?php echo $form_id; ?>" name="card_exp_year"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1004
			       class="card-expiry-year"/>
1005
1006
			<input type="tel" autocomplete="off" name="card_expiry" id="card_expiry-<?php echo $form_id; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1007
			       class="card-expiry give-input required" placeholder="<?php esc_attr_e( 'MM / YY', 'give' ); ?>"
1008
			       required aria-required="true"/>
1009
		</p>
1010
		<?php
1011 1
		/**
1012 1
		 * Fires while rendering credit card info form, after expiration fields.
1013 1
		 *
1014 1
		 * @since 1.0
1015 1
		 *
1016
		 * @param int $form_id The form ID.
1017
		 */
1018
		do_action( 'give_after_cc_expiration', $form_id );
1019
		?>
1020
	</fieldset>
1021
	<?php
1022
	/**
1023
	 * Fires while rendering credit card info form, before the fields.
1024
	 *
1025
	 * @since 1.0
1026
	 *
1027
	 * @param int $form_id The form ID.
1028
	 */
1029
	do_action( 'give_after_cc_fields', $form_id );
1030
1031
	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...
1032
}
1033 1
1034
add_action( 'give_cc_form', 'give_get_cc_form' );
1035
1036
/**
1037
 * Outputs the default credit card address fields.
1038
 *
1039
 * @since  1.0
1040
 *
1041
 * @param  int $form_id The form ID.
1042
 *
1043
 * @return void
1044
 */
1045
function give_default_cc_address_fields( $form_id ) {
1046
	// Get user info.
1047
	$give_user_info = _give_get_prefill_form_field_values( $form_id );
1048
1049
	$logged_in = is_user_logged_in();
1050
1051
	if ( $logged_in ) {
1052 1
		$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...
1053 1
	}
1054 1
1055
	ob_start();
1056
	?>
1057
	<fieldset id="give_cc_address" class="cc-address">
1058
		<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...
1059
		<?php
1060
		/**
1061
		 * Fires while rendering credit card billing form, before address fields.
1062
		 *
1063
		 * @since 1.0
1064
		 *
1065
		 * @param int $form_id The form ID.
1066
		 */
1067
		do_action( 'give_cc_billing_top' );
1068
1069
		// For Country.
1070
		$selected_country = give_get_country();
1071 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...
1072
			$selected_country = $give_user_info['billing_country'];
1073
		}
1074
		$countries = give_get_country_list();
1075
1076
		// For state.
1077 1
		$selected_state = '';
1078
		if ( $selected_country === give_get_country() ) {
1079
			// Get default selected state by admin.
1080
			$selected_state = give_get_state();
1081
		}
1082
		// Get the last payment made by user states.
1083
		if ( ! empty( $give_user_info['card_state'] ) && '*' !== $give_user_info['card_state'] ) {
1084
			$selected_state = $give_user_info['card_state'];
1085
		}
1086
		// Get the country code.
1087 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...
1088
			$selected_country = $give_user_info['billing_country'];
1089
		}
1090
		$label        = __( 'State', 'give' );
1091
		$states_label = give_get_states_label();
1092
		// Check if $country code exists in the array key for states label.
1093 1
		if ( array_key_exists( $selected_country, $states_label ) ) {
1094
			$label = $states_label[ $selected_country ];
1095
		}
1096
		$states = give_get_states( $selected_country );
1097 1
		// Get the country list that do not have any states init.
1098
		$no_states_country = give_no_states_country_list();
1099
		// Get the country list that does not require states.
1100 1
		$states_not_required_country_list = give_states_not_required_country_list();
1101
		?>
1102
		<p id="give-card-country-wrap" class="form-row form-row-wide">
1103
			<label for="billing_country" class="give-label">
1104
				<?php esc_html_e( 'Country', 'give' ); ?>
1105
				<?php if ( give_field_is_required( 'billing_country', $form_id ) ) : ?>
1106
					<span class="give-required-indicator">*</span>
1107
				<?php endif; ?>
1108
				<span class="give-tooltip give-icon give-icon-question"
1109 1
				      data-tooltip="<?php esc_attr_e( 'The country for your billing address.', 'give' ); ?>"></span>
1110
			</label>
1111
1112
			<select
1113
				name="billing_country"
1114
				autocomplete="country-name"
1115
				id="billing_country"
1116
				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...
1117
				<?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...
1118
			>
1119
				<?php
1120
				foreach ( $countries as $country_code => $country ) {
1121
					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...
1122
				}
1123
				?>
1124
			</select>
1125
		</p>
1126
1127
		<p id="give-card-address-wrap" class="form-row form-row-wide">
1128
			<label for="card_address" class="give-label">
1129
				<?php _e( 'Address 1', 'give' ); ?>
1130
				<?php
1131
				if ( give_field_is_required( 'card_address', $form_id ) ) :
1132
					?>
1133
					<span class="give-required-indicator">*</span>
1134
				<?php endif; ?>
1135
				<?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...
1136 1
			</label>
1137
1138
			<input
1139
				type="text"
1140
				id="card_address"
1141
				name="card_address"
1142
				autocomplete="address-line1"
1143
				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...
1144
				placeholder="<?php _e( 'Address line 1', 'give' ); ?>"
1145
				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...
1146
				<?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...
1147
			/>
1148
		</p>
1149
1150
		<p id="give-card-address-2-wrap" class="form-row form-row-wide">
1151
			<label for="card_address_2" class="give-label">
1152
				<?php _e( 'Address 2', 'give' ); ?>
1153 1
				<?php if ( give_field_is_required( 'card_address_2', $form_id ) ) : ?>
1154 1
					<span class="give-required-indicator">*</span>
1155
				<?php endif; ?>
1156
				<?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...
1157
			</label>
1158
1159
			<input
1160
				type="text"
1161 1
				id="card_address_2"
1162
				name="card_address_2"
1163
				autocomplete="address-line2"
1164
				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...
1165
				placeholder="<?php _e( 'Address line 2', 'give' ); ?>"
1166
				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...
1167
				<?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...
1168
			/>
1169
		</p>
1170
1171
		<p id="give-card-city-wrap" class="form-row form-row-wide">
1172
			<label for="card_city" class="give-label">
1173
				<?php _e( 'City', 'give' ); ?>
1174
				<?php if ( give_field_is_required( 'card_city', $form_id ) ) : ?>
1175
					<span class="give-required-indicator">*</span>
1176 1
				<?php endif; ?>
1177
				<?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...
1178 1
			</label>
1179
			<input
1180
				type="text"
1181
				id="card_city"
1182
				name="card_city"
1183
				autocomplete="address-level3"
1184
				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...
1185
				placeholder="<?php _e( 'City', 'give' ); ?>"
1186
				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...
1187
				<?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...
1188
			/>
1189
		</p>
1190
1191
		<p id="give-card-state-wrap"
1192 1
		   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...
1193
			<label for="card_state" class="give-label">
1194
				<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...
1195
				<?php
1196
				if ( give_field_is_required( 'card_state', $form_id ) ) :
1197
					?>
1198
					<span
1199
						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...
1200
				<?php endif; ?>
1201
				<span class="give-tooltip give-icon give-icon-question"
1202
				      data-tooltip="<?php esc_attr_e( 'The state, province, or county for your billing address.', 'give' ); ?>"></span>
1203
			</label>
1204
			<?php
1205
1206
			if ( ! empty( $states ) ) :
1207
				?>
1208
				<select
1209 1
					name="card_state"
1210 1
					autocomplete="address-level4"
1211 1
					id="card_state"
1212 1
					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...
1213 1
					<?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...
1214 1
					<?php
1215 1
					foreach ( $states as $state_code => $state ) {
1216 1
						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...
1217
					}
1218
					?>
1219 1
				</select>
1220
			<?php else : ?>
1221
				<input type="text" size="6" name="card_state" id="card_state" class="card_state give-input"
1222
				       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...
1223
			<?php endif; ?>
1224 1
		</p>
1225 1
1226 1
		<p id="give-card-zip-wrap" class="form-row form-row-last form-row-responsive">
1227 1
			<label for="card_zip" class="give-label">
1228 1
				<?php _e( 'Zip / Postal Code', 'give' ); ?>
1229
				<?php if ( give_field_is_required( 'card_zip', $form_id ) ) : ?>
1230 1
					<span class="give-required-indicator">*</span>
1231
				<?php endif; ?>
1232
				<?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...
1233
			</label>
1234
1235
			<input
1236
				type="text"
1237
				size="4"
1238
				id="card_zip"
1239
				name="card_zip"
1240
				autocomplete="postal-code"
1241
				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...
1242
				placeholder="<?php _e( 'Zip / Postal Code', 'give' ); ?>"
1243
				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...
1244
				<?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...
1245
			/>
1246
		</p>
1247
		<?php
1248
		/**
1249
		 * Fires while rendering credit card billing form, after address fields.
1250
		 *
1251
		 * @since 1.0
1252
		 *
1253
		 * @param int $form_id The form ID.
1254
		 */
1255
		do_action( 'give_cc_billing_bottom' );
1256
		?>
1257
	</fieldset>
1258
	<?php
1259
	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...
1260
}
1261
1262
add_action( 'give_after_cc_fields', 'give_default_cc_address_fields' );
1263
1264
1265
/**
1266
 * Renders the user registration fields. If the user is logged in, a login form is displayed other a registration form
1267
 * is provided for the user to create an account.
1268
 *
1269
 * @since  1.0
1270
 *
1271
 * @param  int $form_id The form ID.
1272
 *
1273
 * @return string
1274
 */
1275
function give_get_register_fields( $form_id ) {
1276
1277
	global $user_ID;
1278
1279
	if ( is_user_logged_in() ) {
1280
		$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...
1281
	}
1282
1283
	$show_register_form = give_show_login_register_option( $form_id );
1284
1285
	ob_start();
1286
	?>
1287
	<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...
1288
1289
		<?php
1290
		/**
1291
		 * Fires while rendering user registration form, before registration fields.
1292
		 *
1293
		 * @since 1.0
1294
		 *
1295
		 * @param int $form_id The form ID.
1296
		 */
1297
		do_action( 'give_register_fields_before', $form_id );
1298
		?>
1299
1300
		<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...
1301
			<?php
1302 1
			/**
1303 1
			 * Fires while rendering user registration form, before account fields.
1304 1
			 *
1305
			 * @since 1.0
1306 1
			 *
1307
			 * @param int $form_id The form ID.
1308 1
			 */
1309 1
			do_action( 'give_register_account_fields_before', $form_id );
1310 1
1311
			$class = ( 'registration' === $show_register_form ) ? 'form-row-wide' : 'form-row-first';
1312
			?>
1313
			<div id="give-create-account-wrap-<?php echo $form_id; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1314
			     class="form-row <?php echo esc_attr( $class ); ?> form-row-responsive">
1315
				<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...
1316
					<?php
1317
					// Add attributes to checkbox, if Guest Checkout is disabled.
1318
					$is_guest_checkout = give_get_meta( $form_id, '_give_logged_in_only', true );
1319
					$id                = 'give-create-account-' . $form_id;
1320
					if ( ! give_is_setting_enabled( $is_guest_checkout ) ) {
1321
						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...
1322
							array(
1323
								'tag_content' => sprintf(
1324
									'<input type="checkbox" name="give_create_account" value="on" id="%s" class="give-input give-disabled" checked />',
1325
									$id
1326
								),
1327
								'label'       => __( 'Registration is required to donate.', 'give' ),
1328
							)
1329
						);
1330
					} else {
1331
						?>
1332
						<input type="checkbox" name="give_create_account" value="on" id="<?php echo $id; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$id'
Loading history...
1333
						       class="give-input"/>
1334
						<?php
1335
					}
1336
1337
					_e( 'Create an account', 'give' );
1338
					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...
1339
					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...
1340
						'/>',
1341
						'data-time="' . time() . '" data-nonce-life="' . give_get_nonce_life() . '"/>',
1342
						give_get_nonce_field( "give_form_create_user_nonce_{$form_id}", 'give-form-user-register-hash', false )
1343
					);
1344
					?>
1345
				</label>
1346
			</div>
1347
1348
			<?php if ( 'both' === $show_register_form ) { ?>
1349
				<div class="give-login-account-wrap form-row form-row-last form-row-responsive">
1350
					<p class="give-login-message"><?php esc_html_e( 'Already have an account?', 'give' ); ?>&nbsp;
1351
						<a href="<?php echo esc_url( add_query_arg( 'login', 1 ) ); ?>" class="give-checkout-login"
1352
						   data-action="give_checkout_login"><?php esc_html_e( 'Login', 'give' ); ?></a>
1353
					</p>
1354
					<p class="give-loading-text">
1355
						<span class="give-loading-animation"></span>
1356 1
					</p>
1357
				</div>
1358
			<?php } ?>
1359
1360
			<?php
1361
			/**
1362
			 * Fires while rendering user registration form, after account fields.
1363 1
			 *
1364
			 * @since 1.0
1365 1
			 *
1366
			 * @param int $form_id The form ID.
1367
			 */
1368
			do_action( 'give_register_account_fields_after', $form_id );
1369
			?>
1370
		</fieldset>
1371
1372
		<?php
1373
		/**
1374
		 * Fires while rendering user registration form, after registration fields.
1375
		 *
1376
		 * @since 1.0
1377
		 *
1378
		 * @param int $form_id The form ID.
1379
		 */
1380
		do_action( 'give_register_fields_after', $form_id );
1381
		?>
1382
1383
		<input type="hidden" name="give-purchase-var" value="needs-to-register"/>
1384
1385
		<?php
1386
		/**
1387
		 * Fire after register or login form render
1388
		 *
1389
		 * @since 1.7
1390
		 */
1391
		do_action( 'give_donation_form_user_info', $form_id );
1392
		?>
1393
1394
	</fieldset>
1395
	<?php
1396
	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...
1397
}
1398
1399
add_action( 'give_donation_form_register_fields', 'give_get_register_fields' );
1400
1401
/**
1402
 * Gets the login fields for the login form on the checkout. This function hooks
1403 1
 * on the give_donation_form_login_fields to display the login form if a user already
1404
 * had an account.
1405 1
 *
1406
 * @since  1.0
1407
 *
1408 1
 * @param  int $form_id The form ID.
1409
 *
1410
 * @return string
1411
 */
1412
function give_get_login_fields( $form_id ) {
1413
1414
	$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...
1415
	$show_register_form = give_show_login_register_option( $form_id );
1416
1417
	ob_start();
1418
	?>
1419
	<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...
1420
		<legend>
1421
			<?php
1422 1
			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...
1423
			if ( ! give_logged_in_only( $form_id ) ) {
1424
				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...
1425 1
			}
1426
			?>
1427
		</legend>
1428
		<?php if ( $show_register_form == 'both' ) { ?>
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
1429
			<p class="give-new-account-link">
1430 1
				<?php _e( 'Don\'t have an account?', 'give' ); ?>&nbsp;
1431
				<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...
1432
				   data-action="give_checkout_register">
1433
					<?php
1434
					if ( give_logged_in_only( $form_id ) ) {
1435
						_e( 'Register as a part of your donation &raquo;', 'give' );
1436
					} else {
1437
						_e( 'Register or donate as a guest &raquo;', 'give' );
1438 1
					}
1439
					?>
1440
				</a>
1441
			</p>
1442
			<p class="give-loading-text">
1443
				<span class="give-loading-animation"></span>
1444
			</p>
1445
		<?php } ?>
1446
		<?php
1447
		/**
1448
		 * Fires while rendering checkout login form, before the fields.
1449
		 *
1450
		 * @since 1.0
1451
		 *
1452
		 * @param int $form_id The form ID.
1453
		 */
1454
		do_action( 'give_donation_form_login_fields_before', $form_id );
1455
		?>
1456
		<div class="give-user-login-fields-container">
1457
			<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...
1458
				<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...
1459
					<?php _e( 'Username', 'give' ); ?>
1460
					<?php if ( give_logged_in_only( $form_id ) ) { ?>
1461
						<span class="give-required-indicator">*</span>
1462
					<?php } ?>
1463
				</label>
1464
1465
				<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...
1466
				       type="text"
1467
				       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...
1468
				       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...
1469
			</div>
1470
1471
			<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...
1472
			     class="give_login_password form-row form-row-last form-row-responsive">
1473
				<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...
1474
					<?php _e( 'Password', 'give' ); ?>
1475
					<?php if ( give_logged_in_only( $form_id ) ) { ?>
1476
						<span class="give-required-indicator">*</span>
1477
					<?php } ?>
1478
				</label>
1479
				<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...
1480
				       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...
1481
				       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...
1482
				<input type="hidden" name="give-purchase-var" value="needs-to-login"/>
1483
			</div>
1484
1485
			<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...
1486
				 <span class="give-forgot-password ">
1487
					 <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...
1488
					    target="_blank"><?php _e( 'Reset Password', 'give' ); ?></a>
1489
				 </span>
1490
			</div>
1491
		</div>
1492
1493
1494
		<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...
1495
			<input type="submit" class="give-submit give-btn button" name="give_login_submit"
1496
			       value="<?php _e( 'Login', 'give' ); ?>"/>
1497
			<?php if ( $show_register_form !== 'login' ) { ?>
0 ignored issues
show
introduced by
Found "!== '". Use Yoda Condition checks, you must
Loading history...
1498
				<input type="button" data-action="give_cancel_login"
1499
				       class="give-cancel-login give-checkout-register-cancel give-btn button" name="give_login_cancel"
1500
				       value="<?php _e( 'Cancel', 'give' ); ?>"/>
1501
			<?php } ?>
1502
			<span class="give-loading-animation"></span>
1503
		</div>
1504
		<?php
1505
		/**
1506
		 * Fires while rendering checkout login form, after the fields.
1507
		 *
1508
		 * @since 1.0
1509
		 *
1510
		 * @param int $form_id The form ID.
1511
		 */
1512
		do_action( 'give_donation_form_login_fields_after', $form_id );
1513
		?>
1514
	</fieldset><!--end #give-login-fields-->
1515
	<?php
1516
	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...
1517
}
1518
1519
add_action( 'give_donation_form_login_fields', 'give_get_login_fields', 10, 1 );
1520
1521
/**
1522
 * Payment Mode Select.
1523
 *
1524
 * Renders the payment mode form by getting all the enabled payment gateways and
1525
 * outputting them as radio buttons for the user to choose the payment gateway. If
1526
 * a default payment gateway has been chosen from the Give Settings, it will be
1527
 * automatically selected.
1528
 *
1529
 * @since  1.0
1530
 *
1531
 * @param  int $form_id The form ID.
1532
 *
1533
 * @return void
1534
 */
1535
function give_payment_mode_select( $form_id, $args ) {
1536
1537
	$gateways  = give_get_enabled_payment_gateways( $form_id );
1538
	$id_prefix = ! empty( $args['id_prefix'] ) ? $args['id_prefix'] : '';
1539
1540
	/**
1541
	 * Fires while selecting payment gateways, before the fields.
1542
	 *
1543
	 * @since 1.7
1544
	 *
1545
	 * @param int $form_id The form ID.
1546
	 */
1547
	do_action( 'give_payment_mode_top', $form_id );
1548
	?>
1549
1550
	<fieldset id="give-payment-mode-select"
1551
		<?php
1552
		if ( count( $gateways ) <= 1 ) {
1553
			echo 'style="display: none;"';
1554
		}
1555
		?>
1556
	>
1557
		<?php
1558
		/**
1559
		 * Fires while selecting payment gateways, before the wrap div.
1560
		 *
1561
		 * @since 1.7
1562
		 *
1563
		 * @param int $form_id The form ID.
1564
		 */
1565
		do_action( 'give_payment_mode_before_gateways_wrap' );
1566
		?>
1567
		<legend
1568
			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...
1569
			<span class="give-loading-text"><span
1570
					class="give-loading-animation"></span>
1571
			</span>
1572
		</legend>
1573
1574
		<div id="give-payment-mode-wrap">
1575
			<?php
1576
			/**
1577
			 * Fires while selecting payment gateways, before the gateways list.
1578
			 *
1579
			 * @since 1.7
1580
			 */
1581
			do_action( 'give_payment_mode_before_gateways' )
1582
			?>
1583
			<ul id="give-gateway-radio-list">
1584
				<?php
1585
				/**
1586
				 * Loop through the active payment gateways.
1587
				 */
1588
				$selected_gateway  = give_get_chosen_gateway( $form_id );
1589
				$give_settings     = give_get_settings();
1590
				$gateways_label    = array_key_exists( 'gateways_label', $give_settings ) ?
1591
					$give_settings['gateways_label'] :
1592
					array();
1593
1594
				foreach ( $gateways as $gateway_id => $gateway ) :
1595
					// Determine the default gateway.
1596
					$checked = checked( $gateway_id, $selected_gateway, false );
1597
					$checked_class = $checked ? ' class="give-gateway-option-selected"' : '';
1598
					?>
1599
					<li<?php echo $checked_class; ?>>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$checked_class'
Loading history...
1600
						<input type="radio" name="payment-mode" class="give-gateway"
1601
						       id="give-gateway-<?php echo esc_attr( $gateway_id . '-' . $id_prefix ); ?>"
1602
						       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...
1603
1604
						<?php
1605
						$label = $gateway['checkout_label'];
1606
						if ( ! empty( $gateways_label[ $gateway_id ] ) ) {
1607
							$label = $gateways_label[ $gateway_id ];
1608
						}
1609
						?>
1610
						<label for="give-gateway-<?php echo esc_attr( $gateway_id . '-' . $id_prefix ); ?>"
1611
						       class="give-gateway-option"
1612
						       id="give-gateway-option-<?php echo esc_attr( $gateway_id ); ?>"> <?php echo esc_html( $label ); ?></label>
1613
					</li>
1614
				<?php
1615
				endforeach;
1616
				?>
1617
			</ul>
1618
			<?php
1619
			/**
1620
			 * Fires while selecting payment gateways, before the gateways list.
1621
			 *
1622
			 * @since 1.7
1623
			 */
1624
			do_action( 'give_payment_mode_after_gateways' );
1625
			?>
1626
		</div>
1627
		<?php
1628
		/**
1629
		 * Fires while selecting payment gateways, after the wrap div.
1630
		 *
1631
		 * @since 1.7
1632
		 *
1633
		 * @param int $form_id The form ID.
1634
		 */
1635
		do_action( 'give_payment_mode_after_gateways_wrap' );
1636
		?>
1637
	</fieldset>
1638
1639
	<?php
1640
	/**
1641
	 * Fires while selecting payment gateways, after the fields.
1642
	 *
1643
	 * @since 1.7
1644
	 *
1645
	 * @param int $form_id The form ID.
1646
	 */
1647
	do_action( 'give_payment_mode_bottom', $form_id );
1648
	?>
1649
1650
	<div id="give_purchase_form_wrap">
1651
1652
		<?php
1653
		/**
1654
		 * Fire after payment field render.
1655
		 *
1656
		 * @since 1.7
1657
		 */
1658
		do_action( 'give_donation_form', $form_id, $args );
1659
		?>
1660
1661
	</div>
1662
1663
	<?php
1664
	/**
1665
	 * Fire after donation form render.
1666
	 *
1667
	 * @since 1.7
1668
	 */
1669
	do_action( 'give_donation_form_wrap_bottom', $form_id );
1670
}
1671
1672
add_action( 'give_payment_mode_select', 'give_payment_mode_select', 10, 2 );
1673
1674
/**
1675
 * Renders the Checkout Agree to Terms, this displays a checkbox for users to
1676
 * agree the T&Cs set in the Give Settings. This is only displayed if T&Cs are
1677
 * set in the Give Settings.
1678
 *
1679
 * @since  1.0
1680
 *
1681
 * @param  int $form_id The form ID.
1682
 *
1683
 * @return bool
1684
 */
1685
function give_terms_agreement( $form_id ) {
1686
	$form_option = give_get_meta( $form_id, '_give_terms_option', true );
1687
1688
	// Bailout if per form and global term and conditions is not setup.
1689
	if (
1690
		give_is_setting_enabled( $form_option, 'global' )
1691
		&& give_is_setting_enabled( give_get_option( 'terms' ) )
1692
	) {
1693
		$label         = give_get_option( 'agree_to_terms_label', esc_html__( 'Agree to Terms?', 'give' ) );
1694
		$terms         = $terms = give_get_option( 'agreement_text', '' );
1695
		$edit_term_url = admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=display&section=term-and-conditions' );
1696
1697
	} elseif ( give_is_setting_enabled( $form_option ) ) {
1698
		$label         = ( $label = give_get_meta( $form_id, '_give_agree_label', true ) ) ? stripslashes( $label ) : esc_html__( 'Agree to Terms?', 'give' );
1699
		$terms         = give_get_meta( $form_id, '_give_agree_text', true );
1700
		$edit_term_url = admin_url( 'post.php?post=' . $form_id . '&action=edit#form_terms_options' );
1701
1702
	} else {
1703
		return false;
1704
	}
1705
1706
	// Bailout: Check if term and conditions text is empty or not.
1707
	if ( empty( $terms ) ) {
1708
		if ( is_user_logged_in() && current_user_can( 'edit_give_forms' ) ) {
1709
			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...
1710
		}
1711
1712
		return false;
1713
	}
1714
1715
	/**
1716
	 * Filter the form term content
1717
	 *
1718
	 * @since  2.1.5
1719
	 */
1720
	$terms = apply_filters( 'give_the_term_content', wpautop( do_shortcode( $terms ) ), $terms, $form_id );
1721
1722
	?>
1723
	<fieldset id="give_terms_agreement">
1724
		<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...
1725
		<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...
1726
			<?php
1727
			/**
1728
			 * Fires while rendering terms of agreement, before the fields.
1729
			 *
1730
			 * @since 1.0
1731
			 */
1732
			do_action( 'give_before_terms' );
1733
1734
			echo $terms;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$terms'
Loading history...
1735
			/**
1736
			 * Fires while rendering terms of agreement, after the fields.
1737
			 *
1738
			 * @since 1.0
1739
			 */
1740
			do_action( 'give_after_terms' );
1741
			?>
1742
		</div>
1743
		<div id="give_show_terms">
1744
			<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...
1745
			   aria-controls="give_terms"><?php esc_html_e( 'Show Terms', 'give' ); ?></a>
1746
			<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...
1747
			   aria-controls="give_terms" style="display:none;"><?php esc_html_e( 'Hide Terms', 'give' ); ?></a>
1748
		</div>
1749
1750
		<input name="give_agree_to_terms" class="required" type="checkbox"
1751
		       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...
1752
		<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...
1753
1754
	</fieldset>
1755
	<?php
1756
}
1757
1758
add_action( 'give_donation_form_after_cc_form', 'give_terms_agreement', 8888, 1 );
1759
1760
/**
1761
 * Checkout Final Total.
1762
 *
1763
 * Shows the final donation total at the bottom of the checkout page.
1764
 *
1765
 * @since  1.0
1766
 *
1767
 * @param  int $form_id The form ID.
1768
 *
1769
 * @return void
1770
 */
1771
function give_checkout_final_total( $form_id ) {
1772
1773
	$total = isset( $_POST['give_total'] ) ?
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
1774
		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...
1775
		give_get_default_form_amount( $form_id );
1776
1777
	// Only proceed if give_total available.
1778
	if ( empty( $total ) ) {
1779
		return;
1780
	}
1781
	?>
1782
	<p id="give-final-total-wrap" class="form-wrap ">
1783
		<?php
1784
		/**
1785
		 * Fires before the donation total label
1786
		 *
1787
		 * @since 2.0.5
1788
		 */
1789
		do_action( 'give_donation_final_total_label_before', $form_id );
1790
		?>
1791
		<span class="give-donation-total-label">
1792
			<?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...
1793
		</span>
1794
		<span class="give-final-total-amount"
1795
		      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...
1796
			<?php
1797
			echo give_currency_filter(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_currency_filter'
Loading history...
1798
				give_format_amount(
1799
					$total, array(
1800
						'sanitize' => false,
1801
						'currency' => give_get_currency( $form_id ),
1802
					)
1803
				), array( 'currency_code' => give_get_currency( $form_id ) )
1804
			);
1805
			?>
1806
		</span>
1807
		<?php
1808
		/**
1809
		 * Fires after the donation final total label
1810
		 *
1811
		 * @since 2.0.5
1812
		 */
1813
		do_action( 'give_donation_final_total_label_after', $form_id );
1814
		?>
1815
	</p>
1816
	<?php
1817
}
1818
1819
add_action( 'give_donation_form_before_submit', 'give_checkout_final_total', 999 );
1820
1821
/**
1822
 * Renders the Checkout Submit section.
1823
 *
1824
 * @since  1.0
1825
 *
1826
 * @param int   $form_id The donation form ID.
1827
 * @param array $args    List of arguments.
1828
 *
1829
 * @return void
1830
 */
1831
function give_checkout_submit( $form_id, $args ) {
1832
	?>
1833
	<fieldset id="give_purchase_submit" class="give-donation-submit">
1834
		<?php
1835
		/**
1836
		 * Fire before donation form submit.
1837
		 *
1838
		 * @since 1.7
1839
		 */
1840
		do_action( 'give_donation_form_before_submit', $form_id, $args );
1841
1842
		give_checkout_hidden_fields( $form_id );
1843
1844
		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...
1845
1846
		/**
1847
		 * Fire after donation form submit.
1848
		 *
1849
		 * @since 1.7
1850
		 */
1851
		do_action( 'give_donation_form_after_submit', $form_id, $args );
1852
		?>
1853
	</fieldset>
1854
	<?php
1855
}
1856
1857
add_action( 'give_donation_form_after_cc_form', 'give_checkout_submit', 9999, 2 );
1858
1859
/**
1860
 * Give Donation form submit button.
1861
 *
1862
 * @since  1.8.8
1863
 *
1864
 * @param  int $form_id The form ID.
1865
 *
1866
 * @return string
1867
 */
1868
function give_get_donation_form_submit_button( $form_id ) {
1869
1870
	$display_label_field = give_get_meta( $form_id, '_give_checkout_label', true );
1871
	$display_label       = ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) );
1872
	ob_start();
1873
	?>
1874
	<div class="give-submit-button-wrap give-clearfix">
1875
		<input type="submit" class="give-submit give-btn" id="give-purchase-button" name="give-purchase"
1876
		       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...
1877
		<span class="give-loading-animation"></span>
1878
	</div>
1879
	<?php
1880
	return apply_filters( 'give_donation_form_submit_button', ob_get_clean(), $form_id );
1881
}
1882
1883
/**
1884
 * Show Give Goals.
1885
 *
1886
 * @since  1.0
1887
 * @since  1.6   Add template for Give Goals Shortcode.
1888
 *               More info is on https://github.com/WordImpress/Give/issues/411
1889
 *
1890
 * @param  int   $form_id The form ID.
1891
 * @param  array $args    An array of form arguments.
1892
 *
1893
 * @return mixed
1894
 */
1895
function give_show_goal_progress( $form_id, $args = array() ) {
1896
1897
	ob_start();
1898
	give_get_template(
1899
		'shortcode-goal', array(
1900
			'form_id' => $form_id,
1901
			'args'    => $args,
1902
		)
1903
	);
1904
1905
	/**
1906
	 * Filter progress bar output
1907
	 *
1908
	 * @since 2.0
1909
	 */
1910
	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...
1911
1912
	return true;
1913
}
1914
1915
add_action( 'give_pre_form', 'give_show_goal_progress', 10, 2 );
1916
1917
/**
1918
 * Show Give Totals Progress.
1919
 *
1920
 * @since  2.1
1921
 *
1922
 * @param  int $total      Total amount based on shortcode parameter.
1923
 * @param  int $total_goal Total Goal amount passed by Admin.
1924
 *
1925
 * @return mixed
1926
 */
1927
function give_show_goal_totals_progress( $total, $total_goal ) {
1928
1929
	// Bail out if total goal is set as an array.
1930
	if ( isset( $total_goal ) && is_array( $total_goal ) ) {
1931
		return false;
1932
	}
1933
1934
	ob_start();
1935
	give_get_template(
1936
		'shortcode-totals-progress', array(
1937
			'total'      => $total,
1938
			'total_goal' => $total_goal,
1939
		)
1940
	);
1941
1942
	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...
1943
1944
	return true;
1945
}
1946
1947
add_action( 'give_pre_form', 'give_show_goal_totals_progress', 10, 2 );
1948
1949
/**
1950
 * Get form content position.
1951
 *
1952
 * @since  1.8
1953
 *
1954
 * @param  $form_id
1955
 * @param  $args
1956
 *
1957
 * @return mixed|string
1958
 */
1959
function give_get_form_content_placement( $form_id, $args ) {
1960
	$show_content = '';
1961
1962
	if ( isset( $args['show_content'] ) && ! empty( $args['show_content'] ) ) {
1963
		// Content positions.
1964
		$content_placement = array(
1965
			'above' => 'give_pre_form',
1966
			'below' => 'give_post_form',
1967
		);
1968
1969
		// Check if content position already decoded.
1970
		if ( in_array( $args['show_content'], $content_placement ) ) {
1971
			return $args['show_content'];
1972
		}
1973
1974
		$show_content = ( 'none' !== $args['show_content'] ? $content_placement[ $args['show_content'] ] : '' );
1975
1976
	} elseif ( give_is_setting_enabled( give_get_meta( $form_id, '_give_display_content', true ) ) ) {
1977
		$show_content = give_get_meta( $form_id, '_give_content_placement', true );
1978
1979
	} elseif ( 'none' !== give_get_meta( $form_id, '_give_content_option', true ) ) {
1980
		// Backward compatibility for _give_content_option for v18.
1981
		$show_content = give_get_meta( $form_id, '_give_content_option', true );
1982
	}
1983
1984
	return $show_content;
1985
}
1986
1987
/**
1988
 * Adds Actions to Render Form Content.
1989
 *
1990
 * @since  1.0
1991
 *
1992
 * @param  int   $form_id The form ID.
1993
 * @param  array $args    An array of form arguments.
1994
 *
1995
 * @return void|bool
1996
 */
1997
function give_form_content( $form_id, $args ) {
1998
1999
	$show_content = give_get_form_content_placement( $form_id, $args );
2000
2001
	// Bailout.
2002
	if ( empty( $show_content ) ) {
2003
		return false;
2004
	}
2005
2006
	// Add action according to value.
2007
	add_action( $show_content, 'give_form_display_content', 10, 2 );
2008
}
2009
2010
add_action( 'give_pre_form_output', 'give_form_content', 10, 2 );
2011
2012
/**
2013
 * Renders Post Form Content.
2014
 *
2015
 * Displays content for Give forms; fired by action from give_form_content.
2016
 *
2017
 * @since  1.0
2018
 *
2019
 * @param  int   $form_id The form ID.
2020
 * @param  array $args    An array of form arguments.
2021
 *
2022
 * @return void
2023
 */
2024
function give_form_display_content( $form_id, $args ) {
2025
	$content      = give_get_meta( $form_id, '_give_form_content', true );
2026
	$show_content = give_get_form_content_placement( $form_id, $args );
2027
2028
	if ( give_is_setting_enabled( give_get_option( 'the_content_filter' ) ) ) {
2029
		$content = apply_filters( 'the_content', $content );
2030
	} else {
2031
		$content = wpautop( do_shortcode( $content ) );
2032
	}
2033
2034
	$output = sprintf(
2035
		'<div id="give-form-content-%s" class="give-form-content-wrap %s-content">%s</div>',
2036
		$form_id,
2037
		$show_content,
2038
		$content
2039
	);
2040
2041
	/**
2042
	 * Filter form content html
2043
	 *
2044
	 * @since 1.0
2045
	 *
2046
	 * @param string $output
2047
	 * @param int    $form_id
2048
	 * @param array  $args
2049
	 */
2050
	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...
2051
2052
	// remove action to prevent content output on addition forms on page.
2053
	// @see: https://github.com/WordImpress/Give/issues/634.
2054
	remove_action( $show_content, 'give_form_display_content' );
2055
}
2056
2057
/**
2058
 * Renders the hidden Checkout fields.
2059
 *
2060
 * @since 1.0
2061
 *
2062
 * @param  int $form_id The form ID.
2063
 *
2064
 * @return void
2065
 */
2066
function give_checkout_hidden_fields( $form_id ) {
2067
2068
	/**
2069
	 * Fires while rendering hidden checkout fields, before the fields.
2070
	 *
2071
	 * @since 1.0
2072
	 *
2073
	 * @param int $form_id The form ID.
2074
	 */
2075
	do_action( 'give_hidden_fields_before', $form_id );
2076
2077
	if ( is_user_logged_in() ) {
2078
		?>
2079
		<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...
2080
	<?php } ?>
2081
	<input type="hidden" name="give_action" value="purchase"/>
2082
	<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...
2083
	<?php
2084
	/**
2085
	 * Fires while rendering hidden checkout fields, after the fields.
2086
	 *
2087
	 * @since 1.0
2088
	 *
2089
	 * @param int $form_id The form ID.
2090
	 */
2091
	do_action( 'give_hidden_fields_after', $form_id );
2092
2093
}
2094
2095
/**
2096
 * Filter Success Page Content.
2097
 *
2098
 * Applies filters to the success page content.
2099
 *
2100
 * @since 1.0
2101
 *
2102
 * @param  string $content Content before filters.
2103
 *
2104
 * @return string $content Filtered content.
2105
 */
2106
function give_filter_success_page_content( $content ) {
2107
2108
	$give_options = give_get_settings();
2109
2110
	if ( isset( $give_options['success_page'] ) && isset( $_GET['payment-confirmation'] ) && is_page( $give_options['success_page'] ) ) {
2111
		if ( has_filter( 'give_payment_confirm_' . $_GET['payment-confirmation'] ) ) {
2112
			$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...
2113
		}
2114
	}
2115
2116
	return $content;
2117
}
2118
2119
add_filter( 'the_content', 'give_filter_success_page_content' );
2120
2121
/**
2122
 * Test Mode Frontend Warning.
2123
 *
2124
 * Displays a notice on the frontend for donation forms.
2125
 *
2126
 * @since 1.1
2127
 */
2128
function give_test_mode_frontend_warning() {
2129
2130
	if ( give_is_test_mode() ) {
2131
		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>';
2132
	}
2133
}
2134
2135
add_action( 'give_pre_form', 'give_test_mode_frontend_warning', 10 );
2136
2137
/**
2138
 * Members-only Form.
2139
 *
2140
 * If "Disable Guest Donations" and "Display Register / Login" is set to none.
2141
 *
2142
 * @since  1.4.1
2143
 *
2144
 * @param  string $final_output
2145
 * @param  array  $args
2146
 *
2147
 * @return string
2148
 */
2149
function give_members_only_form( $final_output, $args ) {
2150
2151
	$form_id = isset( $args['form_id'] ) ? $args['form_id'] : 0;
2152
2153
	// Sanity Check: Must have form_id & not be logged in.
2154
	if ( empty( $form_id ) || is_user_logged_in() ) {
2155
		return $final_output;
2156
	}
2157
2158
	// Logged in only and Register / Login set to none.
2159
	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...
2160
2161
		$final_output = Give()->notices->print_frontend_notice( esc_html__( 'Please log in in order to complete your donation.', 'give' ), false );
2162
2163
		return apply_filters( 'give_members_only_output', $final_output, $form_id );
2164
2165
	}
2166
2167
	return $final_output;
2168
2169
}
2170
2171
add_filter( 'give_donate_form', 'give_members_only_form', 10, 2 );
2172
2173
2174
/**
2175
 * Add donation form hidden fields.
2176
 *
2177
 * @since 1.8.17
2178
 *
2179
 * @param int              $form_id
2180
 * @param array            $args
2181
 * @param Give_Donate_Form $form
2182
 */
2183
function __give_form_add_donation_hidden_field( $form_id, $args, $form ) {
2184
	$id_prefix = ! empty( $args['id_prefix'] ) ? $args['id_prefix'] : '';
2185
	?>
2186
	<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...
2187
	<input type="hidden" name="give-form-id" value="<?php echo intval( $form_id ); ?>"/>
2188
	<input type="hidden" name="give-form-title" value="<?php echo esc_html( $form->post_title ); ?>"/>
2189
	<input type="hidden" name="give-current-url" value="<?php echo esc_url( give_get_current_page_url() ); ?>"/>
2190
	<input type="hidden" name="give-form-url" value="<?php echo esc_url( give_get_current_page_url() ); ?>"/>
2191
	<?php
2192
	// Get the custom option amount.
2193
	$custom_amount = give_get_meta( $form_id, '_give_custom_amount', true );
2194
2195
	// If custom amount enabled.
2196
	if ( give_is_setting_enabled( $custom_amount ) ) {
2197
		?>
2198
		<input type="hidden" name="give-form-minimum"
2199
		       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...
2200
		<input type="hidden" name="give-form-maximum"
2201
		       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...
2202
		<?php
2203
	}
2204
2205
	// WP nonce field.
2206
	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...
2207
		'/>',
2208
		'data-time="' . time() . '" data-nonce-life="' . give_get_nonce_life() . '"/>',
2209
		give_get_nonce_field( "give_donation_form_nonce_{$form_id}", 'give-form-hash', false )
2210
	);
2211
2212
	// Price ID hidden field for variable (multi-level) donation forms.
2213
	if ( give_has_variable_prices( $form_id ) ) {
2214
		// Get the default price ID.
2215
		$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...
2216
		$price_id      = isset( $default_price['_give_id']['level_id'] ) ? $default_price['_give_id']['level_id'] : 0;
2217
2218
		echo sprintf(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'sprintf'
Loading history...
2219
			'<input type="hidden" name="give-price-id" value="%s"/>',
2220
			$price_id
2221
		);
2222
	}
2223
}
2224
2225
add_action( 'give_donation_form_top', '__give_form_add_donation_hidden_field', 0, 3 );
2226
2227
/**
2228
 * Add currency settings on donation form.
2229
 *
2230
 * @since 1.8.17
2231
 *
2232
 * @param array            $form_html_tags
2233
 * @param Give_Donate_Form $form
2234
 *
2235
 * @return array
2236
 */
2237
function __give_form_add_currency_settings( $form_html_tags, $form ) {
2238
	$form_currency     = give_get_currency( $form->ID );
2239
	$currency_settings = give_get_currency_formatting_settings( $form_currency );
2240
2241
	// Check if currency exist.
2242
	if ( empty( $currency_settings ) ) {
2243
		return $form_html_tags;
2244
	}
2245
2246
	$form_html_tags['data-currency_symbol'] = give_currency_symbol( $form_currency );
2247
	$form_html_tags['data-currency_code']   = $form_currency;
2248
2249
	if ( ! empty( $currency_settings ) ) {
2250
		foreach ( $currency_settings as $key => $value ) {
2251
			$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...
2252
		}
2253
	}
2254
2255
	return $form_html_tags;
2256
}
2257
2258
add_filter( 'give_form_html_tags', '__give_form_add_currency_settings', 0, 2 );
2259
2260
/**
2261
 * Adds classes to progress bar container.
2262
 *
2263
 * @since 2.1
2264
 *
2265
 * @param string $class_goal
2266
 *
2267
 * @return string
2268
 */
2269
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...
2270
	$class_goal = 'progress progress-striped active';
2271
2272
	return $class_goal;
2273
}
2274
2275
/**
2276
 * Adds classes to progress bar span tag.
2277
 *
2278
 * @since 2.1
2279
 *
2280
 * @param string $class_bar
2281
 *
2282
 * @return string
2283
 */
2284
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...
2285
	$class_bar = 'bar';
2286
2287
	return $class_bar;
2288
}
2289
2290
/**
2291
 * Add a class to the form wrap on the grid page.
2292
 *
2293
 * @param array $class Array of form wrapper classes.
2294
 * @param int   $id    ID of the form.
2295
 * @param array $args  Additional args.
2296
 *
2297
 * @since 2.1
2298
 *
2299
 * @return array
2300
 */
2301
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...
2302
	$class[] = 'give-form-grid-wrap';
2303
2304
	foreach ( $class as $index => $item ) {
2305
		if ( false !== strpos( $item, 'give-display-' ) ) {
2306
			unset( $class[ $index ] );
2307
		}
2308
	}
2309
2310
	return $class;
2311
}
2312
2313
/**
2314
 * Add hidden field to Form Grid page
2315
 *
2316
 * @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...
2317
 * @param array            $args    An array of form arguments.
2318
 * @param Give_Donate_Form $form    Form object.
2319
 *
2320
 * @since 2.1
2321
 */
2322
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...
2323
	echo '<input type="hidden" name="is-form-grid" value="true" />';
2324
}
2325
2326
/**
2327
 * Redirect to the same paginated URL on the Form Grid page
2328
 * and adds query parameters to open the popup again after
2329
 * redirection.
2330
 *
2331
 * @param string $redirect URL for redirection.
2332
 * @param array  $args     Array of additional args.
2333
 *
2334
 * @since 2.1
2335
 * @return string
2336
 */
2337
function give_redirect_and_popup_form( $redirect, $args ) {
2338
2339
	// Check the page has Form Grid.
2340
	$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...
2341
2342
	if ( 'true' === $is_form_grid ) {
2343
2344
		$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...
2345
		$form_id      = $args['form-id'];
2346
2347
		// Get the URL without Query parameters.
2348
		$redirect = strtok( $redirect, '?' );
2349
2350
		// Add query parameters 'form-id' and 'payment-mode'.
2351
		$redirect = add_query_arg(
2352
			array(
2353
				'form-id'      => $form_id,
2354
				'payment-mode' => $payment_mode,
2355
			), $redirect
2356
		);
2357
	}
2358
2359
	// Return the modified URL.
2360
	return $redirect;
2361
}
2362
2363
add_filter( 'give_send_back_to_checkout', 'give_redirect_and_popup_form', 10, 2 );
2364