Admin
4 years ago
Exceptions
4 years ago
Factories
4 years ago
Helpers
4 years ago
Pipeline
4 years ago
Repositories
3 years ago
Routes
4 years ago
Tabs
3 years ago
resources
3 years ago
App.php
4 years ago
Block.php
3 years ago
Helpers.php
4 years ago
Profile.php
4 years ago
RequestHandler.php
4 years ago
ServiceProvider.php
4 years ago
Shortcode.php
4 years ago
Helpers.php
51 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\DonorDashboards; |
| 4 | |
| 5 | /** |
| 6 | * @since 2.10.0 |
| 7 | */ |
| 8 | class Helpers |
| 9 | { |
| 10 | |
| 11 | /** |
| 12 | * Retrieve the current donor ID from based on session |
| 13 | * @since 2.10.0 |
| 14 | */ |
| 15 | public static function getCurrentDonorId() |
| 16 | { |
| 17 | if (get_current_user_id()) { |
| 18 | $donor = give()->donors->get_donor_by('user_id', get_current_user_id()); |
| 19 | if ($donor) { |
| 20 | return $donor->id; |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | if (give()->email_access) { |
| 25 | give()->email_access->init(); |
| 26 | $useToken = give()->email_access->check_for_token(); |
| 27 | |
| 28 | if ($useToken) { |
| 29 | $donor = give()->donors->get_donor_by('email', give()->email_access->token_email); |
| 30 | |
| 31 | return $donor->id; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | return null; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Retrieve donor logged in status |
| 40 | * |
| 41 | * @since 2.20.2 |
| 42 | */ |
| 43 | public static function isDonorLoggedIn(): bool |
| 44 | { |
| 45 | return is_user_logged_in() || ( |
| 46 | give_is_setting_enabled( give_get_option( 'email_access' ) ) && |
| 47 | Give()->email_access->is_valid_token(Give()->email_access->get_token()) |
| 48 | ); |
| 49 | } |
| 50 | } |
| 51 |