PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.5.7
GiveWP – Donation Plugin and Fundraising Platform v2.5.7
4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / admin / donors / donor-actions.php
give / includes / admin / donors Last commit date
class-donor-table.php 7 years ago donor-actions.php 7 years ago donor-functions.php 6 years ago donors.php 6 years ago
donor-actions.php
639 lines
1 <?php
2 /**
3 * Donors
4 *
5 * @package Give
6 * @subpackage Admin/Donors
7 * @copyright Copyright (c) 2016, GiveWP
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 * Processes a donor edit.
19 *
20 * @param array $args The $_POST array being passed.
21 *
22 * @since 1.0
23 *
24 * @return array|bool $output Response messages
25 */
26 function give_edit_donor( $args ) {
27
28 $donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' );
29
30 if ( ! is_admin() || ! current_user_can( $donor_edit_role ) ) {
31 wp_die( esc_html__( 'You do not have permission to edit this donor.', 'give' ), esc_html__( 'Error', 'give' ), array(
32 'response' => 403,
33 ) );
34 }
35
36 if ( empty( $args ) ) {
37 return false;
38 }
39
40 // Sanitize Data.
41 $args = give_clean( $args );
42
43 $args = wp_parse_args(
44 $args,
45 array(
46 'give_anonymous_donor' => 0
47 )
48 );
49
50 // Verify Nonce.
51 if ( ! wp_verify_nonce( $args['_wpnonce'], 'edit-donor' ) ) {
52 wp_die( esc_html__( 'Cheatin&#8217; uh?', 'give' ), esc_html__( 'Error', 'give' ), array(
53 'response' => 400,
54 ) );
55 }
56
57 $donor_info = $args['donor_info'];
58 $donor_id = intval( $donor_info['id'] );
59
60 $donor = new Give_Donor( $donor_id );
61
62 // Bailout, if donor id doesn't exists.
63 if ( empty( $donor->id ) ) {
64 return false;
65 }
66
67 $defaults = array(
68 'title' => '',
69 'name' => '',
70 'user_id' => 0,
71 'line1' => '',
72 'line2' => '',
73 'city' => '',
74 'zip' => '',
75 'state' => '',
76 'country' => '',
77 );
78
79 $donor_info = wp_parse_args( $donor_info, $defaults );
80
81 if ( (int) $donor_info['user_id'] !== (int) $donor->user_id ) {
82
83 // Make sure we don't already have this user attached to a donor.
84 if ( ! empty( $donor_info['user_id'] ) && false !== Give()->donors->get_donor_by( 'user_id', $donor_info['user_id'] ) ) {
85 give_set_error(
86 'give-invalid-donor-user_id',
87 sprintf(
88 /* translators: %d User ID */
89 __( 'The User ID #%d is already associated with a different donor.', 'give' ),
90 $donor_info['user_id']
91 )
92 );
93 }
94
95 // Make sure it's actually a user.
96 $user = get_user_by( 'id', $donor_info['user_id'] );
97 if ( ! empty( $donor_info['user_id'] ) && false === $user ) {
98 give_set_error(
99 'give-invalid-user_id',
100 sprintf(
101 /* translators: %d User ID */
102 __( 'The User ID #%d does not exist. Please assign an existing user.', 'give' ),
103 $donor_info['user_id']
104 )
105 );
106 }
107 }
108
109 // Bailout, if errors are present.
110 if ( give_get_errors() ) {
111 return false;
112 }
113
114 $donor->update_meta( '_give_anonymous_donor', absint( $args['give_anonymous_donor'] ) );
115
116 // Save company name in when admin update donor company name from dashboard.
117 $donor->update_meta( '_give_donor_company', sanitize_text_field( $args['give_donor_company'] ) );
118
119 // If First name of donor is empty, then fetch the current first name of donor.
120 if ( empty( $donor_info['first_name'] ) ) {
121 $donor_info['first_name'] = $donor->get_first_name();
122 }
123
124 // Sanitize the inputs.
125 $donor_data = array();
126 $donor_data['name'] = trim( "{$donor_info['first_name']} {$donor_info['last_name']}" );
127 $donor_data['first_name'] = $donor_info['first_name'];
128 $donor_data['last_name'] = $donor_info['last_name'];
129 $donor_data['title'] = $donor_info['title'];
130 $donor_data['user_id'] = $donor_info['user_id'];
131
132 $donor_data = apply_filters( 'give_edit_donor_info', $donor_data, $donor_id );
133
134 /**
135 * Filter the address
136 *
137 * @todo unnecessary filter because we are not storing donor address to user.
138 *
139 * @since 1.0
140 */
141 $address = apply_filters( 'give_edit_donor_address', array(), $donor_id );
142
143 $donor_data = give_clean( $donor_data );
144 $address = give_clean( $address );
145
146 $output = give_connect_user_donor_profile( $donor, $donor_data, $address );
147
148 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
149 header( 'Content-Type: application/json' );
150 echo wp_json_encode( $output );
151 wp_die();
152 }
153
154 if ( $output['success'] ) {
155 wp_safe_redirect( add_query_arg(
156 array(
157 'post_type' => 'give_forms',
158 'page' => 'give-donors',
159 'view' => 'overview',
160 'id' => $donor_id,
161 'give-messages[]' => 'profile-updated'
162 ),
163 esc_url( admin_url( 'edit.php' ) )
164 ) );
165 }
166
167 exit;
168
169 }
170
171 add_action( 'give_edit-donor', 'give_edit_donor', 10, 1 );
172
173 /**
174 * Save a donor note.
175 *
176 * @param array $args The $_POST array being passed.
177 *
178 * @since 1.0
179 *
180 * @return int The Note ID that was saved, or 0 if nothing was saved.
181 */
182 function give_donor_save_note( $args ) {
183
184 $donor_view_role = apply_filters( 'give_view_donors_role', 'view_give_reports' );
185
186 if ( ! is_admin() || ! current_user_can( $donor_view_role ) ) {
187 wp_die( __( 'You do not have permission to edit this donor.', 'give' ), __( 'Error', 'give' ), array(
188 'response' => 403,
189 ) );
190 }
191
192 if ( empty( $args ) ) {
193 return false;
194 }
195
196 $donor_note = trim( give_clean( $args['donor_note'] ) );
197 $donor_id = (int) $args['customer_id'];
198 $nonce = $args['add_donor_note_nonce'];
199
200 if ( ! wp_verify_nonce( $nonce, 'add-donor-note' ) ) {
201 wp_die( __( 'Cheatin&#8217; uh?', 'give' ), __( 'Error', 'give' ), array(
202 'response' => 400,
203 ) );
204 }
205
206 if ( empty( $donor_note ) ) {
207 give_set_error( 'empty-donor-note', __( 'A note is required.', 'give' ) );
208 }
209
210 if ( give_get_errors() ) {
211 return false;
212 }
213
214 $donor = new Give_Donor( $donor_id );
215 $new_note = $donor->add_note( $donor_note );
216
217 /**
218 * Fires before inserting donor note.
219 *
220 * @param int $donor_id The ID of the donor.
221 * @param string $new_note Note content.
222 *
223 * @since 1.0
224 */
225 do_action( 'give_pre_insert_donor_note', $donor_id, $new_note );
226
227 if ( ! empty( $new_note ) && ! empty( $donor->id ) ) {
228
229 ob_start();
230 ?>
231 <div class="donor-note-wrapper dashboard-comment-wrap comment-item">
232 <span class="note-content-wrap">
233 <?php echo stripslashes( $new_note ); ?>
234 </span>
235 </div>
236 <?php
237 $output = ob_get_contents();
238 ob_end_clean();
239
240 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
241 echo $output;
242 exit;
243 }
244
245 return $new_note;
246
247 }
248
249 return false;
250
251 }
252
253 add_action( 'give_add-donor-note', 'give_donor_save_note', 10, 1 );
254
255
256 /**
257 * Disconnect a user ID from a donor
258 *
259 * @param array $args Array of arguments.
260 *
261 * @since 1.0
262 *
263 * @return bool|array If the disconnect was successful.
264 */
265 function give_disconnect_donor_user_id( $args ) {
266
267 $donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' );
268
269 if ( ! is_admin() || ! current_user_can( $donor_edit_role ) ) {
270 wp_die( __( 'You do not have permission to edit this donor.', 'give' ), __( 'Error', 'give' ), array(
271 'response' => 403,
272 ) );
273 }
274
275 if ( empty( $args ) ) {
276 return false;
277 }
278
279 $donor_id = (int) $args['customer_id'];
280
281 $nonce = $args['_wpnonce'];
282
283 if ( ! wp_verify_nonce( $nonce, 'edit-donor' ) ) {
284 wp_die( __( 'Cheatin&#8217; uh?', 'give' ), __( 'Error', 'give' ), array(
285 'response' => 400,
286 ) );
287 }
288
289 $donor = new Give_Donor( $donor_id );
290 if ( empty( $donor->id ) ) {
291 return false;
292 }
293
294 $user_id = $donor->user_id;
295
296 /**
297 * Fires before disconnecting user ID from a donor.
298 *
299 * @param int $donor_id The ID of the donor.
300 * @param int $user_id The ID of the user.
301 *
302 * @since 1.0
303 */
304 do_action( 'give_pre_donor_disconnect_user_id', $donor_id, $user_id );
305
306 $output = array();
307 $donor_args = array(
308 'user_id' => 0,
309 );
310
311 $redirect_url = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' ) . $donor_id;
312 $is_donor_updated = $donor->update( $donor_args );
313
314 if ( $is_donor_updated ) {
315
316 // Set meta for disconnected donor id and user id for future reference if needed.
317 update_user_meta( $user_id, '_give_disconnected_donor_id', $donor->id );
318 $donor->update_meta( '_give_disconnected_user_id', $user_id );
319
320 $redirect_url = add_query_arg(
321 'give-messages[]',
322 'disconnect-user',
323 $redirect_url
324 );
325
326 $output['success'] = true;
327
328 } else {
329 $output['success'] = false;
330 give_set_error( 'give-disconnect-user-fail', __( 'Failed to disconnect user from donor.', 'give' ) );
331 }
332
333 $output['redirect'] = $redirect_url;
334
335 /**
336 * Fires after disconnecting user ID from a donor.
337 *
338 * @param int $donor_id The ID of the donor.
339 *
340 * @since 1.0
341 */
342 do_action( 'give_post_donor_disconnect_user_id', $donor_id );
343
344 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
345 header( 'Content-Type: application/json' );
346 echo json_encode( $output );
347 wp_die();
348 }
349
350 return $output;
351
352 }
353
354 add_action( 'give_disconnect-userid', 'give_disconnect_donor_user_id', 10, 1 );
355
356 /**
357 * Add an email address to the donor from within the admin and log a donor note.
358 *
359 * @param array $args Array of arguments: nonce, donor id, and email address.
360 *
361 * @since 1.7
362 *
363 * @return mixed If DOING_AJAX echos out JSON, otherwise returns array of success (bool) and message (string).
364 */
365 function give_add_donor_email( $args ) {
366
367 $donor_id = '';
368 $donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' );
369
370 if ( ! is_admin() || ! current_user_can( $donor_edit_role ) ) {
371 wp_die( __( 'You do not have permission to edit this donor.', 'give' ), __( 'Error', 'give' ), array(
372 'response' => 403,
373 ) );
374 }
375
376 $output = array();
377 if ( empty( $args ) || empty( $args['email'] ) || empty( $args['customer_id'] ) ) {
378 $output['success'] = false;
379 if ( empty( $args['email'] ) ) {
380 $output['message'] = __( 'Email address is required.', 'give' );
381 } elseif ( empty( $args['customer_id'] ) ) {
382 $output['message'] = __( 'Donor ID is required.', 'give' );
383 } else {
384 $output['message'] = __( 'An error has occurred. Please try again.', 'give' );
385 }
386 } elseif ( ! wp_verify_nonce( $args['_wpnonce'], 'give_add_donor_email' ) ) {
387 $output = array(
388 'success' => false,
389 'message' => __( 'We\'re unable to recognize your session. Please refresh the screen to try again; otherwise contact your website administrator for assistance.', 'give' ),
390 );
391 } elseif ( ! is_email( $args['email'] ) ) {
392 $output = array(
393 'success' => false,
394 'message' => __( 'Invalid email.', 'give' ),
395 );
396 } else {
397 $email = sanitize_email( $args['email'] );
398 $donor_id = (int) $args['customer_id'];
399 $primary = 'true' === $args['primary'] ? true : false;
400 $donor = new Give_Donor( $donor_id );
401 if ( false === $donor->add_email( $email, $primary ) ) {
402 if ( in_array( $email, $donor->emails ) ) {
403 $output = array(
404 'success' => false,
405 'message' => __( 'Email already associated with this donor.', 'give' ),
406 );
407 } else {
408 $output = array(
409 'success' => false,
410 'message' => __( 'Email address is already associated with another donor.', 'give' ),
411 );
412 }
413 } else {
414 $redirect = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor_id . '&give-messages[]=email-added' );
415 $output = array(
416 'success' => true,
417 'message' => __( 'Email successfully added to donor.', 'give' ),
418 'redirect' => $redirect,
419 );
420
421 $user = wp_get_current_user();
422 $user_login = ! empty( $user->user_login ) ? $user->user_login : __( 'System', 'give' );
423 $donor_note = sprintf( __( 'Email address %1$s added by %2$s', 'give' ), $email, $user_login );
424 $donor->add_note( $donor_note );
425
426 if ( $primary ) {
427 $donor_note = sprintf( __( 'Email address %1$s set as primary by %2$s', 'give' ), $email, $user_login );
428 $donor->add_note( $donor_note );
429 }
430 }
431 } // End if().
432
433 do_action( 'give_post_add_donor_email', $donor_id, $args );
434
435 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
436 header( 'Content-Type: application/json' );
437 echo json_encode( $output );
438 wp_die();
439 }
440
441 return $output;
442 }
443
444 add_action( 'give_add_donor_email', 'give_add_donor_email', 10, 1 );
445
446
447 /**
448 * Remove an email address to the donor from within the admin and log a donor note and redirect back to the donor interface for feedback.
449 *
450 * @since 1.7
451 *
452 * @return bool|null
453 */
454 function give_remove_donor_email() {
455 if ( empty( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) {
456 return false;
457 }
458 if ( empty( $_GET['email'] ) || ! is_email( $_GET['email'] ) ) {
459 return false;
460 }
461 if ( empty( $_GET['_wpnonce'] ) ) {
462 return false;
463 }
464
465 $nonce = $_GET['_wpnonce'];
466 if ( ! wp_verify_nonce( $nonce, 'give-remove-donor-email' ) ) {
467 wp_die( __( 'We\'re unable to recognize your session. Please refresh the screen to try again; otherwise contact your website administrator for assistance.', 'give' ), __( 'Error', 'give' ), array(
468 'response' => 403,
469 ) );
470 }
471
472 $donor = new Give_Donor( $_GET['id'] );
473 if ( $donor->remove_email( $_GET['email'] ) ) {
474 $url = add_query_arg( 'give-messages[]', 'email-removed', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ) );
475 $user = wp_get_current_user();
476 $user_login = ! empty( $user->user_login ) ? $user->user_login : __( 'System', 'give' );
477 $donor_note = sprintf( __( 'Email address %1$s removed by %2$s', 'give' ), $_GET['email'], $user_login );
478 $donor->add_note( $donor_note );
479 } else {
480 $url = add_query_arg( 'give-messages[]', 'email-remove-failed', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ) );
481 }
482
483 wp_safe_redirect( $url );
484 exit;
485 }
486
487 add_action( 'give_remove_donor_email', 'give_remove_donor_email', 10 );
488
489
490 /**
491 * Set an email address as the primary for a donor from within the admin and log a donor note
492 * and redirect back to the donor interface for feedback
493 *
494 * @since 1.7
495 *
496 * @return bool|null
497 */
498 function give_set_donor_primary_email() {
499 if ( empty( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) {
500 return false;
501 }
502
503 if ( empty( $_GET['email'] ) || ! is_email( $_GET['email'] ) ) {
504 return false;
505 }
506
507 if ( empty( $_GET['_wpnonce'] ) ) {
508 return false;
509 }
510
511 $nonce = $_GET['_wpnonce'];
512
513 if ( ! wp_verify_nonce( $nonce, 'give-set-donor-primary-email' ) ) {
514 wp_die( __( 'We\'re unable to recognize your session. Please refresh the screen to try again; otherwise contact your website administrator for assistance.', 'give' ), __( 'Error', 'give' ), array(
515 'response' => 403,
516 ) );
517 }
518
519 $donor = new Give_Donor( $_GET['id'] );
520
521 if ( $donor->set_primary_email( $_GET['email'] ) ) {
522 $url = add_query_arg( 'give-messages[]', 'primary-email-updated', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ) );
523 $user = wp_get_current_user();
524 $user_login = ! empty( $user->user_login ) ? $user->user_login : __( 'System', 'give' );
525 $donor_note = sprintf( __( 'Email address %1$s set as primary by %2$s', 'give' ), $_GET['email'], $user_login );
526
527 $donor->add_note( $donor_note );
528 } else {
529 $url = add_query_arg( 'give-messages[]', 'primary-email-failed', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ) );
530 }
531
532 wp_safe_redirect( $url );
533 exit;
534 }
535
536 add_action( 'give_set_donor_primary_email', 'give_set_donor_primary_email', 10 );
537
538
539 /**
540 * This function will process the donor deletion.
541 *
542 * @param array $args Donor Deletion Arguments.
543 *
544 * @since 2.2
545 */
546 function give_process_donor_deletion( $args ) {
547 // Bailout.
548 if ( ! isset( $args['give-donor-delete-confirm'] ) ) {
549 return;
550 }
551
552 $donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' );
553
554 // Verify user capabilities to proceed for deleting donor.
555 if ( ! is_admin() || ! current_user_can( $donor_edit_role ) ) {
556 wp_die(
557 esc_html__( 'You do not have permission to delete donors.', 'give' ),
558 esc_html__( 'Error', 'give' ),
559 array(
560 'response' => 403,
561 )
562 );
563 }
564
565 $nonce_action = '';
566 if ( 'delete_bulk_donor' === $args['give_action'] ) {
567 $nonce_action = 'bulk-donors';
568 } elseif ( 'delete_donor' === $args['give_action'] ) {
569 $nonce_action = 'give-delete-donor';
570 }
571
572 // Verify Nonce for deleting bulk donors.
573 give_validate_nonce( $args['_wpnonce'], $nonce_action );
574
575 $redirect_args = array();
576 $donor_ids = ( isset( $args['donor'] ) && is_array( $args['donor'] ) ) ? $args['donor'] : array( $args['donor_id'] );
577 $redirect_args['order'] = ! empty( $args['order'] ) ? $args['order'] : 'DESC';
578 $redirect_args['orderby'] = ! empty( $args['orderby'] ) ? strtolower( $args['orderby'] ) : 'id';
579 $redirect_args['s'] = ! empty( $args['s'] ) ? $args['s'] : '';
580 $delete_donor = ! empty( $args['give-donor-delete-confirm'] ) ? give_is_setting_enabled( $args['give-donor-delete-confirm'] ) : false;
581 $delete_donation = ! empty( $args['give-donor-delete-records'] ) ? give_is_setting_enabled( $args['give-donor-delete-records'] ) : false;
582
583 if ( count( $donor_ids ) > 0 ) {
584
585 // Loop through the selected donors to delete.
586 foreach ( $donor_ids as $donor_id ) {
587
588 $donor = new Give_Donor( $donor_id );
589
590 // Proceed only if valid donor id is provided.
591 if ( $donor->id > 0 ) {
592
593 /**
594 * Fires before deleting donor.
595 *
596 * @param int $donor_id The ID of the donor.
597 * @param bool $delete_donor Confirm Donor Deletion.
598 * @param bool $delete_donation Confirm Donor related donations deletion.
599 *
600 * @since 1.0
601 */
602 do_action( 'give_pre_delete_donor', $donor->id, $delete_donor, $delete_donation );
603
604 // Proceed only, if user confirmed whether they need to delete the donor.
605 if ( $delete_donor ) {
606
607 // Delete donor and linked donations.
608 $donor_delete_status = give_delete_donor_and_related_donation( $donor, array(
609 'delete_donation' => $delete_donation,
610 ) );
611
612 if ( 1 === $donor_delete_status ) {
613 $redirect_args['give-messages[]'] = 'donor-deleted';
614 } elseif ( 2 === $donor_delete_status ) {
615 $redirect_args['give-messages[]'] = 'donor-donations-deleted';
616 }
617 } else {
618 $redirect_args['give-messages[]'] = 'confirm-delete-donor';
619 }
620 } else {
621 $redirect_args['give-messages[]'] = 'invalid-donor-id';
622 } // End if().
623 } // End foreach().
624 } else {
625 $redirect_args['give-messages[]'] = 'no-donor-found';
626 } // End if().
627
628 $redirect_url = add_query_arg(
629 $redirect_args,
630 admin_url( 'edit.php?post_type=give_forms&page=give-donors' )
631 );
632
633 wp_safe_redirect( $redirect_url );
634 give_die();
635
636 }
637 add_action( 'give_delete_donor', 'give_process_donor_deletion' );
638 add_action( 'give_delete_bulk_donor', 'give_process_donor_deletion' );
639