← All changes
|
app/Services/CustomerIdentity/EmailVerificationService.php
+18
-0
1.6.6
→
1.7.0
View file →
| @@ -2,8 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace FluentCart\App\Services\CustomerIdentity; |
| 4 | 4 | |
| 5 | 5 | use FluentCart\Api\Resource\CustomerResource; |
| 6 | +use FluentCart\Api\StoreSettings; | |
| 6 | 7 | use FluentCart\App\Models\Customer; |
| 7 | 8 | use FluentCart\Framework\Support\Arr; |
| 8 | 9 | |
| 9 | 10 | /** Tracks inbox proof independently from WordPress authentication. */ |
| @@ -75,13 +76,30 @@ | ||
| 75 | 76 | ]); |
| 76 | 77 | CustomerResource::resetCurrentCustomerRuntimeCache(); |
| 77 | 78 | } |
| 78 | 79 | |
| 80 | + public static function isEnabled(): bool | |
| 81 | + { | |
| 82 | + return (new StoreSettings())->get('require_customer_email_verification', 'no') !== 'no'; | |
| 83 | + } | |
| 84 | + | |
| 79 | 85 | public static function isRequired(int $userId): bool |
| 80 | 86 | { |
| 81 | 87 | $user = $userId ? get_userdata($userId) : false; |
| 82 | 88 | if (!$user) { |
| 83 | 89 | return true; |
| 90 | + } | |
| 91 | + | |
| 92 | + if (!static::isEnabled()) { | |
| 93 | + return false; | |
| 94 | + } | |
| 95 | + | |
| 96 | + // Registration and email changes always record state, so an account | |
| 97 | + // without it predates email verification and keeps its existing access. | |
| 98 | + if (!metadata_exists('user', $userId, static::META_KEY)) { | |
| 99 | + if (apply_filters('fluent_cart/customer/trust_legacy_accounts', true, ['user' => $user])) { | |
| 100 | + return false; | |
| 101 | + } | |
| 84 | 102 | } |
| 85 | 103 | |
| 86 | 104 | $state = get_user_meta($userId, static::META_KEY, true); |
| 87 | 105 | if (!is_array($state) || Arr::get($state, 'verified') !== true || !static::isSame(Arr::get($state, 'email', ''), $user->user_email)) { |