Test Failed
Push — issues/2610 ( 7de36d...3c64c8 )
by Ravinder
17:57 queued 13:35
created

ajax-functions.php ➔ give_test_ajax_works()   D

Complexity

Conditions 16
Paths 214

Size

Total Lines 71
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 16
eloc 35
nc 214
nop 0
dl 0
loc 71
rs 4.8425
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
/**
3
 * AJAX Functions
4
 *
5
 * Process the front-end AJAX actions.
6
 *
7
 * @package     Give
8
 * @subpackage  Functions/AJAX
9
 * @copyright   Copyright (c) 2016, WordImpress
10
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
11
 * @since       1.0
12
 */
13
14
// Exit if accessed directly.
15
if ( ! defined( 'ABSPATH' ) ) {
16
	exit;
17
}
18
19
/**
20
 * Check if AJAX works as expected
21
 *
22
 * @since  1.0
23
 *
24
 * @return bool True if AJAX works, false otherwise
25
 */
26
function give_test_ajax_works() {
27
	// Handle ajax.
28
	if( wp_doing_ajax() ) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
29
		wp_die( 0, 200 );
30
	}
31
32
	// Check if the Airplane Mode plugin is installed.
33
	if ( class_exists( 'Airplane_Mode_Core' ) ) {
34
35
		$airplane = Airplane_Mode_Core::getInstance();
36
37
		if ( method_exists( $airplane, 'enabled' ) ) {
38
39
			if ( $airplane->enabled() ) {
40
				return true;
41
			}
42
		} else {
43
44
			if ( 'on' === $airplane->check_status() ) {
45
				return true;
46
			}
47
		}
48
	}
49
50
	add_filter( 'block_local_requests', '__return_false' );
51
52
	if ( Give_Cache::get( '_give_ajax_works', true ) ) {
53
		return true;
54
	}
55
56
	$params = array(
57
		'sslverify' => false,
58
		'timeout'   => 30,
59
		'body'      => array(
60
			'action' => 'give_test_ajax',
61
		),
62
	);
63
64
	$ajax = wp_remote_post( give_get_ajax_url(), $params );
65
66
	$works = true;
67
68
	if ( is_wp_error( $ajax ) ) {
69
70
		$works = false;
71
72
	} else {
73
74
		if ( empty( $ajax['response'] ) ) {
75
			$works = false;
76
		}
77
78
		if ( empty( $ajax['response']['code'] ) || 200 !== (int) $ajax['response']['code'] ) {
79
			$works = false;
80
		}
81
82
		if ( empty( $ajax['response']['message'] ) || 'OK' !== $ajax['response']['message'] ) {
83
			$works = false;
84
		}
85
86
		if ( ! isset( $ajax['body'] ) || 0 !== (int) $ajax['body'] ) {
87
			$works = false;
88
		}
89
	}
90
91
	if ( $works ) {
92
		Give_Cache::set( '_give_ajax_works', '1', DAY_IN_SECONDS, true );
93
	}
94
95
	return $works;
96
}
97
98
add_action( 'wp_ajax_nopriv_give_test_ajax', 'give_test_ajax_works' );
99
100
/**
101
 * Get AJAX URL
102
 *
103
 * @since  1.0
104
 *
105
 * @param array $query
106
 *
107
 * @return string
108
 */
109
function give_get_ajax_url( $query = array() ) {
110
	$scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';
111
112
	$current_url = give_get_current_page_url();
113
	$ajax_url    = admin_url( 'admin-ajax.php', $scheme );
114
115
	if ( preg_match( '/^https/', $current_url ) && ! preg_match( '/^https/', $ajax_url ) ) {
116
		$ajax_url = preg_replace( '/^http/', 'https', $ajax_url );
117
	}
118
119
	if( ! empty( $query ) ) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
120
		$ajax_url = add_query_arg( $query, $ajax_url );
121
	}
122
123
	return apply_filters( 'give_ajax_url', $ajax_url );
124
}
125
126
/**
127
 * Loads Checkout Login Fields via AJAX
128
 *
129
 * @since  1.0
130
 *
131
 * @return void
132
 */
