Completed
Push — issue/currency-switcher-suppor... ( ae3c43 )
by Ravinder
813:16 queued 807:21
created

template.php ➔ give_output_levels()   F

Complexity

Conditions 27
Paths 14

Size

Total Lines 111

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 27
nc 14
nop 1
dl 0
loc 111
rs 3.3333
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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

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

Commonly applied refactorings include:

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