Admin
4 years ago
Exceptions
4 years ago
Factories
4 years ago
Helpers
4 years ago
Pipeline
1 year ago
Repositories
3 years ago
Routes
2 years ago
Tabs
1 year ago
resources
1 year ago
App.php
1 year ago
Block.php
2 years ago
Helpers.php
1 year ago
Profile.php
1 year ago
RequestHandler.php
4 years ago
ServiceProvider.php
2 years ago
Shortcode.php
2 years ago
Helpers.php
60 lines
| 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 | |
| 54 | return (is_user_logged_in() && !empty(array_intersect($allowedRoles, $user->roles))) || ( |
| 55 | give_is_setting_enabled( give_get_option( 'email_access' ) ) && |
| 56 | Give()->email_access->is_valid_token(Give()->email_access->get_token()) |
| 57 | ); |
| 58 | } |
| 59 | } |
| 60 |