Test Failed
Pull Request — master (#2482)
by Devin
05:37
created

template.php ➔ give_get_donation_form()   C

Complexity

Conditions 12
Paths 24

Size

Total Lines 191
Code Lines 61

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 57
CRAP Score 12.4792

Importance

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

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

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

Loading history...
513
				$output .= '<li>';
514
				$output .= '<button type="button" data-price-id="custom" class="give-donation-level-btn give-btn give-btn-level-custom" value="custom">';
515
				$output .= $custom_amount_text;
516
				$output .= '</button>';
517
				$output .= '</li>';
518
			}
519
520
			$output .= '</ul>';
521
522
			break;
523
524
		case 'radios':
525
526
			$output .= '<ul id="give-donation-level-radio-list" class="give-donation-levels-wrap">';
527
528
			foreach ( $prices as $price ) {
529
				$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 );
530
				$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 );
531
532
				$output .= '<li>';
533
				$output .= '<input type="radio" data-price-id="' . $price['_give_id']['level_id'] . '" class="' . $level_classes . '" name="give-radio-donation-level" id="give-radio-level-' . $price['_give_id']['level_id'] . '" ' . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? 'checked="checked"' : '' ) . ' value="' . give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ) . '">';
534
				$output .= '<label for="give-radio-level-' . $price['_give_id']['level_id'] . '">' . $level_text . '</label>';
535
				$output .= '</li>';
536
537
			}
538
539
			//Custom Amount.
540 View Code Duplication
			if ( give_is_setting_enabled( $custom_amount ) && ! empty( $custom_amount_text ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
541
				$output .= '<li>';
542
				$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">';
543
				$output .= '<label for="give-radio-level-custom">' . $custom_amount_text . '</label>';
544
				$output .= '</li>';
545
			}
546
547
			$output .= '</ul>';
548
549
			break;
550
551
		case 'dropdown':
552
553
			$output .= '<label for="give-donation-level-select-' . $form_id . '" class="give-hidden">' . esc_html__( 'Choose Your Donation Amount', 'give' ) . ':</label>';
554
			$output .= '<select id="give-donation-level-select-' . $form_id . '" class="give-select give-select-level give-donation-levels-wrap">';
555
556
			//first loop through prices.
557
			foreach ( $prices as $price ) {
558
				$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 );
559
				$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 );
560
561
				$output .= '<option data-price-id="' . $price['_give_id']['level_id'] . '" class="' . $level_classes . '" ' . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? 'selected="selected"' : '' ) . ' value="' . give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ) . '">';
562
				$output .= $level_text;
563
				$output .= '</option>';
564
565
			}
566
567
			//Custom Amount.
568
			if ( give_is_setting_enabled( $custom_amount ) && ! empty( $custom_amount_text ) ) {
569
				$output .= '<option data-price-id="custom" class="give-donation-level-custom" value="custom">' . $custom_amount_text . '</option>';
570
			}
571
572
			$output .= '</select>';
573
574
			break;
575
	}
576
577
	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...
578
}
579
580
/**
581
 * Display Reveal & Lightbox Button.
582
 *
583
 * Outputs a button to reveal form fields.
584
 *
585
 * @since  1.0
586
 *
587
 * @param  int   $form_id The form ID.
588
 * @param  array $args    An array of form arguments.
589
 *
590
 * @return string Checkout button.
591
 */
592
function give_display_checkout_button( $form_id, $args ) {
593
594
	$display_option = ( isset( $args['display_style'] ) && ! empty( $args['display_style'] ) )
595
		? $args['display_style']
596
		: give_get_meta( $form_id, '_give_payment_display', true );
597
598
	if ( 'button' === $display_option ) {
599
		$display_option = 'modal';
600
	} elseif ( $display_option === 'onpage' ) {
0 ignored issues
show
introduced by
Found "=== '". Use Yoda Condition checks, you must
Loading history...
601
		return '';
602
	}
603
604
	$display_label_field = give_get_meta( $form_id, '_give_reveal_label', true );
605
	$display_label       = ! empty( $args['continue_button_title'] ) ? $args['continue_button_title'] : ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) );
606
607
	$output = '<button type="button" class="give-btn give-btn-' . $display_option . '">' . $display_label . '</button>';
608
609
	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...
610
}
611
612
add_action( 'give_after_donation_levels', 'give_display_checkout_button', 10, 2 );
613
614
/**
615
 * Shows the User Info fields in the Personal Info box, more fields can be added via the hooks provided.
616
 *
617
 * @since  1.0
618
 *
619
 * @param  int $form_id The form ID.
620
 *
621
 * @return void
622
 */