133
function give_load_checkout_login_fields() {
134
	/**
135
	 * Fire when render login fields via ajax.
136
	 *
137
	 * @since 1.7
138
	 */
139
	do_action( 'give_donation_form_login_fields' );
140
141
	give_die();
142
}
143
144
add_action( 'wp_ajax_nopriv_give_checkout_login', 'give_load_checkout_login_fields' );
145
146
/**
147
 * Load Checkout Fields
148
 *
149
 * @since  1.3.6
150
 *
151
 * @return void
152
 */
153
function give_load_checkout_fields() {
154
	$form_id = isset( $_POST['form_id'] ) ? $_POST['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...
155
156
	ob_start();
157
158
	/**
159
	 * Fire to render registration/login form.
160
	 *
161
	 * @since 1.7
162
	 */
163
	do_action( 'give_donation_form_register_login_fields', $form_id );
164
165
	$fields = ob_get_clean();
166
167
	wp_send_json( array(
168
		'fields' => wp_json_encode( $fields ),
169
		'submit' => wp_json_encode( give_get_donation_form_submit_button( $form_id ) ),
170
	) );
171
}
172
173
add_action( 'wp_ajax_nopriv_give_cancel_login', 'give_load_checkout_fields' );
174
add_action( 'wp_ajax_nopriv_give_checkout_register', 'give_load_checkout_fields' );
175
176
/**
177
 * Get Form Title via AJAX (used only in WordPress Admin)
178
 *
179
 * @since  1.0
180
 *
181
 * @return void
182
 */
183
function give_ajax_get_form_title() {
184
	if ( isset( $_POST['form_id'] ) ) {
185
		$title = get_the_title( $_POST['form_id'] );
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
186
		if ( $title ) {
187
			echo $title;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$title'
Loading history...
188
		} else {
189
			echo 'fail';
190
		}
191
	}
192
	give_die();
193
}
194
195
add_action( 'wp_ajax_give_get_form_title', 'give_ajax_get_form_title' );
196
add_action( 'wp_ajax_nopriv_give_get_form_title', 'give_ajax_get_form_title' );
197
198
/**
199
 * Retrieve a states drop down
200
 *
201
 * @since  1.0
202
 *
203
 * @return void
204
 */
205
function give_ajax_get_states_field() {
206
	$states_found   = false;
207
	$show_field     = true;
208
	$states_require = true;
209
	// Get the Country code from the $_POST.
210
	$country = sanitize_text_field( $_POST['country'] );
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-validated input variable: $_POST
Loading history...
211
212
	// Get the field name from the $_POST.
213
	$field_name = sanitize_text_field( $_POST['field_name'] );
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-validated input variable: $_POST
Loading history...
214
215
	$label        = __( 'State', 'give' );
216
	$states_label = give_get_states_label();
217
218
	$default_state = '';
219
	if ( $country === give_get_country() ) {
220
		$default_state = give_get_state();
221
	}
222
223
	// Check if $country code exists in the array key for states label.
224
	if ( array_key_exists( $country, $states_label ) ) {
225
		$label = $states_label[ $country ];
226
	}
227
228
	if ( empty( $country ) ) {
229
		$country = give_get_country();
230
	}
231
232
	$states = give_get_states( $country );
233
	if ( ! empty( $states ) ) {
234
		$args         = array(
235
			'name'             => $field_name,
236
			'id'               => $field_name,
237
			'class'            => $field_name . '  give-select',
238
			'options'          => $states,
239
			'show_option_all'  => false,
240
			'show_option_none' => false,
241
			'placeholder'      => $label,
242
			'selected'         => $default_state,
243
		);
244
		$data         = Give()->html->select( $args );
245
		$states_found = true;
246
	} else {
247
		$data = 'nostates';
248
249
		// Get the country list that does not have any states init.
250
		$no_states_country = give_no_states_country_list();
251
252
		// Check if $country code exists in the array key.
253
		if ( array_key_exists( $country, $no_states_country ) ) {
254
			$show_field = false;
255
		}
256
257
		// Get the country list that does not require states.
258
		$states_not_required_country_list = give_states_not_required_country_list();
259
260
		// Check if $country code exists in the array key.
261
		if ( array_key_exists( $country, $states_not_required_country_list ) ) {
262
			$states_require = false;
263
		}
264
	}
265
	$response = array(
266
		'success'        => true,
267
		'states_found'   => $states_found,
268
		'states_label'   => $label,
269
		'show_field'     => $show_field,
270
		'states_require' => $states_require,
271
		'data'           => $data,
272
		'default_state'  => $default_state,
273
	);
274
	wp_send_json( $response );
275
}
276
277
add_action( 'wp_ajax_give_get_states', 'give_ajax_get_states_field' );
278
add_action( 'wp_ajax_nopriv_give_get_states', 'give_ajax_get_states_field' );
279
280
/**
281
 * Retrieve donation forms via AJAX for chosen dropdown search field.
282
 *
283
 * @since  1.0
284
 *
285
 * @return void
286
 */
287
function give_ajax_form_search() {
288
	global $wpdb;
289
290
	$search   = esc_sql( sanitize_text_field( $_GET['s'] ) );
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-validated input variable: $_GET
Loading history...
291
	$excludes = ( isset( $_GET['current_id'] ) ? (array) $_GET['current_id'] : array() );
0 ignored issues
show
Unused Code introduced by
$excludes 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...
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...
292
293
	$results = array();
294
	if ( current_user_can( 'edit_give_forms' ) ) {
295
		$items = $wpdb->get_results( "SELECT ID,post_title FROM $wpdb->posts WHERE `post_type` = 'give_forms' AND `post_title` LIKE '%$search%' LIMIT 50" );
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
296
	} else {
297
		$items = $wpdb->get_results( "SELECT ID,post_title FROM $wpdb->posts WHERE `post_type` = 'give_forms' AND `post_status` = 'publish' AND `post_title` LIKE '%$search%' LIMIT 50" );
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
298
	}
299
300
	if ( $items ) {
301
302
		foreach ( $items as $item ) {
303
304
			$results[] = array(
305
				'id'   => $item->ID,
306
				'name' => $item->post_title,
307
			);
308
		}
309
	} else {
310
311
		$items[] = array(
312
			'id'   => 0,
313
			'name' => __( 'No forms found.', 'give' ),
314
		);
315
316
	}
317
318
	echo json_encode( $results );
319
320
	give_die();
321
}
322
323
add_action( 'wp_ajax_give_form_search', 'give_ajax_form_search' );
324
add_action( 'wp_ajax_nopriv_give_form_search', 'give_ajax_form_search' );
325
326
/**
327
 * Search the donors database via Ajax
328
 *
329
 * @since  1.0
330
 *
331
 * @return void
332
 */
333
function give_ajax_donor_search() {
334
	global $wpdb;
335
336
	$search  = esc_sql( sanitize_text_field( $_GET['s'] ) );
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-validated input variable: $_GET
Loading history...
337
	$results = array();
338
	if ( ! current_user_can( 'view_give_reports' ) ) {
339
		$donors = array();
340
	} else {
341
		$donors = $wpdb->get_results( "SELECT id,name,email FROM $wpdb->donors WHERE `name` LIKE '%$search%' OR `email` LIKE '%$search%' LIMIT 50" );
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
342
	}
343
344
	if ( $donors ) {
345
346
		foreach ( $donors as $donor ) {
347
348
			$results[] = array(
349
				'id'   => $donor->id,
350
				'name' => $donor->name . ' (' . $donor->email . ')',
351
			);
352
		}
353
	} else {
354
355
		$donors[] = array(
356
			'id'   => 0,
357
			'name' => __( 'No donors found.', 'give' ),
358
		);
359
360
	}
361
362
	echo json_encode( $results );
363
364
	give_die();
365
}
366
367
add_action( 'wp_ajax_give_donor_search', 'give_ajax_donor_search' );
368
369
370
/**
371
 * Searches for users via ajax and returns a list of results
372
 *
373
 * @since  1.0
374
 *
375
 * @return void
376
 */
377
function give_ajax_search_users() {
378
379
	if ( current_user_can( 'manage_give_settings' ) ) {
380
381
		$search = esc_sql( sanitize_text_field( $_GET['s'] ) );
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-validated input variable: $_GET
Loading history...
382
383
		$get_users_args = array(
384
			'number' => 9999,
385
			'search' => $search . '*',
386
		);
387
388
		$get_users_args = apply_filters( 'give_search_users_args', $get_users_args );
389
390
		$found_users = apply_filters( 'give_ajax_found_users', get_users( $get_users_args ), $search );
391
		$results     = array();
392
393
		if ( $found_users ) {
394
395
			foreach ( $found_users as $user ) {
396
397
				$results[] = array(
398
					'id'   => $user->ID,
399
					'name' => esc_html( $user->user_login . ' (' . $user->user_email . ')' ),
400
				);
401
			}
402
		} else {
403
404
			$results[] = array(
405
				'id'   => 0,
406
				'name' => __( 'No users found.', 'give' ),
407
			);
408
409
		}
410
411
		echo json_encode( $results );
412
413
	}// End if().
414
415
	give_die();
416
417
}
418
419
add_action( 'wp_ajax_give_user_search', 'give_ajax_search_users' );
420
421
422
/**
423
 * Check for Price Variations (Multi-level donation forms)
424
 *
425
 * @since  1.5
426
 *
427
 * @return void
428
 */
429
function give_check_for_form_price_variations() {
430
431
	if ( ! current_user_can( 'edit_give_forms', get_current_user_id() ) ) {
432
		die( '-1' );
433
	}
434
435
	$form_id = intval( $_POST['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-validated input variable: $_POST
Loading history...
436
	$form    = get_post( $form_id );
437
438
	if ( 'give_forms' != $form->post_type ) {
439
		die( '-2' );
440
	}
441
442
	if ( give_has_variable_prices( $form_id ) ) {
443
		$variable_prices = give_get_variable_prices( $form_id );
444
445
		if ( $variable_prices ) {
446
			$ajax_response = '<select class="give_price_options_select give-select give-select" name="give_price_option">';
447
448
			if ( isset( $_POST['all_prices'] ) ) {
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
449
				$ajax_response .= '<option value="all">' . esc_html__( 'All Levels', 'give' ) . '</option>';
450
			}
451
452
			foreach ( $variable_prices as $key => $price ) {
453
454
				$level_text = ! empty( $price['_give_text'] ) ? esc_html( $price['_give_text'] ) : give_currency_filter( give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ) );
455
456
				$ajax_response .= '<option value="' . esc_attr( $price['_give_id']['level_id'] ) . '">' . $level_text . '</option>';
457
			}
458
			$ajax_response .= '</select>';
459
			echo $ajax_response;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$ajax_response'
Loading history...
460
		}
461
	}
462
463
	give_die();
464
}
465
466
add_action( 'wp_ajax_give_check_for_form_price_variations', 'give_check_for_form_price_variations' );
467
468
469
/**
470
 * Check for Variation Prices HTML  (Multi-level donation forms)
471
 *
472
 * @since  1.6
473
 *
474
 * @return void
475
 */
476
function give_check_for_form_price_variations_html() {
477
	if ( ! current_user_can( 'edit_give_payments', get_current_user_id() ) ) {
478
		wp_die();
479
	}
480
481
	$form_id    = ! empty( $_POST['form_id'] ) ? intval( $_POST['form_id'] ) : false;
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
482
	$payment_id = ! empty( $_POST['payment_id'] ) ? intval( $_POST['payment_id'] ) : false;
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
483
	if ( empty( $form_id ) || empty( $payment_id ) ) {
484
		wp_die();
485
	}
486
487
	$form = get_post( $form_id );
488
	if ( ! empty( $form->post_type ) && 'give_forms' != $form->post_type ) {
489
		wp_die();
490
	}
491
492
	if ( ! give_has_variable_prices( $form_id ) || ! $form_id ) {
0 ignored issues
show
Security Bug introduced by
It seems like $form_id defined by !empty($_POST['form_id']...OST['form_id']) : false on line 481 can also be of type false; however, give_has_variable_prices() does only seem to accept integer, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
Bug Best Practice introduced by
The expression $form_id of type integer|false is loosely compared to false; this is ambiguous if the integer can be zero. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
493
		esc_html_e( 'n/a', 'give' );
494
	} else {
495
		$prices_atts = array();
496 View Code Duplication
		if ( $variable_prices = give_get_variable_prices( $form_id ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
497
			foreach ( $variable_prices as $variable_price ) {
498
				$prices_atts[ $variable_price['_give_id']['level_id'] ] = give_format_amount( $variable_price['_give_amount'], array( 'sanitize' => false ) );
499
			}
500
		}
501
502
		// Variable price dropdown options.
503
		$variable_price_dropdown_option = array(
504
			'id'               => $form_id,
505
			'name'             => 'give-variable-price',
506
			'chosen'           => true,
507
			'show_option_all'  => '',
508
			'show_option_none' => '',
509
			'select_atts'      => 'data-prices=' . esc_attr( json_encode( $prices_atts ) ),
510
		);
511
512
		if ( $payment_id ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $payment_id of type integer|false is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
513
			// Payment object.
514
			$payment = new Give_Payment( $payment_id );
515
516
			// Payment meta.
517
			$payment_meta                               = $payment->get_meta();
518
			$variable_price_dropdown_option['selected'] = $payment_meta['price_id'];
519
		}
520
521
		// Render variable prices select tag html.
522
		give_get_form_variable_price_dropdown( $variable_price_dropdown_option, true );
523
	}
524
525
	give_die();
526
}
527
528
add_action( 'wp_ajax_give_check_for_form_price_variations_html', 'give_check_for_form_price_variations_html' );
529
530
/**
531
 * Send Confirmation Email For Complete Donation History Access.
532
 *
533
 * @since 1.8.17
534
 *
535
 * @return bool
536
 */
537
function give_confirm_email_for_donation_access() {
538
539
	// Verify Security using Nonce.
540
	if ( ! check_ajax_referer( 'give_ajax_nonce', 'nonce' ) ) {
541
		return false;
542
	}
543
544
	// Bail Out, if email is empty.
545
	if ( empty( $_POST['email'] ) ) {
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
546
		return false;
547
	}
548
549
	$donor = Give()->donors->get_donor_by( 'email', give_clean( $_POST['email'] ) );
0 ignored issues
show
Documentation introduced by
give_clean($_POST['email']) is of type string|array, but the function expects a integer.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
introduced by
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...
550
	if ( Give()->email_access->can_send_email( $donor->id ) ) {
551
		$return     = array();
552
		$email_sent = Give()->email_access->send_email( $donor->id, $donor->email );
553
554
		if ( ! $email_sent ) {
555
			$return['status']  = 'error';
556
			$return['message'] = Give()->notices->print_frontend_notice(
557
				__( 'Unable to send email. Please try again.', 'give' ),
558
				false,
559
				'error'
560
			);
561
		}
562
563
		$return['status']  = 'success';
564
		$return['message'] = Give()->notices->print_frontend_notice(
565
			__( 'Please check your email and click on the link to access your complete donation history.', 'give' ),
566
			false,
567
			'success'
568
		);
569
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
570
571
	} else {
572
		$value             = Give()->email_access->verify_throttle / 60;
573
		$return['status']  = 'error';
574
		$return['message'] = Give()->notices->print_frontend_notice(
575
			sprintf(
576
				__( 'Too many access email requests detected. Please wait %s before requesting a new donation history access link.', 'give' ),
577
				sprintf( _n( '%s minute', '%s minutes', $value, 'give' ), $value )
578
			),
579
			false,
580
			'error'
581
		);
582
	}
583
584
	echo json_encode( $return );
585
	give_die();
586
}
587
588
add_action( 'wp_ajax_nopriv_give_confirm_email_for_donations_access', 'give_confirm_email_for_donation_access' );