PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.1
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
give / src / DonorDashboards / Helpers.php

Helpers.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.1, at src/DonorDashboards/Helpers.php

67 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\DonorDashboards;
4
5 use Give\Donors\Models\Donor;
6 use WP_User;
7
8 /**
9 * @since 2.10.0
10 */
11 class Helpers
12 {
13
14 /**
15 * Retrieve the current donor ID from based on session
16 * @since 2.10.0
17 */
18 public static function getCurrentDonorId()
19 {
20 if (get_current_user_id()) {
21 $donor = give()->donors->get_donor_by('user_id', get_current_user_id());
22 if ($donor) {
23 return $donor->id;
24 }
25 }
26
27 if (give()->email_access) {
28 give()->email_access->init();
29 $useToken = give()->email_access->check_for_token();
30
31 if ($useToken) {
32 $donor = give()->donors->get_donor_by('email', give()->email_access->token_email);
33
34 return $donor->id;
35 }
36 }
37
38 return null;
39 }
40
41 /**
42 * Retrieve donor logged in status
43 *
44 * @since 3.15.0 added additional user role check
45 * @since 3.14.0 Add user capability and user role check
46 * @since 2.20.2
47 */
48 public static function isDonorLoggedIn(): bool
49 {
50 /** @var WP_User $user */
51 $user = wp_get_current_user();
52 $allowedRoles = ['administrator', 'give_donor', 'give_subscriber'];
53 // If the user is logged in and they are a donor, return true
54 if ( is_user_logged_in() ) {
55 $donor = give()->donors->get_donor_by('user_id', get_current_user_id());
56 if ($donor) {
57 return true;
58 }
59 }
60
61 return (is_user_logged_in() && !empty(array_intersect($allowedRoles, $user->roles))) || (
62 give_is_setting_enabled( give_get_option( 'email_access' ) ) &&
63 Give()->email_access->is_valid_token(Give()->email_access->get_token())
64 );
65 }
66 }
67