Test Failed
Push — release/2.0 ( f7bd0b...627b34 )
by Ravinder
04:42
created

ajax-functions.php ➔ give_test_ajax_works()   F

Complexity

Conditions 17
Paths 321

Size

Total Lines 82
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 17
eloc 40
nc 321
nop 0
dl 0
loc 82
rs 3.7589
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
28
	// Handle ajax query.
29
	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...
30
31
		if( wp_verify_nonce( 'give_test_ajax', 'nonce' ) ) {
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...
32
			wp_send_json_success();
33
		}
34
35
		wp_die( '0', 400 );
36
	}
37
38
	// Check if the Airplane Mode plugin is installed.
39
	if ( class_exists( 'Airplane_Mode_Core' ) ) {
40
41
		$airplane = Airplane_Mode_Core::getInstance();
42
43
		if ( method_exists( $airplane, 'enabled' ) ) {
44
45
			if ( $airplane->enabled() ) {
46
				return true;
47
			}
48
		} else {
49
50
			if ( 'on' === $airplane->check_status() ) {
51
				return true;
52
			}
53
		}
54
	}
55
56
	add_filter( 'block_local_requests', '__return_false' );
57
58
	if ( Give_Cache::get( '_give_ajax_works', true ) ) {
59
		return true;
60
	}
61
62
	$params = array(
63
		'sslverify' => false,
64
		'timeout'   => 30
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
65
	);
66
67
	$ajax = wp_remote_post(
68
		give_get_ajax_url(
69
			array(
70
				'action' => 'give_test_ajax',
71
				'nonce'  => wp_create_nonce( 'give_test_ajax' ),
72
			)
73
		),
74
		$params
75
	);
76
77
	$works = true;
78
79
	if ( is_wp_error( $ajax ) ) {
80
81
		$works = false;
82
83
	} else {
84
85
		if ( empty( $ajax['response'] ) ) {
86
			$works = false;
87
		}
88
89
		if ( empty( $ajax['response']['code'] ) || 200 !== (int) $ajax['response']['code'] ) {
90
			$works = false;
91
		}
92
93
		if ( empty( $ajax['response']['message'] ) || 'OK' !== $ajax['response']['message'] ) {
94
			$works = false;
95
		}
96
97
		if ( ! isset( $ajax['body'] ) || 0 !== (int) $ajax['body'] ) {
98
			$works = false;
99
		}
100
	}
101
102
	if ( $works ) {
103
		Give_Cache::set( '_give_ajax_works', '1', DAY_IN_SECONDS, true );
104
	}
105
106
	return $works;
107
}
108
109
add_action( 'wp_ajax_nopriv_give_test_ajax', 'give_test_ajax_works' );
110
111
/**
112
 * Get AJAX URL
113
 *
114
 * @since  1.0
115
 *
116
 * @param array $query
117
 *
118
 * @return string
119
 */
120
function give_get_ajax_url( $query = array() ) {
121
	$scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';
122
123
	$current_url = give_get_current_page_url();
124
	$ajax_url    = admin_url( 'admin-ajax.php', $scheme );
125
126
	if ( preg_match( '/^https/', $current_url ) && ! preg_match( '/^https/', $ajax_url ) ) {
127
		$ajax_url = preg_replace( '/^http/', 'https', $ajax_url );
128
	}
129
130
	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...
131
		$ajax_url = add_query_arg( $query, $ajax_url );
132
	}
133
134
	return apply_filters( 'give_ajax_url', $ajax_url );
135
}
136
137
/**
138
 * Loads Checkout Login Fields via AJAX
139
 *
140
 * @since  1.0
141
 *
142
 * @return void
143
 */
144
function give_load_checkout_login_fields() {
145
	/**
146
	 * Fire when render login fields via ajax.
147
	 *
148
	 * @since 1.7
149
	 */
150
	do_action( 'give_donation_form_login_fields' );
151
152
	give_die();
153
}
154
155
add_action( 'wp_ajax_nopriv_give_checkout_login', 'give_load_checkout_login_fields' );
156
157
/**
158
 * Load Checkout Fields
159
 *
160
 * @since  1.3.6
161
 *
162
 * @return void
163
 */
