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 / DonorDashboards / Helpers.php

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

69 lines 1.9 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 WP_User;
6
7 /**
8 * @since 2.10.0
9 */
10 class Helpers
11 {
12
13 /**
14 * Retrieve the current donor ID from based on session
15 * @since 4.16.8.1 Guard against get_donor_by() finding no matching donor for the token's email.
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 if ($donor) {
35 return $donor->id;
36 }
37 }
38 }
39
40 return null;
41 }
42
43 /**
44 * Retrieve donor logged in status
45 *
46 * @since 3.15.0 added additional user role check
47 * @since 3.14.0 Add user capability and user role check
48 * @since 2.20.2
49 */
50 public static function isDonorLoggedIn(): bool
51 {
52 /** @var WP_User $user */
53 $user = wp_get_current_user();
54 $allowedRoles = ['administrator', 'give_donor', 'give_subscriber'];
55 // If the user is logged in and they are a donor, return true
56 if ( is_user_logged_in() ) {
57 $donor = give()->donors->get_donor_by('user_id', get_current_user_id());
58 if ($donor) {
59 return true;
60 }
61 }
62
63 return (is_user_logged_in() && !empty(array_intersect($allowedRoles, $user->roles))) || (
64 give_is_setting_enabled( give_get_option( 'email_access' ) ) &&
65 Give()->email_access->is_valid_token(Give()->email_access->get_token())
66 );
67 }
68 }
69