623
function give_user_info_fields( $form_id ) {
624
	// Get user info.
625
	$give_user_info = _give_get_prefill_form_field_values( $form_id );
626
627
	/**
628
	 * Fire before user personal information fields
629
	 *
630
	 * @since 1.7
631
	 */
632
	do_action( 'give_donation_form_before_personal_info', $form_id );
633
	?>
634
	<fieldset id="give_checkout_user_info">
635
		<legend><?php echo apply_filters( 'give_checkout_personal_info_text', esc_html__( '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...
636
		<p id="give-first-name-wrap" class="form-row form-row-first form-row-responsive">
637
			<label class="give-label" for="give-first">
638
				<?php esc_html_e( 'First Name', 'give' ); ?>
639
				<?php if ( give_field_is_required( 'give_first', $form_id ) ) : ?>
640
					<span class="give-required-indicator">*</span>
641
				<?php endif ?>
642
				<span class="give-tooltip give-icon give-icon-question"
643
					  data-tooltip="<?php esc_attr_e( 'We will use this to personalize your account experience.', 'give' ); ?>"></span>
644
			</label>
645
			<input
646
					class="give-input required"
647
					type="text"
648
					name="give_first"
649
					placeholder="<?php esc_attr_e( 'First Name', 'give' ); ?>"
650
					id="give-first"
651
					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...
652
				<?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...
653
			/>
654
		</p>
655
656
		<p id="give-last-name-wrap" class="form-row form-row-last form-row-responsive">
657
			<label class="give-label" for="give-last">
658
				<?php esc_html_e( 'Last Name', 'give' ); ?>
659
				<?php if ( give_field_is_required( 'give_last', $form_id ) ) : ?>
660
					<span class="give-required-indicator">*</span>
661
				<?php endif ?>
662
				<span class="give-tooltip give-icon give-icon-question"
663
					  data-tooltip="<?php esc_attr_e( 'We will use this as well to personalize your account experience.', 'give' ); ?>"></span>
664
			</label>
665
666
			<input
667
					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...
668
					type="text"
669
					name="give_last"
670
					id="give-last"
671
					placeholder="<?php esc_attr_e( 'Last Name', 'give' ); ?>"
672
					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...
673
				<?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...
674
			/>
675
		</p>
676
677
		<?php
678
		/**
679
		 * Fire before user email field
680
		 *
681
		 * @since 1.7
682
		 */
683
		do_action( 'give_donation_form_before_email', $form_id );
684
		?>
685
		<p id="give-email-wrap" class="form-row form-row-wide">
686
			<label class="give-label" for="give-email">
687
				<?php esc_html_e( 'Email Address', 'give' ); ?>
688
				<?php if ( give_field_is_required( 'give_email', $form_id ) ) { ?>
689
					<span class="give-required-indicator">*</span>
690
				<?php } ?>
691
				<span class="give-tooltip give-icon give-icon-question"
692
					  data-tooltip="<?php esc_attr_e( 'We will send the donation receipt to this address.', 'give' ); ?>"></span>
693
			</label>
694
695
			<input
696
					class="give-input required"
697
					type="email"
698
					name="give_email"
699
					placeholder="<?php esc_attr_e( 'Email Address', 'give' ); ?>"
700
					id="give-email"
701
					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...
702
				<?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...
703
			/>
704
705
		</p>
706
		<?php
707
		/**
708
		 * Fire after user email field
709
		 *
710
		 * @since 1.7
711
		 */
712
		do_action( 'give_donation_form_after_email', $form_id );
713
714
		/**
715
		 * Fire after personal email field
716
		 *
717
		 * @since 1.7
718
		 */
719
		do_action( 'give_donation_form_user_info', $form_id );
720
		?>
721
	</fieldset>
722
	<?php
723
	/**
724
	 * Fire after user personal information fields
725
	 *
726
	 * @since 1.7
727
	 */
728
	do_action( 'give_donation_form_after_personal_info', $form_id );
729
}
730
731
add_action( 'give_donation_form_after_user_info', 'give_user_info_fields' );
732
add_action( 'give_register_fields_before', 'give_user_info_fields' );
733
734
/**
735
 * Renders the credit card info form.
736
 *
737
 * @since  1.0
738
 *
739
 * @param  int $form_id The form ID.
740
 *
741
 * @return void
742
 */
743
function give_get_cc_form( $form_id ) {
744
745
	ob_start();
746
747
	/**
748
	 * Fires while rendering credit card info form, before the fields.
749
	 *
750
	 * @since 1.0
751
	 *
752
	 * @param int $form_id The form ID.
753
	 */
754
	do_action( 'give_before_cc_fields', $form_id );
755
	?>
756
	<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...
757
		<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...
758
		<?php if ( is_ssl() ) : ?>
759
			<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...
760
				<span class="give-icon padlock"></span>
761
				<span><?php esc_html_e( 'This is a secure SSL encrypted payment.', 'give' ); ?></span>
762
			</div>
763
		<?php endif; ?>
764
		<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...
765
			<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...
766
				<?php esc_html_e( 'Card Number', 'give' ); ?>
767
				<span class="give-required-indicator">*</span>
768
				<span class="give-tooltip give-icon give-icon-question"
769
					  data-tooltip="<?php esc_attr_e( 'The (typically) 16 digits on the front of your credit card.', 'give' ); ?>"></span>
770
				<span class="card-type"></span>
771
			</label>
772
773
			<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...
774
				   class="card-number give-input required" placeholder="<?php esc_attr_e( 'Card number', 'give' ); ?>"
775
				   required aria-required="true"/>
776
		</p>
777
778
		<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...
779
			<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...
780
				<?php esc_html_e( 'CVC', 'give' ); ?>
781
				<span class="give-required-indicator">*</span>
782
				<span class="give-tooltip give-icon give-icon-question"
783
					  data-tooltip="<?php esc_attr_e( 'The 3 digit (back) or 4 digit (front) value on your card.', 'give' ); ?>"></span>
784
			</label>
785
786
			<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...
787
				   class="card-cvc give-input required" placeholder="<?php esc_attr_e( 'Security code', 'give' ); ?>"
788
				   required aria-required="true"/>
789
		</p>
790
791
		<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...
792
			<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...
793
				<?php esc_html_e( 'Name on the Card', 'give' ); ?>
794
				<span class="give-required-indicator">*</span>
795
				<span class="give-tooltip give-icon give-icon-question"
796
					  data-tooltip="<?php esc_attr_e( 'The name printed on the front of your credit card.', 'give' ); ?>"></span>
797
			</label>
798
799
			<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...
800
				   class="card-name give-input required" placeholder="<?php esc_attr_e( 'Card name', 'give' ); ?>"
801
				   required aria-required="true"/>
802
		</p>
803
		<?php
804
		/**
805
		 * Fires while rendering credit card info form, before expiration fields.
806
		 *
807
		 * @since 1.0
808
		 *
809
		 * @param int $form_id The form ID.
810
		 */
811
		do_action( 'give_before_cc_expiration' );
812
		?>
813
		<p class="card-expiration form-row form-row-one-third form-row-responsive">
814
			<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...
815
				<?php esc_html_e( 'Expiration', 'give' ); ?>
816
				<span class="give-required-indicator">*</span>
817
				<span class="give-tooltip give-icon give-icon-question"
818
					  data-tooltip="<?php esc_attr_e( 'The date your credit card expires, typically on the front of the card.', 'give' ); ?>"></span>
819
			</label>
820
821
			<input type="hidden" id="card_exp_month-<?php echo $form_id ?>" name="card_exp_month"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
822
				   class="card-expiry-month"/>
823
			<input type="hidden" id="card_exp_year-<?php echo $form_id ?>" name="card_exp_year"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
824
				   class="card-expiry-year"/>
825
826
			<input type="tel" autocomplete="off" name="card_expiry" id="card_expiry-<?php echo $form_id ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
827
				   class="card-expiry give-input required" placeholder="<?php esc_attr_e( 'MM / YY', 'give' ); ?>"
828
				   required aria-required="true"/>
829
		</p>
830
		<?php
831
		/**
832
		 * Fires while rendering credit card info form, after expiration fields.
833
		 *
834
		 * @since 1.0
835
		 *
836
		 * @param int $form_id The form ID.
837
		 */
838
		do_action( 'give_after_cc_expiration', $form_id );
839
		?>
840
	</fieldset>
841
	<?php
842
	/**
843
	 * Fires while rendering credit card info form, before the fields.
844
	 *
845
	 * @since 1.0
846
	 *
847
	 * @param int $form_id The form ID.
848
	 */
849
	do_action( 'give_after_cc_fields', $form_id );
850
851
	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...
852
}
853
854
add_action( 'give_cc_form', 'give_get_cc_form' );
855
856
/**
857
 * Outputs the default credit card address fields.
858
 *
859
 * @since  1.0
860
 *
861
 * @param  int $form_id The form ID.
862
 *
863
 * @return void
864
 */
865
function give_default_cc_address_fields( $form_id ) {
866
	// Get user info.
867
	$give_user_info = _give_get_prefill_form_field_values( $form_id );
868
869
	$logged_in = is_user_logged_in();
870
871
	if ( $logged_in ) {
872
		$user_address = get_user_meta( get_current_user_id(), '_give_user_address', true );
0 ignored issues
show
introduced by
get_user_meta() usage is highly discouraged, check VIP documentation on "Working with wp_users"
Loading history...
873
	}
874
	$line1 = $logged_in && ! empty( $user_address['line1'] ) ? $user_address['line1'] : '';
0 ignored issues
show
Unused Code introduced by
$line1 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...
875
	$line2 = $logged_in && ! empty( $user_address['line2'] ) ? $user_address['line2'] : '';
0 ignored issues
show
Unused Code introduced by
$line2 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...
876
	$city  = $logged_in && ! empty( $user_address['city'] ) ? $user_address['city'] : '';
0 ignored issues
show
Unused Code introduced by
$city 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...
877
	$zip   = $logged_in && ! empty( $user_address['zip'] ) ? $user_address['zip'] : '';
0 ignored issues
show
Unused Code introduced by
$zip 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...
878
879
	ob_start();
880
	?>
881
	<fieldset id="give_cc_address" class="cc-address">
882
		<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...
883
		<?php
884
		/**
885
		 * Fires while rendering credit card billing form, before address fields.
886
		 *
887
		 * @since 1.0
888
		 *
889
		 * @param int $form_id The form ID.
890
		 */
891
		do_action( 'give_cc_billing_top' );
892
893
		// For Country.
894
		$selected_country = give_get_country();
895 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...
896
			$selected_country = $give_user_info['billing_country'];
897
		}
898
		$countries = give_get_country_list();
899
900
		// For state
901
		$selected_state = '';
902
		if ( $selected_country === give_get_country() ) {
903
			// Get defalut selected state by admin.
904
			$selected_state = give_get_state();
905
		}
906
		// Get the last payment made by user states.
907
		if ( ! empty( $give_user_info['card_state'] ) && '*' !== $give_user_info['card_state'] ) {
908
			$selected_state = $give_user_info['card_state'];
909
		}
910
		// Get the country code
911 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...
912
			$selected_country = $give_user_info['billing_country'];
913
		}
914
		$label        = __( 'State', 'give' );
915
		$states_label = give_get_states_label();
916
		// Check if $country code exists in the array key for states label.
917
		if ( array_key_exists( $selected_country, $states_label ) ) {
918
			$label = $states_label[ $selected_country ];
919
		}
920
		$states = give_get_states( $selected_country );
921
		// Get the country list that do not have any states init.
922
		$no_states_country = give_no_states_country_list();
923
		// Get the country list that does not require states.
924
		$states_not_required_country_list = give_states_not_required_country_list();
925
926
		?>
927
	    <p id="give-card-country-wrap" class="form-row form-row-wide">
928
		    <label for="billing_country" class="give-label">
929
			    <?php esc_html_e( 'Country', 'give' ); ?>
930
			    <?php if ( give_field_is_required( 'billing_country', $form_id ) ) : ?>
931
				    <span class="give-required-indicator">*</span>
932
			    <?php endif; ?>
933
			    <span class="give-tooltip give-icon give-icon-question"
934
			          data-tooltip="<?php esc_attr_e( 'The country for your billing address.', 'give' ); ?>"></span>
935
		    </label>
936
937
		    <select
938
				    name="billing_country"
939
				    id="billing_country"
940
				    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...
941
			    <?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...
942
		    >
943
			    <?php
944 View Code Duplication
			    foreach ( $countries as $country_code => $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...
945
				    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...
946
			    }
947
			    ?>
948
		    </select>
949
	    </p>
950
951
	    <p id="give-card-address-wrap" class="form-row form-row-wide">
952
		    <label for="card_address" class="give-label">
953
			    <?php esc_html_e( 'Address 1', 'give' ); ?>
954
			    <?php
955
			    if ( give_field_is_required( 'card_address', $form_id ) ) : ?>
956
				    <span class="give-required-indicator">*</span>
957
			    <?php endif; ?>
958
			    <span class="give-tooltip give-icon give-icon-question"
959
			          data-tooltip="<?php esc_attr_e( 'The primary billing address for your credit card.', 'give' ); ?>"></span>
960
		    </label>
961
962
		    <input
963
				    type="text"
964
				    id="card_address"
965
				    name="card_address"
966
				    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...
967
				    placeholder="<?php esc_attr_e( 'Address line 1', 'give' ); ?>"
968
				    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...
969
			    <?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...
970
		    />
971
	    </p>
972
973
	    <p id="give-card-address-2-wrap" class="form-row form-row-wide">
974
		    <label for="card_address_2" class="give-label">
975
			    <?php esc_html_e( 'Address 2', 'give' ); ?>
976
			    <?php if ( give_field_is_required( 'card_address_2', $form_id ) ) : ?>
977
				    <span class="give-required-indicator">*</span>
978
			    <?php endif; ?>
979
			    <span class="give-tooltip give-icon give-icon-question"
980
			          data-tooltip="<?php esc_attr_e( '(optional) The suite, apt no, PO box, etc, associated with your billing address.', 'give' ); ?>"></span>
981
		    </label>
982
983
		    <input
984
				    type="text"
985
				    id="card_address_2"
986
				    name="card_address_2"
987
				    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...
988
				    placeholder="<?php esc_attr_e( 'Address line 2', 'give' ); ?>"
989
				    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...
990
			    <?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...
991
		    />
992
	    </p>
993
994
	    <p id="give-card-city-wrap" class="form-row form-row-wide">
995 1
		    <label for="card_city" class="give-label">
996
			    <?php esc_html_e( 'City', 'give' ); ?>
997
			    <?php if ( give_field_is_required( 'card_city', $form_id ) ) : ?>
998
				    <span class="give-required-indicator">*</span>
999
			    <?php endif; ?>
1000
			    <span class="give-tooltip give-icon give-icon-question"
1001
			          data-tooltip="<?php esc_attr_e( 'The city for your billing address.', 'give' ); ?>"></span>
1002
		    </label>
1003
		    <input
1004
				    type="text"
1005
				    id="card_city"
1006
				    name="card_city"
1007
				    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...
1008
				    placeholder="<?php esc_attr_e( 'City', 'give' ); ?>"
1009
				    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...
1010
			    <?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...
1011 1
		    />
1012 1
	    </p>
1013 1
1014 1
	    <p id="give-card-state-wrap"
1015 1
	       class="form-row form-row-first form-row-responsive <?php echo ( ! empty( $selected_country ) && array_key_exists( $selected_country, $no_states_country ) ) ? 'give-hidden' : ''; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1016
		    <label for="card_state" class="give-label">
1017
			    <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...
1018
			    <?php if ( give_field_is_required( 'card_state', $form_id ) ) :
1019
				    ?>
1020
				    <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...
1021
			    <?php endif; ?>
1022
			    <span class="give-tooltip give-icon give-icon-question"
1023
			          data-tooltip="<?php esc_attr_e( 'The state, province, or county for your billing address.', 'give' ); ?>"></span>
1024
		    </label>
1025
		    <?php
1026
1027
		    if ( ! empty( $states ) ) : ?>
1028
			    <select
1029
				    name="card_state"
1030
				    id="card_state"
1031
				    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...
1032
				    <?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...
1033 1
				    <?php
1034 View Code Duplication
				    foreach ( $states as $state_code => $state ) {
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...
1035
					    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...
1036
				    }
1037
				    ?>
1038
			    </select>
1039
		    <?php else : ?>
1040
			    <input type="text" size="6" name="card_state" id="card_state" class="card_state give-input"
1041
			           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...
1042
		    <?php endif; ?>
1043
	    </p>
1044
1045
	    <p id="give-card-zip-wrap" class="form-row <?php echo ( ! empty( $selected_country ) && array_key_exists( $selected_country, $no_states_country ) ) ? 'form-row-wide' : 'form-row-last'; ?> form-row-responsive">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1046
		    <label for="card_zip" class="give-label">
1047
			    <?php esc_html_e( 'Zip / Postal Code', 'give' ); ?>
1048
			    <?php if ( give_field_is_required( 'card_zip', $form_id ) ) : ?>
1049
				    <span class="give-required-indicator">*</span>
1050
			    <?php endif; ?>
1051
			    <span class="give-tooltip give-icon give-icon-question"
1052 1
			          data-tooltip="<?php esc_attr_e( 'The zip or postal code for your billing address.', 'give' ); ?>"></span>
1053 1
		    </label>
1054 1
1055
		    <input
1056
				    type="text"
1057
				    size="4"
1058
				    id="card_zip"
1059
				    name="card_zip"
1060
				    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...
1061
				    placeholder="<?php esc_attr_e( 'Zip / Postal Code', 'give' ); ?>"
1062
				    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...
1063
			    <?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...
1064
		    />
1065
	    </p>
1066
1067
		<?php
1068
		/**
1069
		 * Fires while rendering credit card billing form, after address fields.
1070
		 *
1071
		 * @since 1.0
1072
		 *
1073
		 * @param int $form_id The form ID.
1074
		 */
1075
		do_action( 'give_cc_billing_bottom' );
1076
		?>
1077 1
	</fieldset>
1078
	<?php
1079
	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...
1080
}
1081
1082
add_action( 'give_after_cc_fields', 'give_default_cc_address_fields' );
1083
1084
1085
/**
1086
 * Renders the user registration fields. If the user is logged in, a login form is displayed other a registration form
1087
 * is provided for the user to create an account.
1088
 *
1089
 * @since  1.0
1090
 *
1091
 * @param  int $form_id The form ID.
1092
 *
1093 1
 * @return string
1094
 */