164
function give_load_checkout_fields() {
165
	$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...
166
167
	ob_start();
168
169
	/**
170
	 * Fire to render registration/login form.
171
	 *
172
	 * @since 1.7
173
	 */
174
	do_action( 'give_donation_form_register_login_fields', $form_id );
175
176
	$fields = ob_get_clean();
177
178
	wp_send_json( array(
179
		'fields' => wp_json_encode( $fields ),
180
		'submit' => wp_json_encode( give_get_donation_form_submit_button( $form_id ) ),
181
	) );
182
}
183
184
add_action( 'wp_ajax_nopriv_give_cancel_login', 'give_load_checkout_fields' );
185
add_action( 'wp_ajax_nopriv_give_checkout_register', 'give_load_checkout_fields' );
186
187
/**
188
 * Get Form Title via AJAX (used only in WordPress Admin)
189
 *
190
 * @since  1.0
191
 *
192
 * @return void
193
 */
194
function give_ajax_get_form_title() {
195
	if ( isset( $_POST['form_id'] ) ) {
196
		$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...
197
		if ( $title ) {
198
			echo $title;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$title'
Loading history...
199
		} else {
200
			echo 'fail';
201
		}
202
	}
203
	give_die();
204
}
205
206
add_action( 'wp_ajax_give_get_form_title', 'give_ajax_get_form_title' );
207
add_action( 'wp_ajax_nopriv_give_get_form_title', 'give_ajax_get_form_title' );
208
209
/**
210
 * Retrieve a states drop down
211
 *
212
 * @since  1.0
213
 *
214
 * @return void
215
 */
216
function give_ajax_get_states_field() {
217
	$states_found   = false;
218
	$show_field     = true;
219
	$states_require = true;
220
	// Get the Country code from the $_POST.
221
	$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...
222
223
	// Get the field name from the $_POST.
224
	$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...
225
226
	$label        = __( 'State', 'give' );
227
	$states_label = give_get_states_label();
228
229
	$default_state = '';
230
	if ( $country === give_get_country() ) {
231
		$default_state = give_get_state();
232
	}
233
234
	// Check if $country code exists in the array key for states label.
235
	if ( array_key_exists( $country, $states_label ) ) {
236
		$label = $states_label[ $country ];
237
	}
238
239
	if ( empty( $country ) ) {
240
		$country = give_get_country();
241
	}
242
243
	$states = give_get_states( $country );
244
	if ( ! empty( $states ) ) {
245
		$args         = array(
246
			'name'             => $field_name,
247
			'id'               => $field_name,
248
			'class'            => $field_name . '  give-select',
249
			'options'          => $states,
250
			'show_option_all'  => false,
251
			'show_option_none' => false,
252
			'placeholder'      => $label,
253
			'selected'         => $default_state,
254
		);
255
		$data         = Give()->html->select( $args );
256
		$states_found = true;
257
	} else {
258
		$data = 'nostates';
259
260
		// Get the country list that does not have any states init.
261
		$no_states_country = give_no_states_country_list();
262
263
		// Check if $country code exists in the array key.
264
		if ( array_key_exists( $country, $no_states_country ) ) {
265
			$show_field = false;
266
		}
267
268
		// Get the country list that does not require states.
269
		$states_not_required_country_list = give_states_not_required_country_list();
270
271
		// Check if $country code exists in the array key.
272
		if ( array_key_exists( $country, $states_not_required_country_list ) ) {
273
			$states_require = false;
274
		}
275
	}
276
	$response = array(
277
		'success'        => true,
278
		'states_found'   => $states_found,
279
		'states_label'   => $label,
280
		'show_field'     => $show_field,
281
		'states_require' => $states_require,
282
		'data'           => $data,
283
		'default_state'  => $default_state,
284
	);
285
	wp_send_json( $response );
286
}
287
288
add_action( 'wp_ajax_give_get_states', 'give_ajax_get_states_field' );
289
add_action( 'wp_ajax_nopriv_give_get_states', 'give_ajax_get_states_field' );
290
291
/**
292
 * Retrieve donation forms via AJAX for chosen dropdown search field.
293
 *
294
 * @since  1.0
295
 *
296
 * @return void
297
 */
