PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 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 All 256 releases
← All changes | includes/admin/donors/donor-actions.php +126 -56 2.3.2 → 4.17.0 View file →
@@ -16,13 +16,15 @@
16 16
17 17 /**
18 18 * Processes a donor edit.
19 19 *
20 + * @since 3.7.0 Add support to the "phone" field
21 + * @since 1.0
22 + *
20 23 * @param array $args The $_POST array being passed.
21 24 *
22 - * @since 1.0
23 - *
24 25 * @return array|bool $output Response messages
26 + * @throws Exception
25 27 */
26 28 function give_edit_donor( $args ) {
27 29
28 30 $donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' );
@@ -27,11 +29,15 @@
27 29
28 30 $donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' );
29 31
30 32 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 - ) );
33 + wp_die(
34 + esc_html__( 'You do not have permission to edit this donor.', 'give' ),
35 + esc_html__( 'Error', 'give' ),
36 + array(
37 + 'response' => 403,
38 + )
39 + );
34 40 }
35 41
36 42 if ( empty( $args ) ) {
37 43 return false;
@@ -39,13 +45,24 @@
39 45
40 46 // Sanitize Data.
41 47 $args = give_clean( $args );
42 48
49 + $args = wp_parse_args(
50 + $args,
51 + array(
52 + 'give_anonymous_donor' => 0,
53 + )
54 + );
55 +
43 56 // Verify Nonce.
44 57 if ( ! wp_verify_nonce( $args['_wpnonce'], 'edit-donor' ) ) {
45 - wp_die( esc_html__( 'Cheatin’ uh?', 'give' ), esc_html__( 'Error', 'give' ), array(
46 - 'response' => 400,
47 - ) );
58 + wp_die(
59 + esc_html__( 'Cheatin’ uh?', 'give' ),
60 + esc_html__( 'Error', 'give' ),
61 + array(
62 + 'response' => 400,
63 + )
64 + );
48 65 }
49 66
50 67 $donor_info = $args['donor_info'];
51 68 $donor_id = intval( $donor_info['id'] );
@@ -108,8 +125,18 @@
108 125
109 126 // Save company name in when admin update donor company name from dashboard.
110 127 $donor->update_meta( '_give_donor_company', sanitize_text_field( $args['give_donor_company'] ) );
111 128
129 + /**
130 + * Fires after using the submitted data to update the donor metadata.
131 + *
132 + * @param array $args The sanitized data submitted.
133 + * @param int $donor_id The donor ID.
134 + *
135 + * @since 3.7.0
136 + */
137 + do_action('give_admin_donor_details_updating', $args, $donor->id);
138 +
112 139 // If First name of donor is empty, then fetch the current first name of donor.
113 140 if ( empty( $donor_info['first_name'] ) ) {
114 141 $donor_info['first_name'] = $donor->get_first_name();
115 142 }
@@ -144,18 +171,22 @@
144 171 wp_die();
145 172 }
146 173
147 174 if ( $output['success'] ) {
148 - wp_safe_redirect( add_query_arg(
149 - array(
150 - 'post_type' => 'give_forms',
151 - 'page' => 'give-donors',
152 - 'view' => 'overview',
153 - 'id' => $donor_id,
154 - 'give-messages[]' => 'profile-updated'
155 - ),
156 - esc_url( admin_url( 'edit.php' ) )
157 - ) );
175 + wp_safe_redirect(
176 + esc_url_raw(
177 + add_query_arg(
178 + array(
179 + 'post_type' => 'give_forms',
180 + 'page' => 'give-donors',
181 + 'view' => 'legacy-overview',
182 + 'id' => $donor_id,
183 + 'give-messages[]' => 'profile-updated',
184 + ),
185 + admin_url( 'edit.php' )
186 + )
187 + )
188 + );
158 189 }
159 190
160 191 exit;
161 192
@@ -176,11 +207,15 @@
176 207
177 208 $donor_view_role = apply_filters( 'give_view_donors_role', 'view_give_reports' );
178 209
179 210 if ( ! is_admin() || ! current_user_can( $donor_view_role ) ) {
180 - wp_die( __( 'You do not have permission to edit this donor.', 'give' ), __( 'Error', 'give' ), array(
181 - 'response' => 403,
182 - ) );
211 + wp_die(
212 + __( 'You do not have permission to edit this donor.', 'give' ),
213 + __( 'Error', 'give' ),
214 + array(
215 + 'response' => 403,
216 + )
217 + );
183 218 }
184 219
185 220 if ( empty( $args ) ) {
186 221 return false;
@@ -190,11 +225,15 @@
190 225 $donor_id = (int) $args['customer_id'];
191 226 $nonce = $args['add_donor_note_nonce'];
192 227
193 228 if ( ! wp_verify_nonce( $nonce, 'add-donor-note' ) ) {
194 - wp_die( __( 'Cheatin’ uh?', 'give' ), __( 'Error', 'give' ), array(
195 - 'response' => 400,
196 - ) );
229 + wp_die(
230 + __( 'Cheatin’ uh?', 'give' ),
231 + __( 'Error', 'give' ),
232 + array(
233 + 'response' => 400,
234 + )
235 + );
197 236 }
198 237
199 238 if ( empty( $donor_note ) ) {
200 239 give_set_error( 'empty-donor-note', __( 'A note is required.', 'give' ) );
@@ -259,11 +298,15 @@
259 298
260 299 $donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' );
261 300
262 301 if ( ! is_admin() || ! current_user_can( $donor_edit_role ) ) {
263 - wp_die( __( 'You do not have permission to edit this donor.', 'give' ), __( 'Error', 'give' ), array(
264 - 'response' => 403,
265 - ) );
302 + wp_die(
303 + __( 'You do not have permission to edit this donor.', 'give' ),
304 + __( 'Error', 'give' ),
305 + array(
306 + 'response' => 403,
307 + )
308 + );
266 309 }
267 310
268 311 if ( empty( $args ) ) {
269 312 return false;
@@ -273,11 +316,15 @@
273 316
274 317 $nonce = $args['_wpnonce'];
275 318
276 319 if ( ! wp_verify_nonce( $nonce, 'edit-donor' ) ) {
277 - wp_die( __( 'Cheatin’ uh?', 'give' ), __( 'Error', 'give' ), array(
278 - 'response' => 400,
279 - ) );
320 + wp_die(
321 + __( 'Cheatin’ uh?', 'give' ),
322 + __( 'Error', 'give' ),
323 + array(
324 + 'response' => 400,
325 + )
326 + );
280 327 }
281 328
282 329 $donor = new Give_Donor( $donor_id );
283 330 if ( empty( $donor->id ) ) {
@@ -300,15 +347,23 @@
300 347 $donor_args = array(
301 348 'user_id' => 0,
302 349 );
303 350
351 + $redirect_url = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=legacy-overview&id=' ) . $donor_id;
352 + $is_donor_updated = $donor->update( $donor_args );
304 353
305 - $output['success'] = true;
306 - if ( ! $donor->update( $donor_args ) ) {
307 - update_user_meta( $user_id, '_give_is_donor_disconnected', true );
354 + if ( $is_donor_updated ) {
355 +
356 + // Set meta for disconnected donor id and user id for future reference if needed.
308 357 update_user_meta( $user_id, '_give_disconnected_donor_id', $donor->id );
309 358 $donor->update_meta( '_give_disconnected_user_id', $user_id );
310 359
360 + $redirect_url = add_query_arg(
361 + 'give-messages[]',
362 + 'disconnect-user',
363 + $redirect_url
364 + );
365 +
311 366 $output['success'] = true;
312 367
313 368 } else {
314 369 $output['success'] = false;
@@ -314,9 +369,9 @@
314 369 $output['success'] = false;
315 370 give_set_error( 'give-disconnect-user-fail', __( 'Failed to disconnect user from donor.', 'give' ) );
316 371 }
317 372
318 - $output['redirect'] = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' ) . $donor_id;
373 + $output['redirect'] = esc_url_raw( $redirect_url );
319 374
320 375 /**
321 376 * Fires after disconnecting user ID from a donor.
322 377 *
@@ -348,15 +403,19 @@
348 403 * @return mixed If DOING_AJAX echos out JSON, otherwise returns array of success (bool) and message (string).
349 404 */
350 405 function give_add_donor_email( $args ) {
351 406
352 - $donor_id = '';
407 + $donor_id = '';
353 408 $donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' );
354 409
355 410 if ( ! is_admin() || ! current_user_can( $donor_edit_role ) ) {
356 - wp_die( __( 'You do not have permission to edit this donor.', 'give' ), __( 'Error', 'give' ), array(
357 - 'response' => 403,
358 - ) );
411 + wp_die(
412 + __( 'You do not have permission to edit this donor.', 'give' ),
413 + __( 'Error', 'give' ),
414 + array(
415 + 'response' => 403,
416 + )
417 + );
359 418 }
360 419
361 420 $output = array();
362 421 if ( empty( $args ) || empty( $args['email'] ) || empty( $args['customer_id'] ) ) {
@@ -370,9 +429,9 @@
370 429 }
371 430 } elseif ( ! wp_verify_nonce( $args['_wpnonce'], 'give_add_donor_email' ) ) {
372 431 $output = array(
373 432 'success' => false,
374 - 'message' => __( 'Nonce verification failed.', 'give' ),
433 + 'message' => __( 'We\'re unable to recognize your session. Please refresh the screen to try again; otherwise contact your website administrator for assistance.', 'give' ),
375 434 );
376 435 } elseif ( ! is_email( $args['email'] ) ) {
377 436 $output = array(
378 437 'success' => false,
@@ -395,9 +454,9 @@
395 454 'message' => __( 'Email address is already associated with another donor.', 'give' ),
396 455 );
397 456 }
398 457 } else {
399 - $redirect = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor_id . '&give-messages[]=email-added' );
458 + $redirect = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=legacy-overview&id=' . $donor_id . '&give-messages[]=email-added' );
400 459 $output = array(
401 460 'success' => true,
402 461 'message' => __( 'Email successfully added to donor.', 'give' ),
403 462 'redirect' => $redirect,
@@ -448,25 +507,29 @@
448 507 }
449 508
450 509 $nonce = $_GET['_wpnonce'];
451 510 if ( ! wp_verify_nonce( $nonce, 'give-remove-donor-email' ) ) {
452 - wp_die( __( 'Nonce verification failed', 'give' ), __( 'Error', 'give' ), array(
453 - 'response' => 403,
454 - ) );
511 + wp_die(
512 + __( 'We\'re unable to recognize your session. Please refresh the screen to try again; otherwise contact your website administrator for assistance.', 'give' ),
513 + __( 'Error', 'give' ),
514 + array(
515 + 'response' => 403,
516 + )
517 + );
455 518 }
456 519
457 520 $donor = new Give_Donor( $_GET['id'] );
458 521 if ( $donor->remove_email( $_GET['email'] ) ) {
459 - $url = add_query_arg( 'give-messages[]', 'email-removed', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ) );
522 + $url = add_query_arg( 'give-messages[]', 'email-removed', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=legacy-overview&id=' . $donor->id ) );
460 523 $user = wp_get_current_user();
461 524 $user_login = ! empty( $user->user_login ) ? $user->user_login : __( 'System', 'give' );
462 525 $donor_note = sprintf( __( 'Email address %1$s removed by %2$s', 'give' ), $_GET['email'], $user_login );
463 526 $donor->add_note( $donor_note );
464 527 } else {
465 - $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 ) );
528 + $url = add_query_arg( 'give-messages[]', 'email-remove-failed', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=legacy-overview&id=' . $donor->id ) );
466 529 }
467 530
468 - wp_safe_redirect( $url );
531 + wp_safe_redirect( esc_url_raw( $url ) );
469 532 exit;
470 533 }
471 534
472 535 add_action( 'give_remove_donor_email', 'give_remove_donor_email', 10 );
@@ -495,17 +558,21 @@
495 558
496 559 $nonce = $_GET['_wpnonce'];
497 560
498 561 if ( ! wp_verify_nonce( $nonce, 'give-set-donor-primary-email' ) ) {
499 - wp_die( __( 'Nonce verification failed', 'give' ), __( 'Error', 'give' ), array(
500 - 'response' => 403,
501 - ) );
562 + wp_die(
563 + __( 'We\'re unable to recognize your session. Please refresh the screen to try again; otherwise contact your website administrator for assistance.', 'give' ),
564 + __( 'Error', 'give' ),
565 + array(
566 + 'response' => 403,
567 + )
568 + );
502 569 }
503 570
504 571 $donor = new Give_Donor( $_GET['id'] );
505 572
506 573 if ( $donor->set_primary_email( $_GET['email'] ) ) {
507 - $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 ) );
574 + $url = add_query_arg( 'give-messages[]', 'primary-email-updated', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=legacy-overview&id=' . $donor->id ) );
508 575 $user = wp_get_current_user();
509 576 $user_login = ! empty( $user->user_login ) ? $user->user_login : __( 'System', 'give' );
510 577 $donor_note = sprintf( __( 'Email address %1$s set as primary by %2$s', 'give' ), $_GET['email'], $user_login );
511 578
@@ -510,12 +577,12 @@
510 577 $donor_note = sprintf( __( 'Email address %1$s set as primary by %2$s', 'give' ), $_GET['email'], $user_login );
511 578
512 579 $donor->add_note( $donor_note );
513 580 } else {
514 - $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 ) );
581 + $url = add_query_arg( 'give-messages[]', 'primary-email-failed', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=legacy-overview&id=' . $donor->id ) );
515 582 }
516 583
517 - wp_safe_redirect( $url );
584 + wp_safe_redirect( esc_url_raw( $url ) );
518 585 exit;
519 586 }
520 587
521 588 add_action( 'give_set_donor_primary_email', 'give_set_donor_primary_email', 10 );
@@ -589,11 +656,14 @@
589 656 // Proceed only, if user confirmed whether they need to delete the donor.
590 657 if ( $delete_donor ) {
591 658
592 659 // Delete donor and linked donations.
593 - $donor_delete_status = give_delete_donor_and_related_donation( $donor, array(
594 - 'delete_donation' => $delete_donation,
595 - ) );
660 + $donor_delete_status = give_delete_donor_and_related_donation(
661 + $donor,
662 + array(
663 + 'delete_donation' => $delete_donation,
664 + )
665 + );
596 666
597 667 if ( 1 === $donor_delete_status ) {
598 668 $redirect_args['give-messages[]'] = 'donor-deleted';
599 669 } elseif ( 2 === $donor_delete_status ) {
@@ -614,9 +684,9 @@
614 684 $redirect_args,
615 685 admin_url( 'edit.php?post_type=give_forms&page=give-donors' )
616 686 );
617 687
618 - wp_safe_redirect( $redirect_url );
688 + wp_safe_redirect( esc_url_raw( $redirect_url ) );
619 689 give_die();
620 690
621 691 }
622 692 add_action( 'give_delete_donor', 'give_process_donor_deletion' );