Test Failed
Push — release/1.8.12 ( b58a2f...d255b1 )
by Ravinder
375:09 queued 372:17
created

template.php ➔ give_terms_agreement()   C

Complexity

Conditions 8
Paths 10

Size

Total Lines 65
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 0
Metric Value
cc 8
eloc 35
nc 10
nop 1
dl 0
loc 65
ccs 0
cts 0
cp 0
crap 72
rs 6.7651
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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

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

Commonly applied refactorings include:

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