298
function give_ajax_form_search() {
299
	global $wpdb;
300
301
	$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...
302
	$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...
303
304
	$results = array();
305
	if ( current_user_can( 'edit_give_forms' ) ) {
306
		$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...
307
	} else {
308
		$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...
309
	}
310
311
	if ( $items ) {
312
313
		foreach ( $items as $item ) {
314
315
			$results[] = array(
316
				'id'   => $item->ID,
317
				'name' => $item->post_title,
318
			);
319
		}
320
	} else {
321
322
		$items[] = array(
323
			'id'   => 0,
324
			'name' => __( 'No forms found.', 'give' ),
325
		);
326
327
	}
328
329
	echo json_encode( $results );
330
331
	give_die();
332
}
333
334
add_action( 'wp_ajax_give_form_search', 'give_ajax_form_search' );
335
add_action( 'wp_ajax_nopriv_give_form_search', 'give_ajax_form_search' );
336
337
/**
338
 * Search the donors database via Ajax
339
 *
340
 * @since  1.0
341
 *
342
 * @return void
343
 */
344
function give_ajax_donor_search() {
345
	global $wpdb;
346
347
	$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...
348
	$results = array();
349
	if ( ! current_user_can( 'view_give_reports' ) ) {
350
		$donors = array();
351
	} else {
352
		$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...
353
	}
354
355
	if ( $donors ) {
356
357
		foreach ( $donors as $donor ) {
358
359
			$results[] = array(
360
				'id'   => $donor->id,
361
				'name' => $donor->name . ' (' . $donor->email . ')',
362
			);
363
		}
364
	} else {
365
366
		$donors[] = array(
367
			'id'   => 0,
368
			'name' => __( 'No donors found.', 'give' ),
369
		);
370
371
	}
372
373
	echo json_encode( $results );
374
375
	give_die();
376
}
377
378
add_action( 'wp_ajax_give_donor_search', 'give_ajax_donor_search' );
379
380
381
/**
382
 * Searches for users via ajax and returns a list of results
383
 *
384
 * @since  1.0
385
 *
386
 * @return void
387
 */
388
function give_ajax_search_users() {
389
390
	if ( current_user_can( 'manage_give_settings' ) ) {
391
392
		$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...
393
394
		$get_users_args = array(
395
			'number' => 9999,
396
			'search' => $search . '*',
397
		);
398
399
		$get_users_args = apply_filters( 'give_search_users_args', $get_users_args );
400
401
		$found_users = apply_filters( 'give_ajax_found_users', get_users( $get_users_args ), $search );
402
		$results     = array();
403
404
		if ( $found_users ) {
405
406
			foreach ( $found_users as $user ) {
407
408
				$results[] = array(
409
					'id'   => $user->ID,
410
					'name' => esc_html( $user->user_login . ' (' . $user->user_email . ')' ),
411
				);
412
			}
413
		} else {
414
415
			$results[] = array(
416
				'id'   => 0,
417
				'name' => __( 'No users found.', 'give' ),
418
			);
419
420
		}
421
422
		echo json_encode( $results );
423
424
	}// End if().
425
426
	give_die();
427
428
}
429
430
add_action( 'wp_ajax_give_user_search', 'give_ajax_search_users' );
431
432
433
/**
434
 * Check for Price Variations (Multi-level donation forms)
435
 *
436
 * @since  1.5
437
 *
438
 * @return void
439
 */
440
function give_check_for_form_price_variations() {
441
442
	if ( ! current_user_can( 'edit_give_forms', get_current_user_id() ) ) {
443
		die( '-1' );
444
	}
445
446
	$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...
447
	$form    = get_post( $form_id );
448
449
	if ( 'give_forms' != $form->post_type ) {
450
		die( '-2' );
451
	}
452
453
	if ( give_has_variable_prices( $form_id ) ) {
454
		$variable_prices = give_get_variable_prices( $form_id );
455
456
		if ( $variable_prices ) {
457
			$ajax_response = '<select class="give_price_options_select give-select give-select" name="give_price_option">';
458
459
			if ( isset( $_POST['all_prices'] ) ) {
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
460
				$ajax_response .= '<option value="all">' . esc_html__( 'All Levels', 'give' ) . '</option>';
461
			}
462
463
			foreach ( $variable_prices as $key => $price ) {
464
465
				$level_text = ! empty( $price['_give_text'] ) ? esc_html( $price['_give_text'] ) : give_currency_filter( give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ) );
466
467
				$ajax_response .= '<option value="' . esc_attr( $price['_give_id']['level_id'] ) . '">' . $level_text . '</option>';
468
			}
469
			$ajax_response .= '</select>';
470
			echo $ajax_response;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$ajax_response'
Loading history...
471
		}
472
	}