1095
function give_get_register_fields( $form_id ) {
1096
1097 1
	global $user_ID;
1098
1099
	if ( is_user_logged_in() ) {
1100 1
		$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...
1101
	}
1102
1103
	$show_register_form = give_show_login_register_option( $form_id );
1104
1105
	ob_start(); ?>
1106
	<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...
1107
1108
		<?php if ( $show_register_form == 'both' ) { ?>
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
1109 1
			<div class="give-login-account-wrap">
1110
				<p class="give-login-message"><?php esc_html_e( 'Already have an account?', 'give' ); ?>&nbsp;
1111
					<a href="<?php echo esc_url( add_query_arg( 'login', 1 ) ); ?>" class="give-checkout-login"
1112
					   data-action="give_checkout_login"><?php esc_html_e( 'Login', 'give' ); ?></a>
1113
				</p>
1114
				<p class="give-loading-text">
1115
					<span class="give-loading-animation"></span>
1116
				</p>
1117
			</div>
1118
		<?php } ?>
1119
1120
		<?php
1121
		/**
1122
		 * Fires while rendering user registration form, before registration fields.
1123
		 *
1124
		 * @since 1.0
1125
		 *
1126
		 * @param int $form_id The form ID.
1127
		 */
1128
		do_action( 'give_register_fields_before', $form_id );
1129
		?>
1130
1131
		<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...
1132
			<legend>
1133
				<?php
1134
				echo apply_filters( 'give_create_account_fieldset_heading', esc_html__( 'Create an account', 'give' ) );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
1135
				if ( ! give_logged_in_only( $form_id ) ) {
1136 1
					echo ' <span class="sub-text">' . esc_html__( '(optional)', 'give' ) . '</span>';
1137
				}
1138
				?>
1139
			</legend>
1140
			<?php
1141
			/**
1142
			 * Fires while rendering user registration form, before account fields.
1143
			 *
1144
			 * @since 1.0
1145
			 *
1146
			 * @param int $form_id The form ID.
1147
			 */
1148
			do_action( 'give_register_account_fields_before', $form_id );
1149
			?>
1150
			<div id="give-user-login-wrap-<?php echo $form_id; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1151
				 class="form-row form-row-one-third form-row-first form-row-responsive">
1152
				<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...
1153 1
					<?php esc_html_e( 'Username', 'give' ); ?>
1154 1
					<?php if ( give_logged_in_only( $form_id ) ) { ?>
1155
						<span class="give-required-indicator">*</span>
1156
					<?php } ?>
1157
					<span class="give-tooltip give-icon give-icon-question"
1158
						  data-tooltip="<?php esc_attr_e( 'The username you will use to log into your account.', 'give' ); ?>"></span>
1159
				</label>
1160
1161 1
				<input name="give_user_login" id="give-user-login-<?php echo $form_id; ?>" class="give-input"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1162
					   type="text"
1163
					   placeholder="<?php esc_attr_e( '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...
1164
			</div>
1165
1166
			<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...
1167
				 class="form-row form-row-one-third form-row-responsive">
1168
				<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...
1169
					<?php esc_html_e( 'Password', 'give' ); ?>
1170
					<?php if ( give_logged_in_only( $form_id ) ) { ?>
1171
						<span class="give-required-indicator">*</span>
1172
					<?php } ?>
1173
					<span class="give-tooltip give-icon give-icon-question"
1174
						  data-tooltip="<?php esc_attr_e( 'The password used to access your account.', 'give' ); ?>"></span>
1175
				</label>
1176 1
1177
				<input name="give_user_pass" id="give-user-pass-<?php echo $form_id; ?>" class="give-input"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1178 1
					   placeholder="<?php esc_attr_e( 'Password', 'give' ); ?>"
1179
					   type="password"<?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...
1180
			</div>
1181
1182
			<div id="give-user-pass-confirm-wrap-<?php echo $form_id; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1183
				 class="give-register-password form-row form-row-one-third form-row-responsive">
1184
				<label for="give-user-pass-confirm-<?php echo $form_id; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1185
					<?php esc_html_e( 'Confirm PW', 'give' ); ?>
1186
					<?php if ( give_logged_in_only( $form_id ) ) { ?>
1187
						<span class="give-required-indicator">*</span>
1188
					<?php } ?>
1189
					<span class="give-tooltip give-icon give-icon-question"
1190
						  data-tooltip="<?php esc_attr_e( 'Please retype your password to confirm.', 'give' ); ?>"></span>
1191
				</label>
1192 1
1193
				<input name="give_user_pass_confirm" id="give-user-pass-confirm-<?php echo $form_id; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1194
					   class="give-input" placeholder="<?php esc_attr_e( 'Confirm password', 'give' ); ?>"
1195
					   type="password"<?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...
1196
			</div>
1197
			<?php
1198
			/**
1199
			 * Fires while rendering user registration form, after account fields.
1200
			 *
1201
			 * @since 1.0
1202
			 *
1203
			 * @param int $form_id The form ID.
1204
			 */
1205
			do_action( 'give_register_account_fields_after', $form_id );
1206
			?>
1207
		</fieldset>
1208
1209 1
		<?php
1210 1
		/**
1211 1
		 * Fires while rendering user registration form, after registration fields.
1212 1
		 *
1213 1
		 * @since 1.0
1214 1
		 *
1215 1
		 * @param int $form_id The form ID.
1216 1
		 */
1217
		do_action( 'give_register_fields_after', $form_id );
1218
		?>
1219 1
1220
		<input type="hidden" name="give-purchase-var" value="needs-to-register"/>
1221
1222
		<?php
1223
		/**
1224 1
		 * Fire after register or login form render
1225 1
		 *
1226 1
		 * @since 1.7
1227 1
		 */
1228 1
		do_action( 'give_donation_form_user_info', $form_id );
1229
		?>
1230 1
1231
	</fieldset>
1232
	<?php
1233
	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...
1234
}
1235
1236
add_action( 'give_donation_form_register_fields', 'give_get_register_fields' );
1237
1238
/**
1239
 * Gets the login fields for the login form on the checkout. This function hooks
1240
 * on the give_donation_form_login_fields to display the login form if a user already
1241
 * had an account.
1242
 *
1243
 * @since  1.0
1244
 *
1245
 * @param  int $form_id The form ID.
1246
 *
1247
 * @return string
1248
 */
