Completed
Push — issues/3312 ( 6b1a83 )
by Ravinder
1313:55 queued 1307:48
created

template.php ➔ give_user_info_fields()   F

Complexity

Conditions 32
Paths > 20000

Size

Total Lines 209

Duplication

Lines 44
Ratio 21.05 %

Importance

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