| 1 |
<?php |
| 2 |
/** |
| 3 |
* User Functions |
| 4 |
* |
| 5 |
* Functions related to users / donors |
| 6 |
* |
| 7 |
* @package Give |
| 8 |
* @subpackage Functions |
| 9 |
* @copyright Copyright (c) 2016, GiveWP |
| 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 |
* Get Users Donations |
| 21 |
* |
| 22 |
* Retrieves a list of all donations by a specific user. |
| 23 |
* |
| 24 |
* @param int $user User ID or email address. |
| 25 |
* @param int $number Number of donations to retrieve. |
| 26 |
* @param bool $pagination Enable/Disable Pagination. |
| 27 |
* @param string $status Donation Status. |
| 28 |
* |
| 29 |
* @since 1.0 |
| 30 |
* |
| 31 |
* @return bool|array List of all user donations. |
| 32 |
*/ |
| 33 |
function give_get_users_donations( $user = 0, $number = 20, $pagination = false, $status = 'complete' ) { |
| 34 |
|
| 35 |
if ( empty( $user ) ) { |
| 36 |
$user = get_current_user_id(); |
| 37 |
} |
| 38 |
|
| 39 |
if ( 0 === $user && ! Give()->email_access->token_exists ) { |
| 40 |
return false; |
| 41 |
} |
| 42 |
|
| 43 |
$status = ( 'complete' === $status ) ? 'publish' : $status; |
| 44 |
$paged = 1; |
| 45 |
|
| 46 |
if ( $pagination ) { |
| 47 |
if ( get_query_var( 'paged' ) ) { |
| 48 |
$paged = get_query_var( 'paged' ); |
| 49 |
} elseif ( get_query_var( 'page' ) ) { |
| 50 |
$paged = get_query_var( 'page' ); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 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 |
); |
| 63 |
|
| 64 |
if ( $pagination ) { |
| 65 |
$args['page'] = $paged; |
| 66 |
} else { |
| 67 |
$args['nopaging'] = true; |
| 68 |
} |
| 69 |
|
| 70 |
$by_user_id = is_numeric( $user ) ? true : false; |
| 71 |
$donor = new Give_Donor( $user, $by_user_id ); |
| 72 |
|
| 73 |
if ( ! empty( $donor->payment_ids ) ) { |
| 74 |
|
| 75 |
unset( $args['user'] ); |
| 76 |
$args['post__in'] = array_map( 'absint', explode( ',', $donor->payment_ids ) ); |
| 77 |
|
| 78 |
} |
| 79 |
|
| 80 |
$donations = give_get_payments( apply_filters( 'give_get_users_donations_args', $args ) ); |
| 81 |
|
| 82 |
// No donations. |
| 83 |
if ( ! $donations ) { |
| 84 |
return false; |
| 85 |
} |
| 86 |
|
| 87 |
return $donations; |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Get Users Donations |
| 92 |
* |
| 93 |
* Returns a list of unique donation forms given to by a specific user. |
| 94 |
* |
| 95 |
* @param int $user User ID or email address |
| 96 |
* @param string $status Donation Status. |
| 97 |
* |
| 98 |
* @since 1.0 |
| 99 |
* |
| 100 |
* @return bool|object List of unique forms donated by user |
| 101 |
*/ |
| 102 |
function give_get_users_completed_donations( $user = 0, $status = 'complete' ) { |
| 103 |
if ( empty( $user ) ) { |
| 104 |
$user = get_current_user_id(); |
| 105 |
} |
| 106 |
|
| 107 |
if ( empty( $user ) ) { |
| 108 |
return false; |
| 109 |
} |
| 110 |
|
| 111 |
$by_user_id = is_numeric( $user ) ? true : false; |
| 112 |
|
| 113 |
$donor = new Give_Donor( $user, $by_user_id ); |
| 114 |
|
| 115 |
if ( empty( $donor->payment_ids ) ) { |
| 116 |
return false; |
| 117 |
} |
| 118 |
|
| 119 |
// Get all the items donated. |
| 120 |
$payment_ids = array_reverse( explode( ',', $donor->payment_ids ) ); |
| 121 |
$limit_payments = apply_filters( 'give_users_completed_donations_payments', 50 ); |
| 122 |
|
| 123 |
if ( ! empty( $limit_payments ) ) { |
| 124 |
$payment_ids = array_slice( $payment_ids, 0, $limit_payments ); |
| 125 |
Give_Payments_Query::update_meta_cache( $payment_ids ); |
| 126 |
} |
| 127 |
|
| 128 |
$donation_data = []; |
| 129 |
foreach ( $payment_ids as $payment_id ) { |
| 130 |
$donation_data[] = give_get_payment_meta( $payment_id ); |
| 131 |
} |
| 132 |
|
| 133 |
if ( empty( $donation_data ) ) { |
| 134 |
return false; |
| 135 |
} |
| 136 |
|
| 137 |
// Grab only the post ids "form_id" of the forms donated on this order. |
| 138 |
$completed_donations_ids = []; |
| 139 |
foreach ( $donation_data as $donation_meta ) { |
| 140 |
$completed_donations_ids[] = isset( $donation_meta['form_id'] ) ? $donation_meta['form_id'] : ''; |
| 141 |
} |
| 142 |
|
| 143 |
if ( empty( $completed_donations_ids ) ) { |
| 144 |
return false; |
| 145 |
} |
| 146 |
|
| 147 |
// Only include each donation once. |
| 148 |
$form_ids = array_unique( $completed_donations_ids ); |
| 149 |
|
| 150 |
// Make sure we still have some products and a first item. |
| 151 |
if ( empty( $form_ids ) || ! isset( $form_ids[0] ) ) { |
| 152 |
return false; |
| 153 |
} |
| 154 |
|
| 155 |
$post_type = get_post_type( $form_ids[0] ); |
| 156 |
|
| 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 |
); |
| 165 |
|
| 166 |
return apply_filters( 'give_users_completed_donations_list', get_posts( $args ) ); |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
/** |
| 171 |
* Has donations |
| 172 |
* |
| 173 |
* Checks to see if a user has donated to at least one form. |
| 174 |
* |
| 175 |
* @param int $user_id The ID of the user to check. |
| 176 |
* |
| 177 |
* @access public |
| 178 |
* @since 1.0 |
| 179 |
* |
| 180 |
* @return bool True if has donated, false other wise. |
| 181 |
*/ |
| 182 |
function give_has_donations( $user_id = null ) { |
| 183 |
if ( empty( $user_id ) ) { |
| 184 |
$user_id = get_current_user_id(); |
| 185 |
} |
| 186 |
|
| 187 |
if ( give_get_users_donations( $user_id, 1 ) ) { |
| 188 |
return true; // User has at least one donation. |
| 189 |
} |
| 190 |
|
| 191 |
// User has never donated anything. |
| 192 |
return false; |
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
/** |
| 197 |
* Get Donation Status for User. |
| 198 |
* |
| 199 |
* Retrieves the donation count and the total amount spent for a specific user. |
| 200 |
* |
| 201 |
* @param int|string $user The ID or email of the donor to retrieve stats for. |
| 202 |
* |
| 203 |
* @access public |
| 204 |
* @since 1.0 |
| 205 |
* |
| 206 |
* @return array |
| 207 |
*/ |
| 208 |
function give_get_donation_stats_by_user( $user = '' ) { |
| 209 |
|
| 210 |
$field = ''; |
| 211 |
|
| 212 |
if ( is_email( $user ) ) { |
| 213 |
$field = 'email'; |
| 214 |
} elseif ( is_numeric( $user ) ) { |
| 215 |
$field = 'user_id'; |
| 216 |
} |
| 217 |
|
| 218 |
$stats = []; |
| 219 |
$donor = Give()->donors->get_donor_by( $field, $user ); |
| 220 |
|
| 221 |
if ( $donor ) { |
| 222 |
$donor = new Give_Donor( $donor->id ); |
| 223 |
$stats['purchases'] = absint( $donor->purchase_count ); |
| 224 |
$stats['total_spent'] = give_maybe_sanitize_amount( $donor->get_total_donation_amount() ); |
| 225 |
} |
| 226 |
|
| 227 |
/** |
| 228 |
* Filter the donation stats. |
| 229 |
* |
| 230 |
* @since 1.7 |
| 231 |
*/ |
| 232 |
$stats = (array) apply_filters( 'give_donation_stats_by_user', $stats, $user ); |
| 233 |
|
| 234 |
return $stats; |
| 235 |
} |
| 236 |
|
| 237 |
|
| 238 |
/** |
| 239 |
* Count number of donations of a donor. |
| 240 |
* |
| 241 |
* Returns total number of donations a donor has made. |
| 242 |
* |
| 243 |
* @param int|string $user The ID or email of the donor. |
| 244 |
* |
| 245 |
* @access public |
| 246 |
* @since 1.0 |
| 247 |
* |
| 248 |
* @return int The total number of donations. |
| 249 |
*/ |
| 250 |
function give_count_donations_of_donor( $user = null ) { |
| 251 |
|
| 252 |
// Logged in? |
| 253 |
if ( empty( $user ) ) { |
| 254 |
$user = get_current_user_id(); |
| 255 |
} |
| 256 |
|
| 257 |
// Email access? |
| 258 |
if ( empty( $user ) && Give()->email_access->token_email ) { |
| 259 |
$user = Give()->email_access->token_email; |
| 260 |
} |
| 261 |
|
| 262 |
$stats = ! empty( $user ) ? give_get_donation_stats_by_user( $user ) : false; |
| 263 |
|
| 264 |
return isset( $stats['purchases'] ) ? $stats['purchases'] : 0; |
| 265 |
} |
| 266 |
|
| 267 |
/** |
| 268 |
* Calculates the total amount spent by a user. |
| 269 |
* |
| 270 |
* @param int|string $user The ID or email of the donor. |
| 271 |
* |
| 272 |
* @access public |
| 273 |
* @since 1.0 |
| 274 |
* |
| 275 |
* @return float The total amount the user has spent |
| 276 |
*/ |
| 277 |
function give_donation_total_of_user( $user = null ) { |
| 278 |
|
| 279 |
$stats = give_get_donation_stats_by_user( $user ); |
| 280 |
|
| 281 |
return $stats['total_spent']; |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
/** |
| 286 |
* Validate a potential username. |
| 287 |
* |
| 288 |
* @param string $username The username to validate. |
| 289 |
* @param int $form_id Donation Form ID. |
| 290 |
* |
| 291 |
* @since 1.0 |
| 292 |
* |
| 293 |
* @return bool |
| 294 |
*/ |
| 295 |
function give_validate_username( $username, $form_id = 0 ) { |
| 296 |
$valid = true; |
| 297 |
|
| 298 |
// Validate username. |
| 299 |
if ( ! empty( $username ) ) { |
| 300 |
|
| 301 |
// Sanitize username. |
| 302 |
$sanitized_user_name = sanitize_user( $username, false ); |
| 303 |
|
| 304 |
// We have an user name, check if it already exists. |
| 305 |
if ( username_exists( $username ) ) { |
| 306 |
// Username already registered. |
| 307 |
give_set_error( 'username_unavailable', __( 'Username already taken.', 'give' ) ); |
| 308 |
$valid = false; |
| 309 |
|
| 310 |
// Check if it's valid. |
| 311 |
} elseif ( $sanitized_user_name !== $username ) { |
| 312 |
// Invalid username. |
| 313 |
if ( is_multisite() ) { |
| 314 |
give_set_error( 'username_invalid', __( 'Invalid username. Only lowercase letters (a-z) and numbers are allowed.', 'give' ) ); |
| 315 |
$valid = false; |
| 316 |
} else { |
| 317 |
give_set_error( 'username_invalid', __( 'Invalid username.', 'give' ) ); |
| 318 |
$valid = false; |
| 319 |
} |
| 320 |
} |
| 321 |
} else { |
| 322 |
// Username is empty. |
| 323 |
give_set_error( 'username_empty', __( 'Enter a username.', 'give' ) ); |
| 324 |
$valid = false; |
| 325 |
|
| 326 |
// Check if guest checkout is disable for form. |
| 327 |
if ( $form_id && give_logged_in_only( $form_id ) ) { |
| 328 |
give_set_error( 'registration_required', __( 'You must register or log in to complete your donation.', 'give' ) ); |
| 329 |
$valid = false; |
| 330 |
} |
| 331 |
} |
| 332 |
|
| 333 |
/** |
| 334 |
* Filter the username validation result. |
| 335 |
* |
| 336 |
* @param bool $valid Username is valid or not. |
| 337 |
* @param string $username Username to check. |
| 338 |
* @param bool $form_id Donation Form ID. |
| 339 |
* |
| 340 |
* @since 1.8 |
| 341 |
*/ |
| 342 |
$valid = (bool) apply_filters( 'give_validate_username', $valid, $username, $form_id ); |
| 343 |
|
| 344 |
return $valid; |
| 345 |
} |
| 346 |
|
| 347 |
|
| 348 |
/** |
| 349 |
* Validate user email. |
| 350 |
* |
| 351 |
* @param string $email User email. |
| 352 |
* @param bool $registering_new_user Flag to check user register or not. |
| 353 |
* |
| 354 |
* @since 1.8 |
| 355 |
* |
| 356 |
* @return bool |
| 357 |
*/ |
| 358 |
function give_validate_user_email( $email, $registering_new_user = false ) { |
| 359 |
$valid = true; |
| 360 |
|
| 361 |
if ( empty( $email ) ) { |
| 362 |
// No email. |
| 363 |
give_set_error( 'email_empty', __( 'Enter an email.', 'give' ) ); |
| 364 |
$valid = false; |
| 365 |
|
| 366 |
} elseif ( email_exists( $email ) ) { |
| 367 |
// Email already exists. |
| 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' ) ); |
| 369 |
$valid = false; |
| 370 |
|
| 371 |
} elseif ( ! is_email( $email ) ) { |
| 372 |
// Validate email. |
| 373 |
give_set_error( 'email_invalid', __( 'Invalid email.', 'give' ) ); |
| 374 |
$valid = false; |
| 375 |
|
| 376 |
} elseif ( $registering_new_user ) { |
| 377 |
|
| 378 |
// If donor email is not primary. |
| 379 |
if ( ! email_exists( $email ) && give_donor_email_exists( $email ) && give_is_additional_email( $email ) ) { |
| 380 |
// Check if email exists. |
| 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' ) ); |
| 382 |
$valid = false; |
| 383 |
} |
| 384 |
} |
| 385 |
|
| 386 |
/** |
| 387 |
* Filter the email validation result. |
| 388 |
* |
| 389 |
* @param bool $valid Email is valid or not. |
| 390 |
* @param string $email Email to check. |
| 391 |
* @param bool $registering_new_user Registering New or Existing User. |
| 392 |
* |
| 393 |
* @since 1.8 |
| 394 |
*/ |
| 395 |
$valid = (bool) apply_filters( 'give_validate_user_email', $valid, $email, $registering_new_user ); |
| 396 |
|
| 397 |
return $valid; |
| 398 |
} |
| 399 |
|
| 400 |
/** |
| 401 |
* Validate password. |
| 402 |
* |
| 403 |
* @param string $password Password to Validate. |
| 404 |
* @param string $confirm_password Password to Confirm Validation. |
| 405 |
* @param bool $registering_new_user Registering New or Existing User. |
| 406 |
* |
| 407 |
* @since 1.8 |
| 408 |
* |
| 409 |
* @return bool |
| 410 |
*/ |
| 411 |
function give_validate_user_password( $password = '', $confirm_password = '', $registering_new_user = false ) { |
| 412 |
$valid = true; |
| 413 |
|
| 414 |
// Passwords Validation For New Donors Only. |
| 415 |
if ( $registering_new_user ) { |
| 416 |
// Password or confirmation missing. |
| 417 |
if ( ! $password ) { |
| 418 |
// The password is invalid. |
| 419 |
give_set_error( 'password_empty', __( 'Enter a password.', 'give' ) ); |
| 420 |
$valid = false; |
| 421 |
} elseif ( ! $confirm_password ) { |
| 422 |
// Confirmation password is invalid. |
| 423 |
give_set_error( 'confirmation_empty', __( 'Enter the password confirmation.', 'give' ) ); |
| 424 |
$valid = false; |
| 425 |
} |
| 426 |
} |
| 427 |
// Passwords Validation For New Donors as well as Existing Donors. |
| 428 |
if ( $password || $confirm_password ) { |
| 429 |
if ( strlen( $password ) < 6 || strlen( $confirm_password ) < 6 ) { |
| 430 |
// Seems Weak Password. |
| 431 |
give_set_error( 'password_weak', __( 'Passwords should have at least 6 characters.', 'give' ) ); |
| 432 |
$valid = false; |
| 433 |
} |
| 434 |
if ( $password && $confirm_password ) { |
| 435 |
// Verify confirmation matches. |
| 436 |
if ( $password !== $confirm_password ) { |
| 437 |
// Passwords do not match. |
| 438 |
give_set_error( 'password_mismatch', __( 'Passwords you entered do not match. Please try again.', 'give' ) ); |
| 439 |
$valid = false; |
| 440 |
} |
| 441 |
} |
| 442 |
} |
| 443 |
|
| 444 |
/** |
| 445 |
* Filter the password validation result. |
| 446 |
* |
| 447 |
* @param bool $valid Password is Valid or not. |
| 448 |
* @param string $password Password to check validation. |
| 449 |
* @param string $confirm_password Password to confirm validation. |
| 450 |
* @param bool $registering_new_user Registering New or Existing User. |
| 451 |
* |
| 452 |
* @since 1.8 |
| 453 |
*/ |
| 454 |
$valid = (bool) apply_filters( 'give_validate_user_email', $valid, $password, $confirm_password, $registering_new_user ); |
| 455 |
|
| 456 |
return $valid; |
| 457 |
} |
| 458 |
|
| 459 |
/** |
| 460 |
* Counts the total number of donors. |
| 461 |
* |
| 462 |
* @access public |
| 463 |
* @since 1.0 |
| 464 |
* |
| 465 |
* @return int The total number of donors. |
| 466 |
*/ |
| 467 |
function give_count_total_donors() { |
| 468 |
return Give()->donors->count(); |
| 469 |
} |
| 470 |
|
| 471 |
/** |
| 472 |
* Returns the saved address for a donor |
| 473 |
* |
| 474 |
* @access public |
| 475 |
* @since 1.0 |
| 476 |
* |
| 477 |
* @param int/null $donor_id Donor ID. |
| 478 |
* @param array $args { |
| 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 |
* |
| 484 |
* @return array The donor's address, if any |
| 485 |
*/ |
| 486 |
function give_get_donor_address( $donor_id = null, $args = [] ) { |
| 487 |
|
| 488 |
$args['by_user_id'] = false; |
| 489 |
|
| 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; |
| 494 |
} |
| 495 |
|
| 496 |
$donor = new Give_Donor( $donor_id, (bool) $args['by_user_id'] ); |
| 497 |
|
| 498 |
return $donor->get_donor_address( $args ); |
| 499 |
} |
| 500 |
|
| 501 |
/** |
| 502 |
* Give New User Notification |
| 503 |
* |
| 504 |
* Sends the new user notification email when a user registers within the donation form |
| 505 |
* |
| 506 |
* @param int $donation_id Donation ID. |
| 507 |
* @param array $donation_data An Array of Donation Data. |
| 508 |
* |
| 509 |
* @access public |
| 510 |
* @since 1.0 |
| 511 |
* |
| 512 |
* @return void |
| 513 |
*/ |
| 514 |
function give_new_user_notification( $donation_id = 0, $donation_data = [] ) { |
| 515 |
// Bailout. |
| 516 |
if ( |
| 517 |
empty( $donation_id ) |
| 518 |
|| empty( $donation_data ) |
| 519 |
|| ! isset( $_POST['give_create_account'] ) |
| 520 |
|| 'on' !== give_clean( $_POST['give_create_account'] ) |
| 521 |
) { |
| 522 |
return; |
| 523 |
} |
| 524 |
|
| 525 |
// For backward compatibility |
| 526 |
$user = get_user_by( 'ID', $donation_data['user_info']['id'] ); |
| 527 |
|
| 528 |
$donation_data['user_info'] = array_merge( |
| 529 |
$donation_data['user_info'], |
| 530 |
[ |
| 531 |
'user_id' => $donation_data['user_info']['id'], |
| 532 |
'user_first' => $donation_data['user_info']['first_name'], |
| 533 |
'user_last' => $donation_data['user_info']['last_name'], |
| 534 |
'user_email' => $donation_data['user_info']['email'], |
| 535 |
'user_login' => $user->user_login, |
| 536 |
] |
| 537 |
); |
| 538 |
|
| 539 |
do_action( 'give_new-donor-register_email_notification', $donation_data['user_info']['id'], $donation_data['user_info'], $donation_id ); |
| 540 |
do_action( 'give_donor-register_email_notification', $donation_data['user_info']['id'], $donation_data['user_info'], $donation_id ); |
| 541 |
} |
| 542 |
|
| 543 |
add_action( 'give_insert_payment', 'give_new_user_notification', 10, 2 ); |
| 544 |
|
| 545 |
|
| 546 |
/** |
| 547 |
* Get Donor Name By |
| 548 |
* |
| 549 |
* Retrieves the donor name based on the id and the name of the user or donation |
| 550 |
* |
| 551 |
* @param int $id The ID of donation or donor. |
| 552 |
* @param string $from From will be a string to be passed as donation or donor. |
| 553 |
* |
| 554 |
* @access public |
| 555 |
* @since 1.8.9 |
| 556 |
* |
| 557 |
* @return string |
| 558 |
*/ |
| 559 |
function give_get_donor_name_by( $id = 0, $from = 'donation' ) { |
| 560 |
|
| 561 |
// ID shouldn't be empty. |
| 562 |
if ( empty( $id ) ) { |
| 563 |
return ''; |
| 564 |
} |
| 565 |
|
| 566 |
$name = ''; |
| 567 |
$title_prefix = ''; |
| 568 |
|
| 569 |
switch ( $from ) { |
| 570 |
|
| 571 |
case 'donation': |
| 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 ); |
| 575 |
|
| 576 |
$name = "{$first_name} {$last_name}"; |
| 577 |
|
| 578 |
break; |
| 579 |
|
| 580 |
case 'donor': |
| 581 |
$name = Give()->donors->get_column( 'name', $id ); |
| 582 |
$title_prefix = Give()->donor_meta->get_meta( $id, '_give_donor_title_prefix', true ); |
| 583 |
|
| 584 |
break; |
| 585 |
|
| 586 |
} |
| 587 |
|
| 588 |
// If title prefix is set then prepend it to name. |
| 589 |
$name = give_get_donor_name_with_title_prefixes( $title_prefix, $name ); |
| 590 |
|
| 591 |
return $name; |
| 592 |
|
| 593 |
} |
| 594 |
|
| 595 |
/** |
| 596 |
* Checks whether the given donor email exists in users as well as additional_email of donors. |
| 597 |
* |
| 598 |
* @param string $email Donor Email. |
| 599 |
* |
| 600 |
* @since 1.8.9 |
| 601 |
* |
| 602 |
* @return boolean The user's ID on success, and false on failure. |
| 603 |
*/ |
| 604 |
function give_donor_email_exists( $email ) { |
| 605 |
if ( Give()->donors->get_donor_by( 'email', $email ) ) { |
| 606 |
return true; |
| 607 |
} |
| 608 |
return false; |
| 609 |
} |
| 610 |
|
| 611 |
/** |
| 612 |
* This function will check whether the donor email is primary or additional. |
| 613 |
* |
| 614 |
* @param string $email Donor Email. |
| 615 |
* |
| 616 |
* @since 1.8.13 |
| 617 |
* |
| 618 |
* @return bool |
| 619 |
*/ |
| 620 |
function give_is_additional_email( $email ) { |
| 621 |
global $wpdb; |
| 622 |
|
| 623 |
$meta_table = Give()->donor_meta->table_name; |
| 624 |
$meta_type = Give()->donor_meta->meta_type; |
| 625 |
$donor_id = $wpdb->get_var( $wpdb->prepare( "SELECT {$meta_type}_id FROM {$meta_table} WHERE meta_key = 'additional_email' AND meta_value = %s LIMIT 1", $email ) ); |
| 626 |
|
| 627 |
if ( empty( $donor_id ) ) { |
| 628 |
return false; |
| 629 |
} |
| 630 |
|
| 631 |
return true; |
| 632 |
} |
| 633 |
|