473
474
	give_die();
475
}
476
477
add_action( 'wp_ajax_give_check_for_form_price_variations', 'give_check_for_form_price_variations' );
478
479
480
/**
481
 * Check for Variation Prices HTML  (Multi-level donation forms)
482
 *
483
 * @since  1.6
484
 *
485
 * @return void
486
 */
487
function give_check_for_form_price_variations_html() {
488
	if ( ! current_user_can( 'edit_give_payments', get_current_user_id() ) ) {
489
		wp_die();
490
	}
491
492
	$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...
493
	$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...
494
	if ( empty( $form_id ) || empty( $payment_id ) ) {
495
		wp_die();
496
	}
497
498
	$form = get_post( $form_id );
499
	if ( ! empty( $form->post_type ) && 'give_forms' != $form->post_type ) {
500
		wp_die();
501
	}
502
503
	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 492 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...
504
		esc_html_e( 'n/a', 'give' );
505
	} else {
506
		$prices_atts = array();
507 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...
508
			foreach ( $variable_prices as $variable_price ) {
509
				$prices_atts[ $variable_price['_give_id']['level_id'] ] = give_format_amount( $variable_price['_give_amount'], array( 'sanitize' => false ) );
510
			}
511
		}
512
513
		// Variable price dropdown options.
514
		$variable_price_dropdown_option = array(
515
			'id'               => $form_id,
516
			'name'             => 'give-variable-price',
517
			'chosen'           => true,
518
			'show_option_all'  => '',
519
			'show_option_none' => '',
520
			'select_atts'      => 'data-prices=' . esc_attr( json_encode( $prices_atts ) ),
521
		);
522
523
		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...
524
			// Payment object.
525
			$payment = new Give_Payment( $payment_id );
526
527
			// Payment meta.
528
			$payment_meta                               = $payment->get_meta();
529
			$variable_price_dropdown_option['selected'] = $payment_meta['price_id'];
530
		}
531
532
		// Render variable prices select tag html.
533
		give_get_form_variable_price_dropdown( $variable_price_dropdown_option, true );
534
	}
535
536
	give_die();
537
}
538
539
add_action( 'wp_ajax_give_check_for_form_price_variations_html', 'give_check_for_form_price_variations_html' );
540
541
/**
542
 * Send Confirmation Email For Complete Donation History Access.
543
 *
544
 * @since 1.8.17
545
 *
546
 * @return bool
547
 */
548
function give_confirm_email_for_donation_access() {
549
550
	// Verify Security using Nonce.
551
	if ( ! check_ajax_referer( 'give_ajax_nonce', 'nonce' ) ) {
552
		return false;
553
	}
554
555
	// Bail Out, if email is empty.
556
	if ( empty( $_POST['email'] ) ) {
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
557
		return false;
558
	}
559
560
	$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...
561
	if ( Give()->email_access->can_send_email( $donor->id ) ) {
562
		$return     = array();
563
		$email_sent = Give()->email_access->send_email( $donor->id, $donor->email );
564
565
		if ( ! $email_sent ) {
566
			$return['status']  = 'error';
567
			$return['message'] = Give()->notices->print_frontend_notice(
568
				__( 'Unable to send email. Please try again.', 'give' ),
569
				false,
570
				'error'
571
			);
572
		}
573
574
		$return['status']  = 'success';
575
		$return['message'] = Give()->notices->print_frontend_notice(
576
			__( 'Please check your email and click on the link to access your complete donation history.', 'give' ),
577
			false,
578
			'success'
579
		);
580
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
581
582
	} else {
583
		$value             = Give()->email_access->verify_throttle / 60;
584
		$return['status']  = 'error';
585
		$return['message'] = Give()->notices->print_frontend_notice(
586
			sprintf(
587
				__( 'Too many access email requests detected. Please wait %s before requesting a new donation history access link.', 'give' ),
588
				sprintf( _n( '%s minute', '%s minutes', $value, 'give' ), $value )
589
			),
590
			false,
591
			'error'
592
		);
593
	}
594
595
	echo json_encode( $return );
596
	give_die();
597
}
598
599
add_action( 'wp_ajax_nopriv_give_confirm_email_for_donations_access', 'give_confirm_email_for_donation_access' );