Test Failed
Push — release/2.1.3 ( bfa460 )
by Ravinder
16:23
created

template.php ➔ give_payment_mode_select()   C

Complexity

Conditions 7
Paths 40

Size

Total Lines 131
Code Lines 60

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 60
nc 40
nop 2
dl 0
loc 131
rs 6.4589
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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

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

Commonly applied refactorings include:

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