1249
function give_get_login_fields( $form_id ) {
1250
1251
	$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...
1252
	$show_register_form = give_show_login_register_option( $form_id );
1253
1254
	ob_start();
1255
	?>
1256
	<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...
1257
		<legend><?php echo apply_filters( 'give_account_login_fieldset_heading', esc_html__( '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...
1258
			if ( ! give_logged_in_only( $form_id ) ) {
1259
				echo ' <span class="sub-text">' . esc_html__( '(optional)', 'give' ) . '</span>';
1260
			} ?>
1261
		</legend>
1262
		<?php if ( $show_register_form == 'both' ) { ?>
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
1263
			<p class="give-new-account-link">
1264
				<?php esc_html_e( 'Need to create an account?', 'give' ); ?>&nbsp;
1265
				<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...
1266
				   data-action="give_checkout_register">
1267
					<?php esc_html_e( 'Register', 'give' );
1268
					if ( ! give_logged_in_only( $form_id ) ) {
1269
						echo ' ' . esc_html__( 'and donate as a guest &raquo;', 'give' );
1270
					} ?>
1271
				</a>
1272
			</p>
1273
			<p class="give-loading-text">
1274
				<span class="give-loading-animation"></span>
1275
			</p>
1276
		<?php } ?>
1277
		<?php
1278
		/**
1279
		 * Fires while rendering checkout login form, before the fields.
1280
		 *
1281
		 * @since 1.0
1282
		 *
1283
		 * @param int $form_id The form ID.
1284
		 */
1285
		do_action( 'give_checkout_login_fields_before', $form_id );
1286
		?>
1287
		<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...
1288
			<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...
1289
				<?php esc_html_e( 'Username', 'give' ); ?>
1290
				<?php if ( give_logged_in_only( $form_id ) ) { ?>
1291
					<span class="give-required-indicator">*</span>
1292
				<?php } ?>
1293
			</label>
1294
1295
			<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...
1296
				   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...
1297
				   placeholder="<?php esc_attr_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...
1298
		</div>
1299
1300
		<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...
1301
			 class="give_login_password form-row form-row-last form-row-responsive">
1302 1
			<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...
1303 1
				<?php esc_html_e( 'Password', 'give' ); ?>
1304 1
				<?php if ( give_logged_in_only( $form_id ) ) { ?>
1305
					<span class="give-required-indicator">*</span>
1306 1
				<?php } ?>
1307
			</label>
1308 1
			<input class="give-input<?php echo ( give_logged_in_only( $form_id ) ) ? ' required' : ''; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1309 1
				   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...
1310 1
				   placeholder="<?php esc_attr_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...
1311
			<input type="hidden" name="give-purchase-var" value="needs-to-login"/>
1312
		</div>
1313
1314
		<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...
1315
			 <span class="give-forgot-password ">
1316
				 <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...
1317
					target="_blank"><?php esc_html_e( 'Reset Password', 'give' ) ?></a>
1318
			 </span>
1319
		</div>
1320
1321
		<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...
1322
			<input type="submit" class="give-submit give-btn button" name="give_login_submit"
1323
				   value="<?php esc_attr_e( 'Login', 'give' ); ?>"/>
1324
			<?php if ( $show_register_form !== 'login' ) { ?>
0 ignored issues
show
introduced by
Found "!== '". Use Yoda Condition checks, you must
Loading history...
1325
				<input type="button" data-action="give_cancel_login"
1326
					   class="give-cancel-login give-checkout-register-cancel give-btn button" name="give_login_cancel"
1327
					   value="<?php esc_attr_e( 'Cancel', 'give' ); ?>"/>
1328
			<?php } ?>
1329
			<span class="give-loading-animation"></span>
1330
		</div>
1331
		<?php
1332
		/**
1333
		 * Fires while rendering checkout login form, after the fields.
1334
		 *
1335
		 * @since 1.0
1336
		 *
1337
		 * @param int $form_id The form ID.
1338
		 */
1339
		do_action( 'give_checkout_login_fields_after', $form_id );
1340
		?>
1341
	</fieldset><!--end #give-login-fields-->
1342
	<?php
1343
	echo ob_get_clean();
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'ob_get_clean'
Loading history...
1344
}
1345
1346
add_action( 'give_donation_form_login_fields', 'give_get_login_fields', 10, 1 );
1347
1348
/**
1349
 * Payment Mode Select.
1350
 *
1351
 * Renders the payment mode form by getting all the enabled payment gateways and
1352
 * outputting them as radio buttons for the user to choose the payment gateway. If
1353
 * a default payment gateway has been chosen from the Give Settings, it will be
1354
 * automatically selected.
1355
 *
1356 1
 * @since  1.0
1357
 *
1358
 * @param  int $form_id The form ID.
1359
 *
1360
 * @return void
1361
 */
1362
function give_payment_mode_select( $form_id ) {
1363 1
1364
	$gateways = give_get_enabled_payment_gateways( $form_id );
1365 1
1366
	/**
1367
	 * Fires while selecting payment gateways, before the fields.
1368
	 *
1369
	 * @since 1.7
1370
	 *
1371
	 * @param int $form_id The form ID.
1372
	 */
1373
	do_action( 'give_payment_mode_top', $form_id );
1374
	?>
1375
1376
	<fieldset id="give-payment-mode-select" <?php if ( count( $gateways ) <= 1 ) {
1377
		echo 'style="display: none;"';
1378
	} ?>>
1379
		<?php
1380
		/**
1381
		 * Fires while selecting payment gateways, before the wrap div.
1382
		 *
1383
		 * @since 1.7
1384
		 *
1385
		 * @param int $form_id The form ID.
1386
		 */
1387
		do_action( 'give_payment_mode_before_gateways_wrap' );
1388
		?>
1389
		<legend
1390
				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...
1391
			<span class="give-loading-text"><span
1392
						class="give-loading-animation"></span>
1393
            </span>
1394
		</legend>
1395
1396
		<div id="give-payment-mode-wrap">
1397
			<?php
1398
			/**
1399
			 * Fires while selecting payment gateways, befire the gateways list.
1400
			 *
1401
			 * @since 1.7
1402
			 */
1403 1
			do_action( 'give_payment_mode_before_gateways' )
1404
			?>
1405 1
			<ul id="give-gateway-radio-list">
1406
				<?php
1407
				/**
1408 1
				 * Loop through the active payment gateways.
1409
				 */
1410
				$selected_gateway  = give_get_chosen_gateway( $form_id );
1411
1412
				foreach ( $gateways as $gateway_id => $gateway ) :
1413
					//Determine the default gateway.
1414
					$checked = checked( $gateway_id, $selected_gateway, false );
1415
					$checked_class = $checked ? ' class="give-gateway-option-selected"' : ''; ?>
1416
					<li<?php echo $checked_class ?>>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$checked_class'
Loading history...
1417
						<input type="radio" name="payment-mode" class="give-gateway"
1418
							   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...
1419
							   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...
1420
						<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...
1421
							   class="give-gateway-option"
1422 1
							   id="give-gateway-option-<?php echo esc_attr( $gateway_id ); ?>"> <?php echo esc_html( $gateway['checkout_label'] ); ?></label>
1423
					</li>
1424
					<?php
1425 1
				endforeach;
1426
				?>
1427
			</ul>
1428
			<?php
1429
			/**
1430 1
			 * Fires while selecting payment gateways, before the gateways list.
1431
			 *
1432
			 * @since 1.7
1433
			 */
1434
			do_action( 'give_payment_mode_after_gateways' );
1435
			?>
1436
		</div>
1437
		<?php
1438 1
		/**
1439
		 * Fires while selecting payment gateways, after the wrap div.
1440
		 *
1441
		 * @since 1.7
1442
		 *
1443
		 * @param int $form_id The form ID.
1444
		 */
1445
		do_action( 'give_payment_mode_after_gateways_wrap' );
1446
		?>
1447
	</fieldset>
1448
1449
	<?php
1450
	/**
1451
	 * Fires while selecting payment gateways, after the fields.
1452
	 *
1453
	 * @since 1.7
1454
	 *
1455
	 * @param int $form_id The form ID.
1456
	 */
1457
	do_action( 'give_payment_mode_bottom', $form_id );
1458
	?>
1459
1460
	<div id="give_purchase_form_wrap">
1461
1462
		<?php
1463
		/**
1464
		 * Fire after payment field render.
1465
		 *
1466
		 * @since 1.7
1467
		 */
1468
		do_action( 'give_donation_form', $form_id );
1469
		?>
1470
1471
	</div>
1472
1473
	<?php
1474
	/**
1475
	 * Fire after donation form render.
1476
	 *
1477
	 * @since 1.7
1478
	 */
1479
	do_action( 'give_donation_form_wrap_bottom', $form_id );
1480
}
1481
1482
add_action( 'give_payment_mode_select', 'give_payment_mode_select' );
1483
1484
/**
1485
 * Renders the Checkout Agree to Terms, this displays a checkbox for users to
1486
 * agree the T&Cs set in the Give Settings. This is only displayed if T&Cs are
1487
 * set in the Give Settings.
1488
 *
1489
 * @since  1.0
1490
 *
1491
 * @param  int $form_id The form ID.
1492
 *
1493
 * @return bool
1494
 */
1495
function give_terms_agreement( $form_id ) {
1496
	$form_option = give_get_meta( $form_id, '_give_terms_option', true );
1497
1498
	// Bailout if per form and global term and conditions is not setup.
1499
	if (
1500
		give_is_setting_enabled( $form_option, 'global' )
1501
		&& give_is_setting_enabled( give_get_option( 'terms' ) )
1502
	) {
1503
		$label         = give_get_option( 'agree_to_terms_label', esc_html__( 'Agree to Terms?', 'give' ) );
1504
		$terms         = $terms = give_get_option( 'agreement_text', '' );
1505
		$edit_term_url = admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=display&section=term-and-conditions' );
1506
1507
	} elseif ( give_is_setting_enabled( $form_option ) ) {
1508
		$label         = ( $label = give_get_meta( $form_id, '_give_agree_label', true ) ) ? stripslashes( $label ) : esc_html__( 'Agree to Terms?', 'give' );
1509
		$terms         = give_get_meta( $form_id, '_give_agree_text', true );
1510
		$edit_term_url = admin_url( 'post.php?post=' . $form_id . '&action=edit#form_terms_options' );
1511
1512
	} else {
1513
		return false;
1514
	}
1515
1516
	// Bailout: Check if term and conditions text is empty or not.
1517
	if ( empty( $terms ) ) {
1518
		if ( is_user_logged_in() && current_user_can( 'edit_give_forms' ) ) {
1519
			echo sprintf( __( 'Please enter valid terms and conditions in <a href="%s">this form\'s settings</a>.', 'give' ), $edit_term_url );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'sprintf'
Loading history...
1520
		}
1521
1522
		return false;
1523
	}
1524
1525
	?>
1526
	<fieldset id="give_terms_agreement">
1527
		<legend><?php echo apply_filters( 'give_terms_agreement_text', esc_html__( 'Terms', 'give' ) ); ?></legend>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
1528
		<div id="give_terms" class="give_terms-<?php echo $form_id; ?>" style="display:none;">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1529
			<?php
1530
			/**
1531
			 * Fires while rendering terms of agreement, before the fields.
1532
			 *
1533
			 * @since 1.0
1534
			 */
1535
			do_action( 'give_before_terms' );
1536
1537
			echo wpautop( stripslashes( $terms ) );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'wpautop'
Loading history...
1538
			/**
1539
			 * Fires while rendering terms of agreement, after the fields.
1540
			 *
1541
			 * @since 1.0
1542
			 */
1543
			do_action( 'give_after_terms' );
1544
			?>
1545
		</div>
1546
		<div id="give_show_terms">
1547
			<a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1548
			   aria-controls="give_terms"><?php esc_html_e( 'Show Terms', 'give' ); ?></a>
1549
			<a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1550
			   aria-controls="give_terms" style="display:none;"><?php esc_html_e( 'Hide Terms', 'give' ); ?></a>
1551
		</div>
1552
1553
		<input name="give_agree_to_terms" class="required" type="checkbox"
1554
			   id="give_agree_to_terms-<?php echo $form_id; ?>" value="1" required aria-required="true"/>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1555
		<label for="give_agree_to_terms-<?php echo $form_id; ?>"><?php echo $label; ?></label>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$label'
Loading history...
1556
1557
	</fieldset>
1558
	<?php
1559
}
1560
1561
add_action( 'give_donation_form_after_cc_form', 'give_terms_agreement', 8888, 1 );
1562
1563
/**
1564
 * Checkout Final Total.
1565
 *
1566
 * Shows the final donation total at the bottom of the checkout page.
1567
 *
1568
 * @since  1.0
1569
 *
1570
 * @param  int $form_id The form ID.
1571
 *
1572
 * @return void
1573
 */
1574
function give_checkout_final_total( $form_id ) {
1575
1576
	$total = isset( $_POST['give_total'] ) ?
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
1577
		apply_filters( 'give_donation_total', give_maybe_sanitize_amount( $_POST['give_total'] ) ) :
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
1578
		give_get_default_form_amount( $form_id );
1579
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
1580
1581
	//Only proceed if give_total available.
1582
	if ( empty( $total ) ) {
1583
		return;
1584
	}
1585
	?>
1586
	<p id="give-final-total-wrap" class="form-wrap ">
1587
		<span class="give-donation-total-label">
1588
			<?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...
1589
		</span>
1590
		<span class="give-final-total-amount"
1591
			  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...
1592
			<?php echo give_currency_filter( give_format_amount( $total, array( 'sanitize' => false ) ), 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...
1593
		</span>
1594
	</p>
1595
	<?php
1596
}
1597
1598
add_action( 'give_donation_form_before_submit', 'give_checkout_final_total', 999 );
1599
1600
/**
1601
 * Renders the Checkout Submit section.
1602
 *
1603
 * @since  1.0
1604
 *
1605
 * @param  int $form_id The form ID.
1606
 *
1607
 * @return void
1608
 */
1609
function give_checkout_submit( $form_id ) {
1610
	?>
1611
	<fieldset id="give_purchase_submit">
1612
		<?php
1613
		/**
1614
		 * Fire before donation form submit.
1615
		 *
1616
		 * @since 1.7
1617
		 */
1618
		do_action( 'give_donation_form_before_submit', $form_id );
1619
1620
		give_checkout_hidden_fields( $form_id );
1621
1622
		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...
1623
1624
		/**
1625
		 * Fire after donation form submit.
1626
		 *
1627
		 * @since 1.7
1628
		 */
1629
		do_action( 'give_donation_form_after_submit', $form_id );
1630
		?>
1631
	</fieldset>
1632
	<?php
1633
}
1634
1635
add_action( 'give_donation_form_after_cc_form', 'give_checkout_submit', 9999 );
1636
1637
/**
1638
 * Give Donation form submit button.
1639
 *
1640
 * @since  1.8.8
1641
 *
1642
 * @param  int $form_id The form ID.
1643
 *
1644
 * @return string
1645
 */
1646
function give_get_donation_form_submit_button( $form_id ) {
1647
1648
	$display_label_field = give_get_meta( $form_id, '_give_checkout_label', true );
1649
	$display_label       = ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) );
1650
	ob_start();
1651
	?>
1652
	<div class="give-submit-button-wrap give-clearfix">
1653
		<input type="submit" class="give-submit give-btn" id="give-purchase-button" name="give-purchase"
1654
			   value="<?php echo $display_label; ?>"/>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$display_label'
Loading history...
1655
		<span class="give-loading-animation"></span>
1656
	</div>
1657
	<?php
1658
	return apply_filters( 'give_donation_form_submit_button', ob_get_clean(), $form_id );
1659
}
1660
1661
/**
1662
 * Show Give Goals.
1663
 *
1664
 * @since  1.0
1665
 * @since  1.6   Add template for Give Goals Shortcode.
1666
 *               More info is on https://github.com/WordImpress/Give/issues/411
1667
 *
1668
 * @param  int   $form_id The form ID.
1669
 * @param  array $args    An array of form arguments.
1670
 *
1671
 * @return mixed
1672
 */
1673
function give_show_goal_progress( $form_id, $args ) {
1674
1675
	ob_start();
1676
	give_get_template( 'shortcode-goal', array( 'form_id' => $form_id, 'args' => $args ) );
1677
1678
	echo apply_filters( 'give_goal_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...
1679
1680
	return true;
1681
}
1682
1683
add_action( 'give_pre_form', 'give_show_goal_progress', 10, 2 );
1684
1685
1686
/**
1687
 * Get form content position.
1688
 *
1689
 * @since  1.8
1690
 *
1691
 * @param  $form_id
1692
 * @param  $args
1693
 *
1694
 * @return mixed|string
1695
 */
1696
function give_get_form_content_placement( $form_id, $args ) {
1697
	$show_content = '';
1698
1699
	if ( isset( $args['show_content'] ) && ! empty( $args['show_content'] ) ) {
1700
		// Content positions.
1701
		$content_placement = array(
1702
			'above' => 'give_pre_form',
1703
			'below' => 'give_post_form',
1704
		);
1705
1706
		// Check if content position already decoded.
1707
		if ( in_array( $args['show_content'], $content_placement ) ) {
1708
			return $args['show_content'];
1709
		}
1710
1711
		$show_content = ( 'none' !== $args['show_content'] ? $content_placement[ $args['show_content'] ] : '' );
1712
1713
	} elseif ( give_is_setting_enabled( give_get_meta( $form_id, '_give_display_content', true ) ) ) {
1714
		$show_content = give_get_meta( $form_id, '_give_content_placement', true );
1715
1716
	} elseif ( 'none' !== give_get_meta( $form_id, '_give_content_option', true ) ) {
1717
		// Backward compatibility for _give_content_option for v18.
1718
		$show_content = give_get_meta( $form_id, '_give_content_option', true );
1719
	}
1720
1721
	return $show_content;
1722
}
1723
1724
/**
1725
 * Adds Actions to Render Form Content.
1726
 *
1727
 * @since  1.0
1728
 *
1729
 * @param  int   $form_id The form ID.
1730
 * @param  array $args    An array of form arguments.
1731
 *
1732
 * @return void|bool
1733
 */
1734
function give_form_content( $form_id, $args ) {
1735
1736
	$show_content = give_get_form_content_placement( $form_id, $args );
1737
1738
	// Bailout.
1739
	if ( empty( $show_content ) ) {
1740
		return false;
1741
	}
1742
1743
	// Add action according to value.
1744
	add_action( $show_content, 'give_form_display_content', 10, 2 );
1745
}
1746
1747
add_action( 'give_pre_form_output', 'give_form_content', 10, 2 );
1748
1749
/**
1750
 * Renders Post Form Content.
1751
 *
1752
 * Displays content for Give forms; fired by action from give_form_content.
1753
 *
1754
 * @since  1.0
1755
 *
1756
 * @param  int   $form_id The form ID.
1757
 * @param  array $args    An array of form arguments.
1758
 *
1759
 * @return void
1760
 */
1761
function give_form_display_content( $form_id, $args ) {
1762
1763
	$content      = wpautop( give_get_meta( $form_id, '_give_form_content', true ) );
1764
	$show_content = give_get_form_content_placement( $form_id, $args );
1765
1766
	if ( give_is_setting_enabled( give_get_option( 'the_content_filter' ) ) ) {
1767
		$content = apply_filters( 'the_content', $content );
1768
	}
1769
1770
	$output = '<div id="give-form-content-' . $form_id . '" class="give-form-content-wrap ' . $show_content . '-content">' . $content . '</div>';
1771
1772
	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...
1773
1774
	//remove action to prevent content output on addition forms on page.
1775
	//@see: https://github.com/WordImpress/Give/issues/634.
1776
	remove_action( $show_content, 'give_form_display_content' );
1777
}
1778
1779
/**
1780
 * Renders the hidden Checkout fields.
1781
 *
1782
 * @since 1.0
1783
 *
1784
 * @param  int $form_id The form ID.
1785
 *
1786
 * @return void
1787
 */
1788
function give_checkout_hidden_fields( $form_id ) {
1789
1790
	/**
1791
	 * Fires while rendering hidden checkout fields, before the fields.
1792
	 *
1793
	 * @since 1.0
1794
	 *
1795
	 * @param int $form_id The form ID.
1796
	 */
1797
	do_action( 'give_hidden_fields_before', $form_id );
1798
1799
	if ( is_user_logged_in() ) { ?>
1800
		<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...
1801
	<?php } ?>
1802
	<input type="hidden" name="give_action" value="purchase"/>
1803
	<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...
1804
	<?php
1805
	/**
1806
	 * Fires while rendering hidden checkout fields, after the fields.
1807
	 *
1808
	 * @since 1.0
1809
	 *
1810
	 * @param int $form_id The form ID.
1811
	 */
1812
	do_action( 'give_hidden_fields_after', $form_id );
1813
1814
}
1815
1816
/**
1817
 * Filter Success Page Content.
1818
 *
1819
 * Applies filters to the success page content.
1820
 *
1821
 * @since 1.0
1822
 *
1823
 * @param  string $content Content before filters.
1824
 *
1825
 * @return string $content Filtered content.
1826
 */
1827
function give_filter_success_page_content( $content ) {
1828
1829
	$give_options = give_get_settings();
1830
1831
	if ( isset( $give_options['success_page'] ) && isset( $_GET['payment-confirmation'] ) && is_page( $give_options['success_page'] ) ) {
1832
		if ( has_filter( 'give_payment_confirm_' . $_GET['payment-confirmation'] ) ) {
1833
			$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...
1834
		}
1835
	}
1836
1837
	return $content;
1838
}
1839
1840
add_filter( 'the_content', 'give_filter_success_page_content' );
1841
1842
/**
1843
 * Test Mode Frontend Warning.
1844
 *
1845
 * Displays a notice on the frontend for donation forms.
1846
 *
1847
 * @since 1.1
1848
 */
1849
function give_test_mode_frontend_warning() {
1850
1851
	if ( give_is_test_mode() ) {
1852
		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>';
1853
	}
1854
}
1855
1856
add_action( 'give_pre_form', 'give_test_mode_frontend_warning', 10 );
1857
1858
/**
1859
 * Members-only Form.
1860
 *
1861
 * If "Disable Guest Donations" and "Display Register / Login" is set to none.
1862
 *
1863
 * @since  1.4.1
1864
 *
1865
 * @param  string $final_output
1866
 * @param  array  $args
1867
 *
1868
 * @return string
1869
 */
1870
function give_members_only_form( $final_output, $args ) {
1871
1872
	$form_id = isset( $args['form_id'] ) ? $args['form_id'] : 0;
1873
1874
	//Sanity Check: Must have form_id & not be logged in.
1875
	if ( empty( $form_id ) || is_user_logged_in() ) {
1876
		return $final_output;
1877
	}
1878
1879
	//Logged in only and Register / Login set to none.
1880
	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...
1881
1882
		$final_output = Give()->notices->print_frontend_notice( esc_html__( 'Please log in in order to complete your donation.', 'give' ), false );
1883
1884
		return apply_filters( 'give_members_only_output', $final_output, $form_id );
1885
1886
	}
1887
1888
	return $final_output;
1889
1890
}
1891
1892
add_filter( 'give_donate_form', 'give_members_only_form', 10, 2 );
1893
1894
1895
/**
1896
 * Add donation form hidden fields.
1897
 *
1898
 * @since 1.8.17
1899
 *
1900
 * @param int              $form_id
1901
 * @param array            $args
1902
 * @param Give_Donate_Form $form
1903
 */
1904
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...
1905
	?>
1906
	<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...
1907
	<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...
1908
	<input type="hidden" name="give-current-url"
1909
		   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...
1910
	<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...
1911
	<input type="hidden" name="give-form-minimum"
1912
		   value="<?php echo give_format_amount( give_get_form_minimum_price( $form_id ), array( 'sanitize' => false ) ); ?>"/>
0 ignored issues
show
Documentation introduced by
give_get_form_minimum_price($form_id) is of type false|double, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_format_amount'
Loading history...
1913
	<?php
1914
1915
	// Price ID hidden field for variable (multi-level) donation forms.
1916
	if ( give_has_variable_prices( $form_id ) ) {
1917
		// Get default selected price ID.
1918
		$prices   = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $form_id ), $form_id );
