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
give / src / Donors / Actions / CreateUserFromDonor.php

CreateUserFromDonor.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/Donors/Actions/CreateUserFromDonor.php

45 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Donors\Actions;
4
5 use Give\Donors\Exceptions\FailedDonorUserCreationException;
6 use Give\Donors\Models\Donor;
7
8 /**
9 * @since 3.2.0
10 */
11 class CreateUserFromDonor
12 {
13 public function __invoke(Donor $donor): Donor
14 {
15 $userIdOrError = wp_insert_user(apply_filters(
16 'givewp_create_donor_new_user',
17 [
18 'user_login' => $donor->email,
19 'user_pass' => wp_generate_password(),
20 'user_email' => $donor->email,
21 'first_name' => $donor->firstName,
22 'last_name' => $donor->lastName,
23 'role' => give_get_option( 'donor_default_user_role', 'give_donor' ),
24 ],
25 $donor
26 ));
27
28 if(!is_wp_error($userIdOrError)) {
29 $donor->userId = $userIdOrError;
30 } else {
31 throw new FailedDonorUserCreationException(
32 $donor,
33 0,
34 new \Exception($userIdOrError->get_error_message())
35 );
36 }
37
38 do_action('givewp_donor_user_created', $donor);
39
40 $donor->save();
41
42 return $donor;
43 }
44 }
45