PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
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 2.30.0 All 255 releases
← All changes | includes/user-functions.php +48 -76 2.3.24.16.9 View file →
@@ -40,9 +40,9 @@
40 40 return false;
41 41 }
42 42
43 43 $status = ( 'complete' === $status ) ? 'publish' : $status;
44 - $paged = 1;
44 + $paged = 1;
45 45
46 46 if ( $pagination ) {
47 47 if ( get_query_var( 'paged' ) ) {
48 48 $paged = get_query_var( 'paged' );
@@ -50,14 +50,17 @@
50 50 $paged = get_query_var( 'page' );
51 51 }
52 52 }
53 53
54 - $args = apply_filters( 'give_get_users_donations_args', array(
55 - 'user' => $user,
56 - 'number' => $number,
57 - 'status' => $status,
58 - 'orderby' => 'date',
59 - ) );
54 + $args = apply_filters(
55 + 'give_get_users_donations_args',
56 + [
57 + 'user' => $user,
58 + 'number' => $number,
59 + 'status' => $status,
60 + 'orderby' => 'date',
61 + ]
62 + );
60 63
61 64 if ( $pagination ) {
62 65 $args['page'] = $paged;
63 66 } else {
@@ -64,9 +67,9 @@
64 67 $args['nopaging'] = true;
65 68 }
66 69
67 70 $by_user_id = is_numeric( $user ) ? true : false;
68 - $donor = new Give_Donor( $user, $by_user_id );
71 + $donor = new Give_Donor( $user, $by_user_id );
69 72
70 73 if ( ! empty( $donor->payment_ids ) ) {
71 74
72 75 unset( $args['user'] );
@@ -115,12 +118,15 @@
115 118
116 119 // Get all the items donated.
117 120 $payment_ids = array_reverse( explode( ',', $donor->payment_ids ) );
118 121 $limit_payments = apply_filters( 'give_users_completed_donations_payments', 50 );
122 +
119 123 if ( ! empty( $limit_payments ) ) {
120 124 $payment_ids = array_slice( $payment_ids, 0, $limit_payments );
125 + Give_Payments_Query::update_meta_cache( $payment_ids );
121 126 }
122 - $donation_data = array();
127 +
128 + $donation_data = [];
123 129 foreach ( $payment_ids as $payment_id ) {
124 130 $donation_data[] = give_get_payment_meta( $payment_id );
125 131 }
126 132
@@ -128,9 +134,9 @@
128 134 return false;
129 135 }
130 136
131 137 // Grab only the post ids "form_id" of the forms donated on this order.
132 - $completed_donations_ids = array();
138 + $completed_donations_ids = [];
133 139 foreach ( $donation_data as $donation_meta ) {
134 140 $completed_donations_ids[] = isset( $donation_meta['form_id'] ) ? $donation_meta['form_id'] : '';
135 141 }
136 142
@@ -147,13 +153,16 @@
147 153 }
148 154
149 155 $post_type = get_post_type( $form_ids[0] );
150 156
151 - $args = apply_filters( 'give_get_users_completed_donations_args', array(
152 - 'include' => $form_ids,
153 - 'post_type' => $post_type,
154 - 'posts_per_page' => - 1,
155 - ) );
157 + $args = apply_filters(
158 + 'give_get_users_completed_donations_args',
159 + [
160 + 'include' => $form_ids,
161 + 'post_type' => $post_type,
162 + 'posts_per_page' => - 1,
163 + ]
164 + );
156 165
157 166 return apply_filters( 'give_users_completed_donations_list', get_posts( $args ) );
158 167 }
159 168
@@ -205,13 +214,13 @@
205 214 } elseif ( is_numeric( $user ) ) {
206 215 $field = 'user_id';
207 216 }
208 217
209 - $stats = array();
218 + $stats = [];
210 219 $donor = Give()->donors->get_donor_by( $field, $user );
211 220
212 221 if ( $donor ) {
213 - $donor = new Give_Donor( $donor->id );
222 + $donor = new Give_Donor( $donor->id );
214 223 $stats['purchases'] = absint( $donor->purchase_count );
215 224 $stats['total_spent'] = give_maybe_sanitize_amount( $donor->get_total_donation_amount() );
216 225 }
217 226
@@ -315,9 +324,9 @@
315 324 $valid = false;
316 325
317 326 // Check if guest checkout is disable for form.
318 327 if ( $form_id && give_logged_in_only( $form_id ) ) {
319 - give_set_error( 'registration_required', __( 'You must register or login to complete your donation.', 'give' ) );
328 + give_set_error( 'registration_required', __( 'You must register or log in to complete your donation.', 'give' ) );
320 329 $valid = false;
321 330 }
322 331 }
323 332
@@ -355,9 +364,9 @@
355 364 $valid = false;
356 365
357 366 } elseif ( email_exists( $email ) ) {
358 367 // Email already exists.
359 - give_set_error( 'email_exists', __( 'Email already exists.', 'give' ) );
368 + give_set_error( 'email_exists', __( 'The email address provided is already in use by a registered account on this site. Please log in and try again.', 'give' ) );
360 369 $valid = false;
361 370
362 371 } elseif ( ! is_email( $email ) ) {
363 372 // Validate email.
@@ -368,9 +377,9 @@
368 377
369 378 // If donor email is not primary.
370 379 if ( ! email_exists( $email ) && give_donor_email_exists( $email ) && give_is_additional_email( $email ) ) {
371 380 // Check if email exists.
372 - give_set_error( 'email_used', __( 'The email address provided is already active for another user.', 'give' ) );
381 + give_set_error( 'email_used', __( 'The email address provided is already associated with another donor in the system. Please log in or use a different email', 'give' ) );
373 382 $valid = false;
374 383 }
375 384 }
376 385
@@ -465,66 +474,29 @@
465 474 * @access public
466 475 * @since 1.0
467 476 *
468 477 * @param int/null $donor_id Donor ID.
469 - * @param array $args donor args.
478 + * @param array $args {
470 479 *
480 + * @type bool $by_user_id Flag to validate find donor by donor ID or user ID
481 + * @type string $address_type Optional. Which type of donor address this function will return.
482 + * }
483 + *
471 484 * @return array The donor's address, if any
472 485 */
473 -function give_get_donor_address( $donor_id = null, $args = array() ) {
474 - if ( empty( $donor_id ) ) {
475 - $donor_id = get_current_user_id();
476 - }
486 +function give_get_donor_address( $donor_id = null, $args = [] ) {
477 487
478 - $address = array();
479 - $args = wp_parse_args(
480 - $args,
481 - array(
482 - 'address_type' => 'billing',
483 - )
484 - );
485 - $default_address = array(
486 - 'line1' => '',
487 - 'line2' => '',
488 - 'city' => '',
489 - 'state' => '',
490 - 'country' => '',
491 - 'zip' => '',
492 - );
488 + $args['by_user_id'] = false;
493 489
494 -
495 - // Backward compatibility for user id param.
496 - $by_user_id = get_user_by( 'id', $donor_id ) ? true : false;
497 -
498 - // Backward compatibility.
499 - if ( ! give_has_upgrade_completed( 'v20_upgrades_user_address' ) && $by_user_id ) {
500 - return wp_parse_args(
501 - (array) get_user_meta( $donor_id, '_give_user_address', true ),
502 - $default_address
503 - );
490 + // Set user id if donor is empty.
491 + if ( empty( $donor_id ) ) {
492 + $donor_id = get_current_user_id();
493 + $args['by_user_id'] = true;
504 494 }
505 495
506 - $donor = new Give_Donor( $donor_id, $by_user_id );
496 + $donor = new Give_Donor( $donor_id, (bool) $args['by_user_id'] );
507 497
508 - if (
509 - ! $donor->id ||
510 - empty( $donor->address ) ||
511 - ! array_key_exists( $args['address_type'], $donor->address )
512 - ) {
513 - return $default_address;
514 - }
515 -
516 - switch ( true ) {
517 - case is_string( end( $donor->address[ $args['address_type'] ] ) ):
518 - $address = wp_parse_args( $donor->address[ $args['address_type'] ], $default_address );
519 - break;
520 -
521 - case is_array( end( $donor->address[ $args['address_type'] ] ) ):
522 - $address = wp_parse_args( array_shift( $donor->address[ $args['address_type'] ] ), $default_address );
523 - break;
524 - }
525 -
526 - return $address;
498 + return $donor->get_donor_address( $args );
527 499 }
528 500
529 501 /**
530 502 * Give New User Notification
@@ -538,9 +510,9 @@
538 510 * @since 1.0
539 511 *
540 512 * @return void
541 513 */
542 -function give_new_user_notification( $donation_id = 0, $donation_data = array() ) {
514 +function give_new_user_notification( $donation_id = 0, $donation_data = [] ) {
543 515 // Bailout.
544 516 if (
545 517 empty( $donation_id )
546 518 || empty( $donation_data )
@@ -554,15 +526,15 @@
554 526 $user = get_user_by( 'ID', $donation_data['user_info']['id'] );
555 527
556 528 $donation_data['user_info'] = array_merge(
557 529 $donation_data['user_info'],
558 - array(
530 + [
559 531 'user_id' => $donation_data['user_info']['id'],
560 532 'user_first' => $donation_data['user_info']['first_name'],
561 533 'user_last' => $donation_data['user_info']['last_name'],
562 534 'user_email' => $donation_data['user_info']['email'],
563 535 'user_login' => $user->user_login,
564 - )
536 + ]
565 537 );
566 538
567 539 do_action( 'give_new-donor-register_email_notification', $donation_data['user_info']['id'], $donation_data['user_info'], $donation_id );
568 540 do_action( 'give_donor-register_email_notification', $donation_data['user_info']['id'], $donation_data['user_info'], $donation_id );
@@ -596,11 +568,11 @@
596 568
597 569 switch ( $from ) {
598 570
599 571 case 'donation':
600 - $title_prefix = give_get_meta( $id, '_give_payment_donor_title_prefix', true );
601 - $first_name = give_get_meta( $id, '_give_donor_billing_first_name', true );
602 - $last_name = give_get_meta( $id, '_give_donor_billing_last_name', true );
572 + $title_prefix = give_get_meta( $id, '_give_payment_donor_title_prefix', true );
573 + $first_name = give_get_meta( $id, '_give_donor_billing_first_name', true );
574 + $last_name = give_get_meta( $id, '_give_donor_billing_last_name', true );
603 575
604 576 $name = "{$first_name} {$last_name}";
605 577
606 578 break;