1919
		$price_id = 0;
1920
		//loop through prices.
1921
		foreach ( $prices as $price ) {
1922
			if ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) {
0 ignored issues
show
introduced by
Found "=== '". Use Yoda Condition checks, you must
Loading history...
1923
				$price_id = $price['_give_id']['level_id'];
1924
			};
1925
		}
1926
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
1927
1928
		echo sprintf(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'sprintf'
Loading history...
1929
			'<input type="hidden" name="give-price-id" value="%s"/>',
1930
			$price_id
1931
		);
1932
	}
1933
}
1934
1935
add_action( 'give_donation_form_top', '__give_form_add_donation_hidden_field', 0, 3 );
1936
1937
/**
1938
 * Add currency settings on donation form.
1939
 *
1940
 * @since 1.8.17
1941
 *
1942
 * @param array            $form_html_tags
1943
 * @param Give_Donate_Form $form
1944
 *
1945
 * @return array
1946
 */
1947
function __give_form_add_currency_settings( $form_html_tags, $form ) {
1948
	$form_currency     = give_get_currency( $form->ID );
1949
	$currency_settings = give_get_currency_formatting_settings( $form_currency );
1950
1951
	// Check if currency exist.
1952
	if ( empty( $currency_settings ) ) {
1953
		return $form_html_tags;
1954
	}
1955
1956
	$form_html_tags['data-currency_symbol'] = give_currency_symbol( $form_currency );
1957
	$form_html_tags['data-currency_code']   = $form_currency;
1958
1959
	if ( ! empty( $currency_settings ) ) {
1960
		foreach ( $currency_settings as $key => $value ) {
1961
			$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...
1962
		}
1963
	}
1964
1965
	return $form_html_tags;
1966
}
1967
1968
add_filter( 'give_form_html_tags', '__give_form_add_currency_settings', 0, 2 );
1969